From f142f2f654d21cec2e0253566b21e1e6e994a8d3 Mon Sep 17 00:00:00 2001 From: xty Date: Tue, 15 Oct 2024 16:34:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0iOS=20uts=20event-bus=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 9 ++ pages/API/event-bus/uts-event-bus.test.js | 71 ++++++++++++ pages/API/event-bus/uts-event-bus.uvue | 104 ++++++++++++++++++ uni_modules/uts-eventbus/changelog.md | 0 uni_modules/uts-eventbus/package.json | 82 ++++++++++++++ uni_modules/uts-eventbus/readme.md | 6 + .../uts-eventbus/utssdk/app-ios/config.json | 3 + .../uts-eventbus/utssdk/app-ios/index.uts | 58 ++++++++++ uni_modules/uts-eventbus/utssdk/unierror.uts | 0 9 files changed, 333 insertions(+) create mode 100644 pages/API/event-bus/uts-event-bus.test.js create mode 100644 pages/API/event-bus/uts-event-bus.uvue create mode 100644 uni_modules/uts-eventbus/changelog.md create mode 100644 uni_modules/uts-eventbus/package.json create mode 100644 uni_modules/uts-eventbus/readme.md create mode 100644 uni_modules/uts-eventbus/utssdk/app-ios/config.json create mode 100644 uni_modules/uts-eventbus/utssdk/app-ios/index.uts create mode 100644 uni_modules/uts-eventbus/utssdk/unierror.uts diff --git a/pages.json b/pages.json index aa58eb5a..0e71a990 100644 --- a/pages.json +++ b/pages.json @@ -1853,6 +1853,15 @@ "backgroundColorContent": "#fffae8" } }, + // #ifdef APP-IOS + { + "path" : "pages/API/event-bus/uts-event-bus", + "style" : + { + "navigationBarTitleText" : "" + } + }, + // #endif // #ifdef APP { "path": "pages/privacy", diff --git a/pages/API/event-bus/uts-event-bus.test.js b/pages/API/event-bus/uts-event-bus.test.js new file mode 100644 index 00000000..63e43822 --- /dev/null +++ b/pages/API/event-bus/uts-event-bus.test.js @@ -0,0 +1,71 @@ +// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ +const PAGE_PATH = '/pages/API/event-bus/uts-event-bus' + +if ( !process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { + it('pass', async () => { + expect(1).toBe(1); + }); + return; + } + +describe('event-bus', () => { + let page + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor('view') + }) + + it('on', async () => { + await page.callMethod('clear') + await page.callMethod('JsOnUts') + await page.callMethod('emitFromUts') + const l1 = (await page.data()).log.length + expect(l1).toBeGreaterThan(0) + + + await page.callMethod('clear') + await page.callMethod('offUts') + await page.callMethod('emitFromUts') + const l2 = (await page.data()).log.length + expect(l2).toBe(0) + + await page.callMethod('clear') + await page.callMethod('UtsOnJS') + await page.callMethod('emitFormJS') + const l3 = (await page.data()).log.length + expect(l3).toBeGreaterThan(0) + + await page.callMethod('clear') + await page.callMethod('offJs') + await page.callMethod('emitFormJS') + const l4 = (await page.data()).log.length + console.log(l4) + expect(l4).toBe(0) + await page.callMethod('clear') + }) + + it('once', async () => { + await page.callMethod('clear') + await page.callMethod('JsOnUtsOnce') + await page.callMethod('emitFromUts') + const l1 = (await page.data()).log.length + expect(l1).toBeGreaterThan(0) + await page.callMethod('clear') + await page.callMethod('emitFromUts') + const l2 = (await page.data()).log.length + expect(l2).toBe(0) + + await page.callMethod('clear') + await page.callMethod('UtsOnJSOnce') + await page.callMethod('emitFormJS') + const l3 = (await page.data()).log.length + expect(l3).toBeGreaterThan(0) + await page.callMethod('clear') + await page.callMethod('emitFormJS') + const l4 = (await page.data()).log.length + expect(l4).toBe(0) + + await page.callMethod('clear') + }) + +}) diff --git a/pages/API/event-bus/uts-event-bus.uvue b/pages/API/event-bus/uts-event-bus.uvue new file mode 100644 index 00000000..6e554582 --- /dev/null +++ b/pages/API/event-bus/uts-event-bus.uvue @@ -0,0 +1,104 @@ + + + + + diff --git a/uni_modules/uts-eventbus/changelog.md b/uni_modules/uts-eventbus/changelog.md new file mode 100644 index 00000000..e69de29b diff --git a/uni_modules/uts-eventbus/package.json b/uni_modules/uts-eventbus/package.json new file mode 100644 index 00000000..6889e7ed --- /dev/null +++ b/uni_modules/uts-eventbus/package.json @@ -0,0 +1,82 @@ +{ + "id": "uts-eventbus", + "displayName": "uts-eventbus", + "version": "1.0.0", + "description": "uts-eventbus", + "keywords": [ + "uts-eventbus" +], + "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-eventbus/readme.md b/uni_modules/uts-eventbus/readme.md new file mode 100644 index 00000000..7c405122 --- /dev/null +++ b/uni_modules/uts-eventbus/readme.md @@ -0,0 +1,6 @@ +# uts-eventbus +### 开发文档 +[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-eventbus/utssdk/app-ios/config.json b/uni_modules/uts-eventbus/utssdk/app-ios/config.json new file mode 100644 index 00000000..ec0dcfb1 --- /dev/null +++ b/uni_modules/uts-eventbus/utssdk/app-ios/config.json @@ -0,0 +1,3 @@ +{ + "deploymentTarget": "12" +} diff --git a/uni_modules/uts-eventbus/utssdk/app-ios/index.uts b/uni_modules/uts-eventbus/utssdk/app-ios/index.uts new file mode 100644 index 00000000..4b88bfb5 --- /dev/null +++ b/uni_modules/uts-eventbus/utssdk/app-ios/index.uts @@ -0,0 +1,58 @@ + +import { UniUTSJS } from 'DCloudUniappRuntime' +import { NSNumber } from 'Foundation'; + +let MessageChannel : string = "UtsMessage" +var revFromJS = "" + +export function getMessageChannel() : string { + return MessageChannel +} + +export function getRevJsMessage() : string { + return revFromJS +} + +export function emitUtsMessage(arg : string) { + uni.$emit(MessageChannel, arg); +} + +var callbackId : NSNumber | null = null +export function onJsMessage (messageChannel : string ) { + revFromJS = "" + if (callbackId != null) { + uni.$off(messageChannel, callbackId!) + 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!; + } + } + }) +} + +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!; + } + } + }) +} + +export function offJsMessage(messageChannel : string) { + if (callbackId != null) { + uni.$off(messageChannel, callbackId!) + } +} + +export function clearJsMessage() { + revFromJS = "" +} \ No newline at end of file diff --git a/uni_modules/uts-eventbus/utssdk/unierror.uts b/uni_modules/uts-eventbus/utssdk/unierror.uts new file mode 100644 index 00000000..e69de29b -- GitLab