|
| 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> |
0 commit comments