Przeglądaj źródła

登录过期后直接跳转到登录页面

reghao 3 lat temu
rodzic
commit
64b80a28c3

+ 12 - 10
src/api/index.js

@@ -51,25 +51,27 @@ $axios.interceptors.response.use(
     }
     if (error.response) {
       const statusCode = error.response.status
-      const res = error.response.data
       switch (statusCode) {
         case 401:
-          alert(res.data)
-          // 返回 401 清除token信息并跳转到登陆页面
-          store.commit('delToken')
-          router.replace({
-            path: '/login',
-            query: {
-              redirect: router.currentRoute.fullPath
-            }
+          // 清除用户信息和 token 并跳转到登录页面
+          store.dispatch('user/resetToken').then(() => {
+            router.push('/login')
+          }).catch(() => {
           })
+
+          // store.commit('setUserInfo', null)
+          // commit('RESET_STATE')
+          /* store.user.userInfo = null
+          store.user.token = null
+          console.log(store.user)*/
           break
         case 404:
           console.error('网络请求不存在')
           break
         default:
-          console.error(error.response.data.message)
+          console.error(error.response)
       }
+      return error.response
     } else {
       // 请求超时或者网络有问题
       if (error.message.includes('timeout')) {

+ 1 - 6
src/components/player/live-player.vue

@@ -55,12 +55,7 @@ export default {
               console.log('无法识别 url 类型')
             }
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {

+ 2 - 12
src/components/player/player.vue

@@ -48,12 +48,7 @@ export default {
             console.log('无法识别 url 类型')
           }
         } else {
-          this.$notify({
-            title: res.code,
-            message: res.msg,
-            type: 'warning',
-            duration: 500
-          })
+          console.error(res.msg)
         }
       }).catch(error => {
         console.error(error.message)
@@ -74,12 +69,7 @@ export default {
           if (res.code === 0) {
             console.log('播放进度已发送')
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         }).catch(error => {
           console.error(error.message)

+ 1 - 1
src/components/player/video-card.vue

@@ -1,3 +1,4 @@
+<!-- TODO 使用 item-card 页面替换 -->
 <template>
   <!-- padding-left: 10px; padding-right: 10px; -->
   <div style="width: 320px">
@@ -48,7 +49,6 @@ export default {
     }
   },
   created() {
-
   }
 }
 </script>

+ 1 - 6
src/components/register-from.vue

@@ -201,12 +201,7 @@ export default {
           if (res.code === 0) {
             alert(res.msg)
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {

+ 1 - 1
src/components/upload/filepond-upload.vue

@@ -50,7 +50,7 @@ export default {
       videMessage: {},
       myFiles: [],
       server: {
-        url: 'http://localhost:8002' + '/api/file/upload/video',
+        url: 'http://file.reghao.cn' + '/api/file/upload/video',
         timeout: 600_000,
         process: {
           headers: {

+ 5 - 13
src/components/upload/upload-video.vue

@@ -13,7 +13,7 @@
         <v-row justify="center">
           <v-col cols="10">
             <!-- <v-file-input prepend-icon="mdi-video" show-size counter accept="video/*,.flv" chips label="请选择视频文件" @change="setFile" /> -->
-            <FilePondUpload @video="videoUploadSuccess" />
+            <FilePondUpload @video="videoUploadCallback" />
           </v-col>
         </v-row>
         <v-row justify="center">
@@ -27,9 +27,6 @@
               <v-img :src="videoInfo.coverUrl" aspect-ratio="1.77" contain max-height="150" alt="封面图,推荐16:9" />
             </v-card>
           </v-col>
-
-          <!--
-          TODO 现阶段由系统生成封面
           <v-col cols="5">
             <v-file-input
               :rules="rules"
@@ -42,7 +39,7 @@
             <v-btn color="primary" @click="uploadFile">
               上传
             </v-btn>
-          </v-col>-->
+          </v-col>
         </v-row>
         <v-row justify="center">
           <v-col cols="5">
@@ -200,7 +197,7 @@ export default {
       this.files.push(value)
     },
     // filepond 组件上传文件完成时调用
-    videoUploadSuccess(value) {
+    videoUploadCallback(value) {
       if (value.code === 0) {
         this.videoInfo.videoId = value.data.videoId
         this.setTitle(value.data.filename)
@@ -237,7 +234,7 @@ export default {
       for (let i = 0; i < this.files.length; i++) {
         formData.append('file[]', this.files[i])
       }
-      fetch(`/api/file/upload/image`, {
+      fetch(`http://file.reghao.cn/api/file/upload/image`, {
         headers: {
           'X-XSRF-TOKEN': this.$cookies.get('XSRF-TOKEN')
         },
@@ -267,12 +264,7 @@ export default {
               this.categoryMap.Set(name, res.data[i])
             }
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {

+ 1 - 6
src/layout/components/search-input.vue

@@ -56,12 +56,7 @@ export default {
           if (res.code === 0) {
             this.items = res.data
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {

+ 3 - 3
src/router/index.js

@@ -130,9 +130,9 @@ const routes = [
             }
           },
           {
-            path: '/user/setting',
-            name: 'UserSetting',
-            component: () => import('@/views/user/setting.vue'),
+            path: '/user/account',
+            name: 'UserAccount',
+            component: () => import('@/views/user/account.vue'),
             meta: {
               title: '账户设置',
               requireAuth: true

+ 6 - 0
src/store/index.js

@@ -36,6 +36,12 @@ const store = new Vuex.Store({
       // 之后才是修改state中的状态
       state.userInfo = userInfo
     },
+    setUserToken(state, token) {
+      // 将传递的数据先保存到 localStorage 中
+      // localStorage.setItem('user', JSON.stringify(userInfo))
+      // 之后才是修改state中的状态
+      state.token = token
+    },
     setWebInfo(state, webInfo) {
       localStorage.setItem('webInfo', JSON.stringify(webInfo))
       state.userInfo = webInfo

+ 1 - 0
src/utils/auth.js

@@ -11,5 +11,6 @@ export function setToken(token) {
 }
 
 export function removeToken() {
+  console.log('删除 token')
   return Cookies.remove(TokenKey)
 }

+ 1 - 6
src/views/home/index.vue

@@ -49,12 +49,7 @@ export default {
             this.page += 1
             this.busy = false
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {

+ 1 - 6
src/views/home/mblog.vue

@@ -228,12 +228,7 @@ export default {
             this.page += 1
             this.busy = false
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {

+ 1 - 6
src/views/home/search-result.vue

@@ -66,12 +66,7 @@ export default {
             // 页面跳转后滚动到页面顶部
             this.$vuetify.goTo(0)
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         }).catch(error => {
           console.error(error.message)

+ 2 - 1
src/views/studio/index.vue

@@ -4,7 +4,8 @@
       <v-col cols="2">
         <v-sheet rounded="lg">
           <v-list color="transparent">
-            <router-link :to="`/u/${this.$store.state.user.userInfo.userId}`">
+            <router-link :to="`/user/home`">
+            <!--<router-link :to="`/u/${this.$store.state.user.userInfo.userId}`">-->
               <v-row justify="center" align="center">
                 <v-col cols="12" style="text-align: center">
                   <v-avatar size="62">

+ 0 - 0
src/views/user/setting.vue → src/views/user/account.vue


+ 1 - 1
src/views/user/home.vue

@@ -215,7 +215,7 @@ export default {
       this.$router.push('/studio')
     },
     goToSetting() {
-      this.$router.push('/user/setting')
+      this.$router.push('/user/account')
     }
   }
 }

+ 1 - 1
src/views/user/userindex.vue

@@ -54,7 +54,7 @@ export default {
     CheckPower,
     items: [
       { icon: 'mdi-wrench', text: '个人主页', link: '/user/home' },
-      { icon: 'mdi-wrench', text: '账户设置', link: '/user/setting' },
+      { icon: 'mdi-wrench', text: '账户设置', link: '/user/account' },
       { icon: 'mdi-account-multiple', text: '收藏列表', link: '/user/favlist' },
       { icon: 'mdi-account-multiple', text: '稍后再看', link: '/user/playlist' },
       { icon: 'mdi-account-multiple', text: '历史记录', link: '/user/hislist' },

+ 2 - 12
src/views/video/video.vue

@@ -166,12 +166,7 @@ export default {
             this.videoData = res.data
             document.title = res.data.title
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {
@@ -185,12 +180,7 @@ export default {
           if (res.code === 0) {
             this.videoList = res.data.list
           } else {
-            this.$notify({
-              title: res.code,
-              message: res.msg,
-              type: 'warning',
-              duration: 500
-            })
+            console.error(res.msg)
           }
         })
         .catch(error => {