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

feat(用户认证): 添加BJT用户认证流程处理逻辑

在用户登录流程中增加对BJT用户的特殊处理,包括设置eduid和用户信息存储。同时添加selectUser3和setEduid方法用于获取用户信息和设置教育ID。当检测到isBjt标志时,执行特殊认证流程,否则走常规用户信息处理流程。
lsc 2 недель назад
Родитель
Сommit
6546bcde3f
1 измененных файлов с 48 добавлено и 2 удалено
  1. 48 2
      src/App.vue

+ 48 - 2
src/App.vue

@@ -46,7 +46,17 @@ onMounted(() => {
             console.log(r.data.data)
             // store.user = r.data.data
             name.value = r.data.data.userName
-            userInfo(r.data.data)
+            let isBjt = localStorage.getItem('isBjt')
+            let userid = localStorage.getItem('userid')
+            if(isBjt == 1){
+              localStorage.removeItem('isBjt')
+              localStorage.removeItem('userid')
+              setEduid(userid, r.data.data.eduId)
+              setStateUserinfo(userid)
+            }
+            else{
+              userInfo(r.data.data)
+            }
           }
         })
       } else {
@@ -160,7 +170,15 @@ const userInfo2 = (data) => {
     // console.log('rrrrr', r)
     axios.post(`https://beta.api.cocorobo.cn/api/user`, qs.stringify(params)).then(d => {
       // store.user = top.US.userInfo
-      setStateUserinfo(d.data[0][0].userid)
+      // setStateUserinfo(d.data[0][0].userid)
+      let userinfo = selectUser3(data.userId)
+      if(userinfo.eduid){
+        setStateUserinfo(d.data[0][0].userid)
+      }else {
+        localStorage.setItem('userid', userinfo.userid)
+        localStorage.setItem('isBjt', 1)
+        linkLogin()
+      }
     })
   }, [], { "type": "POST", "withCredentials": true });
 
@@ -258,6 +276,34 @@ const selectUser2 = (uid) => {
     }
 }
 
+const selectUser3 = async (uid) => {
+    // 拉取用户信息并处理
+    const requestUser = async () => {
+        try {
+            const res = await axios.get(`https://pbl.cocorobo.cn/api/pbl/selectUser?userid=${uid}`, { withCredentials: true });
+            console.log(res);
+            if (res && res.data && res.data.length && res.data[0].length && res.data[0][0].userid) {
+                // 拉取成功,存储用户信息
+                let userinfo = res.data[0][0];
+                return userinfo;
+            } else {
+                return await requestUser();
+            }
+        } catch (error) {
+            return await requestUser();
+        }
+    };
+
+    return await requestUser();
+}
+
+const setEduid = async (userid, eduId) => {
+  const res = await axios.get(`https://pbl.cocorobo.cn/api/pbl/setEduid?userid=${userid}&eduId=${eduId}`);
+  console.log(res);
+}
+
+
+
 const getUrlParam = (urlStr, urlKey) => {
   const url = new URL(urlStr) // 字符串转换成url格式
   const paramsStr = url.search.slice(1) // 获取'?'后面的参数字符串