diff --git a/pages.json b/pages.json index aa58eb5a3fc05c76baea242cbcd23b5505cc2f0d..0e71a990c04c4f8270f14ba93d7acf5c2adb6a0d 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 0000000000000000000000000000000000000000..63e438223c439fe91f2e5909d374d2e238120e49 --- /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 0000000000000000000000000000000000000000..6e554582b5c2770e2c4c3b5e30e62f0e9ea515f8 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/uni_modules/uts-eventbus/package.json b/uni_modules/uts-eventbus/package.json new file mode 100644 index 0000000000000000000000000000000000000000..6889e7ed8a0947a2b65d4ae5c6fd643e9c657b9e --- /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 0000000000000000000000000000000000000000..7c405122fb122a6c75262f767850f5b0be813a47 --- /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 0000000000000000000000000000000000000000..ec0dcfb1579d5327e81c25ee5e8d78034dfff3c4 --- /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 0000000000000000000000000000000000000000..4b88bfb5fdcf6fe9fd2e110b16b1dd0af70dde5c --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391