resolver-egretimp-plus 0.1.119 → 0.1.121

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 (225) hide show
  1. package/dist/h5/index.js +18 -18
  2. package/dist/web/index.js +11 -11
  3. package/package.json +1 -1
  4. package/src/components/options/OptionsDefault.vue +0 -1
  5. package/src/components/packages-web/CustomComponentCycle.vue +38 -33
  6. package/src/components/packages-web/CustomComponentCycleTabPane.vue +40 -33
  7. package/src/components/packages-web/CustomComponentPlain.vue +6 -5
  8. package/src/components/packages-web/CustomComponentTable.jsx +48 -40
  9. package/src/components/packages-web/ElInput copy.jsx +0 -1
  10. package/src/components/packages-web/ElInput.jsx +0 -1
  11. package/src/config.js +2 -0
  12. package/src/hooks/pageConfig.js +10 -4
  13. package/src/index.jsx +15 -10
  14. package/src/renderer.jsx +4 -1
  15. package/src/resolver-common.vue +22 -2
  16. package/src/rules/rulesDriver.js +4 -0
  17. package/src/utils/common.js +13 -0
  18. package/src/utils/render.jsx +196 -96
  19. package/src-bak/analysisComponent.jsx +0 -343
  20. package/src-bak/api/builtIn.js +0 -10
  21. package/src-bak/bpm/bpmInstance.js +0 -388
  22. package/src-bak/bpm/udc-sdk-esm/cjs/impl/application.js +0 -8
  23. package/src-bak/bpm/udc-sdk-esm/cjs/impl/component.js +0 -97
  24. package/src-bak/bpm/udc-sdk-esm/cjs/impl/datasource.js +0 -88
  25. package/src-bak/bpm/udc-sdk-esm/cjs/impl/iframe/index.js +0 -3
  26. package/src-bak/bpm/udc-sdk-esm/cjs/impl/iframe/udcSdkForIframe/UdcComponent.js +0 -76
  27. package/src-bak/bpm/udc-sdk-esm/cjs/impl/iframe/udcSdkForIframe/index.js +0 -201
  28. package/src-bak/bpm/udc-sdk-esm/cjs/impl/index.js +0 -69
  29. package/src-bak/bpm/udc-sdk-esm/cjs/impl/page.js +0 -56
  30. package/src-bak/bpm/udc-sdk-esm/cjs/impl/utils.js +0 -76
  31. package/src-bak/bpm/udc-sdk-esm/cjs/index.js +0 -46
  32. package/src-bak/bpm/udc-sdk-esm/cjs/utils.js +0 -21
  33. package/src-bak/components/childDialog/index.js +0 -39
  34. package/src-bak/components/childDialog/src/index.vue +0 -185
  35. package/src-bak/components/cmiFormItem/index.js +0 -1
  36. package/src-bak/components/cmiFormItem/src/index.vue +0 -112
  37. package/src-bak/components/confirmInstance-H5/index.js +0 -53
  38. package/src-bak/components/confirmInstance-H5/src/index.vue +0 -54
  39. package/src-bak/components/helper/FormPolyfill.jsx +0 -25
  40. package/src-bak/components/helper/calcTooltip.jsx +0 -134
  41. package/src-bak/components/helper/dock.js +0 -141
  42. package/src-bak/components/helper/eventOrchestration.js +0 -763
  43. package/src-bak/components/helper/resolver.js +0 -163
  44. package/src-bak/components/helper/table.jsx +0 -103
  45. package/src-bak/components/icons/date.vue +0 -33
  46. package/src-bak/components/icons/info.vue +0 -62
  47. package/src-bak/components/icons/loading.vue +0 -19
  48. package/src-bak/components/icons/question-filled.vue +0 -8
  49. package/src-bak/components/loading/index.js +0 -6
  50. package/src-bak/components/loading/loading.js +0 -98
  51. package/src-bak/components/loading/loading.scss +0 -74
  52. package/src-bak/components/loading/loading.vue +0 -89
  53. package/src-bak/components/loadingComponent/LoadingComponent.vue +0 -33
  54. package/src-bak/components/modal/index.js +0 -9
  55. package/src-bak/components/modal/modal.scss +0 -195
  56. package/src-bak/components/modal/modal.vue +0 -201
  57. package/src-bak/components/options/OptionsDefault.vue +0 -47
  58. package/src-bak/components/packages-H5/CmiButton.vue +0 -120
  59. package/src-bak/components/packages-H5/CmiCalendar.vue +0 -152
  60. package/src-bak/components/packages-H5/CmiCell.vue +0 -87
  61. package/src-bak/components/packages-H5/CmiCheckbox.vue +0 -82
  62. package/src-bak/components/packages-H5/CmiDatetimePicker.vue +0 -98
  63. package/src-bak/components/packages-H5/CmiDivider.vue +0 -30
  64. package/src-bak/components/packages-H5/CmiDropdownMenu.vue +0 -58
  65. package/src-bak/components/packages-H5/CmiInput.vue +0 -69
  66. package/src-bak/components/packages-H5/CmiLink.vue +0 -28
  67. package/src-bak/components/packages-H5/CmiPicker.vue +0 -229
  68. package/src-bak/components/packages-H5/CmiRadio.vue +0 -29
  69. package/src-bak/components/packages-H5/CmiSearch.vue +0 -39
  70. package/src-bak/components/packages-H5/CmiSelect.vue +0 -84
  71. package/src-bak/components/packages-H5/CustomComponentCardH5.vue +0 -129
  72. package/src-bak/components/packages-H5/CustomComponentColH5.vue +0 -8
  73. package/src-bak/components/packages-H5/CustomComponentCollapseH5.vue +0 -141
  74. package/src-bak/components/packages-H5/CustomComponentFormLayoutH5.vue +0 -54
  75. package/src-bak/components/packages-H5/CustomComponentTabPaneH5.vue +0 -38
  76. package/src-bak/components/packages-H5/CustomComponentTableH5.vue +0 -352
  77. package/src-bak/components/packages-H5/CustomComponentTabsH5.vue +0 -170
  78. package/src-bak/components/packages-web/CustomComponentCard.vue +0 -40
  79. package/src-bak/components/packages-web/CustomComponentCol.vue +0 -66
  80. package/src-bak/components/packages-web/CustomComponentCollapse.vue +0 -164
  81. package/src-bak/components/packages-web/CustomComponentCycle.vue +0 -95
  82. package/src-bak/components/packages-web/CustomComponentCycleTabPane.vue +0 -155
  83. package/src-bak/components/packages-web/CustomComponentDialog.vue +0 -192
  84. package/src-bak/components/packages-web/CustomComponentEditor.vue +0 -50
  85. package/src-bak/components/packages-web/CustomComponentFileExport.vue +0 -60
  86. package/src-bak/components/packages-web/CustomComponentFileImport.vue +0 -60
  87. package/src-bak/components/packages-web/CustomComponentFormLayout.vue +0 -65
  88. package/src-bak/components/packages-web/CustomComponentGrid.vue +0 -29
  89. package/src-bak/components/packages-web/CustomComponentGridCol.vue +0 -29
  90. package/src-bak/components/packages-web/CustomComponentInputDialog.vue +0 -144
  91. package/src-bak/components/packages-web/CustomComponentNativeTabPane.vue +0 -84
  92. package/src-bak/components/packages-web/CustomComponentPlain.vue +0 -247
  93. package/src-bak/components/packages-web/CustomComponentRow.vue +0 -83
  94. package/src-bak/components/packages-web/CustomComponentSelectEmployees.vue +0 -203
  95. package/src-bak/components/packages-web/CustomComponentSendMail.vue +0 -62
  96. package/src-bak/components/packages-web/CustomComponentSteps.vue +0 -41
  97. package/src-bak/components/packages-web/CustomComponentTabPane.vue +0 -20
  98. package/src-bak/components/packages-web/CustomComponentTable.jsx +0 -814
  99. package/src-bak/components/packages-web/CustomComponentTabs.vue +0 -126
  100. package/src-bak/components/packages-web/CustomComponentTree.vue +0 -28
  101. package/src-bak/components/packages-web/ElButton.vue +0 -146
  102. package/src-bak/components/packages-web/ElCheckbox.vue +0 -97
  103. package/src-bak/components/packages-web/ElDatePicker.vue +0 -93
  104. package/src-bak/components/packages-web/ElInput copy.jsx +0 -393
  105. package/src-bak/components/packages-web/ElInput.jsx +0 -312
  106. package/src-bak/components/packages-web/ElInputNumber.vue +0 -81
  107. package/src-bak/components/packages-web/ElPagination.vue +0 -61
  108. package/src-bak/components/packages-web/ElRadio.vue +0 -47
  109. package/src-bak/components/packages-web/ElSelect.jsx +0 -249
  110. package/src-bak/components/packages-web/ElSelect_bak.vue +0 -155
  111. package/src-bak/components/packages-web/ElText.jsx +0 -187
  112. package/src-bak/components/packages-web/ElTextaa.vue +0 -169
  113. package/src-bak/components/packages-web/ElTimePicker.vue +0 -39
  114. package/src-bak/components/patchComponents-H5.js +0 -46
  115. package/src-bak/components/patchComponents-web.js +0 -46
  116. package/src-bak/components/simpleFormItemPc/index.js +0 -1
  117. package/src-bak/components/simpleFormItemPc/src/index.vue +0 -94
  118. package/src-bak/components/table/index.ts +0 -29
  119. package/src-bak/components/table/src/composables/use-scrollbar.ts +0 -30
  120. package/src-bak/components/table/src/config.ts +0 -256
  121. package/src-bak/components/table/src/filter-panel.vue +0 -260
  122. package/src-bak/components/table/src/h-helper.ts +0 -34
  123. package/src-bak/components/table/src/layout-observer.ts +0 -78
  124. package/src-bak/components/table/src/store/current.ts +0 -85
  125. package/src-bak/components/table/src/store/expand.ts +0 -76
  126. package/src-bak/components/table/src/store/helper.ts +0 -74
  127. package/src-bak/components/table/src/store/index.ts +0 -246
  128. package/src-bak/components/table/src/store/tree.ts +0 -230
  129. package/src-bak/components/table/src/store/watcher.ts +0 -543
  130. package/src-bak/components/table/src/table/defaults.ts +0 -402
  131. package/src-bak/components/table/src/table/key-render-helper.ts +0 -27
  132. package/src-bak/components/table/src/table/style-helper.ts +0 -378
  133. package/src-bak/components/table/src/table/utils-helper.ts +0 -47
  134. package/src-bak/components/table/src/table-body/defaults.ts +0 -52
  135. package/src-bak/components/table/src/table-body/events-helper.ts +0 -203
  136. package/src-bak/components/table/src/table-body/index.ts +0 -119
  137. package/src-bak/components/table/src/table-body/render-helper.ts +0 -283
  138. package/src-bak/components/table/src/table-body/styles-helper.ts +0 -164
  139. package/src-bak/components/table/src/table-column/defaults.ts +0 -237
  140. package/src-bak/components/table/src/table-column/index.ts +0 -202
  141. package/src-bak/components/table/src/table-column/render-helper.ts +0 -214
  142. package/src-bak/components/table/src/table-column/watcher-helper.ts +0 -88
  143. package/src-bak/components/table/src/table-footer/index.ts +0 -128
  144. package/src-bak/components/table/src/table-footer/mapState-helper.ts +0 -33
  145. package/src-bak/components/table/src/table-footer/style-helper.ts +0 -51
  146. package/src-bak/components/table/src/table-header/event-helper.ts +0 -213
  147. package/src-bak/components/table/src/table-header/index.ts +0 -244
  148. package/src-bak/components/table/src/table-header/style.helper.ts +0 -119
  149. package/src-bak/components/table/src/table-header/utils-helper.ts +0 -94
  150. package/src-bak/components/table/src/table-layout.ts +0 -259
  151. package/src-bak/components/table/src/table.vue +0 -389
  152. package/src-bak/components/table/src/tableColumn.ts +0 -3
  153. package/src-bak/components/table/src/tokens.ts +0 -5
  154. package/src-bak/components/table/src/util.ts +0 -521
  155. package/src-bak/components/table/style/css.ts +0 -5
  156. package/src-bak/components/table/style/index.ts +0 -5
  157. package/src-bak/components/tabs/index.js +0 -8
  158. package/src-bak/components/tabs/src/constants.js +0 -23
  159. package/src-bak/components/tabs/src/tab-bar.js +0 -8
  160. package/src-bak/components/tabs/src/tab-bar.vue +0 -92
  161. package/src-bak/components/tabs/src/tab-nav.jsx +0 -424
  162. package/src-bak/components/tabs/src/tab-pane.js +0 -16
  163. package/src-bak/components/tabs/src/tab-pane.vue +0 -80
  164. package/src-bak/components/tabs/src/tabs.jsx +0 -223
  165. package/src-bak/components/tabs/style/css.js +0 -2
  166. package/src-bak/components/tabs/style/index.js +0 -2
  167. package/src-bak/components/thirdPartyFrame/index.js +0 -32
  168. package/src-bak/components/thirdPartyFrame/src/ThirdPartyFrame.vue +0 -125
  169. package/src-bak/enums/index.js +0 -16
  170. package/src-bak/hooks/configLoad.js +0 -45
  171. package/src-bak/hooks/index.js +0 -189
  172. package/src-bak/hooks/mock.js +0 -6960
  173. package/src-bak/hooks/pageConfig.js +0 -127
  174. package/src-bak/index.jsx +0 -443
  175. package/src-bak/renderer.jsx +0 -77
  176. package/src-bak/resolver-H5.vue +0 -88
  177. package/src-bak/resolver-common.vue +0 -129
  178. package/src-bak/resolver-web.vue +0 -91
  179. package/src-bak/rules/eventsSupplement.js +0 -573
  180. package/src-bak/rules/parseCondition.js +0 -378
  181. package/src-bak/rules/ruleUtils.js +0 -273
  182. package/src-bak/rules/rulesDriver.js +0 -139
  183. package/src-bak/rulesImp/events.js +0 -588
  184. package/src-bak/rulesImp/index.js +0 -33
  185. package/src-bak/rulesImp/ruleInstance.js +0 -231
  186. package/src-bak/rulesImp/ruleUtils.js +0 -124
  187. package/src-bak/theme/element/components/button.scss +0 -122
  188. package/src-bak/theme/element/components/card.scss +0 -8
  189. package/src-bak/theme/element/components/checkbox.scss +0 -19
  190. package/src-bak/theme/element/components/collapse.scss +0 -174
  191. package/src-bak/theme/element/components/common.scss +0 -30
  192. package/src-bak/theme/element/components/cycle.scss +0 -0
  193. package/src-bak/theme/element/components/date.scss +0 -13
  194. package/src-bak/theme/element/components/dialog.scss +0 -44
  195. package/src-bak/theme/element/components/form.scss +0 -104
  196. package/src-bak/theme/element/components/index.scss +0 -55
  197. package/src-bak/theme/element/components/input.scss +0 -36
  198. package/src-bak/theme/element/components/message.scss +0 -48
  199. package/src-bak/theme/element/components/pagination.scss +0 -47
  200. package/src-bak/theme/element/components/popper.scss +0 -3
  201. package/src-bak/theme/element/components/radio.scss +0 -40
  202. package/src-bak/theme/element/components/scrollbar.scss +0 -14
  203. package/src-bak/theme/element/components/select.scss +0 -82
  204. package/src-bak/theme/element/components/steps.scss +0 -6
  205. package/src-bak/theme/element/components/table.scss +0 -218
  206. package/src-bak/theme/element/components/tabs.scss +0 -128
  207. package/src-bak/theme/element/components/tag.scss +0 -6
  208. package/src-bak/theme/element/components/text.scss +0 -20
  209. package/src-bak/theme/element/components/textarea.scss +0 -3
  210. package/src-bak/theme/element/components/tree.scss +0 -0
  211. package/src-bak/theme/element/index.scss +0 -55
  212. package/src-bak/utils/cipher.js +0 -141
  213. package/src-bak/utils/common.js +0 -664
  214. package/src-bak/utils/const.js +0 -259
  215. package/src-bak/utils/defaultVal.js +0 -92
  216. package/src-bak/utils/dom.js +0 -36
  217. package/src-bak/utils/format.js +0 -19
  218. package/src-bak/utils/index.js +0 -4
  219. package/src-bak/utils/is.js +0 -74
  220. package/src-bak/utils/loadModule.js +0 -75
  221. package/src-bak/utils/preserveFunc.js +0 -33
  222. package/src-bak/utils/render.jsx +0 -1138
  223. package/src-bak/utils/request.js +0 -136
  224. package/src-bak/utils/respone.js +0 -70
  225. package/src-bak/utils/valid.js +0 -89
