@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.
Files changed (74) hide show
  1. package/LICENSE.md +9 -0
  2. package/lib/BaseKit-3.3.10.js +85 -83
  3. package/lib/BizKit-3.2.7.js +48 -47
  4. package/lib/DeviceKit-3.3.1.js +194 -193
  5. package/lib/HomeKit-3.1.4.js +2 -1
  6. package/lib/MapKit-3.0.7.js +4 -2
  7. package/lib/MiniKit-3.1.0.js +65 -64
  8. package/lib/P2PKit-2.0.3.js +4 -2
  9. package/lib/PlayNetKit-1.1.3.js +2 -1
  10. package/lib/cloud/alarm.js +6 -9
  11. package/lib/cloud/core.js +3 -4
  12. package/lib/cloud/device.js +25 -36
  13. package/lib/cloud/interface.d.ts +7 -7
  14. package/lib/cloud/linkage.js +51 -49
  15. package/lib/cloud/statistic.js +30 -42
  16. package/lib/cloud/timer.js +45 -62
  17. package/lib/constants.js +1 -1
  18. package/lib/core/promisify/index.js +5 -9
  19. package/lib/getBoundingClientRect/index.js +16 -17
  20. package/lib/getBoundingClientRect/index.thing.js +16 -17
  21. package/lib/getBoundingClientRect/index.wechat.js +16 -17
  22. package/lib/getCdnUrl/index.js +0 -2
  23. package/lib/getCdnUrl/index.thing.js +30 -85
  24. package/lib/getCdnUrl/index.wechat.js +0 -2
  25. package/lib/getElementById/index.js +1 -3
  26. package/lib/getElementById/index.thing.js +2 -4
  27. package/lib/getElementById/index.wechat.js +2 -4
  28. package/lib/hideTabBar/index.d.ts +7 -1
  29. package/lib/index.js +3 -2
  30. package/lib/lifecycles/offAppEvent/index.js +2 -2
  31. package/lib/lifecycles/offAppHide/index.js +2 -2
  32. package/lib/lifecycles/offAppShow/index.js +2 -2
  33. package/lib/lifecycles/offError/index.js +2 -2
  34. package/lib/lifecycles/offThemeChange/index.js +2 -2
  35. package/lib/lifecycles/offWindowResize/index.js +2 -2
  36. package/lib/lifecycles/onAppEvent/index.js +2 -2
  37. package/lib/lifecycles/onAppHide/index.js +2 -2
  38. package/lib/lifecycles/onAppShow/index.js +2 -2
  39. package/lib/lifecycles/onError/index.js +2 -2
  40. package/lib/lifecycles/onPageNotFound/index.js +2 -2
  41. package/lib/lifecycles/onThemeChange/index.js +2 -2
  42. package/lib/lifecycles/onWindowResize/index.js +2 -2
  43. package/lib/navigateBack/index.js +3 -6
  44. package/lib/navigateTo/index.js +2 -5
  45. package/lib/onNavigationBarBack/index.js +1 -2
  46. package/lib/onNavigationBarBack/index.wechat.js +1 -2
  47. package/lib/panel/devInfo/index.js +84 -121
  48. package/lib/panel/i18n/index.d.ts +1 -1
  49. package/lib/panel/i18n/index.js +180 -263
  50. package/lib/panel/i18n/index.wechat.d.ts +1 -1
  51. package/lib/panel/i18n/index.wechat.js +184 -268
  52. package/lib/panel/normalizeNetwork.d.ts +2 -2
  53. package/lib/panel/normalizeNetwork.js +2 -7
  54. package/lib/panel/publishDps.d.ts +1 -1
  55. package/lib/panel/publishDps.js +14 -19
  56. package/lib/panel/types/devInfo.d.ts +3 -3
  57. package/lib/panel/types/utilities.d.ts +8 -8
  58. package/lib/panel/utils.js +1 -3
  59. package/lib/reLaunch/index.js +2 -5
  60. package/lib/redirectTo/index.js +2 -7
  61. package/lib/requestCloud/index.js +2 -2
  62. package/lib/requestCloud/index.wechat.js +0 -1
  63. package/lib/setNavigationBarBack/index.js +1 -2
  64. package/lib/setNavigationBarBack/index.wechat.js +1 -2
  65. package/lib/setNavigationBarColor/index.js +3 -6
  66. package/lib/setNavigationBarTitle/index.js +5 -6
  67. package/lib/showTabBar/index.d.ts +7 -1
  68. package/lib/switchTab/index.js +2 -5
  69. package/lib/utils.d.ts +1 -1
  70. package/lib/utils.js +9 -18
  71. package/lib/utils.wechat.d.ts +1 -1
  72. package/lib/utils.wechat.js +14 -26
  73. package/lib/viewAPI.js +14 -13
  74. package/package.json +5 -5
