forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n3Aside.vue
executable file
·107 lines (103 loc) · 2.71 KB
/
n3Aside.vue
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
<template>
<div
:style="{width:width}"
:class="classObj"
v-show="show"
:transition="(this.placement === 'left') ? 'slideleft' : 'slideright'">
<div class="{{prefixCls}}-aside-dialog">
<div class="{{prefixCls}}-aside-content">
<div class="{{prefixCls}}-aside-header">
<button type="button" class="{{prefixCls}}-close" @click='close'><span>×</span></button>
<h4 class="{{prefixCls}}-aside-title">{{header}}</h4>
</div>
<div class="{{prefixCls}}-aside-body">
<slot></slot>
</div>
</div>
</div>
</div>
</template>
<script>
import EventListener from './utils/EventListener'
import getScrollBarWidth from './utils/getScrollBarWidth'
import type from './utils/type'
import element from './utils/element'
export default {
props: {
show: {
type: Boolean,
require: true,
twoWay: true
},
placement: {
type: String,
default: 'right'
},
header: {
type: String
},
width: {
type: String,
default: '320px'
},
onShow: {
type: Function
},
onHide: {
type: Function
},
prefixCls: {
type: String,
default: 'n3'
}
},
computed: {
classObj () {
let {prefixCls, placement} = this
let klass = {}
klass[prefixCls + '-aside'] = true
klass[prefixCls + '-aside-left'] = placement === 'left'
klass[prefixCls + '-aside-right'] = placement === 'right'
return klass
}
},
watch: {
show (val) {
let backdrop = document.createElement('div')
let prefixCls = this.prefixCls
const body = document.body
backdrop.className = prefixCls + '-aside-backdrop'
const scrollBarWidth = getScrollBarWidth()
if (val) {
body.appendChild(backdrop)
element.addClass(body, prefixCls + '-modal-open')
if (scrollBarWidth !== 0) {
body.style.paddingRight = scrollBarWidth + 'px'
}
backdrop.className += ' ' + prefixCls + '-aside-in'
this._clickEvent = EventListener.listen(backdrop, 'click', this.close)
if (type.isFunction(this.onShow)) {
this.onShow()
}
} else {
if (this._clickEvent) this._clickEvent.remove()
backdrop = document.querySelector('.' + prefixCls + '-aside-backdrop')
backdrop.className = prefixCls + '-aside-backdrop'
setTimeout(() => {
element.removeClass(body, prefixCls + '-modal-open')
body.style.paddingRight = '0'
body.removeChild(backdrop)
}, 300)
if (type.isFunction(this.onHide)) {
this.onHide()
}
}
}
},
methods: {
close () {
this.show = false
}
}
}
</script>