Commit f732b569042f7fe77c85cb295538ddd85561f7e9

Authored by 无木
1 parent 9e2aa20d

feat(modal): add redoModalHeight for useModalInner

允许在Modal内部动态加载内容后重新调整高度
src/components/Modal/src/hooks/useModal.ts
@@ -150,6 +150,11 @@ export const useModalInner = (callbackFn?: Fn): UseModalInnerReturnType => { @@ -150,6 +150,11 @@ export const useModalInner = (callbackFn?: Fn): UseModalInnerReturnType => {
150 setModalProps: (props: Partial<ModalProps>) => { 150 setModalProps: (props: Partial<ModalProps>) => {
151 getInstance()?.setModalProps(props); 151 getInstance()?.setModalProps(props);
152 }, 152 },
  153 +
  154 + redoModalHeight: () => {
  155 + const callRedo = getInstance()?.redoModalHeight;
  156 + callRedo && callRedo();
  157 + },
153 }, 158 },
154 ]; 159 ];
155 }; 160 };
src/components/Modal/src/types.ts
@@ -23,6 +23,7 @@ export interface ReturnInnerMethods extends ModalMethods { @@ -23,6 +23,7 @@ export interface ReturnInnerMethods extends ModalMethods {
23 changeLoading: (loading: boolean) => void; 23 changeLoading: (loading: boolean) => void;
24 changeOkLoading: (loading: boolean) => void; 24 changeOkLoading: (loading: boolean) => void;
25 getVisible?: ComputedRef<boolean>; 25 getVisible?: ComputedRef<boolean>;
  26 + redoModalHeight: () => void;
26 } 27 }
27 28
28 export type UseModalInnerReturnType = [RegisterFn, ReturnInnerMethods]; 29 export type UseModalInnerReturnType = [RegisterFn, ReturnInnerMethods];
src/views/demo/comp/modal/Modal1.vue
1 <template> 1 <template>
2 - <BasicModal v-bind="$attrs" title="Modal Title" :helpMessage="['提示1', '提示2']">  
3 - Modal Info. 2 + <BasicModal
  3 + v-bind="$attrs"
  4 + destroyOnClose
  5 + @register="register"
  6 + title="Modal Title"
  7 + :helpMessage="['提示1', '提示2']"
  8 + @visible-change="handleShow"
  9 + >
  10 + <template v-if="loading">
  11 + <div class="empty-tips"> 加载中,稍等3秒…… </div>
  12 + </template>
  13 + <template v-if="!loading">
  14 + <ul>
  15 + <li v-for="index in lines" :key="index">加载完成{{ index }}!</li>
  16 + </ul>
  17 + </template>
4 </BasicModal> 18 </BasicModal>
5 </template> 19 </template>
6 <script lang="ts"> 20 <script lang="ts">
7 - import { defineComponent } from 'vue';  
8 - import { BasicModal } from '/@/components/Modal'; 21 + import { defineComponent, ref } from 'vue';
  22 + import { BasicModal, useModalInner } from '/@/components/Modal';
9 export default defineComponent({ 23 export default defineComponent({
10 components: { BasicModal }, 24 components: { BasicModal },
  25 + setup() {
  26 + const loading = ref(true);
  27 + const lines = ref(10);
  28 + const [register, { setModalProps, redoModalHeight }] = useModalInner();
  29 + function handleShow(visible: boolean) {
  30 + if (visible) {
  31 + loading.value = true;
  32 + setModalProps({ loading: true });
  33 + setTimeout(() => {
  34 + lines.value = Math.round(Math.random() * 20 + 10);
  35 + loading.value = false;
  36 + setModalProps({ loading: false });
  37 + redoModalHeight();
  38 + }, 3000);
  39 + }
  40 + }
  41 + return { register, loading, handleShow, lines };
  42 + },
11 }); 43 });
12 </script> 44 </script>
  45 +<style scoped>
  46 + .empty-tips {
  47 + height: 100px;
  48 + line-height: 100px;
  49 + text-align: center;
  50 + }
  51 +</style>
src/views/demo/comp/modal/index.vue
@@ -2,11 +2,11 @@ @@ -2,11 +2,11 @@
2 <PageWrapper title="modal组件使用示例"> 2 <PageWrapper title="modal组件使用示例">
3 <Alert 3 <Alert
4 message="使用 useModal 进行弹窗操作,默认可以拖动,可以通过 draggable 4 message="使用 useModal 进行弹窗操作,默认可以拖动,可以通过 draggable
5 - 参数进行控制是否可以拖动/全屏" 5 + 参数进行控制是否可以拖动/全屏,并演示了在Modal内动态加载内容并自动调整高度"
6 show-icon 6 show-icon
7 /> 7 />
8 <a-button type="primary" class="my-4" @click="openModalLoading"> 8 <a-button type="primary" class="my-4" @click="openModalLoading">
9 - 打开弹窗 默认可以拖动/全屏 9 + 打开弹窗,加载动态数据并自动调整高度(默认可以拖动/全屏)
10 </a-button> 10 </a-button>
11 11
12 <Alert message="内外同时同时显示隐藏" show-icon /> 12 <Alert message="内外同时同时显示隐藏" show-icon />
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 /> 20 />
21 <a-button type="primary" class="my-4" @click="send"> 打开弹窗并传递数据 </a-button> 21 <a-button type="primary" class="my-4" @click="send"> 打开弹窗并传递数据 </a-button>
22 22
23 - <Modal1 @register="register1" /> 23 + <Modal1 @register="register1" :minHeight="100" />
24 <Modal2 @register="register2" /> 24 <Modal2 @register="register2" />
25 <Modal3 @register="register3" /> 25 <Modal3 @register="register3" />
26 <Modal4 @register="register4" /> 26 <Modal4 @register="register4" />
@@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
39 export default defineComponent({ 39 export default defineComponent({
40 components: { Alert, Modal1, Modal2, Modal3, Modal4, PageWrapper }, 40 components: { Alert, Modal1, Modal2, Modal3, Modal4, PageWrapper },
41 setup() { 41 setup() {
42 - const [register1, { openModal: openModal1, setModalProps }] = useModal(); 42 + const [register1, { openModal: openModal1 }] = useModal();
43 const [register2, { openModal: openModal2 }] = useModal(); 43 const [register2, { openModal: openModal2 }] = useModal();
44 const [register3, { openModal: openModal3 }] = useModal(); 44 const [register3, { openModal: openModal3 }] = useModal();
45 const [register4, { openModal: openModal4 }] = useModal(); 45 const [register4, { openModal: openModal4 }] = useModal();
@@ -50,11 +50,11 @@ @@ -50,11 +50,11 @@
50 }); 50 });
51 } 51 }
52 function openModalLoading() { 52 function openModalLoading() {
53 - openModal1();  
54 - setModalProps({ loading: true });  
55 - setTimeout(() => {  
56 - setModalProps({ loading: false });  
57 - }, 2000); 53 + openModal1(true);
  54 + // setModalProps({ loading: true });
  55 + // setTimeout(() => {
  56 + // setModalProps({ loading: false });
  57 + // }, 2000);
58 } 58 }
59 return { 59 return {
60 register1, 60 register1,