Commit c7cfeb54560972db3e4e30bb27997d3f9343e5ff

Authored by vben
1 parent e034d1ba

chore: form reset logic modification

CHANGELOG.zh_CN.md
... ... @@ -8,6 +8,7 @@
8 8 ### 🎫 Chores
9 9  
10 10 - 删除代码内的可选链语法
  11 +- 表单重置逻辑修改
11 12  
12 13 ### 🐛 Bug Fixes
13 14  
... ...
src/components/Form/src/BasicForm.vue
... ... @@ -194,7 +194,7 @@
194 194 model: formModel,
195 195 field: schema.field,
196 196 values: {
197   - ...unerf(defaultValueRef),
  197 + ...unref(defaultValueRef),
198 198 ...formModel,
199 199 },
200 200 });
... ... @@ -271,11 +271,11 @@
271 271 const formEl = unref(formElRef);
272 272 if (!formEl) return;
273 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 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 139 }
140 140 return rules;
141 141 }
  142 +
142 143 function renderComponent() {
143 144 const {
144 145 componentProps,
... ... @@ -163,7 +164,6 @@ export default defineComponent({
163 164 }
164 165 },
165 166 };
166   -
167 167 const Comp = componentMap.get(component);
168 168  
169 169 const { autoSetPlaceHolder, size } = props.formProps;
... ... @@ -189,9 +189,22 @@ export default defineComponent({
189 189 const bindValue = {
190 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 204 if (!renderComponentContent) {
193 205 return <Comp {...propsData} {...on} {...bindValue} />;
194 206 }
  207 +
195 208 return (
196 209 <Comp {...propsData} {...on} {...bindValue}>
197 210 {{
... ...
src/layouts/default/multitabs/index.tsx
... ... @@ -8,7 +8,7 @@ import {
8 8 computed,
9 9 // ref,
10 10 unref,
11   - onMounted,
  11 + // onMounted,
12 12 toRaw,
13 13 } from 'vue';
14 14 import { Tabs } from 'ant-design-vue';
... ... @@ -24,7 +24,7 @@ import { tabStore } from &#39;/@/store/modules/tab&#39;;
24 24 import { closeTab } from './useTabDropdown';
25 25 import router from '/@/router';
26 26 import { useTabs } from '/@/hooks/web/useTabs';
27   -import { PageEnum } from '/@/enums/pageEnum';
  27 +// import { PageEnum } from '/@/enums/pageEnum';
28 28  
29 29 import './index.less';
30 30 export default defineComponent({
... ... @@ -33,14 +33,17 @@ export default defineComponent({
33 33 let isAddAffix = false;
34 34 const go = useGo();
35 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 48 // 当前激活tab
46 49 // const activeKeyRef = ref<string>('');
... ... @@ -64,14 +67,14 @@ export default defineComponent({
64 67 // 监听路由的话虽然可以,但是路由切换的时间会造成卡顿现象?
65 68 // 使用useTab的addTab的话,当用户手动调转,需要自行调用addTab
66 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 80 immediate: true,
... ...
src/views/demo/table/tableData.tsx
... ... @@ -239,12 +239,10 @@ export function getFormConfig(): Partial&lt;FormProps&gt; {
239 239 {
240 240 label: '选项1',
241 241 value: '1',
242   - key: '1',
243 242 },
244 243 {
245 244 label: '选项2',
246 245 value: '2',
247   - key: '2',
248 246 },
249 247 ],
250 248 },
... ...