@zeppos/zeus-cli 1.3.6 → 1.3.7
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/main.js +8 -8
- package/modules/build.js +5 -3
- package/modules/create.js +6 -5
- package/package.json +1 -1
- package/private-modules/zeppos-app-utils/dist/config/device.js +105 -45
- package/private-modules/zeppos-app-utils/dist/modules/create/local-app.js +3 -2
- package/private-modules/zeppos-app-utils/dist/modules/fetchDevices.js +87 -0
- package/private-modules/zeppos-app-utils/dist/modules/index.js +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os1.0/app/fetch-api/app-side/index.js +6 -18
- package/private-modules/zeppos-app-utils/dist/public/template/os1.0/app/fetch-api/pages/index.js +6 -6
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/app-side/index.js +6 -18
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/pages/index.js +6 -6
- package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/app-side/index.js +7 -35
- package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/page/index.js +1 -1
- package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/page/index.r.layout.js +8 -8
- package/private-modules/zeppos-app-utils/dist/public/template/os3.0/app/fetch-api/page/index.s.layout.js +1 -1
- package/private-modules/zeppos-app-utils/dist/tools/index.js +2 -1
- package/private-modules/zeppos-app-utils/dist/config/device-server.js +0 -116
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/.prettierrc.js +0 -6
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/app-side/index.js +0 -45
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/app.js +0 -25
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/app.json +0 -64
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/assets/gts/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/page/home/index.page.js +0 -155
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/page/home/index.page.json +0 -1
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/page/home/index.style.js +0 -92
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/page/i18n/en-US.po +0 -9
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/secondary-widget/index.js +0 -160
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/setting/i18n/en-US.po +0 -5
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/setting/index.js +0 -143
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/shared/data.js +0 -67
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/shared/defer.js +0 -35
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/shared/device-polyfill.js +0 -6
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/shared/es6-promise.js +0 -1178
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/shared/event.js +0 -42
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/shared/message-side.js +0 -1190
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/shared/message.js +0 -1196
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/utils/constants.js +0 -1
- package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/utils/index.js +0 -38
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
exports.__esModule = true;
|
|
29
|
-
exports.DeviceScreenType = void 0;
|
|
30
|
-
var axios_1 = __importDefault(require("axios"));
|
|
31
|
-
var os = __importStar(require("os"));
|
|
32
|
-
var path = __importStar(require("path"));
|
|
33
|
-
var fs = __importStar(require("fs"));
|
|
34
|
-
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
35
|
-
var lodash_1 = require("lodash");
|
|
36
|
-
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';
|
|
38
|
-
var DeviceScreenType;
|
|
39
|
-
(function (DeviceScreenType) {
|
|
40
|
-
DeviceScreenType["R"] = "r";
|
|
41
|
-
DeviceScreenType["S"] = "s";
|
|
42
|
-
DeviceScreenType["B"] = "b";
|
|
43
|
-
})(DeviceScreenType = exports.DeviceScreenType || (exports.DeviceScreenType = {}));
|
|
44
|
-
var shapeMap = {
|
|
45
|
-
square: DeviceScreenType.S,
|
|
46
|
-
round: DeviceScreenType.R,
|
|
47
|
-
bar: DeviceScreenType.B
|
|
48
|
-
};
|
|
49
|
-
var localContent = {};
|
|
50
|
-
if (fs.existsSync(LOCAL_CACHE_DEVICE_PATH)) {
|
|
51
|
-
try {
|
|
52
|
-
localContent = fs_extra_1["default"].readJsonSync(LOCAL_CACHE_DEVICE_PATH);
|
|
53
|
-
}
|
|
54
|
-
catch (_e) { }
|
|
55
|
-
}
|
|
56
|
-
var now = Date.now().valueOf();
|
|
57
|
-
if (!((0, lodash_1.get)(localContent, 'expiredTime') > now)) {
|
|
58
|
-
axios_1["default"].get(serverPath).then(function (res) {
|
|
59
|
-
if (res.status === 200) {
|
|
60
|
-
var data = res.data;
|
|
61
|
-
if (!(0, lodash_1.isEmpty)(data)) {
|
|
62
|
-
fs_extra_1["default"].writeJsonSync(LOCAL_CACHE_DEVICE_PATH, {
|
|
63
|
-
devices: data,
|
|
64
|
-
expiredTime: now + 24 * 60 * 60 * 1000
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
})["catch"](function (e) {
|
|
69
|
-
console.log(e);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
var deviceList = (0, lodash_1.get)(localContent, 'devices', []);
|
|
74
|
-
var deviceGroup = (0, lodash_1.groupBy)(deviceList, 'productName');
|
|
75
|
-
var deviceInfo = {};
|
|
76
|
-
Object.values(deviceGroup).forEach(function (devices) {
|
|
77
|
-
var _a;
|
|
78
|
-
var info = {
|
|
79
|
-
deviceName: '',
|
|
80
|
-
platforms: [],
|
|
81
|
-
screen: {
|
|
82
|
-
type: DeviceScreenType.R,
|
|
83
|
-
width: 0,
|
|
84
|
-
height: 0
|
|
85
|
-
},
|
|
86
|
-
apiLevelLimit: {
|
|
87
|
-
min: '1.0.0'
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
var deviceInnerName = devices.reduce(function (acc, cur) {
|
|
91
|
-
!info.deviceName && (info.deviceName = cur.productName);
|
|
92
|
-
var screenType = (0, lodash_1.get)(shapeMap, (0, lodash_1.get)(cur, 'value.shape'));
|
|
93
|
-
var _a = (0, lodash_1.get)(cur, 'value.screen.size', '').split('*'), width = _a[0], height = _a[1];
|
|
94
|
-
if (screenType) {
|
|
95
|
-
info.screen.type = screenType;
|
|
96
|
-
}
|
|
97
|
-
if (width && height) {
|
|
98
|
-
info.screen.width = Number(width);
|
|
99
|
-
info.screen.height = Number(height);
|
|
100
|
-
}
|
|
101
|
-
info.platforms.push({
|
|
102
|
-
name: cur.code,
|
|
103
|
-
deviceSource: cur.deviceSource
|
|
104
|
-
});
|
|
105
|
-
Object.assign(info.apiLevelLimit, {
|
|
106
|
-
min: (0, lodash_1.get)(cur, 'value.os.apiLevelLimitMin', '1.0.0'),
|
|
107
|
-
max: (0, lodash_1.get)(cur, 'value.os.version', '')
|
|
108
|
-
});
|
|
109
|
-
return cur.code.length < acc.length ? cur.code : acc;
|
|
110
|
-
}, devices[0].code);
|
|
111
|
-
var lowerName = (0, lodash_1.toLower)(deviceInnerName.replace(/[^a-zA-Z]/g, ''));
|
|
112
|
-
lowerName && Object.assign(deviceInfo, (_a = {},
|
|
113
|
-
_a[lowerName] = info,
|
|
114
|
-
_a));
|
|
115
|
-
});
|
|
116
|
-
exports["default"] = deviceInfo;
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
})
|
package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/app.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
})
|
package/private-modules/zeppos-app-utils/dist/public/template/os2.0/app/fetch-api/todo-list/app.json
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
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
|
|
@@ -1,155 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
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
|
-
})
|