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