Tim_Walker 1 год назад
Родитель
Сommit
92f3ad7eef

+ 3 - 3
src/pages/client/clientUser/mine/setting.vue

@@ -10,9 +10,9 @@
           <u-cell size="large" :border="false" icon="github-circle-fill" title="关于我们" isLink
             url="/pages/client/clientUser/mine/setting/aboutMine" />
           <u-cell size="large" :border="false" icon="file-text-fill" title="用户协议" isLink
-            url="/pages/client/clientUser/mine/setting/agreement" />
+            url="/pages/webview/index?target=http://8.137.122.65:88/用户协议.html" />
           <u-cell size="large" :border="false" icon="file-text" title="隐私政策" isLink
-            url="/pages/client/clientUser/mine/setting/privacyPolicy" />
+            url="/pages/webview/index?target=http://8.137.122.65:88/隐私政策.html" />
           <u-cell icon="integral-fill" title="版本信息" value="V0.0.1" />
         </u-cell-group>
       </view>
@@ -49,7 +49,7 @@
     methods: {
       confirmSwitch() {
         this.showSwitchDialog = false;
-        this.$store.commit('SET_SCOPE','MERCHANT')
+        this.$store.dispatch('SwitchIdentity','MERCHANT')
         uni.navigateTo({
           url: '/pages/merchant/mine/index',
         });

+ 1 - 1
src/pages/client/tabBar/mine/TapList.vue

@@ -113,7 +113,7 @@ export default {
 
     confirmSwitch() {
       this.showSwitchDialog = false;
-      this.$store.commit('SET_SCOPE','MERCHANT')
+      this.$store.dispatch('SwitchIdentity','MERCHANT')
       uni.navigateTo({
         url: '/pages/merchant/mine/index',
       });

+ 1 - 1
src/pages/login/index.vue

@@ -123,7 +123,7 @@ export default {
       this.$store
         .dispatch('LoginByWxCode', data)
         .then(() => {
-          this.$store.commit('SET_SCOPE','CUSTOMER')
+          this.$store.dispatch('SwitchIdentity','CUSTOMER')
           this.$Router.pushTab('/pages/client/tabBar/home/index');
           this.loading = false;
           this.$store.dispatch('GetUserInfo')

+ 1 - 1
src/pages/login/phoneLogin.vue

@@ -101,7 +101,7 @@ export default {
       this.loading = true
       this.$store.dispatch('LoginBySmsCode', data)
         .then(() => {
-          this.$store.commit('SET_SCOPE','CUSTOMER')
+          this.$store.dispatch('SwitchIdentity','CUSTOMER')
           this.$Router.pushTab('/pages/client/tabBar/home/index');
           this.loading = false;
           this.$store.dispatch('GetUserInfo')

+ 1 - 1
src/pages/merchant/mine/setting/index.vue

@@ -113,7 +113,7 @@ export default {
     confirmSwitch() {
       // 点击确认切换身份
       // 处理身份切换逻辑
-      this.$store.commit('SET_SCOPE','CUSTOMER')
+      this.$store.dispatch('SwitchIdentity','CUSTOMER')
       uni.switchTab({
         url: '/pages/client/tabBar/mine/index',
       });

+ 35 - 24
src/store/modules/auth.js

@@ -1,40 +1,36 @@
 /**
  * 用户令牌信息
  */
-import { loginByWxLoginCode,loginByPhoneAndSmsCode, logout } from '@/api/login';
+import { loginByWxLoginCode, loginByPhoneAndSmsCode, logout } from '@/api/login';
+import request from '@/utils/request';
 
 export default {
   state: () => ({
     // login info
-    id:  null,
-    accessToken:  '',
-    refreshToken:  '',
-    mobile:  '',
-    anonymous:  false,
-    duration:  0,
-    scope:  'CUESTOMER',
+    id: null,
+    accessToken: '',
+    refreshToken: '',
+    mobile: '',
+    anonymous: false,
+    duration: 0,
+    scope: 'CUESTOMER',
   }),
 
   mutations: {
     SET_ID: (state, id) => {
       state.id = id;
-
     },
     SET_ACCESS_TOKEN: (state, accessToken) => {
       state.accessToken = accessToken;
-
     },
     SET_REFRESH_TOKEN: (state, refreshToken) => {
       state.refreshToken = refreshToken;
-
     },
     SET_MOBILE: (state, mobile) => {
       state.mobile = mobile;
-
     },
     SET_ANONYMOUS: (state, anonymous) => {
       state.anonymous = anonymous;
-
     },
     SET_DURATION: (state, duration) => {
       state.duration = duration;
@@ -43,13 +39,12 @@ export default {
       state.scope = scope;
     },
   },
-
   actions: {
     LoginByWxCode({ commit }, payload) {
       const data = {
         scope: this.scope,
-        id:'chelvc_client',
-        secret:'chelvc@secret#2023!',
+        id: 'chelvc_client',
+        secret: 'chelvc@secret#2023!',
         code: payload.code,
         mobile: payload.mobile,
       }
@@ -65,7 +60,7 @@ export default {
               commit('SET_DURATION', res.data.duration);
               commit('SET_SCOPE', res.data.scope);
               resolve();
-            }else{
+            } else {
               reject(res)
             }
           })
@@ -77,8 +72,8 @@ export default {
     LoginBySmsCode({ commit }, payload) {
       const data = {
         scope: this.scope,
-        id:'chelvc_client',
-        secret:'chelvc@secret#2023!',
+        id: 'chelvc_client',
+        secret: 'chelvc@secret#2023!',
         code: payload.code,
         mobile: payload.mobile,
         captcha: payload.captcha
@@ -96,7 +91,7 @@ export default {
               commit('SET_DURATION', res.data.duration);
               commit('SET_SCOPE', res.data.scope);
               resolve();
-            }else{
+            } else {
               reject()
             }
           })
@@ -105,10 +100,26 @@ export default {
           });
       });
     },
-    Logout({commit}){
+    // 切换身份
+    SwitchIdentity({ commit }, payload) {
+      const data = {
+        scope: payload,
+        token: this.getters.refreshToken,
+        id: 'chelvc_client',
+        secret: 'chelvc@secret#2023!'
+      }
+      request({
+        url: '/maintain/token/refresh',
+        method: 'post',
+        data: data
+      }).then(res=>{
+        commit('SET_SCOPE', payload);
+      })
+    },
+    Logout({ commit }) {
       const data = {
-        id:'chelvc_client',
-        secret:'chelvc@secret#2023!',
+        id: 'chelvc_client',
+        secret: 'chelvc@secret#2023!',
       }
       return new Promise((resolve, reject) => {
         logout(data)
@@ -122,7 +133,7 @@ export default {
               commit('SET_ANONYMOUS', false);
               commit('SET_DURATION', 0);
               resolve();
-            }else{
+            } else {
               reject()
             }
           })