Modal1.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. destroyOnClose
  5. @register="register"
  6. title="Modal Title"
  7. :helpMessage="['提示1', '提示2']"
  8. @open-change="handleShow"
  9. >
  10. <template #insertFooter>
  11. <a-button type="primary" danger @click="setLines" :disabled="loading">点我更新内容</a-button>
  12. </template>
  13. <template v-if="loading">
  14. <div class="empty-tips">加载中,稍等3秒……</div>
  15. </template>
  16. <template v-if="!loading">
  17. <ul>
  18. <li v-for="index in lines" :key="index">加载完成{{ index }}!</li>
  19. </ul>
  20. </template>
  21. </BasicModal>
  22. </template>
  23. <script lang="ts">
  24. import { defineComponent, ref, watch } from 'vue';
  25. import { BasicModal, useModalInner } from '/@/components/Modal';
  26. export default defineComponent({
  27. components: { BasicModal },
  28. setup() {
  29. const loading = ref(true);
  30. const lines = ref(10);
  31. const [register, { setModalProps, redoModalHeight }] = useModalInner();
  32. watch(
  33. () => lines.value,
  34. () => {
  35. redoModalHeight();
  36. },
  37. );
  38. function handleShow(open: boolean) {
  39. if (open) {
  40. loading.value = true;
  41. setModalProps({ loading: true, confirmLoading: true });
  42. setTimeout(() => {
  43. lines.value = Math.round(Math.random() * 30 + 5);
  44. loading.value = false;
  45. setModalProps({ loading: false, confirmLoading: false });
  46. }, 3000);
  47. }
  48. }
  49. function setLines() {
  50. lines.value = Math.round(Math.random() * 20 + 10);
  51. }
  52. return { register, loading, handleShow, lines, setLines };
  53. },
  54. });
  55. </script>
  56. <style scoped>
  57. .empty-tips {
  58. height: 100px;
  59. line-height: 100px;
  60. text-align: center;
  61. }
  62. </style>