model-action 2.3.4 → 2.4.2
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/modules/Init.d.ts.map +1 -1
- package/dist/modules/Init.js +5 -2
- package/dist/modules/Init.js.map +1 -1
- package/dist/modules/SceneAsset.d.ts +104 -16
- package/dist/modules/SceneAsset.d.ts.map +1 -1
- package/dist/modules/SceneAsset.js +80 -10
- package/dist/modules/SceneAsset.js.map +1 -1
- package/dist/modules/Status.d.ts +9 -0
- package/dist/modules/Status.d.ts.map +1 -1
- package/dist/modules/Status.js +8 -0
- package/dist/modules/Status.js.map +1 -1
- package/dist/peer-stream.d.ts +3 -1
- package/dist/peer-stream.d.ts.map +1 -1
- package/dist/peer-stream.js +30 -6
- package/dist/peer-stream.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -0
- package/src/modules/Init.ts +122 -119
- package/src/modules/SceneAsset.ts +198 -20
- package/src/modules/Status.ts +164 -149
- package/src/peer-stream.js +32 -11
|
@@ -6,12 +6,19 @@ import { Action, SendParam } from "./Action";
|
|
|
6
6
|
/** 前端发往三维的 action */
|
|
7
7
|
export type SceneAssetActionType =
|
|
8
8
|
| "mapLocation"
|
|
9
|
+
| "mapPathTrack"
|
|
10
|
+
| "bindDevice"
|
|
11
|
+
| "focus"
|
|
9
12
|
| "editSave"
|
|
10
13
|
| "editCancel"
|
|
14
|
+
| "enableSceneEdit"
|
|
11
15
|
| "disableSceneEdit";
|
|
12
16
|
|
|
13
|
-
/** 资产大类:房间、POI
|
|
14
|
-
export type SceneAssetType = "Room" | "POI" | string;
|
|
17
|
+
/** 资产大类:房间、POI、巡更路线、路径点等 */
|
|
18
|
+
export type SceneAssetType = "Room" | "POI" | "Routing" | "PathPoint" | string;
|
|
19
|
+
|
|
20
|
+
/** 路线用途 */
|
|
21
|
+
export type SceneAssetPathUseType = "videoPatrol" | string;
|
|
15
22
|
|
|
16
23
|
/** 地图定位 — 房间在单层下的条目 */
|
|
17
24
|
export interface RoomMapLocationParam {
|
|
@@ -59,17 +66,62 @@ export type SceneAssetMapLocationPayload =
|
|
|
59
66
|
params: PoiMapLocationParam[];
|
|
60
67
|
};
|
|
61
68
|
|
|
69
|
+
/** 取点后搜索附近设备的参数 */
|
|
70
|
+
export interface PathTrackEditParam {
|
|
71
|
+
/** 取点后搜索设备点位的半径(米) */
|
|
72
|
+
searchRangeAtPathPoint?: number;
|
|
73
|
+
/** 搜索的点位类型;不传或空默认 Camera */
|
|
74
|
+
searchDeviceType?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 已有路线上的路径点(新增路线不传 points) */
|
|
78
|
+
export interface PathTrackPointParam {
|
|
79
|
+
/** 点在路径上的下标,新生成时由三维返回给前端存储 */
|
|
80
|
+
id: string;
|
|
81
|
+
/** 点的坐标 */
|
|
82
|
+
location?: string;
|
|
83
|
+
/** 点关联的设备 */
|
|
84
|
+
linkId?: string;
|
|
85
|
+
/** 室外空值或省略;楼内为 `buildingId_floor` */
|
|
86
|
+
place?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type SceneAssetMapPathTrackPayload = {
|
|
90
|
+
action: "mapPathTrack";
|
|
91
|
+
type: "Routing";
|
|
92
|
+
/** 路线用途,如 videoPatrol = 视频巡更 */
|
|
93
|
+
useType: SceneAssetPathUseType;
|
|
94
|
+
id: string;
|
|
95
|
+
editParam?: PathTrackEditParam;
|
|
96
|
+
/** 编辑已有路线时传入;新增路线不传 */
|
|
97
|
+
points?: PathTrackPointParam[];
|
|
98
|
+
};
|
|
99
|
+
|
|
62
100
|
export type SceneAssetPayload =
|
|
63
101
|
| SceneAssetMapLocationPayload
|
|
102
|
+
| SceneAssetMapPathTrackPayload
|
|
64
103
|
| {
|
|
65
104
|
action: "editSave";
|
|
105
|
+
type?: SceneAssetType;
|
|
106
|
+
/** 房间/POI 为三维 sceneId;巡更路线可不传,三维取当前编辑数据 */
|
|
107
|
+
id?: string;
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
action: "editCancel";
|
|
111
|
+
type?: SceneAssetType;
|
|
112
|
+
id?: string;
|
|
113
|
+
}
|
|
114
|
+
| {
|
|
115
|
+
action: "bindDevice";
|
|
66
116
|
type: SceneAssetType;
|
|
67
|
-
/**
|
|
117
|
+
/** 路径点 index(添加点时三维返回) */
|
|
68
118
|
id: string;
|
|
119
|
+
editParam?: PathTrackEditParam;
|
|
69
120
|
}
|
|
70
121
|
| {
|
|
71
|
-
action: "
|
|
122
|
+
action: "focus";
|
|
72
123
|
type: SceneAssetType;
|
|
124
|
+
/** 路径点 index */
|
|
73
125
|
id: string;
|
|
74
126
|
}
|
|
75
127
|
| {
|
|
@@ -92,18 +144,54 @@ export interface SceneAssetOnAssetSelectedData {
|
|
|
92
144
|
location: string;
|
|
93
145
|
}
|
|
94
146
|
|
|
95
|
-
/**
|
|
147
|
+
/** 三维推送:单个资产修改后的结果(房间/POI 等) */
|
|
96
148
|
export interface SceneAssetOnEditAssetData {
|
|
97
149
|
action: "OnEditAsset";
|
|
98
150
|
type: SceneAssetType;
|
|
99
|
-
id
|
|
100
|
-
sceneId
|
|
151
|
+
id?: string;
|
|
152
|
+
sceneId?: string;
|
|
153
|
+
/** 路径点场景下为点的 index */
|
|
154
|
+
index?: string;
|
|
155
|
+
location: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 路径点附近搜索到的设备 */
|
|
159
|
+
export interface PathPointLinkDevice {
|
|
160
|
+
sceneId?: string;
|
|
161
|
+
linkId: string;
|
|
162
|
+
type: string;
|
|
163
|
+
label?: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** 三维回传的路径点信息 */
|
|
167
|
+
export interface PathPointPushInfo {
|
|
168
|
+
index: string;
|
|
101
169
|
location: string;
|
|
170
|
+
place?: string;
|
|
171
|
+
linkDevices?: PathPointLinkDevice[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** 三维推送:Alt+左键取路径点 */
|
|
175
|
+
export interface SceneAssetOnAddPathPointData {
|
|
176
|
+
action: "OnAddPathPoint";
|
|
177
|
+
type: SceneAssetType;
|
|
178
|
+
id: string;
|
|
179
|
+
point: PathPointPushInfo;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** 三维推送:路径点重绑设备结果 */
|
|
183
|
+
export interface SceneAssetBindDeviceData {
|
|
184
|
+
action: "bindDevice";
|
|
185
|
+
type: SceneAssetType;
|
|
186
|
+
id: string;
|
|
187
|
+
point: PathPointPushInfo;
|
|
102
188
|
}
|
|
103
189
|
|
|
104
190
|
export type SceneAssetPushData =
|
|
105
191
|
| SceneAssetOnAssetSelectedData
|
|
106
|
-
| SceneAssetOnEditAssetData
|
|
192
|
+
| SceneAssetOnEditAssetData
|
|
193
|
+
| SceneAssetOnAddPathPointData
|
|
194
|
+
| SceneAssetBindDeviceData;
|
|
107
195
|
|
|
108
196
|
/** 三维经 sceneAsset 推送的通用消息壳(无 requestId) */
|
|
109
197
|
export interface SceneAssetPushMessage<
|
|
@@ -188,15 +276,61 @@ export class SceneAssetAction extends Action {
|
|
|
188
276
|
}
|
|
189
277
|
|
|
190
278
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
279
|
+
* 进入巡更路线编辑。路线列表「添加」或某一行「编辑」时调用。
|
|
280
|
+
* 新增路线不传 `points`;编辑已有路线且有点数据时再传。
|
|
193
281
|
*/
|
|
194
|
-
static
|
|
195
|
-
|
|
196
|
-
|
|
282
|
+
static mapPathTrack(
|
|
283
|
+
id: string,
|
|
284
|
+
editParam?: PathTrackEditParam,
|
|
285
|
+
points?: PathTrackPointParam[],
|
|
286
|
+
useType: SceneAssetPathUseType = "videoPatrol"
|
|
287
|
+
) {
|
|
288
|
+
const data: SceneAssetMapPathTrackPayload = {
|
|
289
|
+
action: "mapPathTrack",
|
|
290
|
+
type: "Routing",
|
|
291
|
+
useType,
|
|
292
|
+
id
|
|
293
|
+
};
|
|
294
|
+
if (editParam) {
|
|
295
|
+
data.editParam = { ...editParam };
|
|
296
|
+
if (!data.editParam.searchDeviceType?.trim()) {
|
|
297
|
+
delete data.editParam.searchDeviceType;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (points?.length) {
|
|
301
|
+
data.points = points;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const sendParam: SceneAssetParamType = {
|
|
305
|
+
cmd: "sceneAsset",
|
|
306
|
+
data
|
|
307
|
+
};
|
|
308
|
+
return this.sendParam(
|
|
309
|
+
sendParam,
|
|
310
|
+
`进入巡更路线编辑 - ${useType} id: ${id}${points?.length ? ` points: ${points.length}` : "(新增)"}`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* 重新绑定路径点附近设备(已有路线上的「重绑」)
|
|
316
|
+
* @param id 路径点 index
|
|
317
|
+
*/
|
|
318
|
+
static bindDevice(
|
|
319
|
+
id: string,
|
|
320
|
+
editParam?: PathTrackEditParam,
|
|
321
|
+
type: SceneAssetType = "Routing"
|
|
322
|
+
) {
|
|
323
|
+
const data: Extract<SceneAssetPayload, { action: "bindDevice" }> = {
|
|
324
|
+
action: "bindDevice",
|
|
197
325
|
type,
|
|
198
326
|
id
|
|
199
327
|
};
|
|
328
|
+
if (editParam) {
|
|
329
|
+
data.editParam = { ...editParam };
|
|
330
|
+
if (!data.editParam.searchDeviceType?.trim()) {
|
|
331
|
+
delete data.editParam.searchDeviceType;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
200
334
|
|
|
201
335
|
const sendParam: SceneAssetParamType = {
|
|
202
336
|
cmd: "sceneAsset",
|
|
@@ -204,17 +338,17 @@ export class SceneAssetAction extends Action {
|
|
|
204
338
|
};
|
|
205
339
|
return this.sendParam(
|
|
206
340
|
sendParam,
|
|
207
|
-
|
|
341
|
+
`场景资产重绑设备 - ${type} pointIndex: ${id}`
|
|
208
342
|
);
|
|
209
343
|
}
|
|
210
344
|
|
|
211
345
|
/**
|
|
212
|
-
*
|
|
213
|
-
* @param id
|
|
346
|
+
* 定位到路径上指定 index 的点,并展示编辑轴
|
|
347
|
+
* @param id 路径点 index
|
|
214
348
|
*/
|
|
215
|
-
static
|
|
216
|
-
const data: Extract<SceneAssetPayload, { action: "
|
|
217
|
-
action: "
|
|
349
|
+
static focusPathPoint(id: string, type: SceneAssetType = "Routing") {
|
|
350
|
+
const data: Extract<SceneAssetPayload, { action: "focus" }> = {
|
|
351
|
+
action: "focus",
|
|
218
352
|
type,
|
|
219
353
|
id
|
|
220
354
|
};
|
|
@@ -225,7 +359,51 @@ export class SceneAssetAction extends Action {
|
|
|
225
359
|
};
|
|
226
360
|
return this.sendParam(
|
|
227
361
|
sendParam,
|
|
228
|
-
|
|
362
|
+
`场景资产定位路径点 - ${type} pointIndex: ${id}`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* 前端编辑框「保存」后通知三维。
|
|
368
|
+
* 巡更路线可不传 `id`,三维取当前编辑数据。
|
|
369
|
+
* @param id 三维返回的 sceneId;Routing 可省略
|
|
370
|
+
*/
|
|
371
|
+
static editSave(id?: string, type: SceneAssetType = "Room") {
|
|
372
|
+
const data: Extract<SceneAssetPayload, { action: "editSave" }> = {
|
|
373
|
+
action: "editSave",
|
|
374
|
+
type
|
|
375
|
+
};
|
|
376
|
+
if (id) data.id = id;
|
|
377
|
+
|
|
378
|
+
const sendParam: SceneAssetParamType = {
|
|
379
|
+
cmd: "sceneAsset",
|
|
380
|
+
data
|
|
381
|
+
};
|
|
382
|
+
return this.sendParam(
|
|
383
|
+
sendParam,
|
|
384
|
+
`场景资产编辑保存 - ${type}${id ? ` id: ${id}` : ""}`
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* 前端编辑框「取消」后通知三维。
|
|
390
|
+
* 巡更路线可不传 `id`。
|
|
391
|
+
* @param id 三维返回的 sceneId;Routing 可省略
|
|
392
|
+
*/
|
|
393
|
+
static editCancel(id?: string, type: SceneAssetType = "Room") {
|
|
394
|
+
const data: Extract<SceneAssetPayload, { action: "editCancel" }> = {
|
|
395
|
+
action: "editCancel",
|
|
396
|
+
type
|
|
397
|
+
};
|
|
398
|
+
if (id) data.id = id;
|
|
399
|
+
|
|
400
|
+
const sendParam: SceneAssetParamType = {
|
|
401
|
+
cmd: "sceneAsset",
|
|
402
|
+
data
|
|
403
|
+
};
|
|
404
|
+
return this.sendParam(
|
|
405
|
+
sendParam,
|
|
406
|
+
`场景资产编辑取消 - ${type}${id ? ` id: ${id}` : ""}`
|
|
229
407
|
);
|
|
230
408
|
}
|
|
231
409
|
|
package/src/modules/Status.ts
CHANGED
|
@@ -1,150 +1,165 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 状态操作方法
|
|
3
|
-
*/
|
|
4
|
-
import { Action } from "./Action";
|
|
5
|
-
|
|
6
|
-
// 状态信息
|
|
7
|
-
export interface StatusInfo {
|
|
8
|
-
id: string; // 唯一标识
|
|
9
|
-
state: string; // 状态值:normal | alarm | color=FFFFFF
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Status命令类型(不继承SendParam,因为data中没有action字段)
|
|
13
|
-
type StatusType = {
|
|
14
|
-
cmd: "status";
|
|
15
|
-
data: {
|
|
16
|
-
isLocation?: boolean; // 是否定位到第一个ID对应的设备,默认false
|
|
17
|
-
type?: string; // 变换状态的类型,非必须,如"POI"
|
|
18
|
-
infos: StatusInfo[]; // 要切换状态的设备的数据
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class StatusAction extends Action {
|
|
23
|
-
/**
|
|
24
|
-
* 切换指定ID的模型、POI等的状态
|
|
25
|
-
* @param infos 状态信息数组,包含id和state
|
|
26
|
-
* @param options 可选参数
|
|
27
|
-
* @param options.isLocation 是否定位到第一个ID对应的设备,默认false
|
|
28
|
-
* @param options.type 变换状态的类型,如"POI"
|
|
29
|
-
*/
|
|
30
|
-
static statusChange(
|
|
31
|
-
infos: StatusInfo[],
|
|
32
|
-
options?: {
|
|
33
|
-
isLocation?: boolean;
|
|
34
|
-
type?: string;
|
|
35
|
-
}
|
|
36
|
-
) {
|
|
37
|
-
const data: {
|
|
38
|
-
isLocation?: boolean;
|
|
39
|
-
type?: string;
|
|
40
|
-
infos: StatusInfo[];
|
|
41
|
-
} = {
|
|
42
|
-
infos
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// 如果提供了 isLocation,则添加(默认false,所以只有为true时才添加)
|
|
46
|
-
if (options?.isLocation !== undefined) {
|
|
47
|
-
data.isLocation = options.isLocation;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// 如果提供了 type,则添加
|
|
51
|
-
if (options?.type) {
|
|
52
|
-
data.type = options.type;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const param: StatusType = {
|
|
56
|
-
cmd: "status",
|
|
57
|
-
data
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// 生成描述信息
|
|
61
|
-
let msg = '切换状态';
|
|
62
|
-
if (options?.type) {
|
|
63
|
-
msg = `切换${options.type}状态`;
|
|
64
|
-
}
|
|
65
|
-
if (infos.length === 1) {
|
|
66
|
-
msg += ` - ID: ${infos[0].id}, 状态: ${infos[0].state}`;
|
|
67
|
-
} else {
|
|
68
|
-
msg += ` - 共${infos.length}个设备`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 使用类型断言调用sendParam,因为StatusType不严格符合SendParam(缺少action字段)
|
|
72
|
-
return this.sendParam(param as any, msg);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 设置设备为正常状态
|
|
77
|
-
* @param id 设备ID
|
|
78
|
-
* @param options 可选参数
|
|
79
|
-
*/
|
|
80
|
-
static setNormal(
|
|
81
|
-
id: string,
|
|
82
|
-
options?: {
|
|
83
|
-
isLocation?: boolean;
|
|
84
|
-
type?: string;
|
|
85
|
-
}
|
|
86
|
-
) {
|
|
87
|
-
this.statusChange([{ id, state: 'normal' }], options);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @param id 设备ID
|
|
93
|
-
* @param options 可选参数
|
|
94
|
-
*/
|
|
95
|
-
static
|
|
96
|
-
id: string,
|
|
97
|
-
options?: {
|
|
98
|
-
isLocation?: boolean;
|
|
99
|
-
type?: string;
|
|
100
|
-
}
|
|
101
|
-
) {
|
|
102
|
-
this.statusChange([{ id, state: '
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
* @param id 设备ID
|
|
108
|
-
* @param
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 状态操作方法
|
|
3
|
+
*/
|
|
4
|
+
import { Action } from "./Action";
|
|
5
|
+
|
|
6
|
+
// 状态信息
|
|
7
|
+
export interface StatusInfo {
|
|
8
|
+
id: string; // 唯一标识
|
|
9
|
+
state: string; // 状态值:normal | alarm | color=FFFFFF
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Status命令类型(不继承SendParam,因为data中没有action字段)
|
|
13
|
+
type StatusType = {
|
|
14
|
+
cmd: "status";
|
|
15
|
+
data: {
|
|
16
|
+
isLocation?: boolean; // 是否定位到第一个ID对应的设备,默认false
|
|
17
|
+
type?: string; // 变换状态的类型,非必须,如"POI"
|
|
18
|
+
infos: StatusInfo[]; // 要切换状态的设备的数据
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class StatusAction extends Action {
|
|
23
|
+
/**
|
|
24
|
+
* 切换指定ID的模型、POI等的状态
|
|
25
|
+
* @param infos 状态信息数组,包含id和state
|
|
26
|
+
* @param options 可选参数
|
|
27
|
+
* @param options.isLocation 是否定位到第一个ID对应的设备,默认false
|
|
28
|
+
* @param options.type 变换状态的类型,如"POI"
|
|
29
|
+
*/
|
|
30
|
+
static statusChange(
|
|
31
|
+
infos: StatusInfo[],
|
|
32
|
+
options?: {
|
|
33
|
+
isLocation?: boolean;
|
|
34
|
+
type?: string;
|
|
35
|
+
}
|
|
36
|
+
) {
|
|
37
|
+
const data: {
|
|
38
|
+
isLocation?: boolean;
|
|
39
|
+
type?: string;
|
|
40
|
+
infos: StatusInfo[];
|
|
41
|
+
} = {
|
|
42
|
+
infos
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 如果提供了 isLocation,则添加(默认false,所以只有为true时才添加)
|
|
46
|
+
if (options?.isLocation !== undefined) {
|
|
47
|
+
data.isLocation = options.isLocation;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 如果提供了 type,则添加
|
|
51
|
+
if (options?.type) {
|
|
52
|
+
data.type = options.type;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const param: StatusType = {
|
|
56
|
+
cmd: "status",
|
|
57
|
+
data
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 生成描述信息
|
|
61
|
+
let msg = '切换状态';
|
|
62
|
+
if (options?.type) {
|
|
63
|
+
msg = `切换${options.type}状态`;
|
|
64
|
+
}
|
|
65
|
+
if (infos.length === 1) {
|
|
66
|
+
msg += ` - ID: ${infos[0].id}, 状态: ${infos[0].state}`;
|
|
67
|
+
} else {
|
|
68
|
+
msg += ` - 共${infos.length}个设备`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 使用类型断言调用sendParam,因为StatusType不严格符合SendParam(缺少action字段)
|
|
72
|
+
return this.sendParam(param as any, msg);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 设置设备为正常状态
|
|
77
|
+
* @param id 设备ID
|
|
78
|
+
* @param options 可选参数
|
|
79
|
+
*/
|
|
80
|
+
static setNormal(
|
|
81
|
+
id: string,
|
|
82
|
+
options?: {
|
|
83
|
+
isLocation?: boolean;
|
|
84
|
+
type?: string;
|
|
85
|
+
}
|
|
86
|
+
) {
|
|
87
|
+
this.statusChange([{ id, state: 'normal' }], options);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 设置设备为离线状态
|
|
92
|
+
* @param id 设备ID
|
|
93
|
+
* @param options 可选参数
|
|
94
|
+
*/
|
|
95
|
+
static setOffline(
|
|
96
|
+
id: string,
|
|
97
|
+
options?: {
|
|
98
|
+
isLocation?: boolean;
|
|
99
|
+
type?: string;
|
|
100
|
+
}
|
|
101
|
+
) {
|
|
102
|
+
this.statusChange([{ id, state: 'offline' }], options);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 设置设备为报警状态
|
|
107
|
+
* @param id 设备ID
|
|
108
|
+
* @param options 可选参数
|
|
109
|
+
*/
|
|
110
|
+
static setAlarm(
|
|
111
|
+
id: string,
|
|
112
|
+
options?: {
|
|
113
|
+
isLocation?: boolean;
|
|
114
|
+
type?: string;
|
|
115
|
+
}
|
|
116
|
+
) {
|
|
117
|
+
this.statusChange([{ id, state: 'alarm' }], options);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 设置设备颜色
|
|
122
|
+
* @param id 设备ID
|
|
123
|
+
* @param color 颜色值,格式如 "FFFFFF" 或 "93050C"(不需要#前缀)
|
|
124
|
+
* @param options 可选参数
|
|
125
|
+
*/
|
|
126
|
+
static setColor(
|
|
127
|
+
id: string,
|
|
128
|
+
color: string,
|
|
129
|
+
options?: {
|
|
130
|
+
isLocation?: boolean;
|
|
131
|
+
type?: string;
|
|
132
|
+
}
|
|
133
|
+
) {
|
|
134
|
+
// 移除可能的#前缀
|
|
135
|
+
const colorValue = color.startsWith('#') ? color.slice(1) : color;
|
|
136
|
+
this.statusChange([{ id, state: `color=${colorValue}` }], options);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 批量设置多个设备的状态
|
|
141
|
+
* @param statusMap 状态映射,key为设备ID,value为状态值(normal | alarm | color值)
|
|
142
|
+
* @param options 可选参数
|
|
143
|
+
*/
|
|
144
|
+
static batchSetStatus(
|
|
145
|
+
statusMap: Record<string, string>,
|
|
146
|
+
options?: {
|
|
147
|
+
isLocation?: boolean;
|
|
148
|
+
type?: string;
|
|
149
|
+
}
|
|
150
|
+
) {
|
|
151
|
+
const infos: StatusInfo[] = [];
|
|
152
|
+
for (const id in statusMap) {
|
|
153
|
+
if (statusMap.hasOwnProperty(id)) {
|
|
154
|
+
const state = statusMap[id];
|
|
155
|
+
// 如果state是颜色值(6位十六进制),自动添加color=前缀
|
|
156
|
+
let finalState = state;
|
|
157
|
+
if (/^[0-9A-Fa-f]{6}$/.test(state) && !state.startsWith('color=')) {
|
|
158
|
+
finalState = `color=${state}`;
|
|
159
|
+
}
|
|
160
|
+
infos.push({ id, state: finalState });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
this.statusChange(infos, options);
|
|
164
|
+
}
|
|
150
165
|
}
|