@netang/quasar 0.0.106 → 0.1.8
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/components/field-table.md +30 -29
- package/_docs/docs/components/table.md +24 -25
- package/_docs/docs/utils/table.md +195 -194
- package/components/field-table/index.vue +1227 -1222
- package/components/render/index.vue +120 -150
- package/components/table/index.vue +471 -456
- package/package.json +1 -1
- package/utils/$power.js +1216 -1215
- package/utils/$render.js +75 -0
- package/utils/$table.js +1001 -999
- package/utils/index.js +62 -61
- package/utils/timestamp.js +18 -18
package/utils/$power.js
CHANGED
|
@@ -1,1215 +1,1216 @@
|
|
|
1
|
-
import { provide, inject, ref, computed } from 'vue'
|
|
2
|
-
import { useQuasar } from 'quasar'
|
|
3
|
-
|
|
4
|
-
import $n_has from 'lodash/has'
|
|
5
|
-
import $n_get from 'lodash/get'
|
|
6
|
-
import $n_merge from 'lodash/merge'
|
|
7
|
-
import $n_filter from 'lodash/filter'
|
|
8
|
-
import $n_toLower from 'lodash/toLower'
|
|
9
|
-
import $n_isNumber from 'lodash/isNumber'
|
|
10
|
-
import $n_cloneDeep from 'lodash/cloneDeep'
|
|
11
|
-
import $n_isFunction from 'lodash/isFunction'
|
|
12
|
-
import $n_pick from 'lodash/pick'
|
|
13
|
-
|
|
14
|
-
import $n_router from '@netang/utils/vue/router'
|
|
15
|
-
|
|
16
|
-
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
17
|
-
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
18
|
-
import $n_isValidString from '@netang/utils/isValidString'
|
|
19
|
-
import $n_isRequired from '@netang/utils/isRequired'
|
|
20
|
-
import $n_isNumeric from '@netang/utils/isNumeric'
|
|
21
|
-
import $n_forEach from '@netang/utils/forEach'
|
|
22
|
-
import $n_forIn from '@netang/utils/forIn'
|
|
23
|
-
import $n_slash from '@netang/utils/slash'
|
|
24
|
-
import $n_json from '@netang/utils/json'
|
|
25
|
-
import $n_join from '@netang/utils/join'
|
|
26
|
-
import $n_fail from '@netang/utils/fail'
|
|
27
|
-
import $n_success from '@netang/utils/success'
|
|
28
|
-
import $n_split from '@netang/utils/split'
|
|
29
|
-
import $n_trimString from '@netang/utils/trimString'
|
|
30
|
-
import $n_numberDeep from '@netang/utils/numberDeep'
|
|
31
|
-
import $n_indexOf from '@netang/utils/indexOf'
|
|
32
|
-
import $n_runAsync from '@netang/utils/runAsync'
|
|
33
|
-
import $n_run from '@netang/utils/run'
|
|
34
|
-
import $n_http from '@netang/utils/http'
|
|
35
|
-
|
|
36
|
-
import { statePower } from '../store'
|
|
37
|
-
import { NRenderKey, NPowerKey, NDialogKey, NFormKey, NTableKey } from './symbols'
|
|
38
|
-
|
|
39
|
-
import $n_getData from './getData'
|
|
40
|
-
import $n_toast from './toast'
|
|
41
|
-
import $n_confirm from './confirm'
|
|
42
|
-
import $n_bus from './bus'
|
|
43
|
-
|
|
44
|
-
import $n_config from './config'
|
|
45
|
-
|
|
46
|
-
import { configs } from './config'
|
|
47
|
-
|
|
48
|
-
const {
|
|
49
|
-
// 字典常量
|
|
50
|
-
dicts,
|
|
51
|
-
} = configs
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 创建权限实例
|
|
55
|
-
*/
|
|
56
|
-
function create(options) {
|
|
57
|
-
|
|
58
|
-
// 获取参数
|
|
59
|
-
const o = Object.assign({
|
|
60
|
-
// 路由路径
|
|
61
|
-
path: '',
|
|
62
|
-
// 路由参数
|
|
63
|
-
query: {},
|
|
64
|
-
// 是否加载页面
|
|
65
|
-
pageLoading: false,
|
|
66
|
-
// 页面状态
|
|
67
|
-
pageStatus: null,
|
|
68
|
-
// 空状态描述
|
|
69
|
-
emptyDescription: '',
|
|
70
|
-
// 是否开启权限
|
|
71
|
-
power: true,
|
|
72
|
-
// 是否显示权限按钮
|
|
73
|
-
showPowerBtns: true,
|
|
74
|
-
// 是否显示工具栏权限按钮
|
|
75
|
-
showToolbarPowerBtns: true,
|
|
76
|
-
// 格式化权限按钮
|
|
77
|
-
formatPowerBtns: null,
|
|
78
|
-
// 左边侧滑菜单图标
|
|
79
|
-
leftDrawerIcon: 'format_list_bulleted',
|
|
80
|
-
// 右边侧滑菜单图标
|
|
81
|
-
rightDrawerIcon: 'search',
|
|
82
|
-
// 请求前执行
|
|
83
|
-
requestBefore: null,
|
|
84
|
-
// 请求成功执行
|
|
85
|
-
requestSuccess: null,
|
|
86
|
-
// 请求失败执行
|
|
87
|
-
requestFail: null,
|
|
88
|
-
// 请求后执行
|
|
89
|
-
requestAfter: null,
|
|
90
|
-
}, options)
|
|
91
|
-
|
|
92
|
-
// 获取对话框渲染注入
|
|
93
|
-
const $dialog = inject(NDialogKey)
|
|
94
|
-
const hasDialog = !! $dialog
|
|
95
|
-
|
|
96
|
-
// 获取渲染注入
|
|
97
|
-
const $render = inject(NRenderKey)
|
|
98
|
-
const hasRender = !! $render
|
|
99
|
-
|
|
100
|
-
// 如果有对话框注入
|
|
101
|
-
if (hasDialog) {
|
|
102
|
-
const {
|
|
103
|
-
dialogProps,
|
|
104
|
-
} = $dialog
|
|
105
|
-
|
|
106
|
-
// 合并权限参数
|
|
107
|
-
Object.assign(o, $n_pick(dialogProps, [ 'path', 'query' ]))
|
|
108
|
-
|
|
109
|
-
// 合并权限参数
|
|
110
|
-
if ($n_has($dialog, 'props.powerProps') && $n_isValidObject($dialog.props.powerProps)) {
|
|
111
|
-
$n_merge(o, $dialog.props.powerProps)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// 如果有渲染注入
|
|
116
|
-
if (hasRender) {
|
|
117
|
-
// 如果有权限传参, 则合并参数
|
|
118
|
-
const powerProps = $n_get($render, 'props.powerProps')
|
|
119
|
-
if ($n_isValidObject(powerProps)) {
|
|
120
|
-
$n_merge(o, powerProps)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 获取当前路由
|
|
125
|
-
const $currentRoute = $n_router.getRoute()
|
|
126
|
-
|
|
127
|
-
// 权限路由
|
|
128
|
-
let $route
|
|
129
|
-
|
|
130
|
-
// 如果没有路由
|
|
131
|
-
if (o.path === false) {
|
|
132
|
-
|
|
133
|
-
// 设为空路由
|
|
134
|
-
$route = {
|
|
135
|
-
fullPath: '',
|
|
136
|
-
path: '',
|
|
137
|
-
query: $n_isValidObject(o.query) ? o.query : {},
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// 如果有自定义路径
|
|
141
|
-
} else if ($n_isValidString(o.path)) {
|
|
142
|
-
|
|
143
|
-
// 获取自定义路由
|
|
144
|
-
$route = $n_router.resolve({
|
|
145
|
-
path: o.path,
|
|
146
|
-
query: $n_isValidObject(o.query) ? o.query : {},
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
// 如果在渲染组件内 && 该渲染组件有自定义路由
|
|
150
|
-
} else if (hasRender && $n_has($render, '
|
|
151
|
-
|
|
152
|
-
// 设为渲染组件的路由
|
|
153
|
-
$route = $render
|
|
154
|
-
|
|
155
|
-
// 否则获取当前路由
|
|
156
|
-
} else {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
o.
|
|
263
|
-
o.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
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
|
-
item.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
item.
|
|
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
|
-
all
|
|
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
|
-
all
|
|
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
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
//
|
|
887
|
-
//
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
//
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
//
|
|
910
|
-
//
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
//
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
//
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
//
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
//
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
//
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
&& $
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
//
|
|
1131
|
-
//
|
|
1132
|
-
//
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1
|
+
import { provide, inject, ref, computed } from 'vue'
|
|
2
|
+
import { useQuasar } from 'quasar'
|
|
3
|
+
|
|
4
|
+
import $n_has from 'lodash/has'
|
|
5
|
+
import $n_get from 'lodash/get'
|
|
6
|
+
import $n_merge from 'lodash/merge'
|
|
7
|
+
import $n_filter from 'lodash/filter'
|
|
8
|
+
import $n_toLower from 'lodash/toLower'
|
|
9
|
+
import $n_isNumber from 'lodash/isNumber'
|
|
10
|
+
import $n_cloneDeep from 'lodash/cloneDeep'
|
|
11
|
+
import $n_isFunction from 'lodash/isFunction'
|
|
12
|
+
import $n_pick from 'lodash/pick'
|
|
13
|
+
|
|
14
|
+
import $n_router from '@netang/utils/vue/router'
|
|
15
|
+
|
|
16
|
+
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
17
|
+
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
18
|
+
import $n_isValidString from '@netang/utils/isValidString'
|
|
19
|
+
import $n_isRequired from '@netang/utils/isRequired'
|
|
20
|
+
import $n_isNumeric from '@netang/utils/isNumeric'
|
|
21
|
+
import $n_forEach from '@netang/utils/forEach'
|
|
22
|
+
import $n_forIn from '@netang/utils/forIn'
|
|
23
|
+
import $n_slash from '@netang/utils/slash'
|
|
24
|
+
import $n_json from '@netang/utils/json'
|
|
25
|
+
import $n_join from '@netang/utils/join'
|
|
26
|
+
import $n_fail from '@netang/utils/fail'
|
|
27
|
+
import $n_success from '@netang/utils/success'
|
|
28
|
+
import $n_split from '@netang/utils/split'
|
|
29
|
+
import $n_trimString from '@netang/utils/trimString'
|
|
30
|
+
import $n_numberDeep from '@netang/utils/numberDeep'
|
|
31
|
+
import $n_indexOf from '@netang/utils/indexOf'
|
|
32
|
+
import $n_runAsync from '@netang/utils/runAsync'
|
|
33
|
+
import $n_run from '@netang/utils/run'
|
|
34
|
+
import $n_http from '@netang/utils/http'
|
|
35
|
+
|
|
36
|
+
import { statePower } from '../store'
|
|
37
|
+
import { NRenderKey, NPowerKey, NDialogKey, NFormKey, NTableKey } from './symbols'
|
|
38
|
+
|
|
39
|
+
import $n_getData from './getData'
|
|
40
|
+
import $n_toast from './toast'
|
|
41
|
+
import $n_confirm from './confirm'
|
|
42
|
+
import $n_bus from './bus'
|
|
43
|
+
|
|
44
|
+
import $n_config from './config'
|
|
45
|
+
|
|
46
|
+
import { configs } from './config'
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
// 字典常量
|
|
50
|
+
dicts,
|
|
51
|
+
} = configs
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 创建权限实例
|
|
55
|
+
*/
|
|
56
|
+
function create(options) {
|
|
57
|
+
|
|
58
|
+
// 获取参数
|
|
59
|
+
const o = Object.assign({
|
|
60
|
+
// 路由路径
|
|
61
|
+
path: '',
|
|
62
|
+
// 路由参数
|
|
63
|
+
query: {},
|
|
64
|
+
// 是否加载页面
|
|
65
|
+
pageLoading: false,
|
|
66
|
+
// 页面状态
|
|
67
|
+
pageStatus: null,
|
|
68
|
+
// 空状态描述
|
|
69
|
+
emptyDescription: '',
|
|
70
|
+
// 是否开启权限
|
|
71
|
+
power: true,
|
|
72
|
+
// 是否显示权限按钮
|
|
73
|
+
showPowerBtns: true,
|
|
74
|
+
// 是否显示工具栏权限按钮
|
|
75
|
+
showToolbarPowerBtns: true,
|
|
76
|
+
// 格式化权限按钮
|
|
77
|
+
formatPowerBtns: null,
|
|
78
|
+
// 左边侧滑菜单图标
|
|
79
|
+
leftDrawerIcon: 'format_list_bulleted',
|
|
80
|
+
// 右边侧滑菜单图标
|
|
81
|
+
rightDrawerIcon: 'search',
|
|
82
|
+
// 请求前执行
|
|
83
|
+
requestBefore: null,
|
|
84
|
+
// 请求成功执行
|
|
85
|
+
requestSuccess: null,
|
|
86
|
+
// 请求失败执行
|
|
87
|
+
requestFail: null,
|
|
88
|
+
// 请求后执行
|
|
89
|
+
requestAfter: null,
|
|
90
|
+
}, options)
|
|
91
|
+
|
|
92
|
+
// 获取对话框渲染注入
|
|
93
|
+
const $dialog = $n_has(options, '$dialog') ? options.$dialog : inject(NDialogKey)
|
|
94
|
+
const hasDialog = !! $dialog
|
|
95
|
+
|
|
96
|
+
// 获取渲染注入
|
|
97
|
+
const $render = $n_has(options, '$render') ? options.$render : inject(NRenderKey)
|
|
98
|
+
const hasRender = !! $render
|
|
99
|
+
|
|
100
|
+
// 如果有对话框注入
|
|
101
|
+
if (hasDialog) {
|
|
102
|
+
const {
|
|
103
|
+
dialogProps,
|
|
104
|
+
} = $dialog
|
|
105
|
+
|
|
106
|
+
// 合并权限参数
|
|
107
|
+
Object.assign(o, $n_pick(dialogProps, [ 'path', 'query' ]))
|
|
108
|
+
|
|
109
|
+
// 合并权限参数
|
|
110
|
+
if ($n_has($dialog, 'props.powerProps') && $n_isValidObject($dialog.props.powerProps)) {
|
|
111
|
+
$n_merge(o, $dialog.props.powerProps)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 如果有渲染注入
|
|
116
|
+
if (hasRender) {
|
|
117
|
+
// 如果有权限传参, 则合并参数
|
|
118
|
+
const powerProps = $n_get($render, 'props.powerProps')
|
|
119
|
+
if ($n_isValidObject(powerProps)) {
|
|
120
|
+
$n_merge(o, powerProps)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 获取当前路由
|
|
125
|
+
const $currentRoute = $n_router.getRoute()
|
|
126
|
+
|
|
127
|
+
// 权限路由
|
|
128
|
+
let $route
|
|
129
|
+
|
|
130
|
+
// 如果没有路由
|
|
131
|
+
if (o.path === false) {
|
|
132
|
+
|
|
133
|
+
// 设为空路由
|
|
134
|
+
$route = {
|
|
135
|
+
fullPath: '',
|
|
136
|
+
path: '',
|
|
137
|
+
query: $n_isValidObject(o.query) ? o.query : {},
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 如果有自定义路径
|
|
141
|
+
} else if ($n_isValidString(o.path)) {
|
|
142
|
+
|
|
143
|
+
// 获取自定义路由
|
|
144
|
+
$route = $n_router.resolve({
|
|
145
|
+
path: o.path,
|
|
146
|
+
query: $n_isValidObject(o.query) ? o.query : {},
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// 如果在渲染组件内 && 该渲染组件有自定义路由
|
|
150
|
+
} else if (hasRender && $n_has($render, 'getRoute')) {
|
|
151
|
+
|
|
152
|
+
// 设为渲染组件的路由
|
|
153
|
+
$route = $render.getRoute()
|
|
154
|
+
|
|
155
|
+
// 否则获取当前路由
|
|
156
|
+
} else {
|
|
157
|
+
|
|
158
|
+
$route = $currentRoute
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// quasar 对象
|
|
162
|
+
const $q = useQuasar()
|
|
163
|
+
|
|
164
|
+
// 表格已选数据
|
|
165
|
+
const tableSelected = ref([])
|
|
166
|
+
|
|
167
|
+
// 是否显示左边侧滑菜单
|
|
168
|
+
const leftDrawerModelValue = ref(null)
|
|
169
|
+
|
|
170
|
+
// 是否显示右边侧滑菜单
|
|
171
|
+
const rightDrawerModelValue = ref(null)
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 检查是否上传中
|
|
175
|
+
*/
|
|
176
|
+
function checkUploading() {
|
|
177
|
+
for (const uploader of data.uploader) {
|
|
178
|
+
if (uploader.checkUploading()) {
|
|
179
|
+
return true
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return false
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const _data = {
|
|
186
|
+
// 表格实例
|
|
187
|
+
$table: null,
|
|
188
|
+
// 表单实例
|
|
189
|
+
$form: null,
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 注入数据
|
|
193
|
+
const data = {
|
|
194
|
+
// 页面加载
|
|
195
|
+
pageLoading: ref(o.pageLoading),
|
|
196
|
+
// 页面状态
|
|
197
|
+
pageStatus: ref(o.pageStatus),
|
|
198
|
+
// 空状态描述
|
|
199
|
+
emptyDescription: ref(o.emptyDescription),
|
|
200
|
+
|
|
201
|
+
// 当前路由全路径
|
|
202
|
+
routeFullPath: $route.fullPath,
|
|
203
|
+
// 当前路由路径
|
|
204
|
+
routePath: $route.path,
|
|
205
|
+
// 当前路由参数
|
|
206
|
+
routeQuery: $route.query,
|
|
207
|
+
// 获取当前路由
|
|
208
|
+
getRoute() {
|
|
209
|
+
return $route
|
|
210
|
+
},
|
|
211
|
+
// 格式化权限按钮
|
|
212
|
+
formatPowerBtns: o.formatPowerBtns,
|
|
213
|
+
|
|
214
|
+
// 左边侧滑菜单数据
|
|
215
|
+
leftDrawer: {
|
|
216
|
+
// 图标
|
|
217
|
+
icon: o.leftDrawerIcon,
|
|
218
|
+
// 是否显示
|
|
219
|
+
modelValue: leftDrawerModelValue,
|
|
220
|
+
// 是否显示切换按钮
|
|
221
|
+
showButton() {
|
|
222
|
+
return leftDrawerModelValue.value !== null
|
|
223
|
+
},
|
|
224
|
+
// 切换
|
|
225
|
+
toggle() {
|
|
226
|
+
if (leftDrawerModelValue.value !== null) {
|
|
227
|
+
leftDrawerModelValue.value = ! leftDrawerModelValue.value
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
// 右边侧滑菜单数据
|
|
232
|
+
rightDrawer: {
|
|
233
|
+
// 图标
|
|
234
|
+
icon: o.rightDrawerIcon,
|
|
235
|
+
// 是否显示
|
|
236
|
+
modelValue: rightDrawerModelValue,
|
|
237
|
+
// 是否显示切换按钮
|
|
238
|
+
showButton() {
|
|
239
|
+
return rightDrawerModelValue.value !== null
|
|
240
|
+
},
|
|
241
|
+
// 切换
|
|
242
|
+
toggle() {
|
|
243
|
+
if (rightDrawerModelValue.value !== null) {
|
|
244
|
+
rightDrawerModelValue.value = ! rightDrawerModelValue.value
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
// 表格已选数据
|
|
249
|
+
tableSelected,
|
|
250
|
+
// 上传器
|
|
251
|
+
uploader: [],
|
|
252
|
+
// 检查是否上传中
|
|
253
|
+
checkUploading,
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// 如果是权限页面
|
|
257
|
+
if (o.power) {
|
|
258
|
+
|
|
259
|
+
// 获取当前页面角色权限
|
|
260
|
+
const { status, data: res } = getPageData($route)
|
|
261
|
+
if (! status) {
|
|
262
|
+
o.pageStatus = false
|
|
263
|
+
o.emptyDescription = res.msg
|
|
264
|
+
o.power = false
|
|
265
|
+
|
|
266
|
+
} else {
|
|
267
|
+
// 当前页面权限
|
|
268
|
+
data.powerPage = res.page
|
|
269
|
+
// 当前页面权限按钮
|
|
270
|
+
data.powerBtns = ref(o.showPowerBtns ? res.btns : [])
|
|
271
|
+
// 当前页面工具栏权限按钮
|
|
272
|
+
data.toolbarPowerBtns = computed(function() {
|
|
273
|
+
|
|
274
|
+
if (
|
|
275
|
+
// 如果显示工具栏权限按钮
|
|
276
|
+
o.showToolbarPowerBtns
|
|
277
|
+
// 有权限按钮数据
|
|
278
|
+
&& $n_isValidArray(data.powerBtns.value)
|
|
279
|
+
) {
|
|
280
|
+
const lists = []
|
|
281
|
+
|
|
282
|
+
// 格式化权限按钮列表
|
|
283
|
+
$n_forEach($n_filter(formatBtns(data.powerBtns.value), e => e.type > 2), function(item) {
|
|
284
|
+
|
|
285
|
+
if (! item.hidden) {
|
|
286
|
+
|
|
287
|
+
// 如果是单条数据显示
|
|
288
|
+
const isSingle = item.show === 'single'
|
|
289
|
+
|
|
290
|
+
// 如果是单条 || 多条显示
|
|
291
|
+
if (isSingle || item.show === 'multiple') {
|
|
292
|
+
|
|
293
|
+
// 初始为不显示
|
|
294
|
+
item.show = false
|
|
295
|
+
|
|
296
|
+
// 如果有表格选中数据
|
|
297
|
+
if ($n_isValidArray(data.tableSelected.value)) {
|
|
298
|
+
// 如果是单个显示
|
|
299
|
+
if (isSingle) {
|
|
300
|
+
item.show = data.tableSelected.value.length === 1
|
|
301
|
+
|
|
302
|
+
// 否则是多个显示
|
|
303
|
+
} else {
|
|
304
|
+
item.show = data.tableSelected.value.length >= 1
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// 如果是手机模式
|
|
310
|
+
if ($q.platform.is.mobile) {
|
|
311
|
+
item.icon = undefined
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (
|
|
316
|
+
// 如果有格式化权限按钮方法
|
|
317
|
+
$n_isFunction(o.formatPowerBtns)
|
|
318
|
+
&& o.formatPowerBtns(item, false, tableSelected.value) === false
|
|
319
|
+
) {
|
|
320
|
+
return
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
lists.push(item)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
return lists
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return []
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
// 权限按钮点击
|
|
333
|
+
data.powerBtnClick = async function (powerBtn, tableSelected) {
|
|
334
|
+
|
|
335
|
+
// 权限请求
|
|
336
|
+
await request({
|
|
337
|
+
// 按钮数据
|
|
338
|
+
powerBtn,
|
|
339
|
+
// 权限路由参数
|
|
340
|
+
$route,
|
|
341
|
+
// 当前路由参数
|
|
342
|
+
$currentRoute,
|
|
343
|
+
// 表格选中数据
|
|
344
|
+
tableSelected,
|
|
345
|
+
// 表格实例
|
|
346
|
+
$table: _data.$table,
|
|
347
|
+
// 表单实例
|
|
348
|
+
$form: _data.$form,
|
|
349
|
+
// 检查是否正在上传文件
|
|
350
|
+
checkUploading,
|
|
351
|
+
|
|
352
|
+
// 请求前执行
|
|
353
|
+
requestBefore: o.requestBefore,
|
|
354
|
+
// 请求成功执行
|
|
355
|
+
requestSuccess: o.requestSuccess,
|
|
356
|
+
// 请求失败执行
|
|
357
|
+
requestFail: o.requestFail,
|
|
358
|
+
// 请求后执行
|
|
359
|
+
requestAfter: o.requestAfter,
|
|
360
|
+
})
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// 如果没有开启权限
|
|
366
|
+
if (! o.power) {
|
|
367
|
+
// 当前页面权限
|
|
368
|
+
data.powerPage = {}
|
|
369
|
+
// 当前页面权限按钮
|
|
370
|
+
data.powerBtns = ref([])
|
|
371
|
+
// 当前页面工具栏权限按钮
|
|
372
|
+
data.toolbarPowerBtns = ref([])
|
|
373
|
+
// 权限按钮点击
|
|
374
|
+
data.powerBtnClick = ()=>{}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// 更新数据
|
|
378
|
+
data.update = function(cb) {
|
|
379
|
+
cb(data, _data)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// 提供可以被后代组件注入的值
|
|
383
|
+
provide(NPowerKey, data)
|
|
384
|
+
|
|
385
|
+
return data
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* 设置权限数据
|
|
390
|
+
*/
|
|
391
|
+
function setData(data) {
|
|
392
|
+
|
|
393
|
+
// 如果没有角色数据
|
|
394
|
+
if (! $n_isValidObject(data)) {
|
|
395
|
+
return
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const {
|
|
399
|
+
rows,
|
|
400
|
+
v,
|
|
401
|
+
} = data
|
|
402
|
+
|
|
403
|
+
if (! $n_isValidArray(rows) || ! v) {
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// all id
|
|
408
|
+
const all = {}
|
|
409
|
+
// 页面
|
|
410
|
+
const urls = {}
|
|
411
|
+
// 按钮
|
|
412
|
+
const btns = {}
|
|
413
|
+
// 菜单
|
|
414
|
+
const menus = []
|
|
415
|
+
|
|
416
|
+
for (const item of rows) {
|
|
417
|
+
|
|
418
|
+
// 【格式化 start】
|
|
419
|
+
// --------------------------------------------------
|
|
420
|
+
if (item.data) {
|
|
421
|
+
item.data = $n_json.parse(item.data)
|
|
422
|
+
}
|
|
423
|
+
item.data = $n_isValidObject(item.data) ? $n_numberDeep(item.data) : {}
|
|
424
|
+
|
|
425
|
+
// 设置数据类型
|
|
426
|
+
item.data.type = item.data_type
|
|
427
|
+
delete item.data_type
|
|
428
|
+
|
|
429
|
+
// 标识
|
|
430
|
+
item.name = ''
|
|
431
|
+
|
|
432
|
+
// 如果有 url
|
|
433
|
+
if ($n_isValidString(item.url)) {
|
|
434
|
+
|
|
435
|
+
// url 首位加上反斜杠
|
|
436
|
+
item.url = $n_slash($n_toLower($n_trimString(item.url)), 'start', true)
|
|
437
|
+
if (item.url) {
|
|
438
|
+
|
|
439
|
+
item.data.url = item.url
|
|
440
|
+
|
|
441
|
+
// 截取最后一个反斜杠
|
|
442
|
+
const lastIndex = item.data.url.lastIndexOf('/')
|
|
443
|
+
if (lastIndex > -1) {
|
|
444
|
+
item.name = item.data.url.substring(lastIndex + 1)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
} else {
|
|
448
|
+
item.url = ''
|
|
449
|
+
item.data.url = ''
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
} else {
|
|
453
|
+
item.url = ''
|
|
454
|
+
item.data.url = ''
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// 菜单
|
|
458
|
+
if (item.type === 1) {
|
|
459
|
+
menus.push(item)
|
|
460
|
+
|
|
461
|
+
// 按钮
|
|
462
|
+
} else if (item.type > 2) {
|
|
463
|
+
|
|
464
|
+
// 按钮类型
|
|
465
|
+
switch (item.type) {
|
|
466
|
+
|
|
467
|
+
// 默认按钮
|
|
468
|
+
case 11:
|
|
469
|
+
item.color = 'default'
|
|
470
|
+
break;
|
|
471
|
+
|
|
472
|
+
// 主要按钮
|
|
473
|
+
case 12:
|
|
474
|
+
item.color = 'primary'
|
|
475
|
+
break;
|
|
476
|
+
|
|
477
|
+
// 成功按钮
|
|
478
|
+
case 13:
|
|
479
|
+
item.color = 'secondary'
|
|
480
|
+
break;
|
|
481
|
+
|
|
482
|
+
// 信息按钮
|
|
483
|
+
case 14:
|
|
484
|
+
item.color = 'info'
|
|
485
|
+
break;
|
|
486
|
+
|
|
487
|
+
// 警告按钮
|
|
488
|
+
case 15:
|
|
489
|
+
item.color = 'warning'
|
|
490
|
+
break;
|
|
491
|
+
|
|
492
|
+
// 危险按钮
|
|
493
|
+
case 16:
|
|
494
|
+
item.color = 'negative'
|
|
495
|
+
break;
|
|
496
|
+
|
|
497
|
+
// 隐藏按钮
|
|
498
|
+
case 20:
|
|
499
|
+
item.hidden = true
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
// 【格式化 end】
|
|
504
|
+
// --------------------------------------------------
|
|
505
|
+
|
|
506
|
+
// url
|
|
507
|
+
if (item.url) {
|
|
508
|
+
// 添加至 all
|
|
509
|
+
all[item.id] = item
|
|
510
|
+
// 添加至页面
|
|
511
|
+
urls[item.url] = item
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
for (const item of rows) {
|
|
516
|
+
|
|
517
|
+
// 如果有跳转页面
|
|
518
|
+
if ($n_has(item.data, 'toPage')) {
|
|
519
|
+
// 设置跳转页面地址
|
|
520
|
+
item.data.toPage = $n_has(all, item.data.toPage) ? all[item.data.toPage].data.url : null
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// 如果有请求成功执行类型
|
|
524
|
+
// else if ($n_has(item.data, 'requestSuccess.type')) {
|
|
525
|
+
// // 如果请求成功执行类型是关闭窗口、跳转并刷新页面
|
|
526
|
+
// if (item.data.requestSuccess.type === 'closePushRefresh') {
|
|
527
|
+
// // 设置刷新页面地址
|
|
528
|
+
// item.data.requestSuccess.params =
|
|
529
|
+
// (
|
|
530
|
+
// // 如果有刷新页面的参数 id
|
|
531
|
+
// $n_has(item.data.requestSuccess, 'params')
|
|
532
|
+
// // 如果有页面数据
|
|
533
|
+
// && $n_has(all, item.data.requestSuccess.params)
|
|
534
|
+
// ) ? all[item.data.requestSuccess.params].data.url : null
|
|
535
|
+
// }
|
|
536
|
+
// }
|
|
537
|
+
|
|
538
|
+
if (
|
|
539
|
+
// 数据/按钮
|
|
540
|
+
item.type > 1
|
|
541
|
+
// 有父级数据
|
|
542
|
+
&& $n_has(all, item.pid)
|
|
543
|
+
) {
|
|
544
|
+
const pItem = all[item.pid]
|
|
545
|
+
if ($n_has(btns, pItem.url)) {
|
|
546
|
+
btns[pItem.url].push(item)
|
|
547
|
+
} else {
|
|
548
|
+
btns[pItem.url] = [item]
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// 保存至权限状态中
|
|
554
|
+
statePower.value = {
|
|
555
|
+
// 角色权限版本
|
|
556
|
+
v,
|
|
557
|
+
// all id
|
|
558
|
+
all,
|
|
559
|
+
// 页面
|
|
560
|
+
urls,
|
|
561
|
+
// 按钮
|
|
562
|
+
btns,
|
|
563
|
+
// 菜单
|
|
564
|
+
menus,
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* 获取权限
|
|
570
|
+
*/
|
|
571
|
+
async function getData() {
|
|
572
|
+
|
|
573
|
+
// 如果没有权限数据
|
|
574
|
+
if (! statePower.value.v) {
|
|
575
|
+
|
|
576
|
+
// 获取权限数据
|
|
577
|
+
const res = await $n_getData($n_config('apiDataPowerName'))
|
|
578
|
+
if (res === false) {
|
|
579
|
+
statePower.value = {
|
|
580
|
+
// 权限版本
|
|
581
|
+
v: null,
|
|
582
|
+
// all id
|
|
583
|
+
all: {},
|
|
584
|
+
// 页面
|
|
585
|
+
urls: {},
|
|
586
|
+
// 按钮
|
|
587
|
+
btns: {},
|
|
588
|
+
// 菜单
|
|
589
|
+
menus: [],
|
|
590
|
+
}
|
|
591
|
+
return $n_fail()
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// 如果有权限状态数据, 则直接返回
|
|
596
|
+
if (statePower.value.v) {
|
|
597
|
+
return $n_success($n_cloneDeep(statePower.value))
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return $n_fail()
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* 解析传参
|
|
605
|
+
*/
|
|
606
|
+
function parseQuery(data, settings) {
|
|
607
|
+
|
|
608
|
+
// 如果配置是字符串
|
|
609
|
+
if ($n_isValidString(settings)) {
|
|
610
|
+
|
|
611
|
+
// 如果返回所有传参
|
|
612
|
+
if (settings === 'all') {
|
|
613
|
+
return $n_isValidObject(data) ? data : {}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// 将字符串放到数组中
|
|
617
|
+
settings = [settings]
|
|
618
|
+
|
|
619
|
+
// 如果配置是对象
|
|
620
|
+
} else if ($n_isValidObject(settings)) {
|
|
621
|
+
settings = [settings]
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const query = {}
|
|
625
|
+
|
|
626
|
+
// 如果配置是数组
|
|
627
|
+
if ($n_isValidArray(settings)) {
|
|
628
|
+
|
|
629
|
+
// 别名
|
|
630
|
+
const alias = {}
|
|
631
|
+
|
|
632
|
+
for (let item of settings) {
|
|
633
|
+
// 如果是需要的字段
|
|
634
|
+
if ($n_isValidString(item)) {
|
|
635
|
+
|
|
636
|
+
// 将字段转小写
|
|
637
|
+
item = $n_toLower($n_trimString(item))
|
|
638
|
+
|
|
639
|
+
// 判断字段是否有 as 别名
|
|
640
|
+
const arr = $n_split(item, ' as ')
|
|
641
|
+
|
|
642
|
+
// 如果有别名
|
|
643
|
+
if (arr.length === 2) {
|
|
644
|
+
alias[$n_trimString(arr[0])] = $n_trimString(arr[1])
|
|
645
|
+
|
|
646
|
+
// 否则别名就是当前字段本身
|
|
647
|
+
} else {
|
|
648
|
+
alias[item] = item
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// 否则如果是自定义传参
|
|
652
|
+
} else if ($n_isValidObject(item)) {
|
|
653
|
+
Object.assign(query, item)
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (
|
|
658
|
+
// 如果有参数数据
|
|
659
|
+
$n_isValidObject(data)
|
|
660
|
+
// 如果有定义别名
|
|
661
|
+
&& $n_isValidObject(alias)
|
|
662
|
+
) {
|
|
663
|
+
$n_forIn(data, function(value, key) {
|
|
664
|
+
|
|
665
|
+
// 如果当前字段在别名中
|
|
666
|
+
if ($n_has(alias, key)) {
|
|
667
|
+
query[alias[key]] = value
|
|
668
|
+
}
|
|
669
|
+
})
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return query
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* 格式化权限按钮
|
|
678
|
+
*/
|
|
679
|
+
function formatBtns(powerBtns, filterBtns, toObject = false) {
|
|
680
|
+
|
|
681
|
+
const newLists = []
|
|
682
|
+
|
|
683
|
+
$n_forEach(powerBtns, function(item) {
|
|
684
|
+
|
|
685
|
+
item = $n_cloneDeep(item)
|
|
686
|
+
|
|
687
|
+
const {
|
|
688
|
+
name,
|
|
689
|
+
icon,
|
|
690
|
+
} = item
|
|
691
|
+
|
|
692
|
+
Object.assign(item, {
|
|
693
|
+
// 图标
|
|
694
|
+
icon: icon || undefined,
|
|
695
|
+
// 隐藏按钮
|
|
696
|
+
hidden: $n_get(item, 'hidden') === true,
|
|
697
|
+
// 显示按钮类型
|
|
698
|
+
show: $n_has(item, 'data.show') ? item.data.show : true,
|
|
699
|
+
})
|
|
700
|
+
|
|
701
|
+
// 是否固定按钮
|
|
702
|
+
item.fixed =
|
|
703
|
+
// 非隐藏按钮
|
|
704
|
+
! item.hidden
|
|
705
|
+
// 固定列
|
|
706
|
+
&& $n_get(item, 'data.fixed') === true
|
|
707
|
+
// 单个按钮
|
|
708
|
+
&& item.show === 'single'
|
|
709
|
+
// 按钮有图标
|
|
710
|
+
&& !! item.icon
|
|
711
|
+
|
|
712
|
+
// 如果是对象
|
|
713
|
+
if ($n_isValidObject(filterBtns)) {
|
|
714
|
+
if ($n_has(filterBtns, name)) {
|
|
715
|
+
newLists.push($n_merge(item, filterBtns[name]))
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// 如果是数组
|
|
719
|
+
} else if ($n_isValidArray(filterBtns)) {
|
|
720
|
+
if ($n_indexOf(filterBtns, name) > -1) {
|
|
721
|
+
newLists.push($n_merge(item, filterBtns[name]))
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
} else {
|
|
725
|
+
newLists.push(item)
|
|
726
|
+
}
|
|
727
|
+
})
|
|
728
|
+
|
|
729
|
+
// 转数组
|
|
730
|
+
if (toObject) {
|
|
731
|
+
const obj = {}
|
|
732
|
+
for (const item of newLists) {
|
|
733
|
+
obj[item.name] = item
|
|
734
|
+
}
|
|
735
|
+
return obj
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
return newLists
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* 获取请求传参
|
|
743
|
+
*/
|
|
744
|
+
function getRequestQuery(o) {
|
|
745
|
+
|
|
746
|
+
// 获取按钮数据
|
|
747
|
+
const btnData = o.powerBtn.data
|
|
748
|
+
|
|
749
|
+
// 传参
|
|
750
|
+
const query = {}
|
|
751
|
+
|
|
752
|
+
// 如果有请求传参的传参设置
|
|
753
|
+
if ($n_has(btnData, 'requestQuery.query')) {
|
|
754
|
+
const resQuery = parseQuery(o.query, btnData.requestQuery.query)
|
|
755
|
+
if ($n_isValidObject(resQuery)) {
|
|
756
|
+
Object.assign(query, resQuery)
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// 获取列表数据
|
|
761
|
+
if (
|
|
762
|
+
// 如果按钮参数有显示类型
|
|
763
|
+
$n_has(btnData, 'show')
|
|
764
|
+
// 按钮参数的显示类型必须是单选或多选
|
|
765
|
+
&& $n_indexOf(['single', 'multiple'], btnData.show) > -1
|
|
766
|
+
// 如果有请求传参的列表设置
|
|
767
|
+
&& $n_has(btnData, 'requestQuery.list')
|
|
768
|
+
// 如果有表格数据
|
|
769
|
+
&& $n_isValidArray(o.tableSelected)
|
|
770
|
+
) {
|
|
771
|
+
let newQuery = {}
|
|
772
|
+
|
|
773
|
+
// 如果是单选
|
|
774
|
+
if (btnData.show === 'single') {
|
|
775
|
+
// 取表格选中第一条数据
|
|
776
|
+
newQuery = o.tableSelected[0]
|
|
777
|
+
|
|
778
|
+
// 否则是多选
|
|
779
|
+
} else {
|
|
780
|
+
// 合并表格选中的每一条数据
|
|
781
|
+
for (const item of o.tableSelected) {
|
|
782
|
+
$n_forIn(item, function(value, key) {
|
|
783
|
+
if ($n_has(newQuery, key)) {
|
|
784
|
+
newQuery[key].push(value)
|
|
785
|
+
} else {
|
|
786
|
+
newQuery[key] = [value]
|
|
787
|
+
}
|
|
788
|
+
})
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const resTable = parseQuery(newQuery, btnData.requestQuery.list)
|
|
793
|
+
if ($n_isValidObject(resTable)) {
|
|
794
|
+
Object.assign(query, resTable)
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
return $n_cloneDeep($n_numberDeep(query))
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* 格式化参数
|
|
803
|
+
*/
|
|
804
|
+
function formatQuery(query, isJoinArr) {
|
|
805
|
+
|
|
806
|
+
const newQuery = {}
|
|
807
|
+
|
|
808
|
+
// 格式化参数
|
|
809
|
+
$n_forIn(query, function(value, key) {
|
|
810
|
+
|
|
811
|
+
// 如果是数字
|
|
812
|
+
if ($n_isNumeric(value)) {
|
|
813
|
+
newQuery[key] = $n_isNumber(value) ? value : Number(value)
|
|
814
|
+
|
|
815
|
+
// 如果是字符串
|
|
816
|
+
} else if ($n_isValidString(value)) {
|
|
817
|
+
newQuery[key] = $n_trimString(value)
|
|
818
|
+
|
|
819
|
+
// 如果是数组
|
|
820
|
+
} else if ($n_isValidArray(value)) {
|
|
821
|
+
|
|
822
|
+
const arr = []
|
|
823
|
+
for (const val of value) {
|
|
824
|
+
|
|
825
|
+
// 如果为有效值
|
|
826
|
+
if ($n_isRequired(val)) {
|
|
827
|
+
|
|
828
|
+
// 如果是数字
|
|
829
|
+
if ($n_isNumeric(val)) {
|
|
830
|
+
arr.push($n_isNumber(val) ? val : Number(val))
|
|
831
|
+
|
|
832
|
+
// 如果是字符串
|
|
833
|
+
} else if ($n_isValidString(val)) {
|
|
834
|
+
arr.push($n_trimString(val))
|
|
835
|
+
|
|
836
|
+
// 否则为数组或对象
|
|
837
|
+
} else {
|
|
838
|
+
arr.push(val)
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
if (arr.length) {
|
|
843
|
+
newQuery[key] = isJoinArr ? $n_join(arr, ',') : arr
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
})
|
|
847
|
+
|
|
848
|
+
return newQuery
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* 角色请求
|
|
853
|
+
*/
|
|
854
|
+
async function request(options) {
|
|
855
|
+
|
|
856
|
+
// 参数
|
|
857
|
+
const o = Object.assign({
|
|
858
|
+
// 权限按钮数据
|
|
859
|
+
powerBtn: {},
|
|
860
|
+
// 表格选中数据
|
|
861
|
+
tableSelected: [],
|
|
862
|
+
// 检查是否正在上传文件
|
|
863
|
+
checkUploading: null,
|
|
864
|
+
// 请求前执行
|
|
865
|
+
requestBefore: null,
|
|
866
|
+
// 请求成功执行
|
|
867
|
+
requestSuccess: null,
|
|
868
|
+
// 请求失败执行
|
|
869
|
+
requestFail: null,
|
|
870
|
+
// 请求后执行
|
|
871
|
+
requestAfter: null,
|
|
872
|
+
}, options)
|
|
873
|
+
|
|
874
|
+
const {
|
|
875
|
+
// 权限路由参数
|
|
876
|
+
$route,
|
|
877
|
+
// 当前路由参数
|
|
878
|
+
$currentRoute,
|
|
879
|
+
} = options
|
|
880
|
+
|
|
881
|
+
o.query = $route.query
|
|
882
|
+
|
|
883
|
+
// 判断类型
|
|
884
|
+
if (! $n_get(o.powerBtn, 'data.type')) {
|
|
885
|
+
|
|
886
|
+
// 【调试模式】
|
|
887
|
+
// --------------------------------------------------
|
|
888
|
+
// #ifdef IS_DEBUG
|
|
889
|
+
console.log('没有定义数据类型')
|
|
890
|
+
// #endif
|
|
891
|
+
// --------------------------------------------------
|
|
892
|
+
|
|
893
|
+
return
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// 克隆按钮
|
|
897
|
+
o.powerBtn = $n_cloneDeep(o.powerBtn)
|
|
898
|
+
|
|
899
|
+
// 判断 url
|
|
900
|
+
o.powerBtn.data.url = $n_toLower($n_trimString(o.powerBtn.data.url))
|
|
901
|
+
if (! o.powerBtn.data.url) {
|
|
902
|
+
|
|
903
|
+
if (
|
|
904
|
+
// 如果没有跳转页面地址
|
|
905
|
+
! $n_has(o.powerBtn.data, 'toPage')
|
|
906
|
+
// 或跳转页面地址为空
|
|
907
|
+
|| ! $n_isValidString(o.powerBtn.data.toPage)
|
|
908
|
+
) {
|
|
909
|
+
// 【调试模式】
|
|
910
|
+
// --------------------------------------------------
|
|
911
|
+
// #ifdef IS_DEBUG
|
|
912
|
+
console.log('没有定义 url')
|
|
913
|
+
// #endif
|
|
914
|
+
// --------------------------------------------------
|
|
915
|
+
|
|
916
|
+
return
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// 用跳转页面地址替换 toPage
|
|
920
|
+
o.powerBtn.data = Object.assign({}, o.powerBtn.data, {
|
|
921
|
+
url: o.powerBtn.data.toPage,
|
|
922
|
+
})
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// 获取按钮数据
|
|
926
|
+
const btnData = o.powerBtn.data
|
|
927
|
+
|
|
928
|
+
// 获取请求参数
|
|
929
|
+
let query = getRequestQuery(o)
|
|
930
|
+
|
|
931
|
+
// 如果是打开新窗口
|
|
932
|
+
// --------------------------------------------------
|
|
933
|
+
if (btnData.type === dicts.POWER_DATA_TYPE__OPEN) {
|
|
934
|
+
|
|
935
|
+
query = formatQuery(query, true)
|
|
936
|
+
|
|
937
|
+
// 如果按钮有标题
|
|
938
|
+
const pageTitle = $n_trimString(o.powerBtn.title)
|
|
939
|
+
if (pageTitle) {
|
|
940
|
+
query.n_page_title = pageTitle
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// 如果不是禁止添加来源页面参数
|
|
944
|
+
if ($n_get(btnData, 'noFromPageQuery') !== true) {
|
|
945
|
+
// 来源页面是当前路由的完整路径
|
|
946
|
+
query.n_from_page = encodeURIComponent($currentRoute.fullPath)
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// 请求前执行
|
|
950
|
+
const resBefore = await $n_runAsync(o.requestBefore)({ options: o, requestData: query })
|
|
951
|
+
if (resBefore !== void 0) {
|
|
952
|
+
if (resBefore === false) {
|
|
953
|
+
return
|
|
954
|
+
}
|
|
955
|
+
query = resBefore
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
$n_router.push({
|
|
959
|
+
path: btnData.url,
|
|
960
|
+
query,
|
|
961
|
+
})
|
|
962
|
+
return
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// 请求数据
|
|
966
|
+
let requestData = {}
|
|
967
|
+
|
|
968
|
+
// 如果是提交表单
|
|
969
|
+
// --------------------------------------------------
|
|
970
|
+
if (btnData.type === dicts.POWER_DATA_TYPE__FORM) {
|
|
971
|
+
|
|
972
|
+
// 获取表单注入
|
|
973
|
+
o.$form = $n_has(options, '$form') ? options.$form : inject(NFormKey)
|
|
974
|
+
|
|
975
|
+
if (! o.$form) {
|
|
976
|
+
throw new Error('没有创建表单实例')
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// 如果验证表单
|
|
980
|
+
if ($n_get(btnData, 'validate') !== false) {
|
|
981
|
+
|
|
982
|
+
if (! o.$form.formRef) {
|
|
983
|
+
throw new Error('没有绑定 fromRef')
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// 验证表单
|
|
987
|
+
if (! await o.$form.formRef.value.validate()) {
|
|
988
|
+
return
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// 验证表单数据
|
|
993
|
+
if (! $n_isValidObject(o.$form.formData.value)) {
|
|
994
|
+
throw new Error('没有获取到表单数据')
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
// 检查是否正在上传文件
|
|
998
|
+
if ($n_isFunction(o.checkUploading) && o.checkUploading()) {
|
|
999
|
+
// 轻提示
|
|
1000
|
+
$n_toast({
|
|
1001
|
+
message: '文件上传中,请耐心等待',
|
|
1002
|
+
})
|
|
1003
|
+
return
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// 获取请求数据
|
|
1007
|
+
requestData = $n_merge({}, formatQuery(query, false), o.$form.formData.value)
|
|
1008
|
+
|
|
1009
|
+
// 如果是请求数据
|
|
1010
|
+
// --------------------------------------------------
|
|
1011
|
+
} else {
|
|
1012
|
+
// 获取表格注入
|
|
1013
|
+
o.$table = $n_has(options, '$table') ? options.$table : inject(NTableKey)
|
|
1014
|
+
|
|
1015
|
+
// 获取请求数据
|
|
1016
|
+
requestData = formatQuery(query, false)
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
// 判断是否有确认框
|
|
1020
|
+
const isConfirm = $n_get(btnData, 'confirm')
|
|
1021
|
+
if (
|
|
1022
|
+
// 如果有确认框
|
|
1023
|
+
isConfirm
|
|
1024
|
+
// 如果有密码确认框
|
|
1025
|
+
|| $n_get(btnData, 'confirmPassword')
|
|
1026
|
+
) {
|
|
1027
|
+
// 如果需要先弹出确认框
|
|
1028
|
+
if (isConfirm) {
|
|
1029
|
+
|
|
1030
|
+
// 确认框
|
|
1031
|
+
$n_confirm({
|
|
1032
|
+
// 重要操作,请输入登录密码并确认后操作
|
|
1033
|
+
message: $n_isValidString(isConfirm) ? isConfirm : '确认要执行该操作吗?',
|
|
1034
|
+
})
|
|
1035
|
+
// 点击确认执行
|
|
1036
|
+
.onOk(onRequest)
|
|
1037
|
+
|
|
1038
|
+
return
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// 否则执行请求
|
|
1043
|
+
await onRequest()
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* 请求事件
|
|
1047
|
+
*/
|
|
1048
|
+
async function onRequest() {
|
|
1049
|
+
|
|
1050
|
+
// 请求前执行
|
|
1051
|
+
const resBefore = await $n_runAsync(o.requestBefore)({ options: o, requestData })
|
|
1052
|
+
if (resBefore !== void 0) {
|
|
1053
|
+
if (resBefore === false) {
|
|
1054
|
+
return
|
|
1055
|
+
}
|
|
1056
|
+
requestData = resBefore
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// 请求
|
|
1060
|
+
const res = await $n_http({
|
|
1061
|
+
// 请求地址
|
|
1062
|
+
url: btnData.url,
|
|
1063
|
+
// 请求数据
|
|
1064
|
+
data: requestData,
|
|
1065
|
+
})
|
|
1066
|
+
|
|
1067
|
+
// 返回结果数据
|
|
1068
|
+
const resultData = Object.assign({
|
|
1069
|
+
// 参数
|
|
1070
|
+
options: o,
|
|
1071
|
+
// 请求数据
|
|
1072
|
+
requestData,
|
|
1073
|
+
}, res)
|
|
1074
|
+
|
|
1075
|
+
// 请求后执行
|
|
1076
|
+
if (await $n_runAsync(o.requestAfter)(resultData) === false) {
|
|
1077
|
+
return
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// 如果请求成功
|
|
1081
|
+
if (res.status) {
|
|
1082
|
+
|
|
1083
|
+
// 下一步
|
|
1084
|
+
function next(isNotify = true) {
|
|
1085
|
+
|
|
1086
|
+
// 轻提示
|
|
1087
|
+
if (isNotify) {
|
|
1088
|
+
$n_toast({
|
|
1089
|
+
type: 'positive',
|
|
1090
|
+
message: '恭喜您,操作成功',
|
|
1091
|
+
})
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// 判断是否有请求成功后的操作动作
|
|
1095
|
+
if ($n_has(btnData, 'requestSuccess.type')) {
|
|
1096
|
+
switch (btnData.requestSuccess.type) {
|
|
1097
|
+
|
|
1098
|
+
// 关闭当前页面
|
|
1099
|
+
case 'close':
|
|
1100
|
+
// 关闭窗口并跳转页面
|
|
1101
|
+
case 'closePush':
|
|
1102
|
+
// 关闭窗口、跳转并刷新页面
|
|
1103
|
+
case 'closePushRefresh':
|
|
1104
|
+
|
|
1105
|
+
// 如果是渲染页面
|
|
1106
|
+
// 说明该页面在 <table-splitter> 组件内部被渲染, 则不需要关闭当前窗口
|
|
1107
|
+
if ($n_has($route.query, 'n_renderpage') && $route.query.n_renderpage === 1) {
|
|
1108
|
+
// 则无任何操作
|
|
1109
|
+
return
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
const opts = {
|
|
1113
|
+
type: 'closeCurrentTab',
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
if (
|
|
1117
|
+
// 如果不是关闭当前页面, 则为关闭窗口并跳转页面
|
|
1118
|
+
btnData.requestSuccess.type !== 'close'
|
|
1119
|
+
// 如果有来源页面
|
|
1120
|
+
&& $n_has($route.query, 'n_from_page')
|
|
1121
|
+
&& $n_isValidString($route.query.n_from_page)
|
|
1122
|
+
) {
|
|
1123
|
+
Object.assign(opts, {
|
|
1124
|
+
// 跳转页面地址
|
|
1125
|
+
pushPage: decodeURIComponent($route.query.n_from_page),
|
|
1126
|
+
// 是否跳转并刷新页面
|
|
1127
|
+
isPushRefresh: btnData.requestSuccess.type === 'closePushRefresh',
|
|
1128
|
+
})
|
|
1129
|
+
|
|
1130
|
+
// 否则如果定义了跳转页面
|
|
1131
|
+
// else if ($n_has(btnData, 'requestSuccess.params') && $n_isValidString(btnData.requestSuccess.params)) {
|
|
1132
|
+
// pushPage = btnData.requestSuccess.params
|
|
1133
|
+
// }
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// 关闭当前标签页
|
|
1137
|
+
$n_bus.emit('main', opts)
|
|
1138
|
+
break
|
|
1139
|
+
|
|
1140
|
+
// 重置表单
|
|
1141
|
+
case 'resetForm':
|
|
1142
|
+
$n_run(o.$form?.resetForm)()
|
|
1143
|
+
break
|
|
1144
|
+
|
|
1145
|
+
// 刷新列表
|
|
1146
|
+
case 'refreshList':
|
|
1147
|
+
$n_run(o.$table?.tableRefresh)()
|
|
1148
|
+
break
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
// 请求成功执行
|
|
1154
|
+
if (await $n_runAsync(o.requestSuccess)(Object.assign({ next }, resultData)) === false) {
|
|
1155
|
+
return
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// 下一步
|
|
1159
|
+
next()
|
|
1160
|
+
|
|
1161
|
+
} else {
|
|
1162
|
+
// 请求失败执行
|
|
1163
|
+
$n_run(o.requestFail)(resultData)
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* 获取路由页面的角色权限
|
|
1170
|
+
*/
|
|
1171
|
+
function getPageData($route) {
|
|
1172
|
+
|
|
1173
|
+
if (! $route) {
|
|
1174
|
+
$route = $n_router.getRoute()
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
const path = $n_get($route, 'path')
|
|
1178
|
+
if (! path) {
|
|
1179
|
+
return $n_fail('路由参数错误')
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
if (! statePower.value.v) {
|
|
1183
|
+
return $n_fail('没有获取到权限数据')
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// 获取角色数据
|
|
1187
|
+
const { urls, btns } = $n_cloneDeep(statePower.value)
|
|
1188
|
+
if (! $n_has(urls, path)) {
|
|
1189
|
+
return $n_fail('该页面没有权限')
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
return $n_success({
|
|
1193
|
+
page: urls[path],
|
|
1194
|
+
btns: $n_has(btns, path) ? btns[path] : [],
|
|
1195
|
+
})
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* 权限业务
|
|
1200
|
+
*/
|
|
1201
|
+
const $power = {
|
|
1202
|
+
// 创建权限实例
|
|
1203
|
+
create,
|
|
1204
|
+
// 设置权限数据
|
|
1205
|
+
setData,
|
|
1206
|
+
// 获取权限数据
|
|
1207
|
+
getData,
|
|
1208
|
+
// 获取路由页面的角色权限
|
|
1209
|
+
getPageData,
|
|
1210
|
+
// 格式化权限按钮
|
|
1211
|
+
formatBtns,
|
|
1212
|
+
// 请求
|
|
1213
|
+
request,
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
export default $power
|