Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
yuzhilin
2024-04-15 16:24:58 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
ed6469fd86b22a1e78d0110366ca16773e92328d
ed6469fd
2 parents
4270e243
a5360706
Merge branch 'main' of
http://192.168.1.42/developOne/harmonyPool
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
0 deletions
sight_harmony/commons/wdKit/Index.ets
sight_harmony/commons/wdKit/src/main/ets/utils/EmitterEventId.ts
sight_harmony/commons/wdKit/src/main/ets/utils/EmitterUtils.ts
sight_harmony/commons/wdKit/Index.ets
View file @
ed6469f
...
...
@@ -39,3 +39,7 @@ export { NumberFormatterUtils } from './src/main/ets/utils/NumberFormatterUtils'
// export { PermissionUtils } from './src/main/ets/utils/PermissionUtils'
export { ErrorToastUtils } from './src/main/ets/utils/ErrorToastUtils'
export { EmitterUtils } from './src/main/ets/utils/EmitterUtils'
export { EmitterEventId } from './src/main/ets/utils/EmitterEventId'
\ No newline at end of file
...
...
sight_harmony/commons/wdKit/src/main/ets/utils/EmitterEventId.ts
0 → 100644
View file @
ed6469f
/**
* 线程间通信事件id枚举
*/
export
enum
EmitterEventId
{
// 通知登出,事件id
FORCE_USER_LOGIN_OUT
=
1
}
...
...
sight_harmony/commons/wdKit/src/main/ets/utils/EmitterUtils.ts
0 → 100644
View file @
ed6469f
import
emitter
from
'@ohos.events.emitter'
;
import
HashMap
from
'@ohos.util.HashMap'
;
const
TAG
:
string
=
'EmitterUtils'
;
/**
* 线程间通信简单工具
* TODO 待优化
*/
export
class
EmitterUtils
{
/**
* 发送空消息
* @param eventId 事件id
*/
static
sendEmptyEvent
(
eventId
:
number
)
{
let
event
:
emitter
.
InnerEvent
=
{
eventId
:
eventId
,
priority
:
emitter
.
EventPriority
.
LOW
};
emitter
.
emit
(
event
);
}
/**
* 发送消息
* @param eventId 事件id
* @param data 数据
*/
static
sendEvent
(
eventId
:
number
,
data
:
{
[
key
:
string
]
:
any
;
})
{
let
event
:
emitter
.
InnerEvent
=
{
eventId
:
eventId
,
priority
:
emitter
.
EventPriority
.
LOW
};
let
eventData
:
emitter
.
EventData
=
{
data
:
data
};
emitter
.
emit
(
event
,
eventData
);
}
/**
* 接收消息
* @param eventId 事件id
* @param callback 回调函数
*/
static
receiveEvent
(
eventId
:
number
,
callback
:
(
data
?:
{
[
key
:
string
]:
any
;
})
=>
void
)
{
let
event
:
emitter
.
InnerEvent
=
{
eventId
:
eventId
};
// 收到eventId为1的事件后执行该回调
let
callback1
=
(
eventData
:
emitter
.
EventData
):
void
=>
{
callback
(
eventData
.
data
)
};
// 订阅eventId为1的事件
emitter
.
on
(
event
,
callback1
);
}
}
...
...
Please
register
or
login
to post a comment