@meethive/components 0.0.3 → 0.0.5

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 (111) hide show
  1. package/es/AutoComplete/AutoComplete.js +71 -80
  2. package/es/BadgeStatus/Badge.js +38 -47
  3. package/es/CardSelect/CardSelect.js +115 -137
  4. package/es/CheckButton/CheckButton.js +102 -118
  5. package/es/ConfigProvider/ConfigProvider.js +44 -68
  6. package/es/DragModal/DragModal.js +191 -212
  7. package/es/EditTable/Body.js +158 -189
  8. package/es/EditTable/CellRender.js +10 -12
  9. package/es/EditTable/EditTable.js +385 -434
  10. package/es/EditTable/FormItem.js +140 -169
  11. package/es/EditTable/Group.js +171 -204
  12. package/es/EditTable/Header.js +57 -63
  13. package/es/EditTable/HeaderRender.js +10 -12
  14. package/es/EditTable/components/ContextMenu/Menu.js +78 -86
  15. package/es/EditTable/components/Search/Search.js +151 -163
  16. package/es/EditTable/components/Search/Sort.js +104 -119
  17. package/es/Ellipsis/Ellipsis.js +144 -148
  18. package/es/Empty/Empty.js +51 -57
  19. package/es/FullPage/FullPage.js +20 -19
  20. package/es/Icon/Icon.js +42 -49
  21. package/es/LocaleProvider/LocaleProvider.js +32 -38
  22. package/es/Markdown/Markdown.js +101 -118
  23. package/es/PermissionButton/PermissionButton.js +118 -118
  24. package/es/ProLayout/Basic/BasicLayout.js +361 -418
  25. package/es/ProLayout/Basic/Header.js +97 -111
  26. package/es/ProLayout/PageContainer/index.js +298 -344
  27. package/es/ProLayout/SiderMenu/BaseMenu.js +233 -240
  28. package/es/ProTable/Alert.js +39 -40
  29. package/es/ProTable/Content.js +84 -97
  30. package/es/ProTable/Header.js +32 -33
  31. package/es/ProTable/Pagination.js +56 -55
  32. package/es/ProTable/ProTable.js +256 -276
  33. package/es/RadioButton/RadioButton.js +48 -53
  34. package/es/Scrollbar/Bar.js +65 -76
  35. package/es/Scrollbar/Scrollbar.js +129 -161
  36. package/es/Scrollbar/Thumb.js +101 -150
  37. package/es/Search/Item.js +208 -236
  38. package/es/Search/Search.js +90 -90
  39. package/es/Skeleton/Skeleton.js +26 -27
  40. package/es/Skeleton/components/DashBoardCard.js +26 -27
  41. package/es/Skeleton/components/DashBoardChart.js +26 -27
  42. package/es/Skeleton/components/Detail.js +26 -27
  43. package/es/Skeleton/components/Drawer.js +26 -27
  44. package/es/Skeleton/components/Item.js +55 -54
  45. package/es/Skeleton/components/List.js +29 -27
  46. package/es/Skeleton/components/ListCard.js +28 -28
  47. package/es/Skeleton/components/ListCardItem.js +20 -20
  48. package/es/Skeleton/components/ListTable.js +26 -27
  49. package/es/Skeleton/components/Page.js +27 -26
  50. package/es/Skeleton/components/Search.js +16 -16
  51. package/es/Skeleton/components/Tree.js +26 -27
  52. package/es/TimeFormat/TimeFormat.js +32 -36
  53. package/es/Title/Title.js +23 -26
  54. package/es/ValueItem/ValueItem.js +100 -113
  55. package/es/VirtualTable/VirtualTable.js +235 -271
  56. package/lib/AutoComplete/AutoComplete.js +71 -80
  57. package/lib/BadgeStatus/Badge.js +38 -47
  58. package/lib/CardSelect/CardSelect.js +115 -137
  59. package/lib/CheckButton/CheckButton.js +102 -118
  60. package/lib/ConfigProvider/ConfigProvider.js +44 -68
  61. package/lib/DragModal/DragModal.js +191 -212
  62. package/lib/EditTable/Body.js +158 -189
  63. package/lib/EditTable/CellRender.js +10 -12
  64. package/lib/EditTable/EditTable.js +385 -434
  65. package/lib/EditTable/FormItem.js +140 -169
  66. package/lib/EditTable/Group.js +171 -204
  67. package/lib/EditTable/Header.js +57 -63
  68. package/lib/EditTable/HeaderRender.js +10 -12
  69. package/lib/EditTable/components/ContextMenu/Menu.js +78 -86
  70. package/lib/EditTable/components/Search/Search.js +151 -163
  71. package/lib/EditTable/components/Search/Sort.js +104 -119
  72. package/lib/Ellipsis/Ellipsis.js +144 -148
  73. package/lib/Empty/Empty.js +51 -57
  74. package/lib/FullPage/FullPage.js +20 -19
  75. package/lib/Icon/Icon.js +42 -49
  76. package/lib/LocaleProvider/LocaleProvider.js +32 -38
  77. package/lib/Markdown/Markdown.js +101 -118
  78. package/lib/PermissionButton/PermissionButton.js +118 -118
  79. package/lib/ProLayout/Basic/BasicLayout.js +361 -418
  80. package/lib/ProLayout/Basic/Header.js +97 -111
  81. package/lib/ProLayout/PageContainer/index.js +298 -344
  82. package/lib/ProLayout/SiderMenu/BaseMenu.js +233 -240
  83. package/lib/ProTable/Alert.js +39 -40
  84. package/lib/ProTable/Content.js +84 -97
  85. package/lib/ProTable/Header.js +32 -33
  86. package/lib/ProTable/Pagination.js +56 -55
  87. package/lib/ProTable/ProTable.js +256 -276
  88. package/lib/RadioButton/RadioButton.js +48 -53
  89. package/lib/Scrollbar/Bar.js +65 -76
  90. package/lib/Scrollbar/Scrollbar.js +129 -161
  91. package/lib/Scrollbar/Thumb.js +101 -150
  92. package/lib/Search/Item.js +208 -236
  93. package/lib/Search/Search.js +90 -90
  94. package/lib/Skeleton/Skeleton.js +26 -27
  95. package/lib/Skeleton/components/DashBoardCard.js +26 -27
  96. package/lib/Skeleton/components/DashBoardChart.js +26 -27
  97. package/lib/Skeleton/components/Detail.js +26 -27
  98. package/lib/Skeleton/components/Drawer.js +26 -27
  99. package/lib/Skeleton/components/Item.js +55 -54
  100. package/lib/Skeleton/components/List.js +29 -27
  101. package/lib/Skeleton/components/ListCard.js +28 -28
  102. package/lib/Skeleton/components/ListCardItem.js +20 -20
  103. package/lib/Skeleton/components/ListTable.js +26 -27
  104. package/lib/Skeleton/components/Page.js +27 -26
  105. package/lib/Skeleton/components/Search.js +16 -16
  106. package/lib/Skeleton/components/Tree.js +26 -27
  107. package/lib/TimeFormat/TimeFormat.js +32 -36
  108. package/lib/Title/Title.js +23 -26
  109. package/lib/ValueItem/ValueItem.js +100 -113
  110. package/lib/VirtualTable/VirtualTable.js +235 -271
  111. package/package.json +1 -1
