@netang/quasar 0.1.16 → 0.1.18
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/_docs/docs/utils/table.md +1 -0
- package/components/field-table/index.vue +2 -2
- package/components/private/edit-power-data/index.vue +1 -1
- package/components/private/table-visible-columns-button/index.vue +109 -109
- package/components/table/index.vue +13 -13
- package/package.json +1 -1
- package/utils/$table.js +370 -200
- package/utils/$tree.js +712 -713
package/utils/$tree.js
CHANGED
|
@@ -1,713 +1,712 @@
|
|
|
1
|
-
import $n_has from 'lodash/has'
|
|
2
|
-
import $n_get from 'lodash/get'
|
|
3
|
-
import $n_isNil from 'lodash/isNil'
|
|
4
|
-
import $n_findIndex from 'lodash/findIndex'
|
|
5
|
-
import $n_cloneDeep from 'lodash/cloneDeep'
|
|
6
|
-
|
|
7
|
-
import $n_router from '@netang/utils/vue/router'
|
|
8
|
-
|
|
9
|
-
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
10
|
-
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
11
|
-
import $n_isValidString from '@netang/utils/isValidString'
|
|
12
|
-
import $n_hasId from '@netang/utils/hasId'
|
|
13
|
-
import $n_http from '@netang/utils/http'
|
|
14
|
-
import $n_run from '@netang/utils/run'
|
|
15
|
-
import $n_storage from '@netang/utils/storage'
|
|
16
|
-
|
|
17
|
-
import $n_toast from './toast'
|
|
18
|
-
import $n_confirm from './confirm'
|
|
19
|
-
import $n_dialog from './dialog'
|
|
20
|
-
import $n_alert from './alert'
|
|
21
|
-
|
|
22
|
-
import { isRef, watch, inject, ref } from 'vue'
|
|
23
|
-
|
|
24
|
-
import { NPowerKey } from './symbols'
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 获取节点
|
|
28
|
-
*/
|
|
29
|
-
function getTreeNode(data, nodeId) {
|
|
30
|
-
for (const item of data) {
|
|
31
|
-
|
|
32
|
-
if (item.id === nodeId) {
|
|
33
|
-
return item
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 如果是父节点
|
|
37
|
-
if (item.children.length) {
|
|
38
|
-
const res = getTreeNode(item.children, nodeId)
|
|
39
|
-
if (res) {
|
|
40
|
-
return res
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return false
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 获取子节点
|
|
50
|
-
*/
|
|
51
|
-
function getChildren(data, callback) {
|
|
52
|
-
for (const item of data) {
|
|
53
|
-
if ($n_run(callback)(item) === false) {
|
|
54
|
-
return false
|
|
55
|
-
}
|
|
56
|
-
// 如果是父节点
|
|
57
|
-
if (item.children.length) {
|
|
58
|
-
const res = getChildren(item.children, callback)
|
|
59
|
-
if (res === false) {
|
|
60
|
-
return false
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return true
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 创建树实例
|
|
69
|
-
*/
|
|
70
|
-
function create(options) {
|
|
71
|
-
|
|
72
|
-
const {
|
|
73
|
-
// 路由路径
|
|
74
|
-
path,
|
|
75
|
-
// 路由参数
|
|
76
|
-
query,
|
|
77
|
-
// 树节点列表
|
|
78
|
-
nodes,
|
|
79
|
-
// 树展开节点
|
|
80
|
-
expanded,
|
|
81
|
-
// 原始表单数据
|
|
82
|
-
rawFormData,
|
|
83
|
-
// 表单数据
|
|
84
|
-
formData,
|
|
85
|
-
// 重新加载
|
|
86
|
-
reload,
|
|
87
|
-
// 是否开启展开节点缓存
|
|
88
|
-
cache,
|
|
89
|
-
} = Object.assign({
|
|
90
|
-
// 路由路径
|
|
91
|
-
path: '',
|
|
92
|
-
// 路由参数
|
|
93
|
-
query: {},
|
|
94
|
-
// 是否开启展开节点缓存
|
|
95
|
-
cache: false,
|
|
96
|
-
}, options)
|
|
97
|
-
|
|
98
|
-
// 获取权限注入
|
|
99
|
-
const $power = $n_has(options, '$power') ? options.$power : inject(NPowerKey)
|
|
100
|
-
const hasPowr = !! $power
|
|
101
|
-
|
|
102
|
-
// 获取权限路由
|
|
103
|
-
const $route = $n_isValidString(path) ?
|
|
104
|
-
// 如果为自定义路由
|
|
105
|
-
$n_router.resolve({
|
|
106
|
-
path,
|
|
107
|
-
query,
|
|
108
|
-
})
|
|
109
|
-
// 否则获取当前路由
|
|
110
|
-
: (hasPowr ? $power.getRoute() : $n_router.getRoute())
|
|
111
|
-
|
|
112
|
-
// 权限按钮
|
|
113
|
-
const powerBtns = hasPowr ? $power.powerBtns : ref([])
|
|
114
|
-
|
|
115
|
-
// 是否有展开节点
|
|
116
|
-
const hasExpanded = ! $n_isNil(expanded) && isRef(expanded)
|
|
117
|
-
|
|
118
|
-
// 如果开启展开节点缓存
|
|
119
|
-
if (hasExpanded && cache) {
|
|
120
|
-
|
|
121
|
-
// 设置树展开节点初始缓存
|
|
122
|
-
expanded.value = getExpandedCache(expanded.value)
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 监听树展开节点
|
|
126
|
-
*/
|
|
127
|
-
watch(expanded, function(val) {
|
|
128
|
-
// 设置树展开节点缓存
|
|
129
|
-
setExpandedCache(val)
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 获取节点
|
|
135
|
-
*/
|
|
136
|
-
function getNode(nodeId) {
|
|
137
|
-
return getTreeNode(nodes.value, nodeId)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* 格式化节点
|
|
142
|
-
*/
|
|
143
|
-
function formatNode(attr) {
|
|
144
|
-
|
|
145
|
-
// 设置属性
|
|
146
|
-
attr = Object.assign({}, attr)
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
attr,
|
|
150
|
-
id: attr.id,
|
|
151
|
-
label: attr.title,
|
|
152
|
-
children: [],
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 更新节点
|
|
158
|
-
*/
|
|
159
|
-
function updateNode(data) {
|
|
160
|
-
|
|
161
|
-
// 获取 id
|
|
162
|
-
const id = $n_get(formData.value, 'id')
|
|
163
|
-
|
|
164
|
-
// 更新表单数据
|
|
165
|
-
formData.value = Object.assign({}, formData.value, data)
|
|
166
|
-
|
|
167
|
-
// 获取节点数据
|
|
168
|
-
const nodeItem = getNode(data.id)
|
|
169
|
-
|
|
170
|
-
// 如果为更新节点
|
|
171
|
-
if (id) {
|
|
172
|
-
if (nodeItem) {
|
|
173
|
-
Object.assign(nodeItem, {
|
|
174
|
-
attr: Object.assign({}, formData.value),
|
|
175
|
-
label: formData.value.title,
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// 否则为新增节点
|
|
180
|
-
} else if (
|
|
181
|
-
// 如果为新增节点
|
|
182
|
-
$n_get(data, 'id')
|
|
183
|
-
// 没有节点存在
|
|
184
|
-
&& ! nodeItem
|
|
185
|
-
) {
|
|
186
|
-
// 获取父级节点
|
|
187
|
-
const parentNodeItem = getNode(formData.value.pid)
|
|
188
|
-
if (! parentNodeItem) {
|
|
189
|
-
return
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// 新增节点
|
|
193
|
-
parentNodeItem.children.push(formatNode(formData.value))
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 删除节点
|
|
199
|
-
*/
|
|
200
|
-
function deleteNode({ id, attr }) {
|
|
201
|
-
|
|
202
|
-
// 获取父节点数据
|
|
203
|
-
const parentNodeItem = getNode(attr.pid)
|
|
204
|
-
if (! parentNodeItem) {
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 获取节点索引
|
|
209
|
-
const nodeIndex = $n_findIndex(parentNodeItem.children, { id })
|
|
210
|
-
if (nodeIndex > -1) {
|
|
211
|
-
parentNodeItem.children.splice(nodeIndex, 1)
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* 获取菜单状态
|
|
217
|
-
*/
|
|
218
|
-
function getMenuStatus(options) {
|
|
219
|
-
|
|
220
|
-
const o = Object.assign({
|
|
221
|
-
updateName: 'update',
|
|
222
|
-
moveName: 'move',
|
|
223
|
-
copyName: 'copy',
|
|
224
|
-
deleteName: 'realdel',
|
|
225
|
-
statusName: 'status'
|
|
226
|
-
}, options)
|
|
227
|
-
|
|
228
|
-
const maps = {}
|
|
229
|
-
maps[o.updateName] = 'update'
|
|
230
|
-
maps[o.moveName] = 'move'
|
|
231
|
-
maps[o.copyName] = 'copy'
|
|
232
|
-
maps[o.deleteName] = 'delete'
|
|
233
|
-
maps[o.statusName] = 'status'
|
|
234
|
-
|
|
235
|
-
const allPowerBtn = {}
|
|
236
|
-
for (const item of powerBtns.value) {
|
|
237
|
-
if ($n_has(maps, $n_get(item, 'name'))) {
|
|
238
|
-
allPowerBtn[maps[item.name]] = item
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
all: $n_isValidObject(allPowerBtn),
|
|
244
|
-
update: $n_has(allPowerBtn, 'update'),
|
|
245
|
-
move: $n_has(allPowerBtn, 'move'),
|
|
246
|
-
copy: $n_has(allPowerBtn, 'copy'),
|
|
247
|
-
delete: $n_has(allPowerBtn, 'delete'),
|
|
248
|
-
status: $n_has(allPowerBtn, 'status'),
|
|
249
|
-
allPowerBtn,
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* 确认菜单
|
|
255
|
-
*/
|
|
256
|
-
function confirmMenu(callback) {
|
|
257
|
-
// 确认框
|
|
258
|
-
$n_confirm({
|
|
259
|
-
message: '确认要执行该操作吗?',
|
|
260
|
-
})
|
|
261
|
-
// 点击确认执行
|
|
262
|
-
.onOk(callback)
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* 菜单点击
|
|
267
|
-
*/
|
|
268
|
-
function menuClick(options) {
|
|
269
|
-
|
|
270
|
-
// 参数
|
|
271
|
-
const o = Object.assign({
|
|
272
|
-
// 菜单类型
|
|
273
|
-
type: '',
|
|
274
|
-
// 节点
|
|
275
|
-
node: null,
|
|
276
|
-
}, options)
|
|
277
|
-
|
|
278
|
-
// 菜单类型
|
|
279
|
-
switch (o.type) {
|
|
280
|
-
|
|
281
|
-
// 添加下级
|
|
282
|
-
case 'update':
|
|
283
|
-
// 更新表单数据
|
|
284
|
-
formData.value = Object.assign({}, rawFormData, {
|
|
285
|
-
pid: o.node.attr.id,
|
|
286
|
-
})
|
|
287
|
-
break
|
|
288
|
-
|
|
289
|
-
// 移至节点上
|
|
290
|
-
case 'moveUp':
|
|
291
|
-
// 移至节点内
|
|
292
|
-
case 'moveIn':
|
|
293
|
-
// 移至节点下
|
|
294
|
-
case 'moveDown':
|
|
295
|
-
|
|
296
|
-
if (! $n_get(o.menuStatus, 'value.allPowerBtn.move.url')) {
|
|
297
|
-
console.error('没有找到复制地址')
|
|
298
|
-
return
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// 创建对话框
|
|
302
|
-
$n_dialog.create({
|
|
303
|
-
// 标题
|
|
304
|
-
title: `移动至节点的${o.type === 'moveUp' ? '上方' : (o.type === 'moveDown' ? '下方' : '内部')}`,
|
|
305
|
-
// 宽度
|
|
306
|
-
width: 500,
|
|
307
|
-
// 组件标识
|
|
308
|
-
name: 'moveToTree',
|
|
309
|
-
// 组件参数
|
|
310
|
-
props: {
|
|
311
|
-
// 树节点列表
|
|
312
|
-
nodes,
|
|
313
|
-
// 树展开节点
|
|
314
|
-
expanded,
|
|
315
|
-
},
|
|
316
|
-
// 显示取消按钮
|
|
317
|
-
cancel: true,
|
|
318
|
-
// 点击确认执行
|
|
319
|
-
async onConfirm({ value: moveNodeId }) {
|
|
320
|
-
|
|
321
|
-
// 是否为正确的 id
|
|
322
|
-
if (! $n_hasId(moveNodeId)) {
|
|
323
|
-
$n_toast({
|
|
324
|
-
message: '请选择节点',
|
|
325
|
-
})
|
|
326
|
-
return false
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// 如果节点是自己
|
|
330
|
-
if (moveNodeId === o.node.id) {
|
|
331
|
-
$n_toast({
|
|
332
|
-
message: '不能选择当前节点',
|
|
333
|
-
})
|
|
334
|
-
return false
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// 获取需移动至的节点
|
|
338
|
-
const moveNodeItem = getNode(moveNodeId)
|
|
339
|
-
if (! moveNodeItem) {
|
|
340
|
-
$n_alert({
|
|
341
|
-
message: '移动至的节点不存在',
|
|
342
|
-
})
|
|
343
|
-
return false
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// 克隆当前树列表数据
|
|
347
|
-
const nodesClone = $n_cloneDeep(nodes.value)
|
|
348
|
-
|
|
349
|
-
// 获取当前节点
|
|
350
|
-
const nodeItem = getNode(o.node.id)
|
|
351
|
-
|
|
352
|
-
// 获取当前节点的父节点
|
|
353
|
-
const parentNodeItem = getNode(o.node.attr.pid)
|
|
354
|
-
|
|
355
|
-
// 移动列表数据
|
|
356
|
-
const moveLists = []
|
|
357
|
-
|
|
358
|
-
// 如果是移动至节点内部
|
|
359
|
-
// --------------------------------------------------
|
|
360
|
-
if (o.type === 'moveIn') {
|
|
361
|
-
|
|
362
|
-
// 修改当前节点数据
|
|
363
|
-
nodeItem.attr.pid = moveNodeItem.attr.id
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
//
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
nodeItem.attr.
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
export default $tree
|
|
1
|
+
import $n_has from 'lodash/has'
|
|
2
|
+
import $n_get from 'lodash/get'
|
|
3
|
+
import $n_isNil from 'lodash/isNil'
|
|
4
|
+
import $n_findIndex from 'lodash/findIndex'
|
|
5
|
+
import $n_cloneDeep from 'lodash/cloneDeep'
|
|
6
|
+
|
|
7
|
+
import $n_router from '@netang/utils/vue/router'
|
|
8
|
+
|
|
9
|
+
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
10
|
+
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
11
|
+
import $n_isValidString from '@netang/utils/isValidString'
|
|
12
|
+
import $n_hasId from '@netang/utils/hasId'
|
|
13
|
+
import $n_http from '@netang/utils/http'
|
|
14
|
+
import $n_run from '@netang/utils/run'
|
|
15
|
+
import $n_storage from '@netang/utils/storage'
|
|
16
|
+
|
|
17
|
+
import $n_toast from './toast'
|
|
18
|
+
import $n_confirm from './confirm'
|
|
19
|
+
import $n_dialog from './dialog'
|
|
20
|
+
import $n_alert from './alert'
|
|
21
|
+
|
|
22
|
+
import { isRef, watch, inject, ref } from 'vue'
|
|
23
|
+
|
|
24
|
+
import { NPowerKey } from './symbols'
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 获取节点
|
|
28
|
+
*/
|
|
29
|
+
function getTreeNode(data, nodeId) {
|
|
30
|
+
for (const item of data) {
|
|
31
|
+
|
|
32
|
+
if (item.id === nodeId) {
|
|
33
|
+
return item
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 如果是父节点
|
|
37
|
+
if (item.children.length) {
|
|
38
|
+
const res = getTreeNode(item.children, nodeId)
|
|
39
|
+
if (res) {
|
|
40
|
+
return res
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 获取子节点
|
|
50
|
+
*/
|
|
51
|
+
function getChildren(data, callback) {
|
|
52
|
+
for (const item of data) {
|
|
53
|
+
if ($n_run(callback)(item) === false) {
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
// 如果是父节点
|
|
57
|
+
if (item.children.length) {
|
|
58
|
+
const res = getChildren(item.children, callback)
|
|
59
|
+
if (res === false) {
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 创建树实例
|
|
69
|
+
*/
|
|
70
|
+
function create(options) {
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
// 路由路径
|
|
74
|
+
path,
|
|
75
|
+
// 路由参数
|
|
76
|
+
query,
|
|
77
|
+
// 树节点列表
|
|
78
|
+
nodes,
|
|
79
|
+
// 树展开节点
|
|
80
|
+
expanded,
|
|
81
|
+
// 原始表单数据
|
|
82
|
+
rawFormData,
|
|
83
|
+
// 表单数据
|
|
84
|
+
formData,
|
|
85
|
+
// 重新加载
|
|
86
|
+
reload,
|
|
87
|
+
// 是否开启展开节点缓存
|
|
88
|
+
cache,
|
|
89
|
+
} = Object.assign({
|
|
90
|
+
// 路由路径
|
|
91
|
+
path: '',
|
|
92
|
+
// 路由参数
|
|
93
|
+
query: {},
|
|
94
|
+
// 是否开启展开节点缓存
|
|
95
|
+
cache: false,
|
|
96
|
+
}, options)
|
|
97
|
+
|
|
98
|
+
// 获取权限注入
|
|
99
|
+
const $power = $n_has(options, '$power') ? options.$power : inject(NPowerKey)
|
|
100
|
+
const hasPowr = !! $power
|
|
101
|
+
|
|
102
|
+
// 获取权限路由
|
|
103
|
+
const $route = $n_isValidString(path) ?
|
|
104
|
+
// 如果为自定义路由
|
|
105
|
+
$n_router.resolve({
|
|
106
|
+
path,
|
|
107
|
+
query,
|
|
108
|
+
})
|
|
109
|
+
// 否则获取当前路由
|
|
110
|
+
: (hasPowr ? $power.getRoute() : $n_router.getRoute())
|
|
111
|
+
|
|
112
|
+
// 权限按钮
|
|
113
|
+
const powerBtns = hasPowr ? $power.powerBtns : ref([])
|
|
114
|
+
|
|
115
|
+
// 是否有展开节点
|
|
116
|
+
const hasExpanded = ! $n_isNil(expanded) && isRef(expanded)
|
|
117
|
+
|
|
118
|
+
// 如果开启展开节点缓存
|
|
119
|
+
if (hasExpanded && cache) {
|
|
120
|
+
|
|
121
|
+
// 设置树展开节点初始缓存
|
|
122
|
+
expanded.value = getExpandedCache(expanded.value)
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 监听树展开节点
|
|
126
|
+
*/
|
|
127
|
+
watch(expanded, function(val) {
|
|
128
|
+
// 设置树展开节点缓存
|
|
129
|
+
setExpandedCache(val)
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取节点
|
|
135
|
+
*/
|
|
136
|
+
function getNode(nodeId) {
|
|
137
|
+
return getTreeNode(nodes.value, nodeId)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 格式化节点
|
|
142
|
+
*/
|
|
143
|
+
function formatNode(attr) {
|
|
144
|
+
|
|
145
|
+
// 设置属性
|
|
146
|
+
attr = Object.assign({}, attr)
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
attr,
|
|
150
|
+
id: attr.id,
|
|
151
|
+
label: attr.title,
|
|
152
|
+
children: [],
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 更新节点
|
|
158
|
+
*/
|
|
159
|
+
function updateNode(data) {
|
|
160
|
+
|
|
161
|
+
// 获取 id
|
|
162
|
+
const id = $n_get(formData.value, 'id')
|
|
163
|
+
|
|
164
|
+
// 更新表单数据
|
|
165
|
+
formData.value = Object.assign({}, formData.value, data)
|
|
166
|
+
|
|
167
|
+
// 获取节点数据
|
|
168
|
+
const nodeItem = getNode(data.id)
|
|
169
|
+
|
|
170
|
+
// 如果为更新节点
|
|
171
|
+
if (id) {
|
|
172
|
+
if (nodeItem) {
|
|
173
|
+
Object.assign(nodeItem, {
|
|
174
|
+
attr: Object.assign({}, formData.value),
|
|
175
|
+
label: formData.value.title,
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 否则为新增节点
|
|
180
|
+
} else if (
|
|
181
|
+
// 如果为新增节点
|
|
182
|
+
$n_get(data, 'id')
|
|
183
|
+
// 没有节点存在
|
|
184
|
+
&& ! nodeItem
|
|
185
|
+
) {
|
|
186
|
+
// 获取父级节点
|
|
187
|
+
const parentNodeItem = getNode(formData.value.pid)
|
|
188
|
+
if (! parentNodeItem) {
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 新增节点
|
|
193
|
+
parentNodeItem.children.push(formatNode(formData.value))
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 删除节点
|
|
199
|
+
*/
|
|
200
|
+
function deleteNode({ id, attr }) {
|
|
201
|
+
|
|
202
|
+
// 获取父节点数据
|
|
203
|
+
const parentNodeItem = getNode(attr.pid)
|
|
204
|
+
if (! parentNodeItem) {
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// 获取节点索引
|
|
209
|
+
const nodeIndex = $n_findIndex(parentNodeItem.children, { id })
|
|
210
|
+
if (nodeIndex > -1) {
|
|
211
|
+
parentNodeItem.children.splice(nodeIndex, 1)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 获取菜单状态
|
|
217
|
+
*/
|
|
218
|
+
function getMenuStatus(options) {
|
|
219
|
+
|
|
220
|
+
const o = Object.assign({
|
|
221
|
+
updateName: 'update',
|
|
222
|
+
moveName: 'move',
|
|
223
|
+
copyName: 'copy',
|
|
224
|
+
deleteName: 'realdel',
|
|
225
|
+
statusName: 'status'
|
|
226
|
+
}, options)
|
|
227
|
+
|
|
228
|
+
const maps = {}
|
|
229
|
+
maps[o.updateName] = 'update'
|
|
230
|
+
maps[o.moveName] = 'move'
|
|
231
|
+
maps[o.copyName] = 'copy'
|
|
232
|
+
maps[o.deleteName] = 'delete'
|
|
233
|
+
maps[o.statusName] = 'status'
|
|
234
|
+
|
|
235
|
+
const allPowerBtn = {}
|
|
236
|
+
for (const item of powerBtns.value) {
|
|
237
|
+
if ($n_has(maps, $n_get(item, 'name'))) {
|
|
238
|
+
allPowerBtn[maps[item.name]] = item
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
all: $n_isValidObject(allPowerBtn),
|
|
244
|
+
update: $n_has(allPowerBtn, 'update'),
|
|
245
|
+
move: $n_has(allPowerBtn, 'move'),
|
|
246
|
+
copy: $n_has(allPowerBtn, 'copy'),
|
|
247
|
+
delete: $n_has(allPowerBtn, 'delete'),
|
|
248
|
+
status: $n_has(allPowerBtn, 'status'),
|
|
249
|
+
allPowerBtn,
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 确认菜单
|
|
255
|
+
*/
|
|
256
|
+
function confirmMenu(callback) {
|
|
257
|
+
// 确认框
|
|
258
|
+
$n_confirm({
|
|
259
|
+
message: '确认要执行该操作吗?',
|
|
260
|
+
})
|
|
261
|
+
// 点击确认执行
|
|
262
|
+
.onOk(callback)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 菜单点击
|
|
267
|
+
*/
|
|
268
|
+
function menuClick(options) {
|
|
269
|
+
|
|
270
|
+
// 参数
|
|
271
|
+
const o = Object.assign({
|
|
272
|
+
// 菜单类型
|
|
273
|
+
type: '',
|
|
274
|
+
// 节点
|
|
275
|
+
node: null,
|
|
276
|
+
}, options)
|
|
277
|
+
|
|
278
|
+
// 菜单类型
|
|
279
|
+
switch (o.type) {
|
|
280
|
+
|
|
281
|
+
// 添加下级
|
|
282
|
+
case 'update':
|
|
283
|
+
// 更新表单数据
|
|
284
|
+
formData.value = Object.assign({}, rawFormData, {
|
|
285
|
+
pid: o.node.attr.id,
|
|
286
|
+
})
|
|
287
|
+
break
|
|
288
|
+
|
|
289
|
+
// 移至节点上
|
|
290
|
+
case 'moveUp':
|
|
291
|
+
// 移至节点内
|
|
292
|
+
case 'moveIn':
|
|
293
|
+
// 移至节点下
|
|
294
|
+
case 'moveDown':
|
|
295
|
+
|
|
296
|
+
if (! $n_get(o.menuStatus, 'value.allPowerBtn.move.url')) {
|
|
297
|
+
console.error('没有找到复制地址')
|
|
298
|
+
return
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 创建对话框
|
|
302
|
+
$n_dialog.create({
|
|
303
|
+
// 标题
|
|
304
|
+
title: `移动至节点的${o.type === 'moveUp' ? '上方' : (o.type === 'moveDown' ? '下方' : '内部')}`,
|
|
305
|
+
// 宽度
|
|
306
|
+
width: 500,
|
|
307
|
+
// 组件标识
|
|
308
|
+
name: 'moveToTree',
|
|
309
|
+
// 组件参数
|
|
310
|
+
props: {
|
|
311
|
+
// 树节点列表
|
|
312
|
+
nodes,
|
|
313
|
+
// 树展开节点
|
|
314
|
+
expanded,
|
|
315
|
+
},
|
|
316
|
+
// 显示取消按钮
|
|
317
|
+
cancel: true,
|
|
318
|
+
// 点击确认执行
|
|
319
|
+
async onConfirm({ value: moveNodeId }) {
|
|
320
|
+
|
|
321
|
+
// 是否为正确的 id
|
|
322
|
+
if (! $n_hasId(moveNodeId)) {
|
|
323
|
+
$n_toast({
|
|
324
|
+
message: '请选择节点',
|
|
325
|
+
})
|
|
326
|
+
return false
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 如果节点是自己
|
|
330
|
+
if (moveNodeId === o.node.id) {
|
|
331
|
+
$n_toast({
|
|
332
|
+
message: '不能选择当前节点',
|
|
333
|
+
})
|
|
334
|
+
return false
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 获取需移动至的节点
|
|
338
|
+
const moveNodeItem = getNode(moveNodeId)
|
|
339
|
+
if (! moveNodeItem) {
|
|
340
|
+
$n_alert({
|
|
341
|
+
message: '移动至的节点不存在',
|
|
342
|
+
})
|
|
343
|
+
return false
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// 克隆当前树列表数据
|
|
347
|
+
const nodesClone = $n_cloneDeep(nodes.value)
|
|
348
|
+
|
|
349
|
+
// 获取当前节点
|
|
350
|
+
const nodeItem = getNode(o.node.id)
|
|
351
|
+
|
|
352
|
+
// 获取当前节点的父节点
|
|
353
|
+
const parentNodeItem = getNode(o.node.attr.pid)
|
|
354
|
+
|
|
355
|
+
// 移动列表数据
|
|
356
|
+
const moveLists = []
|
|
357
|
+
|
|
358
|
+
// 如果是移动至节点内部
|
|
359
|
+
// --------------------------------------------------
|
|
360
|
+
if (o.type === 'moveIn') {
|
|
361
|
+
|
|
362
|
+
// 修改当前节点数据
|
|
363
|
+
nodeItem.attr.pid = moveNodeItem.attr.id
|
|
364
|
+
|
|
365
|
+
nodeItem.attr.sort =
|
|
366
|
+
// 如果移动至的节点有子节点
|
|
367
|
+
moveNodeItem.children.length
|
|
368
|
+
// 则获取移动至的节点中最后一个子节点的排序号 + 1
|
|
369
|
+
? moveNodeItem.children[moveNodeItem.children.length - 1].attr.sort + 1
|
|
370
|
+
// 否则排序号设为 1
|
|
371
|
+
: 1
|
|
372
|
+
|
|
373
|
+
// 添加移动列表数据
|
|
374
|
+
moveLists.push({
|
|
375
|
+
id: nodeItem.id,
|
|
376
|
+
pid: nodeItem.attr.pid,
|
|
377
|
+
sort: nodeItem.attr.sort,
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
// 将本节点从原父节点中删除
|
|
381
|
+
const nodeItemIndex = $n_findIndex(parentNodeItem.children, { id: nodeItem.id })
|
|
382
|
+
parentNodeItem.children.splice(nodeItemIndex, 1)
|
|
383
|
+
|
|
384
|
+
// 将本节点添加至移动至的节点的子节点中
|
|
385
|
+
moveNodeItem.children.push(nodeItem)
|
|
386
|
+
|
|
387
|
+
// 否则移动至节点的上方/下方
|
|
388
|
+
// --------------------------------------------------
|
|
389
|
+
} else {
|
|
390
|
+
|
|
391
|
+
// 获取移动至节点的父节点
|
|
392
|
+
let moveParentNodeItem = getNode(moveNodeItem.attr.pid)
|
|
393
|
+
|
|
394
|
+
// 修改当前节点数据
|
|
395
|
+
nodeItem.attr.pid = moveNodeItem.attr.pid
|
|
396
|
+
nodeItem.attr.sort = moveNodeItem.attr.sort + (o.type === 'moveUp' ? 0 : 1)
|
|
397
|
+
|
|
398
|
+
// 添加移动列表数据
|
|
399
|
+
moveLists.push({
|
|
400
|
+
id: nodeItem.id,
|
|
401
|
+
pid: nodeItem.attr.pid,
|
|
402
|
+
sort: nodeItem.attr.sort,
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
// 将本节点从原父节点中删除
|
|
406
|
+
const nodeItemIndex = $n_findIndex(parentNodeItem.children, { id: nodeItem.id })
|
|
407
|
+
parentNodeItem.children.splice(nodeItemIndex, 1)
|
|
408
|
+
|
|
409
|
+
// 获取移动至节点的索引
|
|
410
|
+
const moveNodeItemIndex = $n_findIndex(moveParentNodeItem.children, { id: moveNodeId })
|
|
411
|
+
|
|
412
|
+
for (let i = moveNodeItemIndex + (o.type === 'moveUp' ? 0 : 1); i < moveParentNodeItem.children.length; i++) {
|
|
413
|
+
const item = moveParentNodeItem.children[i]
|
|
414
|
+
item.attr.sort = item.attr.sort + 1
|
|
415
|
+
moveLists.push({
|
|
416
|
+
id: item.id,
|
|
417
|
+
pid: item.attr.pid,
|
|
418
|
+
sort: item.attr.sort,
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// 将本节点插入移动至位置
|
|
423
|
+
moveParentNodeItem.children.splice(moveNodeItemIndex + (o.type === 'moveUp' ? 0 : 1), 0, nodeItem)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// 请求 - 移动
|
|
427
|
+
const { status } = await $n_http({
|
|
428
|
+
url: o.menuStatus.value.allPowerBtn.move.url,
|
|
429
|
+
data: {
|
|
430
|
+
data: moveLists,
|
|
431
|
+
},
|
|
432
|
+
})
|
|
433
|
+
if (! status) {
|
|
434
|
+
// 移动失败, 还原数据
|
|
435
|
+
nodes.value = nodesClone
|
|
436
|
+
return false
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
})
|
|
440
|
+
break
|
|
441
|
+
|
|
442
|
+
// 复制
|
|
443
|
+
case 'copy':
|
|
444
|
+
// 确认菜单
|
|
445
|
+
confirmMenu(async function() {
|
|
446
|
+
|
|
447
|
+
if (! $n_get(o.menuStatus, 'value.allPowerBtn.copy.url')) {
|
|
448
|
+
console.error('没有找到复制地址')
|
|
449
|
+
return
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// 复制的当前节点的属性
|
|
453
|
+
const newAttr = Object.assign({}, o.node.attr, {
|
|
454
|
+
title: '【复制】' + o.node.attr.title,
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
// 复制列表
|
|
458
|
+
const copyLists = [ newAttr ]
|
|
459
|
+
|
|
460
|
+
// 是否复制叶子节点
|
|
461
|
+
const isLeafNode = ! o.node.children.length
|
|
462
|
+
|
|
463
|
+
// 如果复制的是父级节点
|
|
464
|
+
if (! isLeafNode) {
|
|
465
|
+
getChildren(o.node.children, function(item) {
|
|
466
|
+
copyLists.push(item.attr)
|
|
467
|
+
})
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// 请求 - 复制
|
|
471
|
+
const { status, data: res } = await $n_http({
|
|
472
|
+
url: o.menuStatus.value.allPowerBtn.copy.url,
|
|
473
|
+
data: {
|
|
474
|
+
data: copyLists,
|
|
475
|
+
},
|
|
476
|
+
})
|
|
477
|
+
if (! status) {
|
|
478
|
+
return
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// 如果复制的是叶子节点
|
|
482
|
+
if (isLeafNode) {
|
|
483
|
+
|
|
484
|
+
// 如果返回了 id
|
|
485
|
+
if ($n_hasId(res)) {
|
|
486
|
+
|
|
487
|
+
// 更新数据
|
|
488
|
+
Object.assign(newAttr, res)
|
|
489
|
+
|
|
490
|
+
// 获取该叶子节点的父级节点
|
|
491
|
+
const parentNodeItem = getNode(newAttr.pid)
|
|
492
|
+
if (! parentNodeItem) {
|
|
493
|
+
return
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// 新增节点
|
|
497
|
+
parentNodeItem.children.push(formatNode(newAttr))
|
|
498
|
+
|
|
499
|
+
// 否则重新加载列表
|
|
500
|
+
} else {
|
|
501
|
+
reload()
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// 否则重新加载列表
|
|
505
|
+
} else {
|
|
506
|
+
reload()
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// 轻提示
|
|
510
|
+
$n_toast({
|
|
511
|
+
type: 'positive',
|
|
512
|
+
message: '复制成功',
|
|
513
|
+
})
|
|
514
|
+
})
|
|
515
|
+
break
|
|
516
|
+
|
|
517
|
+
// 删除
|
|
518
|
+
case 'delete':
|
|
519
|
+
|
|
520
|
+
// 如果有子节点
|
|
521
|
+
if (o.node.children.length) {
|
|
522
|
+
// 提示框
|
|
523
|
+
$n_alert({
|
|
524
|
+
message: '请先删除该节点下的子节点',
|
|
525
|
+
})
|
|
526
|
+
return
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (! $n_get(o.menuStatus, 'value.allPowerBtn.delete.url')) {
|
|
530
|
+
console.error('没有找到删除地址')
|
|
531
|
+
return
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// 确认菜单
|
|
535
|
+
confirmMenu(async function() {
|
|
536
|
+
|
|
537
|
+
// 请求 - 删除
|
|
538
|
+
const { status } = await $n_http({
|
|
539
|
+
url: o.menuStatus.value.allPowerBtn.delete.url,
|
|
540
|
+
data: {
|
|
541
|
+
id: o.node.id,
|
|
542
|
+
},
|
|
543
|
+
})
|
|
544
|
+
if (! status) {
|
|
545
|
+
return
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// 删除节点
|
|
549
|
+
deleteNode(o.node)
|
|
550
|
+
|
|
551
|
+
// 轻提示
|
|
552
|
+
$n_toast({
|
|
553
|
+
type: 'positive',
|
|
554
|
+
message: '删除成功',
|
|
555
|
+
})
|
|
556
|
+
})
|
|
557
|
+
break
|
|
558
|
+
|
|
559
|
+
// 全部禁用
|
|
560
|
+
case 'statusDisable':
|
|
561
|
+
// 全部正常
|
|
562
|
+
case 'statusNormal':
|
|
563
|
+
|
|
564
|
+
if (! $n_get(o.menuStatus, 'value.allPowerBtn.status.url')) {
|
|
565
|
+
console.error('没有找到状态地址')
|
|
566
|
+
return
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// 确认菜单
|
|
570
|
+
confirmMenu(async function() {
|
|
571
|
+
|
|
572
|
+
// 设置状态 ids
|
|
573
|
+
const statusIds = [ o.node.id ]
|
|
574
|
+
|
|
575
|
+
// 新状态
|
|
576
|
+
const newStatus = o.type === 'statusNormal' ? 1 : 0
|
|
577
|
+
|
|
578
|
+
// 是否叶子节点
|
|
579
|
+
const isLeafNode = ! o.node.children.length
|
|
580
|
+
|
|
581
|
+
// 如果复制的是父级节点
|
|
582
|
+
if (! isLeafNode) {
|
|
583
|
+
getChildren(o.node.children, function(item) {
|
|
584
|
+
statusIds.push(item.id)
|
|
585
|
+
})
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// 请求 - 全部禁用/正常
|
|
589
|
+
const { status } = await $n_http({
|
|
590
|
+
url: o.menuStatus.value.allPowerBtn.status.url,
|
|
591
|
+
data: {
|
|
592
|
+
// ids
|
|
593
|
+
ids: statusIds,
|
|
594
|
+
// 新状态值
|
|
595
|
+
status: newStatus,
|
|
596
|
+
},
|
|
597
|
+
})
|
|
598
|
+
if (! status) {
|
|
599
|
+
return
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// 设置当前节点状态
|
|
603
|
+
o.node.attr.status = newStatus
|
|
604
|
+
|
|
605
|
+
// 如果是父级节点
|
|
606
|
+
if (! isLeafNode) {
|
|
607
|
+
getChildren(o.node.children, function(item) {
|
|
608
|
+
item.attr.status = newStatus
|
|
609
|
+
})
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// 轻提示
|
|
613
|
+
$n_toast({
|
|
614
|
+
type: 'positive',
|
|
615
|
+
message: '恭喜您,操作成功',
|
|
616
|
+
})
|
|
617
|
+
})
|
|
618
|
+
break
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* 获取展开节点缓存
|
|
624
|
+
*/
|
|
625
|
+
function getExpandedCache(defaultValue = []) {
|
|
626
|
+
// 获取展开节点缓存
|
|
627
|
+
const res = $n_storage.get('tree_expanded_' + $route.fullPath)
|
|
628
|
+
return $n_isValidArray(res) ? res : defaultValue
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* 设置展开节点缓存
|
|
633
|
+
*/
|
|
634
|
+
function setExpandedCache(expanded) {
|
|
635
|
+
// 设置展开节点缓存(永久缓存)
|
|
636
|
+
$n_storage.set('tree_expanded_' + $route.fullPath, expanded, 0)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 展开全部
|
|
641
|
+
*/
|
|
642
|
+
function expandAll() {
|
|
643
|
+
|
|
644
|
+
// 展开节点 ids
|
|
645
|
+
const ids = []
|
|
646
|
+
|
|
647
|
+
function getChildren(data) {
|
|
648
|
+
for (const { id, children } of data) {
|
|
649
|
+
ids.push(id)
|
|
650
|
+
if ($n_isValidArray(children)) {
|
|
651
|
+
getChildren(children)
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if ($n_isValidArray(nodes.value)) {
|
|
657
|
+
getChildren(nodes.value)
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// 设置展开节点数组
|
|
661
|
+
expanded.value = ids
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* 收起全部
|
|
666
|
+
*/
|
|
667
|
+
function collapseAll() {
|
|
668
|
+
// 设置展开节点数组
|
|
669
|
+
expanded.value = [0]
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
return {
|
|
673
|
+
// 当前路由全路径
|
|
674
|
+
routeFullPath: $route.fullPath,
|
|
675
|
+
// 当前路由路径
|
|
676
|
+
routePath: $route.path,
|
|
677
|
+
// 当前路由参数
|
|
678
|
+
routeQuery: $route.query,
|
|
679
|
+
// 获取当前路由
|
|
680
|
+
getRoute() {
|
|
681
|
+
return $route
|
|
682
|
+
},
|
|
683
|
+
// 获取节点
|
|
684
|
+
getNode,
|
|
685
|
+
// 更新节点
|
|
686
|
+
updateNode,
|
|
687
|
+
// 删除节点
|
|
688
|
+
deleteNode,
|
|
689
|
+
// 获取菜单状态
|
|
690
|
+
getMenuStatus,
|
|
691
|
+
// 菜单点击
|
|
692
|
+
menuClick,
|
|
693
|
+
// 获取展开节点缓存
|
|
694
|
+
getExpandedCache,
|
|
695
|
+
// 设置展开节点缓存
|
|
696
|
+
setExpandedCache,
|
|
697
|
+
// 展开全部
|
|
698
|
+
expandAll,
|
|
699
|
+
// 收起全部
|
|
700
|
+
collapseAll,
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* 树业务
|
|
706
|
+
*/
|
|
707
|
+
const $tree = {
|
|
708
|
+
// 创建树实例
|
|
709
|
+
create,
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
export default $tree
|