Commit c7cfeb54560972db3e4e30bb27997d3f9343e5ff
1 parent
e034d1ba
chore: form reset logic modification
Showing
5 changed files
with
40 additions
and
25 deletions
CHANGELOG.zh_CN.md
src/components/Form/src/BasicForm.vue
@@ -194,7 +194,7 @@ | @@ -194,7 +194,7 @@ | ||
194 | model: formModel, | 194 | model: formModel, |
195 | field: schema.field, | 195 | field: schema.field, |
196 | values: { | 196 | values: { |
197 | - ...unerf(defaultValueRef), | 197 | + ...unref(defaultValueRef), |
198 | ...formModel, | 198 | ...formModel, |
199 | }, | 199 | }, |
200 | }); | 200 | }); |
@@ -271,11 +271,11 @@ | @@ -271,11 +271,11 @@ | ||
271 | const formEl = unref(formElRef); | 271 | const formEl = unref(formElRef); |
272 | if (!formEl) return; | 272 | if (!formEl) return; |
273 | Object.keys(formModel).forEach((key) => { | 273 | Object.keys(formModel).forEach((key) => { |
274 | - (formModel as any)[key] = undefined; | 274 | + (formModel as any)[key] = defaultValueRef.value[key]; |
275 | }); | 275 | }); |
276 | - const values = formEl.resetFields(); | 276 | + // const values = formEl.resetFields(); |
277 | emit('reset', toRaw(formModel)); | 277 | emit('reset', toRaw(formModel)); |
278 | - return values; | 278 | + // return values; |
279 | } | 279 | } |
280 | 280 | ||
281 | /** | 281 | /** |
src/components/Form/src/FormItem.tsx
@@ -139,6 +139,7 @@ export default defineComponent({ | @@ -139,6 +139,7 @@ export default defineComponent({ | ||
139 | } | 139 | } |
140 | return rules; | 140 | return rules; |
141 | } | 141 | } |
142 | + | ||
142 | function renderComponent() { | 143 | function renderComponent() { |
143 | const { | 144 | const { |
144 | componentProps, | 145 | componentProps, |
@@ -163,7 +164,6 @@ export default defineComponent({ | @@ -163,7 +164,6 @@ export default defineComponent({ | ||
163 | } | 164 | } |
164 | }, | 165 | }, |
165 | }; | 166 | }; |
166 | - | ||
167 | const Comp = componentMap.get(component); | 167 | const Comp = componentMap.get(component); |
168 | 168 | ||
169 | const { autoSetPlaceHolder, size } = props.formProps; | 169 | const { autoSetPlaceHolder, size } = props.formProps; |
@@ -189,9 +189,22 @@ export default defineComponent({ | @@ -189,9 +189,22 @@ export default defineComponent({ | ||
189 | const bindValue = { | 189 | const bindValue = { |
190 | [isCheck ? 'checked' : 'value']: (props.formModel as any)[field], | 190 | [isCheck ? 'checked' : 'value']: (props.formModel as any)[field], |
191 | }; | 191 | }; |
192 | + // TODO先兼容antd的警告,后面官方修复后删除 | ||
193 | + if (component === 'Select') { | ||
194 | + if (Reflect.has(propsData, 'options')) { | ||
195 | + propsData.options = propsData.options.map((item: any) => { | ||
196 | + return { | ||
197 | + key: item.value, | ||
198 | + ...item, | ||
199 | + }; | ||
200 | + }); | ||
201 | + } | ||
202 | + } | ||
203 | + | ||
192 | if (!renderComponentContent) { | 204 | if (!renderComponentContent) { |
193 | return <Comp {...propsData} {...on} {...bindValue} />; | 205 | return <Comp {...propsData} {...on} {...bindValue} />; |
194 | } | 206 | } |
207 | + | ||
195 | return ( | 208 | return ( |
196 | <Comp {...propsData} {...on} {...bindValue}> | 209 | <Comp {...propsData} {...on} {...bindValue}> |
197 | {{ | 210 | {{ |
src/layouts/default/multitabs/index.tsx
@@ -8,7 +8,7 @@ import { | @@ -8,7 +8,7 @@ import { | ||
8 | computed, | 8 | computed, |
9 | // ref, | 9 | // ref, |
10 | unref, | 10 | unref, |
11 | - onMounted, | 11 | + // onMounted, |
12 | toRaw, | 12 | toRaw, |
13 | } from 'vue'; | 13 | } from 'vue'; |
14 | import { Tabs } from 'ant-design-vue'; | 14 | import { Tabs } from 'ant-design-vue'; |
@@ -24,7 +24,7 @@ import { tabStore } from '/@/store/modules/tab'; | @@ -24,7 +24,7 @@ import { tabStore } from '/@/store/modules/tab'; | ||
24 | import { closeTab } from './useTabDropdown'; | 24 | import { closeTab } from './useTabDropdown'; |
25 | import router from '/@/router'; | 25 | import router from '/@/router'; |
26 | import { useTabs } from '/@/hooks/web/useTabs'; | 26 | import { useTabs } from '/@/hooks/web/useTabs'; |
27 | -import { PageEnum } from '/@/enums/pageEnum'; | 27 | +// import { PageEnum } from '/@/enums/pageEnum'; |
28 | 28 | ||
29 | import './index.less'; | 29 | import './index.less'; |
30 | export default defineComponent({ | 30 | export default defineComponent({ |
@@ -33,14 +33,17 @@ export default defineComponent({ | @@ -33,14 +33,17 @@ export default defineComponent({ | ||
33 | let isAddAffix = false; | 33 | let isAddAffix = false; |
34 | const go = useGo(); | 34 | const go = useGo(); |
35 | const { currentRoute } = useRouter(); | 35 | const { currentRoute } = useRouter(); |
36 | - const { addTab, activeKeyRef } = useTabs(); | ||
37 | - onMounted(() => { | ||
38 | - const route = unref(currentRoute); | ||
39 | - addTab(unref(currentRoute).path as PageEnum, false, { | ||
40 | - query: route.query, | ||
41 | - params: route.params, | ||
42 | - }); | ||
43 | - }); | 36 | + const { |
37 | + // addTab, | ||
38 | + activeKeyRef, | ||
39 | + } = useTabs(); | ||
40 | + // onMounted(() => { | ||
41 | + // const route = unref(currentRoute); | ||
42 | + // addTab(unref(currentRoute).path as PageEnum, false, { | ||
43 | + // query: route.query, | ||
44 | + // params: route.params, | ||
45 | + // }); | ||
46 | + // }); | ||
44 | 47 | ||
45 | // 当前激活tab | 48 | // 当前激活tab |
46 | // const activeKeyRef = ref<string>(''); | 49 | // const activeKeyRef = ref<string>(''); |
@@ -64,14 +67,14 @@ export default defineComponent({ | @@ -64,14 +67,14 @@ export default defineComponent({ | ||
64 | // 监听路由的话虽然可以,但是路由切换的时间会造成卡顿现象? | 67 | // 监听路由的话虽然可以,但是路由切换的时间会造成卡顿现象? |
65 | // 使用useTab的addTab的话,当用户手动调转,需要自行调用addTab | 68 | // 使用useTab的addTab的话,当用户手动调转,需要自行调用addTab |
66 | // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw); | 69 | // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw); |
67 | - // const { affix } = currentRoute.value.meta || {}; | ||
68 | - // if (affix) return; | ||
69 | - // const hasInTab = tabStore.getTabsState.some( | ||
70 | - // (item) => item.fullPath === currentRoute.value.fullPath | ||
71 | - // ); | ||
72 | - // if (!hasInTab) { | ||
73 | - // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw); | ||
74 | - // } | 70 | + const { affix } = currentRoute.value.meta || {}; |
71 | + if (affix) return; | ||
72 | + const hasInTab = tabStore.getTabsState.some( | ||
73 | + (item) => item.fullPath === currentRoute.value.fullPath | ||
74 | + ); | ||
75 | + if (!hasInTab) { | ||
76 | + tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw); | ||
77 | + } | ||
75 | }, | 78 | }, |
76 | { | 79 | { |
77 | immediate: true, | 80 | immediate: true, |
src/views/demo/table/tableData.tsx
@@ -239,12 +239,10 @@ export function getFormConfig(): Partial<FormProps> { | @@ -239,12 +239,10 @@ export function getFormConfig(): Partial<FormProps> { | ||
239 | { | 239 | { |
240 | label: '选项1', | 240 | label: '选项1', |
241 | value: '1', | 241 | value: '1', |
242 | - key: '1', | ||
243 | }, | 242 | }, |
244 | { | 243 | { |
245 | label: '选项2', | 244 | label: '选项2', |
246 | value: '2', | 245 | value: '2', |
247 | - key: '2', | ||
248 | }, | 246 | }, |
249 | ], | 247 | ], |
250 | }, | 248 | }, |