@ray-js/api 1.5.15 → 1.5.17
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/lib/cloud/interface.d.ts
CHANGED
@@ -1209,7 +1209,16 @@ export type IGetBindRuleListResponse = Array<{
|
|
1209
1209
|
/**
|
1210
1210
|
* 关联实体的值列表
|
1211
1211
|
*/
|
1212
|
-
associativeEntityValueList: IGetSceneListResponseV2
|
1212
|
+
associativeEntityValueList: Array<IGetSceneListResponseV2[number] & {
|
1213
|
+
/**
|
1214
|
+
* 无线开关规则是否启用
|
1215
|
+
*/
|
1216
|
+
triggerRuleEnable: boolean;
|
1217
|
+
/**
|
1218
|
+
* 无线开关执行规则 id
|
1219
|
+
*/
|
1220
|
+
triggerRuleId: string;
|
1221
|
+
}>;
|
1213
1222
|
/**
|
1214
1223
|
* 绑定 id,一般用来解绑
|
1215
1224
|
*/
|
@@ -4,7 +4,7 @@ type OpenSceneCreateParams = {
|
|
4
4
|
} & ICommon;
|
5
5
|
export declare function openSceneCreate(params?: OpenSceneCreateParams): Promise<void>;
|
6
6
|
export declare const openCreateScene: typeof openSceneCreate;
|
7
|
-
export declare function
|
7
|
+
export declare function openCreateTapToRunScene(params?: ICommon): Promise<void>;
|
8
8
|
export declare function openUniversalCreateScene(params?: OpenSceneCreateParams): Promise<void>;
|
9
9
|
type OpenSceneEdit = {
|
10
10
|
devId?: string;
|
@@ -6,7 +6,7 @@ export function openSceneCreate(params) {
|
|
6
6
|
export const openCreateScene = openSceneCreate;
|
7
7
|
|
8
8
|
// App 基线 5.13.0 以上开始支持
|
9
|
-
export function
|
9
|
+
export function openCreateTapToRunScene(params) {
|
10
10
|
const p = _objectSpread({
|
11
11
|
biz_type: 'click_execution'
|
12
12
|
}, params);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { DevInfo } from '../types/devInfo';
|
1
|
+
import { DevInfo, GroupInfo } from '../types/devInfo';
|
2
2
|
export interface InitPanelEnvironmentOptions {
|
3
3
|
/**
|
4
4
|
* @description 是否需要使用默认离线弹窗
|
@@ -40,10 +40,21 @@ export interface InitPanelEnvironmentOptions {
|
|
40
40
|
* @default undefined
|
41
41
|
*/
|
42
42
|
groupId?: string;
|
43
|
+
/**
|
44
|
+
* 微信详细页面路由
|
45
|
+
* @default undefined
|
46
|
+
*/
|
47
|
+
deviceDetailPage?: string;
|
48
|
+
/**
|
49
|
+
*是否显示故障提示
|
50
|
+
* @default false
|
51
|
+
*/
|
52
|
+
showFault?: boolean;
|
43
53
|
}
|
44
54
|
export declare function parseDevice(dev: ty.device.DeviceInfo | DevInfo): DevInfo;
|
55
|
+
export declare function parseGroup(group: ty.device.GroupInfo): GroupInfo;
|
45
56
|
/**
|
46
|
-
*
|
57
|
+
* 初始化面板环境下使用到的设备或群组信息
|
47
58
|
* @returns Promise<DevInfo>
|
48
59
|
*/
|
49
60
|
export declare const initDevInfo: (option?: {
|
@@ -57,3 +68,10 @@ export declare const updateDevInfo: (devInfo: DevInfo) => void;
|
|
57
68
|
* @param config: InitPanelEnvironmentOptions 配置项
|
58
69
|
*/
|
59
70
|
export declare function initPanelEnvironment(options?: InitPanelEnvironmentOptions): Promise<void>;
|
71
|
+
/**
|
72
|
+
* 初始化面板环境
|
73
|
+
* @param options 一些配置
|
74
|
+
* @param initCallback 初始化回调整
|
75
|
+
* @param destroyCallback 销毁环境回调整
|
76
|
+
*/
|
77
|
+
export declare const useInitPanelEnv: (options?: InitPanelEnvironmentOptions, initCallback?: (devId: string) => any, destroyCallback?: (devId: string) => any) => void;
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
2
|
import { getDeviceInfo, getLaunchOptionsSync, getGroupInfo, registerDeviceListListener, registerGroupChange, exitMiniProgram, subscribeDeviceRemoved, onDeviceRemoved } from '../../all-kits';
|
3
|
+
import { useEffect } from 'react';
|
3
4
|
import getApp from '../../getApp';
|
5
|
+
|
4
6
|
// 本地化缓存 deviceInfo 方便随时调用
|
5
7
|
let __deviceInfo = null;
|
6
8
|
const defaultPanelEnvironmentOptions = {
|
@@ -8,14 +10,15 @@ const defaultPanelEnvironmentOptions = {
|
|
8
10
|
bleCover: false,
|
9
11
|
customTop: null,
|
10
12
|
bleConnectType: 0,
|
11
|
-
showBLEToast: true
|
13
|
+
showBLEToast: true,
|
14
|
+
showFault: false
|
12
15
|
};
|
13
16
|
export function parseDevice(dev) {
|
14
17
|
if (!dev) return null;
|
15
|
-
// @ts-ignore
|
16
18
|
const deviceInfo = _objectSpread({}, dev);
|
19
|
+
// tuyalink 协议设备没有 schema 字段。避免崩溃加设置为空数组
|
17
20
|
const {
|
18
|
-
schema
|
21
|
+
schema = []
|
19
22
|
} = dev;
|
20
23
|
const idCodes = {};
|
21
24
|
const codeIds = {};
|
@@ -32,26 +35,50 @@ export function parseDevice(dev) {
|
|
32
35
|
deviceInfo.codeIds = codeIds;
|
33
36
|
return deviceInfo;
|
34
37
|
}
|
38
|
+
export function parseGroup(group) {
|
39
|
+
if (!group) return null;
|
40
|
+
const groupInfo = _objectSpread({}, group);
|
41
|
+
const {
|
42
|
+
schema
|
43
|
+
} = group;
|
44
|
+
const idCodes = {};
|
45
|
+
const codeIds = {};
|
46
|
+
schema.forEach(item => {
|
47
|
+
// @ts-ignore
|
48
|
+
const {
|
49
|
+
id,
|
50
|
+
code
|
51
|
+
} = item;
|
52
|
+
idCodes[id] = code;
|
53
|
+
codeIds[code] = id;
|
54
|
+
});
|
55
|
+
groupInfo.idCodes = idCodes;
|
56
|
+
groupInfo.codeIds = codeIds;
|
57
|
+
return groupInfo;
|
58
|
+
}
|
35
59
|
|
36
60
|
/**
|
37
|
-
*
|
61
|
+
* 初始化面板环境下使用到的设备或群组信息
|
38
62
|
* @returns Promise<DevInfo>
|
39
63
|
*/
|
40
64
|
export const initDevInfo = option => {
|
41
65
|
return new Promise((resolve, reject) => {
|
66
|
+
var _data$query, _data$query2;
|
42
67
|
if (__deviceInfo) {
|
43
68
|
resolve(__deviceInfo);
|
44
69
|
}
|
45
70
|
const data = getLaunchOptionsSync();
|
46
|
-
|
71
|
+
let {
|
47
72
|
deviceId,
|
48
73
|
groupId
|
49
|
-
} = option ||
|
74
|
+
} = option || {};
|
75
|
+
deviceId = deviceId || ((_data$query = data.query) === null || _data$query === void 0 ? void 0 : _data$query.deviceId);
|
76
|
+
groupId = groupId || ((_data$query2 = data.query) === null || _data$query2 === void 0 ? void 0 : _data$query2.groupId);
|
50
77
|
if (groupId) {
|
51
78
|
getGroupInfo({
|
52
79
|
groupId,
|
53
80
|
success: groupInfo => {
|
54
|
-
__deviceInfo = groupInfo;
|
81
|
+
__deviceInfo = parseDevice(groupInfo);
|
55
82
|
resolve(__deviceInfo);
|
56
83
|
}
|
57
84
|
});
|
@@ -95,19 +122,14 @@ export async function initPanelEnvironment() {
|
|
95
122
|
});
|
96
123
|
return;
|
97
124
|
}
|
125
|
+
let init = false;
|
98
126
|
const App = getApp();
|
99
|
-
|
100
|
-
// 基础库版本需要大于 2.6.0
|
101
|
-
// @ts-ignore
|
102
|
-
App.onReady = event => {
|
127
|
+
const initPanel = event => {
|
103
128
|
var _options$deviceId, _options$groupId;
|
104
129
|
const deviceId = (_options$deviceId = options.deviceId) !== null && _options$deviceId !== void 0 ? _options$deviceId : event.query.deviceId;
|
105
130
|
const groupId = (_options$groupId = options.groupId) !== null && _options$groupId !== void 0 ? _options$groupId : event.query.groupId;
|
106
|
-
const {
|
107
|
-
useDefaultOffline
|
108
|
-
} = options;
|
109
131
|
// @ts-ignore
|
110
|
-
if (ty.panel && ty.panel.initPanelKit
|
132
|
+
if (ty.panel && ty.panel.initPanelKit) {
|
111
133
|
// @ts-ignore
|
112
134
|
ty.panel.initPanelKit(_objectSpread({
|
113
135
|
deviceId,
|
@@ -136,6 +158,48 @@ export async function initPanelEnvironment() {
|
|
136
158
|
});
|
137
159
|
}
|
138
160
|
};
|
161
|
+
// 由于手机性能、初始化方法调用时机、框架初始化及界面加载逻辑的差异,
|
162
|
+
// 有时注册 App.onReady 时可能当前界面已经执行完了该事件,导致逻辑无法正常执行。因此增加延时逻辑,保证逻辑正常执行
|
163
|
+
// 若 3s 后仍未执行,则认为当前界面已经执行完了 App.onReady,直接执行逻辑
|
164
|
+
const timeout = setTimeout(() => {
|
165
|
+
if (init) return;
|
166
|
+
initPanel(getLaunchOptionsSync());
|
167
|
+
}, 3000);
|
168
|
+
// 基础库版本需要大于 2.6.0
|
169
|
+
// @ts-ignore
|
170
|
+
App.onReady = event => {
|
171
|
+
init = true;
|
172
|
+
clearTimeout(timeout);
|
173
|
+
initPanel(event);
|
174
|
+
};
|
175
|
+
|
139
176
|
// 使用 Promise 确保业务可以通过 initPanelEnvironment 的正常调用明确设备信息初始化完成
|
140
177
|
await initDevInfo(options.deviceId || options.groupId ? options : undefined);
|
141
|
-
}
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* 初始化面板环境
|
182
|
+
* @param options 一些配置
|
183
|
+
* @param initCallback 初始化回调整
|
184
|
+
* @param destroyCallback 销毁环境回调整
|
185
|
+
*/
|
186
|
+
export const useInitPanelEnv = function () {
|
187
|
+
var _data$query3, _data$query4;
|
188
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultPanelEnvironmentOptions;
|
189
|
+
let initCallback = arguments.length > 1 ? arguments[1] : undefined;
|
190
|
+
let destroyCallback = arguments.length > 2 ? arguments[2] : undefined;
|
191
|
+
const data = getLaunchOptionsSync();
|
192
|
+
let {
|
193
|
+
deviceId,
|
194
|
+
groupId
|
195
|
+
} = options || {};
|
196
|
+
deviceId = deviceId || ((_data$query3 = data.query) === null || _data$query3 === void 0 ? void 0 : _data$query3.deviceId);
|
197
|
+
groupId = groupId || ((_data$query4 = data.query) === null || _data$query4 === void 0 ? void 0 : _data$query4.groupId);
|
198
|
+
initPanelEnvironment(options);
|
199
|
+
useEffect(() => {
|
200
|
+
initCallback && initCallback(deviceId || groupId);
|
201
|
+
return () => {
|
202
|
+
destroyCallback && destroyCallback(deviceId || groupId);
|
203
|
+
};
|
204
|
+
}, []);
|
205
|
+
};
|
@@ -1,21 +1,21 @@
|
|
1
1
|
export type DpValue = boolean | number | string;
|
2
2
|
export type DpState = Record<string, DpValue>;
|
3
3
|
export interface DpSchema {
|
4
|
-
attr
|
5
|
-
canTrigger
|
4
|
+
attr?: number;
|
5
|
+
canTrigger?: boolean;
|
6
6
|
/**
|
7
7
|
* 功能点标识码,如 switch
|
8
8
|
*/
|
9
9
|
code: string;
|
10
|
-
defaultRecommend
|
11
|
-
editPermission
|
12
|
-
executable
|
13
|
-
extContent
|
14
|
-
iconname
|
10
|
+
defaultRecommend?: boolean;
|
11
|
+
editPermission?: boolean;
|
12
|
+
executable?: boolean;
|
13
|
+
extContent?: string;
|
14
|
+
iconname?: string;
|
15
15
|
/**
|
16
16
|
* 功能点 ID
|
17
17
|
*/
|
18
|
-
id: number;
|
18
|
+
id: number | string;
|
19
19
|
/**
|
20
20
|
* 功能点模式类型
|
21
21
|
* rw: 可下发可上报(可读可写)
|
@@ -34,7 +34,7 @@ export interface DpSchema {
|
|
34
34
|
/**
|
35
35
|
* 功能点类型
|
36
36
|
*/
|
37
|
-
type: 'bool' | 'value' | 'enum' | 'bitmap' | 'string';
|
37
|
+
type: 'bool' | 'value' | 'enum' | 'bitmap' | 'string' | 'raw';
|
38
38
|
/**
|
39
39
|
* 枚举值范围,type = enum 时才存在
|
40
40
|
*/
|
@@ -103,4 +103,17 @@ export type DevInfo = Omit<ty.device.DeviceInfo, 'schema' | 'panelConfig'> & {
|
|
103
103
|
*/
|
104
104
|
panelConfig: PanelConfig;
|
105
105
|
};
|
106
|
+
/**
|
107
|
+
* 群组信息
|
108
|
+
*/
|
109
|
+
export type GroupInfo = ty.device.GroupInfo & {
|
110
|
+
/**
|
111
|
+
* dp id 与 dp code 的映射
|
112
|
+
*/
|
113
|
+
idCodes: Record<string, string>;
|
114
|
+
/**
|
115
|
+
* dp code 与 dp id 的映射
|
116
|
+
*/
|
117
|
+
codeIds: Record<string, string>;
|
118
|
+
};
|
106
119
|
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/api",
|
3
|
-
"version": "1.5.
|
3
|
+
"version": "1.5.17",
|
4
4
|
"description": "Ray universal api",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -29,14 +29,14 @@
|
|
29
29
|
"watch": "ray start --type=component"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@ray-js/framework": "1.5.
|
33
|
-
"@ray-js/router": "1.5.
|
32
|
+
"@ray-js/framework": "1.5.17",
|
33
|
+
"@ray-js/router": "1.5.17",
|
34
34
|
"@ray-js/wechat": "^0.2.9",
|
35
35
|
"base64-browser": "^1.0.1",
|
36
36
|
"query-string": "^7.1.3"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@ray-js/cli": "1.5.
|
39
|
+
"@ray-js/cli": "1.5.17",
|
40
40
|
"art-template": "^4.13.2",
|
41
41
|
"fs-extra": "^10.1.0",
|
42
42
|
"miniprogram-api-typings": "^3.12.2",
|
@@ -46,5 +46,5 @@
|
|
46
46
|
"access": "public",
|
47
47
|
"registry": "https://registry.npmjs.org"
|
48
48
|
},
|
49
|
-
"gitHead": "
|
49
|
+
"gitHead": "75e528047b1398d46fcbab0eb3184c501c63cd64"
|
50
50
|
}
|