@meethive/components 0.0.1

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 (303) hide show
  1. package/es/AutoComplete/AutoComplete.js +84 -0
  2. package/es/AutoComplete/index.js +7 -0
  3. package/es/BadgeStatus/Badge.js +51 -0
  4. package/es/BadgeStatus/color.js +14 -0
  5. package/es/BadgeStatus/index.js +8 -0
  6. package/es/CardSelect/CardSelect.js +141 -0
  7. package/es/CardSelect/index.js +7 -0
  8. package/es/CardSelect/style/index.js +29 -0
  9. package/es/CheckButton/CheckButton.js +122 -0
  10. package/es/CheckButton/index.js +7 -0
  11. package/es/CheckButton/style/index.js +44 -0
  12. package/es/ConfigProvider/ConfigProvider.js +73 -0
  13. package/es/ConfigProvider/context.js +26 -0
  14. package/es/ConfigProvider/index.js +9 -0
  15. package/es/DragModal/DragModal.js +212 -0
  16. package/es/DragModal/index.js +7 -0
  17. package/es/DragModal/style/index.js +86 -0
  18. package/es/EditTable/Body.js +189 -0
  19. package/es/EditTable/CellRender.js +12 -0
  20. package/es/EditTable/EditTable.js +434 -0
  21. package/es/EditTable/FormItem.js +169 -0
  22. package/es/EditTable/Group.js +204 -0
  23. package/es/EditTable/Header.js +63 -0
  24. package/es/EditTable/HeaderRender.js +12 -0
  25. package/es/EditTable/components/ContextMenu/Menu.js +86 -0
  26. package/es/EditTable/components/ContextMenu/index.js +96 -0
  27. package/es/EditTable/components/Search/Search.js +163 -0
  28. package/es/EditTable/components/Search/Sort.js +119 -0
  29. package/es/EditTable/components/Search/index.js +2 -0
  30. package/es/EditTable/consts.js +13 -0
  31. package/es/EditTable/context.js +88 -0
  32. package/es/EditTable/hooks/index.js +19 -0
  33. package/es/EditTable/hooks/useGroup.js +48 -0
  34. package/es/EditTable/hooks/useResizeObserver.js +27 -0
  35. package/es/EditTable/hooks/useValidate.js +112 -0
  36. package/es/EditTable/index.js +25 -0
  37. package/es/EditTable/props.js +60 -0
  38. package/es/EditTable/style/body.js +63 -0
  39. package/es/EditTable/style/form.js +33 -0
  40. package/es/EditTable/style/group.js +33 -0
  41. package/es/EditTable/style/header.js +72 -0
  42. package/es/EditTable/style/index.js +52 -0
  43. package/es/EditTable/style/menu.js +27 -0
  44. package/es/EditTable/style/table.js +46 -0
  45. package/es/EditTable/utils.js +110 -0
  46. package/es/Ellipsis/Ellipsis.js +148 -0
  47. package/es/Ellipsis/index.js +7 -0
  48. package/es/Ellipsis/style/index.js +26 -0
  49. package/es/Empty/Empty.js +63 -0
  50. package/es/Empty/image.js +3 -0
  51. package/es/Empty/index.js +7 -0
  52. package/es/FullPage/FullPage.js +19 -0
  53. package/es/FullPage/index.js +7 -0
  54. package/es/Icon/Icon.js +49 -0
  55. package/es/Icon/index.js +7 -0
  56. package/es/LocaleProvider/LocaleProvider.js +31 -0
  57. package/es/LocaleProvider/index.js +7 -0
  58. package/es/LocaleReciver/index.js +24 -0
  59. package/es/Markdown/Markdown.js +118 -0
  60. package/es/Markdown/index.js +7 -0
  61. package/es/PermissionButton/PermissionButton.js +118 -0
  62. package/es/PermissionButton/confirm.js +94 -0
  63. package/es/PermissionButton/index.js +9 -0
  64. package/es/PermissionButton/shared.js +1 -0
  65. package/es/ProLayout/Basic/BasicLayout.js +422 -0
  66. package/es/ProLayout/Basic/BasicLayoutStyle.js +51 -0
  67. package/es/ProLayout/Basic/Header.js +111 -0
  68. package/es/ProLayout/Basic/HeaderStyle.js +10 -0
  69. package/es/ProLayout/PageContainer/index.js +354 -0
  70. package/es/ProLayout/PageContainer/style.js +85 -0
  71. package/es/ProLayout/RouteContext.js +28 -0
  72. package/es/ProLayout/SiderMenu/BaseMenu.js +241 -0
  73. package/es/ProLayout/SiderMenu/SiderMenu.js +274 -0
  74. package/es/ProLayout/SiderMenu/index.js +2 -0
  75. package/es/ProLayout/SiderMenu/style.js +204 -0
  76. package/es/ProLayout/TopHeader/index.js +170 -0
  77. package/es/ProLayout/TopHeader/style.js +154 -0
  78. package/es/ProLayout/defaultSettings.js +113 -0
  79. package/es/ProLayout/index.js +10 -0
  80. package/es/ProLayout/style/index.js +14 -0
  81. package/es/ProLayout/util.js +58 -0
  82. package/es/ProTable/Alert.js +40 -0
  83. package/es/ProTable/Content.js +97 -0
  84. package/es/ProTable/Header.js +33 -0
  85. package/es/ProTable/Pagination.js +55 -0
  86. package/es/ProTable/ProTable.js +279 -0
  87. package/es/ProTable/hooks/index.js +2 -0
  88. package/es/ProTable/hooks/useTableInject.js +6 -0
  89. package/es/ProTable/hooks/useTableSelection.js +115 -0
  90. package/es/ProTable/index.js +8 -0
  91. package/es/ProTable/setting.js +138 -0
  92. package/es/ProTable/style/index.js +113 -0
  93. package/es/RadioButton/RadioButton.js +53 -0
  94. package/es/RadioButton/index.js +8 -0
  95. package/es/RadioButton/style/index.js +25 -0
  96. package/es/Scrollbar/Bar.js +76 -0
  97. package/es/Scrollbar/Scrollbar.js +161 -0
  98. package/es/Scrollbar/Thumb.js +150 -0
  99. package/es/Scrollbar/constants.js +1 -0
  100. package/es/Scrollbar/index.js +7 -0
  101. package/es/Scrollbar/scrollbarProps.js +100 -0
  102. package/es/Scrollbar/style/index.js +85 -0
  103. package/es/Scrollbar/thumbProps.js +10 -0
  104. package/es/Scrollbar/util.js +39 -0
  105. package/es/Search/Item.js +239 -0
  106. package/es/Search/Search.js +90 -0
  107. package/es/Search/hooks/index.js +117 -0
  108. package/es/Search/hooks/useRouteQuery.js +86 -0
  109. package/es/Search/hooks/useSearchItems.js +50 -0
  110. package/es/Search/hooks/useTermOptions.js +29 -0
  111. package/es/Search/index.js +10 -0
  112. package/es/Search/setting.js +245 -0
  113. package/es/Search/style/index.js +5 -0
  114. package/es/Search/style/item.js +40 -0
  115. package/es/Search/style/search.js +177 -0
  116. package/es/Search/util.js +270 -0
  117. package/es/Skeleton/Skeleton.js +27 -0
  118. package/es/Skeleton/components/DashBoardCard.js +27 -0
  119. package/es/Skeleton/components/DashBoardChart.js +27 -0
  120. package/es/Skeleton/components/Detail.js +27 -0
  121. package/es/Skeleton/components/Drawer.js +27 -0
  122. package/es/Skeleton/components/Item.js +54 -0
  123. package/es/Skeleton/components/List.js +27 -0
  124. package/es/Skeleton/components/ListCard.js +28 -0
  125. package/es/Skeleton/components/ListCardItem.js +20 -0
  126. package/es/Skeleton/components/ListTable.js +27 -0
  127. package/es/Skeleton/components/Page.js +26 -0
  128. package/es/Skeleton/components/Search.js +16 -0
  129. package/es/Skeleton/components/Tree.js +27 -0
  130. package/es/Skeleton/index.js +28 -0
  131. package/es/Skeleton/style/index.js +195 -0
  132. package/es/TimeFormat/TimeFormat.js +36 -0
  133. package/es/TimeFormat/index.js +7 -0
  134. package/es/Title/Title.js +26 -0
  135. package/es/Title/index.js +7 -0
  136. package/es/Title/style/index.js +34 -0
  137. package/es/ValueItem/ValueItem.js +113 -0
  138. package/es/ValueItem/index.js +7 -0
  139. package/es/ValueItem/util.js +17 -0
  140. package/es/VirtualTable/VirtualTable.js +271 -0
  141. package/es/VirtualTable/data.js +60 -0
  142. package/es/VirtualTable/index.js +7 -0
  143. package/es/VirtualTable/style/index.js +34 -0
  144. package/es/components.js +21 -0
  145. package/es/index.js +17 -0
  146. package/es/locale/en-US.js +120 -0
  147. package/es/locale/zh-CN.js +120 -0
  148. package/es/style/styleRegister.js +19 -0
  149. package/es/style/variable.js +4 -0
  150. package/es/style.js +1 -0
  151. package/es/utils/constants.js +10 -0
  152. package/lib/AutoComplete/AutoComplete.js +84 -0
  153. package/lib/AutoComplete/index.js +7 -0
  154. package/lib/BadgeStatus/Badge.js +51 -0
  155. package/lib/BadgeStatus/color.js +14 -0
  156. package/lib/BadgeStatus/index.js +8 -0
  157. package/lib/CardSelect/CardSelect.js +141 -0
  158. package/lib/CardSelect/index.js +7 -0
  159. package/lib/CardSelect/style/index.js +29 -0
  160. package/lib/CheckButton/CheckButton.js +122 -0
  161. package/lib/CheckButton/index.js +7 -0
  162. package/lib/CheckButton/style/index.js +44 -0
  163. package/lib/ConfigProvider/ConfigProvider.js +73 -0
  164. package/lib/ConfigProvider/context.js +26 -0
  165. package/lib/ConfigProvider/index.js +9 -0
  166. package/lib/DragModal/DragModal.js +212 -0
  167. package/lib/DragModal/index.js +7 -0
  168. package/lib/DragModal/style/index.js +86 -0
  169. package/lib/EditTable/Body.js +189 -0
  170. package/lib/EditTable/CellRender.js +12 -0
  171. package/lib/EditTable/EditTable.js +434 -0
  172. package/lib/EditTable/FormItem.js +169 -0
  173. package/lib/EditTable/Group.js +204 -0
  174. package/lib/EditTable/Header.js +63 -0
  175. package/lib/EditTable/HeaderRender.js +12 -0
  176. package/lib/EditTable/components/ContextMenu/Menu.js +86 -0
  177. package/lib/EditTable/components/ContextMenu/index.js +96 -0
  178. package/lib/EditTable/components/Search/Search.js +163 -0
  179. package/lib/EditTable/components/Search/Sort.js +119 -0
  180. package/lib/EditTable/components/Search/index.js +2 -0
  181. package/lib/EditTable/consts.js +13 -0
  182. package/lib/EditTable/context.js +88 -0
  183. package/lib/EditTable/hooks/index.js +19 -0
  184. package/lib/EditTable/hooks/useGroup.js +48 -0
  185. package/lib/EditTable/hooks/useResizeObserver.js +27 -0
  186. package/lib/EditTable/hooks/useValidate.js +112 -0
  187. package/lib/EditTable/index.js +25 -0
  188. package/lib/EditTable/props.js +60 -0
  189. package/lib/EditTable/style/body.js +63 -0
  190. package/lib/EditTable/style/form.js +33 -0
  191. package/lib/EditTable/style/group.js +33 -0
  192. package/lib/EditTable/style/header.js +72 -0
  193. package/lib/EditTable/style/index.js +52 -0
  194. package/lib/EditTable/style/menu.js +27 -0
  195. package/lib/EditTable/style/table.js +46 -0
  196. package/lib/EditTable/utils.js +110 -0
  197. package/lib/Ellipsis/Ellipsis.js +148 -0
  198. package/lib/Ellipsis/index.js +7 -0
  199. package/lib/Ellipsis/style/index.js +26 -0
  200. package/lib/Empty/Empty.js +63 -0
  201. package/lib/Empty/image.js +3 -0
  202. package/lib/Empty/index.js +7 -0
  203. package/lib/FullPage/FullPage.js +19 -0
  204. package/lib/FullPage/index.js +7 -0
  205. package/lib/Icon/Icon.js +49 -0
  206. package/lib/Icon/index.js +7 -0
  207. package/lib/LocaleProvider/LocaleProvider.js +31 -0
  208. package/lib/LocaleProvider/index.js +7 -0
  209. package/lib/LocaleReciver/index.js +24 -0
  210. package/lib/Markdown/Markdown.js +118 -0
  211. package/lib/Markdown/index.js +7 -0
  212. package/lib/PermissionButton/PermissionButton.js +118 -0
  213. package/lib/PermissionButton/confirm.js +94 -0
  214. package/lib/PermissionButton/index.js +9 -0
  215. package/lib/PermissionButton/shared.js +1 -0
  216. package/lib/ProLayout/Basic/BasicLayout.js +422 -0
  217. package/lib/ProLayout/Basic/BasicLayoutStyle.js +51 -0
  218. package/lib/ProLayout/Basic/Header.js +111 -0
  219. package/lib/ProLayout/Basic/HeaderStyle.js +10 -0
  220. package/lib/ProLayout/PageContainer/index.js +354 -0
  221. package/lib/ProLayout/PageContainer/style.js +85 -0
  222. package/lib/ProLayout/RouteContext.js +28 -0
  223. package/lib/ProLayout/SiderMenu/BaseMenu.js +241 -0
  224. package/lib/ProLayout/SiderMenu/SiderMenu.js +274 -0
  225. package/lib/ProLayout/SiderMenu/index.js +2 -0
  226. package/lib/ProLayout/SiderMenu/style.js +204 -0
  227. package/lib/ProLayout/TopHeader/index.js +170 -0
  228. package/lib/ProLayout/TopHeader/style.js +154 -0
  229. package/lib/ProLayout/defaultSettings.js +113 -0
  230. package/lib/ProLayout/index.js +10 -0
  231. package/lib/ProLayout/style/index.js +14 -0
  232. package/lib/ProLayout/util.js +58 -0
  233. package/lib/ProTable/Alert.js +40 -0
  234. package/lib/ProTable/Content.js +97 -0
  235. package/lib/ProTable/Header.js +33 -0
  236. package/lib/ProTable/Pagination.js +55 -0
  237. package/lib/ProTable/ProTable.js +279 -0
  238. package/lib/ProTable/hooks/index.js +2 -0
  239. package/lib/ProTable/hooks/useTableInject.js +6 -0
  240. package/lib/ProTable/hooks/useTableSelection.js +115 -0
  241. package/lib/ProTable/index.js +8 -0
  242. package/lib/ProTable/setting.js +138 -0
  243. package/lib/ProTable/style/index.js +113 -0
  244. package/lib/RadioButton/RadioButton.js +53 -0
  245. package/lib/RadioButton/index.js +8 -0
  246. package/lib/RadioButton/style/index.js +25 -0
  247. package/lib/Scrollbar/Bar.js +76 -0
  248. package/lib/Scrollbar/Scrollbar.js +161 -0
  249. package/lib/Scrollbar/Thumb.js +150 -0
  250. package/lib/Scrollbar/constants.js +1 -0
  251. package/lib/Scrollbar/index.js +7 -0
  252. package/lib/Scrollbar/scrollbarProps.js +100 -0
  253. package/lib/Scrollbar/style/index.js +85 -0
  254. package/lib/Scrollbar/thumbProps.js +10 -0
  255. package/lib/Scrollbar/util.js +39 -0
  256. package/lib/Search/Item.js +239 -0
  257. package/lib/Search/Search.js +90 -0
  258. package/lib/Search/hooks/index.js +117 -0
  259. package/lib/Search/hooks/useRouteQuery.js +86 -0
  260. package/lib/Search/hooks/useSearchItems.js +50 -0
  261. package/lib/Search/hooks/useTermOptions.js +29 -0
  262. package/lib/Search/index.js +10 -0
  263. package/lib/Search/setting.js +245 -0
  264. package/lib/Search/style/index.js +5 -0
  265. package/lib/Search/style/item.js +40 -0
  266. package/lib/Search/style/search.js +177 -0
  267. package/lib/Search/util.js +270 -0
  268. package/lib/Skeleton/Skeleton.js +27 -0
  269. package/lib/Skeleton/components/DashBoardCard.js +27 -0
  270. package/lib/Skeleton/components/DashBoardChart.js +27 -0
  271. package/lib/Skeleton/components/Detail.js +27 -0
  272. package/lib/Skeleton/components/Drawer.js +27 -0
  273. package/lib/Skeleton/components/Item.js +54 -0
  274. package/lib/Skeleton/components/List.js +27 -0
  275. package/lib/Skeleton/components/ListCard.js +28 -0
  276. package/lib/Skeleton/components/ListCardItem.js +20 -0
  277. package/lib/Skeleton/components/ListTable.js +27 -0
  278. package/lib/Skeleton/components/Page.js +26 -0
  279. package/lib/Skeleton/components/Search.js +16 -0
  280. package/lib/Skeleton/components/Tree.js +27 -0
  281. package/lib/Skeleton/index.js +28 -0
  282. package/lib/Skeleton/style/index.js +195 -0
  283. package/lib/TimeFormat/TimeFormat.js +36 -0
  284. package/lib/TimeFormat/index.js +7 -0
  285. package/lib/Title/Title.js +26 -0
  286. package/lib/Title/index.js +7 -0
  287. package/lib/Title/style/index.js +34 -0
  288. package/lib/ValueItem/ValueItem.js +113 -0
  289. package/lib/ValueItem/index.js +7 -0
  290. package/lib/ValueItem/util.js +17 -0
  291. package/lib/VirtualTable/VirtualTable.js +271 -0
  292. package/lib/VirtualTable/data.js +60 -0
  293. package/lib/VirtualTable/index.js +7 -0
  294. package/lib/VirtualTable/style/index.js +34 -0
  295. package/lib/components.js +21 -0
  296. package/lib/index.js +17 -0
  297. package/lib/locale/en-US.js +120 -0
  298. package/lib/locale/zh-CN.js +120 -0
  299. package/lib/style/styleRegister.js +19 -0
  300. package/lib/style/variable.js +4 -0
  301. package/lib/style.js +1 -0
  302. package/lib/utils/constants.js +10 -0
  303. package/package.json +164 -0
