Blame view

src/views/demo/comp/modal/Modal1.vue 1.75 KB
陈文彬 authored
1
<template>
2
3
4
5
6
7
8
9
  <BasicModal
    v-bind="$attrs"
    destroyOnClose
    @register="register"
    title="Modal Title"
    :helpMessage="['提示1', '提示2']"
    @visible-change="handleShow"
  >
10
    <template #insertFooter>
11
      <a-button type="primary" danger @click="setLines" :disabled="loading">点我更新内容</a-button>
12
    </template>
13
    <template v-if="loading">
vben authored
14
      <div class="empty-tips">加载中,稍等3秒……</div>
15
16
17
18
19
20
    </template>
    <template v-if="!loading">
      <ul>
        <li v-for="index in lines" :key="index">加载完成{{ index }}!</li>
      </ul>
    </template>
陈文彬 authored
21
22
23
  </BasicModal>
</template>
<script lang="ts">
24
  import { defineComponent, ref, watch } from 'vue';
25
  import { BasicModal, useModalInner } from '/@/components/Modal';
26
陈文彬 authored
27
28
  export default defineComponent({
    components: { BasicModal },
29
30
31
32
    setup() {
      const loading = ref(true);
      const lines = ref(10);
      const [register, { setModalProps, redoModalHeight }] = useModalInner();
33
34
35
36
37

      watch(
        () => lines.value,
        () => {
          redoModalHeight();
vben authored
38
        },
39
40
      );
41
42
43
      function handleShow(visible: boolean) {
        if (visible) {
          loading.value = true;
44
          setModalProps({ loading: true, confirmLoading: true });
45
          setTimeout(() => {
46
            lines.value = Math.round(Math.random() * 30 + 5);
47
            loading.value = false;
48
            setModalProps({ loading: false, confirmLoading: false });
49
50
51
          }, 3000);
        }
      }
52
53
54
55
56

      function setLines() {
        lines.value = Math.round(Math.random() * 20 + 10);
      }
      return { register, loading, handleShow, lines, setLines };
57
    },
陈文彬 authored
58
59
  });
</script>
60
61
62
63
64
65
66
<style scoped>
  .empty-tips {
    height: 100px;
    line-height: 100px;
    text-align: center;
  }
</style>