index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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="red"
  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" />
  71. <!-- 未登录 -->
  72. <v-btn
  73. v-if="this.$store.state.user == 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. </div>
  84. </template>
  85. <script>
  86. import Head from '@/layout/components/head.vue'
  87. export default {
  88. // TODO 增加分类页
  89. components: {
  90. Head
  91. },
  92. data: () => ({
  93. userInfo: {},
  94. drawer: true,
  95. keyword: '',
  96. items: [
  97. { icon: 'mdi-home', text: '首页', link: '/' },
  98. { icon: 'mdi-trending-up', text: '时下流行', link: '/hot' },
  99. { icon: 'mdi-youtube-subscription', text: '订阅', link: '/subscribe' },
  100. { icon: 'mdi-history', text: '历史记录', link: '/history' },
  101. { icon: 'mdi-playlist-play', text: '稍后再看', link: '/playlist' }
  102. ],
  103. headItem: [
  104. { icon: 'mdi-head', text: '个人主页', link: '/user/', id: 0 },
  105. { icon: 'mdi-wrench', text: '创作中心', link: '/studio', id: 1 },
  106. { icon: 'mdi-logout', text: '退出', link: '/logout', id: 2 }
  107. ]
  108. }),
  109. mounted() {
  110. },
  111. created() {
  112. this.userInfo = this.$store.state.user
  113. this.$vuetify.theme.dark = this.$store.state.darkThemOpen
  114. },
  115. methods: {
  116. headClick(value) {
  117. if (value === 0) {
  118. this.$router.push('/user/' + this.userInfo.id)
  119. } else if (value === 1) {
  120. this.$router.push('/studio')
  121. } else {
  122. this.logout()
  123. }
  124. },
  125. logout() {
  126. fetch(`/api/logout`, {
  127. headers: {
  128. 'Content-Type': 'application/json; charset=UTF-8',
  129. 'X-XSRF-TOKEN': this.$cookies.get('XSRF-TOKEN')
  130. },
  131. method: 'GET',
  132. credentials: 'include'
  133. }).then(response => response.json())
  134. .then(json => {
  135. if (json.status === 200) {
  136. this.$store.commit('setUserInfo', null)
  137. if (this.$route.path === '/') {
  138. location.reload()
  139. } else {
  140. this.$router.push('/')
  141. }
  142. } else {
  143. //
  144. }
  145. })
  146. .catch(e => {
  147. return null
  148. })
  149. },
  150. goToLoginPage() {
  151. this.$router.push('/login')
  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.id) {
  164. return
  165. }
  166. this.$router.push('/user/' + this.$store.state.user.id)
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped>
  172. a {
  173. text-decoration: none;
  174. }
  175. </style>