-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.js
45 lines (42 loc) · 1.04 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
import * as hmUI from "@zos/ui";
import { log as Logger } from "@zos/utils";
import { BasePage } from "@zeppos/zml/base-page";
import {
FETCH_BUTTON,
FETCH_RESULT_TEXT,
} from "zosLoader:./index.[pf].layout.js";
const logger = Logger.getLogger("fetch_api");
let textWidget;
Page(
BasePage({
state: {},
build() {
hmUI.createWidget(hmUI.widget.BUTTON, {
...FETCH_BUTTON,
click_func: (button_widget) => {
logger.log("click button");
this.fetchData();
},
});
},
fetchData() {
this.request({
method: "GET_DATA",
})
.then((data) => {
logger.log("receive data");
const { result = {} } = data;
const text = JSON.stringify(result);
if (!textWidget) {
textWidget = hmUI.createWidget(hmUI.widget.TEXT, {
...FETCH_RESULT_TEXT,
text,
});
} else {
textWidget.setProperty(hmUI.prop.TEXT, text);
}
})
.catch((res) => {});
},
})
);