@vxe-ui/plugin-menu 3.2.2 → 3.3.1

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/src/index.ts ADDED
@@ -0,0 +1,1474 @@
1
+ import XEUtils from 'xe-utils'
2
+
3
+ import type { VxeUIExport, VxeGlobalInterceptorHandles, VxeGlobalMenusHandles } from 'vxe-pc-ui'
4
+ import type { VxeTableConstructor, VxeTablePrivateMethods, VxeTableDefines, VxeColumnPropTypes, VxeTableExtendCellAreaDefines } from 'vxe-table'
5
+ import type { VxeUIPluginMenuOptions } from '../types'
6
+
7
+ let VxeUI: VxeUIExport
8
+ let handleCopy: ((content: string | number) => boolean) | undefined
9
+
10
+ const columnIndexOf = (cols: VxeTableDefines.ColumnInfo[], column: VxeTableDefines.ColumnInfo) => {
11
+ return XEUtils.findIndexOf(cols, item => item.id === column.id)
12
+ }
13
+
14
+ const rowIndexOf = ($table: VxeTableConstructor & VxeTablePrivateMethods, rows: any[], row: any) => {
15
+ return $table.findRowIndexOf(rows, row)
16
+ }
17
+
18
+ function handleFixedColumn (fixed: VxeColumnPropTypes.Fixed) {
19
+ return {
20
+ tableMenuMethod (params: VxeGlobalMenusHandles.TableMenuMethodParams) {
21
+ const { $table, column } = params
22
+ XEUtils.eachTree([column], (column) => {
23
+ column.fixed = fixed
24
+ })
25
+ $table.refreshColumn()
26
+ }
27
+ }
28
+ }
29
+
30
+ function getClipboardObj () {
31
+ const globalStore = VxeUI.globalStore
32
+ if (globalStore) {
33
+ return globalStore.clipboard || ''
34
+ }
35
+ // 兼容老版本
36
+ const globalConfig = (VxeUI as any).config
37
+ if (globalConfig && globalConfig.clipboard) {
38
+ return globalConfig.clipboard
39
+ }
40
+ return null
41
+ }
42
+
43
+ function setClipboardConfig (clipObj: {
44
+ text: string
45
+ html: string
46
+ }) {
47
+ const globalStore = VxeUI.globalStore
48
+ if (globalStore) {
49
+ globalStore.clipboard = clipObj
50
+ } else if ((VxeUI as any).config) {
51
+ // 兼容老版本
52
+ (VxeUI as any).config.clipboard = clipObj
53
+ }
54
+ }
55
+
56
+ let copyElem: HTMLTextAreaElement
57
+
58
+ function handleText (content: string | number) {
59
+ if (!copyElem) {
60
+ copyElem = document.createElement('textarea')
61
+ copyElem.id = '$XECopy'
62
+ const styles = copyElem.style
63
+ styles.width = '48px'
64
+ styles.height = '24px'
65
+ styles.position = 'fixed'
66
+ styles.zIndex = '0'
67
+ styles.left = '-500px'
68
+ styles.top = '-500px'
69
+ document.body.appendChild(copyElem)
70
+ }
71
+ copyElem.value = content === null || content === undefined ? '' : ('' + content)
72
+ }
73
+
74
+ function copyText (content: string | number): boolean {
75
+ let result = false
76
+ try {
77
+ handleText(content)
78
+ copyElem.select()
79
+ copyElem.setSelectionRange(0, copyElem.value.length)
80
+ result = document.execCommand('copy')
81
+ copyElem.blur()
82
+ } catch (e) {}
83
+ return result
84
+ }
85
+
86
+ function handleCopyOrCut (params: VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, isCut?: boolean) {
87
+ const { $event, $table, row, column } = params
88
+ if (row && column) {
89
+ const props = $table
90
+ const { mouseConfig } = props
91
+ const mouseOpts = $table.computeMouseOpts
92
+ let text = ''
93
+ if (mouseConfig && mouseOpts.area) {
94
+ if (isCut) {
95
+ $table.triggerCutCellAreaEvent($event)
96
+ } else {
97
+ $table.triggerCopyCellAreaEvent($event)
98
+ }
99
+ const clipboard = getClipboardObj()
100
+ text = clipboard ? clipboard.text : ''
101
+ } else {
102
+ // 操作内置剪贴板
103
+ text = XEUtils.toValueString(XEUtils.get(row, column.field))
104
+ setClipboardConfig({ text, html: '' })
105
+ }
106
+ // 开始复制操作
107
+ if (XEUtils.isFunction(handleCopy)) {
108
+ handleCopy(text)
109
+ } else {
110
+ copyText(text)
111
+ }
112
+ }
113
+ }
114
+
115
+ function createCommitHandle (code: 'initial' | 'query' | 'reload' | 'delete' | 'save') {
116
+ return function (params: VxeGlobalMenusHandles.TableMenuMethodParams) {
117
+ const { $grid } = params
118
+ if ($grid) {
119
+ $grid.commitProxy(code)
120
+ }
121
+ }
122
+ }
123
+
124
+ function checkCellOverlay (params: VxeGlobalInterceptorHandles.InterceptorShowMenuParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, cellAreas: VxeTableExtendCellAreaDefines.MouseCellArea[]) {
125
+ const { $table } = params
126
+ const { visibleData } = $table.getTableData()
127
+ const { visibleColumn } = $table.getTableColumn()
128
+ const indexMaps: { [key: string]: boolean } = {}
129
+ for (let aIndex = 0, areaSize = cellAreas.length; aIndex < areaSize; aIndex++) {
130
+ const areaItem = cellAreas[aIndex]
131
+ const { rows, cols } = areaItem
132
+ for (let rIndex = 0, rowSize = rows.length; rIndex < rowSize; rIndex++) {
133
+ const offsetRow = rows[rIndex]
134
+ const orIndex = rowIndexOf($table, visibleData, offsetRow)
135
+ for (let cIndex = 0, colSize = cols.length; cIndex < colSize; cIndex++) {
136
+ const offsetColumn = cols[cIndex]
137
+ const ocIndex = columnIndexOf(visibleColumn, offsetColumn)
138
+ const key = orIndex + ':' + ocIndex
139
+ if (indexMaps[key]) {
140
+ return false
141
+ }
142
+ indexMaps[key] = true
143
+ }
144
+ }
145
+ }
146
+ return true
147
+ }
148
+
149
+ function getBeenMerges (params: (VxeGlobalMenusHandles.TableMenuMethodParams | VxeGlobalInterceptorHandles.InterceptorShowMenuParams) & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
150
+ const { $table } = params
151
+ const tableProps = $table
152
+ const { mouseConfig } = tableProps
153
+ const mouseOpts = $table.computeMouseOpts
154
+ const { visibleData } = $table.getTableData()
155
+ const { visibleColumn } = $table.getTableColumn()
156
+ const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
157
+ const mergeList = $table.getMergeCells()
158
+ return mergeList.filter(({ row: mergeRowIndex, col: mergeColIndex, rowspan: mergeRowspan, colspan: mergeColspan }) => {
159
+ return cellAreas.some(areaItem => {
160
+ const { rows, cols } = areaItem
161
+ const startRowIndex = rowIndexOf($table, visibleData, rows[0])
162
+ const endRowIndex = rowIndexOf($table, visibleData, rows[rows.length - 1])
163
+ const startColIndex = columnIndexOf(visibleColumn, cols[0])
164
+ const endColIndex = columnIndexOf(visibleColumn, cols[cols.length - 1])
165
+ return mergeRowIndex >= startRowIndex && mergeRowIndex + mergeRowspan - 1 <= endRowIndex && mergeColIndex >= startColIndex && mergeColIndex + mergeColspan - 1 <= endColIndex
166
+ })
167
+ })
168
+ }
169
+
170
+ function handleClearMergeCells (params: VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
171
+ const { $table } = params
172
+ const beenMerges = getBeenMerges(params)
173
+ if (beenMerges.length) {
174
+ $table.removeMergeCells(beenMerges)
175
+ }
176
+ return beenMerges
177
+ }
178
+
179
+ function checkPrivilege (item: VxeTableDefines.MenuFirstOption | VxeTableDefines.MenuChildOption, params: VxeGlobalInterceptorHandles.InterceptorShowMenuParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
180
+ const { code } = item
181
+ const { $table, $grid, row, column, type } = params
182
+ const tableProps = $table
183
+ const { editConfig, mouseConfig } = tableProps
184
+ switch (code) {
185
+ case 'CLEAR_ALL_SORT': {
186
+ const sortList = $table.getSortColumns()
187
+ item.disabled = !sortList.length
188
+ break
189
+ }
190
+ case 'CLEAR_ALL_FILTER': {
191
+ const filterList = $table.getCheckedFilters()
192
+ item.disabled = !filterList.length
193
+ break
194
+ }
195
+ case 'CLEAR_ALL_MERGE': {
196
+ const mergeCells = $table.getMergeCells()
197
+ const mergeFooterItems = $table.getMergeFooterItems()
198
+ item.disabled = !mergeCells.length && !mergeFooterItems.length
199
+ break
200
+ }
201
+ case 'CLEAR_MERGE_CELL': {
202
+ const beenMerges = getBeenMerges(params)
203
+ item.disabled = !beenMerges.length
204
+ break
205
+ }
206
+ case 'COPY_TITLE': {
207
+ item.disabled = !column || type !== 'header'
208
+ break
209
+ }
210
+ case 'SELECT_ALL_AREA': {
211
+ const { visibleData } = $table.getTableData()
212
+ const { visibleColumn } = $table.getTableColumn()
213
+ item.disabled = !visibleData.length || !visibleColumn.length
214
+ break
215
+ }
216
+ case 'SELECT_AREA_TO_LEFT':
217
+ case 'SELECT_AREA_TO_RIGHT':
218
+ case 'SELECT_AREA_TO_TOP':
219
+ case 'SELECT_AREA_TO_BOTTON': {
220
+ item.disabled = !column || !row
221
+ break
222
+ }
223
+ case 'DELETE_CHECKBOX_ROW': {
224
+ const selectRecords = $table.getCheckboxRecords()
225
+ item.disabled = !selectRecords.length
226
+ break
227
+ }
228
+ case 'EDIT_CELL':
229
+ case 'CLEAR_CELL':
230
+ case 'CLEAR_ROW':
231
+ case 'COPY_CELL':
232
+ case 'CUT_CELL':
233
+ case 'PASTE_CELL':
234
+ case 'MERGE_OR_CLEAR':
235
+ case 'MERGE_CELL':
236
+ case 'REVERT_CELL':
237
+ case 'REVERT_ROW':
238
+ case 'DELETE_ROW':
239
+ case 'DELETE_AREA_ROW':
240
+ case 'CLEAR_SORT':
241
+ case 'SORT_ASC':
242
+ case 'SORT_DESC':
243
+ case 'CLEAR_FILTER':
244
+ case 'FILTER_CELL':
245
+ case 'EXPORT_ROW':
246
+ case 'OPEN_FIND':
247
+ case 'OPEN_REPLACE':
248
+ case 'HIDDEN_COLUMN':
249
+ case 'FIXED_LEFT_COLUMN':
250
+ case 'FIXED_RIGHT_COLUMN':
251
+ case 'CLEAR_FIXED_COLUMN': {
252
+ item.disabled = !column
253
+ if (column) {
254
+ const mouseOpts = $table.computeMouseOpts
255
+ const isChildCol = !!column.parentId
256
+ switch (code) {
257
+ case 'CLEAR_SORT': {
258
+ item.disabled = !column.sortable || !column.order
259
+ break
260
+ }
261
+ case 'SORT_ASC':
262
+ case 'SORT_DESC':
263
+ item.disabled = !column.sortable
264
+ break
265
+ case 'FILTER_CELL':
266
+ case 'CLEAR_FILTER':
267
+ item.disabled = !column.filters || !column.filters.length
268
+ if (!item.disabled) {
269
+ switch (code) {
270
+ case 'CLEAR_FILTER':
271
+ item.disabled = !column.filters.some((option) => option.checked)
272
+ break
273
+ }
274
+ }
275
+ break
276
+ case 'REVERT_CELL': {
277
+ item.disabled = !row || !column.field || !$table.isUpdateByRow(row, column.field)
278
+ break
279
+ }
280
+ case 'REVERT_ROW': {
281
+ item.disabled = !row || !column.field || !$table.isUpdateByRow(row)
282
+ break
283
+ }
284
+ case 'OPEN_FIND':
285
+ case 'OPEN_REPLACE': {
286
+ item.disabled = !(mouseConfig && mouseOpts.area)
287
+ break
288
+ }
289
+ case 'EDIT_CELL': {
290
+ item.disabled = !editConfig || !column.editRender
291
+ break
292
+ }
293
+ case 'COPY_CELL':
294
+ case 'CUT_CELL':
295
+ case 'PASTE_CELL': {
296
+ const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
297
+ item.disabled = cellAreas.length > 1
298
+ if (!item.disabled) {
299
+ switch (code) {
300
+ case 'PASTE_CELL': {
301
+ const clipboard = getClipboardObj()
302
+ item.disabled = !clipboard || !clipboard.text
303
+ break
304
+ }
305
+ }
306
+ }
307
+ break
308
+ }
309
+ case 'MERGE_OR_CLEAR':
310
+ case 'MERGE_CELL': {
311
+ const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
312
+ item.disabled = !cellAreas.length || (cellAreas.length === 1 && cellAreas[0].rows.length === 1 && cellAreas[0].cols.length === 1) || !checkCellOverlay(params, cellAreas)
313
+ break
314
+ }
315
+ case 'FIXED_LEFT_COLUMN':
316
+ item.disabled = isChildCol || column.fixed === 'left'
317
+ break
318
+ case 'FIXED_RIGHT_COLUMN':
319
+ item.disabled = isChildCol || column.fixed === 'right'
320
+ break
321
+ case 'CLEAR_FIXED_COLUMN':
322
+ item.disabled = isChildCol || !column.fixed
323
+ break
324
+ }
325
+ }
326
+ break
327
+ }
328
+ case 'COMMIT_PROXY_INITIAL':
329
+ case 'COMMIT_PROXY_QUERY':
330
+ case 'COMMIT_PROXY_RELOAD':
331
+ case 'COMMIT_PROXY_DELETE':
332
+ case 'COMMIT_PROXY_SAVE': {
333
+ item.disabled = !$grid
334
+ break
335
+ }
336
+ }
337
+ }
338
+
339
+ function handlePrivilegeEvent (params: VxeGlobalInterceptorHandles.InterceptorShowMenuParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
340
+ params.options.forEach((list) => {
341
+ list.forEach((item) => {
342
+ checkPrivilege(item, params)
343
+ if (item.children) {
344
+ item.children.forEach((child) => {
345
+ checkPrivilege(child, params)
346
+ })
347
+ }
348
+ })
349
+ })
350
+ return true
351
+ }
352
+
353
+ function selectMultipleRows () {
354
+ return new Promise<{
355
+ size: number
356
+ }>(resolve => {
357
+ if (VxeUI.modal) {
358
+ const VxeUINumberInputComponent = VxeUI.getComponent('VxeNumberInput')
359
+ if (VxeUINumberInputComponent) {
360
+ let rowSize = 1
361
+ VxeUI.modal.alert({
362
+ title: '请输入行数',
363
+ width: 220,
364
+ maskClosable: false,
365
+ slots: {
366
+ default (params, h) {
367
+ return h(VxeUINumberInputComponent, {
368
+ props: {
369
+ value: rowSize,
370
+ min: 1,
371
+ max: 100,
372
+ type: 'integer',
373
+ align: 'center',
374
+ controlConfig: {
375
+ layout: 'default'
376
+ }
377
+ },
378
+ style: {
379
+ width: '100%'
380
+ },
381
+ on: {
382
+ modelValue (value: any) {
383
+ rowSize = value
384
+ }
385
+ }
386
+ })
387
+ }
388
+ }
389
+ }).then((type) => {
390
+ if (type === 'confirm') {
391
+ resolve({
392
+ size: rowSize || 1
393
+ })
394
+ } else {
395
+ resolve({
396
+ size: 0
397
+ })
398
+ }
399
+ })
400
+ } else {
401
+ console.error(VxeUI.getI18n('vxe.error.reqComp', ['vxe-number-input']))
402
+ resolve({
403
+ size: 0
404
+ })
405
+ }
406
+ } else {
407
+ resolve({
408
+ size: 0
409
+ })
410
+ }
411
+ })
412
+ }
413
+
414
+ /**
415
+ * 浏览器-刷新页面(对应按键F5)
416
+ */
417
+ function systemPageRefresh () {
418
+ location.reload()
419
+ }
420
+
421
+ /**
422
+ * 浏览器-前进
423
+ */
424
+ function systemPageforward () {
425
+ history.forward()
426
+ }
427
+
428
+ /**
429
+ * 浏览器-后退
430
+ */
431
+ function systemPageBack () {
432
+ history.back()
433
+ }
434
+
435
+ function pluginConfig (options?: VxeUIPluginMenuOptions) {
436
+ if (options && options.copy) {
437
+ handleCopy = options.copy
438
+ }
439
+ }
440
+
441
+ export const VxeUIPluginMenu = {
442
+ setConfig: pluginConfig,
443
+ install (core: VxeUIExport, options?: VxeUIPluginMenuOptions) {
444
+ VxeUI = core
445
+
446
+ // 检查版本
447
+ if (VxeUI.checkVersion) {
448
+ const pVersion = 3
449
+ const sVersion = 13
450
+ if (!VxeUI.checkVersion(VxeUI.tableVersion, pVersion, sVersion)) {
451
+ console.error(`[VUE_APP_VXE_PLUGIN_VERSION] ${VxeUI.getI18n('vxe.error.errorVersion', [`vxe-table@${VxeUI.tableVersion || '?'}`, `vxe-table v${pVersion}.${sVersion}+`])}`)
452
+ }
453
+ } else {
454
+ if (!/^(3)\./.test(VxeUI.uiVersion || VxeUI.tableVersion)) {
455
+ console.error('[VUE_APP_VXE_PLUGIN_VERSION] Requires VUE_APP_VXE_TABLE_VERSION+ version. VUE_APP_VXE_PLUGIN_DESCRIBE')
456
+ }
457
+ }
458
+
459
+ pluginConfig(options)
460
+
461
+ VxeUI.menus.mixin({
462
+ /**
463
+ * 浏览器-刷新页面(对应按键F5)
464
+ */
465
+ SYSTEM_PAGE_REFRESH: {
466
+ tableMenuMethod: systemPageRefresh,
467
+ treeMenuMethod: systemPageRefresh,
468
+ calendarMenuMethod: systemPageRefresh,
469
+ menuMenuMethod: systemPageRefresh,
470
+ formDesignMenuMethod: systemPageRefresh
471
+ },
472
+ /**
473
+ * 浏览器-前进
474
+ */
475
+ SYSTEM_PAGE_FORWARD: {
476
+ tableMenuMethod: systemPageforward,
477
+ treeMenuMethod: systemPageforward,
478
+ calendarMenuMethod: systemPageforward,
479
+ menuMenuMethod: systemPageforward,
480
+ formDesignMenuMethod: systemPageforward
481
+ },
482
+ /**
483
+ * 浏览器-后退
484
+ */
485
+ SYSTEM_PAGE_BACK: {
486
+ tableMenuMethod: systemPageBack,
487
+ treeMenuMethod: systemPageBack,
488
+ calendarMenuMethod: systemPageBack,
489
+ menuMenuMethod: systemPageBack,
490
+ formDesignMenuMethod: systemPageBack
491
+ },
492
+ /**
493
+ * 清除单元格数据的值;如果启用 mouse-config.area 功能,则清除区域范围内的单元格数据
494
+ */
495
+ CLEAR_CELL: {
496
+ tableMenuMethod (params) {
497
+ const { $table, row, column } = params
498
+ if (row && column) {
499
+ const tableProps = $table
500
+ const { mouseConfig } = tableProps
501
+ const mouseOpts = $table.computeMouseOpts
502
+ if (mouseConfig && mouseOpts.area) {
503
+ const cellAreas = $table.getCellAreas()
504
+ if (cellAreas && cellAreas.length) {
505
+ cellAreas.forEach(areaItem => {
506
+ const { rows, cols } = areaItem
507
+ cols.forEach(column => {
508
+ rows.forEach(row => {
509
+ $table.clearData(row, column.field)
510
+ })
511
+ })
512
+ })
513
+ }
514
+ } else {
515
+ $table.clearData(row, column.field)
516
+ }
517
+ }
518
+ }
519
+ },
520
+ /**
521
+ * 清除行数据的值
522
+ */
523
+ CLEAR_ROW: {
524
+ tableMenuMethod (params) {
525
+ const { $table, row } = params
526
+ if (row) {
527
+ $table.clearData(row)
528
+ }
529
+ }
530
+ },
531
+ /**
532
+ * 清除复选框选中行数据的值
533
+ */
534
+ CLEAR_CHECKBOX_ROW: {
535
+ tableMenuMethod (params) {
536
+ const { $table } = params
537
+ $table.clearData($table.getCheckboxRecords())
538
+ }
539
+ },
540
+ /**
541
+ * 清除区域选择范围内数据的值
542
+ */
543
+ CLEAR_AREA_ROW: {
544
+ tableMenuMethod (params) {
545
+ const { $table, row, column } = params
546
+ const tableProps = $table
547
+ const { mouseConfig } = tableProps
548
+ const mouseOpts = $table.computeMouseOpts
549
+ if (mouseConfig && mouseOpts.area) {
550
+ const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
551
+ cellAreas.forEach(areaItem => {
552
+ const { rows, cols } = areaItem
553
+ rows.forEach(row => {
554
+ cols.forEach(column => {
555
+ $table.clearData(row)
556
+ })
557
+ })
558
+ })
559
+ } else {
560
+ if (row && column) {
561
+ $table.clearData(row)
562
+ }
563
+ }
564
+ }
565
+ },
566
+ /**
567
+ * 清除所有数据的值
568
+ */
569
+ CLEAR_ALL: {
570
+ tableMenuMethod (params) {
571
+ const { $table } = params
572
+ $table.clearData()
573
+ }
574
+ },
575
+ /**
576
+ * 选取所有区域
577
+ */
578
+ SELECT_ALL_AREA: {
579
+ tableMenuMethod (params) {
580
+ const { $table } = params
581
+ const tableProps = $table
582
+ const { mouseConfig } = tableProps
583
+ const mouseOpts = $table.computeMouseOpts
584
+ if (mouseConfig && mouseOpts.area) {
585
+ const { visibleData } = $table.getTableData()
586
+ const { visibleColumn } = $table.getTableColumn()
587
+ $table.setCellAreas([{
588
+ startRow: XEUtils.first(visibleData),
589
+ endRow: XEUtils.last(visibleData),
590
+ startColumn: XEUtils.first(visibleColumn),
591
+ endColumn: XEUtils.last(visibleColumn)
592
+ }])
593
+ }
594
+ }
595
+ },
596
+ /**
597
+ * 以当前单元格为起点,范围选取到左侧单元格
598
+ */
599
+ SELECT_AREA_TO_LEFT: {
600
+ tableMenuMethod (params) {
601
+ const { $table, row, column } = params
602
+ const tableProps = $table
603
+ const { mouseConfig } = tableProps
604
+ const mouseOpts = $table.computeMouseOpts
605
+ if (mouseConfig && mouseOpts.area) {
606
+ const { visibleColumn } = $table.getTableColumn()
607
+ const cellAreas = $table.getCellAreas()
608
+ if (cellAreas.length === 1) {
609
+ const fitstArea = cellAreas[0]
610
+ $table.setCellAreas([{
611
+ startRow: XEUtils.first(fitstArea.rows),
612
+ endRow: XEUtils.last(fitstArea.rows),
613
+ startColumn: XEUtils.first(visibleColumn),
614
+ endColumn: XEUtils.last(fitstArea.cols)
615
+ }], { column, row })
616
+ } else {
617
+ $table.setCellAreas([{
618
+ startRow: row,
619
+ endRow: row,
620
+ startColumn: XEUtils.first(visibleColumn),
621
+ endColumn: column
622
+ }], { column, row })
623
+ }
624
+ }
625
+ }
626
+ },
627
+ /**
628
+ * 以当前单元格为起点,范围选取到右侧单元格
629
+ */
630
+ SELECT_AREA_TO_RIGHT: {
631
+ tableMenuMethod (params) {
632
+ const { $table, row, column } = params
633
+ const tableProps = $table
634
+ const { mouseConfig } = tableProps
635
+ const mouseOpts = $table.computeMouseOpts
636
+ if (mouseConfig && mouseOpts.area) {
637
+ const { visibleColumn } = $table.getTableColumn()
638
+ const cellAreas = $table.getCellAreas()
639
+ if (cellAreas.length === 1) {
640
+ const fitstArea = cellAreas[0]
641
+ $table.setCellAreas([{
642
+ startRow: XEUtils.first(fitstArea.rows),
643
+ endRow: XEUtils.last(fitstArea.rows),
644
+ startColumn: XEUtils.first(fitstArea.cols),
645
+ endColumn: XEUtils.last(visibleColumn)
646
+ }], { column, row })
647
+ } else {
648
+ $table.setCellAreas([{
649
+ startRow: row,
650
+ endRow: row,
651
+ startColumn: column,
652
+ endColumn: XEUtils.last(visibleColumn)
653
+ }], { column, row })
654
+ }
655
+ }
656
+ }
657
+ },
658
+ /**
659
+ * 以当前单元格为起点,范围选取到顶部单元格
660
+ */
661
+ SELECT_AREA_TO_TOP: {
662
+ tableMenuMethod (params) {
663
+ const { $table, row, column } = params
664
+ const tableProps = $table
665
+ const { mouseConfig } = tableProps
666
+ const mouseOpts = $table.computeMouseOpts
667
+ if (mouseConfig && mouseOpts.area) {
668
+ const { visibleData } = $table.getTableData()
669
+ const cellAreas = $table.getCellAreas()
670
+ if (cellAreas.length === 1) {
671
+ const fitstArea = cellAreas[0]
672
+ $table.setCellAreas([{
673
+ startRow: XEUtils.first(visibleData),
674
+ endRow: XEUtils.last(fitstArea.rows),
675
+ startColumn: XEUtils.first(fitstArea.cols),
676
+ endColumn: XEUtils.last(fitstArea.cols)
677
+ }], { column, row })
678
+ } else {
679
+ $table.setCellAreas([{
680
+ startRow: XEUtils.first(visibleData),
681
+ endRow: row,
682
+ startColumn: column,
683
+ endColumn: column
684
+ }], { column, row })
685
+ }
686
+ }
687
+ }
688
+ },
689
+ /**
690
+ * 以当前单元格为起点,范围选取到底部单元格
691
+ */
692
+ SELECT_AREA_TO_BOTTON: {
693
+ tableMenuMethod (params) {
694
+ const { $table, row, column } = params
695
+ const tableProps = $table
696
+ const { mouseConfig } = tableProps
697
+ const mouseOpts = $table.computeMouseOpts
698
+ if (mouseConfig && mouseOpts.area) {
699
+ const { visibleData } = $table.getTableData()
700
+ const cellAreas = $table.getCellAreas()
701
+ if (cellAreas.length === 1) {
702
+ const fitstArea = cellAreas[0]
703
+ $table.setCellAreas([{
704
+ startRow: XEUtils.first(fitstArea.rows),
705
+ endRow: XEUtils.last(visibleData),
706
+ startColumn: XEUtils.first(fitstArea.cols),
707
+ endColumn: XEUtils.last(fitstArea.cols)
708
+ }], { column, row })
709
+ } else {
710
+ $table.setCellAreas([{
711
+ startRow: row,
712
+ endRow: XEUtils.last(visibleData),
713
+ startColumn: column,
714
+ endColumn: column
715
+ }], { column, row })
716
+ }
717
+ }
718
+ }
719
+ },
720
+ /**
721
+ * 还原单元格数据的值;如果启用 mouse-config.area 功能,则还原区域范围内的单元格数据
722
+ */
723
+ REVERT_CELL: {
724
+ tableMenuMethod (params) {
725
+ const { $table, row, column } = params
726
+ if (row && column) {
727
+ const tableProps = $table
728
+ const { mouseConfig } = tableProps
729
+ const mouseOpts = $table.computeMouseOpts
730
+ if (mouseConfig && mouseOpts.area) {
731
+ const cellAreas = $table.getCellAreas()
732
+ if (cellAreas && cellAreas.length) {
733
+ cellAreas.forEach(areaItem => {
734
+ const { rows, cols } = areaItem
735
+ cols.forEach(column => {
736
+ rows.forEach(row => {
737
+ $table.revertData(row, column.field)
738
+ })
739
+ })
740
+ })
741
+ }
742
+ } else {
743
+ $table.revertData(row, column.field)
744
+ }
745
+ }
746
+ }
747
+ },
748
+ /**
749
+ * 还原行数据的值
750
+ */
751
+ REVERT_ROW: {
752
+ tableMenuMethod (params) {
753
+ const { $table, row } = params
754
+ if (row) {
755
+ $table.revertData(row)
756
+ }
757
+ }
758
+ },
759
+ /**
760
+ * 还原复选框选中行数据的值
761
+ */
762
+ REVERT_CHECKBOX_ROW: {
763
+ tableMenuMethod (params) {
764
+ const { $table } = params
765
+ $table.revertData($table.getCheckboxRecords())
766
+ }
767
+ },
768
+ /**
769
+ * 还原所有数据的值
770
+ */
771
+ REVERT_ALL: {
772
+ tableMenuMethod (params) {
773
+ const { $table } = params
774
+ $table.revertData()
775
+ }
776
+ },
777
+ /**
778
+ * 复制列头标题
779
+ */
780
+ COPY_TITLE: {
781
+ tableMenuMethod (params) {
782
+ const { column } = params
783
+ const text = column.getTitle()
784
+ if (text) {
785
+ // 开始复制操作
786
+ if (XEUtils.isFunction(handleCopy)) {
787
+ handleCopy(text)
788
+ } else {
789
+ copyText(text)
790
+ }
791
+ }
792
+ }
793
+ },
794
+ /**
795
+ * 复制单元格数据的值;如果启用 mouse-config.area 功能,则复制区域范围内的单元格数据,支持 Excel 和 WPS
796
+ */
797
+ COPY_CELL: {
798
+ tableMenuMethod (params) {
799
+ handleCopyOrCut(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods })
800
+ }
801
+ },
802
+ /**
803
+ * 剪贴单元格数据的值;如果启用 mouse-config.area 功能,则剪贴区域范围内的单元格数据,支持 Excel 和 WPS
804
+ */
805
+ CUT_CELL: {
806
+ tableMenuMethod (params) {
807
+ handleCopyOrCut(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, true)
808
+ }
809
+ },
810
+ /**
811
+ * 粘贴从表格中被复制的数据;如果启用 mouse-config.area 功能,则粘贴区域范围内的单元格数据,不支持读取剪贴板
812
+ */
813
+ PASTE_CELL: {
814
+ tableMenuMethod (params) {
815
+ const { $event, $table, row, column } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
816
+ const tableProps = $table
817
+ const { mouseConfig } = tableProps
818
+ const mouseOpts = $table.computeMouseOpts
819
+ if (mouseConfig && mouseOpts.area) {
820
+ $table.triggerPasteCellAreaEvent($event)
821
+ } else {
822
+ const clipboard = getClipboardObj()
823
+ // 读取内置剪贴板
824
+ if (clipboard && clipboard.text) {
825
+ XEUtils.set(row, column.field, clipboard.text)
826
+ }
827
+ }
828
+ }
829
+ },
830
+ /**
831
+ * 如果启用 mouse-config.area 功能,如果所选区域内已存在合并单元格,则取消临时合并,否则临时合并
832
+ */
833
+ MERGE_OR_CLEAR: {
834
+ tableMenuMethod (params) {
835
+ const { $event, $table } = params
836
+ const cellAreas = $table.getCellAreas()
837
+ const beenMerges = getBeenMerges(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods })
838
+ let status = false
839
+ if (beenMerges.length) {
840
+ $table.removeMergeCells(beenMerges)
841
+ } else {
842
+ status = true
843
+ $table.setMergeCells(
844
+ cellAreas.map(({ rows, cols }) => {
845
+ return {
846
+ row: rows[0],
847
+ col: cols[0],
848
+ rowspan: rows.length,
849
+ colspan: cols.length
850
+ }
851
+ })
852
+ )
853
+ }
854
+ const targetAreas = cellAreas.map(({ rows, cols }) => ({ rows, cols }))
855
+ $table.dispatchEvent('cell-area-merge', { status, targetAreas }, $event)
856
+ }
857
+ },
858
+ /**
859
+ * 如果启用 mouse-config.area 功能,临时合并区域范围内的单元格,不管是否存在已合并
860
+ */
861
+ MERGE_CELL: {
862
+ tableMenuMethod (params) {
863
+ const { $event, $table } = params
864
+ const { visibleData } = $table.getTableData()
865
+ const { visibleColumn } = $table.getTableColumn()
866
+ const cellAreas = $table.getCellAreas()
867
+ handleClearMergeCells(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods })
868
+ if (cellAreas.some(({ rows, cols }) => rows.length === visibleData.length || cols.length === visibleColumn.length)) {
869
+ if (VxeUI.modal) {
870
+ VxeUI.modal.message({ content: VxeUI.getI18n('vxe.pro.area.mergeErr'), status: 'error', id: 'operErr' })
871
+ }
872
+ return
873
+ }
874
+ $table.setMergeCells(
875
+ cellAreas.map(({ rows, cols }) => {
876
+ return {
877
+ row: rows[0],
878
+ col: cols[0],
879
+ rowspan: rows.length,
880
+ colspan: cols.length
881
+ }
882
+ })
883
+ )
884
+ const targetAreas = cellAreas.map(({ rows, cols }) => ({ rows, cols }))
885
+ $table.dispatchEvent('cell-area-merge', { status: true, targetAreas }, $event)
886
+ }
887
+ },
888
+ /**
889
+ * 如果启用 mouse-config.area 功能,清除区域范围内单元格的临时合并状态
890
+ */
891
+ CLEAR_MERGE_CELL: {
892
+ tableMenuMethod (params) {
893
+ const { $event, $table } = params
894
+ const beenMerges = handleClearMergeCells(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods })
895
+ if (beenMerges.length) {
896
+ $table.dispatchEvent('clear-cell-area-merge', { mergeCells: beenMerges }, $event)
897
+ }
898
+ }
899
+ },
900
+ /**
901
+ * 清除所有单元格及表尾的临时合并状态
902
+ */
903
+ CLEAR_ALL_MERGE: {
904
+ tableMenuMethod (params) {
905
+ const { $event, $table } = params
906
+ const mergeCells = $table.getMergeCells()
907
+ const mergeFooterItems = $table.getMergeFooterItems()
908
+ $table.clearMergeCells()
909
+ $table.clearMergeFooterItems()
910
+ $table.dispatchEvent('clear-merge', { mergeCells, mergeFooterItems }, $event)
911
+ }
912
+ },
913
+ /**
914
+ * 编辑单元格
915
+ */
916
+ EDIT_CELL: {
917
+ tableMenuMethod (params) {
918
+ const { $table, row, column } = params
919
+ if ($table.setEditCell) {
920
+ $table.setEditCell(row, column)
921
+ } else {
922
+ // 兼容老版本
923
+ $table.setActiveCell(row, column.field)
924
+ }
925
+ }
926
+ },
927
+ /**
928
+ * 编辑行
929
+ */
930
+ EDIT_ROW: {
931
+ tableMenuMethod (params) {
932
+ const { $table, row } = params
933
+ if ($table.setEditRow) {
934
+ $table.setEditRow(row)
935
+ } else {
936
+ // 兼容老版本
937
+ $table.setActiveRow(row)
938
+ }
939
+ }
940
+ },
941
+ /**
942
+ * 插入数据
943
+ */
944
+ INSERT_ROW: {
945
+ tableMenuMethod (params) {
946
+ const { $table, menu, column } = params
947
+ const tableProps = $table
948
+ const { mouseConfig } = tableProps
949
+ const mouseOpts = $table.computeMouseOpts
950
+ $table.insert(menu.params || {}).then(({ rows }) => {
951
+ if (column && mouseConfig && mouseOpts.area) {
952
+ $table.setCellAreas([
953
+ { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
954
+ ])
955
+ }
956
+ })
957
+ }
958
+ },
959
+ /**
960
+ * 插入数据到指定位置
961
+ */
962
+ INSERT_AT_ROW: {
963
+ tableMenuMethod (params) {
964
+ const { $table, menu, row, column } = params
965
+ const tableProps = $table
966
+ const { mouseConfig } = tableProps
967
+ const mouseOpts = $table.computeMouseOpts;
968
+ (row ? $table.insertAt(menu.params || {}, row) : $table.insert(menu.params || {})).then(({ rows }) => {
969
+ if (column && mouseConfig && mouseOpts.area) {
970
+ $table.setCellAreas([
971
+ { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
972
+ ])
973
+ }
974
+ })
975
+ }
976
+ },
977
+ /**
978
+ * 插入多行数据
979
+ */
980
+ BATCH_INSERT_AT_ROW: {
981
+ tableMenuMethod (params) {
982
+ const { $table, menu, row, column } = params
983
+ const tableProps = $table
984
+ const { mouseConfig } = tableProps
985
+ const mouseOpts = $table.computeMouseOpts
986
+ selectMultipleRows().then(({ size }) => {
987
+ if (size) {
988
+ const records = XEUtils.range(0, size).map(() => Object.assign({}, menu.params));
989
+ (row ? $table.insertAt(records, row) : $table.insert(records)).then(({ rows }) => {
990
+ if (column && mouseConfig && mouseOpts.area) {
991
+ $table.setCellAreas([
992
+ { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
993
+ ])
994
+ }
995
+ })
996
+ }
997
+ })
998
+ }
999
+ },
1000
+ /**
1001
+ * 插入数据到指定位置
1002
+ */
1003
+ INSERT_NEXT_AT_ROW: {
1004
+ tableMenuMethod (params) {
1005
+ const { $table, menu, row, column } = params
1006
+ const tableProps = $table
1007
+ const { mouseConfig } = tableProps
1008
+ const mouseOpts = $table.computeMouseOpts;
1009
+ (row ? $table.insertNextAt(menu.params || {}, row) : $table.insert(menu.params || {})).then(({ rows }) => {
1010
+ if (column && mouseConfig && mouseOpts.area) {
1011
+ $table.setCellAreas([
1012
+ { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
1013
+ ])
1014
+ }
1015
+ })
1016
+ }
1017
+ },
1018
+ /**
1019
+ * 插入数据到指定位置
1020
+ */
1021
+ BATCH_INSERT_NEXT_AT_ROW: {
1022
+ tableMenuMethod (params) {
1023
+ const { $table, menu, row, column } = params
1024
+ const tableProps = $table
1025
+ const { mouseConfig } = tableProps
1026
+ const mouseOpts = $table.computeMouseOpts
1027
+ selectMultipleRows().then(({ size }) => {
1028
+ if (size) {
1029
+ const records = XEUtils.range(0, size).map(() => Object.assign({}, menu.params));
1030
+ (row ? $table.insertNextAt(records, row) : $table.insert(records)).then(({ rows }) => {
1031
+ if (column && mouseConfig && mouseOpts.area) {
1032
+ $table.setCellAreas([
1033
+ { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
1034
+ ])
1035
+ }
1036
+ })
1037
+ }
1038
+ })
1039
+ }
1040
+ },
1041
+ /**
1042
+ * 插入数据并激活编辑状态
1043
+ * @deprecated
1044
+ */
1045
+ INSERT_ACTIVED_ROW: {
1046
+ tableMenuMethod (params) {
1047
+ const { $table, menu, column } = params
1048
+ const args: any[] = menu.params || [] // [{}, 'field']
1049
+ const record = Object.assign({}, args[0] || {})
1050
+ $table.insert(record).then(({ row }) => {
1051
+ if ($table.setEditCell) {
1052
+ $table.setEditCell(row, args[1] || column)
1053
+ } else {
1054
+ // 兼容老版本
1055
+ $table.setActiveCell(row, args[1] || column.field)
1056
+ }
1057
+ })
1058
+ }
1059
+ },
1060
+ /**
1061
+ * 插入数据并激活编辑状态
1062
+ * @deprecated
1063
+ */
1064
+ INSERT_EDIT_ROW: {
1065
+ tableMenuMethod (params) {
1066
+ const { $table, menu, column } = params
1067
+ const args: any[] = menu.params || [] // [{}, 'field']
1068
+ const record = Object.assign({}, args[0] || {})
1069
+ $table.insert(record).then(({ row }) => {
1070
+ if ($table.setEditCell) {
1071
+ $table.setEditCell(row, args[1] || column)
1072
+ } else {
1073
+ // 兼容老版本
1074
+ $table.setActiveCell(row, args[1] || column.field)
1075
+ }
1076
+ })
1077
+ }
1078
+ },
1079
+ /**
1080
+ * 插入数据到指定位置并激活编辑状态
1081
+ */
1082
+ INSERT_AT_ACTIVED_ROW: {
1083
+ tableMenuMethod (params) {
1084
+ const { $table, menu, row, column } = params
1085
+ const args: any[] = menu.params || [] // [{}, 'field']
1086
+ const record = Object.assign({}, args[0] || {});
1087
+ (row ? $table.insertAt(record, row) : $table.insert(record)).then(({ row }) => {
1088
+ if ($table.setEditCell) {
1089
+ $table.setEditCell(row, args[1] || column)
1090
+ } else {
1091
+ // 兼容老版本
1092
+ $table.setActiveCell(row, args[1] || column.field)
1093
+ }
1094
+ })
1095
+ }
1096
+ },
1097
+ /**
1098
+ * 插入数据到指定位置并激活编辑状态
1099
+ */
1100
+ INSERT_AT_EDIT_ROW: {
1101
+ tableMenuMethod (params) {
1102
+ const { $table, menu, row, column } = params
1103
+ const args: any[] = menu.params || [] // [{}, 'field']
1104
+ const record = Object.assign({}, args[0] || {});
1105
+ (row ? $table.insertAt(record, row) : $table.insert(record)).then(({ row }) => {
1106
+ if ($table.setEditCell) {
1107
+ $table.setEditCell(row, args[1] || column)
1108
+ } else {
1109
+ // 兼容老版本
1110
+ $table.setActiveCell(row, args[1] || column.field)
1111
+ }
1112
+ })
1113
+ }
1114
+ },
1115
+ /**
1116
+ * 批量插入数据到指定位置并激活编辑状态
1117
+ */
1118
+ BATCH_INSERT_AT_EDIT_ROW: {
1119
+ tableMenuMethod (params) {
1120
+ const { $table, menu, row, column } = params
1121
+ const args: any[] = menu.params || [] // [{}, 'field']
1122
+ selectMultipleRows().then(({ size }) => {
1123
+ if (size) {
1124
+ const records = XEUtils.range(0, size).map(() => Object.assign({}, args[0]));
1125
+ (row ? $table.insertAt(records, row) : $table.insert(records)).then(({ row }) => {
1126
+ if ($table.setEditCell) {
1127
+ $table.setEditCell(row, args[1] || column)
1128
+ } else {
1129
+ // 兼容老版本
1130
+ $table.setActiveCell(row, args[1] || column.field)
1131
+ }
1132
+ })
1133
+ }
1134
+ })
1135
+ }
1136
+ },
1137
+ /**
1138
+ * 插入数据到指定位置并激活编辑状态
1139
+ */
1140
+ INSERT_NEXT_AT_EDIT_ROW: {
1141
+ tableMenuMethod (params) {
1142
+ const { $table, menu, row, column } = params
1143
+ const args: any[] = menu.params || [] // [{}, 'field']
1144
+ const record = Object.assign({}, args[0] || {});
1145
+ (row ? $table.insertNextAt(record, row) : $table.insert(record)).then(({ row }) => {
1146
+ if ($table.setEditCell) {
1147
+ $table.setEditCell(row, args[1] || column)
1148
+ } else {
1149
+ // 兼容老版本
1150
+ $table.setActiveCell(row, args[1] || column.field)
1151
+ }
1152
+ })
1153
+ }
1154
+ },
1155
+ /**
1156
+ * 批量插入数据到指定位置并激活编辑状态
1157
+ */
1158
+ BATCH_INSERT_NEXT_AT_EDIT_ROW: {
1159
+ tableMenuMethod (params) {
1160
+ const { $table, menu, row, column } = params
1161
+ const args: any[] = menu.params || [] // [{}, 'field']
1162
+ selectMultipleRows().then(({ size }) => {
1163
+ if (size) {
1164
+ const records = XEUtils.range(0, size).map(() => Object.assign({}, args[0]));
1165
+ (row ? $table.insertNextAt(records, row) : $table.insert(records)).then(({ row }) => {
1166
+ if ($table.setEditCell) {
1167
+ $table.setEditCell(row, args[1] || column)
1168
+ } else {
1169
+ // 兼容老版本
1170
+ $table.setActiveCell(row, args[1] || column.field)
1171
+ }
1172
+ })
1173
+ }
1174
+ })
1175
+ }
1176
+ },
1177
+ /**
1178
+ * 移除行数据
1179
+ */
1180
+ DELETE_ROW: {
1181
+ tableMenuMethod (params) {
1182
+ const { $table, row } = params
1183
+ if (row) {
1184
+ $table.remove(row)
1185
+ }
1186
+ }
1187
+ },
1188
+ /**
1189
+ * 如果启用 mouse-config.area 功能,移除所选区域行数据
1190
+ */
1191
+ DELETE_AREA_ROW: {
1192
+ tableMenuMethod (params) {
1193
+ const { $table, row } = params
1194
+ const tableProps = $table
1195
+ const { mouseConfig } = tableProps
1196
+ const mouseOpts = $table.computeMouseOpts
1197
+ if (mouseConfig && mouseOpts.area) {
1198
+ const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
1199
+ cellAreas.forEach(areaItem => {
1200
+ const { rows } = areaItem
1201
+ $table.remove(rows)
1202
+ })
1203
+ } else {
1204
+ if (row) {
1205
+ $table.remove(row)
1206
+ }
1207
+ }
1208
+ }
1209
+ },
1210
+ /**
1211
+ * 移除复选框选中行数据
1212
+ */
1213
+ DELETE_CHECKBOX_ROW: {
1214
+ tableMenuMethod (params) {
1215
+ const { $table } = params
1216
+ $table.removeCheckboxRow()
1217
+ }
1218
+ },
1219
+ /**
1220
+ * 移除所有行数据
1221
+ */
1222
+ DELETE_ALL: {
1223
+ tableMenuMethod (params) {
1224
+ const { $table } = params
1225
+ $table.remove()
1226
+ }
1227
+ },
1228
+ /**
1229
+ * 清除所选列排序条件
1230
+ */
1231
+ CLEAR_SORT: {
1232
+ tableMenuMethod (params) {
1233
+ const { $event, $table, column } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
1234
+ if (column) {
1235
+ $table.triggerSortEvent($event, column, null)
1236
+ }
1237
+ }
1238
+ },
1239
+ /**
1240
+ * 清除所有排序条件
1241
+ */
1242
+ CLEAR_ALL_SORT: {
1243
+ tableMenuMethod (params) {
1244
+ const { $event, $table } = params
1245
+ const sortList = $table.getSortColumns()
1246
+ if (sortList.length) {
1247
+ $table.clearSort()
1248
+ $table.dispatchEvent('clear-sort', { sortList }, $event)
1249
+ }
1250
+ }
1251
+ },
1252
+ /**
1253
+ * 按所选列的值升序
1254
+ */
1255
+ SORT_ASC: {
1256
+ tableMenuMethod (params) {
1257
+ const { $event, $table, column } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
1258
+ if (column) {
1259
+ $table.triggerSortEvent($event, column, 'asc')
1260
+ }
1261
+ }
1262
+ },
1263
+ /**
1264
+ * 按所选列的值倒序
1265
+ */
1266
+ SORT_DESC: {
1267
+ tableMenuMethod (params) {
1268
+ const { $event, $table, column } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
1269
+ if (column) {
1270
+ $table.triggerSortEvent($event, column, 'desc')
1271
+ }
1272
+ }
1273
+ },
1274
+ /**
1275
+ * 清除复选框选中列的筛选条件
1276
+ */
1277
+ CLEAR_FILTER: {
1278
+ tableMenuMethod (params) {
1279
+ const { $event, $table, column } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
1280
+ if (column) {
1281
+ $table.handleClearFilter(column)
1282
+ $table.confirmFilterEvent($event)
1283
+ }
1284
+ }
1285
+ },
1286
+ /**
1287
+ * 清除所有列筛选条件
1288
+ */
1289
+ CLEAR_ALL_FILTER: {
1290
+ tableMenuMethod (params) {
1291
+ const { $event, $table } = params
1292
+ const filterList = $table.getCheckedFilters()
1293
+ if (filterList.length) {
1294
+ $table.clearFilter()
1295
+ $table.dispatchEvent('clear-filter', { filterList }, $event)
1296
+ }
1297
+ }
1298
+ },
1299
+ /**
1300
+ * 根据单元格值筛选
1301
+ */
1302
+ FILTER_CELL: {
1303
+ tableMenuMethod (params) {
1304
+ const { $table, row, column } = params
1305
+ if (row && column) {
1306
+ const { field, filters } = column
1307
+ if (filters.length) {
1308
+ const option = filters[0]
1309
+ option.data = XEUtils.get(row, field)
1310
+ option.checked = true
1311
+ $table.updateData()
1312
+ }
1313
+ }
1314
+ }
1315
+ },
1316
+ /**
1317
+ * 导出行数据
1318
+ */
1319
+ EXPORT_ROW: {
1320
+ tableMenuMethod (params) {
1321
+ const { $table, menu, row } = params
1322
+ if (row) {
1323
+ const opts = { data: [row] }
1324
+ $table.exportData(XEUtils.assign({}, menu.params ? menu.params[0] : {}, opts))
1325
+ }
1326
+ }
1327
+ },
1328
+ /**
1329
+ * 导出复选框选中行数据
1330
+ */
1331
+ EXPORT_CHECKBOX_ROW: {
1332
+ tableMenuMethod (params) {
1333
+ const { $table, menu } = params
1334
+ const opts = { data: $table.getCheckboxRecords() }
1335
+ $table.exportData(XEUtils.assign({}, menu.params ? menu.params[0] : {}, opts))
1336
+ }
1337
+ },
1338
+ /**
1339
+ * 导出所有行数据
1340
+ */
1341
+ EXPORT_ALL: {
1342
+ tableMenuMethod (params) {
1343
+ const { $table, menu } = params
1344
+ $table.exportData(menu.params)
1345
+ }
1346
+ },
1347
+ /**
1348
+ * 打印所有行数据
1349
+ */
1350
+ PRINT_ALL: {
1351
+ tableMenuMethod (params) {
1352
+ const { $table, menu } = params
1353
+ $table.print(menu.params)
1354
+ }
1355
+ },
1356
+ /**
1357
+ * 打印复选框选中行
1358
+ */
1359
+ PRINT_CHECKBOX_ROW: {
1360
+ tableMenuMethod (params) {
1361
+ const { $table, menu } = params
1362
+ const opts = { data: $table.getCheckboxRecords() }
1363
+ $table.print(XEUtils.assign(opts, menu.params))
1364
+ }
1365
+ },
1366
+ /**
1367
+ * 打开查找功能
1368
+ */
1369
+ OPEN_FIND: {
1370
+ tableMenuMethod (params) {
1371
+ const { $event, $table } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
1372
+ $table.triggerFNROpenEvent($event, 'find')
1373
+ }
1374
+ },
1375
+ /**
1376
+ * 打开替换功能
1377
+ */
1378
+ OPEN_REPLACE: {
1379
+ tableMenuMethod (params) {
1380
+ const { $event, $table } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
1381
+ $table.triggerFNROpenEvent($event, 'replace')
1382
+ }
1383
+ },
1384
+ /**
1385
+ * 隐藏当前列
1386
+ */
1387
+ HIDDEN_COLUMN: {
1388
+ tableMenuMethod (params) {
1389
+ const { $table, column } = params
1390
+ if (column) {
1391
+ $table.hideColumn(column)
1392
+ }
1393
+ }
1394
+ },
1395
+ /**
1396
+ * 将列固定到左侧
1397
+ */
1398
+ FIXED_LEFT_COLUMN: handleFixedColumn('left'),
1399
+ /**
1400
+ * 将列固定到右侧
1401
+ */
1402
+ FIXED_RIGHT_COLUMN: handleFixedColumn('right'),
1403
+ /**
1404
+ * 清除固定列
1405
+ */
1406
+ CLEAR_FIXED_COLUMN: handleFixedColumn(null),
1407
+ /**
1408
+ * 重置列的可视状态
1409
+ */
1410
+ RESET_COLUMN: {
1411
+ tableMenuMethod (params) {
1412
+ const { $table } = params
1413
+ $table.resetColumn({ visible: true, resizable: false })
1414
+ }
1415
+ },
1416
+ /**
1417
+ * 重置列宽状态
1418
+ */
1419
+ RESET_RESIZABLE: {
1420
+ tableMenuMethod (params) {
1421
+ const { $table } = params
1422
+ $table.resetColumn({ visible: false, resizable: true })
1423
+ }
1424
+ },
1425
+ /**
1426
+ * 重置列的所有状态
1427
+ */
1428
+ RESET_ALL: {
1429
+ tableMenuMethod (params) {
1430
+ const { $table } = params
1431
+ $table.resetColumn(true)
1432
+ }
1433
+ },
1434
+ /**
1435
+ * 用于 proxy-config,重新初始化,恢复到初始状态,触发对应的 ajax.query
1436
+ */
1437
+ COMMIT_PROXY_INITIAL: {
1438
+ tableMenuMethod: createCommitHandle('initial')
1439
+ },
1440
+ /**
1441
+ * 用于 proxy-config,重新加载,如果有分页,返回第一页,触发对应的 ajax.query
1442
+ */
1443
+ COMMIT_PROXY_QUERY: {
1444
+ tableMenuMethod: createCommitHandle('query')
1445
+ },
1446
+ /**
1447
+ * 用于 proxy-config,刷新当前页,触发对应的 ajax.quer
1448
+ */
1449
+ COMMIT_PROXY_RELOAD: {
1450
+ tableMenuMethod: createCommitHandle('reload')
1451
+ },
1452
+ /**
1453
+ * 用于 proxy-config,直接删除,触发对应的 ajax.delete
1454
+ */
1455
+ COMMIT_PROXY_DELETE: {
1456
+ tableMenuMethod: createCommitHandle('delete')
1457
+ },
1458
+ /**
1459
+ * 用于 proxy-config,保存数据,触发对应的 ajax.save
1460
+ */
1461
+ COMMIT_PROXY_SAVE: {
1462
+ tableMenuMethod: createCommitHandle('save')
1463
+ }
1464
+ })
1465
+
1466
+ VxeUI.interceptor.add('event.showMenu', handlePrivilegeEvent)
1467
+ }
1468
+ }
1469
+
1470
+ if (typeof window !== 'undefined' && window.VxeUI && window.VxeUI.use) {
1471
+ window.VxeUI.use(VxeUIPluginMenu)
1472
+ }
1473
+
1474
+ export default VxeUIPluginMenu