Commit 5d554f184f7b61774d1a1b2e61451677b38505de

Authored by 无木
1 parent f732b569

fix(modal): redoModalHeight not work as expected

修复redoModalHeight根据内容重设高度时,只会增大而不能减少Modal高度的问题
src/components/Modal/src/components/ModalWrapper.vue
@@ -60,15 +60,13 @@ @@ -60,15 +60,13 @@
60 redoModalHeight: setModalHeight, 60 redoModalHeight: setModalHeight,
61 }); 61 });
62 62
63 - const spinStyle = computed(  
64 - (): CSSProperties => {  
65 - return {  
66 - minHeight: `${props.minHeight}px`,  
67 - // padding 28  
68 - height: `${unref(realHeightRef)}px`,  
69 - };  
70 - }  
71 - ); 63 + const spinStyle = computed((): CSSProperties => {
  64 + return {
  65 + minHeight: `${props.minHeight}px`,
  66 + // padding 28
  67 + maxHeight: `${unref(realHeightRef)}px`,
  68 + };
  69 + });
72 70
73 watchEffect(() => { 71 watchEffect(() => {
74 props.useWrapper && setModalHeight(); 72 props.useWrapper && setModalHeight();
src/views/demo/comp/modal/Modal1.vue
@@ -7,6 +7,9 @@ @@ -7,6 +7,9 @@
7 :helpMessage="['提示1', '提示2']" 7 :helpMessage="['提示1', '提示2']"
8 @visible-change="handleShow" 8 @visible-change="handleShow"
9 > 9 >
  10 + <template #insertFooter>
  11 + <a-button type="danger" @click="setLines" :disabled="loading">点我更新内容</a-button>
  12 + </template>
10 <template v-if="loading"> 13 <template v-if="loading">
11 <div class="empty-tips"> 加载中,稍等3秒…… </div> 14 <div class="empty-tips"> 加载中,稍等3秒…… </div>
12 </template> 15 </template>
@@ -18,7 +21,7 @@ @@ -18,7 +21,7 @@
18 </BasicModal> 21 </BasicModal>
19 </template> 22 </template>
20 <script lang="ts"> 23 <script lang="ts">
21 - import { defineComponent, ref } from 'vue'; 24 + import { defineComponent, ref, watch } from 'vue';
22 import { BasicModal, useModalInner } from '/@/components/Modal'; 25 import { BasicModal, useModalInner } from '/@/components/Modal';
23 export default defineComponent({ 26 export default defineComponent({
24 components: { BasicModal }, 27 components: { BasicModal },
@@ -26,19 +29,30 @@ @@ -26,19 +29,30 @@
26 const loading = ref(true); 29 const loading = ref(true);
27 const lines = ref(10); 30 const lines = ref(10);
28 const [register, { setModalProps, redoModalHeight }] = useModalInner(); 31 const [register, { setModalProps, redoModalHeight }] = useModalInner();
  32 +
  33 + watch(
  34 + () => lines.value,
  35 + () => {
  36 + redoModalHeight();
  37 + }
  38 + );
  39 +
29 function handleShow(visible: boolean) { 40 function handleShow(visible: boolean) {
30 if (visible) { 41 if (visible) {
31 loading.value = true; 42 loading.value = true;
32 - setModalProps({ loading: true }); 43 + setModalProps({ loading: true, confirmLoading: true });
33 setTimeout(() => { 44 setTimeout(() => {
34 - lines.value = Math.round(Math.random() * 20 + 10); 45 + lines.value = Math.round(Math.random() * 30 + 5);
35 loading.value = false; 46 loading.value = false;
36 - setModalProps({ loading: false });  
37 - redoModalHeight(); 47 + setModalProps({ loading: false, confirmLoading: false });
38 }, 3000); 48 }, 3000);
39 } 49 }
40 } 50 }
41 - return { register, loading, handleShow, lines }; 51 +
  52 + function setLines() {
  53 + lines.value = Math.round(Math.random() * 20 + 10);
  54 + }
  55 + return { register, loading, handleShow, lines, setLines };
42 }, 56 },
43 }); 57 });
44 </script> 58 </script>