Explorar o código

判断身份-暂存

armg hai 2 semanas
pai
achega
567fd3fe1d
Modificáronse 2 ficheiros con 54 adicións e 18 borrados
  1. 17 0
      src/utils/index.ts
  2. 37 18
      src/utils/wecomLogin.ts

+ 17 - 0
src/utils/index.ts

@@ -68,6 +68,23 @@ export const getWecomType = (agentFrom: string) => {
   }
 }
 
+export const getAgentFrom = (WecomType: number) => {
+  switch (WecomType) {
+    case 0://经销商
+      return 'ssb';
+    case 1://好邦手
+      return 'hbs';
+    case 2://服务商
+      return 'stoneLikePaint';
+    case 3://金牌店
+      return 'goldShop';
+    case 4://导购
+      return 'dg';
+    default:
+      return 'ssb'; // 默认为经销商
+  }
+}
+
 export const toLBHome = () => {
   router.replace('/');
 }

+ 37 - 18
src/utils/wecomLogin.ts

@@ -67,7 +67,7 @@ export const initGuidInfo = (): void => {
  * @returns {Promise<void>}
  */
 export const doWecomLogin = async (code: string): Promise<void> => {
-   if (isLogging) return; // 正在登录中,忽略重复调用
+    if (isLogging) return; // 正在登录中,忽略重复调用
     isLogging = true;
     try {
         const lastCodeStr = window.localStorage.getItem('lastCode');
@@ -89,6 +89,25 @@ export const doWecomLogin = async (code: string): Promise<void> => {
         if (res && res.StatusCode === 200 && res.Data && res.Data.token) {
             // 登录成功:存储 AIToken
             window.localStorage.setItem('AIToken', res.Data.token);
+            // 处理身份,身份可能为多个,只能按身份权限大小来固定为某个身份;
+            let roleIds = res.Data.roleIds, agent = '';
+            if (roleIds) {
+                if (roleIds.includes('2')) {
+                    agent = 'stoneLikePaint';//服务商
+                } else if (roleIds.includes('0')) {
+                    agent = 'ssb';//经销商
+                } else if (roleIds.includes('4')) {
+                    agent = 'dg';//导购
+                } else if (roleIds.includes('1')) {
+                    agent = 'hbs';//好邦手
+                } else if (roleIds.includes('3')) {
+                    agent = 'goldShop';//金牌店
+                }
+                console.log("roleIds=", roleIds)
+                console.log("agent=", agent)
+                window.localStorage.setItem('agentFrom', agent);
+                window.localStorage.setItem('agentFromAI', agent);
+            }
             isLogging = false;
             // console.log("router.currentRoute.fullPath=",router.currentRoute.fullPath)
             // 重新跳转目标页面(此时登录状态已满足)
@@ -133,23 +152,23 @@ export const getQyCode = () => {
 
 // utils/authLock.js
 export const authLock = {
-  // 内存锁:实时判断
-  isAuthorizing: false,
-  // 初始化:从本地缓存恢复锁状态(防止页面刷新后锁失效)
-  init() {
-    const lock = window.localStorage.getItem('isWechatAuthorizing');
-    this.isAuthorizing = lock === 'true';
-  },
-  // 加锁:同时更新内存和本地缓存
-  lock() {
-    this.isAuthorizing = true;
-    window.localStorage.setItem('isWechatAuthorizing', 'true');
-  },
-  // 解锁:同时更新内存和本地缓存
-  unlock() {
-    this.isAuthorizing = false;
-    window.localStorage.removeItem('isWechatAuthorizing');
-  }
+    // 内存锁:实时判断
+    isAuthorizing: false,
+    // 初始化:从本地缓存恢复锁状态(防止页面刷新后锁失效)
+    init() {
+        const lock = window.localStorage.getItem('isWechatAuthorizing');
+        this.isAuthorizing = lock === 'true';
+    },
+    // 加锁:同时更新内存和本地缓存
+    lock() {
+        this.isAuthorizing = true;
+        window.localStorage.setItem('isWechatAuthorizing', 'true');
+    },
+    // 解锁:同时更新内存和本地缓存
+    unlock() {
+        this.isAuthorizing = false;
+        window.localStorage.removeItem('isWechatAuthorizing');
+    }
 };
 
 // 初始化锁