Forráskód Böngészése

fix: 自测修复

Darkhorsedamon 2 éve
szülő
commit
74ca544b3f

+ 1 - 1
components/BuyTicket.vue

@@ -161,7 +161,7 @@ export default {
     getUserInfo() {
       this.$axios.get('members/getMemberInfo').then((res)=> {
         if(res.code === 200) {
-          this.$store.commit('setUser',res.result)
+          this.$store.commit('setUser',res.result.memberInfo)
           this.$router.push('/members/me/expenses')
         }
       })

+ 1 - 2
components/BuyVip.vue

@@ -145,8 +145,7 @@ export default {
     getUserInfo() {
       this.$axios.get('members/getMemberInfo').then((res)=> {
         if(res.code === 200) {
-          this.$store.commit('setUser',res.result)
-          // localStorage.setItem('userInfo',JSON.stringify(res.result))
+          this.$store.commit('setUser',res.result.memberInfo)
           this.$router.push('/members/me/expenses')
         }
       })

+ 16 - 16
components/LoginBar.vue

@@ -2,6 +2,7 @@
 <script>
 import qs from 'qs'
 import { mapActions } from 'vuex'
+import { setToken } from '~/utils/cookie';
 
 export default {
   data() {
@@ -53,21 +54,21 @@ export default {
   methods: {
     ...mapActions(['login']),
     handlerLogin() {
-      if(this.checked) {
-        localStorage.setItem('username',this.form.username)
-        localStorage.setItem('password',this.form.password)
-      }else {
-        localStorage.removeItem('username',this.form.username)
-        localStorage.removeItem('password',this.form.password)
-        this.form.username = ''
-        this.form.password = ''
-      }
       this.logging = true
       this.$axios.post('login',qs.stringify(this.form)).then((res)=> {
         if(res.code === 200) {
             this.$store.dispatch('login',res.result).then((token)=> {
             this.$axios.setToken(token, 'Bearer')
             localStorage.setItem('token',token)
+            if(this.checked) {
+              localStorage.setItem('username',this.form.username)
+              localStorage.setItem('password',this.form.password)
+            }else {
+              localStorage.removeItem('username',this.form.username)
+              localStorage.removeItem('password',this.form.password)
+              this.form.username = ''
+              this.form.password = ''
+            }
             this.handlerClose()
             this.getUserInfo()
           })
@@ -78,7 +79,8 @@ export default {
     getUserInfo()  {
       this.$axios.get('members/getMemberInfo').then((res)=> {
         if(res.code === 200) {
-          this.$store.commit('setUser',res.result)
+          this.$store.commit('setUser',res.result.memberInfo)
+          setToken('vuex',JSON.stringify(res.result.memberInfo))
           this.logging = false
           this.$emit('loginSucess')
         }
@@ -95,18 +97,16 @@ export default {
         action: '1', // 找回密码
         receiver: this.forgetForm.account
       }
-      if(this.regPhone.test(this.form.username)) params.type = '1'
-      if(this.regEmail.test(this.form.username)) params.type = '0'
+      if(this.regPhone.test(this.forgetForm.account)) params.type = '1'
+      if(this.regEmail.test(this.forgetForm.account)) params.type = '0'
       this.$axios.get('auth/getVerifyCode', {params}).then((res)=> {
         if(res.code === 200) {
           this.sending = true
           let interval = setInterval(() => {
             this.clock--
             if(this.clock === 0) {
-              this.$once('hook:beforeDestroy',()=> {
-                clearInterval(interval)
-                interval = null
-              })
+              clearInterval(interval)
+              interval = null
               this.clock = 60
               this.sending = false
             }

+ 1 - 1
components/RegisterBar.vue

@@ -83,7 +83,7 @@ export default {
     getUserInfo()  {
       this.$axios.get('members/getMemberInfo').then((res)=> {
         if(res.code === 200) {
-          this.$store.commit('setUser',res.result)
+          this.$store.commit('setUser',res.result.memberInfo)
           this.$emit('loginSucess')
         }
       })

+ 5 - 6
components/UserManage.vue

@@ -30,7 +30,7 @@
         <br/>
         <input  v-model="form.newPassword"  class="login_input_password new" type="password" placeholder="新密码(6-16个字符,区分大小写)">
         <br/>
-        <input  v-model="form.newPassword_confirm"  class="login_input_password confirm" type="password" placeholder="确认新密码">
+        <input  v-model="form.newPasswordConfirm"  class="login_input_password confirm" type="password" placeholder="确认新密码">
         <br/>
         <div class="error-mess error-mess-signup" >
           <span id="error-message error-tip">{{errMsg}}</span>
@@ -51,7 +51,7 @@ export default {
       form: {
         password:'',
         newPassword: '',
-        newPassword_confirm:''
+        newPasswordConfirm:''
       },
       errMsg:''
     }
@@ -60,7 +60,7 @@ export default {
   methods: {
     // 点击注册前置校验
     vailidate() {
-      if(this.form.newPassword !== this.form.newPassword_confirm) {
+      if(this.form.newPassword !== this.form.newPasswordConfirm) {
         this.errMsg = '密码不一致'
       }else if(this.form.newPassword.length < 6) {
         this.errMsg = '密码位数不能少于6位'
@@ -91,8 +91,7 @@ export default {
     getUserInfo()  {
       this.$axios.get('members/getMemberInfo').then((res)=> {
         if(res.code === 200) {
-          this.$store.commit('setUser',res.result)
-          // localStorage.setItem('userInfo',JSON.stringify(res.result))
+          this.$store.commit('setUser',res.result.memberInfo)
         }
       })
     },
@@ -100,7 +99,7 @@ export default {
       this.changePsd = false
       this.form.password = ''
       this.form.newPassword = ''
-      this.form.newPassword_confirm = ''
+      this.form.newPasswordConfirm = ''
     }
   }
 }

+ 9 - 10
layouts/components/NavBar.vue

@@ -3,7 +3,7 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-10-17 15:19:11
- * @LastEditTime: 2022-11-16 09:27:17
+ * @LastEditTime: 2022-11-16 11:38:50
 -->
 <template>
   <div class="h-80px flex relative z-3 justify-between px-[10%] border-b-1 border-b-[#f0f0f0] border-b-solid">
@@ -32,28 +32,28 @@
               <div class="px-24px pt-24px min-w-300px">
                 <div class="flex pb-22px cursor-pointer" style="border-bottom: 1px solid #f0f0f0;">
                   <a href="/members/me/expenses">
-                    <img v-if="userInfo?.memberInfo?.subscriberType === 1" class="w-64px rounded-1/2"  src="http://user-file.17pdf.com/avatars/2020/11/16/0577b907be980556bdafa23fb0be0732-jpg.jpg" >
+                    <img v-if="userInfo?.subscriberType === 1" class="w-64px rounded-1/2"  src="http://user-file.17pdf.com/avatars/2020/11/16/0577b907be980556bdafa23fb0be0732-jpg.jpg" >
                     <img v-else class="w-64px rounded-1/2"  src="http://user-file.17pdf.com/avatars/2018/01/02/f183029426a996325853fa244e7df661-jpg.jpg" >
                   </a>
                   <div class="pl-20px">
-                    <p class="mt-15px mb-10px text-[#333]">{{userInfo?.memberInfo?.name}}</p>
-                    <p class="text-[#999]">{{userInfo?.memberInfo?.email || userInfo?.memberInfo?.phone}}</p>
+                    <p class="mt-15px mb-10px text-[#333]">{{userInfo?.name}}</p>
+                    <p class="text-[#999]">{{userInfo?.email || userInfo?.phone}}</p>
                   </div>
                 </div>
                 <div class="flex py-14px mt-20px justify-between">
                   <div>
-                    <p v-if="userInfo?.memberInfo?.subscriberType === 1" class="text-18px text-[#333] leading-24px">17会员</p>
+                    <p v-if="userInfo?.subscriberType === 1" class="text-18px text-[#333] leading-24px">17会员</p>
                     <p v-else class="text-18px text-[#333] leading-24px">免费用户</p>
-                    <p v-if="userInfo?.memberInfo?.subscriberType === 1" class="text-12px text-[#999] leading-17px">剩余<span class="text-bg-$btn-color-primary">{{userInfo?.memberInfo?.day}}</span>天到期</p>
+                    <p v-if="userInfo?.subscriberType === 1" class="text-12px text-[#999] leading-17px">剩余<span class="text-bg-$btn-color-primary">{{userInfo?.day}}</span>天到期</p>
                     <p v-else class="text-12px text-[#999] leading-17px">订阅会员免费格式转换</p>
                   </div>
                   <button class="btn-renew" @click="$router.push('/pricing')">
-                    {{userInfo?.memberInfo?.subscriberType === 1 ? '续费' : '订阅会员'}}
+                    {{userInfo?.subscriberType === 1 ? '续费' : '订阅会员'}}
                   </button>
                 </div>
                 <div class="flex py-14px my-8px justify-between" style="border-bottom: 1px solid #f0f0f0;">
                   <div>
-                    <p class="text-18px text-[#333] leading-24px"><span class="text-500 text-bg-$btn-color-primary text-22px leading-18px tracking-1px">{{userInfo?.memberInfo?.points}}</span><span class="text-14px text-[rgba(0,0,0,0.8)] leading-18px">/{{userInfo?.memberInfo?.totalPoints}}</span></p>
+                    <p class="text-18px text-[#333] leading-24px"><span class="text-500 text-bg-$btn-color-primary text-22px leading-18px tracking-1px">{{userInfo?.points}}</span><span class="text-14px text-[rgba(0,0,0,0.8)] leading-18px">/{{userInfo?.totalPoints}}</span></p>
                     <p class="text-12px text-[#999] leading-17px">转换券</p>
                   </div>
                   <button class="btn-recharge" @click="handlerOpenLogin('ticket')">充值</button>
@@ -66,7 +66,7 @@
                 </div>
               </div>
             </div>
-            <img slot="reference" class="w-36px h-36px rounded-full mt-23px mr-0 md-0 ml-90px cursor-pointer" :src="userInfo?.memberInfo?.subscriberType === 1 ? 'https://user-file.17pdf.com/avatars/2020/11/16/0577b907be980556bdafa23fb0be0732-jpg.jpg' : 'http://user-file.17pdf.com/avatars/2018/01/02/f183029426a996325853fa244e7df661-jpg.jpg'" @click="$router.push('/members/me/expenses')" />
+            <img slot="reference" class="w-36px h-36px rounded-full mt-23px mr-0 md-0 ml-90px cursor-pointer" :src="userInfo?.subscriberType === 1 ? 'https://user-file.17pdf.com/avatars/2020/11/16/0577b907be980556bdafa23fb0be0732-jpg.jpg' : 'http://user-file.17pdf.com/avatars/2018/01/02/f183029426a996325853fa244e7df661-jpg.jpg'" @click="$router.push('/members/me/expenses')" />
           </el-popover>
         </client-only>
       </div>
@@ -166,7 +166,6 @@ export default {
     },
     handlerLogout() {
       localStorage.removeItem('token')
-      localStorage.removeItem('userInfo')
       this.$store.commit('setUser', {})
       removeToken('Token')
       this.$store.commit('DEL_TOKEN', '')

+ 8 - 8
layouts/userCenter.vue

@@ -3,7 +3,7 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-11-01 20:18:40
- * @LastEditTime: 2022-11-15 19:27:07
+ * @LastEditTime: 2022-11-16 10:16:06
 -->
 <template>
   <div class="font-primary min-w-1200px">
@@ -13,27 +13,27 @@
         <div class="person">
           <div>
             <a href="/members/me/expenses" class="members">
-              <img v-if="userInfo?.memberInfo?.subscriberType === 1" src="http://user-file.17pdf.com/avatars/2020/11/16/0577b907be980556bdafa23fb0be0732-jpg.jpg" >
+              <img v-if="userInfo?.subscriberType === 1" src="http://user-file.17pdf.com/avatars/2020/11/16/0577b907be980556bdafa23fb0be0732-jpg.jpg" >
               <img v-else src="http://user-file.17pdf.com/avatars/2018/01/02/f183029426a996325853fa244e7df661-jpg.jpg" >
             </a>
             <br>
-            <p class="username">{{userInfo?.memberInfo?.name}}</p>
-            <p class="user-showname block mt-16px">{{userInfo?.memberInfo?.email || userInfo?.memberInfo?.phone}}</p>
+            <p class="username">{{userInfo?.name}}</p>
+            <p class="user-showname block mt-16px">{{userInfo?.email || userInfo?.phone}}</p>
           </div>
           <div class="flex py-14px mt-20px justify-between text-left">
             <div>
-              <p v-if="userInfo?.memberInfo?.subscriberType === 1" class="user-vip text-18px mb-6px text-[#333] font-500 leading-24px">17会员</p>
+              <p v-if="userInfo?.subscriberType === 1" class="user-vip text-18px mb-6px text-[#333] font-500 leading-24px">17会员</p>
               <p v-else class="text-18px text-[#333] font-500 leading-24px mb-6px">免费用户</p>
-              <p v-if="userInfo?.memberInfo?.subscriberType === 1" class="text-12px text-[#999] pl-28px mb-6px leading-17px">剩余<span class="text-bg-$btn-color-primary">{{userInfo?.memberInfo?.day}}</span>天到期</p>
+              <p v-if="userInfo?.subscriberType === 1" class="text-12px text-[#999] pl-28px mb-6px leading-17px">剩余<span class="text-bg-$btn-color-primary">{{userInfo?.day}}</span>天到期</p>
               <p v-else class="text-12px text-[#999] leading-17px">订阅会员免费格式转换</p>
             </div>
             <button class="btn-renew" @click="handlerBuy('vip')">
-              {{userInfo?.memberInfo?.subscriberType === 1 ? '续费' : '订阅会员'}}
+              {{userInfo?.subscriberType === 1 ? '续费' : '订阅会员'}}
             </button>
           </div>
           <div class="flex py-14px my-8px justify-between text-left">
             <div class="user-ticket">
-              <p class="text-18px text-[#333] leading-24px mb-6px"><span class="font-500 text-bg-$btn-color-primary text-18px leading-24px tracking-1px">{{userInfo?.memberInfo?.points}}</span><span class="text-bg-$btn-color-primary text-14px leading-18px">张</span><span class="text-14px text-[rgba(0,0,0,0.8)] leading-18px">/{{userInfo?.memberInfo?.totalPoints}}张</span></p>
+              <p class="text-18px text-[#333] leading-24px mb-6px"><span class="font-500 text-bg-$btn-color-primary text-18px leading-24px tracking-1px">{{userInfo?.points}}</span><span class="text-bg-$btn-color-primary text-14px leading-18px">张</span><span class="text-14px text-[rgba(0,0,0,0.8)] leading-18px">/{{userInfo?.totalPoints}}张</span></p>
               <p class="text-12px text-[#999] leading-17px">转换券</p>
             </div>
             <button class="btn-recharge" @click="handlerBuy('ticket')">充值</button>

+ 3 - 3
middleware/user.js

@@ -3,13 +3,13 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-11-08 09:15:06
- * @LastEditTime: 2022-11-16 09:30:48
+ * @LastEditTime: 2022-11-16 13:58:30
  */
 export default function({store, app: {$axios}}) {
   if(store?.state?.token !== '') {
-    $axios.get('members/getMemberInfo').then((res)=> {
+    return $axios.get('members/getMemberInfo').then((res)=> {
       if(res.code === 200) {
-        store.commit('setUser',res.result)
+        store.commit('setUser',res.result.memberInfo)
       }
     })
   }

+ 2 - 2
nuxt.config.js

@@ -3,7 +3,7 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-10-17 11:06:52
- * @LastEditTime: 2022-11-16 09:41:56
+ * @LastEditTime: 2022-11-16 11:28:15
  */
 export default {
   // Global page headers: https://go.nuxtjs.dev/config-head
@@ -34,7 +34,7 @@ export default {
   plugins: [
     '~/plugins/axios',
     {src: '~plugins/element-ui', ssr: false},
-    {src: '@/plugins/localStorage', ssr: false},
+    {src: '@/plugins/localStorage', ssr: true},
     {src: '@/plugins/vueqr', ssr: false},
   ],
 

+ 1 - 1
pages/members/me/expenses.vue

@@ -3,7 +3,7 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-11-01 19:27:42
- * @LastEditTime: 2022-11-08 09:44:09
+ * @LastEditTime: 2022-11-16 13:38:06
 -->
 <template>
   <div>

+ 1 - 2
plugins/axios.js

@@ -3,7 +3,7 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-10-19 13:58:11
- * @LastEditTime: 2022-11-15 17:34:01
+ * @LastEditTime: 2022-11-16 10:25:06
  */
 import { Message } from 'element-ui';
 import { removeToken } from '~/utils/cookie';
@@ -24,7 +24,6 @@ export default function({store, app:{ $axios }, redirect} ) {
       store.commit('setUser', {})
       removeToken('Token')
       localStorage.removeItem('token')
-      localStorage.removeItem('userInfo')
       return Promise.resolve(false)
     }
     if (code !== 200) {

+ 19 - 4
plugins/localStorage.js

@@ -3,12 +3,27 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-10-26 09:30:22
- * @LastEditTime: 2022-11-16 09:24:01
+ * @LastEditTime: 2022-11-16 13:54:28
  */
 import createPersistedState from 'vuex-persistedstate'
+import * as Cookies from 'js-cookie'
+import cookie from 'cookie';
 
-export default ({ store }) => {
+
+export default ({store, req}) => {
     createPersistedState({
-        storage: localStorage
-    })(store)
+        storage: {
+            getItem: (key) => {
+                if (process.server) {
+                    const parsedCookies = cookie.parse(req.headers.cookie);
+                    return parsedCookies[key];
+                } else {
+                    return Cookies.get(key);
+                }
+            },
+            setItem: (key, value) => Cookies.set(key, value, { expires: 15, secure: false }),
+            removeItem: key => Cookies.remove(key)
+        }
+    })(store);
+
 }

+ 0 - 1
static/usermanual.html

@@ -1117,7 +1117,6 @@
     var nl = (navigator.language || navigator.browserLanguage).toLowerCase();
     var cnContainer = document.getElementsByClassName('chinese')[0];
     var enContainer = document.getElementsByClassName('english')[0];
-    console.log(window.location.search)
     if (nl.indexOf('zh-cn') >= 0 && (window.location.search !== '?lang=en')) {
       cnContainer.style.display = 'block';
       enContainer.style.display = 'none';

+ 6 - 7
store/index.js

@@ -3,16 +3,12 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-10-25 17:19:19
- * @LastEditTime: 2022-11-16 09:25:49
+ * @LastEditTime: 2022-11-16 13:51:41
  */
 import { setToken, cookieParse } from '~/utils/cookie'
 
 export const state = () => ({
-  userInfo: {
-    memberInfo: {},
-    pricingList: [],
-    setPricingList: [],
-  },
+  userInfo: {},
   token: '',
   globalLoginVisiable: false,
   globalInterfaceType: false
@@ -41,13 +37,16 @@ export const actions = {
 
   nuxtServerInit ({commit, state}, {req}) {
     let token = null
+    let userInfo = null
     if (req && req.headers && req.headers.cookie) {
       const parsed = cookieParse(req.headers.cookie)
       try {
-        token = parsed.Token
+        token = parsed?.Token || ''
+        userInfo = JSON.parse(decodeURIComponent(parsed.vuex)).userInfo
       } catch (err) {
       }
       commit('SET_TOKEN', token)
+      commit('setUser', userInfo)
     }
   },
 

+ 2 - 2
utils/cookie.js

@@ -3,9 +3,9 @@
  * @Author: 欧阳承珺
  * @LastEditors: 欧阳承珺
  * @Date: 2022-11-11 11:27:09
- * @LastEditTime: 2022-11-11 13:43:02
+ * @LastEditTime: 2022-11-11 11:43:25
  */
-const Cookies = process.client ? require('js-cookie') : undefined
+const Cookies = require('js-cookie')
 
 export function getToken (TokenKey) {
   return Cookies ? Cookies.get(TokenKey) : ''