Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
fe292b7d
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
144
Star
2
Fork
33
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
9
列表
看板
标记
里程碑
合并请求
11
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
9
Issue
9
列表
看板
标记
里程碑
合并请求
11
合并请求
11
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fe292b7d
编写于
12月 06, 2024
作者:
G
git_robot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新 utsJson.json、utsApiJson.json、utsComJson.json、utsUnicloudApiJson.json
上级
c28dbd15
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
2 addition
and
2 deletion
+2
-2
docs/.vuepress/utils/utsComJson.json
docs/.vuepress/utils/utsComJson.json
+1
-1
docs/.vuepress/utils/utsUnicloudApiJson.json
docs/.vuepress/utils/utsUnicloudApiJson.json
+1
-1
未找到文件。
docs/.vuepress/utils/utsComJson.json
浏览文件 @
fe292b7d
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
docs/.vuepress/utils/utsUnicloudApiJson.json
浏览文件 @
fe292b7d
{
"uniCloud_props"
:{
"name"
:
"# uniCloud"
,
"description"
:
""
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| config | **UniCloudInitOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| provider | string | 是 | - | - | 服务商,目前支持 aliyun、tencent、alipay |
\n
@| spaceName | string | 否 | - | - | 服务空间名 |
\n
@| spaceId | string | 是 | - | - | 服务空间id |
\n
@| clientSecret | string | 否 | - | - | 阿里云clientSecret |
\n
@| endpoint | string | 否 | - | - | 阿里云endpoint |
\n
@| spaceAppId | string | 否 | - | - | 支付宝云spaceAppId |
\n
@| accessKey | string | 否 | - | - | 支付宝云accessKey |
\n
@| secretKey | string | 否 | - | - | 支付宝云secretKey |
\n
@| wsEndpoint | string | 否 | - | - | 支付宝云 WebSocket Endpoint |
\n
| mixinDatacom | any | 是 | - | - | - |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
""
,
"tutorial"
:
""
},
"callFunction"
:{
"name"
:
"## callFunction(options) @callfunction"
,
"description"
:
"请求云函数"
,
"compatibility"
:
"### callFunction 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudCallFunctionOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| name | string ([string.CloudFunctionString](/uts/data-type.md#ide-string)) | 是 | - | - | 云函数名 |
\n
@| data | any | 否 | - | - | 云函数参数 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudCallFunctionResult
\\
<T>](#unicloudcallfunctionresult-values)> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| result | T | 是 | - | - | 云函数返回结果 |
\n
@| requestId | string | 否 | - | - | 云函数请求id |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudFunction.callFunction)"
},
"cloudFunction"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/cloud-function.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/cloud-function
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/cloud-function
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@click=
\"
callFunction
\"
>请求云函数</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
callFunctionWithGeneric
\"
>请求云函数传入泛型</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n\r\n
<style>
\r\n
</style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: '请求云函数',
\r\n
callFunctionResult: {},
\r\n
callFunctionError: {},
\r\n
genericDemoShowMessage: '',
\r\n
isUniTest: false
\r\n
}
\r\n
},
\r\n
onLoad() {
\r\n
},
\r\n
onUnload() {
\r\n
if (this.isUniTest) {
\r\n
uni.hideToast()
\r\n
}
\r\n
},
\r\n
methods: {
\r\n
notify(content : string, title : string) {
\r\n
if (!this.isUniTest) {
\r\n
uni.showModal({
\r\n
title,
\r\n
content,
\r\n
showCancel: false
\r\n
})
\r\n
} else {
\r\n
console.log(title, content)
\r\n
}
\r\n
},
\r\n
async callFunctionWithGeneric() : Promise<void> {
\r\n
type EchoCfResult = {
\r\n
showMessage : string
\r\n
}
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
await uniCloud.callFunction<EchoCfResult>({
\r\n
name: 'echo-cf',
\r\n
data: {
\r\n
num: 1,
\r\n
str: 'ABC'
\r\n
}
\r\n
}).then(res => {
\r\n
const result = res.result
\r\n
uni.hideLoading()
\r\n
this.genericDemoShowMessage = result.showMessage
\r\n
this.notify(result.showMessage, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.callFunctionError = {
\r\n
errCode: error.errCode,
\r\n
errMsg: error.errMsg
\r\n
}
\r\n
uni.hideLoading()
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async callFunction() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
await uniCloud.callFunction({
\r\n
name: 'echo-cf',
\r\n
data: {
\r\n
num: 1,
\r\n
str: 'ABC'
\r\n
}
\r\n
}).then(res => {
\r\n
const result = res.result
\r\n
this.callFunctionResult = result
\r\n
console.log(JSON.stringify(result))
\r\n
uni.hideLoading()
\r\n
this.notify(result['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.callFunctionError = {
\r\n
errCode: error.errCode,
\r\n
errMsg: error.errMsg
\r\n
}
\r\n
uni.hideLoading()
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\n
jest_UniCloudError() {
\n
return new Error() instanceof UniCloudError
\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"importObject"
:{
"name"
:
"## importObject(objectName, options?) @importobject"
,
"description"
:
"引用云对象"
,
"compatibility"
:
"### importObject 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| objectName | string ([string.CloudObjectString](/uts/data-type.md#ide-string)) | 是 | - | - | - |
\n
| options | **UniCloudImportObjectOptions** | 否 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| customUI | boolean | 否 | - | - | 是否移除自动展示的ui |
\n
@| loadingOptions | **UniCloudImportObjectLoadingOptions** | 否 | - | - | loading界面配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| title | string | 否 | - | - | 加载框标题 |
\n
@@| mask | boolean | 否 | - | - | 加载框是否显示mask |
\n
@| errorOptions | **UniCloudImportObjectErrorOptions** | 否 | - | - | 错误提示配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| type | string | 否 | - | - | 错误提示类型,可以是modal或者toast |
\n
@@| retry | boolean | 否 | - | - | 是否显示重试按钮 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudCloudObjectCaller](#unicloudcloudobjectcaller-values) |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| _obj | [InternalUniCloudCloudObject](#internalunicloudcloudobject-values) | 是 | - | - | - |
\n
##### InternalUniCloudCloudObject 的方法 @internalunicloudcloudobject-values
\n\n
##### callMethod
\\
<T = UTSJSONObject>(methodName: string, args: Array
\\
<any
\\
| null>): Promise
\\
<T>; @callmethod
\n\n
###### callMethod 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| methodName | string | 是 | - | - | - |
\n
| args | Array
\\
<any
\\
> | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<T> |
\n
\n\n
#### UniCloudCloudObjectCaller 的方法 @unicloudcloudobjectcaller-values
\n\n
#### protected _getArgs(...args: Array
\\
<any
\\
| null>): Array
\\
<any
\\
| null>; @_getargs
\n\n
##### _getArgs 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| args | Array
\\
<any
\\
> | 否 | - | - | - |
\n\n
##### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Array
\\
<any
\\
> |
\n
\n
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudObject.importObject)"
},
"cloudObject"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/cloud-object.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/cloud-object
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/cloud-object
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
addTodo
\"
>添加Todo</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
addTodoWithGeneric
\"
>
\r\n
添加Todo传入泛型
\r\n
</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
randomFail
\"
>随机触发失败重试</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
fail
\"
>云对象失败调用</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
failWithNumberErrCode
\"
>
\r\n
云对象数字错误码
\r\n
</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
success
\"
>云对象成功调用</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n\r\n
<style></style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: '请求云对象',
\r\n
todoTitle: '学习编程',
\r\n
todoContent: '熟悉uts语法',
\r\n
returnTodoTitle: '',
\r\n
returnTodoContent: '',
\r\n
genericDemoReturnTodoTitle: '',
\r\n
genericDemoReturnTodoContent: '',
\r\n
failErrCode: '',
\r\n
failErrDetailTips: '',
\r\n
failNumberErrCode: 0,
\r\n
successErrCode: -1,
\r\n
isUniTest: false
\r\n
}
\r\n
},
\r\n
methods: {
\r\n
notify(content : string, title : string) {
\r\n
if (!this.isUniTest) {
\r\n
uni.showModal({
\r\n
title,
\r\n
content,
\r\n
showCancel: false
\r\n
})
\r\n
} else {
\r\n
console.log(title, content)
\r\n
}
\r\n
},
\r\n
async addTodo() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
const title = this.todoTitle
\r\n
const content = this.todoContent
\r\n
await todo.add<UTSJSONObject>(title, content).then((res : UTSJSONObject) => {
\r\n
this.returnTodoTitle = res['title'] as string
\r\n
this.returnTodoContent = res['content'] as string
\r\n
this.notify(res['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
console.log(err)
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async addTodoWithGeneric() : Promise<void> {
\r\n
type AddTodoResult = {
\r\n
title : string,
\r\n
content : string,
\r\n
showMessage : string
\r\n
}
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
const title = this.todoTitle
\r\n
const content = this.todoContent
\r\n
await todo.add<AddTodoResult>(title, content).then((res : AddTodoResult) => {
\r\n
this.genericDemoReturnTodoTitle = res.title
\r\n
this.genericDemoReturnTodoContent = res.content
\r\n
this.notify(res.showMessage, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
console.log(err)
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async randomFail() : Promise<void> {
\r\n
const todoObj = uniCloud.importObject('todo', {
\r\n
errorOptions: {
\r\n
retry: true
\r\n
}
\r\n
})
\r\n
await todoObj.randomFail().then((res : UTSJSONObject) => {
\r\n
this.notify(res['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async fail() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
await todo.fail().then((res : UTSJSONObject) => {
\r\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\r\n
console.log('todo.fail: ', res);
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.failErrCode = error.errCode as string
\r\n
const detail = error.detail
\r\n
if (detail != null && detail['tips'] != null) {
\r\n
this.failErrDetailTips = detail['tips'] as string
\r\n
}
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async failWithNumberErrCode() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
await todo.failWithNumberErrCode().then((res : UTSJSONObject) => {
\r\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\r\n
console.log('todo.fail: ', res);
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.failNumberErrCode = error.errCode as number
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async success() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
await todo.success().then((res : UTSJSONObject) => {
\r\n
this.successErrCode = res['errCode'] as number
\r\n
this.notify(res['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"uploadFile"
:{
"name"
:
"## uploadFile(options) @uploadfile"
,
"description"
:
"上传文件到云存储"
,
"compatibility"
:
"### uploadFile 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | [UniCloudUploadFileOptions](#uniclouduploadfileoptions-values) | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| filePath | string | 是 | - | - | 文件路径 |
\n
@| cloudPath | string | 是 | - | - | 云端路径 |
\n
@| cloudPathAsRealPath | boolean | 否 | - | - | 是否以云端路径是否为真实路径保存上传的文件 |
\n\n
### UniCloudUploadFileOptions 的方法 @uniclouduploadfileoptions-values
\n\n
### (options: UniCloudUploadProgress) => any @onuploadprogress
\n
上传进度回调
\n
#### onUploadProgress 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
#### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudUploadProgress** | 是 | - | - | 上传进度回调参数 |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| loaded | number | 是 | - | - | 已上传大小 |
\n
@| total | number | 是 | - | - | 总大小 |
\n\n
#### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| filePath | string | 是 | - | - | 文件路径 |
\n
@| fileID | string | 是 | - | - | 文件id |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudStorage.uploadFile)"
},
"getTempFileURL"
:{
"name"
:
"## getTempFileURL(options) @gettempfileurl"
,
"description"
:
"获取文件临时URL"
,
"compatibility"
:
"### getTempFileURL 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudGetTempFileURLOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| fileList | Array
\\
<string
\\
> | 是 | - | - | 文件列表 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudGetTempFileURLResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| fileList | Array
\\
<**UniCloudGetTempFileURLResultItem**
\\
> | 是 | - | - | 文件列表 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| fileID | string | 是 | - | - | 文件id |
\n
@@| tempFileURL | string | 是 | - | - | 文件临时url |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudStorage.chooseAndUploadFile)"
},
"chooseAndUploadFile"
:{
"name"
:
"## chooseAndUploadFile(options) @chooseanduploadfile"
,
"description"
:
"选择并上传文件"
,
"compatibility"
:
"### chooseAndUploadFile 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | [UniCloudChooseAndUploadFileOptions](#unicloudchooseanduploadfileoptions-values) | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| sourceType | Array
\\
<'album'
\\
| 'camera'
\\
> | 否 | - | - | |
\n
@| count | number | 否 | - | - | |
\n
@| sizeType | Array
\\
<'original'
\\
| 'compressed'
\\
> | 否 | - | - | |
\n
@| extension | Array
\\
<string
\\
> | 否 | - | - | |
\n
@| compressed | boolean | 否 | - | - | |
\n
@| maxDuration | number | 否 | - | - | |
\n
@| camera | string | 否 | - | - | - |
\n
@@| 合法值 | 兼容性 | 描述 |
\n
@@| :- | :-: | :- |
\n
@@| front | - | - |
\n
@@| back | - | - |
\n
@| crop | ChooseImageCropOptions | 否 | - | - | |
\n
@| type | string | 是 | - | - | - |
\n
@@| 合法值 | 兼容性 | 描述 |
\n
@@| :- | :-: | :- |
\n
@@| image | - | - |
\n
@@| video | - | - |
\n
@@| all | - | - |
\n\n
### UniCloudChooseAndUploadFileOptions 的方法 @unicloudchooseanduploadfileoptions-values
\n\n
### (arg: UniCloudChooseAndUploadFileResult) => void
\\
| null @onchoosefile
\n\n
#### onChooseFile 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
#### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | **UniCloudChooseAndUploadFileResult** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseAndUploadFileItem**
\\
> | 是 | - | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| name | string | 是 | - | - | - |
\n
@@| path | string | 是 | - | - | - |
\n
@@| cloudPath | string | 是 | - | - | - |
\n
@@| cloudPathAsRealPath | boolean | 否 | - | - | |
\n
@@| url | string | 否 | - | - | |
\n
@@| errMsg | string | 否 | - | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - | - |
\n\n\n
### (arg: UniCloudChooseAndUploadFileProgressEvent) => void
\\
| null @onuploadprogress
\n\n
#### onUploadProgress 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
#### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | **UniCloudChooseAndUploadFileProgressEvent** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| index | number | 是 | - | - | - |
\n
@| loaded | number | 是 | - | - | - |
\n
@| total | number | 是 | - | - | - |
\n
@| tempFilePath | string | 是 | - | - | - |
\n
@| tempFile | [UniCloudChooseAndUploadFileItem](#unicloudchooseanduploadfileitem-values) | 是 | - | - | - |
\n\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudChooseAndUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseAndUploadFileItem**
\\
> | 是 | - | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| name | string | 是 | - | - | - |
\n
@@| path | string | 是 | - | - | - |
\n
@@| cloudPath | string | 是 | - | - | - |
\n
@@| cloudPathAsRealPath | boolean | 否 | - | - | |
\n
@@| url | string | 否 | - | - | |
\n
@@| errMsg | string | 否 | - | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - | - |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudStorage.getTempFileURL)"
},
"cloudStorage"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/cloud-storage.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/cloud-storage
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/cloud-storage
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@click=
\"
uploadFile
\"
>选择文件上传</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
chooseAndUploadFile
\"
>一个接口选择文件并上传</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n
<style>
\r\n
</style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: '云存储'
\r\n
}
\r\n
},
\r\n
onLoad() {
\r\n
},
\r\n
onUnload() {
\r\n
},
\r\n
methods: {
\r\n
uploadFile: function () {
\r\n
uni.chooseImage({
\r\n
count: 1,
\r\n
success(res) : void {
\r\n
uni.showLoading({
\r\n
title: '上传中...'
\r\n
})
\r\n
const tempFilePath = res.tempFilePaths[0]
\r\n
uniCloud.uploadFile({
\r\n
filePath: tempFilePath,
\r\n
cloudPath: 'test.jpg'
\r\n
})
\r\n
.then(function (res) {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
uni.showModal({
\r\n
content: '上传成功',
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
.catch(function (err : any | null) {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
uni.showModal({
\r\n
content: '上传失败,' + error.errMsg,
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
// .finally((_: number) : void => {
\r\n
// uni.hideLoading()
\r\n
// })
\r\n
},
\r\n
fail(err) : void {
\r\n
console.error('chooseImage fail: ', err)
\r\n
}
\r\n
})
\r\n
},
\r\n
chooseAndUploadFile() {
\r\n
uniCloud.chooseAndUploadFile({
\r\n
type: 'image'
\r\n
}).then(function (res) {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
uni.showModal({
\r\n
content: '上传成功',
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
.catch(function (err : any | null) {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
uni.showModal({
\r\n
content: '上传失败,' + error.errMsg,
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"databaseForJQL"
:{
"name"
:
"## databaseForJQL() @databaseforjql"
,
"description"
:
"获取数据库操作实例"
,
"compatibility"
:
"### databaseForJQL 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.91,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
""
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [Database](#database-values) |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| command | any | 是 | - | - | - |
\n
@| Geo | any | 是 | - | - | - |
\n
#### Database 的方法 @database-values
\n\n
#### collection(...args: Array
\\
<any>): Collection; @collection
\n\n
##### collection 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| args | Array
\\
<any
\\
> | 否 | - | - | - |
\n\n
##### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [Collection](#collection-values) |
\n\n
###### Collection 的方法 @collection-values
\n\n
###### where(condition: any): UniCloudDBFilter; @where
\n\n
###### where 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| condition | any | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n\n
###### UniCloudDBFilter 的方法 @uniclouddbfilter-values
\n\n
###### get(arg?: UTSJSONObject
\\
| null): Promise
\\
<UniCloudDBGetResult>; @get
\n\n
###### get 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | any | 否 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBGetResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| data | Array
\\
<any
\\
> | 是 | - | - | 添加的记录的id列表 |
\n
@| count | number | 否 | - | - | 匹配到的数据总量 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### count(): Promise
\\
<UniCloudDBCountResult>; @count
\n\n
###### count 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBCountResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| total | number | 是 | - | - | 添加的记录的id列表 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### update(data: UTSJSONObject): Promise
\\
<UniCloudDBUpdateResult>; @update
\n\n
###### update 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| data | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBUpdateResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| updated | number | 是 | - | - | 更新成功的记录数 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### remove(): Promise
\\
<UniCloudDBRemoveResult>; @remove
\n\n
###### remove 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBRemoveResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| deleted | number | 是 | - | - | 删除成功的记录数 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### getTemp(): UTSJSONObject; @gettemp
\n\n
###### getTemp 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n
###### where(condition: any): UniCloudDBFilter; @where
\n\n
###### where 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| condition | any | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### doc(docId: string): UniCloudDBFilter; @doc
\n\n
###### doc 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| docId | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### field(filed: string): UniCloudDBQuery; @field
\n\n
###### field 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| filed | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n\n
###### UniCloudDBQuery 的方法 @uniclouddbquery-values
\n\n
###### get(arg?: UTSJSONObject
\\
| null): Promise
\\
<UniCloudDBGetResult>; @get
\n\n
###### get 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | any | 否 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n
###### count(): Promise
\\
<UniCloudDBCountResult>; @count
\n\n
###### count 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n
###### getTemp(): UTSJSONObject; @gettemp
\n\n
###### getTemp 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n
###### field(filed: string): UniCloudDBQuery; @field
\n\n
###### field 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| filed | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### skip(num: number): UniCloudDBQuery; @skip
\n\n
###### skip 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### limit(num: number): UniCloudDBQuery; @limit
\n\n
###### limit 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### orderBy(order: string): UniCloudDBQuery; @orderby
\n\n
###### orderBy 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| order | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupBy(field: string): UniCloudDBQuery; @groupby
\n\n
###### groupBy 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupField(field: string): UniCloudDBQuery; @groupfield
\n\n
###### groupField 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### distinct(field: string): UniCloudDBQuery; @distinct
\n\n
###### distinct 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### geoNear(options: UTSJSONObject): UniCloudDBQuery; @geonear
\n\n
###### geoNear 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n
\n\n
###### skip(num: number): UniCloudDBQuery; @skip
\n\n
###### skip 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### limit(num: number): UniCloudDBQuery; @limit
\n\n
###### limit 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### orderBy(order: string): UniCloudDBQuery; @orderby
\n\n
###### orderBy 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| order | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupBy(field: string): UniCloudDBQuery; @groupby
\n\n
###### groupBy 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupField(field: string): UniCloudDBQuery; @groupfield
\n\n
###### groupField 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### distinct(field: string): UniCloudDBQuery; @distinct
\n\n
###### distinct 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### geoNear(options: UTSJSONObject): UniCloudDBQuery; @geonear
\n\n
###### geoNear 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n
\n\n
###### doc(docId: string): UniCloudDBFilter; @doc
\n\n
###### doc 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| docId | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### aggregate(): UniCloudDBFilter; @aggregate
\n\n
###### aggregate 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### foreignKey(foreignKey: string): UniCloudDBFilter; @foreignkey
\n\n
###### foreignKey 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| foreignKey | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### add(data: UTSJSONObject): Promise
\\
<UniCloudDBAddResult>; @add
\n\n
###### add 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| data | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBAddResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| id | string | 是 | - | - | 添加的记录的id |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### get(arg?: UTSJSONObject
\\
| null): Promise
\\
<UniCloudDBGetResult>; @get
\n\n
###### get 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | any | 否 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n
###### count(): Promise
\\
<UniCloudDBCountResult>; @count
\n\n
###### count 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n
###### getTemp(): UTSJSONObject; @gettemp
\n\n
###### getTemp 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n
###### field(filed: string): UniCloudDBQuery; @field
\n\n
###### field 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| filed | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### skip(num: number): UniCloudDBQuery; @skip
\n\n
###### skip 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### limit(num: number): UniCloudDBQuery; @limit
\n\n
###### limit 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### orderBy(order: string): UniCloudDBQuery; @orderby
\n\n
###### orderBy 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| order | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n
\n\n
#### multiSend(...args: Array
\\
<UTSJSONObject>): Promise
\\
<UniCloudDBMultiSendResult>; @multisend
\n
合并查询请求
\n
##### multiSend 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 4.16 | 4.11 |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| args | Array
\\
<any
\\
> | 否 | - | - | - |
\n\n
##### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBMultiSendResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| dataList | Array
\\
<**UniCloudDBMultiSendResultItem**
\\
> | 是 | - | - | 数据列表 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| errCode | any | 是 | - | - | 错误码,可能为字符串或数字,数字0表示成功 |
\n
@@| errMsg | string | 是 | - | - | 错误信息 |
\n
@@| data | Array
\\
<any
\\
> | 否 | - | - | 数据 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.database.databaseForJQL)"
},
"database"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/database.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/database
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/database
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbAdd
\"
>新增单条数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbBatchAdd
\"
>新增多条数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbUpdate
\"
>更新数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbGet
\"
>where传字符串获取数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbGetWithCommand
\"
>where传对象获取数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbRemove
\"
>删除数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbLookupInit
\"
>初始化联表查询数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbLookup
\"
>联表查询</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbMultiSend
\"
>合并查询查询</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n\r\n
<style>
\r\n
</style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: 'ClientDB',
\r\n
addId: '',
\r\n
batchAddIds: [] as Array<string>,
\r\n
batchAddinserted: 0,
\r\n
updateUpdated: 0,
\r\n
getData: [] as Array<UTSJSONObject>,
\r\n
getWithCommandData: [] as Array<UTSJSONObject>,
\r\n
removeDeleted: 0,
\r\n
lookupData: [] as Array<UTSJSONObject>,
\r\n
multiSendSuccessCount: 0,
\r\n
isUniTest: false
\r\n
}
\r\n
},
\r\n
computed: {
\r\n
dataTag() : string {
\r\n
return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag'
\r\n
}
\r\n
},
\r\n
methods: {
\r\n
notify(content : string, title : string) {
\r\n
if (!this.isUniTest) {
\r\n
uni.showModal({
\r\n
title,
\r\n
content,
\r\n
showCancel: false
\r\n
})
\r\n
} else {
\r\n
console.log(title, content)
\r\n
}
\r\n
},
\r\n
async dbAdd() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.add({
\r\n
num: 1,
\r\n
tag: this.dataTag,
\r\n
date: new Date()
\r\n
})
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.addId = res.id
\r\n
this.notify(`新增成功,id: ${res.id}`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbBatchAdd() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.add([{
\r\n
num: 2,
\r\n
tag: this.dataTag,
\r\n
}, {
\r\n
num: 3,
\r\n
tag: this.dataTag,
\r\n
}])
\r\n
.then((res) => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
console.log('JSON.stringify(res.inserted)', JSON.stringify(res.inserted))
\r\n
this.batchAddIds = res.ids
\r\n
this.batchAddinserted = res.inserted
\r\n
this.notify(`新增成功条数${res.inserted}, id列表: ${res.ids.join(',')}`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbGet() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where(
\r\n
`tag ==
\"
${this.dataTag}
\"
`
\r\n
)
\r\n
.field('num, tag')
\r\n
.orderBy('num desc')
\r\n
.skip(1)
\r\n
.limit(2)
\r\n
.get()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.getData = res.data
\r\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbGetWithCommand() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where({
\r\n
num: db.command.gt(1),
\r\n
tag: this.dataTag
\r\n
})
\r\n
.field('num, tag')
\r\n
.orderBy('num desc')
\r\n
.skip(1)
\r\n
.limit(2)
\r\n
.get()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.getWithCommandData = res.data
\r\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbUpdate() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where(
\r\n
`tag ==
\"
${this.dataTag}
\"
`
\r\n
)
\r\n
.update({
\r\n
num: 4
\r\n
})
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.updateUpdated = res.updated
\r\n
this.notify(`更新成功,更新了${res.updated}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbRemove() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where(
\r\n
`tag ==
\"
${this.dataTag}
\"
`
\r\n
)
\r\n
.remove()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.removeDeleted = res.deleted
\r\n
this.notify(`删除成功,删掉了${res.deleted}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbLookupInit() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('local')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.remove()
\r\n
.then(() : Promise<UniCloudDBRemoveResult> => {
\r\n
return db.collection('foreign')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.remove()
\r\n
})
\r\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\r\n
return db.collection('local')
\r\n
.add([{
\r\n
id:
\"
local_1
\"
,
\r\n
name:
\"
local_1_name
\"
,
\r\n
tag: this.dataTag,
\r\n
foreign_id:
\"
foreign_1
\"\r\n
}, {
\r\n
id:
\"
local_2
\"
,
\r\n
name:
\"
local_2_name
\"
,
\r\n
tag: this.dataTag,
\r\n
foreign_id:
\"
foreign_2
\"\r\n
}])
\r\n
})
\r\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\r\n
return db.collection('foreign')
\r\n
.add([{
\r\n
id:
\"
foreign_1
\"
,
\r\n
name:
\"
foreign_1_name
\"
,
\r\n
tag: this.dataTag
\r\n
}, {
\r\n
id:
\"
foreign_2
\"
,
\r\n
name:
\"
foreign_2_name
\"
,
\r\n
tag: this.dataTag
\r\n
}])
\r\n
})
\r\n
.then((_) : void => {
\r\n
uni.hideLoading()
\r\n
this.notify('数据初始化成功', '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
console.error(err)
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbLookup() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
const local = db.collection('local')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.getTemp()
\r\n
const foreign = db.collection('foreign')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.getTemp()
\r\n
await db.collection(local, foreign)
\r\n
.get()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.lookupData = res.data
\r\n
this.notify(`联表查询成功,取到了${res.data.length}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbMultiSend() : Promise<void> {
\r\n
const db = uniCloud.databaseForJQL()
\r\n
const temp1 = db.collection('type')
\r\n
.where(
\r\n
'tag ==
\"
default-tag
\"
'
\r\n
).getTemp()
\r\n
const temp2 = db.collection('type')
\r\n
.where(
\r\n
'tag ==
\"
default-tag
\"
'
\r\n
).getTemp()
\r\n
await db.multiSend(temp1, temp2)
\r\n
.then<void>(res => {
\r\n
uni.hideLoading()
\r\n
let successCount = 0
\r\n
for (let i = 0; i < res.dataList.length; i++) {
\r\n
const item = res.dataList[i]
\r\n
if (item.errCode == 0) {
\r\n
console.log(`第${i}个请求查询到${item.data!.length}条数据`)
\r\n
successCount++
\r\n
} else {
\r\n
console.error(`第${i}个请求查询失败,错误信息:${item.data!.length}`)
\r\n
}
\r\n
}
\r\n
this.multiSendSuccessCount = successCount
\r\n
this.notify(`合并查询成功,成功查询的语句条数为:${successCount}`, '提示')
\r\n
})
\r\n
.catch<void>((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
console.error(err)
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"onResponse"
:{
"name"
:
"## onResponse(callback) @onresponse"
,
"description"
:
"监听响应事件"
,
"compatibility"
:
"### onResponse 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.onResponse)"
},
"offResponse"
:{
"name"
:
"## offResponse(callback) @offresponse"
,
"description"
:
"移除响应事件监听"
,
"compatibility"
:
"### offResponse 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.offResponse)"
},
"onRefreshToken"
:{
"name"
:
"## onRefreshToken(callback) @onrefreshtoken"
,
"description"
:
"监听token刷新事件"
,
"compatibility"
:
"### onRefreshToken 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.onRefreshToken)"
},
"offRefreshToken"
:{
"name"
:
"## offRefreshToken(callback) @offrefreshtoken"
,
"description"
:
"移除token刷新事件监听"
,
"compatibility"
:
"### offRefreshToken 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.offRefreshToken)"
},
"getCurrentUserInfo"
:{
"name"
:
"## getCurrentUserInfo() @getcurrentuserinfo"
,
"description"
:
"获取token内缓存的用户信息"
,
"compatibility"
:
"### getCurrentUserInfo 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.0 | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
""
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| **UniCloudUserInfo** |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| uid | string | 否 | - | - | 用户id |
\n
@| role | Array
\\
<string
\\
> | 是 | - | - | 用户角色列表 |
\n
@| permission | Array
\\
<string
\\
> | 是 | - | - | 用户权限列表 |
\n
@| tokenExpired | number | 是 | - | - | 用户token过期时间 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.getCurrentUserInfo)"
},
"connectWebSocket"
:{
"name"
:
"## connectWebSocket(options) @connectwebsocket"
,
"description"
:
"连接 WebSocket"
,
"compatibility"
:
"### connectWebSocket 兼容性
\n
| Web | Android | iOS |
\n
| :- | :- | :- |
\n
| 4.24 | 4.28 | 4.24 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudConnectWebSocketOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| name | string | 是 | - | - | WebSocket云函数/云对象名称 |
\n
@| query | any | 否 | - | - | 建立连接时需要传递的参数, 仅在 connection 事件中接收到 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| SocketTask |
\n
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.connectWebSocket)"
}}
{
"uniCloud_props"
:{
"name"
:
"# uniCloud"
,
"description"
:
""
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| config | **UniCloudInitOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| provider | string | 是 | - | - | 服务商,目前支持 aliyun、tencent、alipay |
\n
@| spaceName | string | 否 | - | - | 服务空间名 |
\n
@| spaceId | string | 是 | - | - | 服务空间id |
\n
@| clientSecret | string | 否 | - | - | 阿里云clientSecret |
\n
@| endpoint | string | 否 | - | - | 阿里云endpoint |
\n
@| spaceAppId | string | 否 | - | - | 支付宝云spaceAppId |
\n
@| accessKey | string | 否 | - | - | 支付宝云accessKey |
\n
@| secretKey | string | 否 | - | - | 支付宝云secretKey |
\n
@| wsEndpoint | string | 否 | - | - | 支付宝云 WebSocket Endpoint |
\n
| mixinDatacom | any | 是 | - | - | - |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
""
,
"tutorial"
:
""
},
"callFunction"
:{
"name"
:
"## callFunction(options) @callfunction"
,
"description"
:
"请求云函数"
,
"compatibility"
:
"### callFunction 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudCallFunctionOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| name | string ([string.CloudFunctionString](/uts/data-type.md#ide-string)) | 是 | - | - | 云函数名 |
\n
@| data | any | 否 | - | - | 云函数参数 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudCallFunctionResult
\\
<T>](#unicloudcallfunctionresult-values)> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| result | T | 是 | - | - | 云函数返回结果 |
\n
@| requestId | string | 否 | - | - | 云函数请求id |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudFunction.callFunction)"
},
"cloudFunction"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/cloud-function.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/cloud-function
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/cloud-function
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@click=
\"
callFunction
\"
>请求云函数</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
callFunctionWithGeneric
\"
>请求云函数传入泛型</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n\r\n
<style>
\r\n
</style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: '请求云函数',
\r\n
callFunctionResult: {},
\r\n
callFunctionError: {},
\r\n
genericDemoShowMessage: '',
\r\n
isUniTest: false
\r\n
}
\r\n
},
\r\n
onLoad() {
\r\n
},
\r\n
onUnload() {
\r\n
if (this.isUniTest) {
\r\n
uni.hideToast()
\r\n
}
\r\n
},
\r\n
methods: {
\r\n
notify(content : string, title : string) {
\r\n
if (!this.isUniTest) {
\r\n
uni.showModal({
\r\n
title,
\r\n
content,
\r\n
showCancel: false
\r\n
})
\r\n
} else {
\r\n
console.log(title, content)
\r\n
}
\r\n
},
\r\n
async callFunctionWithGeneric() : Promise<void> {
\r\n
type EchoCfResult = {
\r\n
showMessage : string
\r\n
}
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
await uniCloud.callFunction<EchoCfResult>({
\r\n
name: 'echo-cf',
\r\n
data: {
\r\n
num: 1,
\r\n
str: 'ABC'
\r\n
}
\r\n
}).then(res => {
\r\n
const result = res.result
\r\n
uni.hideLoading()
\r\n
this.genericDemoShowMessage = result.showMessage
\r\n
this.notify(result.showMessage, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.callFunctionError = {
\r\n
errCode: error.errCode,
\r\n
errMsg: error.errMsg
\r\n
}
\r\n
uni.hideLoading()
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async callFunction() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
await uniCloud.callFunction({
\r\n
name: 'echo-cf',
\r\n
data: {
\r\n
num: 1,
\r\n
str: 'ABC'
\r\n
}
\r\n
}).then(res => {
\r\n
const result = res.result
\r\n
this.callFunctionResult = result
\r\n
console.log(JSON.stringify(result))
\r\n
uni.hideLoading()
\r\n
this.notify(result['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.callFunctionError = {
\r\n
errCode: error.errCode,
\r\n
errMsg: error.errMsg
\r\n
}
\r\n
uni.hideLoading()
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\n
jest_UniCloudError() {
\n
return new Error() instanceof UniCloudError
\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"importObject"
:{
"name"
:
"## importObject(objectName, options?) @importobject"
,
"description"
:
"引用云对象"
,
"compatibility"
:
"### importObject 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| objectName | string ([string.CloudObjectString](/uts/data-type.md#ide-string)) | 是 | - | - | - |
\n
| options | **UniCloudImportObjectOptions** | 否 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| customUI | boolean | 否 | - | - | 是否移除自动展示的ui |
\n
@| loadingOptions | **UniCloudImportObjectLoadingOptions** | 否 | - | - | loading界面配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| title | string | 否 | - | - | 加载框标题 |
\n
@@| mask | boolean | 否 | - | - | 加载框是否显示mask |
\n
@| errorOptions | **UniCloudImportObjectErrorOptions** | 否 | - | - | 错误提示配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| type | string | 否 | - | - | 错误提示类型,可以是modal或者toast |
\n
@@| retry | boolean | 否 | - | - | 是否显示重试按钮 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudCloudObjectCaller](#unicloudcloudobjectcaller-values) |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| _obj | [InternalUniCloudCloudObject](#internalunicloudcloudobject-values) | 是 | - | - | - |
\n
##### InternalUniCloudCloudObject 的方法 @internalunicloudcloudobject-values
\n\n
##### callMethod
\\
<T = UTSJSONObject>(methodName: string, args: Array
\\
<any
\\
| null>): Promise
\\
<T>; @callmethod
\n\n
###### callMethod 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| methodName | string | 是 | - | - | - |
\n
| args | Array
\\
<any
\\
> | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<T> |
\n
\n\n
#### UniCloudCloudObjectCaller 的方法 @unicloudcloudobjectcaller-values
\n\n
#### protected _getArgs(...args: Array
\\
<any
\\
| null>): Array
\\
<any
\\
| null>; @_getargs
\n\n
##### _getArgs 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| args | Array
\\
<any
\\
> | 否 | - | - | - |
\n\n
##### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Array
\\
<any
\\
> |
\n
\n
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudObject.importObject)"
},
"cloudObject"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/cloud-object.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/cloud-object
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/cloud-object
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
addTodo
\"
>添加Todo</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
addTodoWithGeneric
\"
>
\r\n
添加Todo传入泛型
\r\n
</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
randomFail
\"
>随机触发失败重试</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
fail
\"
>云对象失败调用</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
failWithNumberErrCode
\"
>
\r\n
云对象数字错误码
\r\n
</button>
\r\n
</view>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@tap=
\"
success
\"
>云对象成功调用</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n\r\n
<style></style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: '请求云对象',
\r\n
todoTitle: '学习编程',
\r\n
todoContent: '熟悉uts语法',
\r\n
returnTodoTitle: '',
\r\n
returnTodoContent: '',
\r\n
genericDemoReturnTodoTitle: '',
\r\n
genericDemoReturnTodoContent: '',
\r\n
failErrCode: '',
\r\n
failErrDetailTips: '',
\r\n
failNumberErrCode: 0,
\r\n
successErrCode: -1,
\r\n
isUniTest: false
\r\n
}
\r\n
},
\r\n
methods: {
\r\n
notify(content : string, title : string) {
\r\n
if (!this.isUniTest) {
\r\n
uni.showModal({
\r\n
title,
\r\n
content,
\r\n
showCancel: false
\r\n
})
\r\n
} else {
\r\n
console.log(title, content)
\r\n
}
\r\n
},
\r\n
async addTodo() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
const title = this.todoTitle
\r\n
const content = this.todoContent
\r\n
await todo.add<UTSJSONObject>(title, content).then((res : UTSJSONObject) => {
\r\n
this.returnTodoTitle = res['title'] as string
\r\n
this.returnTodoContent = res['content'] as string
\r\n
this.notify(res['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
console.log(err)
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async addTodoWithGeneric() : Promise<void> {
\r\n
type AddTodoResult = {
\r\n
title : string,
\r\n
content : string,
\r\n
showMessage : string
\r\n
}
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
const title = this.todoTitle
\r\n
const content = this.todoContent
\r\n
await todo.add<AddTodoResult>(title, content).then((res : AddTodoResult) => {
\r\n
this.genericDemoReturnTodoTitle = res.title
\r\n
this.genericDemoReturnTodoContent = res.content
\r\n
this.notify(res.showMessage, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
console.log(err)
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async randomFail() : Promise<void> {
\r\n
const todoObj = uniCloud.importObject('todo', {
\r\n
errorOptions: {
\r\n
retry: true
\r\n
}
\r\n
})
\r\n
await todoObj.randomFail().then((res : UTSJSONObject) => {
\r\n
this.notify(res['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async fail() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
await todo.fail().then((res : UTSJSONObject) => {
\r\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\r\n
console.log('todo.fail: ', res);
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.failErrCode = error.errCode as string
\r\n
const detail = error.detail
\r\n
if (detail != null && detail['tips'] != null) {
\r\n
this.failErrDetailTips = detail['tips'] as string
\r\n
}
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async failWithNumberErrCode() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
await todo.failWithNumberErrCode().then((res : UTSJSONObject) => {
\r\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\r\n
console.log('todo.fail: ', res);
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
this.failNumberErrCode = error.errCode as number
\r\n
console.error(error)
\r\n
})
\r\n
},
\r\n
async success() : Promise<void> {
\r\n
const todo = uniCloud.importObject('todo', {
\r\n
customUI: this.isUniTest
\r\n
})
\r\n
await todo.success().then((res : UTSJSONObject) => {
\r\n
this.successErrCode = res['errCode'] as number
\r\n
this.notify(res['showMessage'] as string, '提示')
\r\n
}).catch((err : any | null) => {
\r\n
const error = err as UniCloudError
\r\n
console.error(error)
\r\n
})
\r\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"uploadFile"
:{
"name"
:
"## uploadFile(options) @uploadfile"
,
"description"
:
"上传文件到云存储"
,
"compatibility"
:
"### uploadFile 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | [UniCloudUploadFileOptions](#uniclouduploadfileoptions-values) | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| filePath | string | 是 | - | - | 文件路径 |
\n
@| cloudPath | string | 是 | - | - | 云端路径 |
\n
@| cloudPathAsRealPath | boolean | 否 | - | - | 是否以云端路径是否为真实路径保存上传的文件 |
\n\n
### UniCloudUploadFileOptions 的方法 @uniclouduploadfileoptions-values
\n\n
### (options: UniCloudUploadProgress) => any @onuploadprogress
\n
上传进度回调
\n
#### onUploadProgress 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
#### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudUploadProgress** | 是 | - | - | 上传进度回调参数 |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| loaded | number | 是 | - | - | 已上传大小 |
\n
@| total | number | 是 | - | - | 总大小 |
\n\n
#### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| filePath | string | 是 | - | - | 文件路径 |
\n
@| fileID | string | 是 | - | - | 文件id |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudStorage.uploadFile)"
},
"getTempFileURL"
:{
"name"
:
"## getTempFileURL(options) @gettempfileurl"
,
"description"
:
"获取文件临时URL"
,
"compatibility"
:
"### getTempFileURL 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudGetTempFileURLOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| fileList | Array
\\
<string
\\
> | 是 | - | - | 文件列表 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudGetTempFileURLResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| fileList | Array
\\
<**UniCloudGetTempFileURLResultItem**
\\
> | 是 | - | - | 文件列表 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| fileID | string | 是 | - | - | 文件id |
\n
@@| tempFileURL | string | 是 | - | - | 文件临时url |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudStorage.chooseAndUploadFile)"
},
"chooseAndUploadFile"
:{
"name"
:
"## chooseAndUploadFile(options) @chooseanduploadfile"
,
"description"
:
"选择并上传文件"
,
"compatibility"
:
"### chooseAndUploadFile 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | [UniCloudChooseAndUploadFileOptions](#unicloudchooseanduploadfileoptions-values) | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| sourceType | Array
\\
<'album'
\\
| 'camera'
\\
> | 否 | - | - | |
\n
@| count | number | 否 | - | - | |
\n
@| sizeType | Array
\\
<'original'
\\
| 'compressed'
\\
> | 否 | - | - | |
\n
@| extension | Array
\\
<string
\\
> | 否 | - | - | |
\n
@| compressed | boolean | 否 | - | - | |
\n
@| maxDuration | number | 否 | - | - | |
\n
@| camera | string | 否 | - | - | - |
\n
@@| 合法值 | 兼容性 | 描述 |
\n
@@| :- | :-: | :- |
\n
@@| front | - | - |
\n
@@| back | - | - |
\n
@| crop | ChooseImageCropOptions | 否 | - | - | |
\n
@| type | string | 是 | - | - | - |
\n
@@| 合法值 | 兼容性 | 描述 |
\n
@@| :- | :-: | :- |
\n
@@| image | - | - |
\n
@@| video | - | - |
\n
@@| all | - | - |
\n\n
### UniCloudChooseAndUploadFileOptions 的方法 @unicloudchooseanduploadfileoptions-values
\n\n
### (arg: UniCloudChooseAndUploadFileResult) => void
\\
| null @onchoosefile
\n\n
#### onChooseFile 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
#### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | **UniCloudChooseAndUploadFileResult** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseAndUploadFileItem**
\\
> | 是 | - | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| name | string | 是 | - | - | - |
\n
@@| path | string | 是 | - | - | - |
\n
@@| cloudPath | string | 是 | - | - | - |
\n
@@| cloudPathAsRealPath | boolean | 否 | - | - | |
\n
@@| url | string | 否 | - | - | |
\n
@@| errMsg | string | 否 | - | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - | - |
\n\n\n
### (arg: UniCloudChooseAndUploadFileProgressEvent) => void
\\
| null @onuploadprogress
\n\n
#### onUploadProgress 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
#### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | **UniCloudChooseAndUploadFileProgressEvent** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| index | number | 是 | - | - | - |
\n
@| loaded | number | 是 | - | - | - |
\n
@| total | number | 是 | - | - | - |
\n
@| tempFilePath | string | 是 | - | - | - |
\n
@| tempFile | [UniCloudChooseAndUploadFileItem](#unicloudchooseanduploadfileitem-values) | 是 | - | - | - |
\n\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudChooseAndUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseAndUploadFileItem**
\\
> | 是 | - | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| name | string | 是 | - | - | - |
\n
@@| path | string | 是 | - | - | - |
\n
@@| cloudPath | string | 是 | - | - | - |
\n
@@| cloudPathAsRealPath | boolean | 否 | - | - | |
\n
@@| url | string | 否 | - | - | |
\n
@@| errMsg | string | 否 | - | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - | - |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.cloudStorage.getTempFileURL)"
},
"cloudStorage"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/cloud-storage.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/cloud-storage
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/cloud-storage
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@click=
\"
uploadFile
\"
>选择文件上传</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
chooseAndUploadFile
\"
>一个接口选择文件并上传</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n
<style>
\r\n
</style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: '云存储'
\r\n
}
\r\n
},
\r\n
onLoad() {
\r\n
},
\r\n
onUnload() {
\r\n
},
\r\n
methods: {
\r\n
uploadFile: function () {
\r\n
uni.chooseImage({
\r\n
count: 1,
\r\n
success(res) : void {
\r\n
uni.showLoading({
\r\n
title: '上传中...'
\r\n
})
\r\n
const tempFilePath = res.tempFilePaths[0]
\r\n
uniCloud.uploadFile({
\r\n
filePath: tempFilePath,
\r\n
cloudPath: 'test.jpg'
\r\n
})
\r\n
.then(function (res) {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
uni.showModal({
\r\n
content: '上传成功',
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
.catch(function (err : any | null) {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
uni.showModal({
\r\n
content: '上传失败,' + error.errMsg,
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
// .finally((_: number) : void => {
\r\n
// uni.hideLoading()
\r\n
// })
\r\n
},
\r\n
fail(err) : void {
\r\n
console.error('chooseImage fail: ', err)
\r\n
}
\r\n
})
\r\n
},
\r\n
chooseAndUploadFile() {
\r\n
uniCloud.chooseAndUploadFile({
\r\n
type: 'image'
\r\n
}).then(function (res) {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
uni.showModal({
\r\n
content: '上传成功',
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
.catch(function (err : any | null) {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
uni.showModal({
\r\n
content: '上传失败,' + error.errMsg,
\r\n
showCancel: false
\r\n
});
\r\n
})
\r\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"databaseForJQL"
:{
"name"
:
"## databaseForJQL() @databaseforjql"
,
"description"
:
"获取数据库操作实例"
,
"compatibility"
:
"### databaseForJQL 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.91,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
""
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [Database](#database-values) |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| command | any | 是 | - | - | - |
\n
@| Geo | any | 是 | - | - | - |
\n
#### Database 的方法 @database-values
\n\n
#### collection(...args: Array
\\
<any>): Collection; @collection
\n\n
##### collection 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| args | Array
\\
<any
\\
> | 否 | - | - | - |
\n\n
##### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [Collection](#collection-values) |
\n\n
###### Collection 的方法 @collection-values
\n\n
###### where(condition: any): UniCloudDBFilter; @where
\n\n
###### where 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| condition | any | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n\n
###### UniCloudDBFilter 的方法 @uniclouddbfilter-values
\n\n
###### get(arg?: UTSJSONObject
\\
| null): Promise
\\
<UniCloudDBGetResult>; @get
\n\n
###### get 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | any | 否 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBGetResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| data | Array
\\
<any
\\
> | 是 | - | - | 添加的记录的id列表 |
\n
@| count | number | 否 | - | - | 匹配到的数据总量 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### count(): Promise
\\
<UniCloudDBCountResult>; @count
\n\n
###### count 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBCountResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| total | number | 是 | - | - | 添加的记录的id列表 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### update(data: UTSJSONObject): Promise
\\
<UniCloudDBUpdateResult>; @update
\n\n
###### update 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| data | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBUpdateResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| updated | number | 是 | - | - | 更新成功的记录数 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### remove(): Promise
\\
<UniCloudDBRemoveResult>; @remove
\n\n
###### remove 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBRemoveResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| deleted | number | 是 | - | - | 删除成功的记录数 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### getTemp(): UTSJSONObject; @gettemp
\n\n
###### getTemp 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n
###### where(condition: any): UniCloudDBFilter; @where
\n\n
###### where 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| condition | any | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### doc(docId: string): UniCloudDBFilter; @doc
\n\n
###### doc 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| docId | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### field(filed: string): UniCloudDBQuery; @field
\n\n
###### field 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| filed | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n\n
###### UniCloudDBQuery 的方法 @uniclouddbquery-values
\n\n
###### get(arg?: UTSJSONObject
\\
| null): Promise
\\
<UniCloudDBGetResult>; @get
\n\n
###### get 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | any | 否 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n
###### count(): Promise
\\
<UniCloudDBCountResult>; @count
\n\n
###### count 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n
###### getTemp(): UTSJSONObject; @gettemp
\n\n
###### getTemp 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n
###### field(filed: string): UniCloudDBQuery; @field
\n\n
###### field 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| filed | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### skip(num: number): UniCloudDBQuery; @skip
\n\n
###### skip 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### limit(num: number): UniCloudDBQuery; @limit
\n\n
###### limit 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### orderBy(order: string): UniCloudDBQuery; @orderby
\n\n
###### orderBy 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| order | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupBy(field: string): UniCloudDBQuery; @groupby
\n\n
###### groupBy 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupField(field: string): UniCloudDBQuery; @groupfield
\n\n
###### groupField 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### distinct(field: string): UniCloudDBQuery; @distinct
\n\n
###### distinct 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### geoNear(options: UTSJSONObject): UniCloudDBQuery; @geonear
\n\n
###### geoNear 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n
\n\n
###### skip(num: number): UniCloudDBQuery; @skip
\n\n
###### skip 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### limit(num: number): UniCloudDBQuery; @limit
\n\n
###### limit 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### orderBy(order: string): UniCloudDBQuery; @orderby
\n\n
###### orderBy 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| order | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupBy(field: string): UniCloudDBQuery; @groupby
\n\n
###### groupBy 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### groupField(field: string): UniCloudDBQuery; @groupfield
\n\n
###### groupField 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### distinct(field: string): UniCloudDBQuery; @distinct
\n\n
###### distinct 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| field | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### geoNear(options: UTSJSONObject): UniCloudDBQuery; @geonear
\n\n
###### geoNear 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n
\n\n
###### doc(docId: string): UniCloudDBFilter; @doc
\n\n
###### doc 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| docId | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### aggregate(): UniCloudDBFilter; @aggregate
\n\n
###### aggregate 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### foreignKey(foreignKey: string): UniCloudDBFilter; @foreignkey
\n\n
###### foreignKey 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| foreignKey | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n
###### add(data: UTSJSONObject): Promise
\\
<UniCloudDBAddResult>; @add
\n\n
###### add 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| data | any | 是 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBAddResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| id | string | 是 | - | - | 添加的记录的id |
\n
@| requestId | string | 否 | - | - | 请求id |
\n\n
###### get(arg?: UTSJSONObject
\\
| null): Promise
\\
<UniCloudDBGetResult>; @get
\n\n
###### get 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| arg | any | 否 | - | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n
###### count(): Promise
\\
<UniCloudDBCountResult>; @count
\n\n
###### count 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n
###### getTemp(): UTSJSONObject; @gettemp
\n\n
###### getTemp 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n
###### field(filed: string): UniCloudDBQuery; @field
\n\n
###### field 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| filed | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### skip(num: number): UniCloudDBQuery; @skip
\n\n
###### skip 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### limit(num: number): UniCloudDBQuery; @limit
\n\n
###### limit 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| num | number | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n
###### orderBy(order: string): UniCloudDBQuery; @orderby
\n\n
###### orderBy 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| - | - | - | - |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| order | string | 是 | - | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n
\n\n
#### multiSend(...args: Array
\\
<UTSJSONObject>): Promise
\\
<UniCloudDBMultiSendResult>; @multisend
\n
合并查询请求
\n
##### multiSend 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 4.16 | 4.11 |
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| args | Array
\\
<any
\\
> | 否 | - | - | - |
\n\n
##### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBMultiSendResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| dataList | Array
\\
<**UniCloudDBMultiSendResultItem**
\\
> | 是 | - | - | 数据列表 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@@| :- | :- | :- | :- | :-: | :- |
\n
@@| errCode | any | 是 | - | - | 错误码,可能为字符串或数字,数字0表示成功 |
\n
@@| errMsg | string | 是 | - | - | 错误信息 |
\n
@@| data | Array
\\
<any
\\
> | 否 | - | - | 数据 |
\n
@| requestId | string | 否 | - | - | 请求id |
\n
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.database.databaseForJQL)"
},
"database"
:{
"example"
:
"## 示例
\n\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha//pages/API/unicloud/unicloud/database.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud/unicloud/database
\n\n
> appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/unicloud/unicloud/database
\n\n
>Template
\n
```vue
\n
<template>
\r\n
<!-- #ifdef APP -->
\r\n
<scroll-view class=
\"
page-scroll-view
\"
>
\r\n
<!-- #endif -->
\r\n
<view>
\r\n
<page-head :title=
\"
title
\"
></page-head>
\r\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\r\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbAdd
\"
>新增单条数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbBatchAdd
\"
>新增多条数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbUpdate
\"
>更新数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbGet
\"
>where传字符串获取数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbGetWithCommand
\"
>where传对象获取数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbRemove
\"
>删除数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbLookupInit
\"
>初始化联表查询数据</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbLookup
\"
>联表查询</button>
\r\n
<button type=
\"
primary
\"
@click=
\"
dbMultiSend
\"
>合并查询查询</button>
\r\n
</view>
\r\n
</view>
\r\n
</view>
\r\n
<!-- #ifdef APP -->
\r\n
</scroll-view>
\r\n
<!-- #endif -->
\r\n
</template>
\r\n\r\n\r\n\r\n
<style>
\r\n
</style>
\n\n
```
\n\n
>Script
\n
```uts
\n\r\n
export default {
\r\n
data() {
\r\n
return {
\r\n
title: 'ClientDB',
\r\n
addId: '',
\r\n
batchAddIds: [] as Array<string>,
\r\n
batchAddinserted: 0,
\r\n
updateUpdated: 0,
\r\n
getData: [] as Array<UTSJSONObject>,
\r\n
getWithCommandData: [] as Array<UTSJSONObject>,
\r\n
removeDeleted: 0,
\r\n
lookupData: [] as Array<UTSJSONObject>,
\r\n
multiSendSuccessCount: 0,
\r\n
isUniTest: false
\r\n
}
\r\n
},
\r\n
computed: {
\r\n
dataTag() : string {
\r\n
return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag'
\r\n
}
\r\n
},
\r\n
methods: {
\r\n
notify(content : string, title : string) {
\r\n
if (!this.isUniTest) {
\r\n
uni.showModal({
\r\n
title,
\r\n
content,
\r\n
showCancel: false
\r\n
})
\r\n
} else {
\r\n
console.log(title, content)
\r\n
}
\r\n
},
\r\n
async dbAdd() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.add({
\r\n
num: 1,
\r\n
tag: this.dataTag,
\r\n
date: new Date()
\r\n
})
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.addId = res.id
\r\n
this.notify(`新增成功,id: ${res.id}`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbBatchAdd() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.add([{
\r\n
num: 2,
\r\n
tag: this.dataTag,
\r\n
}, {
\r\n
num: 3,
\r\n
tag: this.dataTag,
\r\n
}])
\r\n
.then((res) => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
console.log('JSON.stringify(res.inserted)', JSON.stringify(res.inserted))
\r\n
this.batchAddIds = res.ids
\r\n
this.batchAddinserted = res.inserted
\r\n
this.notify(`新增成功条数${res.inserted}, id列表: ${res.ids.join(',')}`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbGet() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where(
\r\n
`tag ==
\"
${this.dataTag}
\"
`
\r\n
)
\r\n
.field('num, tag')
\r\n
.orderBy('num desc')
\r\n
.skip(1)
\r\n
.limit(2)
\r\n
.get()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.getData = res.data
\r\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbGetWithCommand() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where({
\r\n
num: db.command.gt(1),
\r\n
tag: this.dataTag
\r\n
})
\r\n
.field('num, tag')
\r\n
.orderBy('num desc')
\r\n
.skip(1)
\r\n
.limit(2)
\r\n
.get()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.getWithCommandData = res.data
\r\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbUpdate() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where(
\r\n
`tag ==
\"
${this.dataTag}
\"
`
\r\n
)
\r\n
.update({
\r\n
num: 4
\r\n
})
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.updateUpdated = res.updated
\r\n
this.notify(`更新成功,更新了${res.updated}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbRemove() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('type')
\r\n
.where(
\r\n
`tag ==
\"
${this.dataTag}
\"
`
\r\n
)
\r\n
.remove()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.removeDeleted = res.deleted
\r\n
this.notify(`删除成功,删掉了${res.deleted}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbLookupInit() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
await db.collection('local')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.remove()
\r\n
.then(() : Promise<UniCloudDBRemoveResult> => {
\r\n
return db.collection('foreign')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.remove()
\r\n
})
\r\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\r\n
return db.collection('local')
\r\n
.add([{
\r\n
id:
\"
local_1
\"
,
\r\n
name:
\"
local_1_name
\"
,
\r\n
tag: this.dataTag,
\r\n
foreign_id:
\"
foreign_1
\"\r\n
}, {
\r\n
id:
\"
local_2
\"
,
\r\n
name:
\"
local_2_name
\"
,
\r\n
tag: this.dataTag,
\r\n
foreign_id:
\"
foreign_2
\"\r\n
}])
\r\n
})
\r\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\r\n
return db.collection('foreign')
\r\n
.add([{
\r\n
id:
\"
foreign_1
\"
,
\r\n
name:
\"
foreign_1_name
\"
,
\r\n
tag: this.dataTag
\r\n
}, {
\r\n
id:
\"
foreign_2
\"
,
\r\n
name:
\"
foreign_2_name
\"
,
\r\n
tag: this.dataTag
\r\n
}])
\r\n
})
\r\n
.then((_) : void => {
\r\n
uni.hideLoading()
\r\n
this.notify('数据初始化成功', '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
console.error(err)
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbLookup() : Promise<void> {
\r\n
uni.showLoading({
\r\n
title: '加载中...'
\r\n
})
\r\n
const db = uniCloud.databaseForJQL()
\r\n
const local = db.collection('local')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.getTemp()
\r\n
const foreign = db.collection('foreign')
\r\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\r\n
.getTemp()
\r\n
await db.collection(local, foreign)
\r\n
.get()
\r\n
.then(res => {
\r\n
uni.hideLoading()
\r\n
console.log(res)
\r\n
this.lookupData = res.data
\r\n
this.notify(`联表查询成功,取到了${res.data.length}条数据`, '提示')
\r\n
})
\r\n
.catch((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
},
\r\n
async dbMultiSend() : Promise<void> {
\r\n
const db = uniCloud.databaseForJQL()
\r\n
const temp1 = db.collection('type')
\r\n
.where(
\r\n
'tag ==
\"
default-tag
\"
'
\r\n
).getTemp()
\r\n
const temp2 = db.collection('type')
\r\n
.where(
\r\n
'tag ==
\"
default-tag
\"
'
\r\n
).getTemp()
\r\n
await db.multiSend(temp1, temp2)
\r\n
.then<void>(res => {
\r\n
uni.hideLoading()
\r\n
let successCount = 0
\r\n
for (let i = 0; i < res.dataList.length; i++) {
\r\n
const item = res.dataList[i]
\r\n
if (item.errCode == 0) {
\r\n
console.log(`第${i}个请求查询到${item.data!.length}条数据`)
\r\n
successCount++
\r\n
} else {
\r\n
console.error(`第${i}个请求查询失败,错误信息:${item.data!.length}`)
\r\n
}
\r\n
}
\r\n
this.multiSendSuccessCount = successCount
\r\n
this.notify(`合并查询成功,成功查询的语句条数为:${successCount}`, '提示')
\r\n
})
\r\n
.catch<void>((err : any | null) => {
\r\n
uni.hideLoading()
\r\n
const error = err as UniCloudError
\r\n
console.error(err)
\r\n
this.notify(error.errMsg, '错误')
\r\n
})
\r\n
}
\r\n
}
\r\n
}
\r\n\n
```
\n\n
:::"
},
"onResponse"
:{
"name"
:
"## onResponse(callback) @onresponse"
,
"description"
:
"监听响应事件"
,
"compatibility"
:
"### onResponse 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.onResponse)"
},
"offResponse"
:{
"name"
:
"## offResponse(callback) @offresponse"
,
"description"
:
"移除响应事件监听"
,
"compatibility"
:
"### offResponse 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.offResponse)"
},
"onRefreshToken"
:{
"name"
:
"## onRefreshToken(callback) @onrefreshtoken"
,
"description"
:
"监听token刷新事件"
,
"compatibility"
:
"### onRefreshToken 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.onRefreshToken)"
},
"offRefreshToken"
:{
"name"
:
"## offRefreshToken(callback) @offrefreshtoken"
,
"description"
:
"移除token刷新事件监听"
,
"compatibility"
:
"### offRefreshToken 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| callback | (UniCloudResponseEvent: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any | 是 | - | - | - |
\n\n
### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| type | string | 是 | - | - | 响应事件类型 |
\n
| name | string | 是 | - | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.offRefreshToken)"
},
"getCurrentUserInfo"
:{
"name"
:
"## getCurrentUserInfo() @getcurrentuserinfo"
,
"description"
:
"获取token内缓存的用户信息"
,
"compatibility"
:
"### getCurrentUserInfo 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.0 | - | 阿里云 3.9,腾讯云 3.91,支付宝云 3.98 | 4.11 |
\n
"
,
"param"
:
""
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| **UniCloudUserInfo** |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| uid | string | 否 | - | - | 用户id |
\n
@| role | Array
\\
<string
\\
> | 是 | - | - | 用户角色列表 |
\n
@| permission | Array
\\
<string
\\
> | 是 | - | - | 用户权限列表 |
\n
@| tokenExpired | number | 是 | - | - | 用户token过期时间 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.getCurrentUserInfo)"
},
"connectWebSocket"
:{
"name"
:
"## connectWebSocket(options) @connectwebsocket"
,
"description"
:
"连接 WebSocket"
,
"compatibility"
:
"### connectWebSocket 兼容性
\n
| Web | 微信小程序 | Android | iOS |
\n
| :- | :- | :- | :- |
\n
| 4.24 | - | 4.28 | 4.24 |
\n
"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
\n
| :- | :- | :- | :- | :-: | :- |
\n
| options | **UniCloudConnectWebSocketOptions** | 是 | - | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
\n
@| :- | :- | :- | :- | :-: | :- |
\n
@| name | string | 是 | - | - | WebSocket云函数/云对象名称 |
\n
@| query | any | 否 | - | - | 建立连接时需要传递的参数, 仅在 connection 事件中接收到 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| SocketTask |
\n
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
- [相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.utils.connectWebSocket)"
}}
\ No newline at end of file
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录