From 03aa2702ac03be849118e5cb12641ed9aef3adea Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Thu, 18 Apr 2024 17:19:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0uniCloud=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=B3=9B=E5=9E=8B=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unicloud-call-function.test.js | 10 ++++++- .../unicloud-call-function.uvue | 30 +++++++++++++++++++ .../unicloud-import-object.test.js | 5 ++++ .../unicloud-import-object.uvue | 29 +++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-) 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 d6716a12..2917aef6 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 ff984f32..58f32841 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 59fcece3..a3c49839 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 e02c383a..4c60b4b5 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) }) -- GitLab