2018-03-26 16:04:04 +08:00
|
|
|
<template>
|
|
|
|
<div class="md-dialog">
|
|
|
|
<md-popup
|
|
|
|
:value="value"
|
|
|
|
:hasMask="hasMask"
|
|
|
|
:maskClosable="maskClosable"
|
2018-08-22 13:46:33 +08:00
|
|
|
position="center"
|
2018-03-26 16:04:04 +08:00
|
|
|
:transition="transition"
|
|
|
|
:preventScroll="preventScroll"
|
|
|
|
:preventScrollExclude="preventScrollExclude"
|
|
|
|
@input="$_onInput"
|
|
|
|
@show="$_onShow"
|
|
|
|
@hide="$_onHide"
|
|
|
|
>
|
|
|
|
<div class="md-dialog-content">
|
|
|
|
<div class="md-dialog-body">
|
|
|
|
<a
|
|
|
|
role="button"
|
|
|
|
v-if="closable"
|
|
|
|
class="md-dialog-close"
|
|
|
|
@click="close"
|
|
|
|
>
|
|
|
|
<md-icon name="cross" />
|
|
|
|
</a>
|
2018-03-30 11:16:44 +08:00
|
|
|
<div v-if="icon" class="md-dialog-icon">
|
|
|
|
<md-icon :name="icon" />
|
|
|
|
</div>
|
2018-03-26 16:04:04 +08:00
|
|
|
<h2 class="md-dialog-title" v-if="title" v-text="title"></h2>
|
2018-03-30 11:16:44 +08:00
|
|
|
<div class="md-dialog-text" v-if="content" v-html="content"></div>
|
|
|
|
<div class="md-dialog-text" v-else-if="$slots.default">
|
|
|
|
<slot></slot>
|
|
|
|
</div>
|
2018-03-26 16:04:04 +08:00
|
|
|
</div>
|
2018-08-22 13:46:33 +08:00
|
|
|
<footer class="md-dialog-actions" :class="{ 'is-column': layout === 'column' }">
|
2018-03-26 16:04:04 +08:00
|
|
|
<a
|
|
|
|
role="button"
|
2018-08-22 13:46:33 +08:00
|
|
|
class="md-dialog-btn"
|
2018-03-26 16:04:04 +08:00
|
|
|
v-for="(btn, index) in btns"
|
|
|
|
:key="index"
|
|
|
|
v-text="btn.text"
|
|
|
|
@click="$_onClick(btn)"
|
|
|
|
></a>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</md-popup>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
import Popup from '../popup'
|
|
|
|
import Icon from '../icon'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'md-dialog',
|
|
|
|
|
|
|
|
components: {
|
|
|
|
[Popup.name]: Popup,
|
|
|
|
[Icon.name]: Icon,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
closable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
btns: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
2018-08-22 13:46:33 +08:00
|
|
|
layout: {
|
|
|
|
type: String,
|
|
|
|
default: 'row',
|
|
|
|
},
|
2018-03-26 16:04:04 +08:00
|
|
|
appendTo: {
|
|
|
|
default: () => document.body,
|
|
|
|
},
|
|
|
|
hasMask: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
maskClosable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
transition: {
|
|
|
|
type: String,
|
|
|
|
default: 'fade',
|
|
|
|
},
|
|
|
|
preventScroll: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
preventScrollExclude: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
if (this.appendTo) {
|
|
|
|
this.appendTo.appendChild(this.$el)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-18 15:05:47 +08:00
|
|
|
beforeDestroy() {
|
|
|
|
if (this.appendTo) {
|
|
|
|
this.appendTo.removeChild(this.$el)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-03-26 16:04:04 +08:00
|
|
|
methods: {
|
|
|
|
// MARK: private methods
|
|
|
|
|
|
|
|
// MARK: events handler
|
|
|
|
$_onInput(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
},
|
|
|
|
$_onShow() {
|
|
|
|
this.$emit('show')
|
|
|
|
},
|
|
|
|
$_onHide() {
|
|
|
|
this.$emit('hide')
|
|
|
|
},
|
|
|
|
$_onClick(btn) {
|
|
|
|
if (typeof btn.handler === 'function') {
|
|
|
|
btn.handler.call(null)
|
|
|
|
} else {
|
|
|
|
this.close()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// MARK: public methods
|
|
|
|
close() {
|
|
|
|
this.$emit('input', false)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus">
|
|
|
|
.md-dialog
|
|
|
|
z-index dialog-zindex
|
|
|
|
.md-dialog-content
|
|
|
|
width dialog-width
|
|
|
|
border-radius dialog-radius
|
|
|
|
background-color color-bg-base
|
|
|
|
overflow hidden
|
|
|
|
.md-dialog-body
|
2018-06-05 18:34:40 +08:00
|
|
|
color dialog-text-color
|
2018-03-26 16:04:04 +08:00
|
|
|
font-size dialog-text-font-size
|
2018-07-26 17:33:29 +08:00
|
|
|
display flex
|
|
|
|
flex-direction column
|
|
|
|
align-items center
|
|
|
|
justify-content center
|
|
|
|
text-align left
|
2018-08-22 13:46:33 +08:00
|
|
|
padding v-gap-sl h-gap-sl
|
2018-03-30 11:16:44 +08:00
|
|
|
.md-dialog-icon
|
|
|
|
position relative
|
2018-03-26 16:04:04 +08:00
|
|
|
display block
|
|
|
|
width dialog-icon-size
|
|
|
|
height dialog-icon-size
|
2018-08-22 13:46:33 +08:00
|
|
|
margin v-gap-md auto
|
2018-03-30 11:16:44 +08:00
|
|
|
.md-icon
|
|
|
|
width dialog-icon-size
|
|
|
|
height dialog-icon-size
|
|
|
|
fill dialog-icon-fill
|
2018-03-26 16:04:04 +08:00
|
|
|
.md-dialog-close
|
|
|
|
position absolute
|
2018-06-05 18:34:40 +08:00
|
|
|
color dialog-close-color
|
2018-08-22 13:46:33 +08:00
|
|
|
top 32px
|
|
|
|
right 32px
|
2018-03-26 16:04:04 +08:00
|
|
|
z-index 15
|
|
|
|
.md-dialog-title
|
2018-06-05 18:34:40 +08:00
|
|
|
color dialog-title-color
|
2018-07-26 17:33:29 +08:00
|
|
|
text-align center
|
2018-03-26 16:04:04 +08:00
|
|
|
font-size dialog-title-font-size
|
2018-08-22 13:46:33 +08:00
|
|
|
line-height 1.2
|
|
|
|
margin-bottom 28px
|
2018-03-26 16:04:04 +08:00
|
|
|
.md-dialog-actions
|
|
|
|
display flex
|
2018-06-05 18:34:40 +08:00
|
|
|
hairline(top, dialog-action-border-color)
|
2018-08-22 13:46:33 +08:00
|
|
|
&.is-column
|
|
|
|
flex-direction column
|
|
|
|
.md-dialog-btn
|
|
|
|
flex 0 0 auto
|
|
|
|
remove-hairline(right)
|
|
|
|
&:not(:first-child)
|
|
|
|
hairline(top, dialog-action-border-color)
|
|
|
|
&:last-child
|
|
|
|
color color-text-caption
|
|
|
|
&:first-child
|
|
|
|
color dialog-action-highlight-color
|
|
|
|
.md-dialog-btn
|
|
|
|
flex 1 1 0%
|
|
|
|
display flex
|
|
|
|
align-items center
|
|
|
|
justify-content center
|
|
|
|
height dialog-action-height
|
|
|
|
font-size dialog-action-font-size
|
|
|
|
color color-text-caption
|
|
|
|
text-align center
|
|
|
|
hairline(right, dialog-action-border-color)
|
|
|
|
&:last-child
|
|
|
|
color dialog-action-highlight-color
|
|
|
|
remove-hairline(right)
|
|
|
|
|
|
|
|
.md-popup.center
|
|
|
|
.md-popup-box
|
|
|
|
transform translate(-50%, -50%)
|
|
|
|
&.fade-enter
|
|
|
|
opacity 0.01
|
|
|
|
transform translate(-50%, -20%)
|
|
|
|
&.fade-leave-to
|
|
|
|
opacity 0.01
|
|
|
|
transform translate(-50%, -70%)
|
|
|
|
&.fade-enter-active,
|
|
|
|
&.fade-leave-active,
|
|
|
|
&.bounce-leave-active
|
|
|
|
transition all 200ms
|
|
|
|
&.bounce-enter
|
|
|
|
opacity 0.01
|
|
|
|
&.bounce-enter-active
|
|
|
|
animation bounce-in 300ms
|
|
|
|
&.bounce-leave-to
|
|
|
|
opacity 0.01
|
|
|
|
transform translate(-50%, -50%) scale(0.5)
|
|
|
|
@keyframes bounce-in {
|
|
|
|
0% {
|
|
|
|
transform: translate(-50%, -50%) scale(1);
|
|
|
|
}
|
|
|
|
1% {
|
|
|
|
transform: translate(-50%, -50%) scale(0.5);
|
|
|
|
}
|
|
|
|
45% {
|
|
|
|
transform: translate(-50%, -50%) scale(1.05);
|
|
|
|
}
|
|
|
|
80% {
|
|
|
|
transform: translate(-50%, -50%) scale(0.95);
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
transform: translate(-50%, -50%) scale(1);
|
|
|
|
}
|
|
|
|
}
|
2018-03-26 16:04:04 +08:00
|
|
|
</style>
|