Ben Lin
2025-01-10 04c89920754329dfcc3b71dd12e236da18c245c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<template>
  <Modal
    v-model:open="open"
    :title="title"
    @ok="handleSubmit"
    :destroyOnClose="true"
    :width="width || '500px'"
    okText="确定"
    cancelText="取消"
  >
    <div class="pt-5 pr-3px">
      <BasicForm @register="register" />
    </div>
  </Modal>
</template>
 
<script setup lang="ts">
  import { ref } from 'vue';
  import { Modal } from 'ant-design-vue';
  import { FormSchema, BasicForm, useForm } from '@/components/Form';
 
  const props = defineProps<{
    title: string;
    addFormSchemas: FormSchema[];
    onOK?: Fn;
    width?: string;
    labelWidth?: number;
    layout?: 'horizontal' | 'vertical' | 'inline';
  }>();
 
  const open = ref<boolean>(true);
 
  const [register, { validate }] = useForm({
    schemas: props.addFormSchemas,
    showActionButtonGroup: false,
    labelWidth: props.labelWidth || 80,
    layout: props.layout || 'horizontal',
  });
 
  async function handleSubmit() {
    const row = await validate();
    if (props.onOK) {
      await props.onOK(row.txt);
    }
    open.value = false;
  }
</script>
 
<style scoped></style>