Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
6c72fbb4
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
156
Star
2
Fork
37
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
13
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
13
合并请求
13
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6c72fbb4
编写于
4月 22, 2024
作者:
G
git_robot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新 utsUnicloudApiJson.json
上级
23646721
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
docs/.vuepress/utils/utsUnicloudApiJson.json
docs/.vuepress/utils/utsUnicloudApiJson.json
+1
-1
未找到文件。
docs/.vuepress/utils/utsUnicloudApiJson.json
浏览文件 @
6c72fbb4
{
"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
| mixinDatacom | any | 是 | - | - |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
""
,
"tutorial"
:
""
},
"callFunction"
:{
"name"
:
"## callFunction(options) @callfunction"
,
"description"
:
"请求云函数"
,
"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**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| result | any | 是 | - | 云函数返回结果 |
\n
@| requestId | string | 否 | - | 云函数请求id |
\n
"
,
"compatibility"
:
"### callFunction 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-call-function.callFunction)
\n
"
},
"unicloud-call-function"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-call-function/unicloud-call-function.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-call-function/unicloud-call-function
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@click=
\"
callFunction
\"
>请求云函数</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n\n
<style>
\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: '请求云函数',
\n
callFunctionResult: {},
\n
callFunctionError: {},
\n
isUniTest: false
\n
}
\n
},
\n
onLoad() {
\n
},
\n
onUnload() {
\n
if (this.isUniTest) {
\n
uni.hideToast()
\n
}
\n
},
\n
methods: {
\n
notify(content : string, title : string) {
\n
if (!this.isUniTest) {
\n
uni.showModal({
\n
title,
\n
content,
\n
showCancel: false
\n
})
\n
} else {
\n
console.log(title, content)
\n
}
\n
},
\n
async callFunction() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
await uniCloud.callFunction({
\n
name: 'echo-cf',
\n
data: {
\n
num: 1,
\n
str: 'ABC'
\n
}
\n
}).then(res => {
\n
const result = res.result
\n
this.callFunctionResult = result
\n
console.log(JSON.stringify(result))
\n
uni.hideLoading()
\n
this.notify(result['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
this.callFunctionError = {
\n
errCode: error.errCode,
\n
errMsg: error.errMsg
\n
}
\n
uni.hideLoading()
\n
this.notify(error.errMsg, '错误')
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n\n
:::"
},
"importObject"
:{
"name"
:
"## importObject(objectName, options?) @importobject"
,
"description"
:
"引用云对象"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| objectName | string ([string.CloudObjectString](/uts/data-type.md#ide-string)) | 是 | - | - |
\n
| options | **UniCloudImportObjectOptions** | 否 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| customUI | boolean
\\
| null | 否 | - | 是否移除自动展示的ui |
\n
@| loadingOptions | **UniCloudImportObjectLoadingOptions**
\\
| null | 否 | - | loading界面配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| title | string
\\
| null | 否 | - | 加载框标题 |
\n
@@| mask | boolean
\\
| null | 否 | - | 加载框是否显示mask |
\n
@| errorOptions | **UniCloudImportObjectErrorOptions**
\\
| null | 否 | - | 错误提示配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| type | string
\\
| null | 否 | - | 错误提示类型,可以是modal或者toast |
\n
@@| retry | boolean
\\
| null | 否 | - | 是否显示重试按钮 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n
"
,
"compatibility"
:
"### importObject 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-import-object.importObject)
\n
"
},
"unicloud-import-object"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-import-object/unicloud-import-object.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-import-object/unicloud-import-object
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
addTodo
\"
>添加Todo</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
randomFail
\"
>随机触发失败重试</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
fail
\"
>云对象失败调用</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
failWithNumberErrCode
\"
>云对象数字错误码</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
success
\"
>云对象成功调用</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n\n
<style>
\n\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: '请求云对象',
\n
todoTitle: '学习编程',
\n
todoContent: '熟悉uts语法',
\n
returnTodoTitle: '',
\n
returnTodoContent: '',
\n
failErrCode: '',
\n
failNumberErrCode: 0,
\n
successErrCode: -1,
\n
isUniTest: false
\n
}
\n
},
\n
methods: {
\n
notify(content : string, title : string) {
\n
if (!this.isUniTest) {
\n
uni.showModal({
\n
title,
\n
content,
\n
showCancel: false
\n
})
\n
} else {
\n
console.log(title, content)
\n
}
\n
},
\n
async addTodo() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
const title = this.todoTitle
\n
const content = this.todoContent
\n
await todo.add(title, content).then((res : UTSJSONObject) => {
\n
this.returnTodoTitle = res['title'] as string
\n
this.returnTodoContent = res['content'] as string
\n
this.notify(res['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
console.error(error)
\n
})
\n
},
\n
async randomFail() : Promise<void> {
\n
const todoObj = uniCloud.importObject('todo', {
\n
errorOptions: {
\n
retry: true
\n
}
\n
})
\n
await todoObj.randomFail().then((res : UTSJSONObject) => {
\n
this.notify(res['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
console.error(error)
\n
})
\n
},
\n
async fail() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
await todo.fail().then((res : UTSJSONObject) => {
\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\n
console.log('todo.fail: ', res);
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
this.failErrCode = error.errCode as string
\n
console.error(error)
\n
})
\n
},
\n
async failWithNumberErrCode() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
await todo.failWithNumberErrCode().then((res : UTSJSONObject) => {
\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\n
console.log('todo.fail: ', res);
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
this.failNumberErrCode = error.errCode as number
\n
console.error(error)
\n
})
\n
},
\n
async success() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
await todo.success().then((res : UTSJSONObject) => {
\n
this.successErrCode = res['errCode'] as number
\n
this.notify(res['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
console.error(error)
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n\n
:::"
},
"uploadFile"
:{
"name"
:
"## uploadFile(options) @uploadfile"
,
"description"
:
"上传文件到云存储"
,
"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
#### onUploadProgress(options) @onuploadprogress
\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\n\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| filePath | string | 是 | - | 文件路径 |
\n
@| fileID | string | 是 | - | 文件id |
\n
"
,
"compatibility"
:
"### uploadFile 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-file-api.upload-file)
\n
"
},
"getTempFileURL"
:{
"name"
:
"## getTempFileURL(options) @gettempfileurl"
,
"description"
:
"获取文件临时URL"
,
"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
"
,
"compatibility"
:
"### getTempFileURL 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-file-api.choose-and-upload-file)
\n
"
},
"chooseAndUploadFile"
:{
"name"
:
"## chooseAndUploadFile(options) @chooseanduploadfile"
,
"description"
:
"选择并上传文件"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| options | [UniCloudChooseAndUploadFileOptions](#unicloudchooseanduploadfileoptions-values) | 是 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| sourceType | Array
\\
<string
\\
>
\\
| null | 否 | - | |
\n
@| count | number
\\
| null | 否 | - | |
\n
@| sizeType | Array
\\
<string
\\
>
\\
| null | 否 | - | |
\n
@| extension | Array
\\
<string
\\
>
\\
| null | 否 | - | |
\n
@| compressed | boolean
\\
| null | 否 | - | |
\n
@| maxDuration | number
\\
| null | 否 | - | |
\n
@| camera | string
\\
| null | 否 | - | |
\n
@| crop | ChooseImageCropOptions
\\
| null | 否 | - | |
\n
@| type | string | 是 | - | - |
\n\n
#### UniCloudChooseAndUploadFileOptions 的方法 @unicloudchooseanduploadfileoptions-values
\n\n
#### onChooseFile(arg) @onchoosefile
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | **UniCloudChooseFileResult** | 是 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseFileItem**
\\
> | 是 | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| name | string | 是 | - | - |
\n
@@| path | string | 是 | - | - |
\n
@@| cloudPath | string | 是 | - | - |
\n
@@| cloudPathAsRealPath | boolean
\\
| null | 否 | - | |
\n
@@| url | string
\\
| null | 否 | - | |
\n
@@| errMsg | string
\\
| null | 否 | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - |
\n\n
##### 返回值
\n\n
| 类型 | 必备 |
\n
| :- | :- |
\n
| void
\\
| null | 否 |
\n
\n\n\n\n
#### onUploadProgress(arg) @onuploadprogress
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | **UniCloudChooseAndUploadFileProgressEvent** | 是 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| index | number | 是 | - | - |
\n
@| loaded | number | 是 | - | - |
\n
@| total | number | 是 | - | - |
\n
@| tempFilePath | string | 是 | - | - |
\n
@| tempFile | [UniCloudChooseFileItem](#unicloudchoosefileitem-values) | 是 | - | - |
\n\n
##### 返回值
\n\n
| 类型 | 必备 |
\n
| :- | :- |
\n
| void
\\
| null | 否 |
\n
\n\n\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudChooseAndUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseFileItem**
\\
> | 是 | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| name | string | 是 | - | - |
\n
@@| path | string | 是 | - | - |
\n
@@| cloudPath | string | 是 | - | - |
\n
@@| cloudPathAsRealPath | boolean
\\
| null | 否 | - | |
\n
@@| url | string
\\
| null | 否 | - | |
\n
@@| errMsg | string
\\
| null | 否 | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - |
\n
"
,
"compatibility"
:
"### chooseAndUploadFile 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-file-api.getTempFileURL)
\n
"
},
"unicloud-file-api"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-file-api/unicloud-file-api.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-file-api/unicloud-file-api
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@click=
\"
uploadFile
\"
>选择文件上传</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n
<style>
\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: '云存储'
\n
}
\n
},
\n
onLoad() {
\n
},
\n
onUnload() {
\n
},
\n
methods: {
\n
uploadFile: function () {
\n
uni.chooseImage({
\n
count: 1,
\n
success(res) : void {
\n
uni.showLoading({
\n
title: '上传中...'
\n
})
\n
const tempFilePath = res.tempFilePaths[0]
\n
uniCloud.uploadFile({
\n
filePath: tempFilePath,
\n
cloudPath: 'test.jpg'
\n
})
\n
.then(function (res) {
\n
uni.hideLoading()
\n
console.log(res)
\n
uni.showModal({
\n
content: '上传成功',
\n
showCancel: false
\n
});
\n
})
\n
.catch(function (err : any | null) {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
uni.showModal({
\n
content: '上传失败,' + error.errMsg,
\n
showCancel: false
\n
});
\n
})
\n
// .finally((_: number) : void => {
\n
// uni.hideLoading()
\n
// })
\n
},
\n
fail(err) : void {
\n
console.error('chooseImage fail: ', err)
\n
}
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n\n
:::"
},
"databaseForJQL"
:{
"name"
:
"## databaseForJQL() @databaseforjql"
,
"description"
:
"获取数据库操作实例"
,
"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?) @collection
\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) @where
\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?) @get
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | any
\\
| null | 否 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBGetResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| data | Array
\\
<any
\\
> | 是 | - | etResult = { /** |
\n
@| count | number
\\
| null | 否 | - | JSONObject>;<br/> /** |
\n
@| requestId | string | 否 | - | ber
\\
| null; / |
\n\n\n\n
##### count() @count
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBCountResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| total | number | 是 | - | ntResult = { /** |
\n
@| requestId | string | 否 | - | al: number; / |
\n\n\n\n
##### update(data) @update
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| data | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBUpdateResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| updated | number | 是 | - | teResult = { /** |
\n
@| requestId | string | 否 | - | ted: number; / |
\n\n\n\n
##### remove() @remove
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBRemoveResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| deleted | number | 是 | - | veResult = { /** |
\n
@| requestId | string | 否 | - | ted: number; / |
\n\n\n\n
##### getTemp() @gettemp
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n\n\n
##### where(condition) @where
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| condition | any | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### doc(docId) @doc
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| docId | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### field(filed) @field
\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?) @get
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | any
\\
| null | 否 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n\n\n
##### count() @count
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n\n\n
##### getTemp() @gettemp
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n\n\n
##### field(filed) @field
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| filed | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### skip(num) @skip
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### limit(num) @limit
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### orderBy(order) @orderby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| order | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupBy(field) @groupby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupField(field) @groupfield
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### distinct(field) @distinct
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### geoNear(options) @geonear
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| options | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n
\n\n\n\n
##### skip(num) @skip
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### limit(num) @limit
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### orderBy(order) @orderby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| order | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupBy(field) @groupby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupField(field) @groupfield
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### distinct(field) @distinct
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### geoNear(options) @geonear
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| options | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n
\n\n\n\n
##### doc(docId) @doc
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| docId | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### aggregate() @aggregate
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### foreignKey(foreignKey) @foreignkey
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| foreignKey | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### add(data) @add
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| data | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBAddResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| id | string | 是 | - | ddResult = { /** |
\n
@| requestId | string | 否 | - | string; / |
\n\n\n\n
##### get(arg?) @get
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | any
\\
| null | 否 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n\n\n
##### count() @count
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n\n\n
##### getTemp() @gettemp
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n\n\n
##### field(filed) @field
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| filed | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### skip(num) @skip
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### limit(num) @limit
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### orderBy(order) @orderby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| order | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n
\n\n\n
\n
"
,
"compatibility"
:
"### databaseForJQL 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.91,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-database.databaseForJQL)
\n
"
},
"unicloud-database"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-database/unicloud-database.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-database/unicloud-database
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@click=
\"
dbAdd
\"
>新增单条数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbBatchAdd
\"
>新增多条数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbUpdate
\"
>更新数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbGet
\"
>where传字符串获取数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbGetWithCommand
\"
>where传对象获取数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbRemove
\"
>删除数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbLookupInit
\"
>初始化联表查询数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbLookup
\"
>联表查询</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n\n
<style>
\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: 'ClientDB',
\n
addId: '',
\n
batchAddIds: [] as Array<string>,
\n
batchAddinserted: 0,
\n
updateUpdated: 0,
\n
getData: [] as Array<UTSJSONObject>,
\n
getWithCommandData: [] as Array<UTSJSONObject>,
\n
removeDeleted: 0,
\n
lookupData: [] as Array<UTSJSONObject>,
\n
isUniTest: false
\n
}
\n
},
\n
computed: {
\n
dataTag() : string {
\n
return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag'
\n
}
\n
},
\n
methods: {
\n
notify(content : string, title : string) {
\n
if (!this.isUniTest) {
\n
uni.showModal({
\n
title,
\n
content,
\n
showCancel: false
\n
})
\n
} else {
\n
console.log(title, content)
\n
}
\n
},
\n
async dbAdd() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.add({
\n
num: 1,
\n
tag: this.dataTag,
\n
date: new Date()
\n
})
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.addId = res.id
\n
this.notify(`新增成功,id: ${res.id}`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbBatchAdd() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.add([{
\n
num: 2,
\n
tag: this.dataTag,
\n
}, {
\n
num: 3,
\n
tag: this.dataTag,
\n
}])
\n
.then((res) => {
\n
uni.hideLoading()
\n
console.log(res)
\n
console.log('JSON.stringify(res.inserted)', JSON.stringify(res.inserted))
\n
this.batchAddIds = res.ids
\n
this.batchAddinserted = res.inserted
\n
this.notify(`新增成功条数${res.inserted}, id列表: ${res.ids.join(',')}`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbGet() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where(
\n
`tag ==
\"
${this.dataTag}
\"
`
\n
)
\n
.field('num, tag')
\n
.orderBy('num desc')
\n
.skip(1)
\n
.limit(2)
\n
.get()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.getData = res.data
\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbGetWithCommand() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where({
\n
num: db.command.gt(1),
\n
tag: this.dataTag
\n
})
\n
.field('num, tag')
\n
.orderBy('num desc')
\n
.skip(1)
\n
.limit(2)
\n
.get()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.getWithCommandData = res.data
\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbUpdate() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where(
\n
`tag ==
\"
${this.dataTag}
\"
`
\n
)
\n
.update({
\n
num: 4
\n
})
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.updateUpdated = res.updated
\n
this.notify(`更新成功,更新了${res.updated}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbRemove() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where(
\n
`tag ==
\"
${this.dataTag}
\"
`
\n
)
\n
.remove()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.removeDeleted = res.deleted
\n
this.notify(`删除成功,删掉了${res.deleted}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbLookupInit() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('local')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.remove()
\n
.then(() : Promise<UniCloudDBRemoveResult> => {
\n
return db.collection('foreign')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.remove()
\n
})
\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\n
return db.collection('local')
\n
.add([{
\n
id:
\"
local_1
\"
,
\n
name:
\"
local_1_name
\"
,
\n
tag: this.dataTag,
\n
foreign_id:
\"
foreign_1
\"\n
}, {
\n
id:
\"
local_2
\"
,
\n
name:
\"
local_2_name
\"
,
\n
tag: this.dataTag,
\n
foreign_id:
\"
foreign_2
\"\n
}])
\n
})
\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\n
return db.collection('foreign')
\n
.add([{
\n
id:
\"
foreign_1
\"
,
\n
name:
\"
foreign_1_name
\"
,
\n
tag: this.dataTag
\n
}, {
\n
id:
\"
foreign_2
\"
,
\n
name:
\"
foreign_2_name
\"
,
\n
tag: this.dataTag
\n
}])
\n
})
\n
.then((_) : void => {
\n
uni.hideLoading()
\n
this.notify('数据初始化成功', '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
console.error(err)
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbLookup() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
const local = db.collection('local')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.getTemp()
\n
const foreign = db.collection('foreign')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.getTemp()
\n
await db.collection(local, foreign)
\n
.get()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.lookupData = res.data
\n
this.notify(`联表查询成功,取到了${res.data.length}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n\n
:::"
},
"onResponse"
:{
"name"
:
"## onResponse(callback) @onresponse"
,
"description"
:
"监听响应事件"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### onResponse 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.get-current-user-info)
\n
"
},
"offResponse"
:{
"name"
:
"## offResponse(callback) @offresponse"
,
"description"
:
"移除响应事件监听"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### offResponse 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.on-response)
\n
"
},
"onRefreshToken"
:{
"name"
:
"## onRefreshToken(callback) @onrefreshtoken"
,
"description"
:
"监听token刷新事件"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### onRefreshToken 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.off-response)
\n
"
},
"offRefreshToken"
:{
"name"
:
"## offRefreshToken(callback) @offrefreshtoken"
,
"description"
:
"移除token刷新事件监听"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### offRefreshToken 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.on-refresh-token)
\n
"
},
"getCurrentUserInfo"
:{
"name"
:
"## getCurrentUserInfo() @getcurrentuserinfo"
,
"description"
:
"获取token内缓存的用户信息"
,
"param"
:
""
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| **UniCloudUserInfo** |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| uid | string
\\
| null | 否 | - | UserInfo = {<br/> / |
\n
@| role | Array
\\
<string
\\
> | 是 | - | ing
\\
| null; / |
\n
@| permission | Array
\\
<string
\\
> | 是 | - | ay
\\
<string>; / |
\n
@| tokenExpired | number | 是 | - | ay
\\
<string>; /** |
\n
"
,
"compatibility"
:
"### getCurrentUserInfo 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.off-refresh-token)
\n
"
}}
\ No newline at end of file
{
"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
| mixinDatacom | any | 是 | - | - |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
""
,
"tutorial"
:
""
},
"callFunction"
:{
"name"
:
"## callFunction(options) @callfunction"
,
"description"
:
"请求云函数"
,
"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
"
,
"compatibility"
:
"### callFunction 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-call-function.callFunction)
\n
"
},
"unicloud-call-function"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-call-function/unicloud-call-function.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-call-function/unicloud-call-function
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@click=
\"
callFunction
\"
>请求云函数</button>
\n
<button type=
\"
primary
\"
@click=
\"
callFunctionWithGeneric
\"
>请求云函数传入泛型</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n\n
<style>
\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: '请求云函数',
\n
callFunctionResult: {},
\n
callFunctionError: {},
\n
genericDemoShowMessage: '',
\n
isUniTest: false
\n
}
\n
},
\n
onLoad() {
\n
},
\n
onUnload() {
\n
if (this.isUniTest) {
\n
uni.hideToast()
\n
}
\n
},
\n
methods: {
\n
notify(content : string, title : string) {
\n
if (!this.isUniTest) {
\n
uni.showModal({
\n
title,
\n
content,
\n
showCancel: false
\n
})
\n
} else {
\n
console.log(title, content)
\n
}
\n
},
\n
async callFunctionWithGeneric() : Promise<void> {
\n
type EchoCfResult = {
\n
showMessage: string
\n
}
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
await uniCloud.callFunction<EchoCfResult>({
\n
name: 'echo-cf',
\n
data: {
\n
num: 1,
\n
str: 'ABC'
\n
}
\n
}).then(res => {
\n
const result = res.result
\n
uni.hideLoading()
\n
this.genericDemoShowMessage = result.showMessage
\n
this.notify(result.showMessage, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
this.callFunctionError = {
\n
errCode: error.errCode,
\n
errMsg: error.errMsg
\n
}
\n
uni.hideLoading()
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async callFunction() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
await uniCloud.callFunction({
\n
name: 'echo-cf',
\n
data: {
\n
num: 1,
\n
str: 'ABC'
\n
}
\n
}).then(res => {
\n
const result = res.result
\n
this.callFunctionResult = result
\n
console.log(JSON.stringify(result))
\n
uni.hideLoading()
\n
this.notify(result['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
this.callFunctionError = {
\n
errCode: error.errCode,
\n
errMsg: error.errMsg
\n
}
\n
uni.hideLoading()
\n
this.notify(error.errMsg, '错误')
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n
:::"
},
"importObject"
:{
"name"
:
"## importObject(objectName, options?) @importobject"
,
"description"
:
"引用云对象"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| objectName | string ([string.CloudObjectString](/uts/data-type.md#ide-string)) | 是 | - | - |
\n
| options | **UniCloudImportObjectOptions** | 否 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| customUI | boolean
\\
| null | 否 | - | 是否移除自动展示的ui |
\n
@| loadingOptions | **UniCloudImportObjectLoadingOptions**
\\
| null | 否 | - | loading界面配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| title | string
\\
| null | 否 | - | 加载框标题 |
\n
@@| mask | boolean
\\
| null | 否 | - | 加载框是否显示mask |
\n
@| errorOptions | **UniCloudImportObjectErrorOptions**
\\
| null | 否 | - | 错误提示配置 |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| type | string
\\
| null | 否 | - | 错误提示类型,可以是modal或者toast |
\n
@@| retry | boolean
\\
| null | 否 | - | 是否显示重试按钮 |
\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudCloudObjectCaller](#unicloudcloudobjectcaller-values) |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| _obj | [InternalUniCloudCloudObject](#internalunicloudcloudobject-values) | 是 | - | - |
\n
##### InternalUniCloudCloudObject 的方法 @internalunicloudcloudobject-values
\n\n
##### callMethod(methodName, args) @callmethod
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| methodName | string | 是 | - | - |
\n
| args | Array
\\
<any
\\
| null
\\
> | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<T> |
\n
\n\n\n\n
#### UniCloudCloudObjectCaller 的方法 @unicloudcloudobjectcaller-values
\n\n
#### _getArgs(args?) @_getargs
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| args | Array
\\
<any
\\
| null
\\
> | 否 | - | - |
\n\n
##### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Array
\\
<any
\\
| null
\\
> |
\n
\n\n\n
\n
"
,
"compatibility"
:
"### importObject 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-import-object.importObject)
\n
"
},
"unicloud-import-object"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-import-object/unicloud-import-object.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-import-object/unicloud-import-object
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
addTodo
\"
>添加Todo</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
addTodoWithGeneric
\"
>添加Todo传入泛型</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
randomFail
\"
>随机触发失败重试</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
fail
\"
>云对象失败调用</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
failWithNumberErrCode
\"
>云对象数字错误码</button>
\n
</view>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@tap=
\"
success
\"
>云对象成功调用</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n\n
<style>
\n\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: '请求云对象',
\n
todoTitle: '学习编程',
\n
todoContent: '熟悉uts语法',
\n
returnTodoTitle: '',
\n
returnTodoContent: '',
\n
genericDemoReturnTodoTitle: '',
\n
genericDemoReturnTodoContent: '',
\n
failErrCode: '',
\n
failNumberErrCode: 0,
\n
successErrCode: -1,
\n
isUniTest: false
\n
}
\n
},
\n
methods: {
\n
notify(content : string, title : string) {
\n
if (!this.isUniTest) {
\n
uni.showModal({
\n
title,
\n
content,
\n
showCancel: false
\n
})
\n
} else {
\n
console.log(title, content)
\n
}
\n
},
\n
async addTodo() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
const title = this.todoTitle
\n
const content = this.todoContent
\n
await todo.add<UTSJSONObject>(title, content).then((res : UTSJSONObject) => {
\n
this.returnTodoTitle = res['title'] as string
\n
this.returnTodoContent = res['content'] as string
\n
this.notify(res['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
console.log(err)
\n
const error = err as UniCloudError
\n
console.error(error)
\n
})
\n
},
\n
async addTodoWithGeneric() : Promise<void> {
\n
type AddTodoResult = {
\n
title: string,
\n
content: string,
\n
showMessage: string
\n
}
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
const title = this.todoTitle
\n
const content = this.todoContent
\n
await todo.add<AddTodoResult>(title, content).then((res : AddTodoResult) => {
\n
this.genericDemoReturnTodoTitle = res.title
\n
this.genericDemoReturnTodoContent = res.content
\n
this.notify(res.showMessage, '提示')
\n
}).catch((err : any | null) => {
\n
console.log(err)
\n
const error = err as UniCloudError
\n
console.error(error)
\n
})
\n
},
\n
async randomFail() : Promise<void> {
\n
const todoObj = uniCloud.importObject('todo', {
\n
errorOptions: {
\n
retry: true
\n
}
\n
})
\n
await todoObj.randomFail().then((res : UTSJSONObject) => {
\n
this.notify(res['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
console.error(error)
\n
})
\n
},
\n
async fail() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
await todo.fail().then((res : UTSJSONObject) => {
\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\n
console.log('todo.fail: ', res);
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
this.failErrCode = error.errCode as string
\n
console.error(error)
\n
})
\n
},
\n
async failWithNumberErrCode() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
await todo.failWithNumberErrCode().then((res : UTSJSONObject) => {
\n
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
\n
console.log('todo.fail: ', res);
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
this.failNumberErrCode = error.errCode as number
\n
console.error(error)
\n
})
\n
},
\n
async success() : Promise<void> {
\n
const todo = uniCloud.importObject('todo', {
\n
customUI: this.isUniTest
\n
})
\n
await todo.success().then((res : UTSJSONObject) => {
\n
this.successErrCode = res['errCode'] as number
\n
this.notify(res['showMessage'] as string, '提示')
\n
}).catch((err : any | null) => {
\n
const error = err as UniCloudError
\n
console.error(error)
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n
:::"
},
"uploadFile"
:{
"name"
:
"## uploadFile(options) @uploadfile"
,
"description"
:
"上传文件到云存储"
,
"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
#### onUploadProgress(options) @onuploadprogress
\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\n\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| filePath | string | 是 | - | 文件路径 |
\n
@| fileID | string | 是 | - | 文件id |
\n
"
,
"compatibility"
:
"### uploadFile 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-file-api.upload-file)
\n
"
},
"getTempFileURL"
:{
"name"
:
"## getTempFileURL(options) @gettempfileurl"
,
"description"
:
"获取文件临时URL"
,
"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
"
,
"compatibility"
:
"### getTempFileURL 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-file-api.choose-and-upload-file)
\n
"
},
"chooseAndUploadFile"
:{
"name"
:
"## chooseAndUploadFile(options) @chooseanduploadfile"
,
"description"
:
"选择并上传文件"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| options | [UniCloudChooseAndUploadFileOptions](#unicloudchooseanduploadfileoptions-values) | 是 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| sourceType | Array
\\
<string
\\
>
\\
| null | 否 | - | |
\n
@| count | number
\\
| null | 否 | - | |
\n
@| sizeType | Array
\\
<string
\\
>
\\
| null | 否 | - | |
\n
@| extension | Array
\\
<string
\\
>
\\
| null | 否 | - | |
\n
@| compressed | boolean
\\
| null | 否 | - | |
\n
@| maxDuration | number
\\
| null | 否 | - | |
\n
@| camera | string
\\
| null | 否 | - | |
\n
@| crop | ChooseImageCropOptions
\\
| null | 否 | - | |
\n
@| type | string | 是 | - | - |
\n\n
#### UniCloudChooseAndUploadFileOptions 的方法 @unicloudchooseanduploadfileoptions-values
\n\n
#### onChooseFile(arg) @onchoosefile
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | **UniCloudChooseFileResult** | 是 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseFileItem**
\\
> | 是 | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| name | string | 是 | - | - |
\n
@@| path | string | 是 | - | - |
\n
@@| cloudPath | string | 是 | - | - |
\n
@@| cloudPathAsRealPath | boolean
\\
| null | 否 | - | |
\n
@@| url | string
\\
| null | 否 | - | |
\n
@@| errMsg | string
\\
| null | 否 | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - |
\n\n
##### 返回值
\n\n
| 类型 | 必备 |
\n
| :- | :- |
\n
| void
\\
| null | 否 |
\n
\n\n\n\n
#### onUploadProgress(arg) @onuploadprogress
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | **UniCloudChooseAndUploadFileProgressEvent** | 是 | - | - |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| index | number | 是 | - | - |
\n
@| loaded | number | 是 | - | - |
\n
@| total | number | 是 | - | - |
\n
@| tempFilePath | string | 是 | - | - |
\n
@| tempFile | [UniCloudChooseFileItem](#unicloudchoosefileitem-values) | 是 | - | - |
\n\n
##### 返回值
\n\n
| 类型 | 必备 |
\n
| :- | :- |
\n
| void
\\
| null | 否 |
\n
\n\n\n
"
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudChooseAndUploadFileResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| tempFiles | Array
\\
<**UniCloudChooseFileItem**
\\
> | 是 | - | - |
\n
@@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@@| :- | :- | :- | :- | :- |
\n
@@| name | string | 是 | - | - |
\n
@@| path | string | 是 | - | - |
\n
@@| cloudPath | string | 是 | - | - |
\n
@@| cloudPathAsRealPath | boolean
\\
| null | 否 | - | |
\n
@@| url | string
\\
| null | 否 | - | |
\n
@@| errMsg | string
\\
| null | 否 | - | |
\n
@| tempFilePaths | Array
\\
<string
\\
> | 是 | - | - |
\n
"
,
"compatibility"
:
"### chooseAndUploadFile 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-file-api.getTempFileURL)
\n
"
},
"unicloud-file-api"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-file-api/unicloud-file-api.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-file-api/unicloud-file-api
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@click=
\"
uploadFile
\"
>选择文件上传</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n
<style>
\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: '云存储'
\n
}
\n
},
\n
onLoad() {
\n
},
\n
onUnload() {
\n
},
\n
methods: {
\n
uploadFile: function () {
\n
uni.chooseImage({
\n
count: 1,
\n
success(res) : void {
\n
uni.showLoading({
\n
title: '上传中...'
\n
})
\n
const tempFilePath = res.tempFilePaths[0]
\n
uniCloud.uploadFile({
\n
filePath: tempFilePath,
\n
cloudPath: 'test.jpg'
\n
})
\n
.then(function (res) {
\n
uni.hideLoading()
\n
console.log(res)
\n
uni.showModal({
\n
content: '上传成功',
\n
showCancel: false
\n
});
\n
})
\n
.catch(function (err : any | null) {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
uni.showModal({
\n
content: '上传失败,' + error.errMsg,
\n
showCancel: false
\n
});
\n
})
\n
// .finally((_: number) : void => {
\n
// uni.hideLoading()
\n
// })
\n
},
\n
fail(err) : void {
\n
console.error('chooseImage fail: ', err)
\n
}
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n
:::"
},
"databaseForJQL"
:{
"name"
:
"## databaseForJQL() @databaseforjql"
,
"description"
:
"获取数据库操作实例"
,
"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?) @collection
\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) @where
\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?) @get
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | any
\\
| null | 否 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBGetResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| data | Array
\\
<any
\\
> | 是 | - | etResult = { /** |
\n
@| count | number
\\
| null | 否 | - | JSONObject>;<br/> /** |
\n
@| requestId | string | 否 | - | ber
\\
| null; / |
\n\n\n\n
##### count() @count
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBCountResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| total | number | 是 | - | ntResult = { /** |
\n
@| requestId | string | 否 | - | al: number; / |
\n\n\n\n
##### update(data) @update
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| data | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBUpdateResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| updated | number | 是 | - | teResult = { /** |
\n
@| requestId | string | 否 | - | ted: number; / |
\n\n\n\n
##### remove() @remove
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBRemoveResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| deleted | number | 是 | - | veResult = { /** |
\n
@| requestId | string | 否 | - | ted: number; / |
\n\n\n\n
##### getTemp() @gettemp
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n\n\n
##### where(condition) @where
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| condition | any | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### doc(docId) @doc
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| docId | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### field(filed) @field
\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?) @get
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | any
\\
| null | 否 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n\n\n
##### count() @count
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n\n\n
##### getTemp() @gettemp
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n\n\n
##### field(filed) @field
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| filed | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### skip(num) @skip
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### limit(num) @limit
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### orderBy(order) @orderby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| order | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupBy(field) @groupby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupField(field) @groupfield
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### distinct(field) @distinct
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### geoNear(options) @geonear
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| options | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n
\n\n\n\n
##### skip(num) @skip
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### limit(num) @limit
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### orderBy(order) @orderby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| order | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupBy(field) @groupby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### groupField(field) @groupfield
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### distinct(field) @distinct
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| field | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### geoNear(options) @geonear
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| options | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n
\n\n\n\n
##### doc(docId) @doc
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| docId | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### aggregate() @aggregate
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### foreignKey(foreignKey) @foreignkey
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| foreignKey | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBFilter](#uniclouddbfilter-values) |
\n
\n\n\n\n
##### add(data) @add
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| data | any | 是 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<**UniCloudDBAddResult**> |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| id | string | 是 | - | ddResult = { /** |
\n
@| requestId | string | 否 | - | string; / |
\n\n\n\n
##### get(arg?) @get
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| arg | any
\\
| null | 否 | - | |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBGetResult](#uniclouddbgetresult-values)> |
\n
\n\n\n\n
##### count() @count
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| Promise
\\
<[UniCloudDBCountResult](#uniclouddbcountresult-values)> |
\n
\n\n\n\n
##### getTemp() @gettemp
\n\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| any |
\n
\n\n\n\n
##### field(filed) @field
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| filed | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### skip(num) @skip
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### limit(num) @limit
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| num | number | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n\n
##### orderBy(order) @orderby
\n\n
##### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| order | string | 是 | - | - |
\n\n
###### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| [UniCloudDBQuery](#uniclouddbquery-values) |
\n
\n\n\n
\n\n\n
\n
"
,
"compatibility"
:
"### databaseForJQL 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.91,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-database.databaseForJQL)
\n
"
},
"unicloud-database"
:{
"example"
:
"## 示例
\n
> [hello uni-app x](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/pages/API/unicloud-database/unicloud-database.uvue)
\n
::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/unicloud-database/unicloud-database
\n
>Template
\n
```vue
\n
<template>
\n
<!-- #ifdef APP -->
\n
<scroll-view class=
\"
page-scroll-view
\"
>
\n
<!-- #endif -->
\n
<view>
\n
<page-head :title=
\"
title
\"
></page-head>
\n
<view class=
\"
uni-padding-wrap uni-common-mt
\"
>
\n
<view class=
\"
uni-btn-v uni-common-mt
\"
>
\n
<button type=
\"
primary
\"
@click=
\"
dbAdd
\"
>新增单条数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbBatchAdd
\"
>新增多条数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbUpdate
\"
>更新数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbGet
\"
>where传字符串获取数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbGetWithCommand
\"
>where传对象获取数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbRemove
\"
>删除数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbLookupInit
\"
>初始化联表查询数据</button>
\n
<button type=
\"
primary
\"
@click=
\"
dbLookup
\"
>联表查询</button>
\n
</view>
\n
</view>
\n
</view>
\n
<!-- #ifdef APP -->
\n
</scroll-view>
\n
<!-- #endif -->
\n
</template>
\n\n\n\n
<style>
\n
</style>
\n\n
```
\n
>Script
\n
```uts
\n\n
export default {
\n
data() {
\n
return {
\n
title: 'ClientDB',
\n
addId: '',
\n
batchAddIds: [] as Array<string>,
\n
batchAddinserted: 0,
\n
updateUpdated: 0,
\n
getData: [] as Array<UTSJSONObject>,
\n
getWithCommandData: [] as Array<UTSJSONObject>,
\n
removeDeleted: 0,
\n
lookupData: [] as Array<UTSJSONObject>,
\n
isUniTest: false
\n
}
\n
},
\n
computed: {
\n
dataTag() : string {
\n
return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag'
\n
}
\n
},
\n
methods: {
\n
notify(content : string, title : string) {
\n
if (!this.isUniTest) {
\n
uni.showModal({
\n
title,
\n
content,
\n
showCancel: false
\n
})
\n
} else {
\n
console.log(title, content)
\n
}
\n
},
\n
async dbAdd() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.add({
\n
num: 1,
\n
tag: this.dataTag,
\n
date: new Date()
\n
})
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.addId = res.id
\n
this.notify(`新增成功,id: ${res.id}`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbBatchAdd() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.add([{
\n
num: 2,
\n
tag: this.dataTag,
\n
}, {
\n
num: 3,
\n
tag: this.dataTag,
\n
}])
\n
.then((res) => {
\n
uni.hideLoading()
\n
console.log(res)
\n
console.log('JSON.stringify(res.inserted)', JSON.stringify(res.inserted))
\n
this.batchAddIds = res.ids
\n
this.batchAddinserted = res.inserted
\n
this.notify(`新增成功条数${res.inserted}, id列表: ${res.ids.join(',')}`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbGet() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where(
\n
`tag ==
\"
${this.dataTag}
\"
`
\n
)
\n
.field('num, tag')
\n
.orderBy('num desc')
\n
.skip(1)
\n
.limit(2)
\n
.get()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.getData = res.data
\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbGetWithCommand() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where({
\n
num: db.command.gt(1),
\n
tag: this.dataTag
\n
})
\n
.field('num, tag')
\n
.orderBy('num desc')
\n
.skip(1)
\n
.limit(2)
\n
.get()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.getWithCommandData = res.data
\n
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbUpdate() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where(
\n
`tag ==
\"
${this.dataTag}
\"
`
\n
)
\n
.update({
\n
num: 4
\n
})
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.updateUpdated = res.updated
\n
this.notify(`更新成功,更新了${res.updated}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbRemove() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('type')
\n
.where(
\n
`tag ==
\"
${this.dataTag}
\"
`
\n
)
\n
.remove()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.removeDeleted = res.deleted
\n
this.notify(`删除成功,删掉了${res.deleted}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbLookupInit() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
await db.collection('local')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.remove()
\n
.then(() : Promise<UniCloudDBRemoveResult> => {
\n
return db.collection('foreign')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.remove()
\n
})
\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\n
return db.collection('local')
\n
.add([{
\n
id:
\"
local_1
\"
,
\n
name:
\"
local_1_name
\"
,
\n
tag: this.dataTag,
\n
foreign_id:
\"
foreign_1
\"\n
}, {
\n
id:
\"
local_2
\"
,
\n
name:
\"
local_2_name
\"
,
\n
tag: this.dataTag,
\n
foreign_id:
\"
foreign_2
\"\n
}])
\n
})
\n
.then(() : Promise<UniCloudDBBatchAddResult> => {
\n
return db.collection('foreign')
\n
.add([{
\n
id:
\"
foreign_1
\"
,
\n
name:
\"
foreign_1_name
\"
,
\n
tag: this.dataTag
\n
}, {
\n
id:
\"
foreign_2
\"
,
\n
name:
\"
foreign_2_name
\"
,
\n
tag: this.dataTag
\n
}])
\n
})
\n
.then((_) : void => {
\n
uni.hideLoading()
\n
this.notify('数据初始化成功', '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
console.error(err)
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
},
\n
async dbLookup() : Promise<void> {
\n
uni.showLoading({
\n
title: '加载中...'
\n
})
\n
const db = uniCloud.databaseForJQL()
\n
const local = db.collection('local')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.getTemp()
\n
const foreign = db.collection('foreign')
\n
.where(`tag ==
\"
${this.dataTag}
\"
`)
\n
.getTemp()
\n
await db.collection(local, foreign)
\n
.get()
\n
.then(res => {
\n
uni.hideLoading()
\n
console.log(res)
\n
this.lookupData = res.data
\n
this.notify(`联表查询成功,取到了${res.data.length}条数据`, '提示')
\n
})
\n
.catch((err : any | null) => {
\n
uni.hideLoading()
\n
const error = err as UniCloudError
\n
this.notify(error.errMsg, '错误')
\n
})
\n
}
\n
}
\n
}
\n\n
```
\n
:::"
},
"onResponse"
:{
"name"
:
"## onResponse(callback) @onresponse"
,
"description"
:
"监听响应事件"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### onResponse 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.get-current-user-info)
\n
"
},
"offResponse"
:{
"name"
:
"## offResponse(callback) @offresponse"
,
"description"
:
"移除响应事件监听"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### offResponse 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.on-response)
\n
"
},
"onRefreshToken"
:{
"name"
:
"## onRefreshToken(callback) @onrefreshtoken"
,
"description"
:
"监听token刷新事件"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### onRefreshToken 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.off-response)
\n
"
},
"offRefreshToken"
:{
"name"
:
"## offRefreshToken(callback) @offrefreshtoken"
,
"description"
:
"移除token刷新事件监听"
,
"param"
:
"### 参数
\n\n
| 名称 | 类型 | 必填 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| callback | (arg: [UniCloudResponseEvent](#unicloudresponseevent-values)) => any
\\
| null | 是 | - | - |
\n\n
#### UniCloudResponseEvent 的属性值 @unicloudresponseevent-values
\n\n
| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
| :- | :- | :- | :- | :- |
\n
| type | string | 是 | - | 响应事件类型 |
\n
| name | string | 是 | - | 响应事件由哪个云函数触发 |
\n
| content | any | 是 | - | 响应结果、错误内容 |
\n
"
,
"returnValue"
:
""
,
"compatibility"
:
"### offRefreshToken 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.on-refresh-token)
\n
"
},
"getCurrentUserInfo"
:{
"name"
:
"## getCurrentUserInfo() @getcurrentuserinfo"
,
"description"
:
"获取token内缓存的用户信息"
,
"param"
:
""
,
"returnValue"
:
"### 返回值
\n\n
| 类型 |
\n
| :- |
\n
| **UniCloudUserInfo** |
\n
@| 名称 | 类型 | 必备 | 默认值 | 描述 |
\n
@| :- | :- | :- | :- | :- |
\n
@| uid | string
\\
| null | 否 | - | UserInfo = {<br/> / |
\n
@| role | Array
\\
<string
\\
> | 是 | - | ing
\\
| null; / |
\n
@| permission | Array
\\
<string
\\
> | 是 | - | ay
\\
<string>; / |
\n
@| tokenExpired | number | 是 | - | ay
\\
<string>; /** |
\n
"
,
"compatibility"
:
"### getCurrentUserInfo 兼容性
\n
| Android | iOS | web |
\n
| :- | :- | :- |
\n
| 阿里云 3.9,腾讯云 3.91 | 4.11 | 4.0 |
\n
"
,
"tutorial"
:
"
\n
### 参见
\n
[相关 Bug](https://issues.dcloud.net.cn/?mid=api.unicloud.unicloud-utils.off-refresh-token)
\n
"
}}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录