Commit dce3aba20d97d269d30993c4b9b01ae45b940338

Authored by luocong2016
Committed by GitHub
1 parent 256e0275

refactor: 重构案例代码 (#2589)

Showing 1 changed file with 44 additions and 12 deletions
src/views/demo/form/UseForm.vue
1 <template> 1 <template>
2 <PageWrapper title="UseForm操作示例"> 2 <PageWrapper title="UseForm操作示例">
3 - <Space class="mb-4">  
4 - <a-button type="primary" @click="showDrawer"> 更改设置 </a-button>  
5 - <a-button @click="setProps({ resetButtonOptions: { disabled: true, text: '重置New' } })">  
6 - 修改重置按钮  
7 - </a-button>  
8 - <a-button @click="setProps({ submitButtonOptions: { disabled: true, loading: true } })">  
9 - 修改查询按钮  
10 - </a-button>  
11 - <a-button @click="handleLoad" class="mr-2"> 联动回显 </a-button>  
12 - </Space> 3 + <a-button class="mb-4" type="primary" @click="showDrawer"> 更改设置 </a-button>
13 4
14 <Drawer v-model:visible="visible" title="更改设置" placement="right"> 5 <Drawer v-model:visible="visible" title="更改设置" placement="right">
15 - <BasicForm ref="settingFormRef" @register="registerSetting" @submit="handleSubmitSetting" /> 6 + <BasicForm ref="settingFormRef" @register="registerSetting" @submit="handleSubmitSetting">
  7 + <template #other>
  8 + <Space>
  9 + <a-button
  10 + @click="() => withClose({ resetButtonOptions: { disabled: true, text: '重置New' } })"
  11 + >
  12 + 修改重置按钮
  13 + </a-button>
  14 + <a-button
  15 + @click="() => withClose({ submitButtonOptions: { disabled: true, loading: true } })"
  16 + >
  17 + 修改查询按钮
  18 + </a-button>
  19 + <a-button @click="handleLoad" class="mr-2"> 联动回显 </a-button>
  20 + </Space>
  21 + </template>
  22 + </BasicForm>
16 <template #extra> 23 <template #extra>
17 <Space> 24 <Space>
18 <a-button @click="resetSettings">重置设置</a-button> 25 <a-button @click="resetSettings">重置设置</a-button>
@@ -30,7 +37,7 @@ @@ -30,7 +37,7 @@
30 <script lang="ts"> 37 <script lang="ts">
31 import { defineComponent, ref } from 'vue'; 38 import { defineComponent, ref } from 'vue';
32 import { Drawer, Space } from 'ant-design-vue'; 39 import { Drawer, Space } from 'ant-design-vue';
33 - import { BasicForm, FormSchema, useForm } from '/@/components/Form'; 40 + import { BasicForm, FormSchema, useForm, type FormProps } from '/@/components/Form';
34 import { CollapseContainer } from '/@/components/Container'; 41 import { CollapseContainer } from '/@/components/Container';
35 import { PageWrapper } from '/@/components/Page'; 42 import { PageWrapper } from '/@/components/Page';
36 import { areaRecord } from '/@/api/demo/cascader'; 43 import { areaRecord } from '/@/api/demo/cascader';
@@ -272,6 +279,22 @@ @@ -272,6 +279,22 @@
272 size: 'small', 279 size: 'small',
273 }, 280 },
274 }, 281 },
  282 + {
  283 + field: '',
  284 + component: 'Divider',
  285 + label: '其他事件',
  286 + colProps: { span: 24 },
  287 + componentProps: {
  288 + orientation: 'center',
  289 + },
  290 + },
  291 + {
  292 + field: 'other',
  293 + component: 'Input',
  294 + label: '',
  295 + colProps: { span: 24 },
  296 + colSlot: 'other',
  297 + },
275 ]; 298 ];
276 299
277 export default defineComponent({ 300 export default defineComponent({
@@ -294,6 +317,9 @@ @@ -294,6 +317,9 @@
294 }); 317 });
295 318
296 const resetSettings = async () => { 319 const resetSettings = async () => {
  320 + setProps({ resetButtonOptions: { disabled: false, text: '重置' } });
  321 + setProps({ submitButtonOptions: { disabled: false, loading: false } });
  322 + await setFieldsValue({ field9: [] });
297 await settingFormRef.value?.resetFields(); 323 await settingFormRef.value?.resetFields();
298 }; 324 };
299 325
@@ -343,6 +369,11 @@ @@ -343,6 +369,11 @@
343 settingFormRef.value?.submit(); 369 settingFormRef.value?.submit();
344 }; 370 };
345 371
  372 + const withClose = (formProps: Partial<FormProps>) => {
  373 + setProps(formProps);
  374 + visible.value = false;
  375 + };
  376 +
346 return { 377 return {
347 register, 378 register,
348 schemas, 379 schemas,
@@ -354,6 +385,7 @@ @@ -354,6 +385,7 @@
354 visible, 385 visible,
355 showDrawer, 386 showDrawer,
356 settingFormRef, 387 settingFormRef,
  388 + withClose,
357 onSettings, 389 onSettings,
358 resetSettings, 390 resetSettings,
359 registerSetting, 391 registerSetting,