index.vue 4.8 KB

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