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 | 62 | |
63 | 63 | import { basicProps } from './props'; |
64 | 64 | import { useDesign } from '/@/hooks/web/useDesign'; |
65 | + import { cloneDeep } from 'lodash-es'; | |
65 | 66 | |
66 | 67 | export default defineComponent({ |
67 | 68 | name: 'BasicForm', |
... | ... | @@ -132,9 +133,11 @@ |
132 | 133 | } |
133 | 134 | } |
134 | 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 | 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 | 39 | Object.keys(formModel).forEach((key) => { |
40 | 40 | const schema = unref(getSchema).find((item) => item.field === key); |
41 | 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 | 45 | nextTick(() => clearValidate()); |
45 | 46 | |
... | ... | @@ -100,7 +101,7 @@ export function useFormEvents({ |
100 | 101 | } catch (e) { |
101 | 102 | // key not exist |
102 | 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 | 3 | import { unref } from 'vue'; |
4 | 4 | import type { Ref, ComputedRef } from 'vue'; |
5 | 5 | import type { FormProps, FormSchema } from '../types/form'; |
6 | -import { set } from 'lodash-es'; | |
6 | +import { cloneDeep, set } from 'lodash-es'; | |
7 | 7 | |
8 | 8 | interface UseFormValuesContext { |
9 | 9 | defaultValueRef: Ref<any>; |
... | ... | @@ -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 | 130 | return { handleFormValues, initDefault }; | ... | ... |
src/components/Tree/index.ts
src/components/Tree/src/Tree.vue renamed to src/components/Tree/src/BasicTree.vue
1 | 1 | <script lang="tsx"> |
2 | 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 | 12 | import { |
6 | 13 | defineComponent, |
... | ... | @@ -13,7 +20,7 @@ |
13 | 20 | watch, |
14 | 21 | onMounted, |
15 | 22 | } from 'vue'; |
16 | - import TreeHeader from './TreeHeader.vue'; | |
23 | + import TreeHeader from './components/TreeHeader.vue'; | |
17 | 24 | import { Tree, Spin, Empty } from 'ant-design-vue'; |
18 | 25 | import { TreeIcon } from './TreeIcon'; |
19 | 26 | import { ScrollContainer } from '/@/components/Container'; |
... | ... | @@ -21,10 +28,10 @@ |
21 | 28 | import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is'; |
22 | 29 | import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper'; |
23 | 30 | import { filter, treeToList, eachTree } from '/@/utils/helper/treeHelper'; |
24 | - import { useTree } from './useTree'; | |
31 | + import { useTree } from './hooks/useTree'; | |
25 | 32 | import { useContextMenu } from '/@/hooks/web/useContextMenu'; |
26 | 33 | import { CreateContextOptions } from '/@/components/ContextMenu'; |
27 | - import { treeEmits, treeProps } from './tree'; | |
34 | + import { treeEmits, treeProps } from './types/tree'; | |
28 | 35 | import { createBEM } from '/@/utils/bem'; |
29 | 36 | |
30 | 37 | export default defineComponent({ | ... | ... |
src/components/Tree/src/TreeHeader.vue renamed to src/components/Tree/src/components/TreeHeader.vue
... | ... | @@ -40,7 +40,7 @@ |
40 | 40 | import { useI18n } from '/@/hooks/web/useI18n'; |
41 | 41 | import { useDebounceFn } from '@vueuse/core'; |
42 | 42 | import { createBEM } from '/@/utils/bem'; |
43 | - import { ToolbarEnum } from './tree'; | |
43 | + import { ToolbarEnum } from '../types/tree'; | |
44 | 44 | |
45 | 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 | 2 | import type { Ref, ComputedRef } from 'vue'; |
3 | 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 | 59 | import { treeData } from './data'; |
60 | 60 | import { PageWrapper } from '/@/components/Page'; |
61 | 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 | 65 | export default defineComponent({ |
65 | 66 | components: { BasicTree, PageWrapper, Card, Row, Col, Spin }, |
... | ... | @@ -107,7 +108,7 @@ |
107 | 108 | |
108 | 109 | function onLoadData(treeNode) { |
109 | 110 | return new Promise((resolve: (value?: unknown) => void) => { |
110 | - if (!treeNode.children) { | |
111 | + if (isArray(treeNode.children) && treeNode.children.length > 0) { | |
111 | 112 | resolve(); |
112 | 113 | return; |
113 | 114 | } |
... | ... | @@ -119,15 +120,14 @@ |
119 | 120 | { title: `Child Node ${treeNode.eventKey}-1`, key: `${treeNode.eventKey}-1` }, |
120 | 121 | ]; |
121 | 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 | 128 | resolve(); |
129 | 129 | return; |
130 | - }, 1000); | |
130 | + }, 300); | |
131 | 131 | }); |
132 | 132 | } |
133 | 133 | return { | ... | ... |