@@ -1,434 +1,385 @@
1
- function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
- import { defineComponent, ref, reactive, computed, watch, provide, useSlots } from 'vue'
3
- import { tableProps } from 'ant-design-vue/lib/table'
4
- import { useFullscreen } from '@vueuse/core'
5
- import { findIndex, get, sortBy } from 'lodash-es'
6
-
7
- import {
8
- FULL_SCREEN,
9
- RIGHT_MENU,
10
- TABLE_DATA_SOURCE,
11
- TABLE_ERROR,
12
- TABLE_GROUP_ACTIVE,
13
- TABLE_GROUP_ERROR,
14
- TABLE_GROUP_OPTIONS,
15
- TABLE_H_SCROLL,
16
- TABLE_OPEN_GROUP,
17
- TABLE_TOOL,
18
- TABLE_WRAPPER
19
- } from './consts'
20
- import { handleColumnsWidth } from './utils'
21
- import { useGroup, useResizeObserver, useValidate } from './hooks'
22
- import { useFormContext } from './context'
23
- import { bodyProps } from './props'
24
- import Header from './Header.js'
25
- import Body from './Body.js'
26
- import Group from './Group.js'
27
- import { useLocaleReceiver } from '../LocaleReciver'
28
- import useEditTableStyle from './style'
29
-
30
- const defaultGroupId = 'group_1'
31
-
32
- export default defineComponent({
33
- name: 'JEditTable',
34
- components: {
35
- Header,
36
- Body,
37
- Group
38
- },
39
- props: {
40
- ...tableProps(),
41
- ...bodyProps(),
42
- searchColumns: {
43
- type: Array,
44
- default: undefined
45
- },
46
- serial: {
47
- type: [Object, Boolean],
48
- default: () => ({
49
- width: 66,
50
- title: ''
51
- })
52
- },
53
- validateRowKey: {
54
- type: Boolean,
55
- default: false
56
- },
57
- readonly: {
58
- type: Boolean,
59
- default: false
60
- }
61
- } ,
62
- emits: ['scrollDown', 'rightMenuClick', 'editChange', 'searchVisibleChange'],
63
- setup(props, { emit, expose }) {
64
- const [contextLocale] = useLocaleReceiver('EditTable')
65
- const prefixCls = computed(() => 'jetlinks-edit-table')
66
- const [wrapSSR, hashId] = useEditTableStyle(prefixCls)
67
- const slots = useSlots()
68
-
69
- const myColumns = ref([])
70
- const tableWrapper = ref()
71
- const tableBody = ref()
72
- const scrollBarRef = ref()
73
-
74
- const tableStyle = reactive({
75
- width: '100%',
76
- height: props.height
77
- })
78
-
79
- const showScroll = ref(false)
80
- const horizontalScrollWidth = ref(0)
81
- const horizontalScrollLeft = ref(0)
82
-
83
- const fields = {}
84
- const fieldsErrMap = ref({})
85
- const fieldsGroupError = ref({})
86
- const scrollDefaultWidth = ref(17)
87
-
88
- const sortData = reactive
89
-
90
-
91
-
92
-
93
- ({
94
- key: undefined,
95
- order: undefined,
96
- orderKeys: [],
97
- dataIndex: undefined
98
- })
99
-
100
- const { groupActive, groupOptions, addGroup, removeGroup, updateGroupActive, updateGroupOptions } =
101
- useGroup(props.openGroup)
102
-
103
- const _dataSource = computed(() => {
104
- const _options = new Map()
105
- const sortDataSource = sortData.key
106
- ? sortBy(props.dataSource, (val) => {
107
- if (!val.id) return 99999999
108
- const index = findIndex(sortData.orderKeys, (val2) => get(val, sortData.key) === val2)
109
- return sortData.order === 'desc' ? index : ~index + 1
110
- })
111
- : props.dataSource
112
-
113
- sortDataSource.forEach((item, index) => {
114
- item.__dataIndex = index
115
- if (props.openGroup) {
116
- const _groupId = _optionalChain([item, 'optionalAccess', _ => _.expands, 'optionalAccess', _2 => _2.groupId])
117
- if (!_groupId) {
118
- item.expands.groupId = groupActive.value || defaultGroupId
119
- item.expands.groupName = groupActive.label || contextLocale.value.Group.one + '1'
120
- }
121
- const _optionsItem = _options.get(item.expands.groupId)
122
- if (!_optionsItem) {
123
- _options.set(item.expands.groupId, {
124
- value: _optionalChain([item, 'optionalAccess', _3 => _3.expands, 'optionalAccess', _4 => _4.groupId]),
125
- label: _optionalChain([item, 'optionalAccess', _5 => _5.expands, 'optionalAccess', _6 => _6.groupName]),
126
- effective: item.id ? 1 : 0,
127
- len: 1
128
- })
129
- } else {
130
- if (item.id) {
131
- _optionsItem.effective += 1
132
- }
133
- _optionsItem.len += 1
134
- _options.set(item.expands.groupId, _optionsItem)
135
- }
136
- item.__serial = _optionalChain([_optionsItem, 'optionalAccess', _7 => _7.len]) || 1
137
- } else {
138
- item.__serial = index + 1
139
- }
140
- })
141
-
142
- if (props.openGroup) {
143
- updateGroupOptions([..._options.values()])
144
- }
145
- return sortDataSource
146
- })
147
-
148
- const bodyDataSource = computed(() => {
149
- if (props.openGroup) {
150
- return _dataSource.value.filter((item) => item.expands.groupId === groupActive.value)
151
- }
152
- return _dataSource.value
153
- })
154
-
155
- useResizeObserver(tableWrapper, onResize)
156
-
157
- const { isFullscreen, toggle } = useFullscreen(tableWrapper)
158
-
159
- const { rules, validateItem, validate, errorMap } = useValidate(
160
- _dataSource,
161
- props.columns,
162
- props.rowKey,
163
- {
164
- onError: (err) => {
165
- fieldsErrMap.value = {}
166
- fieldsGroupError.value = {}
167
- const errMap = {}
168
-
169
- err.forEach((item, errIndex) => {
170
- item.forEach((e, eIndex) => {
171
- const field = findField(e.__dataIndex, e.field)
172
- const _eventKey = field ? field.eventKey : `${e.__dataIndex}-${e.field}`
173
- if (field) {
174
- field.showErrorTip(e.message)
175
- }
176
- errMap[_eventKey] = e.message
177
-
178
- if (errIndex === 0 && eIndex === 0) {
179
- if (props.openGroup) {
180
- const expands = _dataSource.value[e.__dataIndex].expands
181
- updateGroupActive(expands.groupId, expands.groupName)
182
- }
183
- setTimeout(() => {
184
- tableBody.value.scrollTo(e.__serial - 1)
185
- }, 10)
186
- }
187
- })
188
- })
189
- fieldsErrMap.value = errMap
190
- },
191
- onSuccess: () => {
192
- fieldsErrMap.value = {}
193
- },
194
- onEdit: () => {
195
- emit('editChange', true)
196
- },
197
- validateRowKey: props.validateRowKey
198
- }
199
- )
200
-
201
- provide(TABLE_WRAPPER, tableWrapper)
202
- provide(FULL_SCREEN, isFullscreen)
203
- provide(RIGHT_MENU, { click: rightMenu, getPopupContainer: () => tableWrapper.value })
204
- provide(TABLE_ERROR, fieldsErrMap)
205
- provide(TABLE_GROUP_ERROR, fieldsGroupError)
206
- provide(TABLE_DATA_SOURCE, _dataSource)
207
- provide(TABLE_OPEN_GROUP, props.openGroup)
208
- provide(TABLE_TOOL, {
209
- scrollTo: (record) => {
210
- if (props.openGroup) {
211
- const expands = record.expands
212
- updateGroupActive(expands.groupId, expands.groupName)
213
- }
214
- setTimeout(() => {
215
- tableBody.value.scrollTo(record.__serial)
216
- }, 10)
217
- },
218
- selected: (keys) => {
219
- tableBody.value.updateSelectedKeys(keys)
220
- },
221
- order: (type, key, orderKeys, dataIndex) => {
222
- sortData.key = key
223
- sortData.order = type
224
- sortData.orderKeys = orderKeys
225
- sortData.dataIndex = dataIndex
226
- },
227
- cleanOrder: () => {
228
- sortData.key = undefined
229
- sortData.order = undefined
230
- sortData.orderKeys = []
231
- sortData.dataIndex = undefined
232
- },
233
- sortData
234
- })
235
- provide(TABLE_GROUP_OPTIONS, groupOptions)
236
- provide(TABLE_GROUP_ACTIVE, groupActive)
237
- provide(TABLE_H_SCROLL, horizontalScrollLeft)
238
-
239
- const addField = (key, field) => {
240
- fields[key] = field
241
- }
242
-
243
- const removeField = (key) => {
244
- delete fields[key]
245
- }
246
-
247
- function findField(index, name) {
248
- const fieldId = Object.keys(fields).find((key) => {
249
- const { names } = fields[key]
250
- return names[0] === index && names[1] === name
251
- })
252
- return fields[fieldId]
253
- }
254
-
255
- function removeFieldError(key) {
256
- delete fieldsErrMap.value[key]
257
- }
258
-
259
- function addFieldError(key, message) {
260
- fieldsErrMap.value[key] = message
261
- }
262
-
263
- const scrollWidth = computed(() => {
264
- return props.dataSource.length * props.cellHeight > props.height ? scrollDefaultWidth.value : 0
265
- })
266
-
267
- const handleColumns = () => {
268
- let newColumns = [...props.columns]
269
- if (props.serial) {
270
- const serial = {
271
- dataIndex: '__serial',
272
- title: (props.serial ).title || contextLocale.value.serial,
273
- customRender: (customData) => {
274
- if (_optionalChain([(props.serial ), 'optionalAccess', _8 => _8.customRender])) {
275
- return (props.serial ).customRender(customData)
276
- }
277
- return customData.index + 1
278
- },
279
- width: _optionalChain([(props.serial ), 'optionalAccess', _9 => _9.width]),
280
- fixed: 'left'
281
- }
282
- newColumns = [serial, ...props.columns]
283
- }
284
- myColumns.value = handleColumnsWidth(newColumns, (tableStyle.width ) - scrollWidth.value)
285
- horizontalScrollWidth.value = myColumns.value.reduce((prev, next) => {
286
- prev += next.width
287
- return prev
288
- }, 0)
289
- if (horizontalScrollWidth.value > (tableStyle.width )) {
290
- showScroll.value = true
291
- }
292
- }
293
-
294
- function onResize({ width = 0 }) {
295
- tableStyle.width = width || '100%'
296
- handleColumns()
297
- }
298
-
299
- const onScrollDown = (len) => {
300
- emit('scrollDown', len)
301
- }
302
-
303
- function rightMenu(menuType, record, copyValue) {
304
- emit('rightMenuClick', menuType, record, copyValue)
305
- }
306
-
307
- const scrollToById = (key) => {
308
- const _index = _dataSource.value.findIndex((item) => item[props.rowKey] === key)
309
- tableBody.value.scrollTo(_index)
310
- }
311
-
312
- const scrollToByIndex = (index) => {
313
- tableBody.value.scrollTo(index)
314
- }
315
-
316
- const getTableWrapperRef = () => {
317
- return tableWrapper.value
318
- }
319
-
320
- const groupDelete = (id, index) => {
321
- removeGroup(index)
322
- Object.keys(fieldsErrMap.value).forEach((errorKey) => {
323
- const [idx] = errorKey.split('-')
324
- const dataSourceItem = _dataSource.value[Number(idx)]
325
- const groupId = _optionalChain([dataSourceItem, 'optionalAccess', _10 => _10.expands, 'optionalAccess', _11 => _11.groupId])
326
- if (groupId === id) {
327
- removeFieldError(errorKey)
328
- removeField(errorKey)
329
- }
330
- })
331
- emit('groupDelete', id)
332
- }
333
-
334
- const groupEdit = (record) => {
335
- emit('groupEdit', record)
336
- }
337
-
338
- const getGroupActive = () => {
339
- return groupActive.value
340
- }
341
-
342
- const onHorizontalScroll = () => {
343
- horizontalScrollLeft.value = scrollBarRef.value.scrollLeft
344
- }
345
-
346
- watch(
347
- () => fieldsErrMap.value,
348
- (errorMapVal) => {
349
- fieldsGroupError.value = {}
350
- if (props.openGroup) {
351
- const groupErrorMap = {}
352
- Object.keys(errorMapVal).forEach((errorKey) => {
353
- const [idx] = errorKey.split('-')
354
- const dataSourceItem = _dataSource.value[Number(idx)]
355
- const groupId = _optionalChain([dataSourceItem, 'optionalAccess', _12 => _12.expands, 'optionalAccess', _13 => _13.groupId])
356
- const groupErrorItem = {
357
- [errorKey]: {
358
- message: errorMapVal[errorKey],
359
- index: idx,
360
- serial: dataSourceItem.__serial
361
- }
362
- }
363
- if (groupErrorMap[groupId]) {
364
- groupErrorMap[groupId].push(groupErrorItem)
365
- } else {
366
- groupErrorMap[groupId] = [groupErrorItem]
367
- }
368
- })
369
- fieldsGroupError.value = groupErrorMap
370
- }
371
- },
372
- { deep: true }
373
- )
374
-
375
- watch(
376
- () => scrollWidth.value,
377
- () => {
378
- onResize({ width: tableStyle.width })
379
- }
380
- )
381
-
382
- watch(
383
- () => [JSON.stringify(props.columns), tableStyle.width],
384
- () => {
385
- handleColumns()
386
- }
387
- )
388
-
389
- useFormContext({
390
- dataSource: computed(() => props.dataSource),
391
- errorMap,
392
- rules,
393
- addField,
394
- removeField,
395
- removeFieldError,
396
- addFieldError,
397
- validateItem
398
- })
399
-
400
- expose({
401
- validate,
402
- tableWrapper,
403
- scrollToById,
404
- scrollToByIndex,
405
- getTableWrapperRef,
406
- getGroupActive
407
- })
408
-
409
- return {
410
- slots,
411
- hashId,
412
- isFullscreen,
413
- toggle,
414
- tableWrapper,
415
- tableBody,
416
- scrollBarRef,
417
- myColumns,
418
- tableStyle,
419
- showScroll,
420
- horizontalScrollWidth,
421
- horizontalScrollLeft,
422
- scrollWidth,
423
- bodyDataSource,
424
- groupActive,
425
- groupOptions,
426
- addGroup,
427
- updateGroupActive,
428
- onScrollDown,
429
- groupDelete,
430
- groupEdit,
431
- onHorizontalScroll
432
- }
433
- }
434
- })
1
+ import { defineComponent, ref, reactive, computed, watch, provide, useSlots } from 'vue';
2
+ import { tableProps } from 'ant-design-vue/lib/table';
3
+ import { useFullscreen } from '@vueuse/core';
4
+ import { findIndex, get, sortBy } from 'lodash-es';
5
+ import { FULL_SCREEN, RIGHT_MENU, TABLE_DATA_SOURCE, TABLE_ERROR, TABLE_GROUP_ACTIVE, TABLE_GROUP_ERROR, TABLE_GROUP_OPTIONS, TABLE_H_SCROLL, TABLE_OPEN_GROUP, TABLE_TOOL, TABLE_WRAPPER } from './consts';
6
+ import { handleColumnsWidth } from './utils';
7
+ import { useGroup, useResizeObserver, useValidate } from './hooks';
8
+ import { useFormContext } from './context';
9
+ import { bodyProps } from './props';
10
+ import Header from './Header.js';
11
+ import Body from './Body.js';
12
+ import Group from './Group.js';
13
+ import { useLocaleReceiver } from '../LocaleReciver';
14
+ import useEditTableStyle from './style';
15
+ const defaultGroupId = 'group_1';
16
+ export default defineComponent({
17
+ name: 'JEditTable',
18
+ components: {
19
+ Header,
20
+ Body,
21
+ Group
22
+ },
23
+ props: {
24
+ ...tableProps(),
25
+ ...bodyProps(),
26
+ searchColumns: {
27
+ type: Array,
28
+ default: undefined
29
+ },
30
+ serial: {
31
+ type: [Object, Boolean],
32
+ default: () => ({
33
+ width: 66,
34
+ title: ''
35
+ })
36
+ },
37
+ validateRowKey: {
38
+ type: Boolean,
39
+ default: false
40
+ },
41
+ readonly: {
42
+ type: Boolean,
43
+ default: false
44
+ }
45
+ },
46
+ emits: ['scrollDown', 'rightMenuClick', 'editChange', 'searchVisibleChange'],
47
+ setup(props, {
48
+ emit,
49
+ expose
50
+ }) {
51
+ const [contextLocale] = useLocaleReceiver('EditTable');
52
+ const prefixCls = computed(() => 'jetlinks-edit-table');
53
+ const [wrapSSR, hashId] = useEditTableStyle(prefixCls);
54
+ const slots = useSlots();
55
+ const myColumns = ref([]);
56
+ const tableWrapper = ref();
57
+ const tableBody = ref();
58
+ const scrollBarRef = ref();
59
+ const tableStyle = reactive({
60
+ width: '100%',
61
+ height: props.height
62
+ });
63
+ const showScroll = ref(false);
64
+ const horizontalScrollWidth = ref(0);
65
+ const horizontalScrollLeft = ref(0);
66
+ const fields = {};
67
+ const fieldsErrMap = ref({});
68
+ const fieldsGroupError = ref({});
69
+ const scrollDefaultWidth = ref(17);
70
+ const sortData = reactive({
71
+ key: undefined,
72
+ order: undefined,
73
+ orderKeys: [],
74
+ dataIndex: undefined
75
+ });
76
+ const {
77
+ groupActive,
78
+ groupOptions,
79
+ addGroup,
80
+ removeGroup,
81
+ updateGroupActive,
82
+ updateGroupOptions
83
+ } = useGroup(props.openGroup);
84
+ const _dataSource = computed(() => {
85
+ const _options = new Map();
86
+ const sortDataSource = sortData.key ? sortBy(props.dataSource, val => {
87
+ if (!val.id) return 99999999;
88
+ const index = findIndex(sortData.orderKeys, val2 => get(val, sortData.key) === val2);
89
+ return sortData.order === 'desc' ? index : ~index + 1;
90
+ }) : props.dataSource;
91
+ sortDataSource.forEach((item, index) => {
92
+ item.__dataIndex = index;
93
+ if (props.openGroup) {
94
+ const _groupId = item?.expands?.groupId;
95
+ if (!_groupId) {
96
+ item.expands.groupId = groupActive.value || defaultGroupId;
97
+ item.expands.groupName = groupActive.label || contextLocale.value.Group.one + '1';
98
+ }
99
+ const _optionsItem = _options.get(item.expands.groupId);
100
+ if (!_optionsItem) {
101
+ _options.set(item.expands.groupId, {
102
+ value: item?.expands?.groupId,
103
+ label: item?.expands?.groupName,
104
+ effective: item.id ? 1 : 0,
105
+ len: 1
106
+ });
107
+ } else {
108
+ if (item.id) {
109
+ _optionsItem.effective += 1;
110
+ }
111
+ _optionsItem.len += 1;
112
+ _options.set(item.expands.groupId, _optionsItem);
113
+ }
114
+ item.__serial = _optionsItem?.len || 1;
115
+ } else {
116
+ item.__serial = index + 1;
117
+ }
118
+ });
119
+ if (props.openGroup) {
120
+ updateGroupOptions([..._options.values()]);
121
+ }
122
+ return sortDataSource;
123
+ });
124
+ const bodyDataSource = computed(() => {
125
+ if (props.openGroup) {
126
+ return _dataSource.value.filter(item => item.expands.groupId === groupActive.value);
127
+ }
128
+ return _dataSource.value;
129
+ });
130
+ useResizeObserver(tableWrapper, onResize);
131
+ const {
132
+ isFullscreen,
133
+ toggle
134
+ } = useFullscreen(tableWrapper);
135
+ const {
136
+ rules,
137
+ validateItem,
138
+ validate,
139
+ errorMap
140
+ } = useValidate(_dataSource, props.columns, props.rowKey, {
141
+ onError: err => {
142
+ fieldsErrMap.value = {};
143
+ fieldsGroupError.value = {};
144
+ const errMap = {};
145
+ err.forEach((item, errIndex) => {
146
+ item.forEach((e, eIndex) => {
147
+ const field = findField(e.__dataIndex, e.field);
148
+ const _eventKey = field ? field.eventKey : `${e.__dataIndex}-${e.field}`;
149
+ if (field) {
150
+ field.showErrorTip(e.message);
151
+ }
152
+ errMap[_eventKey] = e.message;
153
+ if (errIndex === 0 && eIndex === 0) {
154
+ if (props.openGroup) {
155
+ const expands = _dataSource.value[e.__dataIndex].expands;
156
+ updateGroupActive(expands.groupId, expands.groupName);
157
+ }
158
+ setTimeout(() => {
159
+ tableBody.value.scrollTo(e.__serial - 1);
160
+ }, 10);
161
+ }
162
+ });
163
+ });
164
+ fieldsErrMap.value = errMap;
165
+ },
166
+ onSuccess: () => {
167
+ fieldsErrMap.value = {};
168
+ },
169
+ onEdit: () => {
170
+ emit('editChange', true);
171
+ },
172
+ validateRowKey: props.validateRowKey
173
+ });
174
+ provide(TABLE_WRAPPER, tableWrapper);
175
+ provide(FULL_SCREEN, isFullscreen);
176
+ provide(RIGHT_MENU, {
177
+ click: rightMenu,
178
+ getPopupContainer: () => tableWrapper.value
179
+ });
180
+ provide(TABLE_ERROR, fieldsErrMap);
181
+ provide(TABLE_GROUP_ERROR, fieldsGroupError);
182
+ provide(TABLE_DATA_SOURCE, _dataSource);
183
+ provide(TABLE_OPEN_GROUP, props.openGroup);
184
+ provide(TABLE_TOOL, {
185
+ scrollTo: record => {
186
+ if (props.openGroup) {
187
+ const expands = record.expands;
188
+ updateGroupActive(expands.groupId, expands.groupName);
189
+ }
190
+ setTimeout(() => {
191
+ tableBody.value.scrollTo(record.__serial);
192
+ }, 10);
193
+ },
194
+ selected: keys => {
195
+ tableBody.value.updateSelectedKeys(keys);
196
+ },
197
+ order: (type, key, orderKeys, dataIndex) => {
198
+ sortData.key = key;
199
+ sortData.order = type;
200
+ sortData.orderKeys = orderKeys;
201
+ sortData.dataIndex = dataIndex;
202
+ },
203
+ cleanOrder: () => {
204
+ sortData.key = undefined;
205
+ sortData.order = undefined;
206
+ sortData.orderKeys = [];
207
+ sortData.dataIndex = undefined;
208
+ },
209
+ sortData
210
+ });
211
+ provide(TABLE_GROUP_OPTIONS, groupOptions);
212
+ provide(TABLE_GROUP_ACTIVE, groupActive);
213
+ provide(TABLE_H_SCROLL, horizontalScrollLeft);
214
+ const addField = (key, field) => {
215
+ fields[key] = field;
216
+ };
217
+ const removeField = key => {
218
+ delete fields[key];
219
+ };
220
+ function findField(index, name) {
221
+ const fieldId = Object.keys(fields).find(key => {
222
+ const {
223
+ names
224
+ } = fields[key];
225
+ return names[0] === index && names[1] === name;
226
+ });
227
+ return fields[fieldId];
228
+ }
229
+ function removeFieldError(key) {
230
+ delete fieldsErrMap.value[key];
231
+ }
232
+ function addFieldError(key, message) {
233
+ fieldsErrMap.value[key] = message;
234
+ }
235
+ const scrollWidth = computed(() => {
236
+ return props.dataSource.length * props.cellHeight > props.height ? scrollDefaultWidth.value : 0;
237
+ });
238
+ const handleColumns = () => {
239
+ let newColumns = [...props.columns];
240
+ if (props.serial) {
241
+ const serial = {
242
+ dataIndex: '__serial',
243
+ title: props.serial.title || contextLocale.value.serial,
244
+ customRender: customData => {
245
+ if (props.serial?.customRender) {
246
+ return props.serial.customRender(customData);
247
+ }
248
+ return customData.index + 1;
249
+ },
250
+ width: props.serial?.width,
251
+ fixed: 'left'
252
+ };
253
+ newColumns = [serial, ...props.columns];
254
+ }
255
+ myColumns.value = handleColumnsWidth(newColumns, tableStyle.width - scrollWidth.value);
256
+ horizontalScrollWidth.value = myColumns.value.reduce((prev, next) => {
257
+ prev += next.width;
258
+ return prev;
259
+ }, 0);
260
+ if (horizontalScrollWidth.value > tableStyle.width) {
261
+ showScroll.value = true;
262
+ }
263
+ };
264
+ function onResize({
265
+ width = 0
266
+ }) {
267
+ tableStyle.width = width || '100%';
268
+ handleColumns();
269
+ }
270
+ const onScrollDown = len => {
271
+ emit('scrollDown', len);
272
+ };
273
+ function rightMenu(menuType, record, copyValue) {
274
+ emit('rightMenuClick', menuType, record, copyValue);
275
+ }
276
+ const scrollToById = key => {
277
+ const _index = _dataSource.value.findIndex(item => item[props.rowKey] === key);
278
+ tableBody.value.scrollTo(_index);
279
+ };
280
+ const scrollToByIndex = index => {
281
+ tableBody.value.scrollTo(index);
282
+ };
283
+ const getTableWrapperRef = () => {
284
+ return tableWrapper.value;
285
+ };
286
+ const groupDelete = (id, index) => {
287
+ removeGroup(index);
288
+ Object.keys(fieldsErrMap.value).forEach(errorKey => {
289
+ const [idx] = errorKey.split('-');
290
+ const dataSourceItem = _dataSource.value[Number(idx)];
291
+ const groupId = dataSourceItem?.expands?.groupId;
292
+ if (groupId === id) {
293
+ removeFieldError(errorKey);
294
+ removeField(errorKey);
295
+ }
296
+ });
297
+ emit('groupDelete', id);
298
+ };
299
+ const groupEdit = record => {
300
+ emit('groupEdit', record);
301
+ };
302
+ const getGroupActive = () => {
303
+ return groupActive.value;
304
+ };
305
+ const onHorizontalScroll = () => {
306
+ horizontalScrollLeft.value = scrollBarRef.value.scrollLeft;
307
+ };
308
+ watch(() => fieldsErrMap.value, errorMapVal => {
309
+ fieldsGroupError.value = {};
310
+ if (props.openGroup) {
311
+ const groupErrorMap = {};
312
+ Object.keys(errorMapVal).forEach(errorKey => {
313
+ const [idx] = errorKey.split('-');
314
+ const dataSourceItem = _dataSource.value[Number(idx)];
315
+ const groupId = dataSourceItem?.expands?.groupId;
316
+ const groupErrorItem = {
317
+ [errorKey]: {
318
+ message: errorMapVal[errorKey],
319
+ index: idx,
320
+ serial: dataSourceItem.__serial
321
+ }
322
+ };
323
+ if (groupErrorMap[groupId]) {
324
+ groupErrorMap[groupId].push(groupErrorItem);
325
+ } else {
326
+ groupErrorMap[groupId] = [groupErrorItem];
327
+ }
328
+ });
329
+ fieldsGroupError.value = groupErrorMap;
330
+ }
331
+ }, {
332
+ deep: true
333
+ });
334
+ watch(() => scrollWidth.value, () => {
335
+ onResize({
336
+ width: tableStyle.width
337
+ });
338
+ });
339
+ watch(() => [JSON.stringify(props.columns), tableStyle.width], () => {
340
+ handleColumns();
341
+ });
342
+ useFormContext({
343
+ dataSource: computed(() => props.dataSource),
344
+ errorMap,
345
+ rules,
346
+ addField,
347
+ removeField,
348
+ removeFieldError,
349
+ addFieldError,
350
+ validateItem
351
+ });
352
+ expose({
353
+ validate,
354
+ tableWrapper,
355
+ scrollToById,
356
+ scrollToByIndex,
357
+ getTableWrapperRef,
358
+ getGroupActive
359
+ });
360
+ return {
361
+ slots,
362
+ hashId,
363
+ isFullscreen,
364
+ toggle,
365
+ tableWrapper,
366
+ tableBody,
367
+ scrollBarRef,
368
+ myColumns,
369
+ tableStyle,
370
+ showScroll,
371
+ horizontalScrollWidth,
372
+ horizontalScrollLeft,
373
+ scrollWidth,
374
+ bodyDataSource,
375
+ groupActive,
376
+ groupOptions,
377
+ addGroup,
378
+ updateGroupActive,
379
+ onScrollDown,
380
+ groupDelete,
381
+ groupEdit,
382
+ onHorizontalScroll
383
+ };
384
+ }
385
+ });