@ray-js/api 1.3.22 → 1.3.23
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/LICENSE.md +9 -0
- 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/P2PKit-2.0.3.js +4 -2
- package/lib/PlayNetKit-1.1.3.js +2 -1
- package/lib/cloud/alarm.js +6 -9
- package/lib/cloud/core.js +3 -4
- package/lib/cloud/device.js +25 -36
- package/lib/cloud/interface.d.ts +7 -7
- package/lib/cloud/linkage.js +51 -49
- package/lib/cloud/statistic.js +30 -42
- package/lib/cloud/timer.js +45 -62
- 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.js +0 -2
- package/lib/getCdnUrl/index.thing.js +30 -85
- package/lib/getCdnUrl/index.wechat.js +0 -2
- 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 -263
- package/lib/panel/i18n/index.wechat.d.ts +1 -1
- package/lib/panel/i18n/index.wechat.js +184 -268
- 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 +14 -19
- 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 -7
- 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 +9 -18
- package/lib/utils.wechat.d.ts +1 -1
- package/lib/utils.wechat.js +14 -26
- package/lib/viewAPI.js +14 -13
- package/package.json +5 -5
@@ -1,295 +1,211 @@
|
|
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
|
-
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
1
|
import { requestCloud, getSystemInfoSync, THING } from '../..';
|
18
|
-
import { getBitValue } from '../utils';
|
2
|
+
import { getBitValue } from '../utils';
|
19
3
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
4
|
+
// 微信小程序暂时只支持本地多语言
|
5
|
+
const I18n = {
|
6
|
+
t: key => key
|
24
7
|
};
|
25
|
-
|
26
|
-
|
27
|
-
function I18N(props) {
|
28
|
-
_classCallCheck(this, I18N);
|
29
|
-
|
8
|
+
export default class I18N {
|
9
|
+
constructor(props) {
|
30
10
|
this.strings = this.mergeLanguage(props, {});
|
31
11
|
this.defaultLang = this.strings.en ? 'en' : Object.keys(this.strings)[0];
|
32
12
|
this.setLanguage(this.defaultLang);
|
33
|
-
|
13
|
+
const langKey = getSystemInfoSync().language;
|
34
14
|
this.setLanguage(langKey);
|
35
15
|
}
|
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
|
-
}
|
16
|
+
forceUpdateNetworkLang(productId) {
|
17
|
+
requestCloud({
|
18
|
+
api: `${THING}.m.i18n.get`,
|
19
|
+
version: '1.0',
|
20
|
+
data: {
|
21
|
+
productId,
|
22
|
+
moduleName: 'h5',
|
23
|
+
endId: 2,
|
24
|
+
osId: 0
|
25
|
+
},
|
26
|
+
// @ts-ignore
|
27
|
+
success: data => {
|
28
|
+
if (data) {
|
29
|
+
this.strings = this.mergeLanguage(this.strings, data);
|
30
|
+
this.buildLanguage(this.__language);
|
58
31
|
}
|
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
32
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
if (
|
104
|
-
|
105
|
-
this.buildLanguage(language);
|
33
|
+
});
|
34
|
+
}
|
35
|
+
mergeLanguage(L1, L2) {
|
36
|
+
if (typeof L1 === 'undefined' && typeof L2 === 'undefined') return {};
|
37
|
+
if (typeof L1 === 'undefined') return L2;
|
38
|
+
if (typeof L2 === 'undefined') return L1;
|
39
|
+
const L0 = Object.assign({}, L1);
|
40
|
+
Object.keys(L2).map(k => {
|
41
|
+
if (typeof L0[k] !== 'undefined') {
|
42
|
+
Object.assign(L0[k], L2[k]);
|
106
43
|
} 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);
|
44
|
+
L0[k] = Object.assign({}, L2[k]);
|
159
45
|
}
|
46
|
+
return null;
|
47
|
+
});
|
48
|
+
return L0;
|
49
|
+
}
|
50
|
+
isZh(language) {
|
51
|
+
/**
|
52
|
+
* ios 的中文简体固定为 zh-Hans,
|
53
|
+
* 但安卓的中文简体可能有一大堆排列组件 = =,如 zh_CN、zh_cn、zh_Hans_CH、zh_hans_cn 等等;
|
54
|
+
*/
|
160
55
|
|
161
|
-
|
56
|
+
/**
|
57
|
+
* 如果匹配到位中文简体地区,
|
58
|
+
* 则将中文 zh 相关的 values 都写入到 this.strings 下,保证兜底本地 zh 相关的能取到,
|
59
|
+
* 再将当前地区 key 相关的 values 都写入到 this.strings 下,优先级最高;
|
60
|
+
*/
|
61
|
+
if (typeof language === 'string' && /^zh-hans$|^zh_hans$|^zh_cn$|^zh-cn$|^zh_hans_\w+|^zh-hans-\w+/.test(language.toLowerCase())) {
|
62
|
+
return true;
|
162
63
|
}
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
return res;
|
64
|
+
return false;
|
65
|
+
}
|
66
|
+
setLanguage(language) {
|
67
|
+
this.__language = language;
|
68
|
+
if (this.isZh(language)) {
|
69
|
+
this.buildLanguage('zh');
|
70
|
+
this.buildLanguage(language);
|
71
|
+
} else {
|
72
|
+
this.buildLanguage(this.__language);
|
173
73
|
}
|
174
|
-
}
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
74
|
+
}
|
75
|
+
buildLanguage(language) {
|
76
|
+
if (this.strings[language]) {
|
77
|
+
const localizedStrings = this.strings[language];
|
78
|
+
Object.keys(localizedStrings).map(key => {
|
79
|
+
// eslint-disable-next-line no-prototype-builtins
|
80
|
+
if (localizedStrings.hasOwnProperty(key)) {
|
81
|
+
this[key] = localizedStrings[key];
|
82
|
+
}
|
83
|
+
return null;
|
84
|
+
});
|
181
85
|
}
|
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);
|
86
|
+
}
|
87
|
+
_getBestMatchingLanguage(language, props) {
|
88
|
+
if (props[language]) return language;
|
89
|
+
const idx = language.lastIndexOf('-');
|
90
|
+
if (idx >= 0) {
|
91
|
+
const lang = language.substring(0, idx);
|
92
|
+
return this._getBestMatchingLanguage(lang, props);
|
197
93
|
}
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
|
94
|
+
const underlineIdx = language.lastIndexOf('_');
|
95
|
+
if (underlineIdx >= 0) {
|
96
|
+
const lang = language.substring(0, underlineIdx);
|
97
|
+
return this._getBestMatchingLanguage(lang, props);
|
203
98
|
}
|
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
|
-
}
|
99
|
+
return this.defaultLang;
|
100
|
+
}
|
223
101
|
|
224
|
-
|
102
|
+
// Format the passed string replacing the numbered placeholders
|
103
|
+
// i.e. I'd like some {0} and {1}, or just {0}
|
104
|
+
// Use example:
|
105
|
+
// strings.formatString(strings.question, strings.bread, strings.butter)
|
106
|
+
formatString(str) {
|
107
|
+
let res = str;
|
108
|
+
for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
|
109
|
+
res = this._replaceAll(`{${i}}`, i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
|
225
110
|
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
111
|
+
return res;
|
112
|
+
}
|
113
|
+
formatValue(key) {
|
114
|
+
let res = typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
115
|
+
for (let i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i++) {
|
116
|
+
res = this._replaceAll(`{${i}}`, i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1], res);
|
230
117
|
}
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
});
|
249
|
-
return result;
|
118
|
+
return res;
|
119
|
+
}
|
120
|
+
_replaceAll(find, replace, str) {
|
121
|
+
// eslint-disable-next-line no-useless-escape, no-param-reassign
|
122
|
+
find = find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
|
123
|
+
if (!str) return '';
|
124
|
+
return str.replace(new RegExp(find, 'g'), replace);
|
125
|
+
}
|
126
|
+
getDpLang(code, value) {
|
127
|
+
let key;
|
128
|
+
if (typeof value === 'undefined') {
|
129
|
+
key = `dp_${code}`.toLowerCase();
|
130
|
+
} else if (typeof value === 'boolean') {
|
131
|
+
const valStr = value ? 'on' : 'off';
|
132
|
+
key = `dp_${code}_${valStr}`.toLowerCase();
|
133
|
+
} else {
|
134
|
+
key = `dp_${code}_${value}`.toLowerCase();
|
250
135
|
}
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
key
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
136
|
+
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
137
|
+
}
|
138
|
+
getDpName(code, defaultName) {
|
139
|
+
const key = `dp_${code}`.toLowerCase();
|
140
|
+
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : defaultName;
|
141
|
+
}
|
142
|
+
getDpsLang(key) {
|
143
|
+
let strs = {};
|
144
|
+
if (typeof key === 'object') {
|
145
|
+
if (typeof key.strKey === 'string') {
|
146
|
+
strs = I18n.t(key.strKey) !== key.strKey ? I18n.t(key.strKey) : typeof this[key.strKey] !== 'undefined' ? this[key.strKey] : I18n.t(key.strKey);
|
147
|
+
} else {
|
148
|
+
Object.keys(key).map(i => {
|
149
|
+
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]);
|
150
|
+
return null;
|
151
|
+
});
|
152
|
+
}
|
153
|
+
} else {
|
154
|
+
strs = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
269
155
|
}
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
var label = schema.label;
|
276
|
-
var labels = [];
|
156
|
+
return strs;
|
157
|
+
}
|
158
|
+
getLang(key, defaultString) {
|
159
|
+
return I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : typeof defaultString !== 'undefined' ? defaultString : I18n.t(key);
|
160
|
+
}
|
277
161
|
|
278
|
-
|
279
|
-
|
280
|
-
|
162
|
+
/**
|
163
|
+
* 获取picker标题
|
164
|
+
* @param {*} dpCode
|
165
|
+
*/
|
166
|
+
getRangeStrings(dpCode, schema) {
|
167
|
+
const result = {};
|
168
|
+
if (typeof schema === 'undefined') return result;
|
169
|
+
const lists = schema.range;
|
170
|
+
lists.map(v => {
|
171
|
+
const key = `dp_${dpCode}_${v}`.toLowerCase();
|
172
|
+
result[v] = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
173
|
+
return null;
|
174
|
+
});
|
175
|
+
return result;
|
176
|
+
}
|
281
177
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
178
|
+
/**
|
179
|
+
* 开关倒计时转换为文案 time => 设备将在xxx后 关闭/开启
|
180
|
+
* 精确到分钟
|
181
|
+
* @param {*} t 倒计时剩余(秒)
|
182
|
+
* @param {*} power 设备当前的开关状态 (如果当前设备为开启状态, 则倒计时显示为关闭)
|
183
|
+
*/
|
184
|
+
parseCountdown(t, power) {
|
185
|
+
const h = parseFloat(`${t / 3600}`);
|
186
|
+
const m = parseFloat(`${t / 60 - h * 60}`);
|
187
|
+
const tHour = I18n.t('t_hour') !== 't_hour' ? I18n.t('t_hour') : typeof this.t_hour !== 'undefined' ? this.t_hour : I18n.t('t_hour');
|
188
|
+
const tMinute = I18n.t('t_minute') !== 't_minute' ? I18n.t('t_minute') : typeof this.t_minute !== 'undefined' ? this.t_minute : I18n.t('t_minute');
|
189
|
+
const time = h >= 1.0 ? `${Math.round(h)}${tHour}` : `${Math.round(m)}${tMinute}`;
|
190
|
+
const key = `countdown_${power ? 'on' : 'off'}`;
|
191
|
+
const str = I18n.t(key) !== key ? I18n.t(key) : typeof this[key] !== 'undefined' ? this[key] : I18n.t(key);
|
192
|
+
return this.formatString(str, time);
|
193
|
+
}
|
194
|
+
getFaultStrings(schema, faultCode, faultValue) {
|
195
|
+
let onlyPrior = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
196
|
+
if (!faultValue) return '';
|
197
|
+
const {
|
198
|
+
label
|
199
|
+
} = schema;
|
200
|
+
const labels = [];
|
201
|
+
for (let i = 0; i < label.length; i++) {
|
202
|
+
const value = label[i];
|
203
|
+
const isExist = getBitValue(faultValue, i);
|
204
|
+
if (isExist) {
|
205
|
+
labels.push(this.getDpLang(faultCode, value));
|
206
|
+
if (onlyPrior) break;
|
286
207
|
}
|
287
|
-
|
288
|
-
return onlyPrior ? labels[0] : labels.join(', ');
|
289
208
|
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
}();
|
294
|
-
|
295
|
-
export { I18N as default };
|
209
|
+
return onlyPrior ? labels[0] : labels.join(', ');
|
210
|
+
}
|
211
|
+
}
|
@@ -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
|
-
dps[
|
28
|
+
dps[`${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;
|