nayota-show-sdk 1.3.97 → 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/package.json +1 -1
- 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/package.json
CHANGED
|
@@ -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
|
+
})
|