Skip to content

Commit 18048d2

Browse files
committed
init
1 parent 24783ac commit 18048d2

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

src/components/SidePanel/index.vue

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<template>
2+
<transition name="rightPanel-animate">
3+
4+
<div
5+
v-show="value"
6+
ref="rightPanel"
7+
class="vs-content-sidebar">
8+
<div class="rightPanel-background"/>
9+
<div
10+
:class="[`vs-sidebar-${color}`]"
11+
class="vs-sidebar">
12+
<div class="vs-sidebar-items">
13+
<slot/>
14+
</div>
15+
</div>
16+
</div>
17+
<!-- <el-button type="primary" icon="el-icon-setting" circle/> -->
18+
19+
</transition>
20+
</template>
21+
22+
<script>
23+
export default {
24+
name: 'RightPanel',
25+
props: {
26+
value: {
27+
default: false,
28+
type: Boolean
29+
},
30+
color: {
31+
default: 'primary',
32+
type: String
33+
},
34+
clickNotClose: {
35+
default: false,
36+
type: Boolean
37+
}
38+
},
39+
watch: {
40+
value() {
41+
if (this.value && !this.clickNotClose) {
42+
this.addEventClick()
43+
}
44+
}
45+
},
46+
mounted() {
47+
this.insertBody()
48+
},
49+
methods: {
50+
addEventClick() {
51+
window.addEventListener('click', this.closeSidebar)
52+
},
53+
closeSidebar(evt) {
54+
const parent = evt.target.closest('.vs-sidebar')
55+
if (!parent) {
56+
this.$emit('input', false)
57+
window.removeEventListener('click', this.closeSidebar)
58+
}
59+
},
60+
insertBody() {
61+
const elx = this.$refs.rightPanel
62+
const body = document.querySelector('body')
63+
body.insertBefore(elx, body.firstChild)
64+
}
65+
}
66+
}
67+
</script>
68+
69+
<style rel="stylesheet/scss" lang="scss" >
70+
.rightPanel-background {
71+
background: rgba(0, 0, 0, .2);
72+
width: 100%;
73+
height: 100%;
74+
position: fixed;
75+
z-index: 20000;
76+
transition: all .3s ease;
77+
opacity: 1;
78+
}
79+
80+
.vs-sidebar{
81+
background: rgb(255,255,255);
82+
z-index :3000;
83+
position: fixed;
84+
height: 100vh;
85+
width: 100%;
86+
max-width: 260px;
87+
top: 0px;
88+
display: flex;
89+
flex-direction: column;
90+
box-shadow: 0px 0px 15px 0px rgba(0,0,0,.05);
91+
left: 0px;
92+
transition: all .25s ease;
93+
z-index: 40000;
94+
left: auto;
95+
right: 0px;
96+
97+
}
98+
99+
// animations
100+
.rightPanel-animate-enter-active,
101+
.rightPanel-animate-leave-active {
102+
transition: all .25s ease;
103+
.vs-sidebar {
104+
transition: all .25s ease;
105+
106+
}
107+
}
108+
109+
.rightPanel-animate-enter,
110+
.rightPanel-animate-leave-to {
111+
.vs-sidebar-background {
112+
opacity: 0 !important;
113+
}
114+
.vs-sidebar {
115+
transform: translate(100%);
116+
}
117+
}
118+
119+
</style>

src/views/layout/Layout.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
<div :class="{hasTagsView:needTagsView}" class="main-container">
66
<navbar/>
77
<tags-view v-if="needTagsView"/>
8+
9+
<div @click="active=!active">点我</div>
810
<app-main/>
11+
<side-panel v-model="active">
12+
apple
13+
</side-panel>
14+
915
</div>
1016
</div>
1117
</template>
1218

1319
<script>
1420
import { Navbar, Sidebar, AppMain, TagsView } from './components'
21+
import SidePanel from '@/components/SidePanel'
1522
import ResizeMixin from './mixin/ResizeHandler'
1623
1724
export default {
@@ -20,9 +27,15 @@ export default {
2027
Navbar,
2128
Sidebar,
2229
AppMain,
23-
TagsView
30+
TagsView,
31+
SidePanel
2432
},
2533
mixins: [ResizeMixin],
34+
data() {
35+
return {
36+
active: false
37+
}
38+
},
2639
computed: {
2740
sidebar() {
2841
return this.$store.state.app.sidebar

0 commit comments

Comments
 (0)