@@ -1,8 +1,4 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import "core-js/modules/es.object.to-string.js";
4
- import "core-js/modules/es.promise.js";
5
- var regionMap = {
1
+ const regionMap = {
6
2
  AY: 'images.tuyacn.com',
7
3
  AZ: 'usimagesd1448c85ulz2o4.cdn5th.com',
8
4
  EU: 'euimagesd2h2yqnfpu4gl5.cdn5th.com',
@@ -11,21 +7,21 @@ var regionMap = {
11
7
  WE: 'd2h2yqnfpu4gl5.cdn5th.com',
12
8
  UE: 'usimagesd1448c85ulz2o4.cdn5th.com'
13
9
  };
14
- var regionCode = 'EU';
10
+ let regionCode = 'EU';
15
11
  export function getRegionCode() {
16
- return new Promise(function (resolve, reject) {
12
+ return new Promise((resolve, reject) => {
17
13
  ty.getAppInfo({
18
- success: function success(res) {
14
+ success: function (res) {
19
15
  resolve(res.regionCode);
20
16
  },
21
- fail: function fail(err) {
17
+ fail: function (err) {
22
18
  reject(err);
23
19
  }
24
20
  });
25
21
  });
26
22
  }
27
23
  ty.getAppInfo({
28
- success: function success(res) {
24
+ success: function (res) {
29
25
  regionCode = res.regionCode;
30
26
  }
31
27
  });
@@ -34,85 +30,34 @@ export default function getCdnUrl(path, cdnMap, region) {
34
30
  console.warn('请传入cdnMap');
35
31
  return path;
36
32
  }
37
-
38
- var cdnShortPath = cdnMap[path];
39
-
33
+ const cdnShortPath = cdnMap[path];
40
34
  if (!cdnShortPath) {
41
35
  console.warn('[App] cdn "' + path + '" is not exist.');
42
36
  return path;
43
37
  }
44
-
45
- var cdnPath = 'https://' + regionMap[region || regionCode] + '/' + cdnShortPath;
38
+ const cdnPath = 'https://' + regionMap[region || regionCode] + '/' + cdnShortPath;
46
39
  return cdnPath;
47
40
  }
48
- export function getCdnUrlAsync() {
49
- return _getCdnUrlAsync.apply(this, arguments);
50
- }
51
-
52
- function _getCdnUrlAsync() {
53
- _getCdnUrlAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(path, cdnMap, region) {
54
- var _regionCode, cdnShortPath, cdnPath;
55
-
56
- return _regeneratorRuntime.wrap(function (_context) {
57
- while (1) {
58
- switch (_context.prev = _context.next) {
59
- case 0:
60
- if (cdnMap) {
61
- _context.next = 3;
62
- break;
63
- }
64
-
65
- console.warn('请传入cdnMap');
66
- return _context.abrupt("return", path);
67
-
68
- case 3:
69
- _regionCode = 'EU';
70
-
71
- if (!region) {
72
- _context.next = 8;
73
- break;
74
- }
75
-
76
- _regionCode = region;
77
- _context.next = 17;
78
- break;
79
-
80
- case 8:
81
- _context.prev = 8;
82
- _context.next = 11;
83
- return getRegionCode();
84
-
85
- case 11:
86
- _regionCode = _context.sent;
87
- _context.next = 17;
88
- break;
89
-
90
- case 14:
91
- _context.prev = 14;
92
- _context.t0 = _context["catch"](8);
93
- console.warn('[App] getRegionCode error, use default region EU', _context.t0);
94
-
95
- case 17:
96
- cdnShortPath = cdnMap[path];
97
-
98
- if (cdnShortPath) {
99
- _context.next = 21;
100
- break;
101
- }
102
-
103
- console.warn('[App] cdn "' + path + '" is not exist.');
104
- return _context.abrupt("return", path);
105
-
106
- case 21:
107
- cdnPath = 'https://' + regionMap[_regionCode] + '/' + cdnShortPath;
108
- return _context.abrupt("return", cdnPath);
109
-
110
- case 23:
111
- case "end":
112
- return _context.stop();
113
- }
114
- }
115
- }, _callee, null, [[8, 14]]);
116
- }));
117
- return _getCdnUrlAsync.apply(this, arguments);
41
+ export async function getCdnUrlAsync(path, cdnMap, region) {
42
+ if (!cdnMap) {
43
+ console.warn('请传入cdnMap');
44
+ return path;
45
+ }
46
+ let _regionCode = 'EU';
47
+ if (region) {
48
+ _regionCode = region;
49
+ } else {
50
+ try {
51
+ _regionCode = await getRegionCode();
52
+ } catch (error) {
53
+ console.warn('[App] getRegionCode error, use default region EU', error);
54
+ }
55
+ }
56
+ const cdnShortPath = cdnMap[path];
57
+ if (!cdnShortPath) {
58
+ console.warn('[App] cdn "' + path + '" is not exist.');
59
+ return path;
60
+ }
61
+ const cdnPath = 'https://' + regionMap[_regionCode] + '/' + cdnShortPath;
62
+ return cdnPath;
118
63
  }
@@ -1,5 +1,3 @@
1
- import "core-js/modules/es.object.to-string.js";
2
- import "core-js/modules/es.promise.js";
3
1
  export default function getCdnUrl(path) {
4
2
  // 暂未实现获取cdn方法,将直接返回path
5
3
  return path;
@@ -1,7 +1,5 @@
1
- import "core-js/modules/es.object.to-string.js";
2
- import "core-js/modules/es.promise.js";
3
1
  export default function getElementById(id) {
4
- return new Promise(function (resolve) {
2
+ return new Promise(resolve => {
5
3
  resolve(document.getElementById(id));
6
4
  });
7
5
  }
@@ -1,8 +1,6 @@
1
- import "core-js/modules/es.object.to-string.js";
2
- import "core-js/modules/es.promise.js";
3
1
  export default function getElementById(id) {
4
- return new Promise(function (resolve) {
5
- var nodeRef = ty.createSelectorQuery().select("#".concat(id));
2
+ return new Promise(resolve => {
3
+ const nodeRef = ty.createSelectorQuery().select(`#${id}`);
6
4
  resolve(nodeRef);
7
5
  });
8
6
  }
@@ -1,8 +1,6 @@
1
- import "core-js/modules/es.object.to-string.js";
2
- import "core-js/modules/es.promise.js";
3
1
  export default function getElementById(id) {
4
- return new Promise(function (resolve) {
5
- var nodeRef = wx.createSelectorQuery().select("#".concat(id));
2
+ return new Promise(resolve => {
3
+ const nodeRef = wx.createSelectorQuery().select(`#${id}`);
6
4
  resolve(nodeRef);
7
5
  });
8
6
  }
@@ -1,3 +1,9 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- declare const _default: (arg?: any) => Promise<any>;
2
+ declare const _default: (arg?: {
3
+ animation?: boolean | undefined;
4
+ } & {
5
+ success?: ((S?: any) => void) | undefined;
6
+ fail?: ((F?: any) => void) | undefined;
7
+ complete?: ((C?: any) => void) | undefined;
8
+ } & import("../core").PromisifyArgs<any, any>) => Promise<any>;
3
9
  export default _default;
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="../@types/api.d.ts" />
2
+
2
3
  export * from './constants';
3
4
  export * from './all-kits';
4
5
  export * from './lifecycles';
@@ -21,15 +22,15 @@ export { default as switchTab } from './switchTab';
21
22
  export { default as onNavigationBarBack } from './onNavigationBarBack';
22
23
  export { default as setNavigationBarBack } from './setNavigationBarBack';
23
24
  export { default as getCdnUrl, getCdnUrlAsync } from './getCdnUrl';
25
+
24
26
  /**
25
27
  * 提供 glboal-api 将 wx / ty 对象暴露出去,供给业务在Ray为显示导出api时进行快速响应开发。
26
28
  */
27
-
28
29
  export { default as globalApi } from './global-api';
29
30
  export * from './cloud';
31
+
30
32
  /**
31
33
  * 0.10.3将一部分未支持的api导入
32
34
  */
33
-
34
35
  export * from './viewAPI';
35
36
  export * from './panel';
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var offAppEvent = function () {
2
+
3
+ const offAppEvent = function () {
3
4
  console.warn('// TODO 暂未实现方法 offAppEvent');
4
5
  };
5
-
6
6
  export default offAppEvent;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var offAppHide = function () {
2
+
3
+ const offAppHide = function () {
3
4
  console.warn('// TODO 暂未实现方法 offAppHide');
4
5
  };
5
-
6
6
  export default offAppHide;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var offAppShow = function () {
2
+
3
+ const offAppShow = function () {
3
4
  console.warn('// TODO 暂未实现方法 offAppShow');
4
5
  };
5
-
6
6
  export default offAppShow;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var offError = function () {
2
+
3
+ const offError = function () {
3
4
  console.warn('// TODO 暂未实现方法 offError');
4
5
  };
5
-
6
6
  export default offError;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var offThemeChange = function () {
2
+
3
+ const offThemeChange = function () {
3
4
  console.warn('// TODO 暂未实现方法 offThemeChange');
4
5
  };
5
-
6
6
  export default offThemeChange;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var offWindowResize = function () {
2
+
3
+ const offWindowResize = function () {
3
4
  console.warn('// TODO 暂未实现方法 offWindowResize');
4
5
  };
5
-
6
6
  export default offWindowResize;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var onAppEvent = function () {
2
+
3
+ const onAppEvent = function () {
3
4
  console.warn('// TODO 暂未实现方法 onAppEvent');
4
5
  };
5
-
6
6
  export default onAppEvent;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var onAppHide = function () {
2
+
3
+ const onAppHide = function () {
3
4
  console.warn('// TODO 暂未实现方法 onAppHide');
4
5
  };
5
-
6
6
  export default onAppHide;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var onAppShow = function () {
2
+
3
+ const onAppShow = function () {
3
4
  console.warn('// TODO 暂未实现方法 onAppShow');
4
5
  };
5
-
6
6
  export default onAppShow;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var onError = function () {
2
+
3
+ const onError = function () {
3
4
  console.warn('// TODO 暂未实现方法 onError');
4
5
  };
5
-
6
6
  export default onError;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var onPageNotFound = function () {
2
+
3
+ const onPageNotFound = function () {
3
4
  console.warn('// TODO 暂未实现方法 onPageNotFound');
4
5
  };
5
-
6
6
  export default onPageNotFound;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var onThemeChange = function () {
2
+
3
+ const onThemeChange = function () {
3
4
  console.warn('// TODO 暂未实现方法 onThemeChange');
4
5
  };
5
-
6
6
  export default onThemeChange;
@@ -1,6 +1,6 @@
1
1
  /// <reference path="../../@types/api.d.ts" />
2
- var onWindowResize = function () {
2
+
3
+ const onWindowResize = function () {
3
4
  console.warn('// TODO 暂未实现方法 onWindowResize');
4
5
  };
5
-
6
6
  export default onWindowResize;
@@ -1,14 +1,11 @@
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
- var navigateBack = function () {
7
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
3
+ import router from '@ray-js/router';
4
+ const navigateBack = function () {
5
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
8
6
  delta: 1
9
7
  };
10
8
  router.go(options.delta * -1);
11
9
  return Promise.resolve();
12
10
  };
13
-
14
11
  export default navigateBack;
@@ -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
- var navigateTo = function (options) {
3
+ import router from '@ray-js/router';
4
+ const navigateTo = function (options) {
7
5
  router.push(options.url);
8
6
  return Promise.resolve();
9
7
  };
10
-
11
8
  export default navigateTo;
@@ -1,5 +1,4 @@
1
- var onNavigationBarBack = function () {
1
+ const onNavigationBarBack = function () {
2
2
  console.warn('尚未支持');
3
3
  };
4
-
5
4
  export default onNavigationBarBack;
@@ -1,5 +1,4 @@
1
- var onNavigationBarBack = function () {
1
+ const onNavigationBarBack = function () {
2
2
  console.warn('尚未支持');
3
3
  };
4
-
5
4
  export default onNavigationBarBack;
@@ -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
- var __deviceInfo = null;
10
- var defaultPanelEnvironmentOptions = {
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; // @ts-ignore
19
-
20
- var deviceInfo = _objectSpread({}, dev);
21
-
22
- var schema = dev.schema;
23
- var idCodes = {};
24
- var codeIds = {};
25
- schema.forEach(function (item) {
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
- var id = item.id,
28
- code = item.code;
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
- export var initDevInfo = function (option) {
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
- var data = getLaunchOptionsSync();
48
-
49
- var _ref = option || data.query,
50
- deviceId = _ref.deviceId,
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: groupId,
56
- success: function success(groupInfo) {
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: deviceId,
64
- success: function success(deviceInfo) {
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 var getDevInfo = function () {
69
+ export const getDevInfo = () => {
74
70
  return __deviceInfo;
75
71
  };
76
- export var updateDevInfo = function (devInfo) {
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
- export function initPanelEnvironment() {
93
- return _initPanelEnvironment.apply(this, arguments);
94
- }
95
-
96
- function _initPanelEnvironment() {
97
- _initPanelEnvironment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
98
- var options,
99
- App,
100
- _args = arguments;
101
- return _regeneratorRuntime.wrap(function (_context) {
102
- while (1) {
103
- switch (_context.prev = _context.next) {
104
- case 0:
105
- options = _args.length > 0 && _args[0] !== undefined ? _args[0] : defaultPanelEnvironmentOptions;
106
-
107
- if (getApp()) {
108
- _context.next = 5;
109
- break;
110
- }
111
-
112
- _context.next = 4;
113
- return new Promise(function (resolve) {
114
- setTimeout(function () {
115
- resolve(initPanelEnvironment(options));
116
- }, 0);
117
- });
118
-
119
- case 4:
120
- return _context.abrupt("return");
121
-
122
- case 5:
123
- App = getApp(); // 基础库版本需要大于 2.6.0
124
- // @ts-ignore
125
-
126
- App.onReady = function (event) {
127
- var _options$deviceId, _options$groupId;
128
-
129
- var deviceId = (_options$deviceId = options.deviceId) !== null && _options$deviceId !== void 0 ? _options$deviceId : event.query.deviceId;
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
- }, _callee);
175
- }));
176
- return _initPanelEnvironment.apply(this, arguments);
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
  }