You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.6 KiB
68 lines
1.6 KiB
7 years ago
|
|
||
7 years ago
|
import PropTypes from '../_util/vue-types'
|
||
7 years ago
|
import { getStyle } from '../_util/props-util'
|
||
7 years ago
|
import BaseMixin from '../_util/BaseMixin'
|
||
7 years ago
|
|
||
|
export default {
|
||
|
mixins: [BaseMixin],
|
||
|
props: {
|
||
|
duration: PropTypes.number.def(1.5),
|
||
7 years ago
|
closable: PropTypes.bool,
|
||
|
prefixCls: PropTypes.string,
|
||
7 years ago
|
},
|
||
|
|
||
|
mounted () {
|
||
|
this.startCloseTimer()
|
||
|
},
|
||
|
|
||
7 years ago
|
beforeDestroy () {
|
||
7 years ago
|
this.clearCloseTimer()
|
||
7 years ago
|
this.willDestroy = true // beforeDestroy调用后依然会触发onMouseleave事件
|
||
7 years ago
|
},
|
||
|
methods: {
|
||
|
close () {
|
||
|
this.clearCloseTimer()
|
||
7 years ago
|
this.__emit('close')
|
||
7 years ago
|
},
|
||
|
|
||
|
startCloseTimer () {
|
||
7 years ago
|
this.clearCloseTimer()
|
||
|
if (!this.willDestroy && this.duration) {
|
||
7 years ago
|
this.closeTimer = setTimeout(() => {
|
||
|
this.close()
|
||
|
}, this.duration * 1000)
|
||
|
}
|
||
|
},
|
||
|
|
||
|
clearCloseTimer () {
|
||
|
if (this.closeTimer) {
|
||
|
clearTimeout(this.closeTimer)
|
||
|
this.closeTimer = null
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
|
||
|
render () {
|
||
|
const { prefixCls, closable, clearCloseTimer, startCloseTimer, $slots, close } = this
|
||
|
const componentClass = `${prefixCls}-notice`
|
||
|
const className = {
|
||
|
[`${componentClass}`]: 1,
|
||
|
[`${componentClass}-closable`]: closable,
|
||
|
}
|
||
|
const style = getStyle(this)
|
||
|
return (
|
||
|
<div class={className} style={style || { right: '50%' } } onMouseenter={clearCloseTimer}
|
||
|
onMouseleave={startCloseTimer}
|
||
|
>
|
||
|
<div class={`${componentClass}-content`}>{$slots.default}</div>
|
||
|
{closable
|
||
|
? <a tabIndex='0' onClick={close} class={`${componentClass}-close`}>
|
||
|
<span class={`${componentClass}-close-x`}></span>
|
||
|
</a> : null
|
||
|
}
|
||
|
</div>
|
||
|
)
|
||
|
},
|
||
|
}
|
||
|
|