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 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 71 watchEffect(() => {
74 72 props.useWrapper && setModalHeight();
... ...
src/views/demo/comp/modal/Modal1.vue
... ... @@ -7,6 +7,9 @@
7 7 :helpMessage="['提示1', '提示2']"
8 8 @visible-change="handleShow"
9 9 >
  10 + <template #insertFooter>
  11 + <a-button type="danger" @click="setLines" :disabled="loading">点我更新内容</a-button>
  12 + </template>
10 13 <template v-if="loading">
11 14 <div class="empty-tips"> 加载中,稍等3秒…… </div>
12 15 </template>
... ... @@ -18,7 +21,7 @@
18 21 </BasicModal>
19 22 </template>
20 23 <script lang="ts">
21   - import { defineComponent, ref } from 'vue';
  24 + import { defineComponent, ref, watch } from 'vue';
22 25 import { BasicModal, useModalInner } from '/@/components/Modal';
23 26 export default defineComponent({
24 27 components: { BasicModal },
... ... @@ -26,19 +29,30 @@
26 29 const loading = ref(true);
27 30 const lines = ref(10);
28 31 const [register, { setModalProps, redoModalHeight }] = useModalInner();
  32 +
  33 + watch(
  34 + () => lines.value,
  35 + () => {
  36 + redoModalHeight();
  37 + }
  38 + );
  39 +
29 40 function handleShow(visible: boolean) {
30 41 if (visible) {
31 42 loading.value = true;
32   - setModalProps({ loading: true });
  43 + setModalProps({ loading: true, confirmLoading: true });
33 44 setTimeout(() => {
34   - lines.value = Math.round(Math.random() * 20 + 10);
  45 + lines.value = Math.round(Math.random() * 30 + 5);
35 46 loading.value = false;
36   - setModalProps({ loading: false });
37   - redoModalHeight();
  47 + setModalProps({ loading: false, confirmLoading: false });
38 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 58 </script>
... ...