init right-panel

This commit is contained in:
Pan 2019-03-13 18:23:06 +08:00
parent 537ecf9990
commit fd550545af
4 changed files with 165 additions and 7 deletions

View File

@ -0,0 +1,141 @@
<template>
<div ref="rightPanel" :class="{show:show}" class="rightPanel-container">
<div class="rightPanel-background" />
<div class="rightPanel">
<div class="handle-button" type="primary" circle @click="show=!show">
<i :class="show?'el-icon-close':'el-icon-setting'" />
</div>
<div class="rightPanel-items">
<slot />
</div>
</div>
</div>
</template>
<script>
import { addClass, removeClass } from '@/utils'
export default {
name: 'RightPanel',
props: {
value: {
default: false,
type: Boolean
},
clickNotClose: {
default: false,
type: Boolean
}
},
data() {
return {
show: false
}
},
watch: {
show(value) {
if (value && !this.clickNotClose) {
this.addEventClick()
}
if (value) {
addClass(document.body, 'showRightPanel')
} else {
removeClass(document.body, 'showRightPanel')
}
}
},
mounted() {
this.insertToBody()
},
methods: {
addEventClick() {
window.addEventListener('click', this.closeSidebar)
},
closeSidebar(evt) {
const parent = evt.target.closest('.rightPanel')
if (!parent) {
this.show = false
window.removeEventListener('click', this.closeSidebar)
}
},
insertToBody() {
const elx = this.$refs.rightPanel
const body = document.querySelector('body')
body.insertBefore(elx, body.firstChild)
}
}
}
</script>
<style>
.showRightPanel {
overflow: hidden;
position: relative;
width: calc(100% - 15px);
}
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
.rightPanel-background {
opacity: 0;
transition: opacity .3s ease;
background: rgba(0, 0, 0, .2);
width: 0;
height: 0;
position: fixed;
z-index: -1;
}
.rightPanel {
background: rgb(255, 255, 255);
z-index: 3000;
position: fixed;
height: 100vh;
width: 100%;
max-width: 260px;
top: 0px;
box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05);
left: 0px;
transition: all .25s ease;
transform: translate(100%);
z-index: 40000;
left: auto;
right: 0px;
}
.show {
transition: all .25s ease;
.rightPanel-background {
z-index: 20000;
opacity: 1;
width: 100%;
height: 100%;
}
.rightPanel {
transform: translate(0);
}
}
.handle-button {
position: absolute;
left: -48px;
border-radius: 4px 0 0 4px !important;
top: 240px;
width: 48px;
height: 48px;
background: #1890ff;
cursor: pointer;
pointer-events: auto;
z-index: 0;
text-align: center;
color: #fff;
line-height: 48px;
i {
font-size: 24px;
line-height: 48px;
}
}
</style>

View File

@ -6,17 +6,21 @@
<navbar />
<tags-view />
<app-main />
<right-panel v-if="showSettings" />
</div>
</div>
</template>
<script>
import RightPanel from '@/components/RightPanel'
import { Navbar, Sidebar, AppMain, TagsView } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import { mapState } from 'vuex'
export default {
name: 'Layout',
components: {
RightPanel,
Navbar,
Sidebar,
AppMain,
@ -24,12 +28,11 @@ export default {
},
mixins: [ResizeMixin],
computed: {
sidebar() {
return this.$store.state.app.sidebar
},
device() {
return this.$store.state.app.device
},
...mapState({
sidebar: state => state.app.sidebar,
device: state => state.app.device,
showSettings: state => state.app.showSettings
}),
classObj() {
return {
hideSidebar: !this.sidebar.opened,

View File

@ -8,7 +8,8 @@ const app = {
},
device: 'desktop',
language: Cookies.get('language') || 'en',
size: Cookies.get('size') || 'medium'
size: Cookies.get('size') || 'medium',
showSettings: true
},
mutations: {
TOGGLE_SIDEBAR: state => {

View File

@ -299,3 +299,16 @@ export function createUniqueString() {
const randomNum = parseInt((1 + Math.random()) * 65536) + ''
return (+(randomNum + timestamp)).toString(32)
}
export function hasClass(ele, cls) {
return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
}
export function addClass(ele, cls) {
if (!hasClass(ele, cls)) ele.className += ' ' + cls
}
export function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
ele.className = ele.className.replace(reg, ' ')
}
}