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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<template>
<modal
v-model="isShow"
:ref="refName"
class="app-modal-ok"
:class="customClass"
:closable="showClose"
:zIndex="zIndex"
:mask="mask"
:maskClosable="maskClosable"
:className="getClassName()"
>
<p slot="header" v-if="title" :class="type" class="header">
<i :class="geticonClass()"></i>
{{ title }}
</p>
<p v-else :class="[type,'body-icon']">
<i :class="geticonClass()"></i>
</p>
<div class="content" v-html="content"></div>
<div slot="footer" ref="modelokFooter">
<template v-for="item in buttonModel">
<i-button v-if="item.visibel" :key="item.value" :type="item.type" @click="button_click(item)">
{{ item.text }}
</i-button>
</template>
<slot name="customFooter" @click="button_click"></slot>
</div>
</modal>
</template>
<script lang="ts">
import { VNode } from 'node_modules/vue/types';
import { Subject } from 'rxjs';
import { AppMessageBox as AppMessage } from './app-message-box';
import { Vue, Component, Prop } from 'vue-property-decorator';
import './app-message-box.less';
@Component({
components: {},
})
export default class AppMessageBox extends Vue {
/**
* 对话框类型
*
* @type {('info' | 'success' | 'warning' | 'error')}
* @memberof AppMessageBox
*/
@Prop({ default: 'info' })
public type?: 'info' | 'success' | 'warning' | 'error' | 'question';
/**
* 标题
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop()
public title?: string;
/**
* 内容
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop()
public content?: string;
/**
* 按钮类型
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop({ default: 'okcancel' })
public buttonType?: string | 'okcancel' | 'yesno' | 'yesnocancel' | 'ok';
/**
* 启用自定义底部
*
* @type {boolean}
* @memberof ModalokOptions
*/
@Prop({ default: false })
public visibleCustomFooter?: boolean;
/**
* 自定义底部
*
* @type {VNode}
* @memberof ModalokOptions
*/
@Prop()
public customFooter?: VNode;
/**
* 自定义类名
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop()
public customClass?: string;
/**
* 自定义类名
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop()
public iconClass?: string;
/**
* 是否显示右上角的关闭按钮
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop({ default: false })
public showClose?: boolean;
/**
* 是否显示遮罩
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop({ default: true })
public mask?: boolean;
/**
* 是否可以点击遮罩关闭
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop({ default: false })
public maskClosable?: boolean;
/**
* 显示模式
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop({ default: 'center' })
public showMode?: string | 'center';
/**
* 关闭回调
*
* @type {Function}
* @memberof AppMessageBox
*/
@Prop()
public onClose?: Function;
/**
* 引用对象名称
*
* @type {string}
* @memberof AppMessageBox
*/
@Prop()
public refName?: string;
/**
* 内置按钮模型
*
* @type {any}
* @memberof AppMessageBox
*/
public buttonModel = [
{ text: this.$t('components.appmessagebox.ok'), value: 'ok', type: 'primary', visibel: false },
{ text: this.$t('app.commonwords.yes'), value: 'yes', type: 'primary', visibel: false },
{ text: this.$t('app.commonwords.no'), value: 'no', visibel: false },
{ text: this.$t('components.appmessagebox.cancel'), value: 'cancel', visibel: false },
];
/**
* 数据传递对象
*
* @type {any}
* @memberof AppMessageBox
*/
public subject: null | Subject<any> = new Subject<any>();
/**
* 层级
*
* @type {any}
* @memberof AppMessageBox
*/
public zIndex: any = null;
/**
* 是否显示
*
* @type {boolean}
* @memberof AppMessageBox
*/
public isShow: boolean = false;
/**
* 获取显示模式类名 居中/top
*
* @memberof AppMessageBox
*/
public getClassName() {
return this.showMode === 'center' ? 'center' : 'top';
}
/**
* 根据type计算iconClass
*
* @memberof AppMessageBox
*/
public geticonClass() {
if (this.customClass) {
return this.customClass;
}
let classes = 'ivu-icon ';
switch (this.type) {
case 'info':
classes = classes + 'ivu-icon-ios-information-circle';
break;
case 'success':
classes = classes + 'ivu-icon-ios-checkmark-circle';
break;
case 'warning':
classes = classes + 'ivu-icon-ios-alert';
break;
case 'error':
classes = classes + 'ivu-icon-ios-close-circle';
break;
case 'question':
classes = classes + 'el-icon-question';
break;
}
return classes;
}
/**
* 获取数据传递对象
*
* @memberof AppMessageBox
*/
public getSubject() {
return this.subject;
}
/**
* 按钮点击
*
* @memberof AppMessageBox
*/
public button_click(item: any) {
this.isShow = false;
if (this.subject) {
this.subject.next(item.value);
}
this.close();
}
/**
* 初始化按钮Model
*
* @memberof AppMessageBox
*/
public initButtonModel() {
if (this.visibleCustomFooter) {
return;
}
switch (this.buttonType) {
case 'okcancel':
this.buttonModel[0].visibel = true;
this.buttonModel[3].visibel = true;
break;
case 'yesno':
this.buttonModel[1].visibel = true;
this.buttonModel[2].visibel = true;
break;
case 'yesnocancel':
this.buttonModel[1].visibel = true;
this.buttonModel[2].visibel = true;
this.buttonModel[3].visibel = true;
break;
case 'ok':
this.buttonModel[0].visibel = true;
break;
}
}
/**
* 关闭方法
*
* @memberof AppMessageBox
*/
public close() {
if (this.onClose) {
this.onClose(this);
}
setTimeout(() => {
document.body.removeChild(this.$el);
this.$destroy();
AppMessage.getInstance().destroyVueExample();
this.subject = null;
}, 500);
}
/**
* Vue生命周期created
*
* @memberof AppMessageBox
*/
public created() {
this.initButtonModel();
}
/**
* Vue生命周期mounted
*
* @memberof AppMessageBox
*/
public mounted() {
const zIndex = this.$store.getters.getZIndex();
if (zIndex) {
this.zIndex = zIndex + 100;
this.$store.commit('updateZIndex', this.zIndex);
}
if (this.visibleCustomFooter && this.customFooter) {
this.$slots.customFooter = [this.customFooter];
this.$forceUpdate();
}
this.isShow = true;
}
}
</script>
<style lang="less" scoped>
</style>