vxe-table 4.23.8 → 4.23.10

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