English
A service space corresponds to a set of independent cloud development resources, including databases, storage spaces, cloud functions and other resources. Service spaces are isolated from each other.
Each service space has a globally unique space ID.
Create a service space in the uniCloud
directory context menu
After creating a service space, associate the service space in the same uniCloud
directory context menu. Only after the project is associated with the service space, you can upload cloud functions, operate the database, storage and other resources under the service space.
The web console can create and delete service spaces and manage online service space resources.
Note for new service space
Before July 18, 2022, the multi-person collaboration in the service space is set up in the app collaboration on dev.dcloud.net.cn. After July 18, 2022, set it on unicloud.dcloud.net.cn instead.
A service space has only one creator, but collaboration members can be set.
When the project involves multi-person development, set up collaborators (select service space -> member management) in the uniCloud WEB console, so that multiple people can use one cloud service space together.
Collaborators can operate authorized service spaces in HBuilderX and the web console. Except for deleting service spaces, other functions can operate normally.
Authorization steps:
Member Management
member list
belowNotice
Each uni-app application has an appid, and each service space has a spaceid.
The service space and the mobile terminal project are in a many-to-many binding relationship. Under the same DCloud account, an application can be associated with multiple service spaces. A service space can also be accessed by multiple projects.
As more and more projects developed by users using uniCloud, some users encountered new problems.
Two or more projects want to share a cloud service space. For example, a system has a client project and an admin project. The two projects need a public service space. There are also the driver side, the passenger side, the user side, the rider side... Many similar problems.
If there are multiple duplicate cloud function files in each project directory. Every project needs to do operations such as synchronizing the cloud function list and downloading cloud functions. Cumbersome and prone to conflict.
In response to the above problems, a solution of one cloud with multiple projects
is provided.
选中项目下的uniCloud-alipay|aliyun|tcb
目录, 右键菜单,点击 【关联云服务空间或项目... 】 ,可以关联云服务空间
、绑定其它项目的服务空间
:
Select the associated project, all uniapp projects are displayed at this time. The user selects any uniapp item to associate, and the association effect is as follows:
associate the cloud service space
, bind the service space of other projects
Taking Alibaba Cloud as an example,
Bind the service space of other projects
refers to the currently used Alibaba Cloud service space associated with other projects.
If the application only connects to one service space, you can do the service space association in HBuilderX. Developers do not need to manually do initialization work (which can be understood as class calls).
//The project is only connected to one service space, so there is no need to initialize
//The API developed by the cloud can be called directly through uniCloud
uniCloud.callFunction()
uniCloud.uploadFile()
If an application needs to connect more service spaces at the same time, more service spaces cannot be bound in HBuilderX. At this time, the developer needs to manually call the initialization method uniCloud.init
in the client code to connect to other service spaces.
The uniCloud.init
method will return an uniCloud
instance, and all subsequent cloud function API calls need to be initiated through the uniCloud
instance (similar to instance calls).
The uniCloud.init
method is defined as follows:
function init(options):uniCloud
The uniCloud.init
method accepts an options
parameter and returns an uniCloud
instance, which can call cloud functions and cloud storage related APIs.
Notice
options parameter description
参数名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
provider | String | 是 | - | aliyun、tencent、alipay |
spaceId | String | 是 | - | 服务空间ID,注意是服务空间ID,不是服务空间名称 |
clientSecret | String | 是 | - | 仅阿里云支持,可以在uniCloud控制台服务空间列表中查看 |
accessKey | String | 是 | - | 仅支付宝小程序云支持, 可以在uniCloud控制台服务空间详情中查看 |
secretKey | String | 是 | - | 仅支付宝小程序云支持, 可以在uniCloud控制台服务空间详情中查看 |
spaceAppId | String | 是 | - | 仅支付宝小程序云支持, 可以在uniCloud控制台服务空间详情中查看 |
endpoint | String | 否 | 阿里云:https://api.bspapp.com ;支付宝小程序云: https://{spaceId}.api-hz.cloudbasefunction.cn | 服务空间地址,仅阿里云与支付宝小程序云支持。 阿里云商用版请将此参数设为 https://api.next.bspapp.com |
Sample code
// If the developer creates multiple service spaces, it needs to be initialized manually. Note that this is front-end code, not cloud function code
const myCloud = uniCloud.init({
provider: 'aliyun',
spaceId: 'xxxx-yyy',
clientSecret: 'xxxx'
});
//Call the API developed by the cloud through the uniCloud instance
myCloud.callFunction()
myCloud.uploadFile()
uniCloud还支持跨服务空间的数据库访问,另见文档