head.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <v-menu v-if="this.$store.state.user.userInfo" top offset-y>
  3. <template v-slot:activator="{ on, attrs }">
  4. <v-btn
  5. dark
  6. v-bind="attrs"
  7. icon
  8. large
  9. v-on="on"
  10. >
  11. <v-avatar
  12. size="32px"
  13. item
  14. >
  15. <v-img
  16. :src="userInfo.avatarUrl"
  17. :alt="userInfo.username"
  18. :title="userInfo.username"
  19. /></v-avatar>
  20. </v-btn>
  21. </template>
  22. <v-list>
  23. <v-list-item
  24. v-for="(item, index) in headItem"
  25. :key="index"
  26. link
  27. @click="headClick(item.id)"
  28. >
  29. <v-list-item-action>
  30. <v-icon>{{ item.icon }}</v-icon>
  31. </v-list-item-action>
  32. <v-list-item-content>
  33. <v-list-item-title>
  34. {{ item.text }}
  35. </v-list-item-title>
  36. </v-list-item-content>
  37. </v-list-item>
  38. </v-list>
  39. </v-menu>
  40. </template>
  41. <script>
  42. export default {
  43. name: 'Head',
  44. data() {
  45. return {
  46. userInfo: {},
  47. headItem: [
  48. { icon: 'mdi-account', text: '个人中心', link: '/user/my', id: 0 },
  49. { icon: 'mdi-application', text: '稍后再看', link: '/user/my/playlist', id: 1 },
  50. { icon: 'mdi-application', text: '收藏列表', link: '/user/my/favlist', id: 2 },
  51. { icon: 'mdi-application', text: '历史记录', link: '/user/my/hislist', id: 3 },
  52. { icon: 'mdi-application', text: '创作中心', link: '/studio', id: 4 },
  53. { icon: 'mdi-logout', text: '退出', link: '/logout', id: 5 }
  54. ]
  55. }
  56. },
  57. created() {
  58. this.userInfo = this.$store.state.user.userInfo
  59. },
  60. methods: {
  61. headClick(value) {
  62. if (value === 0) {
  63. this.$router.push('/user/home')
  64. /* this.$router.push('/user/' + this.userInfo.userId)
  65. location.replace('/user/' + this.userInfo.userId)*/
  66. } else if (value === 1 && this.$route.path !== '/user/playlist') {
  67. this.$router.push('/user/playlist')
  68. } else if (value === 2 && this.$route.path !== '/user/favlist') {
  69. this.$router.push('/user/favlist')
  70. } else if (value === 3 && this.$route.path !== '/user/hislist') {
  71. this.$router.push('/user/hislist')
  72. } else if (value === 4 && this.$route.path !== '/user/studio') {
  73. this.$router.push('/studio')
  74. } else {
  75. this.logout()
  76. }
  77. },
  78. logout() {
  79. // 调用 store/modules/user.js 中的 logout 方法
  80. this.$store.dispatch('user/logout').then(() => {
  81. if (this.$route.path === '/') {
  82. location.reload()
  83. } else {
  84. this.$router.push('/')
  85. }
  86. }).catch(() => {
  87. console.log('用户登录失败')
  88. })
  89. }
  90. }
  91. }
  92. </script>
  93. <style>
  94. </style>