UserHomeLayout.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="user-home-layout">
  3. <div class="main-container">
  4. <div class="menu-container-large">
  5. <template v-for="tab of tabs">
  6. <icon-button
  7. :size="50"
  8. :theme="currentRouteName.match(tab.name) ? 'blue' : ''"
  9. :key="tab.name"
  10. @click="handleIconButtonClick(tab.name)"
  11. :title="tab.title"
  12. >
  13. {{tab.icon}}
  14. </icon-button>
  15. </template>
  16. </div>
  17. <div class="tab-container">
  18. <slide-in-transition>
  19. <router-view/>
  20. </slide-in-transition>
  21. </div>
  22. </div>
  23. <div class="menu-container-small">
  24. <template v-for="tab of tabs">
  25. <icon-button
  26. :size="50"
  27. :theme="currentRouteName.match(tab.name) ? 'blue' : ''"
  28. :key="tab.name"
  29. @click="handleIconButtonClick(tab.name)"
  30. >
  31. {{tab.icon}}
  32. </icon-button>
  33. </template>
  34. </div>
  35. <c-button class="exit" text @click="handleLogout" icon="exit_to_app">注销</c-button>
  36. </div>
  37. </template>
  38. <script>
  39. import IconButton from '@/components/Basic/IconButton'
  40. import { logout } from '@/server/user'
  41. import SlideInTransition from '@/animations/SlideInSameTransition'
  42. import CButton from '@/components/Basic/CButton'
  43. export default {
  44. components: { CButton, IconButton, SlideInTransition },
  45. props: ['tabs', 'role'],
  46. data () {
  47. return {
  48. currentRouteName: this.$route.name
  49. }
  50. },
  51. mounted () {
  52. this.resizeHandler()
  53. window.addEventListener('resize', this.resizeHandler)
  54. },
  55. destroyed () {
  56. window.removeEventListener('resize', this.resizeHandler)
  57. },
  58. watch: {
  59. $route () {
  60. this.currentRouteName = this.$route.path
  61. }
  62. },
  63. methods: {
  64. resizeHandler () {
  65. if (window.innerWidth < 900) {
  66. this.componentType = 'full-screen-component'
  67. } else {
  68. this.componentType = 'tab-side-component'
  69. }
  70. },
  71. handleIconButtonClick (name) {
  72. this.$router.push(`/${this.role}/${name}`)
  73. },
  74. handleLogout () {
  75. logout()
  76. this.$setSuccessMessage('您已退出登录')
  77. this.$router.push({ name: 'login' })
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. @import '~@/style/theme.scss';
  84. .user-home-layout {
  85. height: 100vh;
  86. width: 100%;
  87. display: flex;
  88. align-items: center;
  89. justify-content: center;
  90. }
  91. .main-container {
  92. display: flex;
  93. width: 100%;
  94. margin: 0 auto;
  95. justify-content: center;
  96. }
  97. .tab-container {
  98. overflow: hidden;
  99. transition: width .2s;
  100. }
  101. // 大屏幕情况
  102. @media (min-width: 600px) {
  103. .menu-container-large {
  104. padding: 24px 18px;
  105. display: flex;
  106. flex-direction: column;
  107. justify-content: center;
  108. .icon-button {
  109. margin: 16px 0;
  110. }
  111. }
  112. .tab-container {
  113. display: flex;
  114. max-width: 800px;
  115. }
  116. .menu-container-small {
  117. display: none;
  118. }
  119. }
  120. // 小屏幕情况
  121. @media (max-width: 599px) {
  122. .menu-container-large {
  123. display: none;
  124. }
  125. .tab-container {
  126. box-sizing: border-box;
  127. height: calc(100vh - 54px);
  128. width: 100%;
  129. flex: 1;
  130. }
  131. .user-home-layout {
  132. justify-content: unset;
  133. min-height: calc(100vh - 54px);
  134. }
  135. .menu-container-small {
  136. z-index: 10;
  137. backdrop-filter: saturate(180%) blur(15px);
  138. background: rgba(255, 255, 255, 0.8);
  139. width: 100%;
  140. position: fixed;
  141. padding: 12px 0;
  142. height: 54px;
  143. box-sizing: border-box;
  144. bottom: 0;
  145. display: flex;
  146. align-items: center;
  147. justify-content: space-around;
  148. }
  149. .tab {
  150. min-width: unset;
  151. padding: unset;
  152. }
  153. }
  154. .exit {
  155. z-index: 4;
  156. cursor: pointer;
  157. position: absolute;
  158. top: 10px;
  159. right: 10px;
  160. display: flex;
  161. align-items: center;
  162. color: #6a7a8a;
  163. }
  164. @supports (not(backdrop-filter: saturate(180%) blur(15px))) {
  165. .menu-container-small {
  166. background: rgb(255, 255, 255);
  167. }
  168. }
  169. </style>