Commit 58b30aae9a1d749fdbeaca4f1310059a7cc96db2

Authored by 无木
1 parent 4f9cdc56

refactor: form advanced logic,fixed #2124, #2078,#2089 . follow #2125

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