index.vue
3.9 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
<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}">
<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="ls-mask-content" ref='contentRef' :style="{'height': contentHeight}">
<component :is="editItem" ref='childRef' @loading='loadingFn' :key="key" :formData='formData' />
</div>
<div class="ls-mask-footer" v-if='btnShow'>
<el-button type="primary" @click="onConfirm">{{confirmText}}</el-button>
<el-button @click="onCancel">{{cancelText}}</el-button>
</div>
</div>
</div>
</transition>
</template>
<script>
export default {
name: 'index',
data () {
return {
btnShow:false,
title: '提示',
cancelText: '取消',
confirmText: '确认',
isSync: false,
isShow: false,
cancel: function () { },
confirm: function () { },
editItem: "",
titleStyle: 'center',
width: "75%",
height: "auto",
formData: "",//父组件传递的参数 负责传给子组件
contentHeight: "",
iconClass: "",
key: 0
}
},
props: {
loading: { type: Boolean, default: false },
},
watch: {
isShow (a, b) {
this.key++
this.editItem = this.loadViewFn(this.editItem)
},
},
mounted () {
// 计算滚动条高度
setTimeout(() => {
if(this.btnShow){ //判断按钮的显影来决定是否需要计算高度
if(this.height == 'auto'){
this.contentHeight = (this.$refs.contentRef.offsetHeight - 115) + 'px'
}else{
this.contentHeight =(parseInt(this.height)-parseInt('115px'))+'px';
}
}else{
if(this.height == 'auto'){
this.contentHeight = this.$refs.contentRef.offsetHeight + 'px'
}else{
this.contentHeight =this.height
}
}
}, 500)
},
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([], () =>
r(require(`@/views/${view}.vue`))
);
}
}
}
</script>
<style scoped>
#app {
overflow: hidden;
}
.ls-mask {
width: 100%;
height: 100%;
z-index: 2001;
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: 10px;
}
.ls-mask-window b {
padding-left: 5px;
}
.ls-title {
padding: 16px;
color: #ffffff;
background: linear-gradient(-2deg,#409EFF, transparent)
}
.ls-title .svg-icon {
font-size: 18px;
}
.ls-mask-content {
padding: 20px;
width: 100%;
overflow: scroll;
}
.ls-mask-footer {
height: 65px;
display: flex;
justify-content: center;
width: 100%;
box-shadow: 0px 0px 2px 0px;
border-radius: 0 0 10px 10px;
position: absolute;
bottom: 0;
background: #ffffff;
}
/deep/.closeStyle {
position: absolute;
top: 17px;
right: 12px;
font-size: 20px;
cursor: pointer;
color: #ffffff;
}
/deep/.el-loading-mask {
background: none;
}
/deep/.el-button {
margin: 15px 10px;
width: 75px;
}
</style>