Action2Page.ets
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { WDRouterPage } from './WDRouterPage'
import { Action } from 'wdBean'
import ArrayList from '@ohos.util.ArrayList';
interface HandleObject {
handle: (action: Action) => (WDRouterPage | undefined)
priority: number
}
export class Action2Page {
private static handles: Record<string, ArrayList<HandleObject>> = {};
static register(actionType: string, handle: (action: Action) => (WDRouterPage | undefined), priority: number = 0) {
let handles = Action2Page.handles[actionType] ?? new ArrayList();
let obj: HandleObject = {
handle: handle,
priority: priority
};
handles.add(obj);
handles.sort((f, s) => {
return f.priority - s.priority;
})
Action2Page.handles[actionType] = handles;
}
static get(action?: Action): WDRouterPage | undefined {
if (!action || !action.type) {
return undefined;
}
let handles = Action2Page.handles[action.type];
if (!handles) {
return undefined;
}
let page: WDRouterPage | undefined
for (let i = 0; i < handles.length; i++) {
let tmp = (handles[i] as HandleObject).handle(action);
if (tmp) {
page = tmp;
break
}
}
return page
}
}
export function registerRouter() {
// Action2Page.register("USER_LOGIN", (action: Action) => {
// return WDRouterPage.webLoginPage
// })
// Action2Page.register("JUMP_DETAIL_PAGE", (action) => {
// if (action.params?.pageID == "296ff8a4b07d457cb15b6f9e5f433cc0") {
// return WDRouterPage.tvLivePage
// }
// if (action.params?.detailPageType == 7 || action.params?.detailPageType == 8) {
// return WDRouterPage.shortVideoDetail
// }
// return WDRouterPage.playDetail
// })
Action2Page.register("JUMP_H5_BY_WEB_VIEW", (action) => {
return WDRouterPage.defaultWebPage
})
// Action2Page.register("JUMP_INNER_NEW_PAGE", (action) => {
// if (action.params?.pageID == "WORLDCUP_DETAIL") {
// return WDRouterPage.livependantpage
// }
// return undefined
// })
}