armg 1 hete
szülő
commit
c6d7e33b6c
2 módosított fájl, 26 hozzáadás és 28 törlés
  1. 14 12
      src/utils/index.ts
  2. 12 16
      src/utils/wecomLogin.ts

+ 14 - 12
src/utils/index.ts

@@ -52,36 +52,38 @@ export const Dateformat = (t: string | Date, format: string) => {
 };
 
 export const getWecomType = (agentFrom: string) => {
+  // 用户类型 1经销商 2 服务商 3立邦用户 4导购 5新零售客服
   switch (agentFrom) {
     case 'ssb':
-      return 0;
-    case 'hbs':
       return 1;
     case 'stoneLikePaint':
       return 2;
-    case 'goldShop':
+    case 'hbs':
       return 3;
     case 'dg':
       return 4;
+    case 'xlskf':
+      return 5;
     default:
-      return 0; // 默认为0
+      return 5; // 默认为5
   }
 }
 
 export const getAgentFrom = (WecomType: number) => {
+  // 用户类型 1经销商 2 服务商 3立邦用户 4导购 5新零售客服
   switch (WecomType) {
-    case 0://经销商
+    case 1://经销商
       return 'ssb';
-    case 1://好邦手
-      return 'hbs';
     case 2://服务商
       return 'stoneLikePaint';
-    case 3://金牌店
-      return 'goldShop';
+    case 3://好邦手
+      return 'hbs';
     case 4://导购
       return 'dg';
+    case 5://新零售客服
+      return 'xlskf';
     default:
-      return 'ssb'; // 默认为经销商
+      return 'xlskf'; // 默认为新零售客服
   }
 }
 
@@ -146,7 +148,7 @@ export const getWxconfig = () => {
   formData.append('url', url);
   formData.append('agent', '1');
   wecomTicket(formData).then(response => {
-    console.log("wecomTicket-response=",response)
+    console.log("wecomTicket-response=", response)
     if (response.StatusCode == 200) {
       let qiyeData = response.Data;
       wx.agentConfig({
@@ -175,7 +177,7 @@ export const getWxconfig = () => {
           });
         },
         fail: function (res) {
-          console.log("获取签名失败",res);
+          console.log("获取签名失败", res);
           if (res.errMsg.indexOf('function not exist') > -1) {
             alert('版本过低请升级');
           }

+ 12 - 16
src/utils/wecomLogin.ts

@@ -15,7 +15,7 @@ export interface WecomAuthResponse {
     StatusCode: number;
     Data: {
         token: string; // AIToken
-        roleIds: string[]; 
+        roleIds: string[];
     };
     Message?: string;
 }
@@ -88,24 +88,20 @@ export const doWecomLogin = async (code: string): Promise<void> => {
         // 调用接口兑换 AIToken
         const res: WecomAuthResponse = await wecomAuth(formData);
         if (res && res.StatusCode === 200 && res.Data && res.Data.token) {
-            // 登录成功:存储 AIToken
             window.localStorage.setItem('AIToken', res.Data.token);
             // 处理身份,身份可能为多个,只能按身份权限大小来固定为某个身份;
             if (res.Data.roleIds && res.Data.roleIds.length > 0) {
-                let roleIds = res.Data.roleIds, agent = '';
-                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)
+                // 使用位运算
+                const ROLE_CONFIG = [
+                    { bit: 1 << 1, code: 'stoneLikePaint', desc: '服务商' },  // 2 
+                    { bit: 1 << 0, code: 'ssb', desc: '经销商' },             // 1 
+                    { bit: 1 << 3, code: 'dg', desc: '导购' },                // 8
+                    { bit: 1 << 2, code: 'hbs', desc: '好邦手' },             // 4
+                    { bit: 1 << 4, code: 'xlskf', desc: '新零售客服' }          // 16
+                ];
+                const roleIds = res.Data.roleIds;
+                const matchRole = ROLE_CONFIG.find(item => (roleIds & item.bit) === item.bit);
+                const agent = matchRole && matchRole.code || 'xlskf';
                 window.localStorage.setItem('agentFrom', agent);
                 window.localStorage.setItem('agentFromAI', agent);
             }