vxe-table 4.23.18 → 4.23.20

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.
Files changed (135) hide show
  1. package/dist/all.esm.js +301 -274
  2. package/dist/all.esm.min.js +3 -3
  3. package/dist/style.css +4 -1
  4. package/dist/style.mini.css +1 -1
  5. package/es/components.d.ts +1 -3
  6. package/es/components.js +1 -2
  7. package/es/esm.index.d.ts +7 -0
  8. package/es/esm.index.js +8 -0
  9. package/es/style.css +4 -1
  10. package/es/style.mini.css +1 -1
  11. package/es/table/module/edit/hook.js +2 -4
  12. package/es/table/module/export/export-panel.js +5 -5
  13. package/es/table/module/export/hook.js +8 -10
  14. package/es/table/module/export/import-panel.js +5 -5
  15. package/es/table/src/table.js +0 -1
  16. package/es/table/style.css +4 -1
  17. package/es/table/style.mini.css +1 -1
  18. package/es/ui/abandon.d.ts +82 -0
  19. package/es/ui/abandon.js +90 -0
  20. package/es/ui/index.d.ts +1 -82
  21. package/es/ui/index.js +2 -88
  22. package/es/ui/src/log.js +1 -1
  23. package/es/vxe-table/style.css +4 -1
  24. package/es/vxe-table/style.mini.css +1 -1
  25. package/lib/components.d.ts +1 -3
  26. package/lib/components.js +1 -2
  27. package/lib/esm.index.d.ts +7 -0
  28. package/lib/esm.index.js +39 -0
  29. package/lib/index.umd.js +266 -270
  30. package/lib/index.umd.min.js +3 -3
  31. package/lib/style.css +4 -1
  32. package/lib/style.mini.css +1 -1
  33. package/lib/table/module/edit/hook.js +2 -4
  34. package/lib/table/module/export/export-panel.js +5 -5
  35. package/lib/table/module/export/hook.js +8 -10
  36. package/lib/table/module/export/import-panel.js +5 -5
  37. package/lib/table/src/table.js +0 -1
  38. package/lib/table/style/style.css +4 -1
  39. package/lib/table/style/style.mini.css +1 -1
  40. package/lib/ui/abandon.d.ts +82 -0
  41. package/lib/ui/abandon.js +110 -0
  42. package/lib/ui/index.d.ts +1 -82
  43. package/lib/ui/index.js +3 -88
  44. package/lib/ui/src/log.js +1 -1
  45. package/lib/vxe-table/style/style.css +4 -1
  46. package/lib/vxe-table/style/style.mini.css +1 -1
  47. package/package.json +2 -2
  48. package/packages/colgroup/index.ts +22 -22
  49. package/packages/column/index.ts +22 -22
  50. package/packages/components.ts +42 -45
  51. package/packages/esm.index.ts +10 -0
  52. package/packages/grid/index.ts +18 -18
  53. package/packages/grid/src/emits.ts +5 -5
  54. package/packages/grid/src/grid.ts +2220 -2220
  55. package/packages/grid/src/props.ts +22 -22
  56. package/packages/index.ts +13 -13
  57. package/packages/locale/lang/ar-EG.ts +914 -914
  58. package/packages/locale/lang/de-DE.ts +914 -914
  59. package/packages/locale/lang/en-US.ts +914 -914
  60. package/packages/locale/lang/es-ES.ts +914 -914
  61. package/packages/locale/lang/fr-FR.ts +914 -914
  62. package/packages/locale/lang/hu-HU.ts +914 -914
  63. package/packages/locale/lang/hy-AM.ts +914 -914
  64. package/packages/locale/lang/id-ID.ts +914 -914
  65. package/packages/locale/lang/it-IT.ts +914 -914
  66. package/packages/locale/lang/ja-JP.ts +914 -914
  67. package/packages/locale/lang/ko-KR.ts +914 -914
  68. package/packages/locale/lang/ms-MY.ts +914 -914
  69. package/packages/locale/lang/nb-NO.ts +914 -914
  70. package/packages/locale/lang/pt-BR.ts +914 -914
  71. package/packages/locale/lang/ru-RU.ts +914 -914
  72. package/packages/locale/lang/th-TH.ts +914 -914
  73. package/packages/locale/lang/ug-CN.ts +914 -914
  74. package/packages/locale/lang/uk-UA.ts +914 -914
  75. package/packages/locale/lang/uz-UZ.ts +914 -914
  76. package/packages/locale/lang/vi-VN.ts +914 -914
  77. package/packages/locale/lang/zh-CHT.ts +914 -914
  78. package/packages/locale/lang/zh-CN.ts +914 -914
  79. package/packages/locale/lang/zh-HK.ts +914 -914
  80. package/packages/locale/lang/zh-MO.ts +914 -914
  81. package/packages/locale/lang/zh-TC.ts +914 -914
  82. package/packages/locale/lang/zh-TW.ts +914 -914
  83. package/packages/table/index.ts +26 -26
  84. package/packages/table/module/custom/hook.ts +510 -510
  85. package/packages/table/module/custom/panel.ts +2002 -2002
  86. package/packages/table/module/edit/hook.ts +1232 -1235
  87. package/packages/table/module/export/export-panel.ts +697 -697
  88. package/packages/table/module/export/hook.ts +2158 -2160
  89. package/packages/table/module/export/import-panel.ts +319 -319
  90. package/packages/table/module/export/util.ts +25 -25
  91. package/packages/table/module/filter/hook.ts +505 -505
  92. package/packages/table/module/filter/panel.ts +368 -368
  93. package/packages/table/module/keyboard/hook.ts +498 -498
  94. package/packages/table/module/menu/hook.ts +330 -330
  95. package/packages/table/module/menu/panel.ts +272 -272
  96. package/packages/table/module/validator/hook.ts +653 -653
  97. package/packages/table/render/index.ts +1819 -1819
  98. package/packages/table/src/body.ts +1078 -1078
  99. package/packages/table/src/cell.ts +1524 -1524
  100. package/packages/table/src/column.ts +192 -192
  101. package/packages/table/src/columnInfo.ts +232 -232
  102. package/packages/table/src/emits.ts +134 -134
  103. package/packages/table/src/footer.ts +425 -425
  104. package/packages/table/src/group.ts +67 -67
  105. package/packages/table/src/header.ts +661 -661
  106. package/packages/table/src/props.ts +336 -336
  107. package/packages/table/src/store.ts +14 -14
  108. package/packages/table/src/table.ts +0 -1
  109. package/packages/table/src/use/cell-view.ts +41 -41
  110. package/packages/table/src/use/index.ts +1 -1
  111. package/packages/table/src/util.ts +1206 -1206
  112. package/packages/toolbar/index.ts +18 -18
  113. package/packages/toolbar/src/toolbar.ts +768 -768
  114. package/packages/ui/abandon.ts +136 -0
  115. package/packages/ui/index.ts +404 -520
  116. package/packages/ui/src/anime.ts +51 -51
  117. package/packages/ui/src/comp.ts +3 -3
  118. package/packages/ui/src/dom.ts +466 -466
  119. package/packages/ui/src/log.ts +19 -19
  120. package/packages/ui/src/utils.ts +66 -66
  121. package/packages/ui/src/vn.ts +55 -55
  122. package/packages/v-x-e-table/index.d.ts +3 -3
  123. package/packages/v-x-e-table/index.ts +3 -3
  124. package/styles/components/table.scss +2 -1
  125. package/types/all.d.ts +76 -76
  126. package/types/index.d.ts +4 -4
  127. /package/dist/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  128. /package/dist/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  129. /package/dist/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
  130. /package/es/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  131. /package/es/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  132. /package/es/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
  133. /package/lib/{iconfont.1794366305845.ttf → iconfont.1794633824975.ttf} +0 -0
  134. /package/lib/{iconfont.1794366305845.woff → iconfont.1794633824975.woff} +0 -0
  135. /package/lib/{iconfont.1794366305845.woff2 → iconfont.1794633824975.woff2} +0 -0
