@netang/quasar 0.0.21 → 0.0.23

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/utils/$table.js CHANGED
@@ -1,7 +1,5 @@
1
- import { ref, computed, watch } from 'vue'
2
- import { useRoute } from 'vue-router'
1
+ import { ref, computed, provide, inject, watch } from 'vue'
3
2
  import { date, useQuasar } from 'quasar'
4
- import { parse } from 'qs'
5
3
 
6
4
  // 表格配置
7
5
  import tablesConfig from '@/tables'
@@ -11,84 +9,13 @@ import {
11
9
  setItemValue,
12
10
  } from './$search'
13
11
 
14
- /**
15
- * 获取 url 参数
16
- */
17
- function getUrlQuery(url) {
18
-
19
- const query = {}
20
-
21
- if (utils.indexOf(url, '?') > -1) {
22
-
23
- const arr = url.split('?')
24
-
25
- url = arr[0]
26
- const urlQuery = parse(arr[1])
27
- if (utils.isValidObject(urlQuery)) {
28
- utils.forIn(urlQuery, function (val, key) {
29
-
30
- key = utils.trimString(key)
31
- val = utils.trimString(val)
32
-
33
- if (key && val) {
34
- if (val.indexOf(',') > -1) {
35
- val = val.split(',')
36
- }
37
- query[key] = utils.numberDeep(val)
38
- }
39
- })
40
- }
41
- }
42
-
43
- return {
44
- url,
45
- query,
46
- }
47
- }
48
-
49
- /**
50
- * 对话框设置
51
- */
52
- function dialogSetting($dialog, o) {
53
-
54
- const {
55
- dialogProps,
56
- props,
57
- } = $dialog
58
-
59
- const {
60
- route
61
- } = dialogProps
62
-
63
- // 如果是路由组件地址
64
- if (utils.isValidString(route)) {
65
- o.url = utils.slash(route, 'start', false)
66
- }
67
-
68
- const {
69
- // 是否多选
70
- multiple,
71
- query,
72
- } = props
73
-
74
- // 是否多选
75
- o.selection = multiple ? 'multiple' : 'single'
76
-
77
- // 合并参数
78
- Object.assign(o.query, query)
79
- }
12
+ import { NPowerKey, NTableKey, NDialogKey } from './symbols'
80
13
 
81
14
  /**
82
15
  * 创建表格
83
16
  */
