-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.js
79 lines (68 loc) · 1.88 KB
/
index.js
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
73
74
75
76
77
78
79
import { push } from '@zos/router'
import { px } from '@zos/utils'
import { APITree } from '../config/tree'
import ButtonList from '../utils/UI/ButtonList'
import EmptySpace from '../utils/UI/EmptySpace'
import PageAdvanced from '../utils/template/PageAdvanced'
PageAdvanced({
state: {
params: null,
buttonList: null,
},
onInit(params) {
this.state.logger.log("params", params);
try {
this.state.params = JSON.parse(params);
} catch (error) {
this.state.params = {
path: [],
};
}
},
build() {
this.state.logger.log("build");
const { path = [] } = this.state.params;
const currentTree = path.reduce((prev, curr) => {
return prev[curr];
}, APITree);
this.state.logger.log("currentTree", currentTree);
const list = Object.keys(currentTree).map((key) => {
return {
text: key,
path: currentTree[key].page || "",
};
});
this.state.buttonList = new ButtonList({
list,
absolute_y: px(120),
click_func: (i, index) => {
this.state.logger.log("i", i);
this.state.logger.log("index", index);
const { text, path } = i;
if (path) {
this.state.logger.log("path", path);
this.state.logger.log(
"final path",
`page/${this.state.params.path.join("/")}/${path}`
);
push({
url: `page/${this.state.params.path.join("/")}/${path}`,
});
} else {
push({
url: "page/index",
params: {
path: [...this.state.params.path, text],
},
});
}
},
});
this.state.buttonList.render();
const offset =
list.length *
(this.state.buttonList.space + this.state.buttonList.buttonHeight) +
this.state.buttonList.absolute_y;
new EmptySpace({ y: offset }).render();
},
});