# 发送系统消息 sendAppEvent
将消息发送到其它地方
// 消息发送体
type EventBody = {
appEventChannel: '', // 消息名称
appEventArg: {} // 消息内容
}
type ResBody = {
resultCode: number, resultMessage: string, data: {}
}
zwexplorer.__appEvent.sendAppEvent(data: EventBody, callback?: (res: ResBody)=>void)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
data | String | 是 | 消息发送体 |
data.appEventChannel | String | 是 | 消息名称 |
data.appEventArg | Object | 是 | 消息内容 |
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
res.resultCode | Number | 是 | 状态码,0 为正常,其它为异常 [状态码参考] |
res.data | Object | 否 | 状态码为 0 时,返回获得的信息 |
res.resultMessage | String | 否 | 接口消息 |
zwexplorer__appEvent.sendAppEvent({
appEventChannel: 'do_something', // 消息名称
appEventArg: {
name: '张三',
age: 18
} // 消息内容
}, (res) => {
alert(res);
});
# 监听系统消息 onAppEvent
监听系统消息
type AppEventChannel = string
type AppEventArg = {
[prop: string | number]:any
}
zwexplorer.__appEvent.onAppEvent(channel: AppEventChannel, callback?: (res: AppEventArg)=>void)
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
channel | string | 是 | 消息名称 |
callback | Function | 否 | 监听到来自其它地方发过来的消息 , 回调消息体一般为json 格式 |
zwexplorer.__appEvent.onAppEvent("do_something", (res) => {
// 监听到来自其它地方发过来的消息
console.log(res);
});
# 单次监听系统消息 onceAppEvent
单次监听系统消息
type AppEventChannel = string
type AppEventArg = {
[prop: string | number]:any
}
zwexplorer.__appEvent.onceAppEvent(channel: AppEventChannel, callback?: (res: AppEventArg)=>void)
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
channel | string | 是 | 消息名称 |
callback | Function | 否 | 监听到来自其它地方发过来的消息 , 回调消息体一般为json 格式 |
zwexplorer.__appEvent.onceAppEvent("do_something", (res) => {
// 监听到来自其它地方发过来的消息
console.log(res);
});
# 单次监听系统消息 once
# 移除系统消息监听器 removeListener
移除系统消息监听器
type AppEventChannel = string // 需要移除的消息消息名称
type Callback = Fuction // 需要移除的消息回调函数
zwexplorer.__appEvent.removeListener(channel: AppEventChannel, callback: Callback)
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
channel | string | 是 | 消息名称 |
callback | Function | 否 | 需要移除的消息回调函数 |
zwexplorer.__appEvent.removeListener('do_something', ()=>{})
# 移除所有同名的系统消息监听器 removeAllListeners
移除所有同名的系统消息监听器
type AppEventChannel = string // 需要移除的消息消息名称
zwexplorer.__appEvent.removeAllListeners(channel: AppEventChannel)
参数 | 类型 | 必然存在 | 说明 |
---|---|---|---|
channel | string | 是 | 消息名称 |
zwexplorer.__appEvent.removeAllListeners('do_something')