Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
756bed62
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6018
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
756bed62
编写于
10月 15, 2024
作者:
X
xty
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加iOS uts event-bus 示例
上级
5e9042e2
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
333 addition
and
0 deletion
+333
-0
pages.json
pages.json
+9
-0
pages/API/event-bus/uts-event-bus.test.js
pages/API/event-bus/uts-event-bus.test.js
+71
-0
pages/API/event-bus/uts-event-bus.uvue
pages/API/event-bus/uts-event-bus.uvue
+104
-0
uni_modules/uts-eventbus/changelog.md
uni_modules/uts-eventbus/changelog.md
+0
-0
uni_modules/uts-eventbus/package.json
uni_modules/uts-eventbus/package.json
+82
-0
uni_modules/uts-eventbus/readme.md
uni_modules/uts-eventbus/readme.md
+6
-0
uni_modules/uts-eventbus/utssdk/app-ios/config.json
uni_modules/uts-eventbus/utssdk/app-ios/config.json
+3
-0
uni_modules/uts-eventbus/utssdk/app-ios/index.uts
uni_modules/uts-eventbus/utssdk/app-ios/index.uts
+58
-0
uni_modules/uts-eventbus/utssdk/unierror.uts
uni_modules/uts-eventbus/utssdk/unierror.uts
+0
-0
未找到文件。
pages.json
浏览文件 @
756bed62
...
...
@@ -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"
,
...
...
pages/API/event-bus/uts-event-bus.test.js
0 → 100644
浏览文件 @
756bed62
// 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
'
)
})
})
pages/API/event-bus/uts-event-bus.uvue
0 → 100644
浏览文件 @
756bed62
<template>
<!-- #ifdef APP -->
<scroll-view class="page-scroll-view">
<!-- #endif -->
<view>
<button @click="JsOnUts">1. js监听uts消息</button>
<button @click="emitFromUts">2. uts中触发监听</button>
<button @click="offUts">取消uts消息监听</button>
<button @click="UtsOnJS">1. uts监听js消息</button>
<button @click="emitFormJS">2 .js中触发监听</button>
<button @click="offJs">取消js消息监听</button>
<button @click="clear">清空消息</button>
<view class="box">
<view>收到的消息:</view>
<view>
<view v-for="(item, index) in log" :key="index">{{ item }}</view>
</view>
</view>
</view>
<button @click="testAll">test all</button>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
import {
onJsMessage,
offJsMessage,
emitUtsMessage,
getMessageChannel,
getRevJsMessage,
clearJsMessage,
onJsMessageOnce,
} from "@/uni_modules/uts-eventbus"
export default {
data() {
return {
log: [] as string[],
}
},
methods: {
fn(res : string, res2 : string) {
console.log("on rev: " + res)
this.log.push(res)
this.log.push(res2)
},
fn2(res : string) {
this.log.push(res)
},
JsOnUts() {
uni.$off(getMessageChannel(), this.fn)
uni.$on(getMessageChannel(), this.fn)
},
offUts() {
uni.$off(getMessageChannel(), this.fn)
},
emitFromUts() {
emitUtsMessage("emit form uts")
},
JsOnUtsOnce() {
uni.$once(getMessageChannel(), this.fn2)
},
UtsOnJS() {
onJsMessage("JsMessage")
},
UtsOnJSOnce() {
onJsMessageOnce("JsMessage")
},
offJs() {
offJsMessage("JsMessage")
},
emitFormJS() {
clearJsMessage()
uni.$emit("JsMessage", "emit form js")
let msg = getRevJsMessage()
console.log("message:"+msg)
if (msg && msg.length){
this.log.push(msg)
}
},
clear() {
clearJsMessage()
this.log.length = 0
},
testAll() {
this.JsOnUts();
this.emitFromUts();
this.UtsOnJS();
this.emitFormJS();
}
},
}
</script>
<style>
.box {
padding: 10px;
}
</style>
uni_modules/uts-eventbus/changelog.md
0 → 100644
浏览文件 @
756bed62
uni_modules/uts-eventbus/package.json
0 → 100644
浏览文件 @
756bed62
{
"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
uni_modules/uts-eventbus/readme.md
0 → 100644
浏览文件 @
756bed62
# 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
uni_modules/uts-eventbus/utssdk/app-ios/config.json
0 → 100644
浏览文件 @
756bed62
{
"deploymentTarget"
:
"12"
}
uni_modules/uts-eventbus/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
756bed62
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
uni_modules/uts-eventbus/utssdk/unierror.uts
0 → 100644
浏览文件 @
756bed62
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录