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