@@ -1,76 +0,0 @@
1
- // @ts-nocheck
2
- import { getCurrentInstance, ref } from 'vue'
3
- import { getKeysMap, getRowIdentity, toggleRowStatus } from '../util'
4
-
5
- import type { Ref } from 'vue'
6
- import type { WatcherPropsData } from '.'
7
- import type { Table } from '../table/defaults'
8
-
9
- function useExpand<T>(watcherData: WatcherPropsData<T>) {
10
- const instance = getCurrentInstance() as Table<T>
11
- const defaultExpandAll = ref(false)
12
- const expandRows: Ref<T[]> = ref([])
13
- const updateExpandRows = () => {
14
- const data = watcherData.data.value || []
15
- const rowKey = watcherData.rowKey.value
16
- if (defaultExpandAll.value) {
17
- expandRows.value = data.slice()
18
- } else if (rowKey) {
19
- // TODO:这里的代码可以优化
20
- const expandRowsMap = getKeysMap(expandRows.value, rowKey)
21
- expandRows.value = data.reduce((prev: T[], row: T) => {
22
- const rowId = getRowIdentity(row, rowKey)
23
- const rowInfo = expandRowsMap[rowId]
24
- if (rowInfo) {
25
- prev.push(row)
26
- }
27
- return prev
28
- }, [])
29
- } else {
30
- expandRows.value = []
31
- }
32
- }
33
-
34
- const toggleRowExpansion = (row: T, expanded?: boolean) => {
35
- const changed = toggleRowStatus(expandRows.value, row, expanded)
36
- if (changed) {
37
- instance.emit('expand-change', row, expandRows.value.slice())
38
- }
39
- }
40
-
41
- const setExpandRowKeys = (rowKeys: string[]) => {
42
- instance.store.assertRowKey()
43
- // TODO:这里的代码可以优化
44
- const data = watcherData.data.value || []
45
- const rowKey = watcherData.rowKey.value
46
- const keysMap = getKeysMap(data, rowKey)
47
- expandRows.value = rowKeys.reduce((prev: T[], cur: string) => {
48
- const info = keysMap[cur]
49
- if (info) {
50
- prev.push(info.row)
51
- }
52
- return prev
53
- }, [])
54
- }
55
-
56
- const isRowExpanded = (row: T): boolean => {
57
- const rowKey = watcherData.rowKey.value
58
- if (rowKey) {
59
- const expandMap = getKeysMap(expandRows.value, rowKey)
60
- return !!expandMap[getRowIdentity(row, rowKey)]
61
- }
62
- return expandRows.value.includes(row)
63
- }
64
- return {
65
- updateExpandRows,
66
- toggleRowExpansion,
67
- setExpandRowKeys,
68
- isRowExpanded,
69
- states: {
70
- expandRows,
71
- defaultExpandAll,
72
- },
73
- }
74
- }
75
-
76
- export default useExpand
@@ -1,74 +0,0 @@
1
- // @ts-nocheck
2
- import { watch } from 'vue'
3
- import { debounce } from 'lodash-unified'
4
- import useStore from '.'
5
-
6
- import type { Store } from '.'
7
- import type { Table, TableProps } from '../table/defaults'
8
-
9
- const InitialStateMap = {
10
- rowKey: 'rowKey',
11
- defaultExpandAll: 'defaultExpandAll',
12
- selectOnIndeterminate: 'selectOnIndeterminate',
13
- indent: 'indent',
14
- lazy: 'lazy',
15
- data: 'data',
16
- ['treeProps.hasChildren']: {
17
- key: 'lazyColumnIdentifier',
18
- default: 'hasChildren',
19
- },
20
- ['treeProps.children']: {
21
- key: 'childrenColumnName',
22
- default: 'children',
23
- },
24
- }
25
-
26
- export function createStore<T>(table: Table<T>, props: TableProps<T>) {
27
- if (!table) {
28
- throw new Error('Table is required.')
29
- }
30
-
31
- const store = useStore<T>()
32
- // fix https://github.com/ElemeFE/element/issues/14075
33
- // related pr https://github.com/ElemeFE/element/pull/14146
34
- store.toggleAllSelection = debounce(store._toggleAllSelection, 10)
35
- Object.keys(InitialStateMap).forEach((key) => {
36
- handleValue(getArrKeysValue(props, key), key, store)
37
- })
38
- proxyTableProps(store, props)
39
- return store
40
- }
41
-
42
- function proxyTableProps<T>(store: Store<T>, props: TableProps<T>) {
43
- Object.keys(InitialStateMap).forEach((key) => {
44
- watch(
45
- () => getArrKeysValue(props, key),
46
- (value) => {
47
- handleValue(value, key, store)
48
- }
49
- )
50
- })
51
- }
52
-
53
- function handleValue<T>(value, propsKey: string, store: Store<T>) {
54
- let newVal = value
55
- let storeKey = InitialStateMap[propsKey]
56
- if (typeof InitialStateMap[propsKey] === 'object') {
57
- storeKey = storeKey.key
58
- newVal = newVal || InitialStateMap[propsKey].default
59
- }
60
- store.states[storeKey].value = newVal
61
- }
62
-
63
- function getArrKeysValue<T>(props: TableProps<T>, keys: string) {
64
- if (keys.includes('.')) {
65
- const keyList = keys.split('.')
66
- let value = props
67
- keyList.forEach((key) => {
68
- value = value[key]
69
- })
70
- return value
71
- } else {
72
- return props[keys]
73
- }
74
- }
@@ -1,246 +0,0 @@
1
- // @ts-nocheck
2
- import { getCurrentInstance, nextTick, unref } from 'vue'
3
- import { useNamespace } from 'element-plus/es/hooks/index.mjs'
4
- import useWatcher from './watcher'
5
-
6
- import type { Ref } from 'vue'
7
- import type { TableColumnCtx } from '../table-column/defaults'
8
- import type { Filter, Sort, Table } from '../table/defaults'
9
-
10
- interface WatcherPropsData<T> {
11
- data: Ref<T[]>
12
- rowKey: Ref<string>
13
- }
14
-
15
- function replaceColumn<T>(
16
- array: TableColumnCtx<T>[],
17
- column: TableColumnCtx<T>
18
- ) {
19
- return array.map((item) => {
20
- if (item.id === column.id) {
21
- return column
22
- } else if (item.children?.length) {
23
- item.children = replaceColumn(item.children, column)
24
- }
25
- return item
26
- })
27
- }
28
-
29
- function sortColumn<T>(array: TableColumnCtx<T>[]) {
30
- array.forEach((item) => {
31
- item.no = item.getColumnIndex?.()
32
- if (item.children?.length) {
33
- sortColumn(item.children)
34
- }
35
- })
36
- array.sort((cur, pre) => cur.no - pre.no)
37
- }
38
-
39
- function useStore<T>() {
40
- const instance = getCurrentInstance() as Table<T>
41
- const watcher = useWatcher<T>()
42
- const ns = useNamespace('table')
43
- type StoreStates = typeof watcher.states
44
- const mutations = {
45
- setData(states: StoreStates, data: T[]) {
46
- const dataInstanceChanged = unref(states._data) !== data
47
- states.data.value = data
48
- states._data.value = data
49
- instance.store.execQuery()
50
- // 数据变化,更新部分数据。
51
- // 没有使用 computed,而是手动更新部分数据 https://github.com/vuejs/vue/issues/6660#issuecomment-331417140
52
- instance.store.updateCurrentRowData()
53
- instance.store.updateExpandRows()
54
- instance.store.updateTreeData(
55
- instance.store.states.defaultExpandAll.value
56
- )
57
- if (unref(states.reserveSelection)) {
58
- instance.store.assertRowKey()
59
- instance.store.updateSelectionByRowKey()
60
- } else {
61
- if (dataInstanceChanged) {
62
- instance.store.clearSelection()
63
- } else {
64
- instance.store.cleanSelection()
65
- }
66
- }
67
- instance.store.updateAllSelected()
68
- if (instance.$ready) {
69
- instance.store.scheduleLayout()
70
- }
71
- },
72
-
73
- insertColumn(
74
- states: StoreStates,
75
- column: TableColumnCtx<T>,
76
- parent: TableColumnCtx<T>,
77
- updateColumnOrder: () => void
78
- ) {
79
- const array = unref(states._columns)
80
- let newColumns = []
81
- if (!parent) {
82
- array.push(column)
83
- newColumns = array
84
- } else {
85
- if (parent && !parent.children) {
86
- parent.children = []
87
- }
88
- parent.children.push(column)
89
- newColumns = replaceColumn(array, parent)
90
- }
91
- sortColumn(newColumns)
92
- states._columns.value = newColumns
93
- states.updateOrderFns.push(updateColumnOrder)
94
- if (column.type === 'selection') {
95
- states.selectable.value = column.selectable
96
- states.reserveSelection.value = column.reserveSelection
97
- }
98
- if (instance.$ready) {
99
- instance.store.updateColumns() // hack for dynamics insert column
100
- instance.store.scheduleLayout()
101
- }
102
- },
103
-
104
- updateColumnOrder(states: StoreStates, column: TableColumnCtx<T>) {
105
- const newColumnIndex = column.getColumnIndex?.()
106
- if (newColumnIndex === column.no) return
107
-
108
- sortColumn(states._columns.value)
109
-
110
- if (instance.$ready) {
111
- instance.store.updateColumns()
112
- }
113
- },
114
-
115
- removeColumn(
116
- states: StoreStates,
117
- column: TableColumnCtx<T>,
118
- parent: TableColumnCtx<T>,
119
- updateColumnOrder: () => void
120
- ) {
121
- const array = unref(states._columns) || []
122
- if (parent) {
123
- parent.children.splice(
124
- parent.children.findIndex((item) => item.id === column.id),
125
- 1
126
- )
127
- // fix #10699, delete parent.children immediately will trigger again
128
- nextTick(() => {
129
- if (parent.children?.length === 0) {
130
- delete parent.children
131
- }
132
- })
133
- states._columns.value = replaceColumn(array, parent)
134
- } else {
135
- const index = array.indexOf(column)
136
- if (index > -1) {
137
- array.splice(index, 1)
138
- states._columns.value = array
139
- }
140
- }
141
-
142
- const updateFnIndex = states.updateOrderFns.indexOf(updateColumnOrder)
143
- updateFnIndex > -1 && states.updateOrderFns.splice(updateFnIndex, 1)
144
-
145
- if (instance.$ready) {
146
- instance.store.updateColumns() // hack for dynamics remove column
147
- instance.store.scheduleLayout()
148
- }
149
- },
150
-
151
- sort(states: StoreStates, options: Sort) {
152
- const { prop, order, init } = options
153
- if (prop) {
154
- const column = unref(states.columns).find(
155
- (column) => column.property === prop
156
- )
157
- if (column) {
158
- column.order = order
159
- instance.store.updateSort(column, prop, order)
160
- instance.store.commit('changeSortCondition', { init })
161
- }
162
- }
163
- },
164
-
165
- changeSortCondition(states: StoreStates, options: Sort) {
166
- // 修复 pr https://github.com/ElemeFE/element/pull/15012 导致的 bug
167
- // https://github.com/element-plus/element-plus/pull/4640
168
- const { sortingColumn, sortProp, sortOrder } = states
169
- const columnValue = unref(sortingColumn),
170
- propValue = unref(sortProp),
171
- orderValue = unref(sortOrder)
172
- if (orderValue === null) {
173
- states.sortingColumn.value = null
174
- states.sortProp.value = null
175
- }
176
- const ignore = { filter: true }
177
- instance.store.execQuery(ignore)
178
-
179
- if (!options || !(options.silent || options.init)) {
180
- instance.emit('sort-change', {
181
- column: columnValue,
182
- prop: propValue,
183
- order: orderValue,
184
- })
185
- }
186
-
187
- instance.store.updateTableScrollY()
188
- },
189
-
190
- filterChange(_states: StoreStates, options: Filter<T>) {
191
- const { column, values, silent } = options
192
- const newFilters = instance.store.updateFilters(column, values)
193
- instance.store.execQuery()
194
-
195
- if (!silent) {
196
- instance.emit('filter-change', newFilters)
197
- }
198
- instance.store.updateTableScrollY()
199
- },
200
-
201
- toggleAllSelection() {
202
- instance.store.toggleAllSelection()
203
- },
204
-
205
- rowSelectedChanged(_states, row: T) {
206
- instance.store.toggleRowSelection(row)
207
- instance.store.updateAllSelected()
208
- },
209
-
210
- setHoverRow(states: StoreStates, row: T) {
211
- states.hoverRow.value = row
212
- },
213
-
214
- setCurrentRow(_states, row: T) {
215
- instance.store.updateCurrentRow(row)
216
- },
217
- }
218
- const commit = function (name: keyof typeof mutations, ...args) {
219
- const mutations = instance.store.mutations
220
- if (mutations[name]) {
221
- mutations[name].apply(instance, [instance.store.states].concat(args))
222
- } else {
223
- throw new Error(`Action not found: ${name}`)
224
- }
225
- }
226
- const updateTableScrollY = function () {
227
- nextTick(() => instance.layout.updateScrollY.apply(instance.layout))
228
- }
229
- return {
230
- ns,
231
- ...watcher,
232
- mutations,
233
- commit,
234
- updateTableScrollY,
235
- }
236
- }
237
-
238
- export default useStore
239
-
240
- class HelperStore<T> {
241
- Return = useStore<T>()
242
- }
243
-
244
- type StoreFilter = Record<string, string[]>
245
- type Store<T> = HelperStore<T>['Return']
246
- export type { WatcherPropsData, Store, StoreFilter }
@@ -1,230 +0,0 @@
1
- // @ts-nocheck
2
- import { computed, getCurrentInstance, ref, unref, watch } from 'vue'
3
- import { getRowIdentity, walkTreeNode } from '../util'
4
-
5
- import type { WatcherPropsData } from '.'
6
- import type { Table, TableProps } from '../table/defaults'
7
-
8
- function useTree<T>(watcherData: WatcherPropsData<T>) {
9
- const expandRowKeys = ref<string[]>([])
10
- const treeData = ref<unknown>({})
11
- const indent = ref(16)
12
- const lazy = ref(false)
13
- const lazyTreeNodeMap = ref({})
14
- const lazyColumnIdentifier = ref('hasChildren')
15
- const childrenColumnName = ref('children')
16
- const instance = getCurrentInstance() as Table<T>
17
- const normalizedData = computed(() => {
18
- if (!watcherData.rowKey.value) return {}
19
- const data = watcherData.data.value || []
20
- return normalize(data)
21
- })
22
- const normalizedLazyNode = computed(() => {
23
- const rowKey = watcherData.rowKey.value
24
- const keys = Object.keys(lazyTreeNodeMap.value)
25
- const res = {}
26
- if (!keys.length) return res
27
- keys.forEach((key) => {
28
- if (lazyTreeNodeMap.value[key].length) {
29
- const item = { children: [] }
30
- lazyTreeNodeMap.value[key].forEach((row) => {
31
- const currentRowKey = getRowIdentity(row, rowKey)
32
- item.children.push(currentRowKey)
33
- if (row[lazyColumnIdentifier.value] && !res[currentRowKey]) {
34
- res[currentRowKey] = { children: [] }
35
- }
36
- })
37
- res[key] = item
38
- }
39
- })
40
- return res
41
- })
42
-
43
- const normalize = (data) => {
44
- const rowKey = watcherData.rowKey.value
45
- const res = {}
46
- walkTreeNode(
47
- data,
48
- (parent, children, level) => {
49
- const parentId = getRowIdentity(parent, rowKey)
50
- if (Array.isArray(children)) {
51
- res[parentId] = {
52
- children: children.map((row) => getRowIdentity(row, rowKey)),
53
- level,
54
- }
55
- } else if (lazy.value) {
56
- // 当 children 不存在且 lazy 为 true,该节点即为懒加载的节点
57
- res[parentId] = {
58
- children: [],
59
- lazy: true,
60
- level,
61
- }
62
- }
63
- },
64
- childrenColumnName.value,
65
- lazyColumnIdentifier.value
66
- )
67
- return res
68
- }
69
-
70
- const updateTreeData = (
71
- ifChangeExpandRowKeys = false,
72
- ifExpandAll = instance.store?.states.defaultExpandAll.value
73
- ) => {
74
- const nested = normalizedData.value
75
- const normalizedLazyNode_ = normalizedLazyNode.value
76
- const keys = Object.keys(nested)
77
- const newTreeData = {}
78
- if (keys.length) {
79
- const oldTreeData = unref(treeData)
80
- const rootLazyRowKeys = []
81
- const getExpanded = (oldValue, key) => {
82
- if (ifChangeExpandRowKeys) {
83
- if (expandRowKeys.value) {
84
- return ifExpandAll || expandRowKeys.value.includes(key)
85
- } else {
86
- return !!(ifExpandAll || oldValue?.expanded)
87
- }
88
- } else {
89
- const included =
90
- ifExpandAll ||
91
- (expandRowKeys.value && expandRowKeys.value.includes(key))
92
- return !!(oldValue?.expanded || included)
93
- }
94
- }
95
- // 合并 expanded 与 display,确保数据刷新后,状态不变
96
- keys.forEach((key) => {
97
- const oldValue = oldTreeData[key]
98
- const newValue = { ...nested[key] }
99
- newValue.expanded = getExpanded(oldValue, key)
100
- if (newValue.lazy) {
101
- const { loaded = false, loading = false } = oldValue || {}
102
- newValue.loaded = !!loaded
103
- newValue.loading = !!loading
104
- rootLazyRowKeys.push(key)
105
- }
106
- newTreeData[key] = newValue
107
- })
108
- // 根据懒加载数据更新 treeData
109
- const lazyKeys = Object.keys(normalizedLazyNode_)
110
- if (lazy.value && lazyKeys.length && rootLazyRowKeys.length) {
111
- lazyKeys.forEach((key) => {
112
- const oldValue = oldTreeData[key]
113
- const lazyNodeChildren = normalizedLazyNode_[key].children
114
- if (rootLazyRowKeys.includes(key)) {
115
- // 懒加载的 root 节点,更新一下原有的数据,原来的 children 一定是空数组
116
- if (newTreeData[key].children.length !== 0) {
117
- throw new Error('[ElTable]children must be an empty array.')
118
- }
119
- newTreeData[key].children = lazyNodeChildren
120
- } else {
121
- const { loaded = false, loading = false } = oldValue || {}
122
- newTreeData[key] = {
123
- lazy: true,
124
- loaded: !!loaded,
125
- loading: !!loading,
126
- expanded: getExpanded(oldValue, key),
127
- children: lazyNodeChildren,
128
- level: '',
129
- }
130
- }
131
- })
132
- }
133
- }
134
- treeData.value = newTreeData
135
- instance.store?.updateTableScrollY()
136
- }
137
-
138
- watch(
139
- () => expandRowKeys.value,
140
- () => {
141
- updateTreeData(true)
142
- }
143
- )
144
-
145
- watch(
146
- () => normalizedData.value,
147
- () => {
148
- updateTreeData()
149
- }
150
- )
151
- watch(
152
- () => normalizedLazyNode.value,
153
- () => {
154
- updateTreeData()
155
- }
156
- )
157
-
158
- const updateTreeExpandKeys = (value: string[]) => {
159
- expandRowKeys.value = value
160
- updateTreeData()
161
- }
162
-
163
- const toggleTreeExpansion = (row: T, expanded?: boolean) => {
164
- instance.store.assertRowKey()
165
-
166
- const rowKey = watcherData.rowKey.value
167
- const id = getRowIdentity(row, rowKey)
168
- const data = id && treeData.value[id]
169
- if (id && data && 'expanded' in data) {
170
- const oldExpanded = data.expanded
171
- expanded = typeof expanded === 'undefined' ? !data.expanded : expanded
172
- treeData.value[id].expanded = expanded
173
- if (oldExpanded !== expanded) {
174
- instance.emit('expand-change', row, expanded)
175
- }
176
- instance.store.updateTableScrollY()
177
- }
178
- }
179
-
180
- const loadOrToggle = (row) => {
181
- instance.store.assertRowKey()
182
- const rowKey = watcherData.rowKey.value
183
- const id = getRowIdentity(row, rowKey)
184
- const data = treeData.value[id]
185
- if (lazy.value && data && 'loaded' in data && !data.loaded) {
186
- loadData(row, id, data)
187
- } else {
188
- toggleTreeExpansion(row, undefined)
189
- }
190
- }
191
-
192
- const loadData = (row: T, key: string, treeNode) => {
193
- const { load } = instance.props as unknown as TableProps<T>
194
- if (load && !treeData.value[key].loaded) {
195
- treeData.value[key].loading = true
196
- load(row, treeNode, (data) => {
197
- if (!Array.isArray(data)) {
198
- throw new TypeError('[ElTable] data must be an array')
199
- }
200
- treeData.value[key].loading = false
201
- treeData.value[key].loaded = true
202
- treeData.value[key].expanded = true
203
- if (data.length) {
204
- lazyTreeNodeMap.value[key] = data
205
- }
206
- instance.emit('expand-change', row, true)
207
- })
208
- }
209
- }
210
-
211
- return {
212
- loadData,
213
- loadOrToggle,
214
- toggleTreeExpansion,
215
- updateTreeExpandKeys,
216
- updateTreeData,
217
- normalize,
218
- states: {
219
- expandRowKeys,
220
- treeData,
221
- indent,
222
- lazy,
223
- lazyTreeNodeMap,
224
- lazyColumnIdentifier,
225
- childrenColumnName,
226
- },
227
- }
228
- }
229
-
230
- export default useTree