[improvement] add bind event mixin

This commit is contained in:
陈嘉涵
2019-06-03 17:46:14 +08:00
parent 884f624a16
commit 616db0114e
4 changed files with 56 additions and 82 deletions

View File

@@ -1,5 +1,6 @@
import { use } from '../utils';
import { stopPropagation } from '../utils/event';
import { BindEventMixin } from '../mixins/bind-event';
import Key from './Key';
const [sfc, bem, t] = use('number-keyboard');
@@ -7,6 +8,14 @@ const CLOSE_KEY_TYPE = ['blue', 'big'];
const DELETE_KEY_TYPE = ['delete', 'big', 'gray'];
export default sfc({
mixins: [
BindEventMixin(function (bind) {
if (this.hideOnClickOutside) {
bind(document.body, 'touchstart', this.onBlur);
}
})
],
props: {
show: Boolean,
title: String,
@@ -39,22 +48,6 @@ export default sfc({
}
},
mounted() {
this.handler(true);
},
destroyed() {
this.handler(false);
},
activated() {
this.handler(true);
},
deactivated() {
this.handler(false);
},
watch: {
show() {
if (!this.transition) {
@@ -92,21 +85,6 @@ export default sfc({
},
methods: {
handler(action) {
/* istanbul ignore if */
if (this.$isServer) {
return;
}
if (action !== this.handlerStatus && this.hideOnClickOutside) {
this.handlerStatus = action;
document.body[(action ? 'add' : 'remove') + 'EventListener'](
'touchstart',
this.onBlur
);
}
},
onBlur() {
this.$emit('blur');
},