index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div ref="rightPanel" class="rightPanel-container">
  3. <div class="rightPanel-background" />
  4. <div class="rightPanel">
  5. <div class="rightPanel-items">
  6. <slot />
  7. </div>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'RightPanel',
  14. props: {
  15. clickNotClose: {
  16. default: false,
  17. type: Boolean
  18. }
  19. },
  20. computed: {
  21. show: {
  22. get() {
  23. return this.$store.state.settings.showSettings
  24. },
  25. set(val) {
  26. this.$store.dispatch('settings/changeSetting', {
  27. key: 'showSettings',
  28. value: val
  29. })
  30. }
  31. }
  32. },
  33. watch: {
  34. show(value) {
  35. if (value && !this.clickNotClose) {
  36. this.addEventClick()
  37. }
  38. }
  39. },
  40. mounted() {
  41. this.addEventClick()
  42. },
  43. beforeDestroy() {
  44. const elx = this.$refs.rightPanel
  45. elx.remove()
  46. },
  47. methods: {
  48. addEventClick() {
  49. window.addEventListener('click', this.closeSidebar)
  50. },
  51. closeSidebar(evt) {
  52. const parent = evt.target.closest('.el-drawer__body')
  53. if (!parent) {
  54. this.show = false
  55. window.removeEventListener('click', this.closeSidebar)
  56. }
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. .rightPanel-background {
  63. position: fixed;
  64. top: 0;
  65. left: 0;
  66. opacity: 0;
  67. transition: opacity .3s cubic-bezier(.7, .3, .1, 1);
  68. background: rgba(0, 0, 0, .2);
  69. z-index: -1;
  70. }
  71. .rightPanel {
  72. width: 100%;
  73. max-width: 260px;
  74. height: 100vh;
  75. position: fixed;
  76. top: 0;
  77. right: 0;
  78. box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05);
  79. transition: all .25s cubic-bezier(.7, .3, .1, 1);
  80. transform: translate(100%);
  81. background: #fff;
  82. z-index: 40000;
  83. }
  84. .handle-button {
  85. width: 48px;
  86. height: 48px;
  87. position: absolute;
  88. left: -48px;
  89. text-align: center;
  90. font-size: 24px;
  91. border-radius: 6px 0 0 6px !important;
  92. z-index: 0;
  93. pointer-events: auto;
  94. cursor: pointer;
  95. color: #fff;
  96. line-height: 48px;
  97. i {
  98. font-size: 24px;
  99. line-height: 48px;
  100. }
  101. }
  102. </style>