@@ -0,0 +1,434 @@
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
+ })
@@ -0,0 +1,169 @@
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, reactive, computed, watch, provide, onBeforeUnmount } from 'vue'
3
+ import { Tooltip as ATooltip } from 'ant-design-vue'
4
+ import { get, isArray } from 'lodash-es'
5
+ import { useProvideFormItemContext } from 'ant-design-vue/es/form/FormItemContext'
6
+ import { useInjectError, useInjectForm } from './hooks'
7
+ import { TABLE_FORM_ITEM_ERROR } from './consts'
8
+ import genEditTableStyle from './style'
9
+
10
+ export default defineComponent({
11
+ name: 'JEditTableFormItem',
12
+ components: {
13
+ ATooltip
14
+ },
15
+ props: {
16
+ name: {
17
+ type: [String, Array],
18
+ default: undefined
19
+ },
20
+ required: {
21
+ type: Boolean,
22
+ default: false
23
+ }
24
+ },
25
+ emits: ['change'],
26
+ setup(props, { emit }) {
27
+ const prefixCls = computed(() => 'jetlinks-edit-table')
28
+ const [wrapSSR, hashId] = genEditTableStyle(prefixCls)
29
+
30
+ const context = useInjectForm()
31
+ const globalErrorMessage = useInjectError()
32
+
33
+ let hideTimer = null
34
+
35
+ const eventKey = computed(() => {
36
+ const names = isArray(props.name) ? props.name : [props.name]
37
+ return names.join('-')
38
+ })
39
+
40
+ const errorMap = reactive({
41
+ message: '',
42
+ visible: false
43
+ })
44
+
45
+ const filedId = computed(() => {
46
+ const names = isArray(props.name) ? props.name : [props.name]
47
+ const [index, ...extra] = names
48
+ return `${index}-${extra.join('.')}`
49
+ })
50
+
51
+ const filedName = computed(() => {
52
+ const names = isArray(props.name) ? props.name : [props.name]
53
+ return [...names].pop()
54
+ })
55
+
56
+ const filedValue = computed(() => {
57
+ return get(context.dataSource.value, props.name )
58
+ })
59
+
60
+ provide(TABLE_FORM_ITEM_ERROR, errorMap)
61
+
62
+ const popContainer = (e) => {
63
+ return e
64
+ }
65
+
66
+ const removeTimer = () => {
67
+ if (hideTimer) {
68
+ window.clearTimeout(hideTimer)
69
+ hideTimer = null
70
+ }
71
+ }
72
+
73
+ const showErrorTip = (msg) => {
74
+ removeTimer()
75
+ errorMap.message = msg
76
+ errorMap.visible = true
77
+ }
78
+
79
+ const hideErrorTip = () => {
80
+ errorMap.visible = false
81
+ removeTimer()
82
+ hideTimer = window.setTimeout(() => {
83
+ errorMap.message = ''
84
+ }, 300)
85
+ }
86
+
87
+ const validateRules = () => {
88
+ let index = 0
89
+ if (isArray(props.name)) {
90
+ index = props.name[0]
91
+ }
92
+ const promise = context.validateItem(
93
+ { [filedName.value ]: get(context.dataSource.value, props.name ) },
94
+ index
95
+ )
96
+
97
+ promise.catch((res) => {
98
+ const error = _optionalChain([res, 'optionalAccess', _ => _.filter, 'call', _2 => _2((item) => item.field === filedName.value)]) || []
99
+ if (error.length === 0) {
100
+ hideErrorTip()
101
+ context.removeFieldError(eventKey.value)
102
+ } else {
103
+ removeTimer()
104
+ errorMap.message = _optionalChain([error, 'access', _3 => _3[0], 'optionalAccess', _4 => _4.message]) || errorMap.message
105
+ errorMap.visible = !!error.length
106
+ context.addFieldError(eventKey.value, errorMap.message)
107
+ }
108
+ return errorMap.message
109
+ })
110
+
111
+ return promise
112
+ }
113
+
114
+ const onFieldBlur = () => {
115
+ // validateRules()
116
+ }
117
+
118
+ const onFieldChange = () => {
119
+ validateRules()
120
+ emit('change')
121
+ }
122
+
123
+ watch(
124
+ () => globalErrorMessage.value,
125
+ (val) => {
126
+ if (val[eventKey.value]) {
127
+ showErrorTip(val[eventKey.value])
128
+ } else {
129
+ hideErrorTip()
130
+ }
131
+ },
132
+ { immediate: true, deep: true }
133
+ )
134
+
135
+ useProvideFormItemContext(
136
+ {
137
+ id: filedId,
138
+ onFieldChange,
139
+ onFieldBlur
140
+ } ,
141
+ computed(() => get(context.dataSource.value, props.name ))
142
+ )
143
+
144
+ onBeforeUnmount(() => {
145
+ hideErrorTip()
146
+ })
147
+
148
+ watch(
149
+ () => [filedName.value, props.name],
150
+ () => {
151
+ context.addField(eventKey.value, {
152
+ filedName: filedName.value,
153
+ eventKey: eventKey.value,
154
+ names: props.name,
155
+ validateRules,
156
+ showErrorTip
157
+ })
158
+ },
159
+ { immediate: true }
160
+ )
161
+
162
+ return {
163
+ hashId,
164
+ eventKey,
165
+ errorMap,
166
+ popContainer
167
+ }
168
+ }
169
+ })