@ray-js/api 1.4.0-alpha.3 → 1.4.0-alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/BaseKit-3.3.10.js +85 -83
- package/lib/BizKit-3.2.7.js +48 -47
- package/lib/DeviceKit-3.3.1.js +194 -193
- package/lib/HomeKit-3.1.4.js +2 -1
- package/lib/MapKit-3.0.7.js +4 -2
- package/lib/MiniKit-3.1.0.js +65 -64
- package/lib/PlayNetKit-1.1.3.js +2 -1
- package/lib/cloud/alarm.js +4 -7
- package/lib/cloud/core.js +2 -3
- package/lib/cloud/device.js +20 -31
- package/lib/cloud/interface.d.ts +7 -7
- package/lib/cloud/linkage.js +43 -41
- package/lib/cloud/statistic.js +21 -33
- package/lib/cloud/timer.js +31 -48
- package/lib/constants.js +1 -1
- package/lib/core/promisify/index.js +5 -9
- package/lib/getBoundingClientRect/index.js +16 -17
- package/lib/getBoundingClientRect/index.thing.js +16 -17
- package/lib/getBoundingClientRect/index.wechat.js +16 -17
- package/lib/getCdnUrl/index.thing.js +4 -7
- package/lib/getElementById/index.js +1 -3
- package/lib/getElementById/index.thing.js +2 -4
- package/lib/getElementById/index.wechat.js +2 -4
- package/lib/hideTabBar/index.d.ts +7 -1
- package/lib/index.js +3 -2
- package/lib/lifecycles/offAppEvent/index.js +2 -2
- package/lib/lifecycles/offAppHide/index.js +2 -2
- package/lib/lifecycles/offAppShow/index.js +2 -2
- package/lib/lifecycles/offError/index.js +2 -2
- package/lib/lifecycles/offThemeChange/index.js +2 -2
- package/lib/lifecycles/offWindowResize/index.js +2 -2
- package/lib/lifecycles/onAppEvent/index.js +2 -2
- package/lib/lifecycles/onAppHide/index.js +2 -2
- package/lib/lifecycles/onAppShow/index.js +2 -2
- package/lib/lifecycles/onError/index.js +2 -2
- package/lib/lifecycles/onPageNotFound/index.js +2 -2
- package/lib/lifecycles/onThemeChange/index.js +2 -2
- package/lib/lifecycles/onWindowResize/index.js +2 -2
- package/lib/navigateBack/index.js +3 -6
- package/lib/navigateTo/index.js +2 -5
- package/lib/onNavigationBarBack/index.js +1 -2
- package/lib/onNavigationBarBack/index.wechat.js +1 -2
- package/lib/panel/devInfo/index.js +84 -121
- package/lib/panel/i18n/index.d.ts +1 -1
- package/lib/panel/i18n/index.js +180 -262
- package/lib/panel/i18n/index.wechat.d.ts +1 -1
- package/lib/panel/i18n/index.wechat.js +184 -267
- package/lib/panel/normalizeNetwork.d.ts +2 -2
- package/lib/panel/normalizeNetwork.js +2 -7
- package/lib/panel/publishDps.d.ts +1 -1
- package/lib/panel/publishDps.js +13 -18
- package/lib/panel/types/devInfo.d.ts +3 -3
- package/lib/panel/types/utilities.d.ts +8 -8
- package/lib/panel/utils.js +1 -3
- package/lib/reLaunch/index.js +2 -5
- package/lib/redirectTo/index.js +2 -6
- package/lib/requestCloud/index.js +2 -2
- package/lib/requestCloud/index.wechat.js +0 -1
- package/lib/setNavigationBarBack/index.js +1 -2
- package/lib/setNavigationBarBack/index.wechat.js +1 -2
- package/lib/setNavigationBarColor/index.js +3 -6
- package/lib/setNavigationBarTitle/index.js +5 -6
- package/lib/showTabBar/index.d.ts +7 -1
- package/lib/switchTab/index.js +2 -5
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +5 -14
- package/lib/utils.wechat.d.ts +1 -1
- package/lib/utils.wechat.js +9 -21
- package/lib/viewAPI.js +13 -12
- package/package.json +7 -7
- package/LICENSE.md +0 -9
@@ -1,295 +1,212 @@
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
3
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
4
|
-
import "core-js/modules/es.object.keys.js";
|
5
|
-
import "core-js/modules/es.object.assign.js";
|
6
|
-
import "core-js/modules/es.array.map.js";
|
7
|
-
import "core-js/modules/es.regexp.exec.js";
|
8
|
-
import "core-js/modules/es.regexp.test.js";
|
9
|
-
import "core-js/modules/es.array.last-index-of.js";
|
10
1
|
import "core-js/modules/es.string.replace.js";
|
11
|
-
import "core-js/modules/es.regexp.constructor.js";
|
12
|
-
import "core-js/modules/es.regexp.dot-all.js";
|
13
|
-
import "core-js/modules/es.regexp.sticky.js";
|
14
|
-
import "core-js/modules/es.regexp.to-string.js";
|
15
|
-
import "core-js/modules/es.array.concat.js";
|
16
|
-
import "core-js/modules/es.parse-float.js";
|
17
2
|
import { requestCloud, getSystemInfoSync, THING } from '../..';
|
18
|
-
import { getBitValue } from '../utils';
|
3
|
+
import { getBitValue } from '../utils';
|
19
4
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
5
|
+
// 微信小程序暂时只支持本地多语言
|
6
|
+
const I18n = {
|
7
|
+
t: key => key
|
24
8
|
};
|
25
|
-
|
26
|
-
|
27
|
-
function I18N(props) {
|
28
|
-
_classCallCheck(this, I18N);
|
29
|
-
|
9
|
+
export default class I18N {
|
10
|
+
constructor(props) {
|
30
11
|
this.strings = this.mergeLanguage(props, {});
|
31
12
|
this.defaultLang = this.strings.en ? 'en' : Object.keys(this.strings)[0];
|
32
13
|
this.setLanguage(this.defaultLang);
|
33
|
-
|
14
|
+
const langKey = getSystemInfoSync().language;
|
34
15
|
this.setLanguage(langKey);
|
35
16
|
}
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
// @ts-ignore
|
52
|
-
success: function success(data) {
|
53
|
-
if (data) {
|
54
|
-
_this.strings = _this.mergeLanguage(_this.strings, data);
|
55
|
-
|
56
|
-
_this.buildLanguage(_this.__language);
|
57
|
-
}
|
17
|
+
forceUpdateNetworkLang(productId) {
|
18
|
+
requestCloud({
|
19
|
+
api: "".concat(THING, ".m.i18n.get"),
|
20
|
+
version: '1.0',
|
21
|
+
data: {
|
22
|
+
productId,
|
23
|
+
moduleName: 'h5',
|
24
|
+
endId: 2,
|
25
|
+
osId: 0
|
26
|
+
},
|
27
|
+
// @ts-ignore
|
28
|
+
success: data => {
|
29
|
+
if (data) {
|
30
|
+
this.strings = this.mergeLanguage(this.strings, data);
|
31
|
+
this.buildLanguage(this.__language);
|
58
32
|
}
|
59
|
-
});
|
60
|
-
}
|
61
|
-
}, {
|
62
|
-
key: "mergeLanguage",
|
63
|
-
value: function mergeLanguage(L1, L2) {
|
64
|
-
if (typeof L1 === 'undefined' && typeof L2 === 'undefined') return {};
|
65
|
-
if (typeof L1 === 'undefined') return L2;
|
66
|
-
if (typeof L2 === 'undefined') return L1;
|
67
|
-
var L0 = Object.assign({}, L1);
|
68
|
-
Object.keys(L2).map(function (k) {
|
69
|
-
if (typeof L0[k] !== 'undefined') {
|
70
|
-
Object.assign(L0[k], L2[k]);
|
71
|
-
} else {
|
72
|
-
L0[k] = Object.assign({}, L2[k]);
|
73
|
-
}
|
74
|
-
|
75
|
-
return null;
|
76
|
-
});
|
77
|
-
return L0;
|
78
|
-
}
|
79
|
-
}, {
|
80
|
-
key: "isZh",
|
81
|
-
value: function isZh(language) {
|
82
|
-
/**
|
83
|
-
* ios 的中文简体固定为 zh-Hans,
|
84
|
-
* 但安卓的中文简体可能有一大堆排列组件 = =,如 zh_CN、zh_cn、zh_Hans_CH、zh_hans_cn 等等;
|
85
|
-
*/
|
86
|
-
|
87
|
-
/**
|
88
|
-
* 如果匹配到位中文简体地区,
|
89
|
-
* 则将中文 zh 相关的 values 都写入到 this.strings 下,保证兜底本地 zh 相关的能取到,
|
90
|
-
* 再将当前地区 key 相关的 values 都写入到 this.strings 下,优先级最高;
|
91
|
-
*/
|
92
|
-
if (typeof language === 'string' && /^zh-hans$|^zh_hans$|^zh_cn$|^zh-cn$|^zh_hans_\w+|^zh-hans-\w+/.test(language.toLowerCase())) {
|
93
|
-
return true;
|
94
33
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
if (
|
104
|
-
|
105
|
-
this.buildLanguage(language);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
mergeLanguage(L1, L2) {
|
37
|
+
if (typeof L1 === 'undefined' && typeof L2 === 'undefined') return {};
|
38
|
+
if (typeof L1 === 'undefined') return L2;
|
39
|
+
if (typeof L2 === 'undefined') return L1;
|
40
|
+
const L0 = Object.assign({}, L1);
|
41
|
+
Object.keys(L2).map(k => {
|
42
|
+
if (typeof L0[k] !== 'undefined') {
|
43
|
+
Object.assign(L0[k], L2[k]);
|
106
44
|
} else {
|
107
|
-
|
108
|
-
}
|
109
|
-
}
|
110
|
-
}, {
|
111
|
-
key: "buildLanguage",
|
112
|
-
value: function buildLanguage(language) {
|
113
|
-
var _this2 = this;
|
114
|
-
|
115
|
-
if (this.strings[language]) {
|
116
|
-
var localizedStrings = this.strings[language];
|
117
|
-
Object.keys(localizedStrings).map(function (key) {
|
118
|
-
// eslint-disable-next-line no-prototype-builtins
|
119
|
-
if (localizedStrings.hasOwnProperty(key)) {
|
120
|
-
_this2[key] = localizedStrings[key];
|
121
|
-
}
|
122
|
-
|
123
|
-
return null;
|
124
|
-
});
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}, {
|
128
|
-
key: "_getBestMatchingLanguage",
|
129
|
-
value: function _getBestMatchingLanguage(language, props) {
|
130
|
-
if (props[language]) return language;
|
131
|
-
var idx = language.lastIndexOf('-');
|
132
|
-
|
133
|
-
if (idx >= 0) {
|
134
|
-
var lang = language.substring(0, idx);
|
135
|
-
return this._getBestMatchingLanguage(lang, props);
|
136
|
-
}
|
137
|
-
|
138
|
-
var underlineIdx = language.lastIndexOf('_');
|
139
|
-
|
140
|
-
if (underlineIdx >= 0) {
|
141
|
-
var _lang = language.substring(0, underlineIdx);
|
142
|
-
|
143
|
-
return this._getBestMatchingLanguage(_lang, props);
|
144
|
-
}
|
145
|
-
|
146
|
-
return this.defaultLang;
|
147
|
-
} // Format the passed string replacing the numbered placeholders
|
148
|
-
// i.e. I'd like some {0} and {1}, or just {0}
|
149
|
-
// Use example:
|
150
|
-
// strings.formatString(strings.question, strings.bread, strings.butter)
|
151
|
-
|
152
|
-
}, {
|
153
|
-
key: "formatString",
|
154
|
-
value: function formatString(str) {
|
155
|
-
var res = str;
|
156
|
-
|
157
|
-
for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
|
158
|
-
res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
|
45
|
+
L0[k] = Object.assign({}, L2[k]);
|
159
46
|
}
|
47
|
+
return null;
|
48
|
+
});
|
49
|
+
return L0;
|
50
|
+
}
|
51
|
+
isZh(language) {
|
52
|
+
/**
|
53
|
+
* ios 的中文简体固定为 zh-Hans,
|
54
|
+
* 但安卓的中文简体可能有一大堆排列组件 = =,如 zh_CN、zh_cn、zh_Hans_CH、zh_hans_cn 等等;
|
55
|
+
*/
|
160
56
|
|
161
|
-
|
57
|
+
/**
|
58
|
+
* 如果匹配到位中文简体地区,
|
59
|
+
* 则将中文 zh 相关的 values 都写入到 this.strings 下,保证兜底本地 zh 相关的能取到,
|
60
|
+
* 再将当前地区 key 相关的 values 都写入到 this.strings 下,优先级最高;
|
61
|
+
*/
|
62
|
+
if (typeof language === 'string' && /^zh-hans$|^zh_hans$|^zh_cn$|^zh-cn$|^zh_hans_\w+|^zh-hans-\w+/.test(language.toLowerCase())) {
|
63
|
+
return true;
|
162
64
|
}
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
return res;
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
setLanguage(language) {
|
68
|
+
this.__language = language;
|
69
|
+
if (this.isZh(language)) {
|
70
|
+
this.buildLanguage('zh');
|
71
|
+
this.buildLanguage(language);
|
72
|
+
} else {
|
73
|
+
this.buildLanguage(this.__language);
|
173
74
|
}
|
174
|
-
}
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
75
|
+
}
|
76
|
+
buildLanguage(language) {
|
77
|
+
if (this.strings[language]) {
|
78
|
+
const localizedStrings = this.strings[language];
|
79
|
+
Object.keys(localizedStrings).map(key => {
|
80
|
+
// eslint-disable-next-line no-prototype-builtins
|
81
|
+
if (localizedStrings.hasOwnProperty(key)) {
|
82
|
+
this[key] = localizedStrings[key];
|
83
|
+
}
|
84
|
+
return null;
|
85
|
+
});
|
181
86
|
}
|
182
|
-
}
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
} else if (typeof value === 'boolean') {
|
190
|
-
var valStr = value ? 'on' : 'off';
|
191
|
-
key = "dp_".concat(code, "_").concat(valStr).toLowerCase();
|
192
|
-
} else {
|
193
|
-
key = "dp_".concat(code, "_").concat(value).toLowerCase();
|
194
|
-
}
|
195
|
-
|
196
|
-
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
87
|
+
}
|
88
|
+
_getBestMatchingLanguage(language, props) {
|
89
|
+
if (props[language]) return language;
|
90
|
+
const idx = language.lastIndexOf('-');
|
91
|
+
if (idx >= 0) {
|
92
|
+
const lang = language.substring(0, idx);
|
93
|
+
return this._getBestMatchingLanguage(lang, props);
|
197
94
|
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
|
95
|
+
const underlineIdx = language.lastIndexOf('_');
|
96
|
+
if (underlineIdx >= 0) {
|
97
|
+
const lang = language.substring(0, underlineIdx);
|
98
|
+
return this._getBestMatchingLanguage(lang, props);
|
203
99
|
}
|
204
|
-
|
205
|
-
|
206
|
-
value: function getDpsLang(key) {
|
207
|
-
var _this3 = this;
|
208
|
-
|
209
|
-
var strs = {};
|
210
|
-
|
211
|
-
if (_typeof(key) === 'object') {
|
212
|
-
if (typeof key.strKey === 'string') {
|
213
|
-
strs = I18n.t(key.strKey) !== key.strKey ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
|
214
|
-
} else {
|
215
|
-
Object.keys(key).map(function (i) {
|
216
|
-
strs[key[i]] = I18n.t(key[i]) !== key[i] ? I18n.t(key[i]) : typeof _this3[key[i]] !== 'undefined' ? _this3[key[i]] : I18n.t(key[i]);
|
217
|
-
return null;
|
218
|
-
});
|
219
|
-
}
|
220
|
-
} else {
|
221
|
-
strs = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
222
|
-
}
|
100
|
+
return this.defaultLang;
|
101
|
+
}
|
223
102
|
|
224
|
-
|
103
|
+
// Format the passed string replacing the numbered placeholders
|
104
|
+
// i.e. I'd like some {0} and {1}, or just {0}
|
105
|
+
// Use example:
|
106
|
+
// strings.formatString(strings.question, strings.bread, strings.butter)
|
107
|
+
formatString(str) {
|
108
|
+
let res = str;
|
109
|
+
for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
|
110
|
+
res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
|
225
111
|
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
112
|
+
return res;
|
113
|
+
}
|
114
|
+
formatValue(key) {
|
115
|
+
let res = typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
116
|
+
for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
|
117
|
+
res = this._replaceAll("{".concat(i, "}"), i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
|
230
118
|
}
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
});
|
249
|
-
return result;
|
119
|
+
return res;
|
120
|
+
}
|
121
|
+
_replaceAll(find, replace, str) {
|
122
|
+
// eslint-disable-next-line no-useless-escape, no-param-reassign
|
123
|
+
find = find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
|
124
|
+
if (!str) return '';
|
125
|
+
return str.replace(new RegExp(find, 'g'), replace);
|
126
|
+
}
|
127
|
+
getDpLang(code, value) {
|
128
|
+
let key;
|
129
|
+
if (typeof value === 'undefined') {
|
130
|
+
key = "dp_".concat(code).toLowerCase();
|
131
|
+
} else if (typeof value === 'boolean') {
|
132
|
+
const valStr = value ? 'on' : 'off';
|
133
|
+
key = "dp_".concat(code, "_").concat(valStr).toLowerCase();
|
134
|
+
} else {
|
135
|
+
key = "dp_".concat(code, "_").concat(value).toLowerCase();
|
250
136
|
}
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
key
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
137
|
+
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
138
|
+
}
|
139
|
+
getDpName(code, defaultName) {
|
140
|
+
const key = "dp_".concat(code).toLowerCase();
|
141
|
+
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
|
142
|
+
}
|
143
|
+
getDpsLang(key) {
|
144
|
+
let strs = {};
|
145
|
+
if (typeof key === 'object') {
|
146
|
+
if (typeof key.strKey === 'string') {
|
147
|
+
strs = I18n.t(key.strKey) !== key.strKey ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
|
148
|
+
} else {
|
149
|
+
Object.keys(key).map(i => {
|
150
|
+
strs[key[i]] = I18n.t(key[i]) !== key[i] ? I18n.t(key[i]) : typeof this[key[i]] !== 'undefined' ? this[key[i]] : I18n.t(key[i]);
|
151
|
+
return null;
|
152
|
+
});
|
153
|
+
}
|
154
|
+
} else {
|
155
|
+
strs = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
269
156
|
}
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
var label = schema.label;
|
276
|
-
var labels = [];
|
157
|
+
return strs;
|
158
|
+
}
|
159
|
+
getLang(key, defaultString) {
|
160
|
+
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : typeof defaultString !== 'undefined' ? defaultString : I18n.t(key);
|
161
|
+
}
|
277
162
|
|
278
|
-
|
279
|
-
|
280
|
-
|
163
|
+
/**
|
164
|
+
* 获取picker标题
|
165
|
+
* @param {*} dpCode
|
166
|
+
*/
|
167
|
+
getRangeStrings(dpCode, schema) {
|
168
|
+
const result = {};
|
169
|
+
if (typeof schema === 'undefined') return result;
|
170
|
+
const lists = schema.range;
|
171
|
+
lists.map(v => {
|
172
|
+
const key = "dp_".concat(dpCode, "_").concat(v).toLowerCase();
|
173
|
+
result[v] = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
174
|
+
return null;
|
175
|
+
});
|
176
|
+
return result;
|
177
|
+
}
|
281
178
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
179
|
+
/**
|
180
|
+
* 开关倒计时转换为文案 time => 设备将在xxx后 关闭/开启
|
181
|
+
* 精确到分钟
|
182
|
+
* @param {*} t 倒计时剩余(秒)
|
183
|
+
* @param {*} power 设备当前的开关状态 (如果当前设备为开启状态, 则倒计时显示为关闭)
|
184
|
+
*/
|
185
|
+
parseCountdown(t, power) {
|
186
|
+
const h = parseFloat("".concat(t / 3600));
|
187
|
+
const m = parseFloat("".concat(t / 60 - h * 60));
|
188
|
+
const tHour = I18n.t('t_hour') !== 't_hour' ? I18n.t('t_hour') : typeof this.t_hour !== 'undefined' ? this.t_hour : I18n.t('t_hour');
|
189
|
+
const tMinute = I18n.t('t_minute') !== 't_minute' ? I18n.t('t_minute') : typeof this.t_minute !== 'undefined' ? this.t_minute : I18n.t('t_minute');
|
190
|
+
const time = h >= 1.0 ? "".concat(Math.round(h)).concat(tHour) : "".concat(Math.round(m)).concat(tMinute);
|
191
|
+
const key = "countdown_".concat(power ? 'on' : 'off');
|
192
|
+
const str = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
193
|
+
return this.formatString(str, time);
|
194
|
+
}
|
195
|
+
getFaultStrings(schema, faultCode, faultValue) {
|
196
|
+
let onlyPrior = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
197
|
+
if (!faultValue) return '';
|
198
|
+
const {
|
199
|
+
label
|
200
|
+
} = schema;
|
201
|
+
const labels = [];
|
202
|
+
for (let i = 0; i < label.length; i++) {
|
203
|
+
const value = label[i];
|
204
|
+
const isExist = getBitValue(faultValue, i);
|
205
|
+
if (isExist) {
|
206
|
+
labels.push(this.getDpLang(faultCode, value));
|
207
|
+
if (onlyPrior) break;
|
286
208
|
}
|
287
|
-
|
288
|
-
return onlyPrior ? labels[0] : labels.join(', ');
|
289
209
|
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
}();
|
294
|
-
|
295
|
-
export { I18N as default };
|
210
|
+
return onlyPrior ? labels[0] : labels.join(', ');
|
211
|
+
}
|
212
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { getNetworkType, onNetworkStatusChange } from '../..';
|
2
2
|
import { GetTTTSuccessData, GetTTTEventListenerParams, NetworkState } from './types';
|
3
|
-
|
4
|
-
|
3
|
+
type GetNetworkResult = GetTTTSuccessData<typeof getNetworkType>;
|
4
|
+
type NetworkStatusChangeParam = GetTTTEventListenerParams<typeof onNetworkStatusChange>;
|
5
5
|
/**
|
6
6
|
* 规范统一处理 network 返回值
|
7
7
|
*
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
|
-
|
3
2
|
/**
|
4
3
|
* 规范统一处理 network 返回值
|
5
4
|
*
|
@@ -11,15 +10,11 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
11
10
|
*/
|
12
11
|
export function normalizeNetwork(network, data) {
|
13
12
|
var _result$networkType;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
var networkType = result === null || result === void 0 ? void 0 : (_result$networkType = result.networkType) === null || _result$networkType === void 0 ? void 0 : _result$networkType.toUpperCase();
|
13
|
+
const result = _objectSpread(_objectSpread({}, network), data);
|
14
|
+
const networkType = result === null || result === void 0 ? void 0 : (_result$networkType = result.networkType) === null || _result$networkType === void 0 ? void 0 : _result$networkType.toUpperCase();
|
18
15
|
result.networkType = networkType;
|
19
|
-
|
20
16
|
if (typeof result.isConnected === 'undefined') {
|
21
17
|
result.isConnected = networkType !== 'NONE';
|
22
18
|
}
|
23
|
-
|
24
19
|
return result;
|
25
20
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { publishDpsBase } from '../..';
|
2
2
|
import { GetTTTAllParams, DpState } from './types';
|
3
|
-
|
3
|
+
type PublishDpsOptions = Omit<GetTTTAllParams<typeof publishDpsBase>, 'deviceId' | 'dps'>;
|
4
4
|
/**
|
5
5
|
* 下发 DP 点控制设备
|
6
6
|
*
|
package/lib/panel/publishDps.js
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
|
-
import "core-js/modules/es.object.to-string.js";
|
3
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
4
|
-
import "core-js/modules/es.object.keys.js";
|
5
|
-
import "core-js/modules/es.promise.js";
|
6
2
|
import { publishDpsBase } from '../..';
|
7
3
|
import { getDevInfo } from './devInfo';
|
8
|
-
|
4
|
+
const DEFAULT_OPTIONS = {
|
9
5
|
mode: 2,
|
10
6
|
options: {},
|
11
7
|
pipelines: []
|
12
8
|
};
|
9
|
+
|
13
10
|
/**
|
14
11
|
* 下发 DP 点控制设备
|
15
12
|
*
|
@@ -21,32 +18,32 @@ var DEFAULT_OPTIONS = {
|
|
21
18
|
* publishDps({ switch: false });
|
22
19
|
* publishDps({ '1': false })
|
23
20
|
*/
|
24
|
-
|
25
21
|
export function sendDps(data) {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
Object.keys(data).forEach(
|
22
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
|
23
|
+
const devInfo = getDevInfo();
|
24
|
+
const dps = {};
|
25
|
+
const codeIds = (devInfo === null || devInfo === void 0 ? void 0 : devInfo.codeIds) || {};
|
26
|
+
Object.keys(data).forEach(code => {
|
31
27
|
if (codeIds[code] !== undefined) {
|
32
28
|
dps["".concat(codeIds[code])] = data[code];
|
33
29
|
} else {
|
34
30
|
dps[code] = data[code];
|
35
31
|
}
|
36
32
|
});
|
37
|
-
return new Promise(
|
33
|
+
return new Promise((resolve, reject) => {
|
38
34
|
publishDpsBase(_objectSpread({
|
39
35
|
deviceId: devInfo.devId,
|
40
|
-
dps
|
41
|
-
success:
|
36
|
+
dps,
|
37
|
+
success: ret => {
|
42
38
|
resolve(ret);
|
43
39
|
},
|
44
|
-
fail:
|
40
|
+
fail: err => {
|
45
41
|
reject(err);
|
46
42
|
}
|
47
43
|
}, options));
|
48
44
|
});
|
49
45
|
}
|
46
|
+
|
50
47
|
/**
|
51
48
|
* 兼容新旧 publishDps,可以使用原有小程序提供的调用方式,也可以使用 SDK 提供的调用方式。
|
52
49
|
* @param data ty.device.publishDps的参数 或 当前要下发的 DP 数据,同时支持 key 为 dp code 或 dp id
|
@@ -57,10 +54,8 @@ export function sendDps(data) {
|
|
57
54
|
* publishDps({ switch: false });
|
58
55
|
* publishDps({ '1': false })
|
59
56
|
*/
|
60
|
-
|
61
57
|
export function publishDps(data) {
|
62
|
-
|
63
|
-
|
58
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_OPTIONS;
|
64
59
|
if (data.deviceId && data.dps) {
|
65
60
|
publishDpsBase(_objectSpread(_objectSpread({}, data), options));
|
66
61
|
} else {
|
@@ -1,5 +1,5 @@
|
|
1
|
-
export
|
2
|
-
export
|
1
|
+
export type DpValue = boolean | number | string;
|
2
|
+
export type DpState = Record<string, DpValue>;
|
3
3
|
export interface DpSchema {
|
4
4
|
attr: number;
|
5
5
|
canTrigger: boolean;
|
@@ -85,7 +85,7 @@ interface PanelConfig {
|
|
85
85
|
/**
|
86
86
|
* 设备信息
|
87
87
|
*/
|
88
|
-
export
|
88
|
+
export type DevInfo = Omit<ty.device.DeviceInfo, 'schema' | 'panelConfig'> & {
|
89
89
|
/**
|
90
90
|
* dp id 与 dp code 的映射
|
91
91
|
*/
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
export
|
3
|
-
export
|
4
|
-
export
|
5
|
-
export
|
6
|
-
export
|
7
|
-
export
|
8
|
-
export
|
1
|
+
type AnyFn = (...args: any) => any;
|
2
|
+
export type GetTTTAllParams<Fn extends AnyFn> = Parameters<Fn>['0'];
|
3
|
+
export type GetTTTParams<Fn extends AnyFn> = Omit<GetTTTAllParams<Fn>, 'complete' | 'success' | 'fail'>;
|
4
|
+
export type GetTTTSuccessData<Fn extends AnyFn, TTTParams extends AnyFn = GetTTTAllParams<Fn>['success']> = Parameters<TTTParams>['0'];
|
5
|
+
export type GetTTTFailData<Fn extends AnyFn, TTTParams extends AnyFn = GetTTTAllParams<Fn>['failed']> = Parameters<TTTParams>['0'];
|
6
|
+
export type GetTTTEventListener<Fn extends AnyFn> = GetTTTAllParams<Fn>;
|
7
|
+
export type GetTTTEventListenerParams<Fn extends AnyFn, TTTEventListener extends AnyFn = GetTTTEventListener<Fn>> = Parameters<TTTEventListener>['0'];
|
8
|
+
export type PromisifyTTT<Fn extends AnyFn> = (params: GetTTTParams<Fn>) => Promise<GetTTTSuccessData<Fn>>;
|
9
9
|
export {};
|
package/lib/panel/utils.js
CHANGED
package/lib/reLaunch/index.js
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
import "core-js/modules/es.object.to-string.js";
|
2
|
-
import "core-js/modules/es.promise.js";
|
3
1
|
/// <reference path="../../@types/api.d.ts" />
|
4
|
-
import router from '@ray-js/router';
|
5
2
|
|
6
|
-
|
3
|
+
import router from '@ray-js/router';
|
4
|
+
const reLaunch = function (options) {
|
7
5
|
router.reload(options.url);
|
8
6
|
return Promise.resolve();
|
9
7
|
};
|
10
|
-
|
11
8
|
export default reLaunch;
|