index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. >
  52. <v-icon>mdi-bell</v-icon>
  53. </v-btn>
  54. </template>
  55. <span>通知</span>
  56. </v-tooltip>
  57. <Head v-if="this.$store.state.user.userInfo" />
  58. <!-- 未登录 -->
  59. <v-btn
  60. v-if="this.$store.state.user.userInfo == null"
  61. outlined
  62. @click="goToLoginPage"
  63. >
  64. <v-icon left dark>mdi-account</v-icon> 登录
  65. </v-btn>
  66. </v-container>
  67. </v-app-bar>
  68. <v-main>
  69. <v-container>
  70. <!--根据 router/index.js 中的路由渲染页面-->
  71. <router-view />
  72. </v-container>
  73. </v-main>
  74. <!--
  75. <v-footer app>
  76. <v-col
  77. class="text-center"
  78. cols="12"
  79. >
  80. {{ new Date().getFullYear() }} — <strong>Vuetify</strong>
  81. </v-col>
  82. </v-footer>-->
  83. </v-app>
  84. </template>
  85. <script>
  86. import Head from '@/layout/components/head.vue'
  87. import SearchInput from '@/layout/components/search-input.vue'
  88. export default {
  89. components: {
  90. Head,
  91. SearchInput
  92. },
  93. data: () => ({
  94. userInfo: {},
  95. drawer: true,
  96. keyword: '',
  97. items: [
  98. { icon: 'mdi-youtube-subscription', text: '直播', link: '/live' },
  99. { icon: 'mdi-trending-up', text: '微博', link: '/mblog' },
  100. { icon: 'mdi-trending-up', text: '知乎', link: '/zhihu' }
  101. ],
  102. links: [
  103. '直播',
  104. '微博',
  105. '知乎'
  106. ]
  107. /*,
  108. headItem: [
  109. { icon: 'mdi-head', text: '个人中心', link: '/user/:userId', id: 0 },
  110. { icon: 'mdi-wrench', text: '创作中心', link: '/studio', id: 1 },
  111. { icon: 'mdi-logout', text: '退出', link: '/logout', id: 2 }
  112. ]*/
  113. }),
  114. mounted() {
  115. },
  116. created() {
  117. this.userInfo = this.$store.state.user.userInfo
  118. this.$vuetify.theme.dark = this.$store.state.darkThemOpen
  119. },
  120. methods: {
  121. goToLink() {
  122. console.log('跳转到页面')
  123. // this.$router.push('/studio1')
  124. },
  125. /* headClick(value) {
  126. if (value === 0) {
  127. this.$router.push('/user/' + this.userInfo.userId)
  128. } else if (value === 1) {
  129. this.$router.push('/studio')
  130. } else {
  131. this.logout()
  132. }
  133. },*/
  134. logout() {
  135. // 调用 store/modules/user.js 中的 login 方法
  136. this.$store.dispatch('user/logout').then(() => {
  137. if (this.$route.path === '/') {
  138. location.reload()
  139. } else {
  140. this.$router.push('/')
  141. }
  142. }).catch(() => {
  143. console.log('用户登录失败')
  144. })
  145. },
  146. goToLoginPage() {
  147. this.$router.push('/login')
  148. },
  149. goToPublish() {
  150. this.$router.push('/studio/upload')
  151. },
  152. goToHome() {
  153. if (this.$route.path === '/') {
  154. return
  155. }
  156. this.$router.push('/')
  157. },
  158. goToUserHome() {
  159. if (this.$route.path === '/user/' + this.$store.state.user.userInfo.userId) {
  160. return
  161. }
  162. this.$router.push('/user/' + this.$store.state.user.userInfo.userId)
  163. }
  164. }
  165. }
  166. </script>
  167. <style scoped>
  168. a {
  169. text-decoration: none;
  170. }
  171. </style>