diff --git a/pages/API/unicloud-call-function/unicloud-call-function.test.js b/pages/API/unicloud-call-function/unicloud-call-function.test.js
index d6716a12a9823b1798b308d6ee8b1d92ff5fd4c3..2917aef6f27db4e672ea04f5e87469588d60b3de 100644
--- a/pages/API/unicloud-call-function/unicloud-call-function.test.js
+++ b/pages/API/unicloud-call-function/unicloud-call-function.test.js
@@ -14,7 +14,7 @@ describe('unicloud-call-function', () => {
await page.callMethod('callFunction')
const {
callFunctionResult,
- callFunctionError
+ callFunctionError,
} = await page.data()
console.error(callFunctionResult)
console.error(callFunctionError)
@@ -22,4 +22,12 @@ describe('unicloud-call-function', () => {
expect(callFunctionResult['event']['num']).toBe(1)
expect(callFunctionResult['event']['str']).toBe('ABC')
})
+
+ it('callFunctionWithGeneric', async () => {
+ await page.callMethod('callFunctionWithGeneric')
+ const {
+ genericDemoShowMessage,
+ } = await page.data()
+ expect(genericDemoShowMessage).toBe("Hello uniCloud function")
+ })
})
diff --git a/pages/API/unicloud-call-function/unicloud-call-function.uvue b/pages/API/unicloud-call-function/unicloud-call-function.uvue
index ff984f326fa2ff02e64ed02962dbc2ba2c040fac..58f3284106c118e22183ecdd96e6304fcec4eb18 100644
--- a/pages/API/unicloud-call-function/unicloud-call-function.uvue
+++ b/pages/API/unicloud-call-function/unicloud-call-function.uvue
@@ -7,6 +7,7 @@
+
@@ -22,6 +23,7 @@
title: '请求云函数',
callFunctionResult: {},
callFunctionError: {},
+ genericDemoShowMessage: '',
isUniTest: false
}
},
@@ -44,6 +46,34 @@
console.log(title, content)
}
},
+ async callFunctionWithGeneric() : Promise {
+ type EchoCfResult = {
+ showMessage: string
+ }
+ uni.showLoading({
+ title: '加载中...'
+ })
+ await uniCloud.callFunction({
+ name: 'echo-cf',
+ data: {
+ num: 1,
+ str: 'ABC'
+ }
+ }).then(res => {
+ const result = res.result
+ uni.hideLoading()
+ this.genericDemoShowMessage = result.showMessage
+ this.notify(result.showMessage, '提示')
+ }).catch((err : any | null) => {
+ const error = err as UniCloudError
+ this.callFunctionError = {
+ errCode: error.errCode,
+ errMsg: error.errMsg
+ }
+ uni.hideLoading()
+ this.notify(error.errMsg, '错误')
+ })
+ },
async callFunction() : Promise {
uni.showLoading({
title: '加载中...'
diff --git a/pages/API/unicloud-import-object/unicloud-import-object.test.js b/pages/API/unicloud-import-object/unicloud-import-object.test.js
index 59fcece3b56b315a9245d78c14074a0e3a331a8c..a3c49839b21e9f7b38065623cf45354e82b4063d 100644
--- a/pages/API/unicloud-import-object/unicloud-import-object.test.js
+++ b/pages/API/unicloud-import-object/unicloud-import-object.test.js
@@ -11,6 +11,7 @@ describe('unicloud-import-object', () => {
})
it('importObject', async () => {
await page.callMethod('addTodo')
+ await page.callMethod('addTodoWithGeneric')
await page.callMethod('fail')
await page.callMethod('failWithNumberErrCode')
await page.callMethod('success')
@@ -20,6 +21,8 @@ describe('unicloud-import-object', () => {
todoContent,
returnTodoTitle,
returnTodoContent,
+ genericDemoReturnTodoTitle,
+ genericDemoReturnTodoContent,
failErrCode,
failNumberErrCode,
successErrCode,
@@ -27,6 +30,8 @@ describe('unicloud-import-object', () => {
expect(returnTodoTitle).toBe(todoTitle)
expect(returnTodoContent).toBe(todoContent)
+ expect(genericDemoReturnTodoTitle).toBe(todoTitle)
+ expect(genericDemoReturnTodoContent).toBe(todoContent)
expect(failErrCode).toBe('TEST_ERROR_CODE')
expect(failNumberErrCode).toBe(-1)
expect(successErrCode).toBe(0)
diff --git a/pages/API/unicloud-import-object/unicloud-import-object.uvue b/pages/API/unicloud-import-object/unicloud-import-object.uvue
index e02c383a19ecf1c5a95ca2d50a35cc5243c06c49..4c60b4b50c6b6924758af3498ee09adf13182467 100644
--- a/pages/API/unicloud-import-object/unicloud-import-object.uvue
+++ b/pages/API/unicloud-import-object/unicloud-import-object.uvue
@@ -8,6 +8,9 @@
+
+
+
@@ -36,6 +39,8 @@
todoContent: '熟悉uts语法',
returnTodoTitle: '',
returnTodoContent: '',
+ genericDemoReturnTodoTitle: '',
+ genericDemoReturnTodoContent: '',
failErrCode: '',
failNumberErrCode: 0,
successErrCode: -1,
@@ -60,11 +65,33 @@
})
const title = this.todoTitle
const content = this.todoContent
- await todo.add(title, content).then((res : UTSJSONObject) => {
+ await todo.add(title, content).then((res : UTSJSONObject) => {
this.returnTodoTitle = res['title'] as string
this.returnTodoContent = res['content'] as string
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) => {
+ console.log(err)
+ const error = err as UniCloudError
+ console.error(error)
+ })
+ },
+ async addTodoWithGeneric() : Promise {
+ type AddTodoResult = {
+ title: string,
+ content: string,
+ showMessage: string
+ }
+ const todo = uniCloud.importObject('todo', {
+ customUI: this.isUniTest
+ })
+ const title = this.todoTitle
+ const content = this.todoContent
+ await todo.add(title, content).then((res : AddTodoResult) => {
+ this.genericDemoReturnTodoTitle = res.title
+ this.genericDemoReturnTodoContent = res.content
+ this.notify(res.showMessage, '提示')
+ }).catch((err : any | null) => {
+ console.log(err)
const error = err as UniCloudError
console.error(error)
})