@netang/quasar 0.0.22 → 0.0.24
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/components/dialog/index.vue +1 -3
- package/components/field-date/index.vue +2 -21
- package/components/field-table/index.vue +623 -214
- package/components/field-tree/index.vue +2 -30
- package/components/search/index.vue +95 -93
- package/components/table/index.vue +33 -26
- package/components/table-pagination/index.vue +35 -5
- package/package.json +1 -1
- package/sass/quasar/field.scss +9 -8
- package/utils/$power.js +18 -8
- package/utils/$table.js +304 -172
- package/utils/$tree.js +1 -1
package/utils/$table.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ref, computed, provide, inject, watch } from 'vue'
|
|
2
2
|
import { date, useQuasar } from 'quasar'
|
|
3
|
-
import { parse } from 'qs'
|
|
4
3
|
|
|
5
4
|
// 表格配置
|
|
6
5
|
import tablesConfig from '@/tables'
|
|
@@ -10,39 +9,7 @@ import {
|
|
|
10
9
|
setItemValue,
|
|
11
10
|
} from './$search'
|
|
12
11
|
|
|
13
|
-
import { NPowerKey, NTableKey } from './symbols'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 对话框设置
|
|
17
|
-
*/
|
|
18
|
-
function dialogSetting($dialog, o) {
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
dialogProps,
|
|
22
|
-
props,
|
|
23
|
-
} = $dialog
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
route
|
|
27
|
-
} = dialogProps
|
|
28
|
-
|
|
29
|
-
// 如果是路由组件地址
|
|
30
|
-
if (utils.isValidString(route)) {
|
|
31
|
-
o.url = utils.slash(route, 'start', false)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
// 是否多选
|
|
36
|
-
multiple,
|
|
37
|
-
query,
|
|
38
|
-
} = props
|
|
39
|
-
|
|
40
|
-
// 是否多选
|
|
41
|
-
o.selection = multiple ? 'multiple' : 'single'
|
|
42
|
-
|
|
43
|
-
// 合并参数
|
|
44
|
-
Object.assign(o.query, query)
|
|
45
|
-
}
|
|
12
|
+
import { NPowerKey, NTableKey, NDialogKey } from './symbols'
|
|
46
13
|
|
|
47
14
|
/**
|
|
48
15
|
* 创建表格
|
|
@@ -56,7 +23,7 @@ function create(params) {
|
|
|
56
23
|
|
|
57
24
|
// 每页显示行数选项
|
|
58
25
|
// const rowsPerPageOptions = [30, 40, 50, 100, 200, 500, 1000]
|
|
59
|
-
const rowsPerPageOptions = [
|
|
26
|
+
const rowsPerPageOptions = [3, 40, 50, 100, 200, 500, 1000]
|
|
60
27
|
|
|
61
28
|
// 获取参数
|
|
62
29
|
const o = _.merge({
|
|
@@ -64,12 +31,14 @@ function create(params) {
|
|
|
64
31
|
path: '',
|
|
65
32
|
// 路由参数
|
|
66
33
|
query: {},
|
|
67
|
-
//
|
|
68
|
-
|
|
34
|
+
// 附加请求数据
|
|
35
|
+
data: {},
|
|
69
36
|
// 表格行唯一键值
|
|
70
37
|
rowKey: 'id',
|
|
71
38
|
// 选择类型, 可选值 single multiple none
|
|
72
39
|
selection: 'multiple',
|
|
40
|
+
// 已选数据
|
|
41
|
+
selected: [],
|
|
73
42
|
// 表格加载状态
|
|
74
43
|
loading: false,
|
|
75
44
|
// 表格列数据(对象数组)
|
|
@@ -112,22 +81,22 @@ function create(params) {
|
|
|
112
81
|
showGrid: true,
|
|
113
82
|
// 显示可见列
|
|
114
83
|
showVisibleColumns: true,
|
|
84
|
+
// 开启缓存
|
|
85
|
+
cache: true,
|
|
86
|
+
// 刷新后清空已选数据
|
|
87
|
+
refreshResetSelected: true,
|
|
115
88
|
}, params)
|
|
116
89
|
|
|
117
90
|
// 获取权限注入
|
|
118
91
|
const $power = _.has(params, '$power') ? params.$power : inject(NPowerKey)
|
|
119
92
|
const hasPowr = !! $power
|
|
120
93
|
|
|
121
|
-
// 获取对话框注入
|
|
122
|
-
const $dialog = utils.$dialog.inject()
|
|
123
|
-
const inDialog = !! $dialog
|
|
124
|
-
|
|
125
94
|
// 获取权限路由
|
|
126
95
|
const $route = utils.isValidString(o.path) ?
|
|
127
96
|
// 如果为自定义路由
|
|
128
97
|
utils.router.resolve({
|
|
129
98
|
path: o.path,
|
|
130
|
-
query: o.query,
|
|
99
|
+
query: utils.isValidObject(o.query) ? o.query : {},
|
|
131
100
|
})
|
|
132
101
|
// 否则获取当前路由
|
|
133
102
|
: (hasPowr ? $power.getRoute() : utils.router.getRoute())
|
|
@@ -137,18 +106,15 @@ function create(params) {
|
|
|
137
106
|
|
|
138
107
|
// 表格已选数据
|
|
139
108
|
const tableSelected = hasPowr ? $power.tableSelected : ref([])
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (inDialog) {
|
|
143
|
-
// 对话框设置
|
|
144
|
-
dialogSetting($dialog, o)
|
|
109
|
+
if (utils.isValidArray(o.selected)) {
|
|
110
|
+
tableSelected.value = o.selected
|
|
145
111
|
}
|
|
146
112
|
|
|
147
|
-
//
|
|
148
|
-
const
|
|
113
|
+
// 是否开启缓存
|
|
114
|
+
const isCache = !! o.cache
|
|
149
115
|
|
|
150
|
-
//
|
|
151
|
-
const
|
|
116
|
+
// 缓存名
|
|
117
|
+
const cacheName = $route.fullPath ? $route.fullPath : (utils.isValidString(o.cache) ? o.cache : '')
|
|
152
118
|
|
|
153
119
|
// 表格列
|
|
154
120
|
const tableColumns = []
|
|
@@ -179,6 +145,9 @@ function create(params) {
|
|
|
179
145
|
item.align = 'left'
|
|
180
146
|
}
|
|
181
147
|
|
|
148
|
+
// 是否隐藏
|
|
149
|
+
item.hide = _.get(item, 'hide') === true
|
|
150
|
+
|
|
182
151
|
// 如果有显示项
|
|
183
152
|
if (_.get(item, 'visible') !== false) {
|
|
184
153
|
o.visibleColumns.push(item.field)
|
|
@@ -214,17 +183,11 @@ function create(params) {
|
|
|
214
183
|
})
|
|
215
184
|
|
|
216
185
|
// 获取可见列缓存
|
|
217
|
-
const visibleColumnsCache = o.showVisibleColumns ? utils.storage.get(
|
|
186
|
+
const visibleColumnsCache = o.showVisibleColumns && isCache ? utils.storage.get('table_visible_columns_' + cacheName) : []
|
|
218
187
|
|
|
219
188
|
// 表格可见列
|
|
220
189
|
const tableVisibleColumns = ref(Array.isArray(visibleColumnsCache) ? visibleColumnsCache : _.uniq([...o.visibleColumns]))
|
|
221
190
|
|
|
222
|
-
// 表格工具栏节点
|
|
223
|
-
const tableToolbarRef = ref(null)
|
|
224
|
-
|
|
225
|
-
// 表格节点
|
|
226
|
-
const tableRef = ref(o.ref)
|
|
227
|
-
|
|
228
191
|
// 表格加载状态
|
|
229
192
|
const tableLoading = ref(o.loading)
|
|
230
193
|
|
|
@@ -232,10 +195,10 @@ function create(params) {
|
|
|
232
195
|
const tableRows = ref(o.rows)
|
|
233
196
|
|
|
234
197
|
// 表格翻页参数
|
|
235
|
-
const tablePagination = ref(o.pagination)
|
|
198
|
+
const tablePagination = ref($route.fullPath ? o.pagination : {})
|
|
236
199
|
|
|
237
200
|
// 表格宫格
|
|
238
|
-
const tableGrid = ref(o.showGrid ? utils.storage.get(
|
|
201
|
+
const tableGrid = ref(o.showGrid && isCache ? utils.storage.get('table_grid_' + cacheName) === true : false)
|
|
239
202
|
|
|
240
203
|
// 表格传参
|
|
241
204
|
const tableQuery = ref({})
|
|
@@ -249,14 +212,6 @@ function create(params) {
|
|
|
249
212
|
// 表格合计
|
|
250
213
|
const tableSummary = ref(null)
|
|
251
214
|
|
|
252
|
-
// 如果在表格内部
|
|
253
|
-
if (inDialog) {
|
|
254
|
-
// 提交表格已选数据给对话框
|
|
255
|
-
$dialog.submit(function() {
|
|
256
|
-
return tableSelected.value
|
|
257
|
-
})
|
|
258
|
-
}
|
|
259
|
-
|
|
260
215
|
const {
|
|
261
216
|
// 原始参数
|
|
262
217
|
rawQuery,
|
|
@@ -270,15 +225,14 @@ function create(params) {
|
|
|
270
225
|
} = utils.$search.getRawData(tableColumns, Object.assign({}, $route.query), o.searchFromQuery)
|
|
271
226
|
|
|
272
227
|
// 表格搜索数据值
|
|
273
|
-
const tableSearchValue = ref(firstTableSearchValue)
|
|
274
|
-
|
|
275
|
-
watch(tableSearchValue, function (val) {
|
|
276
|
-
console.log('tableSearchValue', val)
|
|
277
|
-
})
|
|
228
|
+
const tableSearchValue = ref($route.fullPath ? firstTableSearchValue : [])
|
|
278
229
|
|
|
279
230
|
// 表格搜索参数
|
|
280
231
|
const tableSearchOptions = ref()
|
|
281
232
|
|
|
233
|
+
// 是否已加载
|
|
234
|
+
let _isTableLoaded = false
|
|
235
|
+
|
|
282
236
|
// ==========【计算属性】=============================================================================================
|
|
283
237
|
|
|
284
238
|
/**
|
|
@@ -330,12 +284,12 @@ function create(params) {
|
|
|
330
284
|
/**
|
|
331
285
|
* 监听表格宫格模式
|
|
332
286
|
*/
|
|
333
|
-
if (o.showGrid) {
|
|
287
|
+
if (o.showGrid && isCache) {
|
|
334
288
|
watch(tableGrid, function(val) {
|
|
335
289
|
|
|
336
290
|
// 设置宫格模式缓存(永久缓存)
|
|
337
291
|
// #if ! IS_DEV
|
|
338
|
-
utils.storage.set(
|
|
292
|
+
utils.storage.set('table_grid_' + cacheName, val, 0)
|
|
339
293
|
// #endif
|
|
340
294
|
})
|
|
341
295
|
}
|
|
@@ -343,12 +297,12 @@ function create(params) {
|
|
|
343
297
|
/**
|
|
344
298
|
* 监听表格可见列
|
|
345
299
|
*/
|
|
346
|
-
if (o.showVisibleColumns) {
|
|
300
|
+
if (o.showVisibleColumns && isCache) {
|
|
347
301
|
watch(tableVisibleColumns, function(val) {
|
|
348
302
|
|
|
349
303
|
// 设置可见列缓存(永久缓存)
|
|
350
304
|
// #if ! IS_DEV
|
|
351
|
-
utils.storage.set(
|
|
305
|
+
utils.storage.set('table_visible_columns_' + cacheName, val, 0)
|
|
352
306
|
// #endif
|
|
353
307
|
})
|
|
354
308
|
}
|
|
@@ -399,107 +353,240 @@ function create(params) {
|
|
|
399
353
|
*/
|
|
400
354
|
watch(tableQuery, function (query) {
|
|
401
355
|
|
|
402
|
-
// 如果禁止从参数中获取搜索值
|
|
403
|
-
if (! o.searchFromQuery) {
|
|
404
|
-
tableRequestQuery = query
|
|
405
|
-
return
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const newQuery = {}
|
|
409
|
-
|
|
410
356
|
if (utils.isValidObject(query)) {
|
|
411
357
|
|
|
358
|
+
query = _.cloneDeep(query)
|
|
359
|
+
|
|
412
360
|
// 搜索参数键值数组
|
|
413
361
|
const searchQueryKey = []
|
|
414
362
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
363
|
+
// 搜索键值数组
|
|
364
|
+
const NSearchKeys = []
|
|
365
|
+
// 搜索数组
|
|
366
|
+
const NSearchValues = []
|
|
367
|
+
|
|
368
|
+
// 参数中是否有自定义搜索参数
|
|
369
|
+
const hasNSearch = _.has(query, 'n_search')
|
|
370
|
+
if (hasNSearch) {
|
|
371
|
+
// 删除在搜索中存在的参数键值
|
|
372
|
+
utils.forIn(query.n_search, function (item, key) {
|
|
373
|
+
if (_.has(query, key)) {
|
|
374
|
+
delete query[key]
|
|
375
|
+
}
|
|
376
|
+
})
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// 如果允许从参数中获取搜索值
|
|
380
|
+
if (o.searchFromQuery) {
|
|
381
|
+
|
|
382
|
+
utils.forEach(rawSearchOptions, function (item, index) {
|
|
383
|
+
|
|
384
|
+
const valueItem = tableSearchValue.value[index]
|
|
385
|
+
|
|
386
|
+
// 如果传参在搜素 n_search 参数中
|
|
387
|
+
if (hasNSearch && _.has(query.n_search, item.name)) {
|
|
388
|
+
const newSearchItem = query.n_search[item.name]
|
|
389
|
+
if (utils.isValidArray(newSearchItem)) {
|
|
390
|
+
valueItem[0].type = newSearchItem[0].type
|
|
391
|
+
valueItem[0].value = newSearchItem[0].value
|
|
392
|
+
|
|
393
|
+
if (newSearchItem.length > 1) {
|
|
394
|
+
valueItem[1].type = newSearchItem[1].type
|
|
395
|
+
valueItem[1].value = newSearchItem[1].value
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// 设置搜索的 key
|
|
399
|
+
NSearchKeys.push(item.name)
|
|
400
|
+
|
|
401
|
+
// 如果传参在搜索参数中
|
|
402
|
+
} else if (_.has(query, item.name)) {
|
|
403
|
+
// 设置单个搜索值
|
|
404
|
+
setItemValue(valueItem, utils.isRequired(query[item.name]) ? query[item.name] : '')
|
|
405
|
+
// 设置参数中搜索的 key
|
|
406
|
+
searchQueryKey.push(item.name)
|
|
407
|
+
}
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
utils.forEach(searchQueryKey, function (key) {
|
|
411
|
+
delete query[key]
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
if (hasNSearch) {
|
|
415
|
+
utils.forIn(query.n_search, function(item, key) {
|
|
416
|
+
if (
|
|
417
|
+
NSearchKeys.indexOf(key) === -1
|
|
418
|
+
&& utils.isValidArray(item)
|
|
419
|
+
) {
|
|
420
|
+
item[0].field = key
|
|
421
|
+
NSearchValues.push(item[0])
|
|
422
|
+
|
|
423
|
+
if (item.length > 1) {
|
|
424
|
+
item[1].field = key
|
|
425
|
+
NSearchValues.push(item[1])
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
})
|
|
422
429
|
}
|
|
423
|
-
})
|
|
424
430
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
431
|
+
} else {
|
|
432
|
+
utils.forIn(query.n_search, function(item, key) {
|
|
433
|
+
if (utils.isValidArray(item)) {
|
|
434
|
+
item[0].field = key
|
|
435
|
+
NSearchValues.push(item[0])
|
|
436
|
+
if (item.length > 1) {
|
|
437
|
+
item[1].field = key
|
|
438
|
+
NSearchValues.push(item[1])
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
})
|
|
428
442
|
}
|
|
429
443
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
444
|
+
if (NSearchValues.length) {
|
|
445
|
+
query.n_search = NSearchValues
|
|
446
|
+
} else if (hasNSearch) {
|
|
447
|
+
delete query.n_search
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
tableRequestQuery = query
|
|
451
|
+
return
|
|
435
452
|
}
|
|
436
453
|
|
|
437
|
-
tableRequestQuery =
|
|
454
|
+
tableRequestQuery = {}
|
|
455
|
+
|
|
456
|
+
}, {
|
|
457
|
+
// 深度监听
|
|
458
|
+
deep: true,
|
|
438
459
|
})
|
|
439
460
|
|
|
440
461
|
// ==========【方法】================================================================================================
|
|
441
462
|
|
|
442
463
|
/**
|
|
443
|
-
*
|
|
464
|
+
* 表格是否已加载
|
|
465
|
+
*/
|
|
466
|
+
function isTableLoaded() {
|
|
467
|
+
return _isTableLoaded
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 表格加载(只加载一次)
|
|
472
|
+
*/
|
|
473
|
+
async function tableLoad() {
|
|
474
|
+
|
|
475
|
+
// 如果表格已加载过了
|
|
476
|
+
if (_isTableLoaded) {
|
|
477
|
+
// 则无任何操作
|
|
478
|
+
return
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// 表格重新加载
|
|
482
|
+
await tableReload()
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* 表格重新加载
|
|
444
487
|
*/
|
|
445
|
-
function
|
|
488
|
+
async function tableReload() {
|
|
489
|
+
|
|
490
|
+
// 表格已加载
|
|
491
|
+
_isTableLoaded = true
|
|
492
|
+
|
|
493
|
+
if (! $route.fullPath) {
|
|
494
|
+
return
|
|
495
|
+
}
|
|
496
|
+
|
|
446
497
|
// 请求表格合计
|
|
447
498
|
if (o.summary) {
|
|
448
499
|
isRequestSummary = true
|
|
449
500
|
}
|
|
501
|
+
|
|
450
502
|
// 请求表格数据
|
|
451
|
-
tableRef
|
|
503
|
+
// $tableRef?.requestServerInteraction({
|
|
504
|
+
// pagination: o.pagination,
|
|
505
|
+
// })
|
|
506
|
+
await tableRequest({
|
|
507
|
+
pagination: o.pagination,
|
|
508
|
+
})
|
|
509
|
+
|
|
452
510
|
// 清空表格已选数据
|
|
453
|
-
|
|
511
|
+
if (o.refreshResetSelected) {
|
|
512
|
+
tableSelected.value = []
|
|
513
|
+
}
|
|
454
514
|
}
|
|
455
515
|
|
|
456
516
|
/**
|
|
457
|
-
*
|
|
517
|
+
* 表格刷新
|
|
458
518
|
*/
|
|
459
|
-
function
|
|
519
|
+
async function tableRefresh() {
|
|
520
|
+
|
|
521
|
+
if (! $route.fullPath) {
|
|
522
|
+
return
|
|
523
|
+
}
|
|
524
|
+
|
|
460
525
|
// 请求表格合计
|
|
461
526
|
if (o.summary) {
|
|
462
527
|
isRequestSummary = true
|
|
463
528
|
}
|
|
529
|
+
|
|
464
530
|
// 请求表格数据
|
|
465
|
-
tableRef.
|
|
466
|
-
|
|
531
|
+
// $tableRef.requestServerInteraction()
|
|
532
|
+
await tableRequest({
|
|
533
|
+
pagination: tablePagination.value,
|
|
467
534
|
})
|
|
535
|
+
|
|
468
536
|
// 清空表格已选数据
|
|
469
|
-
|
|
537
|
+
if (o.refreshResetSelected) {
|
|
538
|
+
tableSelected.value = []
|
|
539
|
+
}
|
|
470
540
|
}
|
|
471
541
|
|
|
472
542
|
/**
|
|
473
543
|
* 表格搜索重置
|
|
474
544
|
*/
|
|
475
|
-
function tableSearchReset() {
|
|
545
|
+
function tableSearchReset(reload = true) {
|
|
546
|
+
|
|
547
|
+
const newValue = []
|
|
548
|
+
|
|
549
|
+
utils.forEach(rawSearchOptions, function (item, index) {
|
|
550
|
+
// 如果该搜索条件是隐藏的
|
|
551
|
+
if (item.hide) {
|
|
552
|
+
newValue.push(tableSearchValue.value[index])
|
|
553
|
+
// 否则为初始值
|
|
554
|
+
} else {
|
|
555
|
+
newValue.push(rawTableSearchValue[index])
|
|
556
|
+
}
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
console.log('newValue', newValue)
|
|
476
560
|
|
|
477
561
|
// 还原表格搜索数据
|
|
478
|
-
tableSearchValue.value = _.cloneDeep(
|
|
562
|
+
tableSearchValue.value = _.cloneDeep(newValue)
|
|
479
563
|
|
|
480
564
|
// 表格重新加载
|
|
481
|
-
|
|
565
|
+
if (reload) {
|
|
566
|
+
tableReload().finally()
|
|
567
|
+
}
|
|
482
568
|
}
|
|
483
569
|
|
|
484
570
|
/**
|
|
485
|
-
*
|
|
571
|
+
* 获取表格请求数据
|
|
486
572
|
*/
|
|
487
|
-
|
|
573
|
+
function getTableRequestData(props, isSummary = undefined) {
|
|
488
574
|
|
|
489
575
|
// 解构数据
|
|
490
576
|
const {
|
|
491
577
|
// filter,
|
|
492
578
|
pagination: {
|
|
579
|
+
// 页码
|
|
493
580
|
page,
|
|
581
|
+
// 每页的数据条数
|
|
494
582
|
rowsPerPage,
|
|
583
|
+
// 排序字段
|
|
495
584
|
sortBy,
|
|
585
|
+
// 是否降序排列
|
|
496
586
|
descending,
|
|
497
587
|
}
|
|
498
588
|
} = props
|
|
499
589
|
|
|
500
|
-
// 设置加载中
|
|
501
|
-
tableLoading.value = true
|
|
502
|
-
|
|
503
590
|
// 请求数据
|
|
504
591
|
const data = {
|
|
505
592
|
// 页码
|
|
@@ -519,7 +606,7 @@ function create(params) {
|
|
|
519
606
|
}
|
|
520
607
|
|
|
521
608
|
// 合并参数
|
|
522
|
-
utils.forIn(Object.assign({}, rawQuery, tableRequestQuery), function(value, key) {
|
|
609
|
+
utils.forIn(Object.assign({}, rawQuery, tableRequestQuery, o.data), function(value, key) {
|
|
523
610
|
// 如果有值
|
|
524
611
|
if (utils.isRequired(value)) {
|
|
525
612
|
data[key] = value
|
|
@@ -529,15 +616,44 @@ function create(params) {
|
|
|
529
616
|
// 获取搜索值
|
|
530
617
|
const search = utils.$search.formatValue(rawSearchOptions, tableSearchValue.value)
|
|
531
618
|
if (utils.isValidArray(search)) {
|
|
532
|
-
data.
|
|
619
|
+
data.n_search = _.has(data, 'n_search') ? _.concat(data.n_search, search) : search
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (_.isNil(isSummary)) {
|
|
623
|
+
isSummary = isRequestSummary
|
|
533
624
|
}
|
|
534
625
|
|
|
535
626
|
// 如果请求表格合计
|
|
536
|
-
if (
|
|
627
|
+
if (isSummary) {
|
|
537
628
|
data.summary = 1
|
|
538
629
|
}
|
|
539
630
|
|
|
540
|
-
|
|
631
|
+
return data
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* 请求数据
|
|
636
|
+
*/
|
|
637
|
+
async function tableRequest(props) {
|
|
638
|
+
|
|
639
|
+
// 解构数据
|
|
640
|
+
const {
|
|
641
|
+
// filter,
|
|
642
|
+
pagination: {
|
|
643
|
+
// 页码
|
|
644
|
+
page,
|
|
645
|
+
// 每页的数据条数
|
|
646
|
+
rowsPerPage,
|
|
647
|
+
// 排序字段
|
|
648
|
+
sortBy,
|
|
649
|
+
// 是否降序排列
|
|
650
|
+
descending,
|
|
651
|
+
}
|
|
652
|
+
} = props
|
|
653
|
+
|
|
654
|
+
// 获取表格请求数据
|
|
655
|
+
const data = getTableRequestData(props, isRequestSummary)
|
|
656
|
+
|
|
541
657
|
let result
|
|
542
658
|
|
|
543
659
|
// 如果有自定义请求方法
|
|
@@ -545,7 +661,6 @@ function create(params) {
|
|
|
545
661
|
result = await utils.runAsync(o.request)({
|
|
546
662
|
data,
|
|
547
663
|
props,
|
|
548
|
-
tableRef,
|
|
549
664
|
rows: tableRows,
|
|
550
665
|
selected: tableSelected,
|
|
551
666
|
})
|
|
@@ -553,8 +668,8 @@ function create(params) {
|
|
|
553
668
|
// 否则请求服务器
|
|
554
669
|
} else {
|
|
555
670
|
const opts = Object.assign({
|
|
556
|
-
//
|
|
557
|
-
url: $route.
|
|
671
|
+
// 请求数据
|
|
672
|
+
url: $route.path,
|
|
558
673
|
// 请求数据
|
|
559
674
|
data,
|
|
560
675
|
// ~~~~~~ 先开启防抖, 如果后期遇到表格加载不出来的情况, 再关闭防抖
|
|
@@ -562,14 +677,6 @@ function create(params) {
|
|
|
562
677
|
// debounce: false,
|
|
563
678
|
}, o.httpSettings)
|
|
564
679
|
|
|
565
|
-
// 如果在对话框内部
|
|
566
|
-
if (inDialog) {
|
|
567
|
-
opts.headers = {
|
|
568
|
-
// 添加头部查看请求
|
|
569
|
-
Rview: 1,
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
680
|
result = await utils.http(opts)
|
|
574
681
|
}
|
|
575
682
|
|
|
@@ -607,7 +714,6 @@ function create(params) {
|
|
|
607
714
|
utils.forEach(rows, function(row) {
|
|
608
715
|
o.formatRow({
|
|
609
716
|
row,
|
|
610
|
-
tableRef,
|
|
611
717
|
rows: tableRows,
|
|
612
718
|
selected: tableSelected,
|
|
613
719
|
})
|
|
@@ -628,33 +734,37 @@ function create(params) {
|
|
|
628
734
|
/**
|
|
629
735
|
* 单击表格行
|
|
630
736
|
*/
|
|
631
|
-
function tableRowClick(e, row
|
|
737
|
+
function tableRowClick(e, row) {
|
|
738
|
+
|
|
632
739
|
// 如果选择类型为无
|
|
633
740
|
if (o.selection === 'none') {
|
|
634
741
|
// 则无任何操作
|
|
635
742
|
return
|
|
636
743
|
}
|
|
637
744
|
|
|
638
|
-
|
|
639
|
-
|
|
745
|
+
// 如果选择类型为单选
|
|
746
|
+
if (o.selection === 'single') {
|
|
747
|
+
tableSelected.value = [ row ]
|
|
748
|
+
|
|
749
|
+
// 否则为多选
|
|
750
|
+
} else {
|
|
640
751
|
|
|
641
|
-
|
|
642
|
-
|
|
752
|
+
const opt = {}
|
|
753
|
+
opt[o.rowKey] = row[o.rowKey]
|
|
643
754
|
|
|
644
|
-
|
|
645
|
-
|
|
755
|
+
// 获取当前数据索引
|
|
756
|
+
const itemIndex = _.findIndex(tableSelected.value, opt)
|
|
646
757
|
|
|
647
|
-
//
|
|
648
|
-
if (
|
|
649
|
-
|
|
650
|
-
// 否则为多选
|
|
651
|
-
} else {
|
|
758
|
+
// 如果不存在
|
|
759
|
+
if (itemIndex === -1) {
|
|
760
|
+
// 则添加
|
|
652
761
|
tableSelected.value.push(row)
|
|
653
|
-
}
|
|
654
762
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
763
|
+
// 否则
|
|
764
|
+
} else {
|
|
765
|
+
// 删除
|
|
766
|
+
tableSelected.value.splice(itemIndex, 1)
|
|
767
|
+
}
|
|
658
768
|
}
|
|
659
769
|
}
|
|
660
770
|
|
|
@@ -669,16 +779,13 @@ function create(params) {
|
|
|
669
779
|
return
|
|
670
780
|
}
|
|
671
781
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
// 有双击的权限按钮
|
|
680
|
-
if (tableDbClickPowerBtn && tableDbClickPowerBtn.value) {
|
|
681
|
-
tableToolbarRef.value?.onClick(tableDbClickPowerBtn.value, [ row ])
|
|
782
|
+
if (
|
|
783
|
+
// 有权限
|
|
784
|
+
hasPowr
|
|
785
|
+
// 有双击的权限按钮
|
|
786
|
+
&& tableDbClickPowerBtn.value
|
|
787
|
+
) {
|
|
788
|
+
$power.powerBtnClick(tableDbClickPowerBtn.value, [ row ])
|
|
682
789
|
}
|
|
683
790
|
}
|
|
684
791
|
|
|
@@ -689,6 +796,13 @@ function create(params) {
|
|
|
689
796
|
tableSearchOptions.value = await utils.$search.getOptions(rawSearchOptions, format)
|
|
690
797
|
}
|
|
691
798
|
|
|
799
|
+
/**
|
|
800
|
+
* 是否有表格搜索值
|
|
801
|
+
*/
|
|
802
|
+
function hasTableSearchValue() {
|
|
803
|
+
return !! utils.$search.formatValue(rawSearchOptions, tableSearchValue.value).length
|
|
804
|
+
}
|
|
805
|
+
|
|
692
806
|
// 如果开启搜索
|
|
693
807
|
if (o.search) {
|
|
694
808
|
// 设置表格搜索参数
|
|
@@ -699,10 +813,17 @@ function create(params) {
|
|
|
699
813
|
// ==========【返回】=================================================================================================
|
|
700
814
|
|
|
701
815
|
const resTable = {
|
|
702
|
-
//
|
|
703
|
-
|
|
704
|
-
//
|
|
705
|
-
|
|
816
|
+
// 当前路由全路径
|
|
817
|
+
routeFullPath: $route.fullPath,
|
|
818
|
+
// 当前路由路径
|
|
819
|
+
routePath: $route.path,
|
|
820
|
+
// 当前路由参数
|
|
821
|
+
routeQuery: $route.query,
|
|
822
|
+
// 获取当前路由
|
|
823
|
+
getRoute() {
|
|
824
|
+
return $route
|
|
825
|
+
},
|
|
826
|
+
|
|
706
827
|
// 表格加载状态
|
|
707
828
|
tableLoading,
|
|
708
829
|
// 表格 id key
|
|
@@ -739,25 +860,36 @@ function create(params) {
|
|
|
739
860
|
// 表格搜索参数
|
|
740
861
|
tableSearchOptions,
|
|
741
862
|
|
|
742
|
-
//
|
|
743
|
-
|
|
863
|
+
// 表格是否已加载
|
|
864
|
+
isTableLoaded,
|
|
865
|
+
// 表格加载(只加载一次)
|
|
866
|
+
tableLoad,
|
|
744
867
|
// 表格重新加载
|
|
745
868
|
tableReload,
|
|
869
|
+
// 表格刷新
|
|
870
|
+
tableRefresh,
|
|
871
|
+
// 表格搜索重置
|
|
872
|
+
tableSearchReset,
|
|
873
|
+
// 获取表格请求数据
|
|
874
|
+
getTableRequestData,
|
|
746
875
|
// 表格请求数据
|
|
747
876
|
tableRequest,
|
|
748
877
|
// 表格单击表格行
|
|
749
878
|
tableRowClick,
|
|
750
879
|
// 表格双击表格行
|
|
751
880
|
tableRowDblclick,
|
|
752
|
-
// 表格搜索重置
|
|
753
|
-
tableSearchReset,
|
|
754
881
|
// 设置表格搜索参数
|
|
755
882
|
setTableSearchOptions,
|
|
883
|
+
|
|
884
|
+
// 是否有表格搜索值
|
|
885
|
+
hasTableSearchValue,
|
|
756
886
|
}
|
|
757
887
|
|
|
758
|
-
|
|
759
|
-
_data
|
|
760
|
-
|
|
888
|
+
if (hasPowr) {
|
|
889
|
+
$power.update(function(data, _data) {
|
|
890
|
+
_data.$table = resTable
|
|
891
|
+
})
|
|
892
|
+
}
|
|
761
893
|
|
|
762
894
|
// 提供可以被后代组件注入的值
|
|
763
895
|
provide(NTableKey, resTable)
|