index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <v-app>
  3. <v-app-bar
  4. app
  5. color="blue"
  6. dark
  7. >
  8. <v-container class="py-0 fill-height">
  9. <v-toolbar-title
  10. class="hidden-sm-and-down ml-0 pl-4"
  11. style="width: 150px"
  12. >
  13. <span style="cursor:pointer" @click="goToHome()">{{ this.$store.state.webInfo.name }}</span>
  14. </v-toolbar-title>
  15. <router-link v-for="item in items" :key="item.text" :to="item.link">
  16. <v-list-item
  17. link
  18. >
  19. <v-list-item-action>
  20. <v-icon>{{ item.icon }}</v-icon>
  21. </v-list-item-action>
  22. <v-list-item-content>
  23. <v-list-item-title>
  24. {{ item.text }}
  25. </v-list-item-title>
  26. </v-list-item-content>
  27. </v-list-item>
  28. </router-link>
  29. <v-spacer />
  30. <SearchInput />
  31. <v-spacer />
  32. <v-tooltip bottom>
  33. <template v-slot:activator="{ on, attrs }">
  34. <v-btn
  35. icon
  36. v-bind="attrs"
  37. v-on="on"
  38. @click="goToPublish"
  39. >
  40. <v-icon>mdi-video-plus</v-icon>
  41. </v-btn>
  42. </template>
  43. <span>发布</span>
  44. </v-tooltip>
  45. <v-tooltip bottom>
  46. <template v-slot:activator="{ on, attrs }">
  47. <v-btn
  48. icon
  49. v-bind="attrs"
  50. v-on="on"
  51. @click="goToMessage"
  52. >
  53. <v-icon>mdi-bell</v-icon>
  54. </v-btn>
  55. </template>
  56. <span>通知</span>
  57. </v-tooltip>
  58. <Head v-if="this.$store.state.user.userInfo" />
  59. <!-- 未登录 -->
  60. <v-btn
  61. v-if="this.$store.state.user.userInfo == null"
  62. outlined
  63. @click="goToLoginPage"
  64. >
  65. <v-icon left dark>mdi-account</v-icon> 登录
  66. </v-btn>
  67. </v-container>
  68. </v-app-bar>
  69. <v-main>
  70. <v-container>
  71. <!--根据 router/index.js 中的路由渲染页面-->
  72. <router-view />
  73. </v-container>
  74. </v-main>
  75. <!--
  76. <v-footer app>
  77. <v-col
  78. class="text-center"
  79. cols="12"
  80. >
  81. {{ new Date().getFullYear() }} — <strong>Vuetify</strong>
  82. </v-col>
  83. </v-footer>-->
  84. </v-app>
  85. </template>
  86. <script>
  87. import Head from '@/layout/components/head.vue'
  88. import SearchInput from '@/layout/components/search-input.vue'
  89. export default {
  90. components: {
  91. Head,
  92. SearchInput
  93. },
  94. data: () => ({
  95. userInfo: {},
  96. drawer: true,
  97. keyword: '',
  98. items: [
  99. { icon: 'mdi-youtube-subscription', text: '直播', link: '/live' },
  100. { icon: 'mdi-trending-up', text: '微博', link: '/mblog' },
  101. { icon: 'mdi-trending-up', text: '知乎', link: '/zhihu' }
  102. ],
  103. links: [
  104. '直播',
  105. '微博',
  106. '知乎'
  107. ]
  108. /*,
  109. headItem: [
  110. { icon: 'mdi-head', text: '个人中心', link: '/user/:userId', id: 0 },
  111. { icon: 'mdi-wrench', text: '创作中心', link: '/studio', id: 1 },
  112. { icon: 'mdi-logout', text: '退出', link: '/logout', id: 2 }
  113. ]*/
  114. }),
  115. mounted() {
  116. },
  117. created() {
  118. this.userInfo = this.$store.state.user.userInfo
  119. this.$vuetify.theme.dark = this.$store.state.darkThemOpen
  120. },
  121. methods: {
  122. goToLink() {
  123. console.log('跳转到页面')
  124. // this.$router.push('/studio1')
  125. },
  126. /* headClick(value) {
  127. if (value === 0) {
  128. this.$router.push('/user/' + this.userInfo.userId)
  129. } else if (value === 1) {
  130. this.$router.push('/studio')
  131. } else {
  132. this.logout()
  133. }
  134. },*/
  135. logout() {
  136. // 调用 store/modules/user.js 中的 login 方法
  137. this.$store.dispatch('user/logout').then(() => {
  138. if (this.$route.path === '/') {
  139. location.reload()
  140. } else {
  141. this.$router.push('/')
  142. }
  143. }).catch(() => {
  144. console.log('用户登录失败')
  145. })
  146. },
  147. goToLoginPage() {
  148. this.$router.push('/login')
  149. },
  150. goToMessage() {
  151. this.$router.push('/message')
  152. },
  153. goToPublish() {
  154. this.$router.push('/studio/upload')
  155. },
  156. goToHome() {
  157. if (this.$route.path === '/') {
  158. return
  159. }
  160. this.$router.push('/')
  161. },
  162. goToUserHome() {
  163. if (this.$route.path === '/user/' + this.$store.state.user.userInfo.userId) {
  164. return
  165. }
  166. this.$router.push('/user/' + this.$store.state.user.userInfo.userId)
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped>
  172. a {
  173. text-decoration: none;
  174. }
  175. </style>