Commit 58b30aae9a1d749fdbeaca4f1310059a7cc96db2
1 parent
4f9cdc56
refactor: form advanced logic,fixed #2124, #2078,#2089 . follow #2125
Showing
3 changed files
with
13 additions
and
6 deletions
src/components/Form/src/BasicForm.vue
@@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
10 | <slot name="formHeader"></slot> | 10 | <slot name="formHeader"></slot> |
11 | <template v-for="schema in getSchema" :key="schema.field"> | 11 | <template v-for="schema in getSchema" :key="schema.field"> |
12 | <FormItem | 12 | <FormItem |
13 | + :isAdvanced="fieldsIsAdvancedMap[schema.field]" | ||
13 | :tableAction="tableAction" | 14 | :tableAction="tableAction" |
14 | :formActionType="formActionType" | 15 | :formActionType="formActionType" |
15 | :schema="schema" | 16 | :schema="schema" |
@@ -141,7 +142,7 @@ | @@ -141,7 +142,7 @@ | ||
141 | } | 142 | } |
142 | }); | 143 | }); |
143 | 144 | ||
144 | - const { handleToggleAdvanced } = useAdvanced({ | 145 | + const { handleToggleAdvanced, fieldsIsAdvancedMap } = useAdvanced({ |
145 | advanceState, | 146 | advanceState, |
146 | emit, | 147 | emit, |
147 | getProps, | 148 | getProps, |
@@ -299,6 +300,7 @@ | @@ -299,6 +300,7 @@ | ||
299 | getFormActionBindProps: computed( | 300 | getFormActionBindProps: computed( |
300 | (): Recordable => ({ ...getProps.value, ...advanceState }), | 301 | (): Recordable => ({ ...getProps.value, ...advanceState }), |
301 | ), | 302 | ), |
303 | + fieldsIsAdvancedMap, | ||
302 | ...formActionType, | 304 | ...formActionType, |
303 | }; | 305 | }; |
304 | }, | 306 | }, |
src/components/Form/src/components/FormItem.vue
@@ -44,6 +44,9 @@ | @@ -44,6 +44,9 @@ | ||
44 | formActionType: { | 44 | formActionType: { |
45 | type: Object as PropType<FormActionType>, | 45 | type: Object as PropType<FormActionType>, |
46 | }, | 46 | }, |
47 | + isAdvanced: { | ||
48 | + type: Boolean, | ||
49 | + }, | ||
47 | }, | 50 | }, |
48 | setup(props, { slots }) { | 51 | setup(props, { slots }) { |
49 | const { t } = useI18n(); | 52 | const { t } = useI18n(); |
@@ -103,8 +106,8 @@ | @@ -103,8 +106,8 @@ | ||
103 | const { show, ifShow } = props.schema; | 106 | const { show, ifShow } = props.schema; |
104 | const { showAdvancedButton } = props.formProps; | 107 | const { showAdvancedButton } = props.formProps; |
105 | const itemIsAdvanced = showAdvancedButton | 108 | const itemIsAdvanced = showAdvancedButton |
106 | - ? isBoolean(props.schema.isAdvanced) | ||
107 | - ? props.schema.isAdvanced | 109 | + ? isBoolean(props.isAdvanced) |
110 | + ? props.isAdvanced | ||
108 | : true | 111 | : true |
109 | : true; | 112 | : true; |
110 | 113 |
src/components/Form/src/hooks/useAdvanced.ts
1 | import type { ColEx } from '../types'; | 1 | import type { ColEx } from '../types'; |
2 | import type { AdvanceState } from '../types/hooks'; | 2 | import type { AdvanceState } from '../types/hooks'; |
3 | -import { ComputedRef, getCurrentInstance, Ref } from 'vue'; | 3 | +import { ComputedRef, getCurrentInstance, Ref, shallowReactive } from 'vue'; |
4 | import type { FormProps, FormSchema } from '../types/form'; | 4 | import type { FormProps, FormSchema } from '../types/form'; |
5 | import { computed, unref, watch } from 'vue'; | 5 | import { computed, unref, watch } from 'vue'; |
6 | import { isBoolean, isFunction, isNumber, isObject } from '/@/utils/is'; | 6 | import { isBoolean, isFunction, isNumber, isObject } from '/@/utils/is'; |
@@ -113,6 +113,8 @@ export default function ({ | @@ -113,6 +113,8 @@ export default function ({ | ||
113 | } | 113 | } |
114 | } | 114 | } |
115 | 115 | ||
116 | + const fieldsIsAdvancedMap = shallowReactive({}); | ||
117 | + | ||
116 | function updateAdvanced() { | 118 | function updateAdvanced() { |
117 | let itemColSum = 0; | 119 | let itemColSum = 0; |
118 | let realItemColSum = 0; | 120 | let realItemColSum = 0; |
@@ -148,7 +150,7 @@ export default function ({ | @@ -148,7 +150,7 @@ export default function ({ | ||
148 | if (isAdvanced) { | 150 | if (isAdvanced) { |
149 | realItemColSum = itemColSum; | 151 | realItemColSum = itemColSum; |
150 | } | 152 | } |
151 | - schema.isAdvanced = isAdvanced; | 153 | + fieldsIsAdvancedMap[schema.field] = isAdvanced; |
152 | } | 154 | } |
153 | } | 155 | } |
154 | 156 | ||
@@ -166,5 +168,5 @@ export default function ({ | @@ -166,5 +168,5 @@ export default function ({ | ||
166 | advanceState.isAdvanced = !advanceState.isAdvanced; | 168 | advanceState.isAdvanced = !advanceState.isAdvanced; |
167 | } | 169 | } |
168 | 170 | ||
169 | - return { handleToggleAdvanced }; | 171 | + return { handleToggleAdvanced, fieldsIsAdvancedMap }; |
170 | } | 172 | } |