zet-lib 1.3.38 → 1.3.40
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/LICENSE +21 -21
- package/README.md +15 -15
- package/lib/ErrorWithCode.js +6 -6
- package/lib/Form.js +1019 -1019
- package/lib/Mail.js +68 -68
- package/lib/Modal.js +95 -95
- package/lib/Pool.js +437 -437
- package/lib/UI.js +7 -7
- package/lib/Util.js +1384 -1367
- package/lib/access.js +6 -6
- package/lib/cache.js +3 -3
- package/lib/connection.js +409 -409
- package/lib/debug.js +22 -22
- package/lib/index.js +36 -36
- package/lib/io.js +44 -44
- package/lib/languages/lang_en.js +125 -125
- package/lib/languages/lang_fr.js +125 -125
- package/lib/languages/lang_id.js +126 -126
- package/lib/languages/lang_jp.js +125 -125
- package/lib/moduleLib.js +661 -661
- package/lib/tableForm.js +10 -10
- package/lib/views/generator.ejs +598 -598
- package/lib/views/generator_layout.ejs +224 -224
- package/lib/views/generatorjs.ejs +927 -927
- package/lib/zAppRouter.js +1637 -1637
- package/lib/zCache.js +301 -301
- package/lib/zComponent.js +27 -27
- package/lib/zFn.js +58 -58
- package/lib/zFunction.js +20 -20
- package/lib/zGeneratorRouter.js +1641 -1641
- package/lib/zMenuRouter.js +556 -556
- package/lib/zPage.js +188 -188
- package/lib/zReport.js +982 -982
- package/lib/zRole.js +256 -256
- package/lib/zRoleRouter.js +609 -609
- package/lib/zRoute.js +5025 -5019
- package/lib/zTester.js +93 -93
- package/lib/zapp.js +65 -65
- package/lib/zdataTable.js +330 -330
- package/package.json +56 -56
package/lib/zRole.js
CHANGED
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
const Util = require('./Util')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const myCache = require('./cache')
|
|
4
|
-
const zRoute = require('./zRoute')
|
|
5
|
-
|
|
6
|
-
const a = {}
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
Please add your routes here
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const routes = zRoute.ROUTES()
|
|
13
|
-
const cacheRoutes = myCache.get('ROUTES')
|
|
14
|
-
const cacheRoles = myCache.get('ROLES') || {}
|
|
15
|
-
|
|
16
|
-
if (cacheRoutes && cacheRoutes.length) {
|
|
17
|
-
a.routes = process.env.NODE_ENV == 'production' ? Util.arrayDeletes(cacheRoutes, ['auth', 'test']) : Util.arrayDeletes(cacheRoutes, ['generator', 'auth', 'test'])
|
|
18
|
-
} else {
|
|
19
|
-
a.routes = process.env.NODE_ENV == 'production' ? Util.arrayDeletes(routes, ['auth', 'test']) : Util.arrayDeletes(routes, ['generator', 'auth', 'test'])
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
Default actions
|
|
24
|
-
you can additional here
|
|
25
|
-
*/
|
|
26
|
-
a.actions = ['index', 'create', 'update', 'delete', 'delete_all', 'view', 'import', 'export', 'approval', 'lock']
|
|
27
|
-
|
|
28
|
-
/*
|
|
29
|
-
all in table roles
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
a.params = function (roleId) {
|
|
33
|
-
let cacheRoles = myCache.get('ROLES')
|
|
34
|
-
if (cacheRoles && cacheRoles.hasOwnProperty(roleId)) {
|
|
35
|
-
return roleId ? cacheRoles[roleId].params : {}
|
|
36
|
-
}
|
|
37
|
-
return {}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
a.rules = function (roleId) {
|
|
41
|
-
return a.params(roleId)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
a.list = (roleId, route) => {
|
|
45
|
-
let params = a.params(roleId)
|
|
46
|
-
return a.levels(route, params)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
a.levels = (route, params) => {
|
|
50
|
-
let obj = {}
|
|
51
|
-
if (a.routes.indexOf(route) > -1) {
|
|
52
|
-
for (let i = 0; i < a.actions.length; i++) {
|
|
53
|
-
if (params.hasOwnProperty(route)) {
|
|
54
|
-
if (params[route].indexOf(a.actions[i]) > -1) {
|
|
55
|
-
obj[a.actions[i]] = true
|
|
56
|
-
} else {
|
|
57
|
-
obj[a.actions[i]] = false
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
obj[a.actions[i]] = false
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
for (let i = 0; i < a.actions.length; i++) {
|
|
65
|
-
obj[a.actions[i]] = true
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return obj
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
a.myLevel = (req, res, table) => {
|
|
72
|
-
const levels = a.levels(table, a.routes.includes(table) ? a.rules(res.locals.roleId) : {})
|
|
73
|
-
return levels
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
a.menuAccess = (res, menu) => {
|
|
77
|
-
if (Array.isArray(menu)) {
|
|
78
|
-
let isTrue = false
|
|
79
|
-
for (let i = 0; i < menu.length; i++) {
|
|
80
|
-
let r = a.menuAccess(res, menu[i])
|
|
81
|
-
if (r == true) {
|
|
82
|
-
return true
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
if (Util.in_array(menu, a.routes)) {
|
|
87
|
-
let params = a.params(res.locals.roleId)
|
|
88
|
-
let arr = Object.keys(params) || []
|
|
89
|
-
if (Util.in_array(menu, arr)) {
|
|
90
|
-
return true
|
|
91
|
-
} else {
|
|
92
|
-
return false
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
return true
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return false
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
a.isAccess = (roleId, route, action) => {
|
|
102
|
-
let params = a.params(roleId)
|
|
103
|
-
if (a.routes.includes(route)) {
|
|
104
|
-
if (!params[route]) {
|
|
105
|
-
return false
|
|
106
|
-
}
|
|
107
|
-
if (a.actions.includes(action)) {
|
|
108
|
-
if (params[route].includes(action)) {
|
|
109
|
-
return true
|
|
110
|
-
} else {
|
|
111
|
-
return false
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
return true
|
|
115
|
-
}
|
|
116
|
-
return false
|
|
117
|
-
}
|
|
118
|
-
return true
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
//get access page after login
|
|
122
|
-
a.access = (req, res, next) => {
|
|
123
|
-
if (req.session.user === null || typeof req.session.user === 'undefined') {
|
|
124
|
-
req.session.sessionFlash = Util.flashError(LANGUAGE.login_first)
|
|
125
|
-
res.redirect(`${process.env.APP_AFTER_LOGOUT}`)
|
|
126
|
-
} else {
|
|
127
|
-
const isAccess = a.isAccess(res.locals.roleId, req.route, req.action)
|
|
128
|
-
if (isAccess) {
|
|
129
|
-
next()
|
|
130
|
-
} else {
|
|
131
|
-
if (a.isAccess(res.locals.roleId, 'zrole', 'index')) {
|
|
132
|
-
req.session.sessionFlash = Util.flashError(LANGUAGE.no_access)
|
|
133
|
-
res.redirect(`${process.env.APP_AFTER_LOGIN}?setup=role`)
|
|
134
|
-
} else {
|
|
135
|
-
res.redirect(`${process.env.APP_AFTER_LOGIN}`)
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
a.menu = (req, res) => {
|
|
142
|
-
let jsonArray = []
|
|
143
|
-
if (!res.locals.isLogin) return jsonArray
|
|
144
|
-
let companyId = res.locals.companyId
|
|
145
|
-
let userId = res.locals.userId
|
|
146
|
-
let jsonMenu = myCache.get('MENU')
|
|
147
|
-
let arr = []
|
|
148
|
-
if (jsonMenu && jsonMenu.hasOwnProperty(companyId)) {
|
|
149
|
-
arr = jsonMenu[companyId] || []
|
|
150
|
-
}
|
|
151
|
-
//console.log(JSON.stringify(arr))
|
|
152
|
-
let count = arr.length
|
|
153
|
-
arr.map((me) => {
|
|
154
|
-
if (a.menuAccess(res, me.href)) {
|
|
155
|
-
let obj = a.addItemMenu(me)
|
|
156
|
-
//console.log(obj)
|
|
157
|
-
if (me.hasOwnProperty('children')) {
|
|
158
|
-
obj.children = a.childrenMenu(res, me.children)
|
|
159
|
-
if (obj.children.length) {
|
|
160
|
-
jsonArray.push(obj)
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
jsonArray.push(obj)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
//console.log(JSON.stringify(jsonArray))
|
|
168
|
-
return jsonArray
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
a.menuSystems = (req, res) => {
|
|
172
|
-
let arr = []
|
|
173
|
-
let menus = myCache.get('MENU_SYSTEMS')
|
|
174
|
-
let children = []
|
|
175
|
-
menus['users'].forEach(function (item) {
|
|
176
|
-
if (a.menuAccess(res, item.href)) {
|
|
177
|
-
children.push(item)
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
if (children.length == 0) {
|
|
181
|
-
delete menus.users
|
|
182
|
-
} else {
|
|
183
|
-
let userManagament = {
|
|
184
|
-
text: 'LANGUAGE.users',
|
|
185
|
-
icon: 'tabler-users-plus',
|
|
186
|
-
children: children,
|
|
187
|
-
}
|
|
188
|
-
arr.push(userManagament)
|
|
189
|
-
}
|
|
190
|
-
children = []
|
|
191
|
-
menus['systems'].forEach(function (item) {
|
|
192
|
-
if (a.menuAccess(res, item.href)) {
|
|
193
|
-
children.push(item)
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
if (children.length == 0) {
|
|
197
|
-
delete menus.systems
|
|
198
|
-
} else {
|
|
199
|
-
let settings = {
|
|
200
|
-
text: 'LANGUAGE.systems',
|
|
201
|
-
icon: 'tabler-settings-check',
|
|
202
|
-
children: children,
|
|
203
|
-
}
|
|
204
|
-
arr.push(settings)
|
|
205
|
-
}
|
|
206
|
-
return arr
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
a.menus = (req, res) => {
|
|
210
|
-
let arr = a.menu(req, res)
|
|
211
|
-
let menus = [...arr, ...a.menuSystems(req, res)]
|
|
212
|
-
return menus
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
a.addItemMenu = (obj) => {
|
|
216
|
-
let newObj = {}
|
|
217
|
-
for (const key in obj) {
|
|
218
|
-
if (key != 'children') {
|
|
219
|
-
newObj[key] = obj[key]
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return newObj
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
a.childrenMenu = (res, arr) => {
|
|
226
|
-
let myArr = []
|
|
227
|
-
let nArr = arr.reduce((result, item) => [...result, item.href], [])
|
|
228
|
-
let isAccess = a.menuAccess(res, nArr)
|
|
229
|
-
if (isAccess) {
|
|
230
|
-
//stupid way
|
|
231
|
-
arr.map((item) => {
|
|
232
|
-
let obj = {}
|
|
233
|
-
if (a.isAccess(res.locals.roleId, item.href, 'index')) {
|
|
234
|
-
obj = a.addItemMenu(item)
|
|
235
|
-
if (item.hasOwnProperty('children') && item.children.length) {
|
|
236
|
-
let child = []
|
|
237
|
-
child.push(a.childrenMenu(res, item.children))
|
|
238
|
-
//console.log('child',child)
|
|
239
|
-
if (child[0]) {
|
|
240
|
-
obj.children = child[0]
|
|
241
|
-
} else {
|
|
242
|
-
delete obj
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (obj.hasOwnProperty('children') && obj.children.length == 0) {
|
|
246
|
-
} else {
|
|
247
|
-
myArr.push(obj)
|
|
248
|
-
}
|
|
249
|
-
//console.log('OBJ ===== ', obj)
|
|
250
|
-
}
|
|
251
|
-
})
|
|
252
|
-
}
|
|
253
|
-
return myArr
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
module.exports = a
|
|
1
|
+
const Util = require('./Util')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const myCache = require('./cache')
|
|
4
|
+
const zRoute = require('./zRoute')
|
|
5
|
+
|
|
6
|
+
const a = {}
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
Please add your routes here
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const routes = zRoute.ROUTES()
|
|
13
|
+
const cacheRoutes = myCache.get('ROUTES')
|
|
14
|
+
const cacheRoles = myCache.get('ROLES') || {}
|
|
15
|
+
|
|
16
|
+
if (cacheRoutes && cacheRoutes.length) {
|
|
17
|
+
a.routes = process.env.NODE_ENV == 'production' ? Util.arrayDeletes(cacheRoutes, ['auth', 'test']) : Util.arrayDeletes(cacheRoutes, ['generator', 'auth', 'test'])
|
|
18
|
+
} else {
|
|
19
|
+
a.routes = process.env.NODE_ENV == 'production' ? Util.arrayDeletes(routes, ['auth', 'test']) : Util.arrayDeletes(routes, ['generator', 'auth', 'test'])
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
Default actions
|
|
24
|
+
you can additional here
|
|
25
|
+
*/
|
|
26
|
+
a.actions = ['index', 'create', 'update', 'delete', 'delete_all', 'view', 'import', 'export', 'approval', 'lock']
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
all in table roles
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
a.params = function (roleId) {
|
|
33
|
+
let cacheRoles = myCache.get('ROLES')
|
|
34
|
+
if (cacheRoles && cacheRoles.hasOwnProperty(roleId)) {
|
|
35
|
+
return roleId ? cacheRoles[roleId].params : {}
|
|
36
|
+
}
|
|
37
|
+
return {}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
a.rules = function (roleId) {
|
|
41
|
+
return a.params(roleId)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
a.list = (roleId, route) => {
|
|
45
|
+
let params = a.params(roleId)
|
|
46
|
+
return a.levels(route, params)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
a.levels = (route, params) => {
|
|
50
|
+
let obj = {}
|
|
51
|
+
if (a.routes.indexOf(route) > -1) {
|
|
52
|
+
for (let i = 0; i < a.actions.length; i++) {
|
|
53
|
+
if (params.hasOwnProperty(route)) {
|
|
54
|
+
if (params[route].indexOf(a.actions[i]) > -1) {
|
|
55
|
+
obj[a.actions[i]] = true
|
|
56
|
+
} else {
|
|
57
|
+
obj[a.actions[i]] = false
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
obj[a.actions[i]] = false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
for (let i = 0; i < a.actions.length; i++) {
|
|
65
|
+
obj[a.actions[i]] = true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return obj
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
a.myLevel = (req, res, table) => {
|
|
72
|
+
const levels = a.levels(table, a.routes.includes(table) ? a.rules(res.locals.roleId) : {})
|
|
73
|
+
return levels
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
a.menuAccess = (res, menu) => {
|
|
77
|
+
if (Array.isArray(menu)) {
|
|
78
|
+
let isTrue = false
|
|
79
|
+
for (let i = 0; i < menu.length; i++) {
|
|
80
|
+
let r = a.menuAccess(res, menu[i])
|
|
81
|
+
if (r == true) {
|
|
82
|
+
return true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
if (Util.in_array(menu, a.routes)) {
|
|
87
|
+
let params = a.params(res.locals.roleId)
|
|
88
|
+
let arr = Object.keys(params) || []
|
|
89
|
+
if (Util.in_array(menu, arr)) {
|
|
90
|
+
return true
|
|
91
|
+
} else {
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
a.isAccess = (roleId, route, action) => {
|
|
102
|
+
let params = a.params(roleId)
|
|
103
|
+
if (a.routes.includes(route)) {
|
|
104
|
+
if (!params[route]) {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
if (a.actions.includes(action)) {
|
|
108
|
+
if (params[route].includes(action)) {
|
|
109
|
+
return true
|
|
110
|
+
} else {
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
return true
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//get access page after login
|
|
122
|
+
a.access = (req, res, next) => {
|
|
123
|
+
if (req.session.user === null || typeof req.session.user === 'undefined') {
|
|
124
|
+
req.session.sessionFlash = Util.flashError(LANGUAGE.login_first)
|
|
125
|
+
res.redirect(`${process.env.APP_AFTER_LOGOUT}`)
|
|
126
|
+
} else {
|
|
127
|
+
const isAccess = a.isAccess(res.locals.roleId, req.route, req.action)
|
|
128
|
+
if (isAccess) {
|
|
129
|
+
next()
|
|
130
|
+
} else {
|
|
131
|
+
if (a.isAccess(res.locals.roleId, 'zrole', 'index')) {
|
|
132
|
+
req.session.sessionFlash = Util.flashError(LANGUAGE.no_access)
|
|
133
|
+
res.redirect(`${process.env.APP_AFTER_LOGIN}?setup=role`)
|
|
134
|
+
} else {
|
|
135
|
+
res.redirect(`${process.env.APP_AFTER_LOGIN}`)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
a.menu = (req, res) => {
|
|
142
|
+
let jsonArray = []
|
|
143
|
+
if (!res.locals.isLogin) return jsonArray
|
|
144
|
+
let companyId = res.locals.companyId
|
|
145
|
+
let userId = res.locals.userId
|
|
146
|
+
let jsonMenu = myCache.get('MENU')
|
|
147
|
+
let arr = []
|
|
148
|
+
if (jsonMenu && jsonMenu.hasOwnProperty(companyId)) {
|
|
149
|
+
arr = jsonMenu[companyId] || []
|
|
150
|
+
}
|
|
151
|
+
//console.log(JSON.stringify(arr))
|
|
152
|
+
let count = arr.length
|
|
153
|
+
arr.map((me) => {
|
|
154
|
+
if (a.menuAccess(res, me.href)) {
|
|
155
|
+
let obj = a.addItemMenu(me)
|
|
156
|
+
//console.log(obj)
|
|
157
|
+
if (me.hasOwnProperty('children')) {
|
|
158
|
+
obj.children = a.childrenMenu(res, me.children)
|
|
159
|
+
if (obj.children.length) {
|
|
160
|
+
jsonArray.push(obj)
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
jsonArray.push(obj)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
//console.log(JSON.stringify(jsonArray))
|
|
168
|
+
return jsonArray
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
a.menuSystems = (req, res) => {
|
|
172
|
+
let arr = []
|
|
173
|
+
let menus = myCache.get('MENU_SYSTEMS')
|
|
174
|
+
let children = []
|
|
175
|
+
menus['users'].forEach(function (item) {
|
|
176
|
+
if (a.menuAccess(res, item.href)) {
|
|
177
|
+
children.push(item)
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
if (children.length == 0) {
|
|
181
|
+
delete menus.users
|
|
182
|
+
} else {
|
|
183
|
+
let userManagament = {
|
|
184
|
+
text: 'LANGUAGE.users',
|
|
185
|
+
icon: 'tabler-users-plus',
|
|
186
|
+
children: children,
|
|
187
|
+
}
|
|
188
|
+
arr.push(userManagament)
|
|
189
|
+
}
|
|
190
|
+
children = []
|
|
191
|
+
menus['systems'].forEach(function (item) {
|
|
192
|
+
if (a.menuAccess(res, item.href)) {
|
|
193
|
+
children.push(item)
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
if (children.length == 0) {
|
|
197
|
+
delete menus.systems
|
|
198
|
+
} else {
|
|
199
|
+
let settings = {
|
|
200
|
+
text: 'LANGUAGE.systems',
|
|
201
|
+
icon: 'tabler-settings-check',
|
|
202
|
+
children: children,
|
|
203
|
+
}
|
|
204
|
+
arr.push(settings)
|
|
205
|
+
}
|
|
206
|
+
return arr
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
a.menus = (req, res) => {
|
|
210
|
+
let arr = a.menu(req, res)
|
|
211
|
+
let menus = [...arr, ...a.menuSystems(req, res)]
|
|
212
|
+
return menus
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
a.addItemMenu = (obj) => {
|
|
216
|
+
let newObj = {}
|
|
217
|
+
for (const key in obj) {
|
|
218
|
+
if (key != 'children') {
|
|
219
|
+
newObj[key] = obj[key]
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return newObj
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
a.childrenMenu = (res, arr) => {
|
|
226
|
+
let myArr = []
|
|
227
|
+
let nArr = arr.reduce((result, item) => [...result, item.href], [])
|
|
228
|
+
let isAccess = a.menuAccess(res, nArr)
|
|
229
|
+
if (isAccess) {
|
|
230
|
+
//stupid way
|
|
231
|
+
arr.map((item) => {
|
|
232
|
+
let obj = {}
|
|
233
|
+
if (a.isAccess(res.locals.roleId, item.href, 'index')) {
|
|
234
|
+
obj = a.addItemMenu(item)
|
|
235
|
+
if (item.hasOwnProperty('children') && item.children.length) {
|
|
236
|
+
let child = []
|
|
237
|
+
child.push(a.childrenMenu(res, item.children))
|
|
238
|
+
//console.log('child',child)
|
|
239
|
+
if (child[0]) {
|
|
240
|
+
obj.children = child[0]
|
|
241
|
+
} else {
|
|
242
|
+
delete obj
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (obj.hasOwnProperty('children') && obj.children.length == 0) {
|
|
246
|
+
} else {
|
|
247
|
+
myArr.push(obj)
|
|
248
|
+
}
|
|
249
|
+
//console.log('OBJ ===== ', obj)
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
return myArr
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
module.exports = a
|