nayota-show-sdk 1.3.96 → 1.3.98
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/api/bmsRouter.js +2 -2
- package/api/devices.js +8 -0
- package/package.json +1 -1
- package/utils/iot-module-specs.js +34 -0
- package/utils/iot-module-specs.test.js +51 -0
- package/utils/legacy-bms-router.js +133 -0
- package/utils/legacy-bms-router.test.js +74 -0
package/api/bmsRouter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { requestShow } from '../utils'
|
|
2
|
+
import { normalizeLegacyCameraRouterResponse } from '../utils/legacy-bms-router'
|
|
2
3
|
/**
|
|
3
4
|
* @file BMS路由api
|
|
4
5
|
* @module BMS路由接口
|
|
@@ -134,7 +135,7 @@ export function list(query) {
|
|
|
134
135
|
url: '/bms-routers',
|
|
135
136
|
method: 'get',
|
|
136
137
|
params: query
|
|
137
|
-
})
|
|
138
|
+
}).then(response => normalizeLegacyCameraRouterResponse(response))
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
/**
|
|
@@ -212,4 +213,3 @@ export default {
|
|
|
212
213
|
deleteMany,
|
|
213
214
|
getOne
|
|
214
215
|
}
|
|
215
|
-
|
package/api/devices.js
CHANGED
|
@@ -399,6 +399,10 @@ export function getPropHistoryData(data) {
|
|
|
399
399
|
* }
|
|
400
400
|
*/
|
|
401
401
|
export function updateDepart(data) {
|
|
402
|
+
if (shouldUseIot('updateDepart')) {
|
|
403
|
+
return executeIotModuleAction(MODULE_NAME, 'updateDepart', data)
|
|
404
|
+
}
|
|
405
|
+
|
|
402
406
|
return requestShow({
|
|
403
407
|
url: '/devices/updateDepart',
|
|
404
408
|
method: 'post',
|
|
@@ -407,6 +411,10 @@ export function updateDepart(data) {
|
|
|
407
411
|
}
|
|
408
412
|
|
|
409
413
|
export function updateProp(data) {
|
|
414
|
+
if (shouldUseIot('updateProp')) {
|
|
415
|
+
return executeIotModuleAction(MODULE_NAME, 'updateProp', data)
|
|
416
|
+
}
|
|
417
|
+
|
|
410
418
|
return requestShow({
|
|
411
419
|
url: '/devices/updateProp',
|
|
412
420
|
method: 'post',
|
package/package.json
CHANGED
|
@@ -1195,6 +1195,40 @@ export const iotModuleSpecs = {
|
|
|
1195
1195
|
message: data?.message ?? payload?.message
|
|
1196
1196
|
})
|
|
1197
1197
|
}
|
|
1198
|
+
},
|
|
1199
|
+
updateDepart: {
|
|
1200
|
+
toRequest(data = {}) {
|
|
1201
|
+
return {
|
|
1202
|
+
url: '/devices/updateDepart',
|
|
1203
|
+
method: 'post',
|
|
1204
|
+
data
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
fromResponse(response) {
|
|
1208
|
+
const payload = response && response.data && response.status ? response.data : response
|
|
1209
|
+
const data = payload?.data !== undefined ? payload.data : payload
|
|
1210
|
+
return removeUndefinedFields({
|
|
1211
|
+
code: Number(data?.code ?? payload?.code ?? 0),
|
|
1212
|
+
message: data?.message ?? payload?.message ?? '更新成功'
|
|
1213
|
+
})
|
|
1214
|
+
}
|
|
1215
|
+
},
|
|
1216
|
+
updateProp: {
|
|
1217
|
+
toRequest(data = {}) {
|
|
1218
|
+
return {
|
|
1219
|
+
url: '/devices/updateProp',
|
|
1220
|
+
method: 'post',
|
|
1221
|
+
data
|
|
1222
|
+
}
|
|
1223
|
+
},
|
|
1224
|
+
fromResponse(response) {
|
|
1225
|
+
const payload = response && response.data && response.status ? response.data : response
|
|
1226
|
+
const data = payload?.data !== undefined ? payload.data : payload
|
|
1227
|
+
return removeUndefinedFields({
|
|
1228
|
+
code: Number(data?.code ?? payload?.code ?? 0),
|
|
1229
|
+
message: data?.message ?? payload?.message ?? '更新成功'
|
|
1230
|
+
})
|
|
1231
|
+
}
|
|
1198
1232
|
}
|
|
1199
1233
|
}
|
|
1200
1234
|
},
|
|
@@ -735,3 +735,54 @@ describe('iotModuleSpecs devices getPropHistoryData legacy compatibility', () =>
|
|
|
735
735
|
})
|
|
736
736
|
})
|
|
737
737
|
})
|
|
738
|
+
|
|
739
|
+
describe('iotModuleSpecs devices legacy mutation compatibility', () => {
|
|
740
|
+
const devices = iotModuleSpecs.devices.operations
|
|
741
|
+
|
|
742
|
+
test('posts updateDepart to the v2 legacy-compatible endpoint', () => {
|
|
743
|
+
const payload = {
|
|
744
|
+
deviceIds: ['twin-1', 'twin-2'],
|
|
745
|
+
depart: 'hierarchy-1'
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const request = devices.updateDepart.toRequest(payload)
|
|
749
|
+
|
|
750
|
+
expect(request).toEqual({
|
|
751
|
+
url: '/devices/updateDepart',
|
|
752
|
+
method: 'post',
|
|
753
|
+
data: payload
|
|
754
|
+
})
|
|
755
|
+
|
|
756
|
+
expect(devices.updateDepart.fromResponse({ code: 0 })).toEqual({
|
|
757
|
+
code: 0,
|
|
758
|
+
message: '更新成功'
|
|
759
|
+
})
|
|
760
|
+
})
|
|
761
|
+
|
|
762
|
+
test('posts updateProp to the v2 legacy-compatible endpoint', () => {
|
|
763
|
+
const payload = {
|
|
764
|
+
deviceId: 'twin-1',
|
|
765
|
+
iotDeviceId: 'device-1',
|
|
766
|
+
props: [
|
|
767
|
+
{
|
|
768
|
+
type: 'Operate',
|
|
769
|
+
address: 'powerSwitch',
|
|
770
|
+
name: '开关'
|
|
771
|
+
}
|
|
772
|
+
]
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
const request = devices.updateProp.toRequest(payload)
|
|
776
|
+
|
|
777
|
+
expect(request).toEqual({
|
|
778
|
+
url: '/devices/updateProp',
|
|
779
|
+
method: 'post',
|
|
780
|
+
data: payload
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
expect(devices.updateProp.fromResponse({ code: 0, message: '更新成功' })).toEqual({
|
|
784
|
+
code: 0,
|
|
785
|
+
message: '更新成功'
|
|
786
|
+
})
|
|
787
|
+
})
|
|
788
|
+
})
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const CAMERA_GROUP_SUBJECT = 'models-camera'
|
|
2
|
+
const CAMERA_DEVICE_SUBJECT = 'models-camera-device'
|
|
3
|
+
|
|
4
|
+
function text(value) {
|
|
5
|
+
return String(value || '').trim()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function lower(value) {
|
|
9
|
+
return text(value).toLowerCase()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function isCameraRoute(route = {}) {
|
|
13
|
+
const subject = lower(route.subject)
|
|
14
|
+
const path = lower(route.path)
|
|
15
|
+
const name = text(route.name || route.title)
|
|
16
|
+
const icon = lower(route.icon && typeof route.icon === 'object' ? route.icon.icon : route.icon)
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
subject.includes('camera') ||
|
|
20
|
+
path.includes('camera') ||
|
|
21
|
+
name.includes('摄像头') ||
|
|
22
|
+
name.includes('视频监控') ||
|
|
23
|
+
icon.includes('camera') ||
|
|
24
|
+
icon.includes('video')
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function hasCameraChild(route = {}) {
|
|
29
|
+
return Array.isArray(route.children) && route.children.some(child => isCameraRoute(child))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function toLegacyCameraChild(route = {}, level) {
|
|
33
|
+
return {
|
|
34
|
+
...route,
|
|
35
|
+
name: route.name === '摄像头监控' ? '设备管理' : route.name || '设备管理',
|
|
36
|
+
type: '页面',
|
|
37
|
+
path: CAMERA_DEVICE_SUBJECT,
|
|
38
|
+
subject: CAMERA_DEVICE_SUBJECT,
|
|
39
|
+
level: level + 1,
|
|
40
|
+
children: []
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function normalizeLegacyCameraRouterItem(route = {}) {
|
|
45
|
+
const children = Array.isArray(route.children)
|
|
46
|
+
? route.children.map(child => normalizeLegacyCameraRouterItem(child))
|
|
47
|
+
: []
|
|
48
|
+
const routeWithChildren = { ...route, children }
|
|
49
|
+
|
|
50
|
+
if (!isCameraRoute(routeWithChildren)) {
|
|
51
|
+
return routeWithChildren
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
lower(routeWithChildren.subject) === CAMERA_DEVICE_SUBJECT ||
|
|
56
|
+
lower(routeWithChildren.path) === CAMERA_DEVICE_SUBJECT
|
|
57
|
+
) {
|
|
58
|
+
return {
|
|
59
|
+
...routeWithChildren,
|
|
60
|
+
type: routeWithChildren.type || '页面',
|
|
61
|
+
path: CAMERA_DEVICE_SUBJECT,
|
|
62
|
+
subject: CAMERA_DEVICE_SUBJECT
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (hasCameraChild(routeWithChildren)) {
|
|
67
|
+
return {
|
|
68
|
+
...routeWithChildren,
|
|
69
|
+
name: routeWithChildren.name || '摄像头监控',
|
|
70
|
+
subject: routeWithChildren.subject && lower(routeWithChildren.subject).includes('camera')
|
|
71
|
+
? routeWithChildren.subject
|
|
72
|
+
: CAMERA_GROUP_SUBJECT
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const level = Number.isFinite(Number(routeWithChildren.level))
|
|
77
|
+
? Number(routeWithChildren.level)
|
|
78
|
+
: 0
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
...routeWithChildren,
|
|
82
|
+
name: routeWithChildren.name || '摄像头监控',
|
|
83
|
+
type: '分组',
|
|
84
|
+
path: routeWithChildren.path && lower(routeWithChildren.path).includes('camera')
|
|
85
|
+
? undefined
|
|
86
|
+
: routeWithChildren.path,
|
|
87
|
+
subject: CAMERA_GROUP_SUBJECT,
|
|
88
|
+
level,
|
|
89
|
+
children: [toLegacyCameraChild(routeWithChildren, level)]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function normalizeRows(rows) {
|
|
94
|
+
return rows.map(row => normalizeLegacyCameraRouterItem(row))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function normalizeLegacyCameraRouterResponse(response) {
|
|
98
|
+
if (!response || typeof response !== 'object') {
|
|
99
|
+
return response
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (Array.isArray(response.rows)) {
|
|
103
|
+
return {
|
|
104
|
+
...response,
|
|
105
|
+
rows: normalizeRows(response.rows)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (response.data && Array.isArray(response.data.rows)) {
|
|
110
|
+
return {
|
|
111
|
+
...response,
|
|
112
|
+
data: {
|
|
113
|
+
...response.data,
|
|
114
|
+
rows: normalizeRows(response.data.rows)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (response.data?.data && Array.isArray(response.data.data.rows)) {
|
|
120
|
+
return {
|
|
121
|
+
...response,
|
|
122
|
+
data: {
|
|
123
|
+
...response.data,
|
|
124
|
+
data: {
|
|
125
|
+
...response.data.data,
|
|
126
|
+
rows: normalizeRows(response.data.data.rows)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return response
|
|
133
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const {
|
|
2
|
+
normalizeLegacyCameraRouterItem,
|
|
3
|
+
normalizeLegacyCameraRouterResponse
|
|
4
|
+
} = require('./legacy-bms-router')
|
|
5
|
+
|
|
6
|
+
describe('legacy BMS router camera compatibility', () => {
|
|
7
|
+
test('wraps camera leaf route as the legacy camera group', () => {
|
|
8
|
+
const result = normalizeLegacyCameraRouterItem({
|
|
9
|
+
_id: 'route-camera',
|
|
10
|
+
name: '摄像头监控',
|
|
11
|
+
type: '页面',
|
|
12
|
+
subject: 'route-legacy-camera',
|
|
13
|
+
path: 'camera-management',
|
|
14
|
+
level: 0,
|
|
15
|
+
children: []
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
expect(result).toMatchObject({
|
|
19
|
+
_id: 'route-camera',
|
|
20
|
+
name: '摄像头监控',
|
|
21
|
+
type: '分组',
|
|
22
|
+
subject: 'models-camera',
|
|
23
|
+
level: 0
|
|
24
|
+
})
|
|
25
|
+
expect(result.children).toHaveLength(1)
|
|
26
|
+
expect(result.children[0]).toMatchObject({
|
|
27
|
+
name: '设备管理',
|
|
28
|
+
type: '页面',
|
|
29
|
+
subject: 'models-camera-device',
|
|
30
|
+
path: 'models-camera-device',
|
|
31
|
+
level: 1,
|
|
32
|
+
children: []
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('keeps existing legacy camera children and normalizes group subject', () => {
|
|
37
|
+
const result = normalizeLegacyCameraRouterItem({
|
|
38
|
+
name: '摄像头监控',
|
|
39
|
+
type: '分组',
|
|
40
|
+
subject: 'group-models-1731378379908',
|
|
41
|
+
children: [
|
|
42
|
+
{
|
|
43
|
+
name: '设备管理',
|
|
44
|
+
type: '页面',
|
|
45
|
+
subject: 'models-camera-device',
|
|
46
|
+
path: 'models-camera-device'
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
expect(result.subject).toBe('models-camera')
|
|
52
|
+
expect(result.children[0].subject).toBe('models-camera-device')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('normalizes rows in legacy response envelopes', () => {
|
|
56
|
+
const result = normalizeLegacyCameraRouterResponse({
|
|
57
|
+
code: 0,
|
|
58
|
+
data: {
|
|
59
|
+
total: 1,
|
|
60
|
+
rows: [
|
|
61
|
+
{
|
|
62
|
+
name: '摄像头监控',
|
|
63
|
+
type: '页面',
|
|
64
|
+
subject: 'camera-page',
|
|
65
|
+
children: []
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
expect(result.data.rows[0].subject).toBe('models-camera')
|
|
72
|
+
expect(result.data.rows[0].children[0].subject).toBe('models-camera-device')
|
|
73
|
+
})
|
|
74
|
+
})
|