index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.insertToBody()
  42. this.addEventClick()
  43. },
  44. beforeDestroy() {
  45. const elx = this.$refs.rightPanel
  46. elx.remove()
  47. },
  48. methods: {
  49. addEventClick() {
  50. window.addEventListener('click', this.closeSidebar)
  51. },
  52. closeSidebar(evt) {
  53. const parent = evt.target.closest('.el-drawer__body')
  54. if (!parent) {
  55. this.show = false
  56. window.removeEventListener('click', this.closeSidebar)
  57. }
  58. },
  59. insertToBody() {
  60. const elx = this.$refs.rightPanel
  61. const body = document.querySelector('body')
  62. body.insertBefore(elx, body.firstChild)
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. .rightPanel-background {
  69. position: fixed;
  70. top: 0;
  71. left: 0;
  72. opacity: 0;
  73. transition: opacity .3s cubic-bezier(.7, .3, .1, 1);
  74. background: rgba(0, 0, 0, .2);
  75. z-index: -1;
  76. }
  77. .rightPanel {
  78. width: 100%;
  79. max-width: 260px;
  80. height: 100vh;
  81. position: fixed;
  82. top: 0;
  83. right: 0;
  84. box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05);
  85. transition: all .25s cubic-bezier(.7, .3, .1, 1);
  86. transform: translate(100%);
  87. background: #fff;
  88. z-index: 40000;
  89. }
  90. .handle-button {
  91. width: 48px;
  92. height: 48px;
  93. position: absolute;
  94. left: -48px;
  95. text-align: center;
  96. font-size: 24px;
  97. border-radius: 6px 0 0 6px !important;
  98. z-index: 0;
  99. pointer-events: auto;
  100. cursor: pointer;
  101. color: #fff;
  102. line-height: 48px;
  103. i {
  104. font-size: 24px;
  105. line-height: 48px;
  106. }
  107. }
  108. </style>