@@ -1,768 +1,768 @@
1
- import { h, ref, computed, inject, createCommentVNode, VNode, reactive, nextTick, PropType, onBeforeUnmount } from 'vue'
2
- import { defineVxeComponent } from '../../ui/src/comp'
3
- import XEUtils from 'xe-utils'
4
- import { VxeUI } from '@vxe-ui/core'
5
- import { getSlotVNs } from '../../ui/src/vn'
6
- import { createComponentLog } from '../../ui/src/log'
7
-
8
- import type { ValueOf, VxeButtonEvents, VxeComponentSlotType, VxeButtonDefines } from 'vxe-pc-ui'
9
- import type { VxeGridConstructor, GridPrivateMethods, ToolbarMethods, ToolbarInternalData, VxeToolbarConstructor, VxeToolbarEmits, VxeToolbarPropTypes, ToolbarPrivateRef, ToolbarReactData, VxeTableConstructor, VxeTablePrivateMethods } from '../../../types'
10
-
11
- const { warnLog, errLog } = createComponentLog('toolbar')
12
-
13
- const { getConfig, getIcon, getI18n, renderer, commands, createEvent, useFns } = VxeUI
14
-
15
- function createReactData(): ToolbarReactData {
16
- return {
17
- isRefresh: false,
18
- connectFlag: 0,
19
- columns: []
20
- }
21
- }
22
-
23
- function createInternalData(): ToolbarInternalData {
24
- return {
25
- connectTable: null
26
- }
27
- }
28
-
29
- export default /* define-vxe-component start */ defineVxeComponent({
30
- name: 'VxeToolbar',
31
- props: {
32
- loading: Boolean,
33
- refresh: [Boolean, Object] as PropType<VxeToolbarPropTypes.Refresh>,
34
- refreshOptions: Object as PropType<VxeToolbarPropTypes.RefreshOptions>,
35
- import: [Boolean, Object] as PropType<VxeToolbarPropTypes.Import>,
36
- importOptions: Object as PropType<VxeToolbarPropTypes.ImportOptions>,
37
- export: [Boolean, Object] as PropType<VxeToolbarPropTypes.Export>,
38
- exportOptions: Object as PropType<VxeToolbarPropTypes.ExportOptions>,
39
- print: [Boolean, Object] as PropType<VxeToolbarPropTypes.Print>,
40
- printOptions: Object as PropType<VxeToolbarPropTypes.PrintOptions>,
41
- zoom: [Boolean, Object] as PropType<VxeToolbarPropTypes.Zoom>,
42
- zoomOptions: Object as PropType<VxeToolbarPropTypes.ZoomOptions>,
43
- custom: [Boolean, Object] as PropType<VxeToolbarPropTypes.Custom>,
44
- customOptions: Object as PropType<VxeToolbarPropTypes.CustomOptions>,
45
- buttons: {
46
- type: Array as PropType<VxeToolbarPropTypes.Buttons>,
47
- default: () => getConfig().toolbar.buttons
48
- },
49
- tools: {
50
- type: Array as PropType<VxeToolbarPropTypes.Tools>,
51
- default: () => getConfig().toolbar.tools
52
- },
53
- perfect: {
54
- type: Boolean as PropType<VxeToolbarPropTypes.Perfect>,
55
- default: () => getConfig().toolbar.perfect
56
- },
57
- size: {
58
- type: String as PropType<VxeToolbarPropTypes.Size>,
59
- default: () => getConfig().toolbar.size || getConfig().size
60
- },
61
- className: [String, Function] as PropType<VxeToolbarPropTypes.ClassName>
62
- },
63
- emits: ['button-click', 'tool-click'] as VxeToolbarEmits,
64
- setup(props, context) {
65
- const { slots, emit } = context
66
-
67
- const xID = XEUtils.uniqueId()
68
-
69
- // 使用已安装的组件,如果未安装则不渲染
70
- const VxeUIButtonComponent = VxeUI.getComponent('VxeButton')
71
-
72
- const $xeGrid = inject<(VxeGridConstructor & GridPrivateMethods) | null>('$xeGrid', null)
73
- const $xeGantt = inject('$xeGantt', null)
74
- const $xeGGWrapper = $xeGrid || $xeGantt
75
-
76
- const { computeSize } = useFns.useSize(props)
77
-
78
- const reactData = reactive(createReactData())
79
-
80
- const internalData = createInternalData()
81
-
82
- const refElem = ref<HTMLDivElement>()
83
-
84
- const refMaps: ToolbarPrivateRef = {
85
- refElem
86
- }
87
-
88
- const $xeToolbar = {
89
- xID,
90
- props,
91
- context,
92
- reactData,
93
- internalData,
94
- getRefMaps: () => refMaps
95
- } as unknown as VxeToolbarConstructor
96
-
97
- let toolbarMethods = {} as ToolbarMethods
98
-
99
- const computeRefreshOpts = computed(() => {
100
- return Object.assign({}, XEUtils.clone(getConfig().toolbar.refresh, true), props.refreshOptions, props.refresh) as VxeToolbarPropTypes.RefreshOptions
101
- })
102
-
103
- const computeImportOpts = computed(() => {
104
- return Object.assign({}, XEUtils.clone(getConfig().toolbar.import, true), props.importOptions, props.import) as VxeToolbarPropTypes.ImportOptions
105
- })
106
-
107
- const computeExportOpts = computed(() => {
108
- return Object.assign({}, XEUtils.clone(getConfig().toolbar.export, true), props.exportOptions, props.export) as VxeToolbarPropTypes.ExportOptions
109
- })
110
-
111
- const computePrintOpts = computed(() => {
112
- return Object.assign({}, XEUtils.clone(getConfig().toolbar.print, true), props.printOptions, props.print) as VxeToolbarPropTypes.PrintOptions
113
- })
114
-
115
- const computeZoomOpts = computed(() => {
116
- return Object.assign({}, XEUtils.clone(getConfig().toolbar.zoom, true), props.zoomOptions, props.zoom) as VxeToolbarPropTypes.ZoomOptions
117
- })
118
-
119
- const computeCustomOpts = computed(() => {
120
- return Object.assign({}, XEUtils.clone(getConfig().toolbar.custom, true), props.customOptions, props.custom) as VxeToolbarPropTypes.CustomOptions
121
- })
122
-
123
- const computeTableCustomOpts = computed(() => {
124
- const { connectTable } = internalData
125
- const $table = connectTable
126
- if (reactData.connectFlag || $table) {
127
- if ($table) {
128
- const { computeCustomOpts } = $table.getComputeMaps()
129
- return computeCustomOpts.value
130
- }
131
- }
132
- return { trigger: '' }
133
- })
134
-
135
- const computeTrigger = computed(() => {
136
- const tableCustomOpts = computeTableCustomOpts.value
137
- return tableCustomOpts.trigger
138
- })
139
-
140
- const checkTable = () => {
141
- const { connectTable } = internalData
142
- const $table = connectTable
143
- if ($table) {
144
- return true
145
- }
146
- errLog('vxe.error.barUnableLink')
147
- }
148
-
149
- const handleClickSettingEvent = ({ $event }: any) => {
150
- const { connectTable } = internalData
151
- const $table = connectTable
152
- if ($table) {
153
- if ($table.triggerCustomEvent) {
154
- $table.triggerCustomEvent($event)
155
- }
156
- }
157
- }
158
-
159
- const handleMouseenterSettingEvent = ({ $event }: any) => {
160
- const { connectTable } = internalData
161
- const $table = connectTable
162
- if ($table) {
163
- $table.customOpenEvent($event)
164
- }
165
- }
166
-
167
- const handleMouseleaveSettingEvent = ({ $event }: any) => {
168
- const { connectTable } = internalData
169
- const $table = connectTable
170
- if ($table) {
171
- const { customStore } = $table.reactData
172
- customStore.activeBtn = false
173
- setTimeout(() => {
174
- if (!customStore.activeBtn && !customStore.activeWrapper) {
175
- $table.customCloseEvent($event)
176
- }
177
- }, 350)
178
- }
179
- }
180
-
181
- const refreshEvent: VxeButtonEvents.Click = ({ $event }) => {
182
- const { isRefresh } = reactData
183
- const refreshOpts = computeRefreshOpts.value
184
- if (!isRefresh) {
185
- const queryMethod = refreshOpts.queryMethod || refreshOpts.query
186
- if (queryMethod) {
187
- reactData.isRefresh = true
188
- try {
189
- Promise.resolve(queryMethod({}))
190
- .catch((e) => e)
191
- .then(() => {
192
- reactData.isRefresh = false
193
- })
194
- } catch (e) {
195
- reactData.isRefresh = false
196
- }
197
- } else if ($xeGGWrapper) {
198
- reactData.isRefresh = true
199
- $xeGGWrapper
200
- .triggerToolbarCommitEvent({ code: refreshOpts.code || 'reload' }, $event)
201
- .catch(() => {})
202
- .then(() => {
203
- reactData.isRefresh = false
204
- })
205
- }
206
- }
207
- }
208
-
209
- const zoomEvent: VxeButtonEvents.Click = ({ $event }) => {
210
- if ($xeGGWrapper) {
211
- $xeGGWrapper.triggerZoomEvent($event)
212
- } else {
213
- warnLog('vxe.error.notProp', ['zoom'])
214
- }
215
- }
216
-
217
- const importEvent = () => {
218
- if (checkTable()) {
219
- const { connectTable } = internalData
220
- const $table = connectTable
221
- if ($table) {
222
- $table.importData()
223
- }
224
- }
225
- }
226
-
227
- const openImportEvent = () => {
228
- if (checkTable()) {
229
- const { connectTable } = internalData
230
- const $table = connectTable
231
- if ($table) {
232
- $table.openImport()
233
- }
234
- }
235
- }
236
-
237
- const exportEvent = () => {
238
- if (checkTable()) {
239
- const { connectTable } = internalData
240
- const $table = connectTable
241
- if ($table) {
242
- $table.exportData()
243
- }
244
- }
245
- }
246
-
247
- const openExportEvent = () => {
248
- if (checkTable()) {
249
- const { connectTable } = internalData
250
- const $table = connectTable
251
- if ($table) {
252
- $table.openExport()
253
- }
254
- }
255
- }
256
-
257
- const printEvent = () => {
258
- if (checkTable()) {
259
- const { connectTable } = internalData
260
- const $table = connectTable
261
- if ($table) {
262
- $table.print()
263
- }
264
- }
265
- }
266
-
267
- const openPrintEvent = () => {
268
- if (checkTable()) {
269
- const { connectTable } = internalData
270
- const $table = connectTable
271
- if ($table) {
272
- $table.openPrint()
273
- }
274
- }
275
- }
276
-
277
- const handleDefaultCodeEvent = (eventParams: VxeButtonDefines.ClickEventParams, item: VxeToolbarPropTypes.ButtonConfig | VxeToolbarPropTypes.ToolConfig, cb: () => void) => {
278
- switch (item.code) {
279
- case 'print':
280
- printEvent()
281
- break
282
- case 'open_print':
283
- openPrintEvent()
284
- break
285
- case 'custom':
286
- handleClickSettingEvent(eventParams)
287
- break
288
- case 'export':
289
- exportEvent()
290
- break
291
- case 'open_export':
292
- openExportEvent()
293
- break
294
- case 'import':
295
- importEvent()
296
- break
297
- case 'open_import':
298
- openImportEvent()
299
- break
300
- case 'zoom':
301
- zoomEvent(eventParams)
302
- break
303
- case 'refresh':
304
- refreshEvent(eventParams)
305
- break
306
- default:
307
- cb()
308
- break
309
- }
310
- }
311
-
312
- const btnEvent = (eventParams: VxeButtonDefines.ClickEventParams, item: VxeToolbarPropTypes.ButtonConfig) => {
313
- const { $event } = eventParams
314
- const { connectTable } = internalData
315
- const $table = connectTable
316
- const { code } = item
317
- if (code) {
318
- handleDefaultCodeEvent(eventParams, item, () => {
319
- if ($xeGGWrapper) {
320
- $xeGGWrapper.triggerToolbarBtnEvent(item, $event)
321
- } else {
322
- const gCommandOpts = commands.get(code)
323
- const params = { code, button: item, $table: $table as VxeTableConstructor, $grid: $xeGrid, $gantt: $xeGantt, $event }
324
- if (gCommandOpts) {
325
- const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
326
- if (tCommandMethod) {
327
- tCommandMethod(params)
328
- } else {
329
- errLog('vxe.error.notCommands', [code])
330
- }
331
- }
332
- $xeToolbar.dispatchEvent('button-click', params, $event)
333
- }
334
- })
335
- }
336
- }
337
-
338
- const tolEvent = (eventParams: VxeButtonDefines.ClickEventParams, item: VxeToolbarPropTypes.ToolConfig) => {
339
- const { $event } = eventParams
340
- const { connectTable } = internalData
341
- const $table = connectTable
342
- const { code } = item
343
- if (code) {
344
- handleDefaultCodeEvent(eventParams, item, () => {
345
- if ($xeGGWrapper) {
346
- $xeGGWrapper.triggerToolbarTolEvent(item, $event)
347
- } else {
348
- const gCommandOpts = commands.get(code)
349
- const params = { code, button: null, tool: item, $table: $table as VxeTableConstructor, $grid: $xeGrid, $gantt: $xeGantt, $event }
350
- if (gCommandOpts) {
351
- const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
352
- if (tCommandMethod) {
353
- tCommandMethod(params)
354
- } else {
355
- errLog('vxe.error.notCommands', [code])
356
- }
357
- }
358
- $xeToolbar.dispatchEvent('tool-click', params, $event)
359
- }
360
- })
361
- }
362
- }
363
-
364
- const dispatchEvent = (type: ValueOf<VxeToolbarEmits>, params: Record<string, any>, evnt: Event | null) => {
365
- emit(type, createEvent(evnt, { $toolbar: $xeToolbar }, params))
366
- }
367
-
368
- toolbarMethods = {
369
- dispatchEvent,
370
- syncUpdate(params) {
371
- internalData.connectTable = params.$table as VxeTableConstructor & VxeTablePrivateMethods
372
- reactData.columns = params.collectColumn
373
- reactData.connectFlag++
374
- }
375
- }
376
-
377
- Object.assign($xeToolbar, toolbarMethods)
378
-
379
- const renderDropdowns = (item: VxeToolbarPropTypes.ButtonConfig, isBtn: boolean) => {
380
- const { dropdowns } = item
381
- const downVNs: VNode[] = []
382
- if (dropdowns) {
383
- return dropdowns.map((child, index) => {
384
- if (child.visible === false) {
385
- return createCommentVNode()
386
- }
387
- return VxeUIButtonComponent
388
- ? h(VxeUIButtonComponent, {
389
- key: index,
390
- ...Object.assign({}, child, {
391
- content: child.content || child.name,
392
- options: undefined
393
- }),
394
- onClick: (eventParams) => (isBtn ? btnEvent(eventParams, child) : tolEvent(eventParams, child))
395
- })
396
- : createCommentVNode()
397
- })
398
- }
399
- return downVNs
400
- }
401
-
402
- /**
403
- * 渲染按钮
404
- */
405
- const renderLeftBtns = () => {
406
- const { buttons } = props
407
- const { connectTable } = internalData
408
- const $table = connectTable
409
- const buttonsSlot = slots.buttons
410
- const buttonPrefixSlot = slots.buttonPrefix || slots['button-prefix']
411
- const buttonSuffixSlot = slots.buttonSuffix || slots['button-suffix']
412
- const btnVNs: VxeComponentSlotType[] = []
413
- if (buttons) {
414
- const { computeRendererOpts } = $table ? $table.getComputeMaps() : {}
415
- const rendererOpts = (computeRendererOpts ? computeRendererOpts.value : null) || {}
416
- buttons.forEach((item, index) => {
417
- const { dropdowns, buttonRender } = item
418
- if (item.visible !== false) {
419
- const compConf = buttonRender && buttonRender.name ? rendererOpts[buttonRender.name] || renderer.get(buttonRender.name) : null
420
- if (buttonRender && compConf && compConf.renderToolbarButton) {
421
- const toolbarButtonClassName = compConf.toolbarButtonClassName
422
- const params = { $grid: $xeGrid, $gantt: $xeGantt, $table: $table!, button: item }
423
- btnVNs.push(
424
- h(
425
- 'span',
426
- {
427
- key: `br${item.code || index}`,
428
- class: ['vxe-button--item', toolbarButtonClassName ? (XEUtils.isFunction(toolbarButtonClassName) ? toolbarButtonClassName(params) : toolbarButtonClassName) : '']
429
- },
430
- getSlotVNs(compConf.renderToolbarButton(buttonRender, params))
431
- )
432
- )
433
- } else {
434
- if (VxeUIButtonComponent) {
435
- btnVNs.push(
436
- h(
437
- VxeUIButtonComponent,
438
- {
439
- key: `bd${item.code || index}`,
440
- ...Object.assign({}, item, {
441
- content: item.content || item.name,
442
- options: undefined
443
- }),
444
- onClick: (eventParams) => btnEvent(eventParams, item)
445
- },
446
- dropdowns && dropdowns.length
447
- ? {
448
- dropdowns: () => renderDropdowns(item, true)
449
- }
450
- : {}
451
- )
452
- )
453
- }
454
- }
455
- }
456
- })
457
- }
458
- return [
459
- h(
460
- 'div',
461
- {
462
- class: 'vxe-button--prefix-wrapper'
463
- },
464
- buttonPrefixSlot ? getSlotVNs(buttonPrefixSlot({ buttons: buttons || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
465
- ),
466
- h(
467
- 'div',
468
- {
469
- class: 'vxe-button--item-wrapper'
470
- },
471
- buttonsSlot ? getSlotVNs(buttonsSlot({ buttons: buttons || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : btnVNs
472
- ),
473
- h(
474
- 'div',
475
- {
476
- class: 'vxe-button--suffix-wrapper'
477
- },
478
- buttonSuffixSlot ? getSlotVNs(buttonSuffixSlot({ buttons: buttons || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
479
- )
480
- ]
481
- }
482
-
483
- /**
484
- * 渲染右侧工具
485
- */
486
- const renderRightTools = () => {
487
- const { tools } = props
488
- const { connectTable } = internalData
489
- const $table = connectTable
490
- const toolsSlot = slots.tools
491
- const toolPrefixSlot = slots.toolPrefix || slots['tool-prefix']
492
- const toolSuffixSlot = slots.toolSuffix || slots['tool-suffix']
493
- const btnVNs: VxeComponentSlotType[] = []
494
- if (tools) {
495
- const { computeRendererOpts } = $table ? $table.getComputeMaps() : {}
496
- const rendererOpts = (computeRendererOpts ? computeRendererOpts.value : null) || {}
497
- tools.forEach((item, tIndex) => {
498
- const { dropdowns, toolRender } = item
499
- if (item.visible !== false) {
500
- const compConf = toolRender && toolRender.name ? rendererOpts[toolRender.name] || renderer.get(toolRender.name) : null
501
- if (toolRender && compConf && compConf.renderToolbarTool) {
502
- const toolbarToolClassName = compConf.toolbarToolClassName
503
- const params = { $grid: $xeGrid, $gantt: $xeGantt, $table: $table!, tool: item }
504
- btnVNs.push(
505
- h(
506
- 'span',
507
- {
508
- key: tIndex,
509
- class: ['vxe-tool--item', toolbarToolClassName ? (XEUtils.isFunction(toolbarToolClassName) ? toolbarToolClassName(params) : toolbarToolClassName) : '']
510
- },
511
- getSlotVNs(compConf.renderToolbarTool(toolRender, params))
512
- )
513
- )
514
- } else {
515
- if (VxeUIButtonComponent) {
516
- btnVNs.push(
517
- h(
518
- VxeUIButtonComponent,
519
- {
520
- key: tIndex,
521
- ...Object.assign({}, item, {
522
- content: item.content || item.name,
523
- options: undefined
524
- }),
525
- onClick: (eventParams) => tolEvent(eventParams, item)
526
- },
527
- dropdowns && dropdowns.length
528
- ? {
529
- dropdowns: () => renderDropdowns(item, false)
530
- }
531
- : {}
532
- )
533
- )
534
- }
535
- }
536
- }
537
- })
538
- }
539
- return [
540
- h(
541
- 'div',
542
- {
543
- class: 'vxe-tool--prefix-wrapper'
544
- },
545
- toolPrefixSlot ? getSlotVNs(toolPrefixSlot({ tools: tools || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
546
- ),
547
- h(
548
- 'div',
549
- {
550
- class: 'vxe-tool--item-wrapper'
551
- },
552
- toolsSlot ? getSlotVNs(toolsSlot({ tools: tools || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : btnVNs
553
- ),
554
- h(
555
- 'div',
556
- {
557
- class: 'vxe-tool--suffix-wrapper'
558
- },
559
- toolSuffixSlot ? getSlotVNs(toolSuffixSlot({ tools: tools || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
560
- )
561
- ]
562
- }
563
-
564
- const renderToolImport = () => {
565
- const importOpts = computeImportOpts.value
566
- return VxeUIButtonComponent
567
- ? h(VxeUIButtonComponent, {
568
- key: 'import',
569
- circle: true,
570
- icon: importOpts.icon || getIcon().TOOLBAR_TOOLS_IMPORT,
571
- title: getI18n('vxe.toolbar.import'),
572
- onClick: openImportEvent
573
- })
574
- : createCommentVNode()
575
- }
576
-
577
- const renderToolExport = () => {
578
- const exportOpts = computeExportOpts.value
579
- return VxeUIButtonComponent
580
- ? h(VxeUIButtonComponent, {
581
- key: 'export',
582
- circle: true,
583
- icon: exportOpts.icon || getIcon().TOOLBAR_TOOLS_EXPORT,
584
- title: getI18n('vxe.toolbar.export'),
585
- onClick: openExportEvent
586
- })
587
- : createCommentVNode()
588
- }
589
-
590
- const renderToolPrint = () => {
591
- const printOpts = computePrintOpts.value
592
- return VxeUIButtonComponent
593
- ? h(VxeUIButtonComponent, {
594
- key: 'print',
595
- circle: true,
596
- icon: printOpts.icon || getIcon().TOOLBAR_TOOLS_PRINT,
597
- title: getI18n('vxe.toolbar.print'),
598
- onClick: openPrintEvent
599
- })
600
- : createCommentVNode()
601
- }
602
-
603
- const renderToolRefresh = () => {
604
- const refreshOpts = computeRefreshOpts.value
605
- return VxeUIButtonComponent
606
- ? h(VxeUIButtonComponent, {
607
- key: 'refresh',
608
- circle: true,
609
- icon: reactData.isRefresh ? refreshOpts.iconLoading || getIcon().TOOLBAR_TOOLS_REFRESH_LOADING : refreshOpts.icon || getIcon().TOOLBAR_TOOLS_REFRESH,
610
- title: getI18n('vxe.toolbar.refresh'),
611
- onClick: refreshEvent
612
- })
613
- : createCommentVNode()
614
- }
615
-
616
- const renderToolZoom = () => {
617
- const zoomOpts = computeZoomOpts.value
618
- return $xeGGWrapper && VxeUIButtonComponent
619
- ? h(VxeUIButtonComponent, {
620
- key: 'zoom',
621
- circle: true,
622
- icon: $xeGGWrapper.isMaximized() ? zoomOpts.iconOut || getIcon().TOOLBAR_TOOLS_MINIMIZE : zoomOpts.iconIn || getIcon().TOOLBAR_TOOLS_FULLSCREEN,
623
- title: getI18n(`vxe.toolbar.zoom${$xeGGWrapper.isMaximized() ? 'Out' : 'In'}`),
624
- onClick: zoomEvent
625
- })
626
- : createCommentVNode()
627
- }
628
-
629
- const renderToolCustom = () => {
630
- const customOpts = computeCustomOpts.value
631
- const btnTrigger = computeTrigger.value
632
- const customBtnOns: {
633
- onClick?: typeof handleClickSettingEvent
634
- onMouseenter?: typeof handleMouseenterSettingEvent
635
- onMouseleave?: typeof handleMouseleaveSettingEvent
636
- } = {}
637
- if (btnTrigger === 'manual') {
638
- // 手动触发
639
- } else if (btnTrigger === 'hover') {
640
- // hover 触发
641
- customBtnOns.onMouseenter = handleMouseenterSettingEvent
642
- customBtnOns.onMouseleave = handleMouseleaveSettingEvent
643
- } else {
644
- // 点击触发
645
- customBtnOns.onClick = handleClickSettingEvent
646
- }
647
- return VxeUIButtonComponent
648
- ? h(VxeUIButtonComponent, {
649
- key: 'custom',
650
- circle: true,
651
- icon: customOpts.icon || getIcon().TOOLBAR_TOOLS_CUSTOM,
652
- title: getI18n('vxe.toolbar.custom'),
653
- className: 'vxe-toolbar-custom-target',
654
- ...customBtnOns
655
- })
656
- : createCommentVNode()
657
- }
658
-
659
- const renderVN = () => {
660
- const { perfect, loading, refresh, zoom, custom, className } = props
661
- const vSize = computeSize.value
662
-
663
- return h(
664
- 'div',
665
- {
666
- ref: refElem,
667
- class: [
668
- 'vxe-toolbar',
669
- className ? (XEUtils.isFunction(className) ? className({ $toolbar: $xeToolbar }) : className) : '',
670
- {
671
- [`size--${vSize}`]: vSize,
672
- 'is--perfect': perfect,
673
- 'is--loading': loading
674
- }
675
- ]
676
- },
677
- [
678
- h(
679
- 'div',
680
- {
681
- class: 'vxe-buttons--wrapper'
682
- },
683
- renderLeftBtns()
684
- ),
685
- h(
686
- 'div',
687
- {
688
- class: 'vxe-tools--wrapper'
689
- },
690
- renderRightTools()
691
- ),
692
- h(
693
- 'div',
694
- {
695
- class: 'vxe-tools--operate'
696
- },
697
- [
698
- props.import ? renderToolImport() : createCommentVNode(),
699
- props.export ? renderToolExport() : createCommentVNode(),
700
- props.print ? renderToolPrint() : createCommentVNode(),
701
- refresh ? renderToolRefresh() : createCommentVNode(),
702
- zoom && $xeGGWrapper ? renderToolZoom() : createCommentVNode(),
703
- custom ? renderToolCustom() : createCommentVNode()
704
- ]
705
- )
706
- ]
707
- )
708
- }
709
-
710
- $xeToolbar.renderVN = renderVN
711
-
712
- nextTick(() => {
713
- const refreshOpts = computeRefreshOpts.value
714
- const queryMethod = refreshOpts.queryMethod || refreshOpts.query
715
- if (props.refresh && !$xeGGWrapper && !queryMethod) {
716
- warnLog('vxe.error.notFunc', ['queryMethod'])
717
- }
718
-
719
- if (XEUtils.isPlainObject(props.custom)) {
720
- warnLog('vxe.error.delProp', ['custom={...}', 'custom=boolean & custom-options={...}'])
721
- }
722
- if (XEUtils.isPlainObject(props.print)) {
723
- warnLog('vxe.error.delProp', ['print={...}', 'print=boolean & print-options={...}'])
724
- }
725
- if (XEUtils.isPlainObject(props.export)) {
726
- warnLog('vxe.error.delProp', ['export={...}', 'export=boolean & export-options={...}'])
727
- }
728
- if (XEUtils.isPlainObject(props.import)) {
729
- warnLog('vxe.error.delProp', ['import={...}', 'import=boolean & import-options={...}'])
730
- }
731
- if (XEUtils.isPlainObject(props.refresh)) {
732
- warnLog('vxe.error.delProp', ['refresh={...}', 'refresh=boolean & refresh-options={...}'])
733
- }
734
- if (XEUtils.isPlainObject(props.refresh)) {
735
- warnLog('vxe.error.delProp', ['zoom={...}', 'zoom=boolean & zoom-options={...}'])
736
- }
737
-
738
- const customOpts = computeCustomOpts.value
739
- if (customOpts.isFooter) {
740
- warnLog('vxe.error.delProp', ['toolbar.custom.isFooter', 'table.custom-config.showFooter'])
741
- }
742
- if (customOpts.showFooter) {
743
- warnLog('vxe.error.delProp', ['toolbar.custom.showFooter', 'table.custom-config.showFooter'])
744
- }
745
- if (customOpts.immediate) {
746
- warnLog('vxe.error.delProp', ['toolbar.custom.immediate', 'table.custom-config.immediate'])
747
- }
748
- if (customOpts.trigger) {
749
- warnLog('vxe.error.delProp', ['toolbar.custom.trigger', 'table.custom-config.trigger'])
750
- }
751
- if (props.refresh || props.import || props.export || props.print || props.zoom) {
752
- if (!VxeUIButtonComponent) {
753
- errLog('vxe.error.reqComp', ['vxe-button'])
754
- }
755
- }
756
- })
757
-
758
- onBeforeUnmount(() => {
759
- XEUtils.assign(reactData, createReactData())
760
- XEUtils.assign(internalData, createInternalData())
761
- })
762
-
763
- return $xeToolbar
764
- },
765
- render() {
766
- return this.renderVN()
767
- }
768
- }) /* define-vxe-component end */
1
+ import { h, ref, computed, inject, createCommentVNode, VNode, reactive, nextTick, PropType, onBeforeUnmount } from 'vue'
2
+ import { defineVxeComponent } from '../../ui/src/comp'
3
+ import XEUtils from 'xe-utils'
4
+ import { VxeUI } from '@vxe-ui/core'
5
+ import { getSlotVNs } from '../../ui/src/vn'
6
+ import { createComponentLog } from '../../ui/src/log'
7
+
8
+ import type { ValueOf, VxeButtonEvents, VxeComponentSlotType, VxeButtonDefines } from 'vxe-pc-ui'
9
+ import type { VxeGridConstructor, GridPrivateMethods, ToolbarMethods, ToolbarInternalData, VxeToolbarConstructor, VxeToolbarEmits, VxeToolbarPropTypes, ToolbarPrivateRef, ToolbarReactData, VxeTableConstructor, VxeTablePrivateMethods } from '../../../types'
10
+
11
+ const { warnLog, errLog } = createComponentLog('toolbar')
12
+
13
+ const { getConfig, getIcon, getI18n, renderer, commands, createEvent, useFns } = VxeUI
14
+
15
+ function createReactData(): ToolbarReactData {
16
+ return {
17
+ isRefresh: false,
18
+ connectFlag: 0,
19
+ columns: []
20
+ }
21
+ }
22
+
23
+ function createInternalData(): ToolbarInternalData {
24
+ return {
25
+ connectTable: null
26
+ }
27
+ }
28
+
29
+ export default /* define-vxe-component start */ defineVxeComponent({
30
+ name: 'VxeToolbar',
31
+ props: {
32
+ loading: Boolean,
33
+ refresh: [Boolean, Object] as PropType<VxeToolbarPropTypes.Refresh>,
34
+ refreshOptions: Object as PropType<VxeToolbarPropTypes.RefreshOptions>,
35
+ import: [Boolean, Object] as PropType<VxeToolbarPropTypes.Import>,
36
+ importOptions: Object as PropType<VxeToolbarPropTypes.ImportOptions>,
37
+ export: [Boolean, Object] as PropType<VxeToolbarPropTypes.Export>,
38
+ exportOptions: Object as PropType<VxeToolbarPropTypes.ExportOptions>,
39
+ print: [Boolean, Object] as PropType<VxeToolbarPropTypes.Print>,
40
+ printOptions: Object as PropType<VxeToolbarPropTypes.PrintOptions>,
41
+ zoom: [Boolean, Object] as PropType<VxeToolbarPropTypes.Zoom>,
42
+ zoomOptions: Object as PropType<VxeToolbarPropTypes.ZoomOptions>,
43
+ custom: [Boolean, Object] as PropType<VxeToolbarPropTypes.Custom>,
44
+ customOptions: Object as PropType<VxeToolbarPropTypes.CustomOptions>,
45
+ buttons: {
46
+ type: Array as PropType<VxeToolbarPropTypes.Buttons>,
47
+ default: () => getConfig().toolbar.buttons
48
+ },
49
+ tools: {
50
+ type: Array as PropType<VxeToolbarPropTypes.Tools>,
51
+ default: () => getConfig().toolbar.tools
52
+ },
53
+ perfect: {
54
+ type: Boolean as PropType<VxeToolbarPropTypes.Perfect>,
55
+ default: () => getConfig().toolbar.perfect
56
+ },
57
+ size: {
58
+ type: String as PropType<VxeToolbarPropTypes.Size>,
59
+ default: () => getConfig().toolbar.size || getConfig().size
60
+ },
61
+ className: [String, Function] as PropType<VxeToolbarPropTypes.ClassName>
62
+ },
63
+ emits: ['button-click', 'tool-click'] as VxeToolbarEmits,
64
+ setup(props, context) {
65
+ const { slots, emit } = context
66
+
67
+ const xID = XEUtils.uniqueId()
68
+
69
+ // 使用已安装的组件,如果未安装则不渲染
70
+ const VxeUIButtonComponent = VxeUI.getComponent('VxeButton')
71
+
72
+ const $xeGrid = inject<(VxeGridConstructor & GridPrivateMethods) | null>('$xeGrid', null)
73
+ const $xeGantt = inject('$xeGantt', null)
74
+ const $xeGGWrapper = $xeGrid || $xeGantt
75
+
76
+ const { computeSize } = useFns.useSize(props)
77
+
78
+ const reactData = reactive(createReactData())
79
+
80
+ const internalData = createInternalData()
81
+
82
+ const refElem = ref<HTMLDivElement>()
83
+
84
+ const refMaps: ToolbarPrivateRef = {
85
+ refElem
86
+ }
87
+
88
+ const $xeToolbar = {
89
+ xID,
90
+ props,
91
+ context,
92
+ reactData,
93
+ internalData,
94
+ getRefMaps: () => refMaps
95
+ } as unknown as VxeToolbarConstructor
96
+
97
+ let toolbarMethods = {} as ToolbarMethods
98
+
99
+ const computeRefreshOpts = computed(() => {
100
+ return Object.assign({}, XEUtils.clone(getConfig().toolbar.refresh, true), props.refreshOptions, props.refresh) as VxeToolbarPropTypes.RefreshOptions
101
+ })
102
+
103
+ const computeImportOpts = computed(() => {
104
+ return Object.assign({}, XEUtils.clone(getConfig().toolbar.import, true), props.importOptions, props.import) as VxeToolbarPropTypes.ImportOptions
105
+ })
106
+
107
+ const computeExportOpts = computed(() => {
108
+ return Object.assign({}, XEUtils.clone(getConfig().toolbar.export, true), props.exportOptions, props.export) as VxeToolbarPropTypes.ExportOptions
109
+ })
110
+
111
+ const computePrintOpts = computed(() => {
112
+ return Object.assign({}, XEUtils.clone(getConfig().toolbar.print, true), props.printOptions, props.print) as VxeToolbarPropTypes.PrintOptions
113
+ })
114
+
115
+ const computeZoomOpts = computed(() => {
116
+ return Object.assign({}, XEUtils.clone(getConfig().toolbar.zoom, true), props.zoomOptions, props.zoom) as VxeToolbarPropTypes.ZoomOptions
117
+ })
118
+
119
+ const computeCustomOpts = computed(() => {
120
+ return Object.assign({}, XEUtils.clone(getConfig().toolbar.custom, true), props.customOptions, props.custom) as VxeToolbarPropTypes.CustomOptions
121
+ })
122
+
123
+ const computeTableCustomOpts = computed(() => {
124
+ const { connectTable } = internalData
125
+ const $table = connectTable
126
+ if (reactData.connectFlag || $table) {
127
+ if ($table) {
128
+ const { computeCustomOpts } = $table.getComputeMaps()
129
+ return computeCustomOpts.value
130
+ }
131
+ }
132
+ return { trigger: '' }
133
+ })
134
+
135
+ const computeTrigger = computed(() => {
136
+ const tableCustomOpts = computeTableCustomOpts.value
137
+ return tableCustomOpts.trigger
138
+ })
139
+
140
+ const checkTable = () => {
141
+ const { connectTable } = internalData
142
+ const $table = connectTable
143
+ if ($table) {
144
+ return true
145
+ }
146
+ errLog('vxe.error.barUnableLink')
147
+ }
148
+
149
+ const handleClickSettingEvent = ({ $event }: any) => {
150
+ const { connectTable } = internalData
151
+ const $table = connectTable
152
+ if ($table) {
153
+ if ($table.triggerCustomEvent) {
154
+ $table.triggerCustomEvent($event)
155
+ }
156
+ }
157
+ }
158
+
159
+ const handleMouseenterSettingEvent = ({ $event }: any) => {
160
+ const { connectTable } = internalData
161
+ const $table = connectTable
162
+ if ($table) {
163
+ $table.customOpenEvent($event)
164
+ }
165
+ }
166
+
167
+ const handleMouseleaveSettingEvent = ({ $event }: any) => {
168
+ const { connectTable } = internalData
169
+ const $table = connectTable
170
+ if ($table) {
171
+ const { customStore } = $table.reactData
172
+ customStore.activeBtn = false
173
+ setTimeout(() => {
174
+ if (!customStore.activeBtn && !customStore.activeWrapper) {
175
+ $table.customCloseEvent($event)
176
+ }
177
+ }, 350)
178
+ }
179
+ }
180
+
181
+ const refreshEvent: VxeButtonEvents.Click = ({ $event }) => {
182
+ const { isRefresh } = reactData
183
+ const refreshOpts = computeRefreshOpts.value
184
+ if (!isRefresh) {
185
+ const queryMethod = refreshOpts.queryMethod || refreshOpts.query
186
+ if (queryMethod) {
187
+ reactData.isRefresh = true
188
+ try {
189
+ Promise.resolve(queryMethod({}))
190
+ .catch((e) => e)
191
+ .then(() => {
192
+ reactData.isRefresh = false
193
+ })
194
+ } catch (e) {
195
+ reactData.isRefresh = false
196
+ }
197
+ } else if ($xeGGWrapper) {
198
+ reactData.isRefresh = true
199
+ $xeGGWrapper
200
+ .triggerToolbarCommitEvent({ code: refreshOpts.code || 'reload' }, $event)
201
+ .catch(() => {})
202
+ .then(() => {
203
+ reactData.isRefresh = false
204
+ })
205
+ }
206
+ }
207
+ }
208
+
209
+ const zoomEvent: VxeButtonEvents.Click = ({ $event }) => {
210
+ if ($xeGGWrapper) {
211
+ $xeGGWrapper.triggerZoomEvent($event)
212
+ } else {
213
+ warnLog('vxe.error.notProp', ['zoom'])
214
+ }
215
+ }
216
+
217
+ const importEvent = () => {
218
+ if (checkTable()) {
219
+ const { connectTable } = internalData
220
+ const $table = connectTable
221
+ if ($table) {
222
+ $table.importData()
223
+ }
224
+ }
225
+ }
226
+
227
+ const openImportEvent = () => {
228
+ if (checkTable()) {
229
+ const { connectTable } = internalData
230
+ const $table = connectTable
231
+ if ($table) {
232
+ $table.openImport()
233
+ }
234
+ }
235
+ }
236
+
237
+ const exportEvent = () => {
238
+ if (checkTable()) {
239
+ const { connectTable } = internalData
240
+ const $table = connectTable
241
+ if ($table) {
242
+ $table.exportData()
243
+ }
244
+ }
245
+ }
246
+
247
+ const openExportEvent = () => {
248
+ if (checkTable()) {
249
+ const { connectTable } = internalData
250
+ const $table = connectTable
251
+ if ($table) {
252
+ $table.openExport()
253
+ }
254
+ }
255
+ }
256
+
257
+ const printEvent = () => {
258
+ if (checkTable()) {
259
+ const { connectTable } = internalData
260
+ const $table = connectTable
261
+ if ($table) {
262
+ $table.print()
263
+ }
264
+ }
265
+ }
266
+
267
+ const openPrintEvent = () => {
268
+ if (checkTable()) {
269
+ const { connectTable } = internalData
270
+ const $table = connectTable
271
+ if ($table) {
272
+ $table.openPrint()
273
+ }
274
+ }
275
+ }
276
+
277
+ const handleDefaultCodeEvent = (eventParams: VxeButtonDefines.ClickEventParams, item: VxeToolbarPropTypes.ButtonConfig | VxeToolbarPropTypes.ToolConfig, cb: () => void) => {
278
+ switch (item.code) {
279
+ case 'print':
280
+ printEvent()
281
+ break
282
+ case 'open_print':
283
+ openPrintEvent()
284
+ break
285
+ case 'custom':
286
+ handleClickSettingEvent(eventParams)
287
+ break
288
+ case 'export':
289
+ exportEvent()
290
+ break
291
+ case 'open_export':
292
+ openExportEvent()
293
+ break
294
+ case 'import':
295
+ importEvent()
296
+ break
297
+ case 'open_import':
298
+ openImportEvent()
299
+ break
300
+ case 'zoom':
301
+ zoomEvent(eventParams)
302
+ break
303
+ case 'refresh':
304
+ refreshEvent(eventParams)
305
+ break
306
+ default:
307
+ cb()
308
+ break
309
+ }
310
+ }
311
+
312
+ const btnEvent = (eventParams: VxeButtonDefines.ClickEventParams, item: VxeToolbarPropTypes.ButtonConfig) => {
313
+ const { $event } = eventParams
314
+ const { connectTable } = internalData
315
+ const $table = connectTable
316
+ const { code } = item
317
+ if (code) {
318
+ handleDefaultCodeEvent(eventParams, item, () => {
319
+ if ($xeGGWrapper) {
320
+ $xeGGWrapper.triggerToolbarBtnEvent(item, $event)
321
+ } else {
322
+ const gCommandOpts = commands.get(code)
323
+ const params = { code, button: item, $table: $table as VxeTableConstructor, $grid: $xeGrid, $gantt: $xeGantt, $event }
324
+ if (gCommandOpts) {
325
+ const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
326
+ if (tCommandMethod) {
327
+ tCommandMethod(params)
328
+ } else {
329
+ errLog('vxe.error.notCommands', [code])
330
+ }
331
+ }
332
+ $xeToolbar.dispatchEvent('button-click', params, $event)
333
+ }
334
+ })
335
+ }
336
+ }
337
+
338
+ const tolEvent = (eventParams: VxeButtonDefines.ClickEventParams, item: VxeToolbarPropTypes.ToolConfig) => {
339
+ const { $event } = eventParams
340
+ const { connectTable } = internalData
341
+ const $table = connectTable
342
+ const { code } = item
343
+ if (code) {
344
+ handleDefaultCodeEvent(eventParams, item, () => {
345
+ if ($xeGGWrapper) {
346
+ $xeGGWrapper.triggerToolbarTolEvent(item, $event)
347
+ } else {
348
+ const gCommandOpts = commands.get(code)
349
+ const params = { code, button: null, tool: item, $table: $table as VxeTableConstructor, $grid: $xeGrid, $gantt: $xeGantt, $event }
350
+ if (gCommandOpts) {
351
+ const tCommandMethod = gCommandOpts.tableCommandMethod || gCommandOpts.commandMethod
352
+ if (tCommandMethod) {
353
+ tCommandMethod(params)
354
+ } else {
355
+ errLog('vxe.error.notCommands', [code])
356
+ }
357
+ }
358
+ $xeToolbar.dispatchEvent('tool-click', params, $event)
359
+ }
360
+ })
361
+ }
362
+ }
363
+
364
+ const dispatchEvent = (type: ValueOf<VxeToolbarEmits>, params: Record<string, any>, evnt: Event | null) => {
365
+ emit(type, createEvent(evnt, { $toolbar: $xeToolbar }, params))
366
+ }
367
+
368
+ toolbarMethods = {
369
+ dispatchEvent,
370
+ syncUpdate(params) {
371
+ internalData.connectTable = params.$table as VxeTableConstructor & VxeTablePrivateMethods
372
+ reactData.columns = params.collectColumn
373
+ reactData.connectFlag++
374
+ }
375
+ }
376
+
377
+ Object.assign($xeToolbar, toolbarMethods)
378
+
379
+ const renderDropdowns = (item: VxeToolbarPropTypes.ButtonConfig, isBtn: boolean) => {
380
+ const { dropdowns } = item
381
+ const downVNs: VNode[] = []
382
+ if (dropdowns) {
383
+ return dropdowns.map((child, index) => {
384
+ if (child.visible === false) {
385
+ return createCommentVNode()
386
+ }
387
+ return VxeUIButtonComponent
388
+ ? h(VxeUIButtonComponent, {
389
+ key: index,
390
+ ...Object.assign({}, child, {
391
+ content: child.content || child.name,
392
+ options: undefined
393
+ }),
394
+ onClick: (eventParams) => (isBtn ? btnEvent(eventParams, child) : tolEvent(eventParams, child))
395
+ })
396
+ : createCommentVNode()
397
+ })
398
+ }
399
+ return downVNs
400
+ }
401
+
402
+ /**
403
+ * 渲染按钮
404
+ */
405
+ const renderLeftBtns = () => {
406
+ const { buttons } = props
407
+ const { connectTable } = internalData
408
+ const $table = connectTable
409
+ const buttonsSlot = slots.buttons
410
+ const buttonPrefixSlot = slots.buttonPrefix || slots['button-prefix']
411
+ const buttonSuffixSlot = slots.buttonSuffix || slots['button-suffix']
412
+ const btnVNs: VxeComponentSlotType[] = []
413
+ if (buttons) {
414
+ const { computeRendererOpts } = $table ? $table.getComputeMaps() : {}
415
+ const rendererOpts = (computeRendererOpts ? computeRendererOpts.value : null) || {}
416
+ buttons.forEach((item, index) => {
417
+ const { dropdowns, buttonRender } = item
418
+ if (item.visible !== false) {
419
+ const compConf = buttonRender && buttonRender.name ? rendererOpts[buttonRender.name] || renderer.get(buttonRender.name) : null
420
+ if (buttonRender && compConf && compConf.renderToolbarButton) {
421
+ const toolbarButtonClassName = compConf.toolbarButtonClassName
422
+ const params = { $grid: $xeGrid, $gantt: $xeGantt, $table: $table!, button: item }
423
+ btnVNs.push(
424
+ h(
425
+ 'span',
426
+ {
427
+ key: `br${item.code || index}`,
428
+ class: ['vxe-button--item', toolbarButtonClassName ? (XEUtils.isFunction(toolbarButtonClassName) ? toolbarButtonClassName(params) : toolbarButtonClassName) : '']
429
+ },
430
+ getSlotVNs(compConf.renderToolbarButton(buttonRender, params))
431
+ )
432
+ )
433
+ } else {
434
+ if (VxeUIButtonComponent) {
435
+ btnVNs.push(
436
+ h(
437
+ VxeUIButtonComponent,
438
+ {
439
+ key: `bd${item.code || index}`,
440
+ ...Object.assign({}, item, {
441
+ content: item.content || item.name,
442
+ options: undefined
443
+ }),
444
+ onClick: (eventParams) => btnEvent(eventParams, item)
445
+ },
446
+ dropdowns && dropdowns.length
447
+ ? {
448
+ dropdowns: () => renderDropdowns(item, true)
449
+ }
450
+ : {}
451
+ )
452
+ )
453
+ }
454
+ }
455
+ }
456
+ })
457
+ }
458
+ return [
459
+ h(
460
+ 'div',
461
+ {
462
+ class: 'vxe-button--prefix-wrapper'
463
+ },
464
+ buttonPrefixSlot ? getSlotVNs(buttonPrefixSlot({ buttons: buttons || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
465
+ ),
466
+ h(
467
+ 'div',
468
+ {
469
+ class: 'vxe-button--item-wrapper'
470
+ },
471
+ buttonsSlot ? getSlotVNs(buttonsSlot({ buttons: buttons || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : btnVNs
472
+ ),
473
+ h(
474
+ 'div',
475
+ {
476
+ class: 'vxe-button--suffix-wrapper'
477
+ },
478
+ buttonSuffixSlot ? getSlotVNs(buttonSuffixSlot({ buttons: buttons || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
479
+ )
480
+ ]
481
+ }
482
+
483
+ /**
484
+ * 渲染右侧工具
485
+ */
486
+ const renderRightTools = () => {
487
+ const { tools } = props
488
+ const { connectTable } = internalData
489
+ const $table = connectTable
490
+ const toolsSlot = slots.tools
491
+ const toolPrefixSlot = slots.toolPrefix || slots['tool-prefix']
492
+ const toolSuffixSlot = slots.toolSuffix || slots['tool-suffix']
493
+ const btnVNs: VxeComponentSlotType[] = []
494
+ if (tools) {
495
+ const { computeRendererOpts } = $table ? $table.getComputeMaps() : {}
496
+ const rendererOpts = (computeRendererOpts ? computeRendererOpts.value : null) || {}
497
+ tools.forEach((item, tIndex) => {
498
+ const { dropdowns, toolRender } = item
499
+ if (item.visible !== false) {
500
+ const compConf = toolRender && toolRender.name ? rendererOpts[toolRender.name] || renderer.get(toolRender.name) : null
501
+ if (toolRender && compConf && compConf.renderToolbarTool) {
502
+ const toolbarToolClassName = compConf.toolbarToolClassName
503
+ const params = { $grid: $xeGrid, $gantt: $xeGantt, $table: $table!, tool: item }
504
+ btnVNs.push(
505
+ h(
506
+ 'span',
507
+ {
508
+ key: tIndex,
509
+ class: ['vxe-tool--item', toolbarToolClassName ? (XEUtils.isFunction(toolbarToolClassName) ? toolbarToolClassName(params) : toolbarToolClassName) : '']
510
+ },
511
+ getSlotVNs(compConf.renderToolbarTool(toolRender, params))
512
+ )
513
+ )
514
+ } else {
515
+ if (VxeUIButtonComponent) {
516
+ btnVNs.push(
517
+ h(
518
+ VxeUIButtonComponent,
519
+ {
520
+ key: tIndex,
521
+ ...Object.assign({}, item, {
522
+ content: item.content || item.name,
523
+ options: undefined
524
+ }),
525
+ onClick: (eventParams) => tolEvent(eventParams, item)
526
+ },
527
+ dropdowns && dropdowns.length
528
+ ? {
529
+ dropdowns: () => renderDropdowns(item, false)
530
+ }
531
+ : {}
532
+ )
533
+ )
534
+ }
535
+ }
536
+ }
537
+ })
538
+ }
539
+ return [
540
+ h(
541
+ 'div',
542
+ {
543
+ class: 'vxe-tool--prefix-wrapper'
544
+ },
545
+ toolPrefixSlot ? getSlotVNs(toolPrefixSlot({ tools: tools || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
546
+ ),
547
+ h(
548
+ 'div',
549
+ {
550
+ class: 'vxe-tool--item-wrapper'
551
+ },
552
+ toolsSlot ? getSlotVNs(toolsSlot({ tools: tools || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : btnVNs
553
+ ),
554
+ h(
555
+ 'div',
556
+ {
557
+ class: 'vxe-tool--suffix-wrapper'
558
+ },
559
+ toolSuffixSlot ? getSlotVNs(toolSuffixSlot({ tools: tools || [], $grid: $xeGrid, $gantt: $xeGantt, $table: $table })) : []
560
+ )
561
+ ]
562
+ }
563
+
564
+ const renderToolImport = () => {
565
+ const importOpts = computeImportOpts.value
566
+ return VxeUIButtonComponent
567
+ ? h(VxeUIButtonComponent, {
568
+ key: 'import',
569
+ circle: true,
570
+ icon: importOpts.icon || getIcon().TOOLBAR_TOOLS_IMPORT,
571
+ title: getI18n('vxe.toolbar.import'),
572
+ onClick: openImportEvent
573
+ })
574
+ : createCommentVNode()
575
+ }
576
+
577
+ const renderToolExport = () => {
578
+ const exportOpts = computeExportOpts.value
579
+ return VxeUIButtonComponent
580
+ ? h(VxeUIButtonComponent, {
581
+ key: 'export',
582
+ circle: true,
583
+ icon: exportOpts.icon || getIcon().TOOLBAR_TOOLS_EXPORT,
584
+ title: getI18n('vxe.toolbar.export'),
585
+ onClick: openExportEvent
586
+ })
587
+ : createCommentVNode()
588
+ }
589
+
590
+ const renderToolPrint = () => {
591
+ const printOpts = computePrintOpts.value
592
+ return VxeUIButtonComponent
593
+ ? h(VxeUIButtonComponent, {
594
+ key: 'print',
595
+ circle: true,
596
+ icon: printOpts.icon || getIcon().TOOLBAR_TOOLS_PRINT,
597
+ title: getI18n('vxe.toolbar.print'),
598
+ onClick: openPrintEvent
599
+ })
600
+ : createCommentVNode()
601
+ }
602
+
603
+ const renderToolRefresh = () => {
604
+ const refreshOpts = computeRefreshOpts.value
605
+ return VxeUIButtonComponent
606
+ ? h(VxeUIButtonComponent, {
607
+ key: 'refresh',
608
+ circle: true,
609
+ icon: reactData.isRefresh ? refreshOpts.iconLoading || getIcon().TOOLBAR_TOOLS_REFRESH_LOADING : refreshOpts.icon || getIcon().TOOLBAR_TOOLS_REFRESH,
610
+ title: getI18n('vxe.toolbar.refresh'),
611
+ onClick: refreshEvent
612
+ })
613
+ : createCommentVNode()
614
+ }
615
+
616
+ const renderToolZoom = () => {
617
+ const zoomOpts = computeZoomOpts.value
618
+ return $xeGGWrapper && VxeUIButtonComponent
619
+ ? h(VxeUIButtonComponent, {
620
+ key: 'zoom',
621
+ circle: true,
622
+ icon: $xeGGWrapper.isMaximized() ? zoomOpts.iconOut || getIcon().TOOLBAR_TOOLS_MINIMIZE : zoomOpts.iconIn || getIcon().TOOLBAR_TOOLS_FULLSCREEN,
623
+ title: getI18n(`vxe.toolbar.zoom${$xeGGWrapper.isMaximized() ? 'Out' : 'In'}`),
624
+ onClick: zoomEvent
625
+ })
626
+ : createCommentVNode()
627
+ }
628
+
629
+ const renderToolCustom = () => {
630
+ const customOpts = computeCustomOpts.value
631
+ const btnTrigger = computeTrigger.value
632
+ const customBtnOns: {
633
+ onClick?: typeof handleClickSettingEvent
634
+ onMouseenter?: typeof handleMouseenterSettingEvent
635
+ onMouseleave?: typeof handleMouseleaveSettingEvent
636
+ } = {}
637
+ if (btnTrigger === 'manual') {
638
+ // 手动触发
639
+ } else if (btnTrigger === 'hover') {
640
+ // hover 触发
641
+ customBtnOns.onMouseenter = handleMouseenterSettingEvent
642
+ customBtnOns.onMouseleave = handleMouseleaveSettingEvent
643
+ } else {
644
+ // 点击触发
645
+ customBtnOns.onClick = handleClickSettingEvent
646
+ }
647
+ return VxeUIButtonComponent
648
+ ? h(VxeUIButtonComponent, {
649
+ key: 'custom',
650
+ circle: true,
651
+ icon: customOpts.icon || getIcon().TOOLBAR_TOOLS_CUSTOM,
652
+ title: getI18n('vxe.toolbar.custom'),
653
+ className: 'vxe-toolbar-custom-target',
654
+ ...customBtnOns
655
+ })
656
+ : createCommentVNode()
657
+ }
658
+
659
+ const renderVN = () => {
660
+ const { perfect, loading, refresh, zoom, custom, className } = props
661
+ const vSize = computeSize.value
662
+
663
+ return h(
664
+ 'div',
665
+ {
666
+ ref: refElem,
667
+ class: [
668
+ 'vxe-toolbar',
669
+ className ? (XEUtils.isFunction(className) ? className({ $toolbar: $xeToolbar }) : className) : '',
670
+ {
671
+ [`size--${vSize}`]: vSize,
672
+ 'is--perfect': perfect,
673
+ 'is--loading': loading
674
+ }
675
+ ]
676
+ },
677
+ [
678
+ h(
679
+ 'div',
680
+ {
681
+ class: 'vxe-buttons--wrapper'
682
+ },
683
+ renderLeftBtns()
684
+ ),
685
+ h(
686
+ 'div',
687
+ {
688
+ class: 'vxe-tools--wrapper'
689
+ },
690
+ renderRightTools()
691
+ ),
692
+ h(
693
+ 'div',
694
+ {
695
+ class: 'vxe-tools--operate'
696
+ },
697
+ [
698
+ props.import ? renderToolImport() : createCommentVNode(),
699
+ props.export ? renderToolExport() : createCommentVNode(),
700
+ props.print ? renderToolPrint() : createCommentVNode(),
701
+ refresh ? renderToolRefresh() : createCommentVNode(),
702
+ zoom && $xeGGWrapper ? renderToolZoom() : createCommentVNode(),
703
+ custom ? renderToolCustom() : createCommentVNode()
704
+ ]
705
+ )
706
+ ]
707
+ )
708
+ }
709
+
710
+ $xeToolbar.renderVN = renderVN
711
+
712
+ nextTick(() => {
713
+ const refreshOpts = computeRefreshOpts.value
714
+ const queryMethod = refreshOpts.queryMethod || refreshOpts.query
715
+ if (props.refresh && !$xeGGWrapper && !queryMethod) {
716
+ warnLog('vxe.error.notFunc', ['queryMethod'])
717
+ }
718
+
719
+ if (XEUtils.isPlainObject(props.custom)) {
720
+ warnLog('vxe.error.delProp', ['custom={...}', 'custom=boolean & custom-options={...}'])
721
+ }
722
+ if (XEUtils.isPlainObject(props.print)) {
723
+ warnLog('vxe.error.delProp', ['print={...}', 'print=boolean & print-options={...}'])
724
+ }
725
+ if (XEUtils.isPlainObject(props.export)) {
726
+ warnLog('vxe.error.delProp', ['export={...}', 'export=boolean & export-options={...}'])
727
+ }
728
+ if (XEUtils.isPlainObject(props.import)) {
729
+ warnLog('vxe.error.delProp', ['import={...}', 'import=boolean & import-options={...}'])
730
+ }
731
+ if (XEUtils.isPlainObject(props.refresh)) {
732
+ warnLog('vxe.error.delProp', ['refresh={...}', 'refresh=boolean & refresh-options={...}'])
733
+ }
734
+ if (XEUtils.isPlainObject(props.refresh)) {
735
+ warnLog('vxe.error.delProp', ['zoom={...}', 'zoom=boolean & zoom-options={...}'])
736
+ }
737
+
738
+ const customOpts = computeCustomOpts.value
739
+ if (customOpts.isFooter) {
740
+ warnLog('vxe.error.delProp', ['toolbar.custom.isFooter', 'table.custom-config.showFooter'])
741
+ }
742
+ if (customOpts.showFooter) {
743
+ warnLog('vxe.error.delProp', ['toolbar.custom.showFooter', 'table.custom-config.showFooter'])
744
+ }
745
+ if (customOpts.immediate) {
746
+ warnLog('vxe.error.delProp', ['toolbar.custom.immediate', 'table.custom-config.immediate'])
747
+ }
748
+ if (customOpts.trigger) {
749
+ warnLog('vxe.error.delProp', ['toolbar.custom.trigger', 'table.custom-config.trigger'])
750
+ }
751
+ if (props.refresh || props.import || props.export || props.print || props.zoom) {
752
+ if (!VxeUIButtonComponent) {
753
+ errLog('vxe.error.reqComp', ['vxe-button'])
754
+ }
755
+ }
756
+ })
757
+
758
+ onBeforeUnmount(() => {
759
+ XEUtils.assign(reactData, createReactData())
760
+ XEUtils.assign(internalData, createInternalData())
761
+ })
762
+
763
+ return $xeToolbar
764
+ },
765
+ render() {
766
+ return this.renderVN()
767
+ }
768
+ }) /* define-vxe-component end */