index.vue 4.2 KB

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