UserHomeLayout.vue 3.8 KB

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