Blame view

src/components/Popup/index.vue 3.93 KB
liangyifan committed
1
<template>
任超 committed
2
  <transition name="msgbox-fade" v-if="myShow">
任超 committed
3
    <div class="ls-mask" v-loading="loading">
任超 committed
4
      <div class="ls-mask-window" :style="{ 'width': width }">
liangyifan committed
5
        <div class="ls-head">
任超 committed
6 7 8
          <div class="ls-title" :style="{ 'text-align': titleStyle }">
            <svg-icon v-if="iconClass != ''" :icon-class='iconClass' />
            <b>{{ title }}</b>
liangyifan committed
9 10
          </div>
          <svg-icon icon-class='close' class="closeStyle" @click="onCancel" />
liangyifan committed
11
        </div>
任超 committed
12
        <div class="mask-content" ref='contentRef' :style="{ 'height': contentHeight }">
任超 committed
13
          <component :is="editItem" ref='childRef' @loading='loadingFn' :key="key" :formData='formData' />
任超 committed
14
        </div>
liangyifan committed
15
        <div class="ls-mask-footer" v-if='btnShow'>
任超 committed
16 17
          <el-button type="primary" @click="onConfirm">{{ confirmText }}</el-button>
          <el-button @click="onCancel">{{ cancelText }}</el-button>
liangyifan committed
18 19
        </div>
      </div>
任超 committed
20 21 22 23 24 25 26 27
    </div>
  </transition>
</template>
<script>
export default {
  name: 'index',
  data () {
    return {
任超 committed
28
      title: '标题',
任超 committed
29 30 31 32 33
      editItem: "",
      formData: undefined,//父组件传递的参数 负责传给子组件
      btnShow: false,
      cancel: function () { },
      confirm: function () { },
任超 committed
34 35 36 37
      cancelText: '取消',
      confirmText: '确认',
      isSync: false,
      isShow: false,
任超 committed
38
      myShow: false,
任超 committed
39 40
      titleStyle: 'center',
      width: "75%",
liangyifan committed
41
      height: "auto",
任超 committed
42 43 44
      contentHeight: "",
      iconClass: "",
      key: 0
任超 committed
45 46 47 48 49 50
    }
  },
  props: {
    loading: { type: Boolean, default: false },
  },
  watch: {
任超 committed
51
    isShow (newValue) {
任超 committed
52
      this.editItem = this.loadViewFn(this.editItem)
任超 committed
53
      document.body.appendChild(this.$el);
任超 committed
54
      this.myShow = newValue
任超 committed
55
    }
任超 committed
56
  },
任超 committed
57 58
  mounted () {
    //  计算滚动条高度
任超 committed
59 60 61
    setTimeout(() => {
      if (this.btnShow) {
        if (this.height == 'auto') {
任超 committed
62
          this.contentHeight = (this.$refs.contentRef.offsetHeight) + 'px'
任超 committed
63 64 65 66 67
        } else {
          this.contentHeight = this.height
        }
      } else {
        if (this.height == 'auto') {
任超 committed
68
          this.contentHeight = (this.$refs.contentRef.offsetHeight) + 'px'
任超 committed
69 70 71 72 73
        } else {
          this.contentHeight = this.height
        }
      }
    }, 300)
liangyifan committed
74
  },
任超 committed
75 76 77 78 79 80 81
  methods: {
    onCancel () {
      this.isShow = false
      this.cancel()
    },
    onConfirm () {
      this.loading = true
任超 committed
82
      let res = new Promise((resolve, reject) => {
任超 committed
83
        this.confirm()
任超 committed
84 85 86 87
        resolve(true)
      })
      if (res) {
        this.isShow = false
任超 committed
88 89 90 91 92 93 94 95
      }
    },
    loadingFn (e) { //加载状态
      this.loading = e
    },
    loadViewFn (view) {
      return (r) =>
        require.ensure([], () =>
liangyifan committed
96
          r(require(`@/views/${view}.vue`))
任超 committed
97
        )
任超 committed
98
    }
任超 committed
99 100 101 102 103
  },
  destroyed () {
    if (this.appendToBody && this.$el && this.$el.parentNode) {
      this.$el.parentNode.removeChild(this.$el);
    }
liangyifan committed
104
  }
任超 committed
105 106
}
</script>
任超 committed
107
<style scoped lang="scss" >
任超 committed
108 109 110
.ls-mask {
  width: 100%;
  height: 100%;
任超 committed
111
  z-index: 2000;
任超 committed
112 113 114 115
  position: fixed;
  left: 0;
  top: 0;
  background: rgba(0, 0, 0, 0.3);
任超 committed
116

任超 committed
117 118 119 120
}

.ls-mask-window {
  background: white;
liangyifan committed
121
  position: relative;
任超 committed
122 123
  left: 50%;
  top: 50%;
liangyifan committed
124
  min-height: 200px;
任超 committed
125
  transform: translate(-50%, -50%);
任超 committed
126 127
  border-radius: 5px;
  overflow: hidden;
任超 committed
128
}
liangyifan committed
129

任超 committed
130
.ls-mask-window b {
liangyifan committed
131
  padding-left: 5px;
任超 committed
132
}
任超 committed
133 134

.ls-title {
135
  padding: 16px;
liangyifan committed
136
  color: #ffffff;
任超 committed
137
  font-size: 16px;
138
  background: linear-gradient(3deg, #409EFF, #a7cbee);
liangyifan committed
139
}
任超 committed
140 141 142 143 144

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

任超 committed
145
.mask-content {
任超 committed
146
  padding: 20px;
liangyifan committed
147
  width: 100%;
任超 committed
148
  min-height: 30%;
149
  max-height: 90vh;
任超 committed
150
  overflow-y: scroll;
任超 committed
151 152 153
}

.ls-mask-footer {
154 155 156 157 158
  height: 50px;
  display: flex;
  justify-content: center;
  width: 100%;
  position: absolute;
任超 committed
159
  border-top: 1px solid $borderColor;
160 161
  bottom: 0;
  background: #ffffff;
任超 committed
162 163 164
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  overflow: hidden;
任超 committed
165 166
}

liangyifan committed
167

任超 committed
168
/deep/.closeStyle {
任超 committed
169
  position: absolute;
liangyifan committed
170 171 172
  top: 13px;
  right: 26px;
  font-size: 24px;
任超 committed
173
  cursor: pointer;
1  
liangyifan committed
174
  color: #409EFF;
任超 committed
175
}
任超 committed
176

任超 committed
177 178 179 180
/deep/.el-loading-mask {
  background: none;
}
</style>