model-action 1.0.23 → 2.0.0

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 (66) hide show
  1. package/dist/index.d.ts +8 -4
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +8 -4
  4. package/dist/index.js.map +1 -0
  5. package/dist/modules/Action.d.ts +5 -14
  6. package/dist/modules/Action.d.ts.map +1 -0
  7. package/dist/modules/Action.js +1 -10
  8. package/dist/modules/Action.js.map +1 -0
  9. package/dist/modules/Building.d.ts +28 -0
  10. package/dist/modules/Building.d.ts.map +1 -0
  11. package/dist/modules/Building.js +70 -0
  12. package/dist/modules/Building.js.map +1 -0
  13. package/dist/modules/Camera.d.ts +37 -0
  14. package/dist/modules/Camera.d.ts.map +1 -0
  15. package/dist/modules/Camera.js +110 -0
  16. package/dist/modules/Camera.js.map +1 -0
  17. package/dist/modules/Environment.d.ts +22 -0
  18. package/dist/modules/Environment.d.ts.map +1 -0
  19. package/dist/modules/Environment.js +53 -0
  20. package/dist/modules/Environment.js.map +1 -0
  21. package/dist/modules/Focus.d.ts +12 -0
  22. package/dist/modules/Focus.d.ts.map +1 -0
  23. package/dist/modules/Focus.js +22 -0
  24. package/dist/modules/Focus.js.map +1 -0
  25. package/dist/modules/Poi.d.ts +45 -62
  26. package/dist/modules/Poi.d.ts.map +1 -0
  27. package/dist/modules/Poi.js +117 -88
  28. package/dist/modules/Poi.js.map +1 -0
  29. package/dist/modules/Routing.d.ts +23 -31
  30. package/dist/modules/Routing.d.ts.map +1 -0
  31. package/dist/modules/Routing.js +62 -63
  32. package/dist/modules/Routing.js.map +1 -0
  33. package/dist/modules/Scene.d.ts +12 -15
  34. package/dist/modules/Scene.d.ts.map +1 -0
  35. package/dist/modules/Scene.js +26 -15
  36. package/dist/modules/Scene.js.map +1 -0
  37. package/dist/modules/Status.d.ts +59 -0
  38. package/dist/modules/Status.d.ts.map +1 -0
  39. package/dist/modules/Status.js +91 -0
  40. package/dist/modules/Status.js.map +1 -0
  41. package/dist/modules/Track.d.ts +65 -22
  42. package/dist/modules/Track.d.ts.map +1 -0
  43. package/dist/modules/Track.js +128 -20
  44. package/dist/modules/Track.js.map +1 -0
  45. package/dist/modules/VideoFusion.d.ts +1 -0
  46. package/dist/modules/VideoFusion.d.ts.map +1 -0
  47. package/dist/modules/VideoFusion.js +1 -0
  48. package/dist/modules/VideoFusion.js.map +1 -0
  49. package/dist/modules/Window.d.ts +1 -0
  50. package/dist/modules/Window.d.ts.map +1 -0
  51. package/dist/modules/Window.js +1 -0
  52. package/dist/modules/Window.js.map +1 -0
  53. package/package.json +1 -1
  54. package/src/index.ts +7 -4
  55. package/src/modules/Action.ts +4 -25
  56. package/src/modules/Building.ts +103 -0
  57. package/src/modules/Camera.ts +175 -0
  58. package/src/modules/Environment.ts +81 -0
  59. package/src/modules/Focus.ts +33 -0
  60. package/src/modules/Poi.ts +194 -117
  61. package/src/modules/Routing.ts +96 -85
  62. package/src/modules/Scene.ts +43 -21
  63. package/src/modules/Status.ts +150 -0
  64. package/src/modules/Track.ts +259 -30
  65. package/src/modules/VideoFusion.ts +0 -122
  66. package/src/modules/Window.ts +0 -40
@@ -1,117 +1,128 @@
1
-
2
1
  /**
3
- * 巡更
2
+ * 巡检操作方法
4
3
  */
