Blame view

src/components/Popup/index.vue 4.72 KB
1 2 3
<!--
 * @Description: 
 * @Autor: renchao
4
 * @LastEditTime: 2023-10-09 10:21:32
5
-->
liangyifan committed
6
<template>
任超 committed
7
  <transition name="msgbox-fade" v-if="myShow">
任超 committed
8
    <div class="ls-mask" v-loading="loading">
任超 committed
9
      <div class="ls-mask-window" :style="{ 'width': width }">
liangyifan committed
10
        <div class="ls-head">
任超 committed
11 12 13
          <div class="ls-title" :style="{ 'text-align': titleStyle }">
            <svg-icon v-if="iconClass != ''" :icon-class='iconClass' />
            <b>{{ title }}</b>
liangyifan committed
14 15
          </div>
          <svg-icon icon-class='close' class="closeStyle" @click="onCancel" />
liangyifan committed
16
        </div>
17
        <div class="mask-content" ref='contentRef'>
任超 committed
18
          <component :is="editItem" ref='childRef' @loading='loadingFn' :key="key" :formData='formData' />
任超 committed
19
        </div>
liangyifan committed
20
        <div class="ls-mask-footer" v-if='btnShow'>
任超 committed
21 22
          <el-button type="primary" @click="onConfirm">{{ confirmText }}</el-button>
          <el-button @click="onCancel">{{ cancelText }}</el-button>
liangyifan committed
23 24
        </div>
      </div>
任超 committed
25 26 27 28
    </div>
  </transition>
</template>
<script>
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
  export default {
    name: 'index',
    data () {
      return {
        title: '标题',
        editItem: "",
        formData: undefined,//父组件传递的参数 负责传给子组件
        btnShow: false,
        cancel: function () { },
        confirm: function () { },
        cancelText: '取消',
        confirmText: '确认',
        isSync: false,
        isShow: false,
        myShow: false,
        titleStyle: 'center',
        width: "75%",
        height: "auto",
        contentHeight: "",
        iconClass: "",
        key: 0
      }
    },
    props: {
      loading: { type: Boolean, default: false },
    },
    watch: {
      isShow (newValue) {
57
        this.$nextTick(() => {
58 59
          this.editItem = this.loadViewFn(this.editItem)
          document.body.appendChild(this.$el);
60 61
          this.myShow = newValue
        })
62 63 64 65 66 67 68 69 70 71 72 73 74 75
      }
    },
    mounted () {
      /**
       * @description: 计算滚动条高度
       * @author: renchao
       */
      setTimeout(() => {
        if (this.btnShow) {
          if (this.height == 'auto') {
            this.contentHeight = (this.$refs.contentRef.offsetHeight) + 'px'
          } else {
            this.contentHeight = this.height
          }
任超 committed
76
        } else {
77 78 79 80 81
          if (this.height == 'auto') {
            this.contentHeight = (this.$refs.contentRef.offsetHeight) + 'px'
          } else {
            this.contentHeight = this.height
          }
任超 committed
82
        }
83
      }, 300)
任超 committed
84
    },
85 86 87 88 89 90
    methods: {
      /**
       * @description: onCancel
       * @author: renchao
       */
      onCancel () {
任超 committed
91
        this.isShow = false
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
        this.cancel()
      },
      /**
       * @description: onConfirm
       * @author: renchao
       */
      onConfirm () {
        this.loading = true
        let res = new Promise((resolve, reject) => {
          this.confirm()
          resolve(true)
        })
        if (res) {
          this.isShow = false
        }
      },
      /**
       * @description: loadingFn
       * @param {*} e
       * @author: renchao
       */
      loadingFn (e) { //加载状态
        this.loading = e
      },
      /**
       * @description: loadViewFn
       * @param {*} view
       * @author: renchao
       */
      loadViewFn (view) {
        return (r) =>
          require.ensure([], () =>
            r(require(`@/views/${view}.vue`))
          )
任超 committed
126 127
      }
    },
128 129 130 131
    destroyed () {
      if (this.appendToBody && this.$el && this.$el.parentNode) {
        this.$el.parentNode.removeChild(this.$el);
      }
任超 committed
132
    }
liangyifan committed
133
  }
任超 committed
134
</script>
任超 committed
135
<style scoped lang="scss" >
136 137 138 139 140 141 142 143 144
  .ls-mask {
    width: 100%;
    height: 100%;
    z-index: 2000;
    position: fixed;
    left: 0;
    top: 0;
    background: rgba(0, 0, 0, 0.3);
  }
liangyifan committed
145

146 147 148 149 150 151 152 153
  .ls-mask-window {
    background: white;
    position: relative;
    left: 50%;
    top: 50%;
    min-height: 200px;
    transform: translate(-50%, -50%);
    border-radius: 5px;
154
    // overflow: hidden;
155
  }
任超 committed
156

157 158 159
  .ls-mask-window b {
    padding-left: 5px;
  }
任超 committed
160

161 162 163 164 165 166
  .ls-title {
    padding: 16px;
    color: #ffffff;
    font-size: 16px;
    background: linear-gradient(3deg, #409eff, #a7cbee);
  }
任超 committed
167

168 169 170
  .ls-title .svg-icon {
    font-size: 18px;
  }
任超 committed
171

172 173 174 175 176 177 178
  .mask-content {
    padding: 20px;
    width: 100%;
    min-height: 30%;
    max-height: 90vh;
    overflow-y: scroll;
  }
任超 committed
179

180 181 182 183 184 185 186 187 188 189 190 191 192
  .ls-mask-footer {
    height: 50px;
    display: flex;
    justify-content: center;
    width: 100%;
    position: absolute;
    border-top: 1px solid $borderColor;
    bottom: 0;
    background: #ffffff;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    overflow: hidden;
  }
liangyifan committed
193

194 195 196 197 198 199 200 201
  /deep/.closeStyle {
    position: absolute;
    top: 13px;
    right: 26px;
    font-size: 24px;
    cursor: pointer;
    color: #409eff;
  }
任超 committed
202

203 204 205
  /deep/.el-loading-mask {
    background: none;
  }
任超 committed
206
</style>