From 9de6696c589c52d508c5682e3397f106ab50fe42 Mon Sep 17 00:00:00 2001 From: xty Date: Sat, 16 Nov 2024 16:50:53 +0800 Subject: [PATCH] =?UTF-8?q?uts=20dialogpage=20uni.$emit=E8=A1=A5=E5=85=85o?= =?UTF-8?q?bject=E7=B1=BB=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 --- pages.json | 7 ++ pages/API/dialog-page/uts-dialog-page.uvue | 29 +++++++ pages/API/event-bus/uts-event-bus.test.js | 21 ++++- pages/API/event-bus/uts-event-bus.uvue | 61 ++++++++++++-- uni_modules/uts-dialogpage/changelog.md | 0 uni_modules/uts-dialogpage/package.json | 82 +++++++++++++++++++ uni_modules/uts-dialogpage/readme.md | 6 ++ .../uts-dialogpage/utssdk/app-ios/config.json | 3 + .../uts-dialogpage/utssdk/app-ios/index.uts | 65 +++++++++++++++ .../uts-dialogpage/utssdk/interface.uts | 6 ++ .../uts-dialogpage/utssdk/unierror.uts | 39 +++++++++ .../uts-eventbus/utssdk/app-ios/index.uts | 34 +++++--- 12 files changed, 332 insertions(+), 21 deletions(-) create mode 100644 pages/API/dialog-page/uts-dialog-page.uvue create mode 100644 uni_modules/uts-dialogpage/changelog.md create mode 100644 uni_modules/uts-dialogpage/package.json create mode 100644 uni_modules/uts-dialogpage/readme.md create mode 100644 uni_modules/uts-dialogpage/utssdk/app-ios/config.json create mode 100644 uni_modules/uts-dialogpage/utssdk/app-ios/index.uts create mode 100644 uni_modules/uts-dialogpage/utssdk/interface.uts create mode 100644 uni_modules/uts-dialogpage/utssdk/unierror.uts diff --git a/pages.json b/pages.json index 6dfacdf4..5e6eb321 100644 --- a/pages.json +++ b/pages.json @@ -1932,6 +1932,13 @@ "navigationBarTitleText": "" } }, + { + "path" : "pages/API/dialog-page/uts-dialog-page", + "style" : + { + "navigationBarTitleText" : "" + } + }, // #endif // #ifdef APP { diff --git a/pages/API/dialog-page/uts-dialog-page.uvue b/pages/API/dialog-page/uts-dialog-page.uvue new file mode 100644 index 00000000..26fa9dc5 --- /dev/null +++ b/pages/API/dialog-page/uts-dialog-page.uvue @@ -0,0 +1,29 @@ + + + + + diff --git a/pages/API/event-bus/uts-event-bus.test.js b/pages/API/event-bus/uts-event-bus.test.js index 83bd6715..b130f8ea 100644 --- a/pages/API/event-bus/uts-event-bus.test.js +++ b/pages/API/event-bus/uts-event-bus.test.js @@ -34,14 +34,31 @@ describe('event-bus', () => { await page.callMethod('JsOnUts') await page.callMethod('emitFromUts') const l1 = (await page.data()).log.length - expect(l1).toBeGreaterThan(0) + expect(l1).toBeGreaterThan(0) + + await page.callMethod('clear') + await page.callMethod('emitUtsMessageUTSObject') + const data = await page.data() + console.log(data) + expect(data.log.length).toBe(1) + expect(data.log[0].name).toMatch('金运大厦') + + await page.callMethod('clear') + await page.callMethod('emitUtsMessages') + const l12 = (await page.data()).log.length + expect(l12).toBe(2) + await page.callMethod('clear') + await page.callMethod('emitUtsMessageNoArgument') + const l13 = (await page.data()).log.length + expect(l13).toBe(0) await page.callMethod('clear') await page.callMethod('offUts') await page.callMethod('emitFromUts') const l2 = (await page.data()).log.length - expect(l2).toBe(0) + expect(l2).toBe(0) + await page.callMethod('clear') await page.callMethod('UtsOnJS') diff --git a/pages/API/event-bus/uts-event-bus.uvue b/pages/API/event-bus/uts-event-bus.uvue index 6e554582..2dab4b0a 100644 --- a/pages/API/event-bus/uts-event-bus.uvue +++ b/pages/API/event-bus/uts-event-bus.uvue @@ -4,11 +4,15 @@ - - + + + + + - + + @@ -29,7 +33,10 @@ import { onJsMessage, offJsMessage, - emitUtsMessage, + emitUtsMessage, + emitUtsMessageUTSObject, + emitUtsMessageNoArgument, + emitUtsMessages, getMessageChannel, getRevJsMessage, clearJsMessage, @@ -44,10 +51,15 @@ } }, methods: { - fn(res : string, res2 : string) { - console.log("on rev: " + res) - this.log.push(res) - this.log.push(res2) + fn(res : any, res2 : any) { + if (res != null){ + console.log("on rev: " + JSON.stringify(res)) + this.log.push(res) + } + if (res2 != null) { + console.log("on rev: " + JSON.stringify(res2)) + this.log.push(res2) + } }, fn2(res : string) { this.log.push(res) @@ -61,6 +73,25 @@ }, emitFromUts() { emitUtsMessage("emit form uts") + }, + emitUtsMessageUTSObject() { + emitUtsMessageUTSObject({ + latitude: 39.951028, + longitude: 116.354662, + name: '金运大厦', + address: '西直门北大街xx号' + }) + }, + emitUtsMessages() { + emitUtsMessages({ + latitude: 39.951028, + longitude: 116.354662, + name: '金运大厦', + address: '西直门北大街xx号' + }, "emit form uts") + }, + emitUtsMessageNoArgument() { + emitUtsMessageNoArgument() }, JsOnUtsOnce() { uni.$once(getMessageChannel(), this.fn2) @@ -82,6 +113,20 @@ if (msg && msg.length){ this.log.push(msg) } + }, + emitFormJSObject() { + clearJsMessage() + uni.$emit("JsMessage", { + latitude: 39.951028, + longitude: 116.354662, + name: '金运大厦form js', + address: '西直门北大街xx号 from js' + }) + let msg = getRevJsMessage() + console.log("message:"+msg) + if (msg && msg.length){ + this.log.push(msg) + } }, clear() { clearJsMessage() diff --git a/uni_modules/uts-dialogpage/changelog.md b/uni_modules/uts-dialogpage/changelog.md new file mode 100644 index 00000000..e69de29b diff --git a/uni_modules/uts-dialogpage/package.json b/uni_modules/uts-dialogpage/package.json new file mode 100644 index 00000000..d655ddfc --- /dev/null +++ b/uni_modules/uts-dialogpage/package.json @@ -0,0 +1,82 @@ +{ + "id": "uts-dialogpage", + "displayName": "uts-dialogpage", + "version": "1.0.0", + "description": "uts-dialogpage", + "keywords": [ + "uts-dialogpage" +], + "repository": "", + "engines": { + "HBuilderX": "^3.6.8" + }, + "dcloudext": { + "type": "uts", + "sale": { + "regular": { + "price": "0.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "", + "data": "", + "permissions": "" + }, + "npmurl": "" + }, + "uni_modules": { + "dependencies": [], + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "u", + "aliyun": "u", + "alipay": "u" + }, + "client": { + "Vue": { + "vue2": "u", + "vue3": "u" + }, + "App": { + "app-android": "u", + "app-ios": "u" + }, + "H5-mobile": { + "Safari": "u", + "Android Browser": "u", + "微信浏览器(Android)": "u", + "QQ浏览器(Android)": "u" + }, + "H5-pc": { + "Chrome": "u", + "IE": "u", + "Edge": "u", + "Firefox": "u", + "Safari": "u" + }, + "小程序": { + "微信": "u", + "阿里": "u", + "百度": "u", + "字节跳动": "u", + "QQ": "u", + "钉钉": "u", + "快手": "u", + "飞书": "u", + "京东": "u" + }, + "快应用": { + "华为": "u", + "联盟": "u" + } + } + } + } +} \ No newline at end of file diff --git a/uni_modules/uts-dialogpage/readme.md b/uni_modules/uts-dialogpage/readme.md new file mode 100644 index 00000000..7fe7d7d5 --- /dev/null +++ b/uni_modules/uts-dialogpage/readme.md @@ -0,0 +1,6 @@ +# uts-dialogpage +### 开发文档 +[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) +[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) +[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html) +[Hello UTS](https://gitcode.net/dcloud/hello-uts) \ No newline at end of file diff --git a/uni_modules/uts-dialogpage/utssdk/app-ios/config.json b/uni_modules/uts-dialogpage/utssdk/app-ios/config.json new file mode 100644 index 00000000..ec0dcfb1 --- /dev/null +++ b/uni_modules/uts-dialogpage/utssdk/app-ios/config.json @@ -0,0 +1,3 @@ +{ + "deploymentTarget": "12" +} diff --git a/uni_modules/uts-dialogpage/utssdk/app-ios/index.uts b/uni_modules/uts-dialogpage/utssdk/app-ios/index.uts new file mode 100644 index 00000000..a1882d62 --- /dev/null +++ b/uni_modules/uts-dialogpage/utssdk/app-ios/index.uts @@ -0,0 +1,65 @@ +/** + * 引用 iOS 系统库,示例如下: + * import { UIDevice } from "UIKit"; + * [可选实现,按需引入] + */ + +// import {OpenDialogPageOptions,openDialogPage} from "DCloudUTSExtAPI"; + +/* 引入 interface.uts 文件中定义的变量 */ +import { TestOpenDialogPage, TestCloseDialogPage } from '../interface.uts'; + +var curDialogPage : UniDialogPage | null = null +export const testOpenDialogPage : TestOpenDialogPage = function (url:string) { + + // let utsJsonObj : DCloudUTSExtAPI.OpenDialogPageOptions = { + // url:"zhangsan" + // } + console.log("testOpenDialogPage") + + // let option = new OpenDialogPageOptions({ + // url:url + // }) + let option = new OpenDialogPageOptions() + option.url = url + console.log(url) + + option.animationType ="slide-in-left" + // option.parentPage = getCurrentPages()[0] + + option.success = (arg : OpenDialogPageSuccess )=>{ + console.log("success") + } + option.complete = (arg : OpenDialogPageComplete )=>{ + console.log(arg) + } + + option.fail = (arg : OpenDialogPageFail )=>{ + console.log("fail") + } + curDialogPage = uni.openDialogPage(option) +} + +export const testCloseDialogPage : TestCloseDialogPage = function () { + console.log("testCloseDialogPage") + if ( curDialogPage != null ){ + let option = new CloseDialogPageOptions() + option.dialogPage = curDialogPage + + option.success = (arg : CloseDialogPageSuccess )=>{ + console.log("success") + } + option.complete = (arg : CloseDialogPageComplete )=>{ + console.log(arg) + } + + option.fail = (arg : CloseDialogPageFail )=>{ + console.log("fail") + } + uni.closeDialogPage(option) + } +} + +/** + * 更多插件开发的信息详见:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html + */ diff --git a/uni_modules/uts-dialogpage/utssdk/interface.uts b/uni_modules/uts-dialogpage/utssdk/interface.uts new file mode 100644 index 00000000..8cd8c84e --- /dev/null +++ b/uni_modules/uts-dialogpage/utssdk/interface.uts @@ -0,0 +1,6 @@ +/** + * interface.uts + * uts插件接口定义文件,按规范定义接口文件可以在HBuilderX中更好的做到语法提示 + */ +export type TestOpenDialogPage = (url:string)=>void +export type TestCloseDialogPage = ()=>void \ No newline at end of file diff --git a/uni_modules/uts-dialogpage/utssdk/unierror.uts b/uni_modules/uts-dialogpage/utssdk/unierror.uts new file mode 100644 index 00000000..c20aca6d --- /dev/null +++ b/uni_modules/uts-dialogpage/utssdk/unierror.uts @@ -0,0 +1,39 @@ +/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */ +import { MyApiErrorCode, MyApiFail } from "./interface.uts" +/** + * 错误主题 + * 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。 + * [可选实现] + */ +export const UniErrorSubject = 'uts-api'; + + +/** + * 错误信息 + * @UniError + * [可选实现] + */ +export const MyAPIErrors : Map = new Map([ + /** + * 错误码及对应的错误信息 + */ + [9010001, 'custom error mseeage1'], + [9010002, 'custom error mseeage2'], +]); + + +/** + * 错误对象实现 + */ +export class MyApiFailImpl extends UniError implements MyApiFail { + + /** + * 错误对象构造函数 + */ + constructor(errCode : MyApiErrorCode) { + super(); + this.errSubject = UniErrorSubject; + this.errCode = errCode; + this.errMsg = MyAPIErrors.get(errCode) ?? ""; + } +} diff --git a/uni_modules/uts-eventbus/utssdk/app-ios/index.uts b/uni_modules/uts-eventbus/utssdk/app-ios/index.uts index 4b88bfb5..666fa3e6 100644 --- a/uni_modules/uts-eventbus/utssdk/app-ios/index.uts +++ b/uni_modules/uts-eventbus/utssdk/app-ios/index.uts @@ -17,19 +17,30 @@ export function emitUtsMessage(arg : string) { uni.$emit(MessageChannel, arg); } +export function emitUtsMessageUTSObject(arg : UTSJSONObject) { + uni.$emit(MessageChannel, arg); +} + +export function emitUtsMessages(arg : UTSJSONObject, arg2 : string ){ + uni.$emit(MessageChannel, arg, arg2); +} + +export function emitUtsMessageNoArgument(){ + uni.$emit(MessageChannel); +} + var callbackId : NSNumber | null = null export function onJsMessage (messageChannel : string ) { revFromJS = "" if (callbackId != null) { uni.$off(messageChannel, callbackId!) - callbackId = null + callbackId = null } - callbackId = uni.$on(messageChannel, function (...spreadArgs : Any) { if (spreadArgs.length > 0) { - let arg0 = spreadArgs[0] as String | null - if ( arg0 != null ){ - revFromJS = arg0!; + let arg0 = JSON.stringify(spreadArgs[0]) + if ( typeof arg0 == "string" ) { + revFromJS = arg0! } } }) @@ -39,20 +50,21 @@ export function onJsMessageOnce (messageChannel : string ) { revFromJS = "" uni.$once(messageChannel, function (...spreadArgs : Any) { if (spreadArgs.length > 0) { - let arg0 = spreadArgs[0] as String | null - if ( arg0 != null ){ - revFromJS = arg0!; - } + let arg0 = JSON.stringify(spreadArgs[0]) + if ( typeof arg0 == "string" ) { + revFromJS = arg0! + } } }) } export function offJsMessage(messageChannel : string) { if (callbackId != null) { - uni.$off(messageChannel, callbackId!) + uni.$off(messageChannel, callbackId!) + callbackId = null } } export function clearJsMessage() { revFromJS = "" -} \ No newline at end of file +} -- GitLab