@ray-js/api 1.4.0-alpha.0 → 1.4.0-alpha.10
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/@types/P2PKit.d.ts +402 -0
- package/@types/all-kits.d.ts +1 -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.d.ts +27 -0
- package/lib/P2PKit-2.0.3.js +79 -0
- package/lib/PlayNetKit-1.1.3.js +2 -1
- package/lib/all-kits.d.ts +1 -0
- package/lib/all-kits.js +1 -0
- 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.d.ts +1 -0
- package/lib/getCdnUrl/index.js +4 -0
- package/lib/getCdnUrl/index.thing.d.ts +3 -1
- package/lib/getCdnUrl/index.thing.js +54 -19
- package/lib/getCdnUrl/index.wechat.d.ts +1 -0
- package/lib/getCdnUrl/index.wechat.js +4 -0
- 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/index.d.ts +1 -1
- package/lib/index.js +4 -3
- 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/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 +25 -25
- package/LICENSE.md +0 -9
@@ -1,13 +1,8 @@
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
2
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
4
|
-
import "core-js/modules/es.object.to-string.js";
|
5
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
6
|
-
import "core-js/modules/es.promise.js";
|
7
2
|
import { getDeviceInfo, getLaunchOptionsSync, getGroupInfo, getApp, registerDeviceListListener, registerGroupChange, exitMiniProgram, subscribeDeviceRemoved, onDeviceRemoved } from '@ray-js/api';
|
8
3
|
// 本地化缓存 deviceInfo 方便随时调用
|
9
|
-
|
10
|
-
|
4
|
+
let __deviceInfo = null;
|
5
|
+
const defaultPanelEnvironmentOptions = {
|
11
6
|
useDefaultOffline: true,
|
12
7
|
bleCover: false,
|
13
8
|
customTop: null,
|
@@ -15,17 +10,20 @@ var defaultPanelEnvironmentOptions = {
|
|
15
10
|
showBLEToast: true
|
16
11
|
};
|
17
12
|
export function parseDevice(dev) {
|
18
|
-
if (!dev) return null;
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
if (!dev) return null;
|
14
|
+
// @ts-ignore
|
15
|
+
const deviceInfo = _objectSpread({}, dev);
|
16
|
+
const {
|
17
|
+
schema
|
18
|
+
} = dev;
|
19
|
+
const idCodes = {};
|
20
|
+
const codeIds = {};
|
21
|
+
schema.forEach(item => {
|
26
22
|
// @ts-ignore
|
27
|
-
|
28
|
-
|
23
|
+
const {
|
24
|
+
id,
|
25
|
+
code
|
26
|
+
} = item;
|
29
27
|
idCodes[id] = code;
|
30
28
|
codeIds[code] = id;
|
31
29
|
});
|
@@ -33,35 +31,33 @@ export function parseDevice(dev) {
|
|
33
31
|
deviceInfo.codeIds = codeIds;
|
34
32
|
return deviceInfo;
|
35
33
|
}
|
34
|
+
|
36
35
|
/**
|
37
36
|
* 初始化面板环境下使用到的设备信息
|
38
37
|
* @returns Promise<DevInfo>
|
39
38
|
*/
|
40
|
-
|
41
|
-
|
42
|
-
return new Promise(function (resolve, reject) {
|
39
|
+
export const initDevInfo = option => {
|
40
|
+
return new Promise((resolve, reject) => {
|
43
41
|
if (__deviceInfo) {
|
44
42
|
resolve(__deviceInfo);
|
45
43
|
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
groupId = _ref.groupId;
|
52
|
-
|
44
|
+
const data = getLaunchOptionsSync();
|
45
|
+
const {
|
46
|
+
deviceId,
|
47
|
+
groupId
|
48
|
+
} = option || data.query;
|
53
49
|
if (groupId) {
|
54
50
|
getGroupInfo({
|
55
|
-
groupId
|
56
|
-
success:
|
51
|
+
groupId,
|
52
|
+
success: groupInfo => {
|
57
53
|
__deviceInfo = groupInfo;
|
58
54
|
resolve(__deviceInfo);
|
59
55
|
}
|
60
56
|
});
|
61
57
|
} else {
|
62
58
|
getDeviceInfo({
|
63
|
-
deviceId
|
64
|
-
success:
|
59
|
+
deviceId,
|
60
|
+
success: deviceInfo => {
|
65
61
|
__deviceInfo = parseDevice(deviceInfo);
|
66
62
|
resolve(__deviceInfo);
|
67
63
|
},
|
@@ -70,108 +66,75 @@ export var initDevInfo = function (option) {
|
|
70
66
|
}
|
71
67
|
});
|
72
68
|
};
|
73
|
-
export
|
69
|
+
export const getDevInfo = () => {
|
74
70
|
return __deviceInfo;
|
75
71
|
};
|
76
|
-
export
|
72
|
+
export const updateDevInfo = devInfo => {
|
77
73
|
__deviceInfo = devInfo;
|
78
74
|
};
|
75
|
+
|
79
76
|
/**
|
80
77
|
* 监听设备移除
|
81
78
|
*/
|
82
|
-
|
83
|
-
var handleDeviceRemoved = function () {
|
79
|
+
const handleDeviceRemoved = () => {
|
84
80
|
exitMiniProgram();
|
85
81
|
};
|
82
|
+
|
86
83
|
/**
|
87
84
|
* 绑定当前设备或群组基础事件
|
88
85
|
* @param config: InitPanelEnvironmentOptions 配置项
|
89
86
|
*/
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
var groupId = (_options$groupId = options.groupId) !== null && _options$groupId !== void 0 ? _options$groupId : event.query.groupId;
|
131
|
-
var useDefaultOffline = options.useDefaultOffline; // @ts-ignore
|
132
|
-
|
133
|
-
if (ty.panel && ty.panel.initPanelKit && useDefaultOffline) {
|
134
|
-
// @ts-ignore
|
135
|
-
ty.panel.initPanelKit(_objectSpread({
|
136
|
-
deviceId: deviceId,
|
137
|
-
groupId: groupId
|
138
|
-
}, options));
|
139
|
-
} else {
|
140
|
-
// 否则使用 registerDeviceListListener 注册,删除上述条件方法
|
141
|
-
// 若需要能用离线逻辑,则需要在 global.config.ts 中添加 pageWrapper: ['@ray-js/ray-panel-wrapper/lib/page'],
|
142
|
-
if (deviceId) {
|
143
|
-
registerDeviceListListener({
|
144
|
-
deviceIdList: [deviceId]
|
145
|
-
});
|
146
|
-
}
|
147
|
-
|
148
|
-
if (groupId) {
|
149
|
-
registerGroupChange({
|
150
|
-
groupIdList: [groupId]
|
151
|
-
});
|
152
|
-
}
|
153
|
-
}
|
154
|
-
|
155
|
-
if (deviceId) {
|
156
|
-
subscribeDeviceRemoved({
|
157
|
-
deviceId: deviceId,
|
158
|
-
success: function success() {
|
159
|
-
onDeviceRemoved(handleDeviceRemoved);
|
160
|
-
}
|
161
|
-
});
|
162
|
-
}
|
163
|
-
}; // 使用 Promise 确保业务可以通过 initPanelEnvironment 的正常调用明确设备信息初始化完成
|
164
|
-
|
165
|
-
|
166
|
-
_context.next = 9;
|
167
|
-
return initDevInfo(options.deviceId || options.groupId ? options : undefined);
|
168
|
-
|
169
|
-
case 9:
|
170
|
-
case "end":
|
171
|
-
return _context.stop();
|
172
|
-
}
|
87
|
+
export async function initPanelEnvironment() {
|
88
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultPanelEnvironmentOptions;
|
89
|
+
if (!getApp()) {
|
90
|
+
await new Promise(resolve => {
|
91
|
+
setTimeout(() => {
|
92
|
+
resolve(initPanelEnvironment(options));
|
93
|
+
}, 0);
|
94
|
+
});
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
const App = getApp();
|
98
|
+
|
99
|
+
// 基础库版本需要大于 2.6.0
|
100
|
+
// @ts-ignore
|
101
|
+
App.onReady = event => {
|
102
|
+
var _options$deviceId, _options$groupId;
|
103
|
+
const deviceId = (_options$deviceId = options.deviceId) !== null && _options$deviceId !== void 0 ? _options$deviceId : event.query.deviceId;
|
104
|
+
const groupId = (_options$groupId = options.groupId) !== null && _options$groupId !== void 0 ? _options$groupId : event.query.groupId;
|
105
|
+
const {
|
106
|
+
useDefaultOffline
|
107
|
+
} = options;
|
108
|
+
// @ts-ignore
|
109
|
+
if (ty.panel && ty.panel.initPanelKit && useDefaultOffline) {
|
110
|
+
// @ts-ignore
|
111
|
+
ty.panel.initPanelKit(_objectSpread({
|
112
|
+
deviceId,
|
113
|
+
groupId
|
114
|
+
}, options));
|
115
|
+
} else {
|
116
|
+
// 否则使用 registerDeviceListListener 注册,删除上述条件方法
|
117
|
+
// 若需要能用离线逻辑,则需要在 global.config.ts 中添加 pageWrapper: ['@ray-js/ray-panel-wrapper/lib/page'],
|
118
|
+
if (deviceId) {
|
119
|
+
registerDeviceListListener({
|
120
|
+
deviceIdList: [deviceId]
|
121
|
+
});
|
122
|
+
}
|
123
|
+
if (groupId) {
|
124
|
+
registerGroupChange({
|
125
|
+
groupIdList: [groupId]
|
126
|
+
});
|
173
127
|
}
|
174
|
-
}
|
175
|
-
|
176
|
-
|
128
|
+
}
|
129
|
+
if (deviceId) {
|
130
|
+
subscribeDeviceRemoved({
|
131
|
+
deviceId,
|
132
|
+
success: () => {
|
133
|
+
onDeviceRemoved(handleDeviceRemoved);
|
134
|
+
}
|
135
|
+
});
|
136
|
+
}
|
137
|
+
};
|
138
|
+
// 使用 Promise 确保业务可以通过 initPanelEnvironment 的正常调用明确设备信息初始化完成
|
139
|
+
await initDevInfo(options.deviceId || options.groupId ? options : undefined);
|
177
140
|
}
|