84
17
  function create(params) {
85
18
 
86
- // ==========【注入】=================================================================================================
87
-
88
- // 获取对话框注入
89
- const $dialog = utils.$dialog.inject()
90
- const inDialog = !! $dialog
91
-
92
19
  // ==========【数据】=================================================================================================
93
20
 
94
21
  // quasar 对象
@@ -96,20 +23,22 @@ function create(params) {
96
23
 
97
24
  // 每页显示行数选项
98
25
  // const rowsPerPageOptions = [30, 40, 50, 100, 200, 500, 1000]
99
- const rowsPerPageOptions = [4, 40, 50, 100, 200, 500, 1000]
26
+ const rowsPerPageOptions = [3, 40, 50, 100, 200, 500, 1000]
100
27
 
101
28
  // 获取参数
102
29
  const o = _.merge({
103
- // 请求地址
104
- url: '',
105
- // 参数
30
+ // 路由路径
31
+ path: '',
32
+ // 路由参数
106
33
  query: {},
107
- // 表格节点
108
- ref: null,
34
+ // 附加请求数据
35
+ data: {},
109
36
  // 表格行唯一键值
110
37
  rowKey: 'id',
111
38
  // 选择类型, 可选值 single multiple none
112
39
  selection: 'multiple',
40
+ // 已选数据
41
+ selected: [],
113
42
  // 表格加载状态
114
43
  loading: false,
115
44
  // 表格列数据(对象数组)
@@ -132,8 +61,6 @@ function create(params) {
132
61
  // 是否降序排列
133
62
  descending: true,
134
63
  },
135
- // 已选数据
136
- selected: [],
137
64
  // 每页显示行数选项
138
65
  rowsPerPageOptions,
139
66
  // 请求方法
@@ -148,42 +75,53 @@ function create(params) {
148
75
  search: true,
149
76
  // 是否开启合计
150
77
  summary: false,
151
- // 权限按钮列表
152
- roleBtnLists: null,
153
78
  // 从参数中获取搜索值
154
79
  searchFromQuery: true,
155
80
  // 显示宫格
156
81
  showGrid: true,
157
82
  // 显示可见列
158
83
  showVisibleColumns: true,
84
+ // 开启缓存
85
+ cache: true,
86
+ // 刷新后清空已选数据
87
+ refreshResetSelected: true,
159
88
  }, params)
160
89
 
161
- // 如果是对话框注入
162
- if (inDialog) {
163
- // 对话框设置
164
- dialogSetting($dialog, o)
165
- }
90
+ // 获取权限注入
91
+ const $power = _.has(params, '$power') ? params.$power : inject(NPowerKey)
92
+ const hasPowr = !! $power
166
93
 
167
- // 如果没有地址, 则使用当前路由地址
168
- if (! o.url) {
169
- // 当前路由
170
- o.url = useRoute().fullPath
171
- }
94
+ // 获取权限路由
95
+ const $route = utils.isValidString(o.path) ?
96
+ // 如果为自定义路由
97
+ utils.router.resolve({
98
+ path: o.path,
99
+ query: utils.isValidObject(o.query) ? o.query : {},
100
+ })
101
+ // 否则获取当前路由
102
+ : (hasPowr ? $power.getRoute() : utils.router.getRoute())
103
+
104
+ // 是否有权限按钮
105
+ const hasPowerBtns = hasPowr ? ! $power.powerBtns.value.length : false
172
106
 
173
- // 是否显示权限按钮
174
- const showRoleBtn = o.roleBtnLists !== null
107
+ // 表格已选数据
108
+ const tableSelected = hasPowr ? $power.tableSelected : ref([])
109
+ if (utils.isValidArray(o.selected)) {
110
+ tableSelected.value = o.selected
111
+ }
175
112
 
176
- // 宫格模式缓存名
177
- const gridCacheName = 'table_grid_' + o.url
113
+ // 是否开启缓存
114
+ const isCache = !! o.cache
178
115
 
179
- // 可见列缓存名
180
- const visibleColumnsCacheName = 'table_visible_columns_' + o.url
116
+ // 缓存名
117
+ const cacheName = $route.fullPath ? $route.fullPath : (utils.isValidString(o.cache) ? o.cache : '')
181
118
 
182
119
  // 表格列
183
120
  const tableColumns = []
184
121
 
185
- // 添加操作列
186
- if (showRoleBtn) {
122
+ // 如果有权限按钮
123
+ if (hasPowerBtns) {
124
+ // 添加操作列
187
125
  o.columns.push({
188
126
  label: '操作',
189
127
  name: 'settings',
@@ -207,6 +145,9 @@ function create(params) {
207
145
  item.align = 'left'
208
146
  }
209
147
 
148
+ // 是否隐藏
149
+ item.hide = _.get(item, 'hide') === true
150
+
210
151
  // 如果有显示项
211
152
  if (_.get(item, 'visible') !== false) {
212
153
  o.visibleColumns.push(item.field)
@@ -230,9 +171,9 @@ function create(params) {
230
171
  }
231
172
 
232
173
  // 如果有路由
233
- if (_.get(item, 'router')) {
174
+ if (_.get(item, 'route')) {
234
175
  // 如果该值在当前路由路径中, 则显示
235
- if (utils.indexOf(o.url, item.router) > -1) {
176
+ if (utils.indexOf($route.fullPath, item.route) > -1) {
236
177
  tableColumns.push(item)
237
178
  }
238
179
 
@@ -242,17 +183,11 @@ function create(params) {
242
183
  })
243
184
 
244
185
  // 获取可见列缓存
245
- const visibleColumnsCache = o.showVisibleColumns ? utils.storage.get(visibleColumnsCacheName) : []
186
+ const visibleColumnsCache = o.showVisibleColumns && isCache ? utils.storage.get('table_visible_columns_' + cacheName) : []
246
187
 
247
188
  // 表格可见列
248
189
  const tableVisibleColumns = ref(Array.isArray(visibleColumnsCache) ? visibleColumnsCache : _.uniq([...o.visibleColumns]))
249
190
 
250
- // 表格工具栏节点
251
- const tableToolbarRef = ref(null)
252
-
253
- // 表格节点
254
- const tableRef = ref(o.ref)
255
-
256
191
  // 表格加载状态
257
192
  const tableLoading = ref(o.loading)
258
193
 
@@ -260,13 +195,10 @@ function create(params) {
260
195
  const tableRows = ref(o.rows)
261
196
 
262
197
  // 表格翻页参数
263
- const tablePagination = ref(o.pagination)
264
-
265
- // 表格已选数据
266
- const tableSelected = ref(o.selected)
198
+ const tablePagination = ref($route.fullPath ? o.pagination : {})
267
199
 
268
200
  // 表格宫格
269
- const tableGrid = ref(o.showGrid ? utils.storage.get(gridCacheName) === true : false)
201
+ const tableGrid = ref(o.showGrid && isCache ? utils.storage.get('table_grid_' + cacheName) === true : false)
270
202
 
271
203
  // 表格传参
272
204
  const tableQuery = ref({})
@@ -280,18 +212,6 @@ function create(params) {
280
212
  // 表格合计
281
213
  const tableSummary = ref(null)
282
214
 
283
- // 获取 url 参数
284
- const resUrl = getUrlQuery(o.url)
285
- o.url = resUrl.url
286
-
287
- // 如果在表格内部
288
- if (inDialog) {
289
- // 提交表格已选数据给对话框
290
- $dialog.submit(function() {
291
- return tableSelected.value
292
- })
293
- }
294
-
295
215
  const {
296
216
  // 原始参数
297
217
  rawQuery,
@@ -302,27 +222,29 @@ function create(params) {
302
222
  // 首次表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
303
223
  firstTableSearchValue,
304
224
  // 表格搜索值(如果表格搜索参数中带了初始值, 则设置初始值)
305
- } = utils.$search.getRawData(tableColumns, Object.assign({}, o.query, resUrl.query), o.searchFromQuery)
225
+ } = utils.$search.getRawData(tableColumns, Object.assign({}, $route.query), o.searchFromQuery)
306
226
 
307
227
  // 表格搜索数据值
308
- const tableSearchValue = ref(firstTableSearchValue)
309
-
310
- watch(tableSearchValue, function (val) {
311
- console.log('tableSearchValue', val)
312
- })
228
+ const tableSearchValue = ref($route.fullPath ? firstTableSearchValue : [])
313
229
 
314
230
  // 表格搜索参数
315
231
  const tableSearchOptions = ref()
316
232
 
233
+ // 是否已加载
234
+ let _isTableLoaded = false
235
+
317
236
  // ==========【计算属性】=============================================================================================
318
237
 
319
- // 固定在右边的权限按钮列表
320
- const tableFixedRoleBtnLists = showRoleBtn ? computed(function () {
238
+ /**
239
+ * 固定在表格右边的权限按钮列表
240
+ */
241
+ const tableFixedPowerBtns = ! hasPowerBtns ? ref([]) : computed(function () {
321
242
 
322
243
  const lists = []
323
244
 
324
245
  // 先格式化权限按钮列表
325
- utils.forEach(utils.$role.formatRoleBtnLists(o.roleBtnLists.value), function(item) {
246
+ utils.forEach(utils.$power.formatBtns($power.powerBtns.value), function(item) {
247
+
326
248
  // 如果是固定按钮
327
249
  if (item.fixed) {
328
250
  lists.push(item)
@@ -330,25 +252,25 @@ function create(params) {
330
252
  })
331
253
 
332
254
  return lists
333
- }) : []
255
+ })
334
256
 
335
257
  /**
336
- * 表格双击权限按钮
258
+ * 获取权限按钮中可双击的按钮
337
259
  */
338
- const tableDbClickRoleBtn = o.roleBtnLists ? computed(function () {
260
+ const tableDbClickPowerBtn = ! hasPowerBtns ? ref(null) : computed(function () {
339
261
  if (
340
262
  // 非手机模式
341
263
  ! $q.platform.is.mobile
342
264
  // 有权限列表
343
- && utils.isValidArray(o.roleBtnLists.value)
265
+ && utils.isValidArray($power.powerBtns.value)
344
266
  ) {
345
- for (const item of o.roleBtnLists.value) {
267
+ for (const item of $power.powerBtns.value) {
346
268
  if (_.has(item, 'data.dbclick') === true) {
347
269
  return item
348
270
  }
349
271
  }
350
272
  }
351
- }) : null
273
+ })
352
274
 
353
275
  /**
354
276
  * 是否显示固定在右边的权限按钮列表
@@ -362,12 +284,12 @@ function create(params) {
362
284
  /**
363
285
  * 监听表格宫格模式
364
286
  */
365
- if (o.showGrid) {
287
+ if (o.showGrid && isCache) {
366
288
  watch(tableGrid, function(val) {
367
289
 
368
290
  // 设置宫格模式缓存(永久缓存)
369
291
  // #if ! IS_DEV
370
- utils.storage.set(gridCacheName, val, 0)
292
+ utils.storage.set('table_grid_' + cacheName, val, 0)
371
293
  // #endif
372
294
  })
373
295
  }
@@ -375,12 +297,12 @@ function create(params) {
375
297
  /**
376
298
  * 监听表格可见列
377
299
  */
378
- if (o.showVisibleColumns) {
300
+ if (o.showVisibleColumns && isCache) {
379
301
  watch(tableVisibleColumns, function(val) {
380
302
 
381
303
  // 设置可见列缓存(永久缓存)
382
304
  // #if ! IS_DEV
383
- utils.storage.set(visibleColumnsCacheName, val, 0)
305
+ utils.storage.set('table_visible_columns_' + cacheName, val, 0)
384
306
  // #endif
385
307
  })
386
308
  }
@@ -388,8 +310,8 @@ function create(params) {
388
310
  /**
389
311
  * 监听固定在右边的权限按钮列表
390
312
  */
391
- if (showRoleBtn) {
392
- watch(tableFixedRoleBtnLists, function (lists) {
313
+ if (hasPowerBtns) {
314
+ watch(tableFixedPowerBtns, function (lists) {
393
315
 
394
316
  const index = utils.indexOf(tableVisibleColumns.value, 'settings')
395
317
 
@@ -431,107 +353,240 @@ function create(params) {
431
353
  */
432
354
  watch(tableQuery, function (query) {
433
355
 
434
- // 如果禁止从参数中获取搜索值
435
- if (! o.searchFromQuery) {
436
- tableRequestQuery = query
437
- return
438
- }
439
-
440
- const newQuery = {}
441
-
442
356
  if (utils.isValidObject(query)) {
443
357
 
358
+ query = _.cloneDeep(query)
359
+
444
360
  // 搜索参数键值数组
445
361
  const searchQueryKey = []
446
362
 
447
- utils.forEach(rawSearchOptions, function (item, index) {
448
- // 如果传参在搜索参数中
449
- if (_.has(query, item.name)) {
450
- // 设置单个搜索值
451
- setItemValue(tableSearchValue.value[index], utils.isRequired(query[item.name]) ? query[item.name] : '')
452
- // 设置参数中搜索的 key
453
- searchQueryKey.push(item.name)
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
+ })
454
429
  }
455
- })
456
430
 
457
- if (! searchQueryKey.length) {
458
- tableRequestQuery = query
459
- return
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
+ })
460
442
  }
461
443
 
462
- utils.forIn(query, function(val, key) {
463
- if (searchQueryKey.indexOf(key) === -1) {
464
- newQuery[key] = val
465
- }
466
- })
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
467
452
  }
468
453
 
469
- tableRequestQuery = newQuery
454
+ tableRequestQuery = {}
455
+
456
+ }, {
457
+ // 深度监听
458
+ deep: true,
470
459
  })
471
460
 
472
461
  // ==========【方法】================================================================================================
473
462
 
474
463
  /**
475
- * 表格刷新
464
+ * 表格是否已加载
476
465
  */
477
- function tableRefresh() {
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
+ * 表格重新加载
487
+ */
488
+ async function tableReload() {
489
+
490
+ // 表格已加载
491
+ _isTableLoaded = true
492
+
493
+ if (! $route.fullPath) {
494
+ return
495
+ }
496
+
478
497
  // 请求表格合计
479
498
  if (o.summary) {
480
499
  isRequestSummary = true
481
500
  }
501
+
482
502
  // 请求表格数据
483
- tableRef.value.requestServerInteraction()
503
+ // $tableRef?.requestServerInteraction({
504
+ // pagination: o.pagination,
505
+ // })
506
+ await tableRequest({
507
+ pagination: o.pagination,
508
+ })
509
+
484
510
  // 清空表格已选数据
485
- tableSelected.value = []
511
+ if (o.refreshResetSelected) {
512
+ tableSelected.value = []
513
+ }
486
514
  }
487
515
 
488
516
  /**
489
- * 表格重新加载
517
+ * 表格刷新
490
518
  */
491
- function tableReload() {
519
+ async function tableRefresh() {
520
+
521
+ if (! $route.fullPath) {
522
+ return
523
+ }
524
+
492
525
  // 请求表格合计
493
526
  if (o.summary) {
494
527
  isRequestSummary = true
495
528
  }
529
+
496
530
  // 请求表格数据
497
- tableRef.value.requestServerInteraction({
498
- pagination: o.pagination,
531
+ // $tableRef.requestServerInteraction()
532
+ await tableRequest({
533
+ pagination: tablePagination.value,
499
534
  })
535
+
500
536
  // 清空表格已选数据
501
- tableSelected.value = []
537
+ if (o.refreshResetSelected) {
538
+ tableSelected.value = []
539
+ }
502
540
  }
503
541
 
504
542
  /**
505
543
  * 表格搜索重置
506
544
  */
507
- 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)
508
560
 
509
561
  // 还原表格搜索数据
510
- tableSearchValue.value = _.cloneDeep(rawTableSearchValue)
562
+ tableSearchValue.value = _.cloneDeep(newValue)
511
563
 
512
564
  // 表格重新加载
513
- tableReload()
565
+ if (reload) {
566
+ tableReload().finally()
567
+ }
514
568
  }
515
569
 
516
570
  /**
517
- * 请求数据
571
+ * 获取表格请求数据
518
572
  */
519
- async function tableRequest(props) {
573
+ function getTableRequestData(props, isSummary = undefined) {
520
574
 
521
575
  // 解构数据
522
576
  const {
523
577
  // filter,
524
578
  pagination: {
579
+ // 页码
525
580
  page,
581
+ // 每页的数据条数
526
582
  rowsPerPage,
583
+ // 排序字段
527
584
  sortBy,
585
+ // 是否降序排列
528
586
  descending,
529
587
  }
530
588
  } = props
531
589
 
532
- // 设置加载中
533
- tableLoading.value = true
534
-
535
590
  // 请求数据
536
591
  const data = {
537
592
  // 页码
@@ -551,7 +606,7 @@ function create(params) {
551
606
  }
552
607
 
553
608
  // 合并参数
554
- utils.forIn(Object.assign({}, rawQuery, tableRequestQuery), function(value, key) {
609
+ utils.forIn(Object.assign({}, rawQuery, tableRequestQuery, o.data), function(value, key) {
555
610
  // 如果有值
556
611
  if (utils.isRequired(value)) {
557
612
  data[key] = value
@@ -561,15 +616,44 @@ function create(params) {
561
616
  // 获取搜索值
562
617
  const search = utils.$search.formatValue(rawSearchOptions, tableSearchValue.value)
563
618
  if (utils.isValidArray(search)) {
564
- data.search = _.has(data, 'search') ? _.concat(data.search, search) : search
619
+ data.n_search = _.has(data, 'n_search') ? _.concat(data.n_search, search) : search
620
+ }
621
+
622
+ if (_.isNil(isSummary)) {
623
+ isSummary = isRequestSummary
565
624
  }
566
625
 
567
626
  // 如果请求表格合计
568
- if (isRequestSummary) {
627
+ if (isSummary) {
569
628
  data.summary = 1
570
629
  }
571
630
 
572
- // 请求数据
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
+
573
657
  let result
574
658
 
575
659
  // 如果有自定义请求方法
@@ -577,7 +661,6 @@ function create(params) {
577
661
  result = await utils.runAsync(o.request)({
578
662
  data,
579
663
  props,
580
- tableRef,
581
664
  rows: tableRows,
582
665
  selected: tableSelected,
583
666
  })
@@ -585,8 +668,8 @@ function create(params) {
585
668
  // 否则请求服务器
586
669
  } else {
587
670
  const opts = Object.assign({
588
- // 请求 - 登录
589
- url: o.url,
671
+ // 请求数据
672
+ url: $route.path,
590
673
  // 请求数据
591
674
  data,
592
675
  // ~~~~~~ 先开启防抖, 如果后期遇到表格加载不出来的情况, 再关闭防抖
@@ -594,14 +677,6 @@ function create(params) {
594
677
  // debounce: false,
595
678
  }, o.httpSettings)
596
679
 
597
- // 如果在对话框内部
598
- if (inDialog) {
599
- opts.headers = {
600
- // 添加头部查看请求
601
- Rview: 1,
602
- }
603
- }
604
-
605
680
  result = await utils.http(opts)
606
681
  }
607
682
 
@@ -639,7 +714,6 @@ function create(params) {
639
714
  utils.forEach(rows, function(row) {
640
715
  o.formatRow({
641
716
  row,
642
- tableRef,
643
717
  rows: tableRows,
644
718
  selected: tableSelected,
645
719
  })
@@ -660,33 +734,37 @@ function create(params) {
660
734
  /**
661
735
  * 单击表格行
662
736
  */
663
- function tableRowClick(e, row, index) {
737
+ function tableRowClick(e, row) {
738
+
664
739
  // 如果选择类型为无
665
740
  if (o.selection === 'none') {
666
741
  // 则无任何操作
667
742
  return
668
743
  }
669
744
 
670
- const opt = {}
671
- opt[o.rowKey] = row[o.rowKey]
745
+ // 如果选择类型为单选
746
+ if (o.selection === 'single') {
747
+ tableSelected.value = [ row ]
748
+
749
+ // 否则为多选
750
+ } else {
672
751
 
673
- // 获取当前数据索引
674
- const itemIndex = _.findIndex(tableSelected.value, opt)
752
+ const opt = {}
753
+ opt[o.rowKey] = row[o.rowKey]
675
754
 
676
- // 如果不存在, 则添加
677
- if (itemIndex === -1) {
755
+ // 获取当前数据索引
756
+ const itemIndex = _.findIndex(tableSelected.value, opt)
678
757
 
679
- // 如果选择类型为单选
680
- if (o.selection === 'single') {
681
- tableSelected.value = [row]
682
- // 否则为多选
683
- } else {
758
+ // 如果不存在
759
+ if (itemIndex === -1) {
760
+ // 则添加
684
761
  tableSelected.value.push(row)
685
- }
686
762
 
687
- // 否则删除
688
- } else {
689
- tableSelected.value.splice(itemIndex, 1)
763
+ // 否则
764
+ } else {
765
+ // 删除
766
+ tableSelected.value.splice(itemIndex, 1)
767
+ }
690
768
  }
691
769
  }
692
770
 
@@ -701,16 +779,13 @@ function create(params) {
701
779
  return
702
780
  }
703
781
 
704
- // 如果在对话框内部 && 如果是单选
705
- if (inDialog && o.selection === 'single') {
706
- tableSelected.value = [ row ]
707
- $dialog.confirm()
708
- return
709
- }
710
-
711
- // 有双击的权限按钮
712
- if (tableDbClickRoleBtn && tableDbClickRoleBtn.value) {
713
- tableToolbarRef.value?.onClick(tableDbClickRoleBtn.value, [ row ])
782
+ if (
783
+ // 有权限
784
+ hasPowr
785
+ // 有双击的权限按钮
786
+ && tableDbClickPowerBtn.value
787
+ ) {
788
+ $power.powerBtnClick(tableDbClickPowerBtn.value, [ row ])
714
789
  }
715
790
  }
716
791
 
@@ -721,6 +796,13 @@ function create(params) {
721
796
  tableSearchOptions.value = await utils.$search.getOptions(rawSearchOptions, format)
722
797
  }
723
798
 
799
+ /**
800
+ * 是否有表格搜索值
801
+ */
802
+ function hasTableSearchValue() {
803
+ return !! utils.$search.formatValue(rawSearchOptions, tableSearchValue.value).length
804
+ }
805
+
724
806
  // 如果开启搜索
725
807
  if (o.search) {
726
808
  // 设置表格搜索参数
@@ -730,11 +812,18 @@ function create(params) {
730
812
 
731
813
  // ==========【返回】=================================================================================================
732
814
 
733
- return {
734
- // 表格工具栏节点
735
- tableToolbarRef,
736
- // 表格节点
737
- tableRef,
815
+ const resTable = {
816
+ // 当前路由全路径
817
+ routeFullPath: $route.fullPath,
818
+ // 当前路由路径
819
+ routePath: $route.path,
820
+ // 当前路由参数
821
+ routeQuery: $route.query,
822
+ // 获取当前路由
823
+ getRoute() {
824
+ return $route
825
+ },
826
+
738
827
  // 表格加载状态
739
828
  tableLoading,
740
829
  // 表格 id key
@@ -754,7 +843,7 @@ function create(params) {
754
843
  // 表格已选数据
755
844
  tableSelected,
756
845
  // 固定在右边的权限按钮列表
757
- tableFixedRoleBtnLists,
846
+ tableFixedPowerBtns,
758
847
  // 是否显示固定在右边的权限按钮列表
759
848
  showTableFixed,
760
849
  // 表格图片标识
@@ -771,21 +860,41 @@ function create(params) {
771
860
  // 表格搜索参数
772
861
  tableSearchOptions,
773
862
 
774
- // 表格刷新
775
- tableRefresh,
863
+ // 表格是否已加载
864
+ isTableLoaded,
865
+ // 表格加载(只加载一次)
866
+ tableLoad,
776
867
  // 表格重新加载
777
868
  tableReload,
869
+ // 表格刷新
870
+ tableRefresh,
871
+ // 表格搜索重置
872
+ tableSearchReset,
873
+ // 获取表格请求数据
874
+ getTableRequestData,
778
875
  // 表格请求数据
779
876
  tableRequest,
780
877
  // 表格单击表格行
781
878
  tableRowClick,
782
879
  // 表格双击表格行
783
880
  tableRowDblclick,
784
- // 表格搜索重置
785
- tableSearchReset,
786
881
  // 设置表格搜索参数
787
882
  setTableSearchOptions,
883
+
884
+ // 是否有表格搜索值
885
+ hasTableSearchValue,
886
+ }
887
+
888
+ if (hasPowr) {
889
+ $power.update(function(data, _data) {
890
+ _data.$table = resTable
891
+ })
788
892
  }
893
+
894
+ // 提供可以被后代组件注入的值
895
+ provide(NTableKey, resTable)
896
+
897
+ return resTable
789
898
  }
790
899
 
791
900
  /**