resolver-egretimp-plus 0.1.113 → 0.1.115

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 (219) hide show
  1. package/dist/h5/index.js +1 -1
  2. package/dist/theme/element/index.css +1 -1
  3. package/dist/theme/element/src/components/common.scss +4 -0
  4. package/dist/theme/element/src/components/text.scss +17 -0
  5. package/dist/web/index.js +2 -2
  6. package/package.json +1 -1
  7. package/src/analysisComponent.jsx +2 -1
  8. package/src/components/helper/table.jsx +26 -23
  9. package/src/components/packages-H5/CustomComponentCollapseH5.vue +6 -2
  10. package/src/components/packages-web/ElText.jsx +0 -1
  11. package/src/theme/element/components/common.scss +4 -0
  12. package/src/theme/element/components/text.scss +17 -0
  13. package/src-bak/analysisComponent.jsx +343 -0
  14. package/src-bak/api/builtIn.js +10 -0
  15. package/src-bak/bpm/bpmInstance.js +388 -0
  16. package/src-bak/bpm/udc-sdk-esm/cjs/impl/application.js +8 -0
  17. package/src-bak/bpm/udc-sdk-esm/cjs/impl/component.js +97 -0
  18. package/src-bak/bpm/udc-sdk-esm/cjs/impl/datasource.js +88 -0
  19. package/src-bak/bpm/udc-sdk-esm/cjs/impl/iframe/index.js +3 -0
  20. package/src-bak/bpm/udc-sdk-esm/cjs/impl/iframe/udcSdkForIframe/UdcComponent.js +76 -0
  21. package/src-bak/bpm/udc-sdk-esm/cjs/impl/iframe/udcSdkForIframe/index.js +201 -0
  22. package/src-bak/bpm/udc-sdk-esm/cjs/impl/index.js +69 -0
  23. package/src-bak/bpm/udc-sdk-esm/cjs/impl/page.js +56 -0
  24. package/src-bak/bpm/udc-sdk-esm/cjs/impl/utils.js +76 -0
  25. package/src-bak/bpm/udc-sdk-esm/cjs/index.js +46 -0
  26. package/src-bak/bpm/udc-sdk-esm/cjs/utils.js +21 -0
  27. package/src-bak/components/childDialog/index.js +39 -0
  28. package/src-bak/components/childDialog/src/index.vue +185 -0
  29. package/src-bak/components/cmiFormItem/index.js +1 -0
  30. package/src-bak/components/cmiFormItem/src/index.vue +112 -0
  31. package/src-bak/components/confirmInstance-H5/index.js +53 -0
  32. package/src-bak/components/confirmInstance-H5/src/index.vue +54 -0
  33. package/src-bak/components/helper/FormPolyfill.jsx +25 -0
  34. package/src-bak/components/helper/calcTooltip.jsx +134 -0
  35. package/src-bak/components/helper/dock.js +141 -0
  36. package/src-bak/components/helper/eventOrchestration.js +763 -0
  37. package/src-bak/components/helper/resolver.js +163 -0
  38. package/src-bak/components/helper/table.jsx +103 -0
  39. package/src-bak/components/icons/date.vue +33 -0
  40. package/src-bak/components/icons/info.vue +62 -0
  41. package/src-bak/components/icons/loading.vue +19 -0
  42. package/src-bak/components/icons/question-filled.vue +8 -0
  43. package/src-bak/components/loading/index.js +6 -0
  44. package/src-bak/components/loading/loading.js +98 -0
  45. package/src-bak/components/loading/loading.scss +74 -0
  46. package/src-bak/components/loading/loading.vue +89 -0
  47. package/src-bak/components/loadingComponent/LoadingComponent.vue +33 -0
  48. package/src-bak/components/modal/index.js +9 -0
  49. package/src-bak/components/modal/modal.scss +195 -0
  50. package/src-bak/components/modal/modal.vue +201 -0
  51. package/src-bak/components/options/OptionsDefault.vue +47 -0
  52. package/src-bak/components/packages-H5/CmiButton.vue +120 -0
  53. package/src-bak/components/packages-H5/CmiCalendar.vue +152 -0
  54. package/src-bak/components/packages-H5/CmiCell.vue +87 -0
  55. package/src-bak/components/packages-H5/CmiCheckbox.vue +82 -0
  56. package/src-bak/components/packages-H5/CmiDatetimePicker.vue +98 -0
  57. package/src-bak/components/packages-H5/CmiDivider.vue +30 -0
  58. package/src-bak/components/packages-H5/CmiDropdownMenu.vue +58 -0
  59. package/src-bak/components/packages-H5/CmiInput.vue +69 -0
  60. package/src-bak/components/packages-H5/CmiLink.vue +28 -0
  61. package/src-bak/components/packages-H5/CmiPicker.vue +229 -0
  62. package/src-bak/components/packages-H5/CmiRadio.vue +29 -0
  63. package/src-bak/components/packages-H5/CmiSearch.vue +39 -0
  64. package/src-bak/components/packages-H5/CmiSelect.vue +84 -0
  65. package/src-bak/components/packages-H5/CustomComponentCardH5.vue +129 -0
  66. package/src-bak/components/packages-H5/CustomComponentColH5.vue +8 -0
  67. package/src-bak/components/packages-H5/CustomComponentCollapseH5.vue +137 -0
  68. package/src-bak/components/packages-H5/CustomComponentFormLayoutH5.vue +54 -0
  69. package/src-bak/components/packages-H5/CustomComponentTabPaneH5.vue +38 -0
  70. package/src-bak/components/packages-H5/CustomComponentTableH5.vue +352 -0
  71. package/src-bak/components/packages-H5/CustomComponentTabsH5.vue +170 -0
  72. package/src-bak/components/packages-web/CustomComponentCard.vue +40 -0
  73. package/src-bak/components/packages-web/CustomComponentCol.vue +66 -0
  74. package/src-bak/components/packages-web/CustomComponentCollapse.vue +164 -0
  75. package/src-bak/components/packages-web/CustomComponentCycle.vue +95 -0
  76. package/src-bak/components/packages-web/CustomComponentCycleTabPane.vue +155 -0
  77. package/src-bak/components/packages-web/CustomComponentDialog.vue +192 -0
  78. package/src-bak/components/packages-web/CustomComponentEditor.vue +50 -0
  79. package/src-bak/components/packages-web/CustomComponentFileExport.vue +60 -0
  80. package/src-bak/components/packages-web/CustomComponentFileImport.vue +60 -0
  81. package/src-bak/components/packages-web/CustomComponentFormLayout.vue +65 -0
  82. package/src-bak/components/packages-web/CustomComponentGrid.vue +29 -0
  83. package/src-bak/components/packages-web/CustomComponentGridCol.vue +29 -0
  84. package/src-bak/components/packages-web/CustomComponentInputDialog.vue +144 -0
  85. package/src-bak/components/packages-web/CustomComponentNativeTabPane.vue +84 -0
  86. package/src-bak/components/packages-web/CustomComponentPlain.vue +243 -0
  87. package/src-bak/components/packages-web/CustomComponentRow.vue +83 -0
  88. package/src-bak/components/packages-web/CustomComponentSelectEmployees.vue +203 -0
  89. package/src-bak/components/packages-web/CustomComponentSendMail.vue +62 -0
  90. package/src-bak/components/packages-web/CustomComponentSteps.vue +41 -0
  91. package/src-bak/components/packages-web/CustomComponentTabPane.vue +20 -0
  92. package/src-bak/components/packages-web/CustomComponentTable.jsx +813 -0
  93. package/src-bak/components/packages-web/CustomComponentTabs.vue +126 -0
  94. package/src-bak/components/packages-web/CustomComponentTree.vue +28 -0
  95. package/src-bak/components/packages-web/ElButton.vue +146 -0
  96. package/src-bak/components/packages-web/ElCheckbox.vue +97 -0
  97. package/src-bak/components/packages-web/ElDatePicker.vue +93 -0
  98. package/src-bak/components/packages-web/ElInput copy.jsx +393 -0
  99. package/src-bak/components/packages-web/ElInput.jsx +312 -0
  100. package/src-bak/components/packages-web/ElInputNumber.vue +81 -0
  101. package/src-bak/components/packages-web/ElPagination.vue +61 -0
  102. package/src-bak/components/packages-web/ElRadio.vue +47 -0
  103. package/src-bak/components/packages-web/ElSelect.jsx +249 -0
  104. package/src-bak/components/packages-web/ElSelect_bak.vue +155 -0
  105. package/src-bak/components/packages-web/ElText.jsx +187 -0
  106. package/src-bak/components/packages-web/ElTextaa.vue +169 -0
  107. package/src-bak/components/packages-web/ElTimePicker.vue +39 -0
  108. package/src-bak/components/patchComponents-H5.js +46 -0
  109. package/src-bak/components/patchComponents-web.js +46 -0
  110. package/src-bak/components/simpleFormItemPc/index.js +1 -0
  111. package/src-bak/components/simpleFormItemPc/src/index.vue +94 -0
  112. package/src-bak/components/table/index.ts +29 -0
  113. package/src-bak/components/table/src/composables/use-scrollbar.ts +30 -0
  114. package/src-bak/components/table/src/config.ts +256 -0
  115. package/src-bak/components/table/src/filter-panel.vue +260 -0
  116. package/src-bak/components/table/src/h-helper.ts +34 -0
  117. package/src-bak/components/table/src/layout-observer.ts +78 -0
  118. package/src-bak/components/table/src/store/current.ts +85 -0
  119. package/src-bak/components/table/src/store/expand.ts +76 -0
  120. package/src-bak/components/table/src/store/helper.ts +74 -0
  121. package/src-bak/components/table/src/store/index.ts +246 -0
  122. package/src-bak/components/table/src/store/tree.ts +230 -0
  123. package/src-bak/components/table/src/store/watcher.ts +543 -0
  124. package/src-bak/components/table/src/table/defaults.ts +402 -0
  125. package/src-bak/components/table/src/table/key-render-helper.ts +27 -0
  126. package/src-bak/components/table/src/table/style-helper.ts +378 -0
  127. package/src-bak/components/table/src/table/utils-helper.ts +47 -0
  128. package/src-bak/components/table/src/table-body/defaults.ts +52 -0
  129. package/src-bak/components/table/src/table-body/events-helper.ts +203 -0
  130. package/src-bak/components/table/src/table-body/index.ts +119 -0
  131. package/src-bak/components/table/src/table-body/render-helper.ts +283 -0
  132. package/src-bak/components/table/src/table-body/styles-helper.ts +164 -0
  133. package/src-bak/components/table/src/table-column/defaults.ts +237 -0
  134. package/src-bak/components/table/src/table-column/index.ts +202 -0
  135. package/src-bak/components/table/src/table-column/render-helper.ts +214 -0
  136. package/src-bak/components/table/src/table-column/watcher-helper.ts +88 -0
  137. package/src-bak/components/table/src/table-footer/index.ts +128 -0
  138. package/src-bak/components/table/src/table-footer/mapState-helper.ts +33 -0
  139. package/src-bak/components/table/src/table-footer/style-helper.ts +51 -0
  140. package/src-bak/components/table/src/table-header/event-helper.ts +213 -0
  141. package/src-bak/components/table/src/table-header/index.ts +244 -0
  142. package/src-bak/components/table/src/table-header/style.helper.ts +119 -0
  143. package/src-bak/components/table/src/table-header/utils-helper.ts +94 -0
  144. package/src-bak/components/table/src/table-layout.ts +259 -0
  145. package/src-bak/components/table/src/table.vue +389 -0
  146. package/src-bak/components/table/src/tableColumn.ts +3 -0
  147. package/src-bak/components/table/src/tokens.ts +5 -0
  148. package/src-bak/components/table/src/util.ts +521 -0
  149. package/src-bak/components/table/style/css.ts +5 -0
  150. package/src-bak/components/table/style/index.ts +5 -0
  151. package/src-bak/components/tabs/index.js +8 -0
  152. package/src-bak/components/tabs/src/constants.js +23 -0
  153. package/src-bak/components/tabs/src/tab-bar.js +8 -0
  154. package/src-bak/components/tabs/src/tab-bar.vue +92 -0
  155. package/src-bak/components/tabs/src/tab-nav.jsx +424 -0
  156. package/src-bak/components/tabs/src/tab-pane.js +16 -0
  157. package/src-bak/components/tabs/src/tab-pane.vue +80 -0
  158. package/src-bak/components/tabs/src/tabs.jsx +223 -0
  159. package/src-bak/components/tabs/style/css.js +2 -0
  160. package/src-bak/components/tabs/style/index.js +2 -0
  161. package/src-bak/components/thirdPartyFrame/index.js +32 -0
  162. package/src-bak/components/thirdPartyFrame/src/ThirdPartyFrame.vue +125 -0
  163. package/src-bak/enums/index.js +16 -0
  164. package/src-bak/hooks/configLoad.js +45 -0
  165. package/src-bak/hooks/index.js +189 -0
  166. package/src-bak/hooks/mock.js +6960 -0
  167. package/src-bak/hooks/pageConfig.js +127 -0
  168. package/src-bak/index.jsx +440 -0
  169. package/src-bak/renderer.jsx +77 -0
  170. package/src-bak/resolver-H5.vue +88 -0
  171. package/src-bak/resolver-common.vue +129 -0
  172. package/src-bak/resolver-web.vue +91 -0
  173. package/src-bak/rules/eventsSupplement.js +573 -0
  174. package/src-bak/rules/parseCondition.js +378 -0
  175. package/src-bak/rules/ruleUtils.js +273 -0
  176. package/src-bak/rules/rulesDriver.js +118 -0
  177. package/src-bak/rulesImp/events.js +588 -0
  178. package/src-bak/rulesImp/index.js +33 -0
  179. package/src-bak/rulesImp/ruleInstance.js +231 -0
  180. package/src-bak/rulesImp/ruleUtils.js +124 -0
  181. package/src-bak/theme/element/components/button.scss +122 -0
  182. package/src-bak/theme/element/components/card.scss +8 -0
  183. package/src-bak/theme/element/components/checkbox.scss +19 -0
  184. package/src-bak/theme/element/components/collapse.scss +174 -0
  185. package/src-bak/theme/element/components/common.scss +30 -0
  186. package/src-bak/theme/element/components/cycle.scss +0 -0
  187. package/src-bak/theme/element/components/date.scss +13 -0
  188. package/src-bak/theme/element/components/dialog.scss +44 -0
  189. package/src-bak/theme/element/components/form.scss +104 -0
  190. package/src-bak/theme/element/components/index.scss +55 -0
  191. package/src-bak/theme/element/components/input.scss +36 -0
  192. package/src-bak/theme/element/components/message.scss +48 -0
  193. package/src-bak/theme/element/components/pagination.scss +47 -0
  194. package/src-bak/theme/element/components/popper.scss +3 -0
  195. package/src-bak/theme/element/components/radio.scss +40 -0
  196. package/src-bak/theme/element/components/scrollbar.scss +14 -0
  197. package/src-bak/theme/element/components/select.scss +82 -0
  198. package/src-bak/theme/element/components/steps.scss +6 -0
  199. package/{src/components/styles/CustomComponenTable.scss → src-bak/theme/element/components/table.scss} +90 -13
  200. package/src-bak/theme/element/components/tabs.scss +128 -0
  201. package/src-bak/theme/element/components/tag.scss +6 -0
  202. package/{src/components/styles → src-bak/theme/element/components}/text.scss +3 -3
  203. package/src-bak/theme/element/components/textarea.scss +3 -0
  204. package/src-bak/theme/element/components/tree.scss +0 -0
  205. package/src-bak/theme/element/index.scss +55 -0
  206. package/src-bak/utils/cipher.js +141 -0
  207. package/src-bak/utils/common.js +664 -0
  208. package/src-bak/utils/const.js +259 -0
  209. package/src-bak/utils/defaultVal.js +92 -0
  210. package/src-bak/utils/dom.js +36 -0
  211. package/src-bak/utils/format.js +19 -0
  212. package/src-bak/utils/index.js +4 -0
  213. package/src-bak/utils/is.js +74 -0
  214. package/src-bak/utils/loadModule.js +75 -0
  215. package/src-bak/utils/preserveFunc.js +33 -0
  216. package/src-bak/utils/render.jsx +1138 -0
  217. package/src-bak/utils/request.js +136 -0
  218. package/src-bak/utils/respone.js +70 -0
  219. package/src-bak/utils/valid.js +89 -0
@@ -0,0 +1,76 @@
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
@@ -0,0 +1,74 @@
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
+ }
@@ -0,0 +1,246 @@
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 }
@@ -0,0 +1,230 @@
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