@zeppos/zeus-cli 1.3.7 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/post-command.js +1 -1
- package/package.json +2 -2
- package/private-modules/zeppos-app-utils/dist/config/project.js +1 -1
- package/private-modules/zeppos-app-utils/dist/modules/fetchDevices.js +3 -1
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/.prettierrc.js +6 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/app-side/index.js +45 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/app.js +25 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/app.json +64 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/assets/gts/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/page/home/index.page.js +155 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/page/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/page/home/index.style.js +92 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/page/i18n/en-US.po +9 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/secondary-widget/index.js +160 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/setting/i18n/en-US.po +5 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/setting/index.js +143 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/shared/data.js +67 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/shared/defer.js +35 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/shared/device-polyfill.js +6 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/shared/es6-promise.js +1178 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/shared/event.js +42 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/shared/message-side.js +1190 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/shared/message.js +1196 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/utils/constants.js +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/utils/index.js +38 -0
- package/private-modules/zeppos-app-utils/package.json +1 -1
package/bin/post-command.js
CHANGED
|
@@ -3,4 +3,4 @@ exports.__esModule = true;
|
|
|
3
3
|
var zeppos_app_utils_1 = require("zeppos-app-utils");
|
|
4
4
|
var bin = require('../package.json').bin;
|
|
5
5
|
process.env.CMD_NAME = Object.keys(bin || {})[0] || 'zeus';
|
|
6
|
-
process.env.ACCOUNT_ENV = zeppos_app_utils_1.globalStorage.get('account_env')
|
|
6
|
+
process.env.ACCOUNT_ENV = zeppos_app_utils_1.globalStorage.get('account_env') === 'test' ? 'test' : 'production';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeppos/zeus-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "zeus mini-program tools",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"author": "zepp",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"qrcode-terminal": "^0.12.0",
|
|
22
22
|
"vorpal": "^1.12.0",
|
|
23
23
|
"yargs": "^17.5.1",
|
|
24
|
-
"@zeppos/zpm": "^3.0.
|
|
24
|
+
"@zeppos/zpm": "^3.0.5",
|
|
25
25
|
"axios": "^0.27.2",
|
|
26
26
|
"chalk": "^4.1.2",
|
|
27
27
|
"chokidar": "^3.5.3",
|
|
@@ -71,7 +71,7 @@ var getLocalStorage = function () {
|
|
|
71
71
|
exports.getLocalStorage = getLocalStorage;
|
|
72
72
|
var getLocalConfig = function () {
|
|
73
73
|
var zeusStorageInfo = (0, exports.getLocalStorage)();
|
|
74
|
-
var account_env = zeusStorageInfo.account_env
|
|
74
|
+
var account_env = zeusStorageInfo.account_env === 'test' ? 'test' : 'production';
|
|
75
75
|
var LOGIN_URL = new URL(getLoginURL[account_env]);
|
|
76
76
|
var ANALYTICS_HOST = getAnalyticsHost[account_env];
|
|
77
77
|
var accountPrefix = "____".concat(LOGIN_URL.host.replace(/\./g, '_'), "__");
|
|
@@ -33,8 +33,10 @@ var path = __importStar(require("path"));
|
|
|
33
33
|
var fs = __importStar(require("fs"));
|
|
34
34
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
35
35
|
var lodash_1 = require("lodash");
|
|
36
|
+
var config_1 = require("../config");
|
|
37
|
+
var accountEnv = (0, config_1.getLocalConfig)().account_env;
|
|
36
38
|
var LOCAL_CACHE_DEVICE_PATH = path.resolve(os.homedir(), ".zepp/.zeus_devices");
|
|
37
|
-
var serverPath = 'https://upload-cdn.zepp.com/zeppos/devkit/zeus/devices.json';
|
|
39
|
+
var serverPath = accountEnv === 'test' ? 'https://upload-testing-cdn.huami.com/zeppos/devkit/zeus/devices.json' : 'https://upload-cdn.zepp.com/zeppos/devkit/zeus/devices.json';
|
|
38
40
|
var DeviceScreenType;
|
|
39
41
|
(function (DeviceScreenType) {
|
|
40
42
|
DeviceScreenType["R"] = "r";
|
package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/todo-list/app-side/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MessageBuilder } from '../shared/message-side'
|
|
2
|
+
import { DEFAULT_TODO_LIST } from './../utils/constants'
|
|
3
|
+
const messageBuilder = new MessageBuilder()
|
|
4
|
+
|
|
5
|
+
function getTodoList() {
|
|
6
|
+
return settings.settingsStorage.getItem('todoList')
|
|
7
|
+
? JSON.parse(settings.settingsStorage.getItem('todoList'))
|
|
8
|
+
: [...DEFAULT_TODO_LIST]
|
|
9
|
+
}
|
|
10
|
+
AppSideService({
|
|
11
|
+
onInit() {
|
|
12
|
+
messageBuilder.listen(() => {})
|
|
13
|
+
settings.settingsStorage.addListener('change', ({ key, newValue, oldValue }) => {
|
|
14
|
+
messageBuilder.call(getTodoList())
|
|
15
|
+
})
|
|
16
|
+
messageBuilder.on('request', (ctx) => {
|
|
17
|
+
const payload = messageBuilder.buf2Json(ctx.request.payload)
|
|
18
|
+
if (payload.method === 'GET_TODO_LIST') {
|
|
19
|
+
ctx.response({
|
|
20
|
+
data: { result: getTodoList() }
|
|
21
|
+
})
|
|
22
|
+
} else if (payload.method === 'ADD') {
|
|
23
|
+
// 这里补充一个
|
|
24
|
+
const todoList = getTodoList()
|
|
25
|
+
const newTodoList = [...todoList, String(Math.floor(Math.random() * 100))]
|
|
26
|
+
settings.settingsStorage.setItem('todoList', JSON.stringify(newTodoList))
|
|
27
|
+
|
|
28
|
+
ctx.response({
|
|
29
|
+
data: { result: newTodoList }
|
|
30
|
+
})
|
|
31
|
+
} else if (payload.method === 'DELETE') {
|
|
32
|
+
const { params: { index } = {} } = payload
|
|
33
|
+
const todoList = getTodoList()
|
|
34
|
+
const newTodoList = todoList.filter((_, i) => i !== index)
|
|
35
|
+
settings.settingsStorage.setItem('todoList', JSON.stringify(newTodoList))
|
|
36
|
+
|
|
37
|
+
ctx.response({
|
|
38
|
+
data: { result: newTodoList }
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
onRun() {},
|
|
44
|
+
onDestroy() {}
|
|
45
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import './shared/device-polyfill'
|
|
2
|
+
import { MessageBuilder } from './shared/message'
|
|
3
|
+
import { getPackageInfo } from '@zos/app'
|
|
4
|
+
import { log as Logger } from '@zos/utils'
|
|
5
|
+
import * as ble from '@zos/ble'
|
|
6
|
+
|
|
7
|
+
const logger = Logger.getLogger('todo-list-app')
|
|
8
|
+
|
|
9
|
+
App({
|
|
10
|
+
globalData: {
|
|
11
|
+
messageBuilder: null
|
|
12
|
+
},
|
|
13
|
+
onCreate() {
|
|
14
|
+
logger.log('app onCreate invoked')
|
|
15
|
+
const { appId } = getPackageInfo()
|
|
16
|
+
const messageBuilder = new MessageBuilder({ appId, appDevicePort: 20, appSidePort: 0, ble })
|
|
17
|
+
this.globalData.messageBuilder = messageBuilder
|
|
18
|
+
messageBuilder.connect()
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
onDestroy() {
|
|
22
|
+
logger.log('app onDestroy invoked')
|
|
23
|
+
this.globalData.messageBuilder && this.globalData.messageBuilder.disConnect()
|
|
24
|
+
}
|
|
25
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"configVersion": "v2",
|
|
3
|
+
"app": {
|
|
4
|
+
"appType": "app",
|
|
5
|
+
"version": {
|
|
6
|
+
"code": 1,
|
|
7
|
+
"name": "1.0.0"
|
|
8
|
+
},
|
|
9
|
+
"appId": 20001,
|
|
10
|
+
"appName": "Todo List",
|
|
11
|
+
"icon": "icon.png",
|
|
12
|
+
"vender": "zepp",
|
|
13
|
+
"description": "todo list application"
|
|
14
|
+
},
|
|
15
|
+
"runtime": {
|
|
16
|
+
"apiVersion": {
|
|
17
|
+
"compatible": "2.0.0",
|
|
18
|
+
"target": "2.0.0",
|
|
19
|
+
"minVersion": "2.0"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"targets": {
|
|
23
|
+
"gts": {
|
|
24
|
+
"module": {
|
|
25
|
+
"page": {
|
|
26
|
+
"pages": ["page/home/index.page"]
|
|
27
|
+
},
|
|
28
|
+
"app-side": {
|
|
29
|
+
"path": "app-side/index"
|
|
30
|
+
},
|
|
31
|
+
"setting": {
|
|
32
|
+
"path": "setting/index"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"designWidth": 390,
|
|
36
|
+
"platforms": [
|
|
37
|
+
{
|
|
38
|
+
"name": "gtr4",
|
|
39
|
+
"deviceSource": 7930112
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "gtr4-2",
|
|
43
|
+
"deviceSource": 7930113
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "gts4",
|
|
47
|
+
"deviceSource": 7995648
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "gts4-w",
|
|
51
|
+
"deviceSource": 7995649
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"permissions": ["data:os.device.info", "device:os.local_storage"],
|
|
57
|
+
"i18n": {
|
|
58
|
+
"en-US": {
|
|
59
|
+
"name": "Todo List"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"defaultLanguage": "en-US",
|
|
63
|
+
"debug": false
|
|
64
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createWidget, widget, prop } from '@zos/ui'
|
|
2
|
+
import { getDeviceInfo, SCREEN_SHAPE_SQUARE } from '@zos/device'
|
|
3
|
+
import { log as Logger } from '@zos/utils'
|
|
4
|
+
import { localStorage } from '@zos/storage'
|
|
5
|
+
|
|
6
|
+
import { TITLE_TEXT_STYLE, TIPS_TEXT_STYLE, SCROLL_LIST, ADD_BUTTON } from './index.style'
|
|
7
|
+
import { getScrollListDataConfig } from './../../utils/index'
|
|
8
|
+
|
|
9
|
+
const logger = Logger.getLogger('todo-list-page')
|
|
10
|
+
const { messageBuilder } = getApp()._options.globalData
|
|
11
|
+
|
|
12
|
+
Page({
|
|
13
|
+
state: {
|
|
14
|
+
scrollList: null,
|
|
15
|
+
tipText: null,
|
|
16
|
+
refreshText: null,
|
|
17
|
+
addButton: null,
|
|
18
|
+
dataList: localStorage.getItem('dataList', [])
|
|
19
|
+
},
|
|
20
|
+
onInit() {
|
|
21
|
+
logger.debug('page onInit invoked')
|
|
22
|
+
this.onMessage()
|
|
23
|
+
this.getTodoList()
|
|
24
|
+
},
|
|
25
|
+
build() {
|
|
26
|
+
logger.debug('page build invoked')
|
|
27
|
+
|
|
28
|
+
if (getDeviceInfo().screenShape !== SCREEN_SHAPE_SQUARE) {
|
|
29
|
+
this.state.title = createWidget(widget.TEXT, {
|
|
30
|
+
...TITLE_TEXT_STYLE
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.state.addButton = createWidget(widget.BUTTON, {
|
|
35
|
+
...ADD_BUTTON,
|
|
36
|
+
click_func: () => {
|
|
37
|
+
this.addRandomTodoItem()
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
this.createAndUpdateList()
|
|
42
|
+
},
|
|
43
|
+
onDestroy() {
|
|
44
|
+
logger.debug('page onDestroy invoked')
|
|
45
|
+
localStorage.setItem('dataList', this.state.dataList)
|
|
46
|
+
},
|
|
47
|
+
onMessage() {
|
|
48
|
+
messageBuilder.on('call', ({ payload: buf }) => {
|
|
49
|
+
const data = messageBuilder.buf2Json(buf)
|
|
50
|
+
const dataList = data.map((i) => ({ name: i }))
|
|
51
|
+
logger.log('call dataList', dataList)
|
|
52
|
+
this.refreshAndUpdate(dataList)
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
getTodoList() {
|
|
56
|
+
messageBuilder
|
|
57
|
+
.request({
|
|
58
|
+
method: 'GET_TODO_LIST'
|
|
59
|
+
})
|
|
60
|
+
.then(({ result }) => {
|
|
61
|
+
this.state.dataList = result.map((d) => ({ name: d }))
|
|
62
|
+
logger.log('GET_TODO_LIST dataList', this.state.dataList)
|
|
63
|
+
this.createAndUpdateList()
|
|
64
|
+
})
|
|
65
|
+
.catch((res) => {})
|
|
66
|
+
},
|
|
67
|
+
addRandomTodoItem() {
|
|
68
|
+
messageBuilder
|
|
69
|
+
.request({
|
|
70
|
+
method: 'ADD'
|
|
71
|
+
})
|
|
72
|
+
.then(({ result }) => {
|
|
73
|
+
this.state.dataList = result.map((d) => ({ name: d }))
|
|
74
|
+
this.createAndUpdateList()
|
|
75
|
+
})
|
|
76
|
+
.catch((res) => {})
|
|
77
|
+
},
|
|
78
|
+
deleteTodoItem(index) {
|
|
79
|
+
messageBuilder
|
|
80
|
+
.request({
|
|
81
|
+
method: 'DELETE',
|
|
82
|
+
params: { index }
|
|
83
|
+
})
|
|
84
|
+
.then(({ result }) => {
|
|
85
|
+
const dataList = result.map((d) => ({ name: d }))
|
|
86
|
+
|
|
87
|
+
this.refreshAndUpdate(dataList)
|
|
88
|
+
})
|
|
89
|
+
.catch((res) => {})
|
|
90
|
+
},
|
|
91
|
+
changeUI(showEmpty) {
|
|
92
|
+
const { dataList } = this.state
|
|
93
|
+
|
|
94
|
+
if (showEmpty) {
|
|
95
|
+
if (dataList.length === 0) {
|
|
96
|
+
!this.state.tipText &&
|
|
97
|
+
(this.state.tipText = createWidget(widget.TEXT, {
|
|
98
|
+
...TIPS_TEXT_STYLE
|
|
99
|
+
}))
|
|
100
|
+
}
|
|
101
|
+
const isTip = dataList.length === 0
|
|
102
|
+
|
|
103
|
+
this.state.refreshText && this.state.refreshText.setProperty(prop.VISIBLE, false)
|
|
104
|
+
this.state.tipText && this.state.tipText.setProperty(prop.VISIBLE, isTip)
|
|
105
|
+
this.state.scrollList && this.state.scrollList.setProperty(prop.VISIBLE, !isTip)
|
|
106
|
+
} else {
|
|
107
|
+
// 占位刷新
|
|
108
|
+
!this.state.refreshText &&
|
|
109
|
+
(this.state.refreshText = createWidget(widget.TEXT, {
|
|
110
|
+
...TIPS_TEXT_STYLE,
|
|
111
|
+
text: ' '
|
|
112
|
+
}))
|
|
113
|
+
|
|
114
|
+
this.state.tipText && this.state.tipText.setProperty(prop.VISIBLE, false)
|
|
115
|
+
this.state.refreshText.setProperty(prop.VISIBLE, true)
|
|
116
|
+
this.state.scrollList && this.state.scrollList.setProperty(prop.VISIBLE, false)
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
createAndUpdateList(showEmpty = true) {
|
|
120
|
+
const _scrollListItemClick = (list, index) => {
|
|
121
|
+
this.deleteTodoItem(index)
|
|
122
|
+
}
|
|
123
|
+
const { scrollList, dataList } = this.state
|
|
124
|
+
this.changeUI(showEmpty)
|
|
125
|
+
const dataTypeConfig = getScrollListDataConfig(dataList.length === 0 ? -1 : 0, dataList.length)
|
|
126
|
+
if (scrollList) {
|
|
127
|
+
scrollList.setProperty(prop.UPDATE_DATA, {
|
|
128
|
+
data_array: dataList,
|
|
129
|
+
data_count: dataList.length,
|
|
130
|
+
data_type_config: [{ start: 0, end: dataList.length, type_id: 2 }],
|
|
131
|
+
data_type_config_count: dataTypeConfig.length,
|
|
132
|
+
on_page: 1
|
|
133
|
+
})
|
|
134
|
+
} else {
|
|
135
|
+
this.state.scrollList = createWidget(widget.SCROLL_LIST, {
|
|
136
|
+
...(SCROLL_LIST || {}),
|
|
137
|
+
data_array: dataList,
|
|
138
|
+
data_count: dataList.length,
|
|
139
|
+
data_type_config: dataTypeConfig,
|
|
140
|
+
data_type_config_count: dataTypeConfig.length,
|
|
141
|
+
on_page: 1,
|
|
142
|
+
item_click_func: _scrollListItemClick
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
refreshAndUpdate(dataList = []) {
|
|
147
|
+
this.state.dataList = []
|
|
148
|
+
this.createAndUpdateList(false)
|
|
149
|
+
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
this.state.dataList = dataList
|
|
152
|
+
this.createAndUpdateList()
|
|
153
|
+
}, 20)
|
|
154
|
+
}
|
|
155
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { align, text_style } from '@zos/ui'
|
|
2
|
+
import { getText } from '@zos/i18n'
|
|
3
|
+
import { getDeviceInfo } from '@zos/device'
|
|
4
|
+
import { px } from '@zos/utils'
|
|
5
|
+
|
|
6
|
+
export const { width: DEVICE_WIDTH, height: DEVICE_HEIGHT } = getDeviceInfo()
|
|
7
|
+
|
|
8
|
+
export const TITLE_TEXT_STYLE = {
|
|
9
|
+
text: getText('todoList'),
|
|
10
|
+
x: px(42),
|
|
11
|
+
y: px(65),
|
|
12
|
+
w: DEVICE_WIDTH - px(42 * 2),
|
|
13
|
+
h: px(50),
|
|
14
|
+
color: 0xffffff,
|
|
15
|
+
text_size: 36,
|
|
16
|
+
align_h: align.CENTER_H,
|
|
17
|
+
text_style: text_style.WRAP,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ADD_BUTTON = {
|
|
21
|
+
text: getText('add'),
|
|
22
|
+
x: px(30),
|
|
23
|
+
y: px(65),
|
|
24
|
+
w: px(80),
|
|
25
|
+
h: px(50),
|
|
26
|
+
normal_color: 0xfc6950,
|
|
27
|
+
press_color: 0xfeb4a8,
|
|
28
|
+
radius: px(12)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const TIPS_TEXT_STYLE = {
|
|
32
|
+
text: getText('noData'),
|
|
33
|
+
x: px(15),
|
|
34
|
+
y: px(120),
|
|
35
|
+
w: DEVICE_WIDTH - px(15 * 2),
|
|
36
|
+
h: DEVICE_HEIGHT - px(120),
|
|
37
|
+
color: 0xffffff,
|
|
38
|
+
text_size: 32,
|
|
39
|
+
align_h: align.CENTER_H,
|
|
40
|
+
align_v: align.CENTER_V,
|
|
41
|
+
text_style: text_style.WRAP,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const SCROLL_LIST = {
|
|
45
|
+
item_height: px(80),
|
|
46
|
+
item_space: px(6),
|
|
47
|
+
item_config: [
|
|
48
|
+
{
|
|
49
|
+
type_id: 1,
|
|
50
|
+
item_bg_color: 0x333333,
|
|
51
|
+
item_bg_radius: px(10),
|
|
52
|
+
text_view: [
|
|
53
|
+
{
|
|
54
|
+
x: px(80),
|
|
55
|
+
y: px(0),
|
|
56
|
+
w: px(360),
|
|
57
|
+
h: px(80),
|
|
58
|
+
key: 'name',
|
|
59
|
+
color: 0xffff00,
|
|
60
|
+
text_size: px(36),
|
|
61
|
+
align_h: align.LEFT,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
text_view_count: 1,
|
|
65
|
+
item_height: px(80)
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type_id: 2,
|
|
69
|
+
item_bg_color: 0x333333,
|
|
70
|
+
item_bg_radius: px(10),
|
|
71
|
+
text_view: [
|
|
72
|
+
{
|
|
73
|
+
x: px(80),
|
|
74
|
+
y: px(0),
|
|
75
|
+
w: px(360),
|
|
76
|
+
h: px(80),
|
|
77
|
+
key: 'name',
|
|
78
|
+
color: 0xff0000,
|
|
79
|
+
text_size: px(36),
|
|
80
|
+
align_h: align.LEFT,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
text_view_count: 1,
|
|
84
|
+
item_height: px(80)
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
item_config_count: 2,
|
|
88
|
+
x: px(30),
|
|
89
|
+
y: px(120),
|
|
90
|
+
h: DEVICE_HEIGHT - px(180),
|
|
91
|
+
w: DEVICE_WIDTH - px(30) * 2
|
|
92
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { createWidget, widget, prop } from '@zos/ui'
|
|
2
|
+
import { getDeviceInfo, SCREEN_SHAPE_SQUARE } from '@zos/device'
|
|
3
|
+
import { log as Logger } from '@zos/utils'
|
|
4
|
+
|
|
5
|
+
import { TITLE_TEXT_STYLE, TIPS_TEXT_STYLE, SCROLL_LIST, ADD_BUTTON } from '../page/home/index.style'
|
|
6
|
+
import { readFileSync, writeFileSync } from '../utils/fs'
|
|
7
|
+
import { getScrollListDataConfig } from '../utils/index'
|
|
8
|
+
|
|
9
|
+
const logger = Logger.getLogger('todo-list-page')
|
|
10
|
+
const { messageBuilder } = getApp()._options.globalData
|
|
11
|
+
|
|
12
|
+
SecondaryWidget({
|
|
13
|
+
state: {
|
|
14
|
+
scrollList: null,
|
|
15
|
+
tipText: null,
|
|
16
|
+
refreshText: null,
|
|
17
|
+
addButton: null,
|
|
18
|
+
dataList: readFileSync()
|
|
19
|
+
},
|
|
20
|
+
onInit() {
|
|
21
|
+
logger.debug('page onInit invoked')
|
|
22
|
+
this.onMessage()
|
|
23
|
+
this.getTodoList()
|
|
24
|
+
},
|
|
25
|
+
build() {
|
|
26
|
+
logger.debug('page build invoked')
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
if (getDeviceInfo().screenShape !== SCREEN_SHAPE_SQUARE) {
|
|
30
|
+
this.state.title = createWidget(widget.TEXT, {
|
|
31
|
+
...TITLE_TEXT_STYLE
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.state.addButton = createWidget(widget.BUTTON, {
|
|
36
|
+
...ADD_BUTTON,
|
|
37
|
+
click_func: () => {
|
|
38
|
+
this.addRandomTodoItem()
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
this.createAndUpdateList()
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.log('LifeCycle Error', e)
|
|
45
|
+
e && e.stack && e.stack.split(/\n/).forEach((i) => console.log('error stack', i))
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
onDestroy() {
|
|
49
|
+
logger.debug('page onDestroy invoked')
|
|
50
|
+
writeFileSync(this.state.dataList, false)
|
|
51
|
+
},
|
|
52
|
+
onMessage() {
|
|
53
|
+
messageBuilder.on('call', ({ payload: buf }) => {
|
|
54
|
+
const data = messageBuilder.buf2Json(buf)
|
|
55
|
+
const dataList = data.map((i) => ({ name: i }))
|
|
56
|
+
logger.log('call dataList', dataList)
|
|
57
|
+
this.refreshAndUpdate(dataList)
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
getTodoList() {
|
|
61
|
+
messageBuilder
|
|
62
|
+
.request({
|
|
63
|
+
method: 'GET_TODO_LIST'
|
|
64
|
+
})
|
|
65
|
+
.then(({ result }) => {
|
|
66
|
+
this.state.dataList = result.map((d) => ({ name: d }))
|
|
67
|
+
logger.log('GET_TODO_LIST dataList', this.state.dataList)
|
|
68
|
+
this.createAndUpdateList()
|
|
69
|
+
})
|
|
70
|
+
.catch((res) => {})
|
|
71
|
+
},
|
|
72
|
+
addRandomTodoItem() {
|
|
73
|
+
messageBuilder
|
|
74
|
+
.request({
|
|
75
|
+
method: 'ADD'
|
|
76
|
+
})
|
|
77
|
+
.then(({ result }) => {
|
|
78
|
+
this.state.dataList = result.map((d) => ({ name: d }))
|
|
79
|
+
this.createAndUpdateList()
|
|
80
|
+
})
|
|
81
|
+
.catch((res) => {})
|
|
82
|
+
},
|
|
83
|
+
deleteTodoItem(index) {
|
|
84
|
+
messageBuilder
|
|
85
|
+
.request({
|
|
86
|
+
method: 'DELETE',
|
|
87
|
+
params: { index }
|
|
88
|
+
})
|
|
89
|
+
.then(({ result }) => {
|
|
90
|
+
const dataList = result.map((d) => ({ name: d }))
|
|
91
|
+
|
|
92
|
+
this.refreshAndUpdate(dataList)
|
|
93
|
+
})
|
|
94
|
+
.catch((res) => {})
|
|
95
|
+
},
|
|
96
|
+
changeUI(showEmpty) {
|
|
97
|
+
const { dataList } = this.state
|
|
98
|
+
|
|
99
|
+
if (showEmpty) {
|
|
100
|
+
if (dataList.length === 0) {
|
|
101
|
+
!this.state.tipText &&
|
|
102
|
+
(this.state.tipText = createWidget(widget.TEXT, {
|
|
103
|
+
...TIPS_TEXT_STYLE
|
|
104
|
+
}))
|
|
105
|
+
}
|
|
106
|
+
const isTip = dataList.length === 0
|
|
107
|
+
|
|
108
|
+
this.state.refreshText && this.state.refreshText.setProperty(prop.VISIBLE, false)
|
|
109
|
+
this.state.tipText && this.state.tipText.setProperty(prop.VISIBLE, isTip)
|
|
110
|
+
this.state.scrollList && this.state.scrollList.setProperty(prop.VISIBLE, !isTip)
|
|
111
|
+
} else {
|
|
112
|
+
// 占位刷新
|
|
113
|
+
!this.state.refreshText &&
|
|
114
|
+
(this.state.refreshText = createWidget(widget.TEXT, {
|
|
115
|
+
...TIPS_TEXT_STYLE,
|
|
116
|
+
text: ' '
|
|
117
|
+
}))
|
|
118
|
+
|
|
119
|
+
this.state.tipText && this.state.tipText.setProperty(prop.VISIBLE, false)
|
|
120
|
+
this.state.refreshText.setProperty(prop.VISIBLE, true)
|
|
121
|
+
this.state.scrollList && this.state.scrollList.setProperty(prop.VISIBLE, false)
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
createAndUpdateList(showEmpty = true) {
|
|
125
|
+
const _scrollListItemClick = (list, index) => {
|
|
126
|
+
this.deleteTodoItem(index)
|
|
127
|
+
}
|
|
128
|
+
const { scrollList, dataList } = this.state
|
|
129
|
+
this.changeUI(showEmpty)
|
|
130
|
+
const dataTypeConfig = getScrollListDataConfig(dataList.length === 0 ? -1 : 0, dataList.length)
|
|
131
|
+
if (scrollList) {
|
|
132
|
+
scrollList.setProperty(prop.UPDATE_DATA, {
|
|
133
|
+
data_array: dataList,
|
|
134
|
+
data_count: dataList.length,
|
|
135
|
+
data_type_config: [{ start: 0, end: dataList.length, type_id: 2 }],
|
|
136
|
+
data_type_config_count: dataTypeConfig.length,
|
|
137
|
+
on_page: 1
|
|
138
|
+
})
|
|
139
|
+
} else {
|
|
140
|
+
this.state.scrollList = createWidget(widget.SCROLL_LIST, {
|
|
141
|
+
...(SCROLL_LIST || {}),
|
|
142
|
+
data_array: dataList,
|
|
143
|
+
data_count: dataList.length,
|
|
144
|
+
data_type_config: dataTypeConfig,
|
|
145
|
+
data_type_config_count: dataTypeConfig.length,
|
|
146
|
+
on_page: 1,
|
|
147
|
+
item_click_func: _scrollListItemClick
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
refreshAndUpdate(dataList = []) {
|
|
152
|
+
this.state.dataList = []
|
|
153
|
+
this.createAndUpdateList(false)
|
|
154
|
+
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
this.state.dataList = dataList
|
|
157
|
+
this.createAndUpdateList()
|
|
158
|
+
}, 20)
|
|
159
|
+
}
|
|
160
|
+
})
|