5
- import { Action, } from "./Action";
4
+ import { Action, SendParam } from "./Action";
5
+
6
+ // 路由巡视动作类型
7
+ export type RoutingActionType = 'start' | 'stop' | 'pause' | 'restart'
8
+
9
+ // 路由巡视类型
10
+ export type RoutingType = 'videoPatrol'
11
+
12
+ // 路由巡视参数
13
+ export interface RoutingParam {
14
+ type: RoutingType; // 巡视类型,目前只有 videoPatrol
15
+ id: string; // 路线ID,命名规则:园区室外使用 VP-1, VP-2;室内分层建筑使用 A-1(A楼1楼)
16
+ isPauseAtRouting?: boolean; // 巡检途中遇到摄像头弹框时是否停下来,默认 false
17
+ isRolerMoveOnRouting?: boolean; // 巡检途中是否有人在路径上行走,默认 false
18
+ isViewFollow?: boolean; // 巡检途中视角是否跟随路径线,默认 false。true时,isRolerMoveOnRouting 应为 false
19
+ }
20
+
21
+ type RoutingParamType = SendParam & {
22
+ cmd: "routing";
23
+ data: {
24
+ action: RoutingActionType;
25
+ type?: RoutingType;
26
+ id?: string;
27
+ isPauseAtRouting?: boolean;
28
+ isRolerMoveOnRouting?: boolean;
29
+ isViewFollow?: boolean;
30
+ };
31
+ }
6
32
 
