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 1 <template>
2 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 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 23 <template #extra>
17 24 <Space>
18 25 <a-button @click="resetSettings">重置设置</a-button>
... ... @@ -30,7 +37,7 @@
30 37 <script lang="ts">
31 38 import { defineComponent, ref } from 'vue';
32 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 41 import { CollapseContainer } from '/@/components/Container';
35 42 import { PageWrapper } from '/@/components/Page';
36 43 import { areaRecord } from '/@/api/demo/cascader';
... ... @@ -272,6 +279,22 @@
272 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 300 export default defineComponent({
... ... @@ -294,6 +317,9 @@
294 317 });
295 318  
296 319 const resetSettings = async () => {
  320 + setProps({ resetButtonOptions: { disabled: false, text: '重置' } });
  321 + setProps({ submitButtonOptions: { disabled: false, loading: false } });
  322 + await setFieldsValue({ field9: [] });
297 323 await settingFormRef.value?.resetFields();
298 324 };
299 325  
... ... @@ -343,6 +369,11 @@
343 369 settingFormRef.value?.submit();
344 370 };
345 371  
  372 + const withClose = (formProps: Partial<FormProps>) => {
  373 + setProps(formProps);
  374 + visible.value = false;
  375 + };
  376 +
346 377 return {
347 378 register,
348 379 schemas,
... ... @@ -354,6 +385,7 @@
354 385 visible,
355 386 showDrawer,
356 387 settingFormRef,
  388 + withClose,
357 389 onSettings,
358 390 resetSettings,
359 391 registerSetting,
... ...