提交 | 用户 | age
|
2a61f6
|
1 |
<template> |
L |
2 |
<div ref="rightPanel" :class="{show:show}" class="rightPanel-container"> |
|
3 |
<div class="rightPanel-background" /> |
|
4 |
<div class="rightPanel"> |
|
5 |
<div class="handle-button" :style="{'top':buttonTop+'px','background-color':theme}" @click="show=!show"> |
|
6 |
<i :class="show?'el-icon-close':'el-icon-setting'" /> |
|
7 |
</div> |
|
8 |
<div class="rightPanel-items"> |
|
9 |
<slot /> |
|
10 |
</div> |
|
11 |
</div> |
|
12 |
</div> |
|
13 |
</template> |
|
14 |
|
|
15 |
<script> |
|
16 |
|
|
17 |
export default { |
|
18 |
name: 'RightPanel', |
|
19 |
props: { |
|
20 |
clickNotClose: { |
|
21 |
default: false, |
|
22 |
type: Boolean |
|
23 |
}, |
|
24 |
buttonTop: { |
|
25 |
default: 250, |
|
26 |
type: Number |
|
27 |
} |
|
28 |
}, |
|
29 |
data() { |
|
30 |
return { |
|
31 |
show: false |
|
32 |
} |
|
33 |
}, |
|
34 |
computed: { |
|
35 |
theme() { |
|
36 |
return this.$store.state.settings.theme |
|
37 |
} |
|
38 |
}, |
|
39 |
watch: { |
|
40 |
show(value) { |
|
41 |
if (value && !this.clickNotClose) { |
|
42 |
this.addEventClick() |
|
43 |
} |
|
44 |
} |
|
45 |
}, |
|
46 |
mounted() { |
|
47 |
this.insertToBody() |
|
48 |
}, |
|
49 |
beforeDestroy() { |
|
50 |
const elx = this.$refs.rightPanel |
|
51 |
elx.remove() |
|
52 |
}, |
|
53 |
methods: { |
|
54 |
addEventClick() { |
|
55 |
window.addEventListener('click', this.closeSidebar) |
|
56 |
}, |
|
57 |
closeSidebar(evt) { |
|
58 |
const parent = evt.target.closest('.rightPanel') |
|
59 |
if (!parent) { |
|
60 |
this.show = false |
|
61 |
window.removeEventListener('click', this.closeSidebar) |
|
62 |
} |
|
63 |
}, |
|
64 |
insertToBody() { |
|
65 |
const elx = this.$refs.rightPanel |
|
66 |
const body = document.querySelector('body') |
|
67 |
body.insertBefore(elx, body.firstChild) |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
</script> |
|
72 |
|
|
73 |
<style> |
|
74 |
.showRightPanel { |
|
75 |
overflow: hidden; |
|
76 |
position: relative; |
|
77 |
width: calc(100% - 15px); |
|
78 |
} |
|
79 |
</style> |
|
80 |
|
|
81 |
<style lang="scss" scoped> |
|
82 |
.rightPanel-background { |
|
83 |
position: fixed; |
|
84 |
top: 0; |
|
85 |
left: 0; |
|
86 |
opacity: 0; |
|
87 |
transition: opacity .3s cubic-bezier(.7, .3, .1, 1); |
|
88 |
background: rgba(0, 0, 0, .2); |
|
89 |
z-index: -1; |
|
90 |
} |
|
91 |
|
|
92 |
.rightPanel { |
|
93 |
width: 100%; |
|
94 |
max-width: 260px; |
|
95 |
height: 100vh; |
|
96 |
position: fixed; |
|
97 |
top: 0; |
|
98 |
right: 0; |
|
99 |
box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05); |
|
100 |
transition: all .25s cubic-bezier(.7, .3, .1, 1); |
|
101 |
transform: translate(100%); |
|
102 |
background: #fff; |
|
103 |
z-index: 40000; |
|
104 |
} |
|
105 |
|
|
106 |
.show { |
|
107 |
transition: all .3s cubic-bezier(.7, .3, .1, 1); |
|
108 |
|
|
109 |
.rightPanel-background { |
|
110 |
z-index: 20000; |
|
111 |
opacity: 1; |
|
112 |
width: 100%; |
|
113 |
height: 100%; |
|
114 |
} |
|
115 |
|
|
116 |
.rightPanel { |
|
117 |
transform: translate(0); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
.handle-button { |
|
122 |
width: 48px; |
|
123 |
height: 48px; |
|
124 |
position: absolute; |
|
125 |
left: -48px; |
|
126 |
text-align: center; |
|
127 |
font-size: 24px; |
|
128 |
border-radius: 6px 0 0 6px !important; |
|
129 |
z-index: 0; |
|
130 |
pointer-events: auto; |
|
131 |
cursor: pointer; |
|
132 |
color: #fff; |
|
133 |
line-height: 48px; |
|
134 |
i { |
|
135 |
font-size: 24px; |
|
136 |
line-height: 48px; |
|
137 |
} |
|
138 |
} |
|
139 |
</style> |