vxe-table 4.19.0-beta.2 → 4.19.0-beta.3

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