index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. <v-text-field
  37. v-model="keyword"
  38. flat
  39. solo-inverted
  40. hide-details
  41. prepend-inner-icon="mdi-magnify"
  42. label="搜索"
  43. />
  44. <v-spacer />
  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="goToPublish"
  52. >
  53. <v-icon>mdi-video-plus</v-icon>
  54. </v-btn>
  55. </template>
  56. <span>发布</span>
  57. </v-tooltip>
  58. <v-tooltip bottom>
  59. <template v-slot:activator="{ on, attrs }">
  60. <v-btn
  61. icon
  62. v-bind="attrs"
  63. v-on="on"
  64. >
  65. <v-icon>mdi-bell</v-icon>
  66. </v-btn>
  67. </template>
  68. <span>通知</span>
  69. </v-tooltip>
  70. <Head v-if="this.$store.state.user.userInfo" />
  71. <!-- 未登录 -->
  72. <v-btn
  73. v-if="this.$store.state.user.userInfo == null"
  74. outlined
  75. @click="goToLoginPage"
  76. >
  77. <v-icon left dark>mdi-account</v-icon> 登录
  78. </v-btn>
  79. </v-app-bar>
  80. <v-main>
  81. <router-view />
  82. </v-main>
  83. <!--
  84. <v-footer app>
  85. <v-col
  86. class="text-center"
  87. cols="12"
  88. >
  89. {{ new Date().getFullYear() }} — <strong>Vuetify</strong>
  90. </v-col>
  91. </v-footer>-->
  92. </div>
  93. </template>
  94. <script>
  95. import Head from '@/layout/components/head.vue'
  96. export default {
  97. // TODO 增加分类页
  98. components: {
  99. Head
  100. },
  101. data: () => ({
  102. userInfo: {},
  103. drawer: true,
  104. keyword: '',
  105. items: [
  106. { icon: 'mdi-home', text: '首页', link: '/' },
  107. { icon: 'mdi-trending-up', text: '状态', link: '/hot' },
  108. { icon: 'mdi-youtube-subscription', text: '直播', link: '/subscribe' },
  109. { icon: 'mdi-history', text: '历史记录', link: '/history' },
  110. { icon: 'mdi-playlist-play', text: '稍后再看', link: '/playlist' }
  111. ],
  112. headItem: [
  113. { icon: 'mdi-head', text: '个人中心', link: '/studio', id: 0 },
  114. { icon: 'mdi-wrench', text: '创作中心', link: '/studio', id: 1 },
  115. { icon: 'mdi-logout', text: '退出', link: '/logout', id: 2 }
  116. ]
  117. }),
  118. mounted() {
  119. },
  120. created() {
  121. this.userInfo = this.$store.state.user.userInfo
  122. this.$vuetify.theme.dark = this.$store.state.darkThemOpen
  123. },
  124. methods: {
  125. headClick(value) {
  126. if (value === 0) {
  127. this.$router.push('/user/' + this.userInfo.id)
  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. /* fetch(`/api/logout`, {
  146. headers: {
  147. 'Content-Type': 'application/json; charset=UTF-8',
  148. 'X-XSRF-TOKEN': this.$cookies.get('XSRF-TOKEN')
  149. },
  150. method: 'GET',
  151. credentials: 'include'
  152. }).then(response => response.json())
  153. .then(json => {
  154. if (json.status === 200) {
  155. this.$store.commit('setUserInfo', null)
  156. if (this.$route.path === '/') {
  157. location.reload()
  158. } else {
  159. this.$router.push('/')
  160. }
  161. } else {
  162. //
  163. }
  164. })
  165. .catch(e => {
  166. return null
  167. })*/
  168. },
  169. goToLoginPage() {
  170. this.$router.push('/login')
  171. },
  172. goToPublish() {
  173. this.$router.push('/studio/upload')
  174. },
  175. goToHome() {
  176. if (this.$route.path === '/') {
  177. return
  178. }
  179. this.$router.push('/')
  180. },
  181. goToUserHome() {
  182. if (this.$route.path === '/user/' + this.$store.state.user.userInfo.id) {
  183. return
  184. }
  185. this.$router.push('/user/' + this.$store.state.user.userInfo.id)
  186. }
  187. }
  188. }
  189. </script>
  190. <style scoped>
  191. a {
  192. text-decoration: none;
  193. }
  194. </style>