Blame view

src/components/ywPopup/index.vue 4.63 KB
1 2 3
<!--
 * @Description: 
 * @Autor: renchao
4
 * @LastEditTime: 2023-10-13 11:01:27
5
-->
6 7
<template>
  <transition name="msgbox-fade">
8
    <div class="ls-mask" ref="popup" v-if="myShow">
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
      <div class="ls-mask-window" :class="isMain ? 'mainCenter' : 'contentCenter'" :style="{ 'width': width }">
        <div class="ls-head">
          <div class="ls-title" :style="{ 'text-align': titleStyle }">
            <svg-icon v-if="iconClass != ''" :icon-class='iconClass' />
            <b>{{ title }}</b>
          </div>
          <svg-icon icon-class='close' class="closeStyle" @click="onCancel" />
        </div>
        <div class="mask-content" ref='contentRef' :style="{ 'height': contentHeight }">
          <component :is="editItem" ref='childRef' :key="key" :formData='formData' />
        </div>
        <div class="ls-mask-footer" v-if='btnShow'>
          <el-button @click="onCancel">{{ cancelText }}</el-button>
        </div>
      </div>
    </div>
  </transition>
</template>
<script>
  import Popup1 from './index'
  export default {
    name: 'index',
    data () {
      return {
33
        zIndexCounter: 2000,
34 35 36 37
        title: '标题',
        editItem: "",
        isMain: false,
        formData: undefined,//父组件传递的参数 负责传给子组件
38
        btnShow: true,
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        cancel: function () { },
        confirm: function () { },
        cancelText: '取消',
        confirmText: '确认',
        isSync: false,
        isShow: false,
        myShow: false,
        titleStyle: 'center',
        width: "75%",
        height: "auto",
        contentHeight: "",
        iconClass: "",
        key: 0
      }
    },
    watch: {
      isShow (newValue) {
        this.$nextTick(() => {
57 58
          this.editItem = this.loadViewFn(this.editItem)
          document.body.appendChild(this.$el);
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
          this.myShow = newValue
        })
      }
    },
    mounted () {
      //  计算滚动条高度
      setTimeout(() => {
        if (this.btnShow) {
          if (this.height == 'auto') {
            this.contentHeight = (this.$refs.contentRef.offsetHeight) + 'px'
          } else {
            this.contentHeight = this.height
          }
        } else {
          if (this.height == 'auto') {
            this.contentHeight = (this.$refs.contentRef.offsetHeight) + 'px'
          } else {
            this.contentHeight = this.height
          }
        }
      }, 300)
    },
    methods: {
yuanbo committed
82 83 84 85
      /**
       * @description: onCancel
       * @author: renchao
       */
86 87 88
      onCancel () {
        Popup1().close()
      },
yuanbo committed
89 90 91 92
      /**
       * @description: onConfirm
       * @author: renchao
       */
93 94 95 96 97 98 99 100 101
      onConfirm () {
        let res = new Promise((resolve, reject) => {
          this.confirm()
          resolve(true)
        })
        if (res) {
          this.isShow = false
        }
      },
yuanbo committed
102 103 104 105 106
      /**
       * @description: loadViewFn
       * @param {*} view
       * @author: renchao
       */
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
      loadViewFn (view) {
        return (r) =>
          require.ensure([], () =>
            r(require(`@/views/${view}.vue`))
          )
      }
    },
    destroyed () {
      if (this.appendToBody && this.$el && this.$el.parentNode) {
        this.$el.parentNode.removeChild(this.$el);
      }
    }
  }
</script>
<style scoped lang="scss" >
  @import "~@/styles/mixin.scss";
  @import "~@/styles/dialogBox.scss";

  .ls-mask {
    width: 100%;
    height: 100%;
    z-index: 500;
    position: fixed;
    left: 0;
    top: 0;
    background: rgba(0, 0, 0, 0.3);
  }

  .ls-mask-window {
    background: white;
    position: relative;
    left: 50%;
    top: 50%;
    min-height: 200px;
    transform: translate(-50%, -50%);
    border-radius: 5px;
143
    // overflow: hidden;
144 145 146 147 148 149 150 151
  }

  .ls-mask-window b {
    padding-left: 5px;
  }

  .ls-title {
    padding: 16px;
152 153
    color: #ffffff;
    background: linear-gradient(3deg, #409eff, #a7cbee);
154 155 156 157 158 159 160 161
    font-size: 16px;
  }

  .ls-title .svg-icon {
    font-size: 18px;
  }

  .mask-content {
162
    padding: 5px 20px 30px 20px;
163 164 165 166 167 168
    width: 100%;
    max-height: 90vh;
    overflow-y: scroll;
  }

  .ls-mask-footer {
169
    height: 33px;
170 171 172 173 174 175 176 177 178
    display: flex;
    justify-content: center;
    width: 100%;
    position: absolute;
    bottom: 0;
    background: #ffffff;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    overflow: hidden;
179
    margin-bottom: 10px;
180 181 182 183 184 185 186 187
  }

  /deep/.closeStyle {
    position: absolute;
    top: 13px;
    right: 26px;
    font-size: 24px;
    cursor: pointer;
188
    color: #ffffff;
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  }

  /deep/.el-loading-mask {
    background: none;
  }

  .dialog-fade-enter-active,
  .dialog-fade-leave-active {
    transition: opacity 0.3s;
  }

  .dialog-fade-enter,
  .dialog-fade-leave-to {
    opacity: 0;
  }
</style>