Blame view

src/views/demo/comp/modal/Modal4.vue 1.71 KB
陈文彬 authored
1
2
3
<template>
  <BasicModal v-bind="$attrs" @register="register" title="Modal Title">
    <p class="h-20">外部传递数据: {{ receiveModalDataRef }}</p>
4
    <BasicForm @register="registerForm" :model="model" />
陈文彬 authored
5
6
7
  </BasicModal>
</template>
<script lang="ts">
8
  import { defineComponent, nextTick, ref } from 'vue';
陈文彬 authored
9
  import { BasicModal, useModalInner } from '/@/components/Modal';
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  const schemas: FormSchema[] = [
    {
      field: 'field1',
      component: 'Input',
      label: '字段1',
      colProps: {
        span: 12,
      },
      defaultValue: '111',
    },
    {
      field: 'field2',
      component: 'Input',
      label: '字段2',
      colProps: {
        span: 12,
      },
    },
  ];
陈文彬 authored
30
  export default defineComponent({
31
    components: { BasicModal, BasicForm },
陈文彬 authored
32
    setup() {
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
      const modelRef = ref({});
      const [
        registerForm,
        {
          // setFieldsValue,
          // setProps
        },
      ] = useForm({
        labelWidth: 120,
        schemas,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });

      const [register, { receiveModalDataRef }] = useModalInner((data) => {
        nextTick(() => {
          // 方式1
          // setFieldsValue({
          //   field2: data.data,
          //   field1: data.info,
          // });

          // 方式2
          modelRef.value = { field2: data.data, field1: data.info };

          // setProps({
          //   model:{ field2: data.data, field1: data.info }
          // })
        });
      });
      return { register, receiveModalDataRef, schemas, registerForm, model: modelRef };
陈文彬 authored
66
67
68
    },
  });
</script>