vxe-table 4.18.6 → 4.18.8

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 (148) 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/src/table.js +89 -79
  8. package/es/table/src/util.js +6 -0
  9. package/es/table/style.css +18 -48
  10. package/es/ui/index.js +1 -1
  11. package/es/ui/src/dom.js +21 -0
  12. package/es/ui/src/log.js +1 -1
  13. package/es/vxe-table/style.css +18 -48
  14. package/lib/index.common.js +2 -1
  15. package/lib/index.umd.js +2762 -2833
  16. package/lib/index.umd.min.js +1 -1
  17. package/lib/style.css +1 -1
  18. package/lib/table/src/table.js +15 -12
  19. package/lib/table/src/table.min.js +1 -1
  20. package/lib/table/src/util.js +6 -0
  21. package/lib/table/src/util.min.js +1 -1
  22. package/lib/table/style/style.css +18 -48
  23. package/lib/ui/index.js +1 -1
  24. package/lib/ui/index.min.js +1 -1
  25. package/lib/ui/src/dom.js +23 -0
  26. package/lib/ui/src/dom.min.js +1 -1
  27. package/lib/ui/src/log.js +1 -1
  28. package/lib/ui/src/log.min.js +1 -1
  29. package/lib/v-x-e-table/index.js +2 -1
  30. package/lib/v-x-e-table/index.min.js +1 -1
  31. package/lib/vxe-colgroup/index.js +2 -1
  32. package/lib/vxe-colgroup/index.min.js +1 -1
  33. package/lib/vxe-column/index.js +2 -1
  34. package/lib/vxe-column/index.min.js +1 -1
  35. package/lib/vxe-grid/index.js +2 -1
  36. package/lib/vxe-grid/index.min.js +1 -1
  37. package/lib/vxe-table/index.js +2 -1
  38. package/lib/vxe-table/index.min.js +1 -1
  39. package/lib/vxe-table/style/style.css +18 -48
  40. package/lib/vxe-toolbar/index.js +2 -1
  41. package/lib/vxe-toolbar/index.min.js +1 -1
  42. package/lib/vxe-ui/index.js +2 -1
  43. package/lib/vxe-ui/index.min.js +1 -1
  44. package/lib/vxe-v-x-e-table/index.js +2 -1
  45. package/lib/vxe-v-x-e-table/index.min.js +1 -1
  46. package/package.json +91 -91
  47. package/packages/colgroup/index.ts +22 -22
  48. package/packages/column/index.ts +22 -22
  49. package/packages/components.ts +43 -43
  50. package/packages/grid/index.ts +18 -18
  51. package/packages/grid/src/emits.ts +19 -19
  52. package/packages/grid/src/grid.ts +1768 -1768
  53. package/packages/grid/src/props.ts +23 -23
  54. package/packages/index.ts +4 -4
  55. package/packages/locale/lang/ar-EG.ts +832 -832
  56. package/packages/locale/lang/de-DE.ts +832 -832
  57. package/packages/locale/lang/en-US.ts +832 -832
  58. package/packages/locale/lang/es-ES.ts +832 -832
  59. package/packages/locale/lang/fr-FR.ts +832 -832
  60. package/packages/locale/lang/hu-HU.ts +832 -832
  61. package/packages/locale/lang/hy-AM.ts +832 -832
  62. package/packages/locale/lang/id-ID.ts +832 -832
  63. package/packages/locale/lang/it-IT.ts +832 -832
  64. package/packages/locale/lang/ja-JP.ts +832 -832
  65. package/packages/locale/lang/ko-KR.ts +832 -832
  66. package/packages/locale/lang/ms-MY.ts +832 -832
  67. package/packages/locale/lang/nb-NO.ts +832 -832
  68. package/packages/locale/lang/pt-BR.ts +832 -832
  69. package/packages/locale/lang/ru-RU.ts +832 -832
  70. package/packages/locale/lang/th-TH.ts +832 -832
  71. package/packages/locale/lang/ug-CN.ts +832 -832
  72. package/packages/locale/lang/uk-UA.ts +832 -832
  73. package/packages/locale/lang/uz-UZ.ts +832 -832
  74. package/packages/locale/lang/vi-VN.ts +832 -832
  75. package/packages/locale/lang/zh-CHT.ts +832 -832
  76. package/packages/locale/lang/zh-CN.ts +832 -832
  77. package/packages/locale/lang/zh-HK.ts +3 -3
  78. package/packages/locale/lang/zh-MO.ts +3 -3
  79. package/packages/locale/lang/zh-TC.ts +3 -3
  80. package/packages/locale/lang/zh-TW.ts +3 -3
  81. package/packages/table/index.ts +26 -26
  82. package/packages/table/module/custom/hook.ts +359 -359
  83. package/packages/table/module/custom/panel.ts +1331 -1331
  84. package/packages/table/module/edit/hook.ts +1032 -1032
  85. package/packages/table/module/export/export-panel.ts +567 -567
  86. package/packages/table/module/export/hook.ts +1654 -1654
  87. package/packages/table/module/export/import-panel.ts +266 -266
  88. package/packages/table/module/export/util.ts +24 -24
  89. package/packages/table/module/filter/hook.ts +468 -468
  90. package/packages/table/module/filter/panel.ts +301 -301
  91. package/packages/table/module/keyboard/hook.ts +495 -495
  92. package/packages/table/module/menu/hook.ts +325 -325
  93. package/packages/table/module/menu/panel.ts +201 -201
  94. package/packages/table/module/validator/hook.ts +631 -631
  95. package/packages/table/render/index.ts +1440 -1440
  96. package/packages/table/src/body.ts +932 -932
  97. package/packages/table/src/cell.ts +1290 -1290
  98. package/packages/table/src/column.ts +190 -190
  99. package/packages/table/src/columnInfo.ts +225 -225
  100. package/packages/table/src/emits.ts +123 -123
  101. package/packages/table/src/footer.ts +368 -368
  102. package/packages/table/src/group.ts +59 -59
  103. package/packages/table/src/header.ts +559 -559
  104. package/packages/table/src/props.ts +324 -324
  105. package/packages/table/src/store.ts +14 -14
  106. package/packages/table/src/table.ts +14010 -14001
  107. package/packages/table/src/use/cell-view.ts +44 -44
  108. package/packages/table/src/use/index.ts +1 -1
  109. package/packages/table/src/util.ts +1070 -1064
  110. package/packages/toolbar/index.ts +18 -18
  111. package/packages/toolbar/src/toolbar.ts +701 -701
  112. package/packages/ui/index.ts +530 -530
  113. package/packages/ui/src/anime.ts +52 -52
  114. package/packages/ui/src/comp.ts +3 -3
  115. package/packages/ui/src/dom.ts +259 -236
  116. package/packages/ui/src/log.ts +8 -8
  117. package/packages/ui/src/utils.ts +56 -56
  118. package/packages/ui/src/vn.ts +55 -55
  119. package/packages/v-x-e-table/index.d.ts +4 -4
  120. package/packages/v-x-e-table/index.ts +4 -4
  121. package/styles/all.scss +7 -7
  122. package/styles/base.scss +16 -16
  123. package/styles/components/grid.scss +89 -89
  124. package/styles/components/icon.scss +225 -225
  125. package/styles/components/old-icon.scss +715 -715
  126. package/styles/components/table-module/all.scss +6 -6
  127. package/styles/components/table-module/custom.scss +527 -527
  128. package/styles/components/table-module/export.scss +130 -130
  129. package/styles/components/table-module/filter.scss +130 -130
  130. package/styles/components/table-module/menu.scss +81 -81
  131. package/styles/components/table.scss +2679 -2679
  132. package/styles/components/toolbar.scss +119 -119
  133. package/styles/default.scss +2 -2
  134. package/styles/helpers/baseMixin.scss +95 -95
  135. package/styles/index.scss +4 -4
  136. package/styles/modules.scss +5 -5
  137. package/styles/theme/base.scss +93 -93
  138. package/styles/theme/dark.scss +49 -49
  139. package/styles/theme/light.scss +44 -44
  140. package/styles/variable.scss +43 -43
  141. package/types/all.d.ts +37 -37
  142. package/types/index.d.ts +4 -4
  143. /package/es/{iconfont.1773972993993.ttf → iconfont.1774240404046.ttf} +0 -0
  144. /package/es/{iconfont.1773972993993.woff → iconfont.1774240404046.woff} +0 -0
  145. /package/es/{iconfont.1773972993993.woff2 → iconfont.1774240404046.woff2} +0 -0
  146. /package/lib/{iconfont.1773972993993.ttf → iconfont.1774240404046.ttf} +0 -0
  147. /package/lib/{iconfont.1773972993993.woff → iconfont.1774240404046.woff} +0 -0
  148. /package/lib/{iconfont.1773972993993.woff2 → iconfont.1774240404046.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
+ })