Просмотр исходного кода

修复apply页面刷新丢失信息

zweizhao 7 лет назад
Родитель
Сommit
8adb9e0953
4 измененных файлов с 21 добавлено и 15 удалено
  1. 2 2
      components/header.vue
  2. 8 2
      pages/cert/apply.vue
  3. 1 1
      pages/cert/index.vue
  4. 10 10
      plugins/http.js

+ 2 - 2
components/header.vue

@@ -190,7 +190,7 @@ export default {
       location.href = url
     },
     async getUserinfo() {
-      let res = await this.$get('/api/user/getInfo', { neverLogout: true })
+      let res = await this.$get('/api/user/getInfo', {}, { neverLogout: true })
       if(res) {
         this.updateUserinfo({
           userinfo: res.data
@@ -201,7 +201,7 @@ export default {
       window.location.href = '/search/?keyword=' + this.keywork;
     },
     async getMessageCount() {
-      let res = await this.$get('/api/message/getUnreadCount', { neverLogout: true })
+      let res = await this.$get('/api/message/getUnreadCount', {}, { neverLogout: true })
       if(res) {
         this.messageCount = res.data
       }

+ 8 - 2
pages/cert/apply.vue

@@ -46,8 +46,9 @@ import http from '@/plugins/http'
 
 export default {
   async asyncData({ query, req }) {
+    let headers = req && req.headers
     let type = query.type
-      , { data } = await http.post(`/api/cert/getDetail`, { id: type, neverLogout: true })
+      , { data } = await http.post(`/api/cert/getDetail`, { id: type }, { config: { headers }, neverLogout: true })
     return {
       detail: data,
     }
@@ -64,15 +65,20 @@ export default {
     }
   },
   computed: {
+    userinfo() {
+      return this.$store.state.userinfo
+    },
     isDeath() {
       return !this.detail.can_click
     },
     isLogin() {
-      return this.detail.user_info
+      debugger
+      return this.userinfo
     }
   },
   mounted() {
     console.log(this.detail)
+    console.log(this.userinfo)
   },
   methods: {
     clickVipPrice() {

+ 1 - 1
pages/cert/index.vue

@@ -74,7 +74,7 @@ export default {
       return item.btn_name !== "申请认证" || !item.can_click
     },
     async getList() {
-      let res = await this.$post('/api/cert/getList', { page, neverLogout: true })
+      let res = await this.$post('/api/cert/getList', { page }, { neverLogout: true })
       if(res.status) {
         let list = res.data.list
         this.list = list

+ 10 - 10
plugins/http.js

@@ -13,10 +13,7 @@ import Vue from 'vue'
  * @param {object} payload 其他选项
  * @param {object} promise 返回一个 promise
  */
-const get = async (path, data, payload) => {
-  let result = await request('get', path, data, payload)
-  return result
-}
+const get = async (path, data, payload = {}) => await request('get', path, data, payload)
 
 /**
  *
@@ -25,7 +22,7 @@ const get = async (path, data, payload) => {
  * @param {object} payload 其他选项
  * @param {object} promise 返回一个 promise
  */
-const post = async (path, data = {}, payload) => {
+const post = async (path, data = {}, payload = { config: {} }) => {
   let formData = ''
   for(const key in data) {
     if(data.hasOwnProperty(key)) {
@@ -34,10 +31,13 @@ const post = async (path, data = {}, payload) => {
     }
   }
   formData = formData.slice(0, formData.length - 1)
+  let config = { headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' } }
+  if(payload.config.headers) config.headers = {
+    ...config.headers,
+    ...payload.config.headers,
+  }
 
-  let result = await request('post', path, formData, { config: { headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' } } })
-
-  return result
+  return await request('post', path, formData, { config })
 }
 
 /**
@@ -71,11 +71,11 @@ const request = async (method, path, data, payload = {}) => {
   if(typeof rData !== 'object') rData = JSON.parse(rData)
   // consoleFormat({ rData })
   if(rData.status === 1) return rData
-  else if(rData.status === -99 && !data.neverLogout) {
+  else if(rData.status === -99 && !payload.neverLogout) {
     location.href = '/login'
     return
   } else {
-    if(!data.neverLogout) Vue.prototype.$message.error(rData.info)
+    if(!payload.neverLogout) Vue.prototype.$message.error(rData.info)
     return
   }
 }