7
33
  export class RoutingAction extends Action {
8
34
  /**
9
- * 巡检开始
10
- * @param {*} id (必须)巡检的唯一ID)
11
- * @param {*} type (必须)巡检的类型)
12
- * videoPatrol => 视频巡更
13
- * cameraRoute => 视角跟随样条线
14
- */
15
- static videoPatrolStart(id: string, type: string = "videoPatrol", extendParams = {}) {
16
- const param: any = {
17
- cmd: "routing",
18
- action: "start",
19
- id,
20
- ...extendParams,
35
+ * 开始路由巡视
36
+ * 显示指定路线的巡视效果,相机跟随路线,线路是在场景中预设的一条固定的样条线
37
+ * @param param 路由巡视参数
38
+ */
39
+ static start(param: RoutingParam) {
40
+ // 如果 isViewFollow 为 true,则 isRolerMoveOnRouting 应该为 false
41
+ if (param.isViewFollow === true && param.isRolerMoveOnRouting === true) {
42
+ console.warn('当 isViewFollow true 时,isRolerMoveOnRouting 应该为 false');
43
+ }
44
+
45
+ const data: {
46
+ action: 'start';
47
+ type: RoutingType;
48
+ id: string;
49
+ isPauseAtRouting?: boolean;
50
+ isRolerMoveOnRouting?: boolean;
51
+ isViewFollow?: boolean;
52
+ } = {
53
+ action: 'start',
54
+ type: param.type,
55
+ id: param.id
21
56
  };
22
- if (type) {
23
- param.type = type
57
+
58
+ // 可选参数
59
+ if (param.isPauseAtRouting !== undefined) {
60
+ data.isPauseAtRouting = param.isPauseAtRouting;
61
+ }
62
+ if (param.isRolerMoveOnRouting !== undefined) {
63
+ data.isRolerMoveOnRouting = param.isRolerMoveOnRouting;
64
+ }
65
+ if (param.isViewFollow !== undefined) {
66
+ data.isViewFollow = param.isViewFollow;
24
67
  }
25
- this.sendParam(param, '巡更开始')
26
- }
27
68
 
28
- /**
29
- * 巡检结束
30
- * @param {*} id (必须)巡检的唯一ID)
31
- * @param {*} type (必须)巡检的类型)
32
- */
33
- static videoPatrolStop(id: string, type: string = "videoPatrol", extendParams = {}) {
34
- const param: any = {
69
+ const sendParam: RoutingParamType = {
35
70
  cmd: "routing",
36
- action: "stop",
37
- id,
38
- ...extendParams,
71
+ data
39
72
  };
40
- if (type) {
41
- param.type = type
42
- }
43
- this.sendParam(param, '巡更结束')
73
+ this.sendParam(sendParam, '开始路由巡视')
44
74
  }
45
75
 
46
76
  /**
47
- * 巡检暂停
48
- * @param {*} id (必须)巡检的唯一ID)
49
- * @param {*} type (必须)巡检的类型)
77
+ * 停止路由巡视
78
+ * 停止并隐藏巡视,整条巡检结束后,必须调用 start 才能重新开始
50
79
  */
51
- static videoPatrolPause(id: string, type: string = "videoPatrol", extendParams = {}) {
52
- const param: any = {
53
- cmd: "routing",
54
- action: "pause",
55
- id,
56
- ...extendParams,
80
+ static stop() {
81
+ const data: {
82
+ action: 'stop';
83
+ } = {
84
+ action: 'stop'
57
85
  };
58
- if (type) {
59
- param.type = type
60
- }
61
- this.sendParam(param, '巡更暂停')
62
- }
63
86
 
64
- /**
65
- * 巡检下一步
66
- * @param {*} id (必须)巡检的唯一ID)
67
- * @param {*} type (必须)巡检的类型)
68
- */
69
- static videoPatrolNext(id: string, type: string = "videoPatrol", extendParams = {}) {
70
- const param: any = {
87
+ const sendParam: RoutingParamType = {
71
88
  cmd: "routing",
72
- action: "next",
73
- id,
74
- ...extendParams,
89
+ data
75
90
  };
76
- if (type) {
77
- param.type = type
78
- }
79
- this.sendParam(param, '巡更下一步')
91
+ this.sendParam(sendParam, '停止路由巡视')
80
92
  }
81
93
 
82
94
  /**
83
- * 巡更上一步
84
- * @param {*} id (必须)巡检的唯一ID)
85
- * @param {*} type (必须)巡检的类型)
95
+ * 暂停路由巡视
86
96
  */
87
- static videoPatrolPrev(id: string, type: string = "videoPatrol", extendParams = {}) {
88
- const param: any = {
97
+ static pause() {
98
+ const data: {
99
+ action: 'pause';
100
+ } = {
101
+ action: 'pause'
102
+ };
103
+
104
+ const sendParam: RoutingParamType = {
89
105
  cmd: "routing",
90
- action: "last",
91
- id,
92
- ...extendParams,
106
+ data
93
107
  };
94
- if(type){
95
- param.type = type
96
- }
97
- this.sendParam(param, '巡更上一步')
108
+ this.sendParam(sendParam, '暂停路由巡视')
98
109
  }
99
110
 
100
111
  /**
101
- * 巡更重新开始,从暂停点开始
102
- * @param {*} id (必须)巡检的唯一ID)
103
- * @param {*} type (必须)巡检的类型)
112
+ * 重新开始路由巡视
113
+ * 从暂停点继续开始巡视
104
114
  */
105
- static videoPatrolRestart(id: string, type: string = "videoPatrol", extendParams = {}) {
106
- const param: any = {
115
+ static restart() {
116
+ const data: {
117
+ action: 'restart';
118
+ } = {
119
+ action: 'restart'
120
+ };
121
+
122
+ const sendParam: RoutingParamType = {
107
123
  cmd: "routing",
108
- action: "restart",
109
- id,
110
- ...extendParams,
124
+ data
111
125
  };
112
- if (type) {
113
- param.type = type
114
- }
115
- this.sendParam(param, '巡更重新开始,从暂停点开始')
126
+ this.sendParam(sendParam, '重新开始路由巡视')
116
127
  }
117
128
  }
@@ -1,35 +1,57 @@
1
-
2
-
3
-
4
1
  /**
5
- * 场景方法
2
+ * 场景操作方法
6
3
  */
7
4
  import { Action, SendParam } from "./Action";
8
5
 
6
+ // 场景操作类型
7
+ export type SceneActionType = 'changeSence' | 'resetSence';
9
8
 
10
- enum SceneActionType{
11
- Exit = '0', //退出独显
12
- Enter = '1', //进入独显
9
+ // 场景编码类型
10
+ export type SceneCode = 'QF' | 'RZ' | string; // QF = 曲阜,RZ = 日照
11
+
12
+ type SceneParamType = SendParam & {
13
+ cmd: "sence";
14
+ data: {
15
+ action: SceneActionType;
16
+ code?: SceneCode;
17
+ };
13
18
  }
14
- type SceneType = {
15
- action: SceneActionType,
16
- isAdjustLight: boolean //是否调整灯光
17
- tag?: string, //指定场景需要打的tag,根据项目定义,如果场景中只有一处需要独显,这里可以不传该字段
18
- } & SendParam
19
19
 
20
20
  export class SceneAction extends Action {
21
21
  /**
22
- * 独显某场景模型
23
- * @param {*} action 1进入独显 0退出独显
22
+ * 切换场景
23
+ * @param code 场景编码
24
24
  */
25
- static singleShow(action:SceneActionType,isAdjustLight:SceneType['isAdjustLight'] = false,tag:SceneType['tag']) {
26
- const param: SceneType = {
27
- cmd: "POI",
28
- action,
29
- tag,
30
- isAdjustLight
25
+ static changeSence(code: SceneCode) {
26
+ const data: {
27
+ action: 'changeSence';
28
+ code: SceneCode;
29
+ } = {
30
+ action: 'changeSence',
31
+ code
32
+ };
33
+
34
+ const sendParam: SceneParamType = {
35
+ cmd: "sence",
36
+ data
31
37
  };
32
- this.sendParam(param, `${action==='0'?'退出':'进入'}独显`);
38
+ this.sendParam(sendParam, `切换场景 - code: ${code}`);
33
39
  }
34
40
 
41
+ /**
42
+ * 重置场景到初始状态
43
+ */
44
+ static resetSence() {
45
+ const data: {
46
+ action: 'resetSence';
47
+ } = {
48
+ action: 'resetSence'
49
+ };
50
+
51
+ const sendParam: SceneParamType = {
52
+ cmd: "sence",
53
+ data
54
+ };
55
+ this.sendParam(sendParam, '重置场景到初始状态');
56
+ }
35
57
  }
@@ -0,0 +1,150 @@
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
+ 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 setAlarm(
96
+ id: string,
97
+ options?: {
98
+ isLocation?: boolean;
99
+ type?: string;
100
+ }
101
+ ) {
102
+ this.statusChange([{ id, state: 'alarm' }], options);
103
+ }
104
+
105
+ /**
106
+ * 设置设备颜色
107
+ * @param id 设备ID
108
+ * @param color 颜色值,格式如 "FFFFFF" 或 "93050C"(不需要#前缀)
109
+ * @param options 可选参数
110
+ */
111
+ static setColor(
112
+ id: string,
113
+ color: string,
114
+ options?: {
115
+ isLocation?: boolean;
116
+ type?: string;
117
+ }
118
+ ) {
119
+ // 移除可能的#前缀
120
+ const colorValue = color.startsWith('#') ? color.slice(1) : color;
121
+ this.statusChange([{ id, state: `color=${colorValue}` }], options);
122
+ }
123
+
124
+ /**
125
+ * 批量设置多个设备的状态
126
+ * @param statusMap 状态映射,key为设备ID,value为状态值(normal | alarm | color值)
127
+ * @param options 可选参数
128
+ */
129
+ static batchSetStatus(
130
+ statusMap: Record<string, string>,
131
+ options?: {
132
+ isLocation?: boolean;
133
+ type?: string;
134
+ }
135
+ ) {
136
+ const infos: StatusInfo[] = [];
137
+ for (const id in statusMap) {
138
+ if (statusMap.hasOwnProperty(id)) {
139
+ const state = statusMap[id];
140
+ // 如果state是颜色值(6位十六进制),自动添加color=前缀
141
+ let finalState = state;
142
+ if (/^[0-9A-Fa-f]{6}$/.test(state) && !state.startsWith('color=')) {
143
+ finalState = `color=${state}`;
144
+ }
145
+ infos.push({ id, state: finalState });
146
+ }
147
+ }
148
+ this.statusChange(infos, options);
149
+ }
150
+ }