Blame view

src/components/tanchuang/index.vue 3.99 KB
liangyifan committed
1
<template>
任超 committed
2 3 4
  <transition name="fade" mode="out-in" v-if="isShow">
    <div class="ls-mask" v-loading="loading">
      <div class="ls-mask-window" :style="{'width':width,'height':height}">
liangyifan committed
5
        <div class="ls-head">
liangyifan committed
6
          <div class="ls-title" :style="{'text-align':titleStyle}">
任超 committed
7
            <svg-icon v-if="iconClass!=''" :icon-class='iconClass' />
liangyifan committed
8 9 10
            <b>{{title}}</b>
          </div>
          <svg-icon icon-class='close' class="closeStyle" @click="onCancel" />
liangyifan committed
11
        </div>
任超 committed
12

liangyifan committed
13
        <div class="ls-mask-content" ref='contentRef' :style="{'height': contentHeight}">
任超 committed
14
          <component :is="editItem" ref='childRef' @loading='loadingFn' :key="key" :formData='formData' />
任超 committed
15
        </div>
liangyifan committed
16
        <div class="ls-mask-footer" v-if='btnShow'>
任超 committed
17 18
          <el-button type="primary" @click="onConfirm">{{confirmText}}</el-button>
          <el-button @click="onCancel">{{cancelText}}</el-button>
liangyifan committed
19 20
        </div>
      </div>
任超 committed
21 22 23 24 25 26 27 28
    </div>
  </transition>
</template>
<script>
export default {
  name: 'index',
  data () {
    return {
liangyifan committed
29
      btnShow: false,
任超 committed
30 31 32 33 34 35 36 37 38 39
      title: '提示',
      cancelText: '取消',
      confirmText: '确认',
      isSync: false,
      isShow: false,
      cancel: function () { },
      confirm: function () { },
      editItem: "",
      titleStyle: 'center',
      width: "75%",
liangyifan committed
40
      height: "auto",
任超 committed
41
      formData: undefined,//父组件传递的参数 负责传给子组件
任超 committed
42 43 44
      contentHeight: "",
      iconClass: "",
      key: 0
任超 committed
45 46 47 48 49 50 51
    }
  },
  props: {
    loading: { type: Boolean, default: false },
  },
  watch: {
    isShow (a, b) {
任超 committed
52
      this.key++
任超 committed
53 54 55
      this.editItem = this.loadViewFn(this.editItem)
    },
  },
任超 committed
56 57
  mounted () {
    //  计算滚动条高度
任超 committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    // setTimeout(() => {
    //   if (this.btnShow) {
    //     if (this.height == 'auto') {
    //       this.contentHeight = (this.$refs.contentRef.offsetHeight - 200) + 'px'
    //     } else {
    //       this.contentHeight = this.height
    //     }
    //   } else {
    //     if (this.height == 'auto') {
    //       this.contentHeight = this.$refs.contentRef.offsetHeight
    //     } else {
    //       this.contentHeight = this.height
    //     }
    //   }
    // }, 500)
liangyifan committed
73
  },
任超 committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  methods: {
    onCancel () {
      this.isShow = false
      this.cancel()
    },
    onConfirm () {
      this.loading = true
      let isOk = this.$refs.childRef.childFn()  //子组件方法 必须命名一致
      if (isOk || isOk == undefined) { //如果子组件没有 return false 就代表子组件方法一切正常
        this.isShow = false
        this.confirm()
      } else { //否则
        console.log('弹窗不关闭')
      }
    },
    loadingFn (e) { //加载状态
      this.loading = e
    },
    loadViewFn (view) {
      return (r) =>
        require.ensure([], () =>
liangyifan committed
95 96
          r(require(`@/views/${view}.vue`))
        );
任超 committed
97
    }
liangyifan committed
98
  }
任超 committed
99 100
}
</script>
任超 committed
101
<style scoped lang="scss" >
任超 committed
102 103 104 105 106 107 108 109
.ls-mask {
  width: 100%;
  height: 100%;
  z-index: 2001;
  position: fixed;
  left: 0;
  top: 0;
  background: rgba(0, 0, 0, 0.3);
任超 committed
110

任超 committed
111 112 113 114
}

.ls-mask-window {
  background: white;
liangyifan committed
115
  position: relative;
任超 committed
116 117
  left: 50%;
  top: 50%;
liangyifan committed
118
  min-height: 200px;
任超 committed
119
  transform: translate(-50%, -50%);
任超 committed
120
  border-radius: 10px;
任超 committed
121
}
liangyifan committed
122

任超 committed
123
.ls-mask-window b {
liangyifan committed
124
  padding-left: 5px;
任超 committed
125
}
任超 committed
126 127

.ls-title {
128
  padding: 16px;
liangyifan committed
129
  color: #ffffff;
130 131 132 133
  background: linear-gradient(3deg, #409EFF, #a7cbee);
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
  overflow: hidden;
liangyifan committed
134
}
任超 committed
135 136 137 138 139

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

任超 committed
140 141
.ls-mask-content {
  padding: 20px;
liangyifan committed
142 143
  width: 100%;
  overflow: scroll;
任超 committed
144 145 146
}

.ls-mask-footer {
147 148 149 150 151
  height: 50px;
  display: flex;
  justify-content: center;
  width: 100%;
  position: absolute;
任超 committed
152
  border-top: 1px solid $borderColor;
153 154
  bottom: 0;
  background: #ffffff;
任超 committed
155 156 157
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
  overflow: hidden;
任超 committed
158 159
}

liangyifan committed
160

任超 committed
161
/deep/.closeStyle {
任超 committed
162
  position: absolute;
liangyifan committed
163 164 165
  top: 13px;
  right: 26px;
  font-size: 24px;
任超 committed
166
  cursor: pointer;
1  
liangyifan committed
167
  color: #409EFF;
任超 committed
168
}
任超 committed
169

任超 committed
170 171 172
/deep/.el-loading-mask {
  background: none;
}
任超 committed
173 174

/deep/.el-button {
liangyifan committed
175
  margin: 8px 10px;
176
  width: 75px;
liangyifan committed
177
}
任超 committed
178
</style>
liangyifan committed
179