qinchulong
2025-03-29 039a4a5433e7f80adc88b491b549e5d9486e4f9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<template>
  <el-dialog
    custom-class="v-dialog"
    v-model="vmodel"
    :top="top"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :width="width"
    :before-close="handleClose"
  >
    <template #title> <i :class="icon"></i> {{ title }} </template>
    <div class="dia-content" :style="{ height: contentHeight + 'px' }">
      <el-scrollbar style="flex: 1">
        <!-- 是否开启懒加载2020.12.06 -->
        <div
          v-if="inited"
          class="srcoll-content"
          :style="{ padding: padding + 'px' }"
        >
              <slot name="content"></slot>
          <slot></slot>
        </div>
      </el-scrollbar>
      <div class="dia-footer">
        <slot name="footer"></slot>
        <el-button
          type="primary"
          v-if="!footer"
          size="mini"
          @click="handleClose()"
          ><i class="el-icon-close"></i>关闭</el-button
        >
      </div>
    </div>
  </el-dialog>
</template>
 
<script>
import { defineComponent, ref, watch, watchEffect } from "vue";
 
export default defineComponent({
  props: {
    modelValue: false,
    lazy: {
      //是否开启懒加载2020.12.06
      type: Boolean,
      default: false,
    },
    icon: {
      type: String,
      default: "el-icon-warning-outline",
    },
    title: {
      type: String,
      default: "基本信息",
    },
    height: {
      type: Number,
      default: 200,
    },
    width: {
      type: Number,
      default: 650,
    },
    padding: {
      type: Number,
      default: 16,
    },
    hideMask: {
      type: Boolean,
      default: false,
    },
    draggable: {
      type: Boolean,
      default: false,
    },
    mask: {
      type: Boolean,
      default: true,
    },
    onModelClose: {
      //2021.07.11增加弹出框关闭事件
      type: Function,
      default: (iconClick) => {
        return true;
      },
    },
  },
  setup(props, context) {
    const clientHeight = document.body.clientHeight;
    const inited = ref(true);
    const vmodel = ref(false);
    const footer = ref(false);
    const top = ref(100);
    vmodel.value = props.modelValue;
    footer.value = !!context.slots.footer;
    const contentHeight = ref(200);
    contentHeight.value = props.height;
    const handleClose = (done, iconClose) => {
      let result = props.onModelClose(!!iconClose);
      if (result === false) return;
      vmodel.value = false;
      context.emit("update:modelValue", false);
      done && done();
    };
    const calcHeight = (val) => {
      if (props.height > clientHeight) {
        contentHeight.value = clientHeight-56;
        return clientHeight / -2 + "px";
      }
      contentHeight.value=val||props.height;
      return (props.height + 56) / -2 + "px";
    };
 
    top.value = calcHeight();
    watch(
      () => props.modelValue,
      (newVal, oldVal) => {
        vmodel.value = newVal;
      }
    );
    watch(
      () => props.height,
      (newVal, oldVal) => {
        top.value = calcHeight();
      }
    );
    return {
      handleClose,
      inited,
      vmodel,
      footer,
      top,
      calcHeight,
      contentHeight
    };
  },
});
</script>
 
<style lang="less" scoped>
.dia-content {
  display: flex;
  flex-direction: column;
  .dia-footer {
    min-height: 40px;
    width: 100%;
    border-top: 1px solid #e2e2e2;
    text-align: right;
    padding: 6px 8px;
  }
}
</style>