@ray-js/ray-ipc-utils 1.1.0-beta-1
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/README.md +126 -0
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/useTrafficViewTip/index.d.ts +1 -0
- package/lib/hooks/useTrafficViewTip/index.js +3 -0
- package/lib/index.config.js +14 -0
- package/lib/index.d.ts +44 -0
- package/lib/index.js +7 -0
- package/lib/index.module.less +5 -0
- package/lib/interface.d.ts +63 -0
- package/lib/interface.js +26 -0
- package/lib/kit/device/index.d.ts +15 -0
- package/lib/kit/device/index.js +68 -0
- package/lib/kit/index.d.ts +2 -0
- package/lib/kit/index.js +2 -0
- package/lib/kit/interface.d.ts +13 -0
- package/lib/kit/interface.js +1 -0
- package/lib/kit/ipc/index.d.ts +124 -0
- package/lib/kit/ipc/index.js +709 -0
- package/lib/props.d.ts +4 -0
- package/lib/props.js +3 -0
- package/lib/service/index.d.ts +47 -0
- package/lib/service/index.js +502 -0
- package/lib/typings/index.d.ts +13 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.js +27 -0
- package/package.json +77 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IpcConfigInfo, ServeTpe } from '../interface';
|
|
2
|
+
/**
|
|
3
|
+
* 获取IPC设备配置及缓存信息、
|
|
4
|
+
* 包含: 视频清晰度、对讲方式、拾音器、视频缩放最大倍数
|
|
5
|
+
* @param {string} deviceId 设备id
|
|
6
|
+
*/
|
|
7
|
+
export declare const getCameraConfigInfo: (deviceId: string) => Promise<IpcConfigInfo>;
|
|
8
|
+
/**
|
|
9
|
+
* 获取IPC设备配置收藏点信息列表
|
|
10
|
+
* @param {string} deviceId 设备id
|
|
11
|
+
*/
|
|
12
|
+
export declare const getCollectionPointsInfo: (deviceId: string) => Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* 更新IPC设备单个收藏点信息
|
|
15
|
+
* @param {string} deviceId 设备id
|
|
16
|
+
* @param {number} id 收藏点id
|
|
17
|
+
* @param {string} name 收藏点名称
|
|
18
|
+
*/
|
|
19
|
+
export declare const updateCollectionPointsInfo: (deviceId: string, id: number, name: string) => Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* 删除IPC设备单个收藏点信息
|
|
22
|
+
* @param {string} deviceId 设备id
|
|
23
|
+
*/
|
|
24
|
+
export declare const delCollectionPointsInfo: (deviceId: string, pointData: [{
|
|
25
|
+
devId: string;
|
|
26
|
+
mpId: number;
|
|
27
|
+
}]) => Promise<import("../kit/interface").IRes>;
|
|
28
|
+
/**
|
|
29
|
+
* 添加IPC设备单个收藏点信息
|
|
30
|
+
* @param {string} deviceId 设备id
|
|
31
|
+
*/
|
|
32
|
+
export declare const addCollectionPointsInfo: (deviceId: string, name: string) => Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* 获取增值服务大类链接及是否直接跳转
|
|
35
|
+
* @param {string} deviceId 设备id
|
|
36
|
+
* @param {ServeTpe} serveType 支持的服务大类
|
|
37
|
+
* @param {object} paramData 路径拼接参数
|
|
38
|
+
* @param {boolean} action 是否直接跳转响应
|
|
39
|
+
* @param {string} utm_rtid 链路ID
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export declare const getServiceUrl: (deviceId: string, serveType: ServeTpe, paramData?: Record<string, any>, action?: boolean, utm_rtid?: string) => Promise<{
|
|
43
|
+
code: number;
|
|
44
|
+
msg?: string;
|
|
45
|
+
url?: string;
|
|
46
|
+
type?: number;
|
|
47
|
+
}>;
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.some.js";
|
|
5
|
+
/* eslint-disable camelcase */
|
|
6
|
+
import _trim from 'lodash/trim';
|
|
7
|
+
import { JsonUtil, getInitUtmTid } from '../utils';
|
|
8
|
+
import { getDevInfo, getNativeStorage, setNativeStorage, publishDps, getDpStateValue, getDpIdByCode, jumpToWebView, goToMiniProgramByShortLink, getCurrentSupportedTalkMode } from '../kit';
|
|
9
|
+
import { ClarityType, IntercomMode, MuteMode, ServeTpe } from '../interface';
|
|
10
|
+
const errStyle = 'background: red; color: #fff;';
|
|
11
|
+
|
|
12
|
+
// 获取 IPC 配置信息
|
|
13
|
+
const get_ipc_config_info_api = {
|
|
14
|
+
url: 'tuya.m.rtc.config.get',
|
|
15
|
+
version: '1.0'
|
|
16
|
+
};
|
|
17
|
+
// 获取 IPC 收藏点信息
|
|
18
|
+
const get_ipc_collect_info_api = {
|
|
19
|
+
url: 'tuya.m.ipc.memory.point.list',
|
|
20
|
+
version: '2.0'
|
|
21
|
+
};
|
|
22
|
+
// 更新 IPC 单个收藏点信息
|
|
23
|
+
const update_ipc_collect_info_api = {
|
|
24
|
+
url: 'tuya.m.ipc.memory.point.rename',
|
|
25
|
+
version: '1.0'
|
|
26
|
+
};
|
|
27
|
+
// 获取 IPC 增值服务平台配置地址
|
|
28
|
+
const get_ipc_cvas_url_api = {
|
|
29
|
+
url: 'm.ecm.cvas.basic.url.config.get',
|
|
30
|
+
version: '1.0'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @description: 对讲模式
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const intercomCallMode = {
|
|
38
|
+
1: IntercomMode.OneWay,
|
|
39
|
+
2: IntercomMode.TwoWay
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @description: 清晰度模式
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
const videoResolutionMode = {
|
|
47
|
+
1: ClarityType.SS,
|
|
48
|
+
2: ClarityType.SD,
|
|
49
|
+
4: ClarityType.HD,
|
|
50
|
+
8: ClarityType.UD,
|
|
51
|
+
16: ClarityType.SSP,
|
|
52
|
+
65535: ClarityType.AUDIO
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description: 通用接口调用
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
const api = function (a, postData) {
|
|
60
|
+
let v = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '1.0';
|
|
61
|
+
return new Promise(resolve => {
|
|
62
|
+
ty.apiRequestByAtop(_objectSpread(_objectSpread({}, {
|
|
63
|
+
api: a,
|
|
64
|
+
postData: postData,
|
|
65
|
+
version: v
|
|
66
|
+
}), {}, {
|
|
67
|
+
success: d => {
|
|
68
|
+
const data = typeof d === 'string' ? JsonUtil.parseJSON(d) : d;
|
|
69
|
+
resolve(data);
|
|
70
|
+
},
|
|
71
|
+
fail: err => {
|
|
72
|
+
const e = typeof err === 'string' ? JsonUtil.parseJSON(err) : err;
|
|
73
|
+
resolve({
|
|
74
|
+
code: -1,
|
|
75
|
+
msg: e.message || e.errorMsg || e
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 获取IPC设备配置信息
|
|
84
|
+
* @param deviceId 设备ID
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
const getIpcConfigInfo = deviceId => {
|
|
88
|
+
const {
|
|
89
|
+
url,
|
|
90
|
+
version
|
|
91
|
+
} = get_ipc_config_info_api;
|
|
92
|
+
return api(url, {
|
|
93
|
+
devId: deviceId
|
|
94
|
+
}, version);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 获取IPC设备配置及缓存信息、
|
|
99
|
+
* 包含: 视频清晰度、对讲方式、拾音器、视频缩放最大倍数
|
|
100
|
+
* @param {string} deviceId 设备id
|
|
101
|
+
*/
|
|
102
|
+
// eslint-disable-next-line consistent-return
|
|
103
|
+
export const getCameraConfigInfo = async deviceId => {
|
|
104
|
+
try {
|
|
105
|
+
const devInfo = await getDevInfo(deviceId);
|
|
106
|
+
if (devInfo.code !== 0) {
|
|
107
|
+
throw devInfo.msg;
|
|
108
|
+
}
|
|
109
|
+
const {
|
|
110
|
+
isVirtualDevice
|
|
111
|
+
} = devInfo.data;
|
|
112
|
+
// 配置默认值
|
|
113
|
+
const defaultResolution = ClarityType.HD;
|
|
114
|
+
const supportedResolutions = [ClarityType.HD, ClarityType.SD];
|
|
115
|
+
const defaultIntercomMode = IntercomMode.TwoWay;
|
|
116
|
+
const supportedIntercomModes = [IntercomMode.OneWay, IntercomMode.TwoWay];
|
|
117
|
+
const defaultMuteMode = MuteMode.OFF;
|
|
118
|
+
let maxZoomSettings = 6;
|
|
119
|
+
let microphoneSettings = {
|
|
120
|
+
isMicrophoneSupported: true,
|
|
121
|
+
defaultMuteMode,
|
|
122
|
+
cachedMuteMode: defaultMuteMode
|
|
123
|
+
};
|
|
124
|
+
let intercomInfo = {
|
|
125
|
+
isIntercomSupported: true,
|
|
126
|
+
defaultIntercomMode,
|
|
127
|
+
cachedIntercomMode: defaultIntercomMode,
|
|
128
|
+
supportedIntercomModes
|
|
129
|
+
};
|
|
130
|
+
let videoResolution = {
|
|
131
|
+
defaultResolution,
|
|
132
|
+
cachedResolution: defaultResolution,
|
|
133
|
+
availableResolutions: supportedResolutions
|
|
134
|
+
};
|
|
135
|
+
// native 缓存Key值
|
|
136
|
+
|
|
137
|
+
const nativeStorageInfo = await Promise.all([`${deviceId}_resolution`, `${deviceId}_intercom`, `${deviceId}_microphone`, `${deviceId}_maxZoomSettings`].map(key => getNativeStorage(key)));
|
|
138
|
+
console.log(nativeStorageInfo, 'nativeStorageInfo');
|
|
139
|
+
const [resolutionStorage, intercomStorage, microphoneStorage, maxZoomSettingsStorage] = nativeStorageInfo;
|
|
140
|
+
// 任意缓存为空,则请求接口
|
|
141
|
+
if (nativeStorageInfo.some(item => {
|
|
142
|
+
var _item$data;
|
|
143
|
+
return !(item !== null && item !== void 0 && (_item$data = item.data) !== null && _item$data !== void 0 && _item$data.data);
|
|
144
|
+
})) {
|
|
145
|
+
// 非虚拟机设备,请求接口
|
|
146
|
+
if (!isVirtualDevice) {
|
|
147
|
+
var _rtcApiResult$audioAt, _rtcApiResult$audioAt2, _rtcApiResult$audioAt3;
|
|
148
|
+
const rtcApiResult = await getIpcConfigInfo(deviceId);
|
|
149
|
+
|
|
150
|
+
// 1. 拾音器模块
|
|
151
|
+
const isMicrophoneSupported = rtcApiResult === null || rtcApiResult === void 0 || (_rtcApiResult$audioAt = rtcApiResult.audioAttributes) === null || _rtcApiResult$audioAt === void 0 || (_rtcApiResult$audioAt = _rtcApiResult$audioAt.hardwareCapability) === null || _rtcApiResult$audioAt === void 0 ? void 0 : _rtcApiResult$audioAt.includes(1);
|
|
152
|
+
// 拾音器默认声音都为关闭, 若接口返回不支持,则将缓存值设置为关闭
|
|
153
|
+
microphoneSettings.isMicrophoneSupported = isMicrophoneSupported;
|
|
154
|
+
const muteStatus = isMicrophoneSupported ? microphoneSettings.cachedMuteMode : defaultMuteMode;
|
|
155
|
+
microphoneSettings.cachedMuteMode = muteStatus;
|
|
156
|
+
|
|
157
|
+
// 2. 对讲功能模块
|
|
158
|
+
const isIntercomSupported = rtcApiResult === null || rtcApiResult === void 0 || (_rtcApiResult$audioAt2 = rtcApiResult.audioAttributes) === null || _rtcApiResult$audioAt2 === void 0 || (_rtcApiResult$audioAt2 = _rtcApiResult$audioAt2.hardwareCapability) === null || _rtcApiResult$audioAt2 === void 0 ? void 0 : _rtcApiResult$audioAt2.includes(2);
|
|
159
|
+
intercomInfo.isIntercomSupported = isIntercomSupported;
|
|
160
|
+
// 获取支持的对讲方式
|
|
161
|
+
const supportedIntercomModes = rtcApiResult === null || rtcApiResult === void 0 || (_rtcApiResult$audioAt3 = rtcApiResult.audioAttributes) === null || _rtcApiResult$audioAt3 === void 0 ? void 0 : _rtcApiResult$audioAt3.callMode;
|
|
162
|
+
if (isIntercomSupported && supportedIntercomModes.length > 0) {
|
|
163
|
+
var _appIntercomCached$da;
|
|
164
|
+
intercomInfo.defaultIntercomMode = intercomCallMode[supportedIntercomModes[0]];
|
|
165
|
+
intercomInfo.supportedIntercomModes = supportedIntercomModes.map(mode => intercomCallMode[mode]);
|
|
166
|
+
// 获取APP当前存储的对讲模式, 因目前设置页对讲设置使用的还是原生页面,需要读取APP缓存保持一致
|
|
167
|
+
const appIntercomCached = await getCurrentSupportedTalkMode(deviceId);
|
|
168
|
+
if (appIntercomCached.code !== 0) {
|
|
169
|
+
throw appIntercomCached.msg;
|
|
170
|
+
}
|
|
171
|
+
intercomInfo.cachedIntercomMode = intercomCallMode[appIntercomCached === null || appIntercomCached === void 0 || (_appIntercomCached$da = appIntercomCached.data) === null || _appIntercomCached$da === void 0 ? void 0 : _appIntercomCached$da.talkbackMode];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 3. 视频分辨率模块
|
|
175
|
+
videoResolution.defaultResolution = videoResolutionMode[rtcApiResult === null || rtcApiResult === void 0 ? void 0 : rtcApiResult.vedioClarity];
|
|
176
|
+
const supportedVideoClarity = rtcApiResult === null || rtcApiResult === void 0 ? void 0 : rtcApiResult.vedioClaritys;
|
|
177
|
+
videoResolution.availableResolutions = supportedVideoClarity.map(mode => videoResolutionMode[mode]);
|
|
178
|
+
|
|
179
|
+
// 4. 最大倍数模块
|
|
180
|
+
maxZoomSettings = (rtcApiResult === null || rtcApiResult === void 0 ? void 0 : rtcApiResult.maxZoomInTimes) !== 0 ? rtcApiResult === null || rtcApiResult === void 0 ? void 0 : rtcApiResult.maxZoomInTimes : 6;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 1. 设置拾音器缓存
|
|
184
|
+
if (!microphoneStorage.data) {
|
|
185
|
+
setNativeStorage(`${deviceId}_microphone`, microphoneSettings);
|
|
186
|
+
}
|
|
187
|
+
// 2. 设置对讲缓存
|
|
188
|
+
if (!intercomStorage.data) {
|
|
189
|
+
setNativeStorage(`${deviceId}_intercom`, intercomInfo);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 3. 设置视频清晰度缓存
|
|
193
|
+
if (!resolutionStorage.data) {
|
|
194
|
+
setNativeStorage(`${deviceId}_resolution`, videoResolution);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 4. 设置最大倍数缓存
|
|
198
|
+
if (!maxZoomSettingsStorage.data) {
|
|
199
|
+
setNativeStorage(`${deviceId}_maxZoomSettings`, maxZoomSettings);
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
var _appIntercomCached$da2, _intercomStorage$data;
|
|
203
|
+
// 对于对讲缓存的方式每次需从APP获取更新
|
|
204
|
+
intercomInfo = intercomStorage.data;
|
|
205
|
+
const appIntercomCached = await getCurrentSupportedTalkMode(deviceId);
|
|
206
|
+
if (appIntercomCached.code !== 0) {
|
|
207
|
+
throw appIntercomCached.msg;
|
|
208
|
+
}
|
|
209
|
+
intercomInfo.cachedIntercomMode = intercomCallMode[appIntercomCached === null || appIntercomCached === void 0 || (_appIntercomCached$da2 = appIntercomCached.data) === null || _appIntercomCached$da2 === void 0 ? void 0 : _appIntercomCached$da2.talkbackMode];
|
|
210
|
+
if ((intercomStorage === null || intercomStorage === void 0 || (_intercomStorage$data = intercomStorage.data) === null || _intercomStorage$data === void 0 ? void 0 : _intercomStorage$data.cachedIntercomMode) !== intercomInfo.cachedIntercomMode) {
|
|
211
|
+
setNativeStorage(`${deviceId}_intercom`, intercomInfo);
|
|
212
|
+
}
|
|
213
|
+
videoResolution = resolutionStorage.data;
|
|
214
|
+
microphoneSettings = microphoneStorage.data;
|
|
215
|
+
maxZoomSettings = maxZoomSettingsStorage.data;
|
|
216
|
+
}
|
|
217
|
+
const ipcConfig = {
|
|
218
|
+
videoResolution,
|
|
219
|
+
intercomInfo,
|
|
220
|
+
microphoneSettings,
|
|
221
|
+
maxZoomSettings
|
|
222
|
+
};
|
|
223
|
+
return ipcConfig;
|
|
224
|
+
} catch (err) {
|
|
225
|
+
ty.showToast({
|
|
226
|
+
title: I18n.t('get_ipc_config_info_api_err'),
|
|
227
|
+
icon: 'error'
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
code: -1,
|
|
231
|
+
msg: String(err)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 获取IPC设备配置收藏点信息列表
|
|
238
|
+
* @param {string} deviceId 设备id
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
export const getCollectionPointsInfo = deviceId => {
|
|
242
|
+
const {
|
|
243
|
+
url,
|
|
244
|
+
version
|
|
245
|
+
} = get_ipc_collect_info_api;
|
|
246
|
+
return api(url, {
|
|
247
|
+
devId: deviceId
|
|
248
|
+
}, version);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 更新IPC设备单个收藏点信息
|
|
253
|
+
* @param {string} deviceId 设备id
|
|
254
|
+
* @param {number} id 收藏点id
|
|
255
|
+
* @param {string} name 收藏点名称
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
export const updateCollectionPointsInfo = (deviceId, id, name) => {
|
|
259
|
+
const {
|
|
260
|
+
url,
|
|
261
|
+
version
|
|
262
|
+
} = update_ipc_collect_info_api;
|
|
263
|
+
if (_trim(name) === '') {
|
|
264
|
+
ty.showToast({
|
|
265
|
+
icon: 'error',
|
|
266
|
+
title: '请输入收藏点名称'
|
|
267
|
+
});
|
|
268
|
+
return {
|
|
269
|
+
code: -1,
|
|
270
|
+
msg: '请输入收藏点名称'
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
if (_trim(name).length > 10) {
|
|
274
|
+
ty.showToast({
|
|
275
|
+
icon: 'error',
|
|
276
|
+
title: '收藏点名称不能超过10个字符'
|
|
277
|
+
});
|
|
278
|
+
return {
|
|
279
|
+
code: -1,
|
|
280
|
+
msg: '收藏点名称不能超过10个字符'
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
return api(url, {
|
|
284
|
+
devId: deviceId,
|
|
285
|
+
id,
|
|
286
|
+
name
|
|
287
|
+
}, version);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 删除IPC设备单个收藏点信息
|
|
292
|
+
* @param {string} deviceId 设备id
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
export const delCollectionPointsInfo = async (deviceId, pointData) => {
|
|
296
|
+
// 1. 先获取巡航状态,如果正在巡航,提示停止巡航
|
|
297
|
+
const cruiseSwitchInfo = await getDpStateValue(deviceId, 'cruise_switch');
|
|
298
|
+
if ((cruiseSwitchInfo === null || cruiseSwitchInfo === void 0 ? void 0 : cruiseSwitchInfo.code) === -1) {
|
|
299
|
+
ty.showToast({
|
|
300
|
+
title: cruiseSwitchInfo.msg
|
|
301
|
+
});
|
|
302
|
+
return {
|
|
303
|
+
code: -1,
|
|
304
|
+
msg: cruiseSwitchInfo.msg
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
if (cruiseSwitchInfo.data) {
|
|
308
|
+
ty.showToast({
|
|
309
|
+
title: '正在巡航,请先停止巡航'
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
code: -1,
|
|
313
|
+
msg: '正在巡航,请先停止巡航'
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
// 2. 下发DP删除收藏点 dpCode: memory_point_set
|
|
317
|
+
const memoryPointSetDpId = await getDpIdByCode(deviceId, 'memory_point_set');
|
|
318
|
+
if ((cruiseSwitchInfo === null || cruiseSwitchInfo === void 0 ? void 0 : cruiseSwitchInfo.code) === -1) {
|
|
319
|
+
ty.showToast({
|
|
320
|
+
title: cruiseSwitchInfo.msg
|
|
321
|
+
});
|
|
322
|
+
return {
|
|
323
|
+
code: -1,
|
|
324
|
+
msg: cruiseSwitchInfo.msg
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
const publishResult = publishDps(deviceId, {
|
|
328
|
+
[memoryPointSetDpId.data]: JSON.stringify({
|
|
329
|
+
type: 2,
|
|
330
|
+
data: {
|
|
331
|
+
num: 1,
|
|
332
|
+
sets: pointData
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
});
|
|
336
|
+
if (publishResult.code === -1) {
|
|
337
|
+
ty.showToast({
|
|
338
|
+
icon: 'error',
|
|
339
|
+
title: publishResult.msg
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
return publishResult;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* 添加IPC设备单个收藏点信息
|
|
347
|
+
* @param {string} deviceId 设备id
|
|
348
|
+
*/
|
|
349
|
+
|
|
350
|
+
export const addCollectionPointsInfo = async (deviceId, name) => {
|
|
351
|
+
const collectList = await getCollectionPointsInfo(deviceId);
|
|
352
|
+
if (collectList.length >= 6) {
|
|
353
|
+
ty.showToast({
|
|
354
|
+
icon: 'error',
|
|
355
|
+
title: '最多只能添加6个收藏点'
|
|
356
|
+
});
|
|
357
|
+
return {
|
|
358
|
+
code: -1,
|
|
359
|
+
msg: '最多只能添加6个收藏点'
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
const cruiseSwitchInfo = await getDpStateValue(deviceId, 'cruise_switch');
|
|
363
|
+
if ((cruiseSwitchInfo === null || cruiseSwitchInfo === void 0 ? void 0 : cruiseSwitchInfo.code) === -1) {
|
|
364
|
+
ty.showToast({
|
|
365
|
+
icon: 'error',
|
|
366
|
+
title: cruiseSwitchInfo.msg
|
|
367
|
+
});
|
|
368
|
+
return {
|
|
369
|
+
code: -1,
|
|
370
|
+
msg: cruiseSwitchInfo.msg
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
if (cruiseSwitchInfo.data) {
|
|
374
|
+
ty.showToast({
|
|
375
|
+
icon: 'error',
|
|
376
|
+
title: '正在巡航,请先停止巡航'
|
|
377
|
+
});
|
|
378
|
+
return {
|
|
379
|
+
code: -1,
|
|
380
|
+
msg: '正在巡航,请先停止巡航'
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
// 2. 下发DP删除收藏点 dpCode: memory_point_set
|
|
384
|
+
const memoryPointSetDpId = await getDpIdByCode(deviceId, 'memory_point_set');
|
|
385
|
+
if ((cruiseSwitchInfo === null || cruiseSwitchInfo === void 0 ? void 0 : cruiseSwitchInfo.code) === -1) {
|
|
386
|
+
ty.showToast({
|
|
387
|
+
icon: 'error',
|
|
388
|
+
title: cruiseSwitchInfo.msg
|
|
389
|
+
});
|
|
390
|
+
return {
|
|
391
|
+
code: -1,
|
|
392
|
+
msg: cruiseSwitchInfo.msg
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (_trim(name) === '') {
|
|
396
|
+
ty.showToast({
|
|
397
|
+
icon: 'error',
|
|
398
|
+
title: '请输入收藏点名称'
|
|
399
|
+
});
|
|
400
|
+
return {
|
|
401
|
+
code: -1,
|
|
402
|
+
msg: '请输入收藏点名称'
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (_trim(name).length > 10) {
|
|
406
|
+
ty.showToast({
|
|
407
|
+
icon: 'error',
|
|
408
|
+
title: '收藏点名称不能超过10个字符'
|
|
409
|
+
});
|
|
410
|
+
return {
|
|
411
|
+
code: -1,
|
|
412
|
+
msg: '收藏点名称不能超过10个字符'
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
const publishResult = await publishDps(deviceId, {
|
|
416
|
+
[memoryPointSetDpId.data]: JSON.stringify({
|
|
417
|
+
type: 1,
|
|
418
|
+
data: {
|
|
419
|
+
name: _trim(name)
|
|
420
|
+
}
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
if (publishResult.code === -1) {
|
|
424
|
+
ty.showToast({
|
|
425
|
+
icon: 'error',
|
|
426
|
+
title: publishResult.msg
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
return publishResult;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* 获取增值服务大类链接及是否直接跳转
|
|
434
|
+
* @param {string} deviceId 设备id
|
|
435
|
+
* @param {ServeTpe} serveType 支持的服务大类
|
|
436
|
+
* @param {object} paramData 路径拼接参数
|
|
437
|
+
* @param {boolean} action 是否直接跳转响应
|
|
438
|
+
* @param {string} utm_rtid 链路ID
|
|
439
|
+
*
|
|
440
|
+
*/
|
|
441
|
+
|
|
442
|
+
export const getServiceUrl = async function (deviceId, serveType) {
|
|
443
|
+
let paramData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
444
|
+
let action = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
445
|
+
let utm_rtid = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : getInitUtmTid();
|
|
446
|
+
try {
|
|
447
|
+
const {
|
|
448
|
+
homeId
|
|
449
|
+
} = await ty.home.getCurrentHomeInfo();
|
|
450
|
+
const {
|
|
451
|
+
language
|
|
452
|
+
} = await ty.getSystemInfo();
|
|
453
|
+
const frontParams = {
|
|
454
|
+
bizOwner: 'ipc',
|
|
455
|
+
lang: language
|
|
456
|
+
};
|
|
457
|
+
if (serveType === ServeTpe.aiInspectionReport) {
|
|
458
|
+
// 巡检报告
|
|
459
|
+
frontParams.activeTime = paramData === null || paramData === void 0 ? void 0 : paramData.activeTime;
|
|
460
|
+
frontParams.reportId = paramData === null || paramData === void 0 ? void 0 : paramData.reportId;
|
|
461
|
+
frontParams.devId = paramData === null || paramData === void 0 ? void 0 : paramData.devId;
|
|
462
|
+
}
|
|
463
|
+
const params = {
|
|
464
|
+
path: '',
|
|
465
|
+
isSupportMini: true,
|
|
466
|
+
homeId,
|
|
467
|
+
param: frontParams,
|
|
468
|
+
categoryCode: serveType || ServeTpe.securityCloudService,
|
|
469
|
+
deviceId,
|
|
470
|
+
utmRtid: utm_rtid
|
|
471
|
+
};
|
|
472
|
+
if (serveType === ServeTpe.aiInspectionReport) {
|
|
473
|
+
// 巡检报告
|
|
474
|
+
params.categoryCode = '';
|
|
475
|
+
params.path = 'pages/aiInspection/reportDetails/index';
|
|
476
|
+
}
|
|
477
|
+
const {
|
|
478
|
+
url,
|
|
479
|
+
version
|
|
480
|
+
} = get_ipc_cvas_url_api;
|
|
481
|
+
const result = await api(url, params, version);
|
|
482
|
+
if ((result === null || result === void 0 ? void 0 : result.code) === -1) {
|
|
483
|
+
return result;
|
|
484
|
+
}
|
|
485
|
+
if (!action) {
|
|
486
|
+
return result;
|
|
487
|
+
}
|
|
488
|
+
if ((result === null || result === void 0 ? void 0 : result.type) === 2) {
|
|
489
|
+
// 跳转小程序
|
|
490
|
+
const minResult = await goToMiniProgramByShortLink(result === null || result === void 0 ? void 0 : result.url);
|
|
491
|
+
return minResult;
|
|
492
|
+
}
|
|
493
|
+
// 跳转H5
|
|
494
|
+
const webResult = await jumpToWebView(result === null || result === void 0 ? void 0 : result.url);
|
|
495
|
+
return webResult;
|
|
496
|
+
} catch (err) {
|
|
497
|
+
return {
|
|
498
|
+
code: -1,
|
|
499
|
+
msg: err
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// 常用函数方法
|
|
2
|
+
|
|
3
|
+
export const JsonUtil = {
|
|
4
|
+
parseJSON(str) {
|
|
5
|
+
if (typeof str !== 'string') {
|
|
6
|
+
return str || {}; // 如果不是字符串,直接返回原值或空对象
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(str); // 尝试直接解析JSON字符串
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return str; // 如果解析失败,返回原始字符串
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 初始化埋点链路ID
|
|
18
|
+
*/
|
|
19
|
+
export const getInitUtmTid = () => {
|
|
20
|
+
const choiceStr = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
21
|
+
let finalStr = '';
|
|
22
|
+
finalStr += choiceStr.charAt(Math.floor(Math.random() * 26));
|
|
23
|
+
for (let i = 0; i < 15; i++) {
|
|
24
|
+
finalStr += choiceStr.charAt(Math.floor(Math.random() * 36)); // 生成剩余的字符
|
|
25
|
+
}
|
|
26
|
+
return finalStr;
|
|
27
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ray-js/ray-ipc-utils",
|
|
3
|
+
"version": "1.1.0-beta-1",
|
|
4
|
+
"description": "IPC 工具库",
|
|
5
|
+
"main": "lib/index",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"types": "lib/index.d.ts",
|
|
11
|
+
"maintainers": [
|
|
12
|
+
"tuya_npm",
|
|
13
|
+
{
|
|
14
|
+
"name": "tuyafe",
|
|
15
|
+
"email": "tuyafe@tuya.com"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
|
20
|
+
"build": "ray build --type=component",
|
|
21
|
+
"watch": "ray start --type=component --output ./example/src/lib",
|
|
22
|
+
"build:tuya": "ray build -t tuya ./example",
|
|
23
|
+
"build:wechat": "ray build ./example --target=wechat",
|
|
24
|
+
"build:web": "ray build ./example --target=web",
|
|
25
|
+
"build:native": "ray build ./example --target=native",
|
|
26
|
+
"start:native": "ray start ./example -t native --verbose",
|
|
27
|
+
"start:tuya": "ray start -t tuya ./example --bundler=webpack",
|
|
28
|
+
"start:wechat": "ray start ./example -t wechat --verbose",
|
|
29
|
+
"start:web": "ray start ./example -t web",
|
|
30
|
+
"prepublishOnly": "yarn build",
|
|
31
|
+
"release-it": "standard-version",
|
|
32
|
+
"test": "yarn jest"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@ray-js/ray": "^1.4.9"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"clsx": "^1.2.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@commitlint/cli": "^7.2.1",
|
|
42
|
+
"@commitlint/config-conventional": "^9.0.1",
|
|
43
|
+
"@ray-js/cli": "^1.4.9",
|
|
44
|
+
"@ray-js/panel-sdk": "^1.13.0-storage.7",
|
|
45
|
+
"@ray-js/ray": "^1.4.9",
|
|
46
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
47
|
+
"@types/jest": "^29.5.14",
|
|
48
|
+
"core-js": "^3.19.1",
|
|
49
|
+
"eslint-config-tuya-panel": "^0.4.2",
|
|
50
|
+
"husky": "^1.2.0",
|
|
51
|
+
"lint-staged": "^10.2.11",
|
|
52
|
+
"standard-version": "9.3.2"
|
|
53
|
+
},
|
|
54
|
+
"resolutions": {
|
|
55
|
+
"@ray-js/builder-mp": "1.4.15",
|
|
56
|
+
"follow-redirects": "1.15.6",
|
|
57
|
+
"@babel/traverse": "7.25.9",
|
|
58
|
+
"dot-prop": "4.2.1",
|
|
59
|
+
"ejs": "3.1.10"
|
|
60
|
+
},
|
|
61
|
+
"husky": {
|
|
62
|
+
"hooks": {
|
|
63
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js",
|
|
64
|
+
"pre-commit": "lint-staged"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"lint-staged": {
|
|
68
|
+
"*.{ts,tsx,js,jsx}": [
|
|
69
|
+
"eslint --fix",
|
|
70
|
+
"git add"
|
|
71
|
+
],
|
|
72
|
+
"*.{json,md,yml,yaml}": [
|
|
73
|
+
"prettier --write",
|
|
74
|
+
"git add"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|