RightFrame.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <script lang="ts" setup>
  2. import {computed, ref, useSlots, watch} from 'vue'
  3. import convert from '@/assets/svg/convert.svg'
  4. // const emit = defineEmits(['update:useLeftSidebar'])
  5. const slots = useSlots()
  6. let sidebarWidth = ref(window.innerWidth * 0.22)
  7. let leftSidebarShow = ref(true)
  8. const leftSidebarStyle = computed(() => {
  9. return {
  10. transform: leftSidebarShow.value ? 'translateX(0px)' : `translateX(-${sidebarWidth.value}px)`,
  11. width: `${sidebarWidth.value}px`,
  12. }
  13. })
  14. let rightSidebarShow = ref(true)
  15. const rightSidebarStyle = computed(() => {
  16. return {
  17. transform: rightSidebarShow.value ? 'translateX(0px)' : `translateX(${sidebarWidth.value}px)`,
  18. width: `${sidebarWidth.value}px`,
  19. }
  20. })
  21. function convertSidebar(modelName) {
  22. if (modelName === 'left') {
  23. debugger
  24. leftSidebarShow.value = !leftSidebarShow.value
  25. } else {
  26. rightSidebarShow.value = !rightSidebarShow.value
  27. }
  28. }
  29. watch(
  30. () => slots.leftModule,
  31. (val): void => {
  32. if (!val) {
  33. leftSidebarShow.value = false
  34. }
  35. },
  36. )
  37. watch(
  38. () => slots.rightModule,
  39. (val): void => {
  40. if (!val) {
  41. rightSidebarShow.value = false
  42. }
  43. },
  44. )
  45. </script>
  46. <template>
  47. <div class="right-frame">
  48. <div v-if="slots.leftModule" :style="leftSidebarStyle" class="gw-sidebar-left">
  49. <div class="gw-sidebar-container">
  50. <slot name="leftModule"></slot>
  51. </div>
  52. <div class="gw-sidebar-btn left-btn" @click="convertSidebar('left')">
  53. <icon :data="convert"/>
  54. </div>
  55. </div>
  56. <div :style="rightSidebarStyle" class="gw-sidebar-right">
  57. <div v-if="slots.rightModule" class="gw-sidebar-container">
  58. <slot name="rightModule"></slot>
  59. </div>
  60. <div v-if="slots.rightModule" class="gw-sidebar-btn right-btn" @click="convertSidebar('right')">
  61. <icon :data="convert"/>
  62. </div>
  63. <div v-if="slots.btnGroup" ref="rightTopBtn" class="right-top-btn">
  64. <slot name="btnGroup"></slot>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <style lang="scss" scoped>
  70. .right-frame {
  71. position: relative;
  72. height: 100%;
  73. padding: 0 0.7rem 0.7rem 0.7rem;
  74. .right-top-btn {
  75. pointer-events: auto;
  76. position: absolute;
  77. top: 0;
  78. right: calc(23vw + 2rem);
  79. display: flex;
  80. flex-direction: column;
  81. font-size: 1.2rem;
  82. button {
  83. font-size: 1.2rem;
  84. }
  85. .transition-box {
  86. padding: 0.7rem;
  87. margin-bottom: 0.35rem;
  88. border-radius: 4px;
  89. background-color: #409eff;
  90. text-align: center;
  91. color: #fff;
  92. box-sizing: border-box;
  93. }
  94. }
  95. .gw-sidebar-left,
  96. .gw-sidebar-right {
  97. pointer-events: auto;
  98. position: relative;
  99. transition: 0.3s;
  100. // transition: all 1s;
  101. height: calc(100%);
  102. min-width: 300px;
  103. &:hover .gw-sidebar-btn {
  104. display: flex;
  105. }
  106. .gw-sidebar-container {
  107. display: flex;
  108. flex-direction: column;
  109. width: 100%;
  110. height: 100%;
  111. }
  112. .gw-sidebar-btn {
  113. top: 10px;
  114. position: absolute;
  115. cursor: pointer;
  116. background-color: #2e6ca6;
  117. height: 40px;
  118. width: 40px;
  119. display: none;
  120. justify-content: center;
  121. align-items: center;
  122. &.left-btn {
  123. right: -40px;
  124. border-radius: 0 20px 20px 0;
  125. }
  126. &.right-btn {
  127. left: -40px;
  128. border-radius: 20px 0 0 20px;
  129. }
  130. svg {
  131. fill: #fff;
  132. height: 12px;
  133. width: 12px;
  134. }
  135. }
  136. }
  137. .gw-sidebar-left {
  138. float: left;
  139. }
  140. .gw-sidebar-right {
  141. float: right;
  142. }
  143. }
  144. </style>