Blame view

src/views/demo/comp/modal/index.vue 2.6 KB
陈文彬 authored
1
<template>
vben authored
2
  <div class="px-10 py-4">
陈文彬 authored
3
4
5
6
7
    <Alert
      message="使用 useModal 进行弹窗操作,默认可以拖动,可以通过 draggable
    参数进行控制是否可以拖动/全屏"
      show-icon
    />
vben authored
8
    <a-button type="primary" class="my-4" @click="openModalLoading"
陈文彬 authored
9
10
11
      >打开弹窗 默认可以拖动/全屏</a-button
    >
vben authored
12
13
14
15
    <Alert message="内外同时同时显示隐藏" show-icon />
    <a-button type="primary" class="my-4" @click="openModal2">打开弹窗</a-button>
    <Alert message="自适应高度" show-icon />
    <a-button type="primary" class="my-4" @click="openModal3">打开弹窗</a-button>
陈文彬 authored
16
17
18
19
20

    <Alert
      message="内外数据交互,外部通过 transferModalData 发送,内部通过 receiveDrawerDataRef 接收。该数据具有响应式"
      show-icon
    />
vben authored
21
    <a-button type="primary" class="my-4" @click="send">打开弹窗并传递数据</a-button>
陈文彬 authored
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

    <Modal1 @register="register1" />
    <Modal2 @register="register2" />
    <Modal3 @register="register3" />
    <Modal4 @register="register4" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { Alert } from 'ant-design-vue';
  import { useModal } from '/@/components/Modal';
  import Modal1 from './Modal1.vue';
  import Modal2 from './Modal2.vue';
  import Modal3 from './Modal3.vue';
  import Modal4 from './Modal4.vue';
  export default defineComponent({
    components: { Alert, Modal1, Modal2, Modal3, Modal4 },
    setup() {
      const [register1, { openModal: openModal1, setModalProps }] = useModal();
      const [register2, { openModal: openModal2 }] = useModal();
      const [register3, { openModal: openModal3 }] = useModal();
43
44
45
46
47
48
49
      const [
        register4,
        {
          openModal: openModal4,
          // transferModalData
        },
      ] = useModal();
陈文彬 authored
50
      function send() {
51
52
53
54
        // transferModalData({
        //   data: 'content',
        //   info: 'Info',
        // });
55
56
57
58
59
60
        // setTimeout(() => {
        //   transferModalData({
        //     data: 'content1',
        //     info: 'Info1',
        //   });
        // }, 3000);
61
62
63
64
        openModal4(true, {
          data: 'content',
          info: 'Info',
        });
陈文彬 authored
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
      }
      function openModalLoading() {
        openModal1();
        setModalProps({ loading: true });
        setTimeout(() => {
          setModalProps({ loading: false });
        }, 2000);
      }
      return {
        register1,
        openModal1,
        register2,
        openModal2,
        register3,
        openModal3,
        register4,
        openModal4,
        send,
        openModalLoading,
      };
    },
  });
</script>