@vxe-ui/plugin-menu 4.3.2 → 4.4.0

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 CHANGED
@@ -8,6 +8,16 @@ import type { VxeUIPluginMenuOptions } from '../types'
8
8
  let VxeUI: VxeUIExport
9
9
  let handleCopy: ((content: string | number) => boolean) | undefined
10
10
 
11
+ /**
12
+ * 用于开关类型的配置项
13
+ * 局部启用规则:conf={}
14
+ * 局部禁用规则:conf={enabled:false}
15
+ * 全局默认启用规则:conf.enabled=true
16
+ */
17
+ export function hasEnableConf (conf: any, opts: any): boolean {
18
+ return opts && (conf ? opts.enabled !== false : opts.enabled)
19
+ }
20
+
11
21
  const columnIndexOf = (cols: VxeTableDefines.ColumnInfo[], column: VxeTableDefines.ColumnInfo) => {
12
22
  return XEUtils.findIndexOf(cols, item => item.id === column.id)
13
23
  }
@@ -91,8 +101,8 @@ function handleCopyOrCut (params: VxeGlobalMenusHandles.TableMenuMethodParams &
91
101
  const { mouseConfig } = tableProps
92
102
  const { computeMouseOpts } = $table.getComputeMaps()
93
103
  const mouseOpts = computeMouseOpts.value
94
- let text = ''
95
- if (mouseConfig && mouseOpts.area) {
104
+ let text: string
105
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
96
106
  if (isCut) {
97
107
  $table.triggerCutCellAreaEvent($event)
98
108
  } else {
@@ -156,7 +166,7 @@ function getBeenMerges (params: (VxeGlobalMenusHandles.TableMenuMethodParams | V
156
166
  const mouseOpts = computeMouseOpts.value
157
167
  const { visibleData } = $table.getTableData()
158
168
  const { visibleColumn } = $table.getTableColumn()
159
- const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
169
+ const cellAreas = hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area ? $table.getCellAreas() : []
160
170
  const mergeList = $table.getMergeCells()
161
171
  return mergeList.filter(({ row: mergeRowIndex, col: mergeColIndex, rowspan: mergeRowspan, colspan: mergeColspan }) => {
162
172
  return cellAreas.some(areaItem => {
@@ -230,10 +240,14 @@ function checkPrivilege (item: VxeTableDefines.MenuFirstOption | VxeTableDefines
230
240
  }
231
241
  case 'EDIT_CELL':
232
242
  case 'CLEAR_CELL':
243
+ case 'CLEAR_AREA_CELL':
233
244
  case 'CLEAR_ROW':
234
245
  case 'COPY_CELL':
246
+ case 'COPY_AREA_CELL':
235
247
  case 'CUT_CELL':
248
+ case 'CUT_AREA_CELL':
236
249
  case 'PASTE_CELL':
250
+ case 'PASTE_AREA_CELL':
237
251
  case 'MERGE_OR_CLEAR':
238
252
  case 'MERGE_CELL':
239
253
  case 'REVERT_CELL':
@@ -287,7 +301,7 @@ function checkPrivilege (item: VxeTableDefines.MenuFirstOption | VxeTableDefines
287
301
  }
288
302
  case 'OPEN_FIND':
289
303
  case 'OPEN_REPLACE': {
290
- item.disabled = !(mouseConfig && mouseOpts.area)
304
+ item.disabled = !(hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area)
291
305
  break
292
306
  }
293
307
  case 'EDIT_CELL': {
@@ -295,13 +309,17 @@ function checkPrivilege (item: VxeTableDefines.MenuFirstOption | VxeTableDefines
295
309
  break
296
310
  }
297
311
  case 'COPY_CELL':
312
+ case 'COPY_AREA_CELL':
298
313
  case 'CUT_CELL':
299
- case 'PASTE_CELL': {
300
- const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
314
+ case 'CUT_AREA_CELL':
315
+ case 'PASTE_CELL':
316
+ case 'PASTE_AREA_CELL': {
317
+ const cellAreas = hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area ? $table.getCellAreas() : []
301
318
  item.disabled = cellAreas.length > 1
302
319
  if (!item.disabled) {
303
320
  switch (code) {
304
- case 'PASTE_CELL': {
321
+ case 'PASTE_CELL':
322
+ case 'PASTE_AREA_CELL': {
305
323
  const clipboard = getClipboardObj()
306
324
  item.disabled = !clipboard || !clipboard.text
307
325
  break
@@ -312,7 +330,7 @@ function checkPrivilege (item: VxeTableDefines.MenuFirstOption | VxeTableDefines
312
330
  }
313
331
  case 'MERGE_OR_CLEAR':
314
332
  case 'MERGE_CELL': {
315
- const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
333
+ const cellAreas = hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area ? $table.getCellAreas() : []
316
334
  item.disabled = !cellAreas.length || (cellAreas.length === 1 && cellAreas[0].rows.length === 1 && cellAreas[0].cols.length === 1) || !checkCellOverlay(params, cellAreas)
317
335
  break
318
336
  }
@@ -503,7 +521,7 @@ export const VxeUIPluginMenu = {
503
521
  const { mouseConfig } = tableProps
504
522
  const { computeMouseOpts } = $table.getComputeMaps()
505
523
  const mouseOpts = computeMouseOpts.value
506
- if (mouseConfig && mouseOpts.area) {
524
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
507
525
  const cellAreas = $table.getCellAreas()
508
526
  if (cellAreas && cellAreas.length) {
509
527
  cellAreas.forEach(areaItem => {
@@ -521,6 +539,33 @@ export const VxeUIPluginMenu = {
521
539
  }
522
540
  }
523
541
  },
542
+ /**
543
+ * 用于 mouse-config.area 功能,清除区域范围内的单元格数据
544
+ */
545
+ CLEAR_AREA_CELL: {
546
+ tableMenuMethod (params) {
547
+ const { $table, row, column } = params
548
+ if (row && column) {
549
+ const tableProps = $table.props
550
+ const { mouseConfig } = tableProps
551
+ const { computeMouseOpts } = $table.getComputeMaps()
552
+ const mouseOpts = computeMouseOpts.value
553
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
554
+ const cellAreas = $table.getCellAreas()
555
+ if (cellAreas && cellAreas.length) {
556
+ cellAreas.forEach(areaItem => {
557
+ const { rows, cols } = areaItem
558
+ cols.forEach(column => {
559
+ rows.forEach(row => {
560
+ $table.clearData(row, column.field)
561
+ })
562
+ })
563
+ })
564
+ }
565
+ }
566
+ }
567
+ }
568
+ },
524
569
  /**
525
570
  * 清除行数据的值
526
571
  */
@@ -551,8 +596,8 @@ export const VxeUIPluginMenu = {
551
596
  const { mouseConfig } = tableProps
552
597
  const { computeMouseOpts } = $table.getComputeMaps()
553
598
  const mouseOpts = computeMouseOpts.value
554
- if (mouseConfig && mouseOpts.area) {
555
- const cellAreas = mouseConfig && mouseOpts.area ? $table.getCellAreas() : []
599
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
600
+ const cellAreas = mouseOpts.area ? $table.getCellAreas() : []
556
601
  cellAreas.forEach(areaItem => {
557
602
  const { rows } = areaItem
558
603
  $table.clearData(rows)
@@ -583,7 +628,7 @@ export const VxeUIPluginMenu = {
583
628
  const { mouseConfig } = tableProps
584
629
  const { computeMouseOpts } = $table.getComputeMaps()
585
630
  const mouseOpts = computeMouseOpts.value
586
- if (mouseConfig && mouseOpts.area) {
631
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
587
632
  const { visibleData } = $table.getTableData()
588
633
  const { visibleColumn } = $table.getTableColumn()
589
634
  $table.setCellAreas([{
@@ -605,7 +650,7 @@ export const VxeUIPluginMenu = {
605
650
  const { mouseConfig } = tableProps
606
651
  const { computeMouseOpts } = $table.getComputeMaps()
607
652
  const mouseOpts = computeMouseOpts.value
608
- if (row && column && mouseConfig && mouseOpts.area) {
653
+ if (row && column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
609
654
  const { visibleColumn } = $table.getTableColumn()
610
655
  const cellAreas = $table.getCellAreas()
611
656
  if (cellAreas.length === 1) {
@@ -637,7 +682,7 @@ export const VxeUIPluginMenu = {
637
682
  const { mouseConfig } = tableProps
638
683
  const { computeMouseOpts } = $table.getComputeMaps()
639
684
  const mouseOpts = computeMouseOpts.value
640
- if (row && column && mouseConfig && mouseOpts.area) {
685
+ if (row && column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
641
686
  const { visibleColumn } = $table.getTableColumn()
642
687
  const cellAreas = $table.getCellAreas()
643
688
  if (cellAreas.length === 1) {
@@ -669,7 +714,7 @@ export const VxeUIPluginMenu = {
669
714
  const { mouseConfig } = tableProps
670
715
  const { computeMouseOpts } = $table.getComputeMaps()
671
716
  const mouseOpts = computeMouseOpts.value
672
- if (row && column && mouseConfig && mouseOpts.area) {
717
+ if (row && column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
673
718
  const { visibleData } = $table.getTableData()
674
719
  const cellAreas = $table.getCellAreas()
675
720
  if (cellAreas.length === 1) {
@@ -701,7 +746,7 @@ export const VxeUIPluginMenu = {
701
746
  const { mouseConfig } = tableProps
702
747
  const { computeMouseOpts } = $table.getComputeMaps()
703
748
  const mouseOpts = computeMouseOpts.value
704
- if (row && column && mouseConfig && mouseOpts.area) {
749
+ if (row && column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
705
750
  const { visibleData } = $table.getTableData()
706
751
  const cellAreas = $table.getCellAreas()
707
752
  if (cellAreas.length === 1) {
@@ -734,7 +779,7 @@ export const VxeUIPluginMenu = {
734
779
  const { mouseConfig } = tableProps
735
780
  const { computeMouseOpts } = $table.getComputeMaps()
736
781
  const mouseOpts = computeMouseOpts.value
737
- if (mouseConfig && mouseOpts.area) {
782
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
738
783
  const cellAreas = $table.getCellAreas()
739
784
  if (cellAreas && cellAreas.length) {
740
785
  cellAreas.forEach(areaItem => {
@@ -806,6 +851,14 @@ export const VxeUIPluginMenu = {
806
851
  handleCopyOrCut(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods })
807
852
  }
808
853
  },
854
+ /**
855
+ * 复制单元格数据的值;用于 mouse-config.area 功能,复制区域范围内的单元格数据,支持 Excel 和 WPS
856
+ */
857
+ COPY_AREA_CELL: {
858
+ tableMenuMethod (params) {
859
+ handleCopyOrCut(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods })
860
+ }
861
+ },
809
862
  /**
810
863
  * 剪贴单元格数据的值;如果启用 mouse-config.area 功能,则剪贴区域范围内的单元格数据,支持 Excel 和 WPS
811
864
  */
@@ -814,6 +867,14 @@ export const VxeUIPluginMenu = {
814
867
  handleCopyOrCut(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, true)
815
868
  }
816
869
  },
870
+ /**
871
+ * 剪贴单元格数据的值;用于 mouse-config.area 功能,剪贴区域范围内的单元格数据,支持 Excel 和 WPS
872
+ */
873
+ CUT_AREA_CELL: {
874
+ tableMenuMethod (params) {
875
+ handleCopyOrCut(params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, true)
876
+ }
877
+ },
817
878
  /**
818
879
  * 粘贴从表格中被复制的数据;如果启用 mouse-config.area 功能,则粘贴区域范围内的单元格数据,不支持读取剪贴板
819
880
  */
@@ -824,7 +885,7 @@ export const VxeUIPluginMenu = {
824
885
  const { mouseConfig } = tableProps
825
886
  const { computeMouseOpts } = $table.getComputeMaps()
826
887
  const mouseOpts = computeMouseOpts.value
827
- if (mouseConfig && mouseOpts.area) {
888
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
828
889
  $table.triggerPasteCellAreaEvent($event)
829
890
  } else {
830
891
  const clipboard = getClipboardObj()
@@ -835,6 +896,21 @@ export const VxeUIPluginMenu = {
835
896
  }
836
897
  }
837
898
  },
899
+ /**
900
+ * 粘贴从表格中被复制的数据;用于 mouse-config.area 功能,粘贴区域范围内的单元格数据,不支持读取剪贴板
901
+ */
902
+ PASTE_AREA_CELL: {
903
+ tableMenuMethod (params) {
904
+ const { $event, $table } = params as VxeGlobalMenusHandles.TableMenuMethodParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }
905
+ const tableProps = $table.props
906
+ const { mouseConfig } = tableProps
907
+ const { computeMouseOpts } = $table.getComputeMaps()
908
+ const mouseOpts = computeMouseOpts.value
909
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
910
+ $table.triggerPasteCellAreaEvent($event)
911
+ }
912
+ }
913
+ },
838
914
  /**
839
915
  * 如果启用 mouse-config.area 功能,如果所选区域内已存在合并单元格,则取消临时合并,否则临时合并
840
916
  */
@@ -957,7 +1033,7 @@ export const VxeUIPluginMenu = {
957
1033
  const { computeMouseOpts } = $table.getComputeMaps()
958
1034
  const mouseOpts = computeMouseOpts.value
959
1035
  $table.insert(menu.params || {}).then(({ rows }) => {
960
- if (column && mouseConfig && mouseOpts.area) {
1036
+ if (column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
961
1037
  $table.setCellAreas([
962
1038
  { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
963
1039
  ])
@@ -976,7 +1052,7 @@ export const VxeUIPluginMenu = {
976
1052
  const { computeMouseOpts } = $table.getComputeMaps()
977
1053
  const mouseOpts = computeMouseOpts.value;
978
1054
  (row ? $table.insertAt(menu.params || {}, row) : $table.insert(menu.params || {})).then(({ rows }) => {
979
- if (column && mouseConfig && mouseOpts.area) {
1055
+ if (column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
980
1056
  $table.setCellAreas([
981
1057
  { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
982
1058
  ])
@@ -998,7 +1074,7 @@ export const VxeUIPluginMenu = {
998
1074
  if (size) {
999
1075
  const records = XEUtils.range(0, size).map(() => Object.assign({}, menu.params));
1000
1076
  (row ? $table.insertAt(records, row) : $table.insert(records)).then(({ rows }) => {
1001
- if (column && mouseConfig && mouseOpts.area) {
1077
+ if (column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
1002
1078
  $table.setCellAreas([
1003
1079
  { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
1004
1080
  ])
@@ -1019,7 +1095,7 @@ export const VxeUIPluginMenu = {
1019
1095
  const { computeMouseOpts } = $table.getComputeMaps()
1020
1096
  const mouseOpts = computeMouseOpts.value;
1021
1097
  (row ? $table.insertNextAt(menu.params || {}, row) : $table.insert(menu.params || {})).then(({ rows }) => {
1022
- if (column && mouseConfig && mouseOpts.area) {
1098
+ if (column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
1023
1099
  $table.setCellAreas([
1024
1100
  { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
1025
1101
  ])
@@ -1041,7 +1117,7 @@ export const VxeUIPluginMenu = {
1041
1117
  if (size) {
1042
1118
  const records = XEUtils.range(0, size).map(() => Object.assign({}, menu.params));
1043
1119
  (row ? $table.insertNextAt(records, row) : $table.insert(records)).then(({ rows }) => {
1044
- if (column && mouseConfig && mouseOpts.area) {
1120
+ if (column && hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
1045
1121
  $table.setCellAreas([
1046
1122
  { startRow: XEUtils.first(rows), endRow: XEUtils.last(rows), startColumn: column, endColumn: column }
1047
1123
  ])
@@ -1208,7 +1284,7 @@ export const VxeUIPluginMenu = {
1208
1284
  const { mouseConfig } = tableProps
1209
1285
  const { computeMouseOpts } = $table.getComputeMaps()
1210
1286
  const mouseOpts = computeMouseOpts.value
1211
- if (mouseConfig && mouseOpts.area) {
1287
+ if (hasEnableConf(mouseConfig, mouseOpts) && mouseOpts.area) {
1212
1288
  const cellAreas = $table.getCellAreas()
1213
1289
  cellAreas.forEach(areaItem => {
1214
1290
  const { rows } = areaItem