Commit d21578ab3305ad00303a1b5365fadd38c6b43e7d
Committed by
GitHub
1 parent
857af11c
表单设置初始值defaultValue时候使用深度拷贝 (#1935)
* fix: fix wrong naming * perf: 表单设置初始值defaultValue时候使用深度拷贝 * perf: 表单设置初始值defaultValue时候使用深度拷贝 * Revert "perf: 表单设置初始值defaultValue时候使用深度拷贝" This reverts commit a103cd11b4c8e4eeac3be114c103a5c30f562042. * perf: perf Tree Component * fix: 解决tree树形异步懒加载,点击两次才能关闭 Co-authored-by: yfh01 <unconfigured@null.spigotmc.org>
Showing
9 changed files
with
32 additions
and
21 deletions
src/components/Form/src/BasicForm.vue
@@ -62,6 +62,7 @@ | @@ -62,6 +62,7 @@ | ||
62 | 62 | ||
63 | import { basicProps } from './props'; | 63 | import { basicProps } from './props'; |
64 | import { useDesign } from '/@/hooks/web/useDesign'; | 64 | import { useDesign } from '/@/hooks/web/useDesign'; |
65 | + import { cloneDeep } from 'lodash-es'; | ||
65 | 66 | ||
66 | export default defineComponent({ | 67 | export default defineComponent({ |
67 | name: 'BasicForm', | 68 | name: 'BasicForm', |
@@ -132,9 +133,11 @@ | @@ -132,9 +133,11 @@ | ||
132 | } | 133 | } |
133 | } | 134 | } |
134 | if (unref(getProps).showAdvancedButton) { | 135 | if (unref(getProps).showAdvancedButton) { |
135 | - return schemas.filter((schema) => schema.component !== 'Divider') as FormSchema[]; | 136 | + return cloneDeep( |
137 | + schemas.filter((schema) => schema.component !== 'Divider') as FormSchema[], | ||
138 | + ); | ||
136 | } else { | 139 | } else { |
137 | - return schemas as FormSchema[]; | 140 | + return cloneDeep(schemas as FormSchema[]); |
138 | } | 141 | } |
139 | }); | 142 | }); |
140 | 143 |
src/components/Form/src/hooks/useFormEvents.ts
@@ -39,7 +39,8 @@ export function useFormEvents({ | @@ -39,7 +39,8 @@ export function useFormEvents({ | ||
39 | Object.keys(formModel).forEach((key) => { | 39 | Object.keys(formModel).forEach((key) => { |
40 | const schema = unref(getSchema).find((item) => item.field === key); | 40 | const schema = unref(getSchema).find((item) => item.field === key); |
41 | const isInput = schema?.component && defaultValueComponents.includes(schema.component); | 41 | const isInput = schema?.component && defaultValueComponents.includes(schema.component); |
42 | - formModel[key] = isInput ? defaultValueRef.value[key] || '' : defaultValueRef.value[key]; | 42 | + const defaultValue = cloneDeep(defaultValueRef.value[key]); |
43 | + formModel[key] = isInput ? defaultValue || '' : defaultValue; | ||
43 | }); | 44 | }); |
44 | nextTick(() => clearValidate()); | 45 | nextTick(() => clearValidate()); |
45 | 46 | ||
@@ -100,7 +101,7 @@ export function useFormEvents({ | @@ -100,7 +101,7 @@ export function useFormEvents({ | ||
100 | } catch (e) { | 101 | } catch (e) { |
101 | // key not exist | 102 | // key not exist |
102 | if (isDef(defaultValueRef.value[nestKey])) { | 103 | if (isDef(defaultValueRef.value[nestKey])) { |
103 | - formModel[nestKey] = defaultValueRef.value[nestKey]; | 104 | + formModel[nestKey] = cloneDeep(defaultValueRef.value[nestKey]); |
104 | } | 105 | } |
105 | } | 106 | } |
106 | }); | 107 | }); |
src/components/Form/src/hooks/useFormValues.ts
@@ -3,7 +3,7 @@ import { dateUtil } from '/@/utils/dateUtil'; | @@ -3,7 +3,7 @@ import { dateUtil } from '/@/utils/dateUtil'; | ||
3 | import { unref } from 'vue'; | 3 | import { unref } from 'vue'; |
4 | import type { Ref, ComputedRef } from 'vue'; | 4 | import type { Ref, ComputedRef } from 'vue'; |
5 | import type { FormProps, FormSchema } from '../types/form'; | 5 | import type { FormProps, FormSchema } from '../types/form'; |
6 | -import { set } from 'lodash-es'; | 6 | +import { cloneDeep, set } from 'lodash-es'; |
7 | 7 | ||
8 | interface UseFormValuesContext { | 8 | interface UseFormValuesContext { |
9 | defaultValueRef: Ref<any>; | 9 | defaultValueRef: Ref<any>; |
@@ -124,7 +124,7 @@ export function useFormValues({ | @@ -124,7 +124,7 @@ export function useFormValues({ | ||
124 | } | 124 | } |
125 | } | 125 | } |
126 | }); | 126 | }); |
127 | - defaultValueRef.value = obj; | 127 | + defaultValueRef.value = cloneDeep(obj); |
128 | } | 128 | } |
129 | 129 | ||
130 | return { handleFormValues, initDefault }; | 130 | return { handleFormValues, initDefault }; |
src/components/Tree/index.ts
1 | -import BasicTree from './src/Tree.vue'; | 1 | +import BasicTree from './src/BasicTree.vue'; |
2 | import './style'; | 2 | import './style'; |
3 | 3 | ||
4 | export { BasicTree }; | 4 | export { BasicTree }; |
5 | export type { ContextMenuItem } from '/@/hooks/web/useContextMenu'; | 5 | export type { ContextMenuItem } from '/@/hooks/web/useContextMenu'; |
6 | -export * from './src/tree'; | 6 | +export * from './src/types/tree'; |
src/components/Tree/src/Tree.vue renamed to src/components/Tree/src/BasicTree.vue
1 | <script lang="tsx"> | 1 | <script lang="tsx"> |
2 | import type { CSSProperties } from 'vue'; | 2 | import type { CSSProperties } from 'vue'; |
3 | - import type { FieldNames, TreeState, TreeItem, KeyType, CheckKeys, TreeActionType } from './tree'; | 3 | + import type { |
4 | + FieldNames, | ||
5 | + TreeState, | ||
6 | + TreeItem, | ||
7 | + KeyType, | ||
8 | + CheckKeys, | ||
9 | + TreeActionType, | ||
10 | + } from './types/tree'; | ||
4 | 11 | ||
5 | import { | 12 | import { |
6 | defineComponent, | 13 | defineComponent, |
@@ -13,7 +20,7 @@ | @@ -13,7 +20,7 @@ | ||
13 | watch, | 20 | watch, |
14 | onMounted, | 21 | onMounted, |
15 | } from 'vue'; | 22 | } from 'vue'; |
16 | - import TreeHeader from './TreeHeader.vue'; | 23 | + import TreeHeader from './components/TreeHeader.vue'; |
17 | import { Tree, Spin, Empty } from 'ant-design-vue'; | 24 | import { Tree, Spin, Empty } from 'ant-design-vue'; |
18 | import { TreeIcon } from './TreeIcon'; | 25 | import { TreeIcon } from './TreeIcon'; |
19 | import { ScrollContainer } from '/@/components/Container'; | 26 | import { ScrollContainer } from '/@/components/Container'; |
@@ -21,10 +28,10 @@ | @@ -21,10 +28,10 @@ | ||
21 | import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is'; | 28 | import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is'; |
22 | import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper'; | 29 | import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper'; |
23 | import { filter, treeToList, eachTree } from '/@/utils/helper/treeHelper'; | 30 | import { filter, treeToList, eachTree } from '/@/utils/helper/treeHelper'; |
24 | - import { useTree } from './useTree'; | 31 | + import { useTree } from './hooks/useTree'; |
25 | import { useContextMenu } from '/@/hooks/web/useContextMenu'; | 32 | import { useContextMenu } from '/@/hooks/web/useContextMenu'; |
26 | import { CreateContextOptions } from '/@/components/ContextMenu'; | 33 | import { CreateContextOptions } from '/@/components/ContextMenu'; |
27 | - import { treeEmits, treeProps } from './tree'; | 34 | + import { treeEmits, treeProps } from './types/tree'; |
28 | import { createBEM } from '/@/utils/bem'; | 35 | import { createBEM } from '/@/utils/bem'; |
29 | 36 | ||
30 | export default defineComponent({ | 37 | export default defineComponent({ |
src/components/Tree/src/TreeHeader.vue renamed to src/components/Tree/src/components/TreeHeader.vue
@@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
40 | import { useI18n } from '/@/hooks/web/useI18n'; | 40 | import { useI18n } from '/@/hooks/web/useI18n'; |
41 | import { useDebounceFn } from '@vueuse/core'; | 41 | import { useDebounceFn } from '@vueuse/core'; |
42 | import { createBEM } from '/@/utils/bem'; | 42 | import { createBEM } from '/@/utils/bem'; |
43 | - import { ToolbarEnum } from './tree'; | 43 | + import { ToolbarEnum } from '../types/tree'; |
44 | 44 | ||
45 | const searchValue = ref(''); | 45 | const searchValue = ref(''); |
46 | 46 |
src/components/Tree/src/useTree.ts renamed to src/components/Tree/src/hooks/useTree.ts
1 | -import type { InsertNodeParams, KeyType, FieldNames, TreeItem } from './tree'; | 1 | +import type { InsertNodeParams, KeyType, FieldNames, TreeItem } from '../types/tree'; |
2 | import type { Ref, ComputedRef } from 'vue'; | 2 | import type { Ref, ComputedRef } from 'vue'; |
3 | import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree'; | 3 | import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree'; |
4 | 4 |
src/components/Tree/src/tree.ts renamed to src/components/Tree/src/types/tree.ts
src/views/demo/tree/index.vue
@@ -59,7 +59,8 @@ | @@ -59,7 +59,8 @@ | ||
59 | import { treeData } from './data'; | 59 | import { treeData } from './data'; |
60 | import { PageWrapper } from '/@/components/Page'; | 60 | import { PageWrapper } from '/@/components/Page'; |
61 | import { Card, Row, Col, Spin } from 'ant-design-vue'; | 61 | import { Card, Row, Col, Spin } from 'ant-design-vue'; |
62 | - import { cloneDeep } from 'lodash-es'; | 62 | + import { cloneDeep, uniq } from 'lodash-es'; |
63 | + import { isArray } from '/@/utils/is'; | ||
63 | 64 | ||
64 | export default defineComponent({ | 65 | export default defineComponent({ |
65 | components: { BasicTree, PageWrapper, Card, Row, Col, Spin }, | 66 | components: { BasicTree, PageWrapper, Card, Row, Col, Spin }, |
@@ -107,7 +108,7 @@ | @@ -107,7 +108,7 @@ | ||
107 | 108 | ||
108 | function onLoadData(treeNode) { | 109 | function onLoadData(treeNode) { |
109 | return new Promise((resolve: (value?: unknown) => void) => { | 110 | return new Promise((resolve: (value?: unknown) => void) => { |
110 | - if (!treeNode.children) { | 111 | + if (isArray(treeNode.children) && treeNode.children.length > 0) { |
111 | resolve(); | 112 | resolve(); |
112 | return; | 113 | return; |
113 | } | 114 | } |
@@ -119,15 +120,14 @@ | @@ -119,15 +120,14 @@ | ||
119 | { title: `Child Node ${treeNode.eventKey}-1`, key: `${treeNode.eventKey}-1` }, | 120 | { title: `Child Node ${treeNode.eventKey}-1`, key: `${treeNode.eventKey}-1` }, |
120 | ]; | 121 | ]; |
121 | asyncTreeAction.updateNodeByKey(treeNode.eventKey, { children: nodeChildren }); | 122 | asyncTreeAction.updateNodeByKey(treeNode.eventKey, { children: nodeChildren }); |
122 | - asyncTreeAction.setExpandedKeys([ | ||
123 | - treeNode.eventKey, | ||
124 | - ...asyncTreeAction.getExpandedKeys(), | ||
125 | - ]); | 123 | + asyncTreeAction.setExpandedKeys( |
124 | + uniq([treeNode.eventKey, ...asyncTreeAction.getExpandedKeys()]), | ||
125 | + ); | ||
126 | } | 126 | } |
127 | 127 | ||
128 | resolve(); | 128 | resolve(); |
129 | return; | 129 | return; |
130 | - }, 1000); | 130 | + }, 300); |
131 | }); | 131 | }); |
132 | } | 132 | } |
133 | return { | 133 | return { |