浏览代码

登录问题

lsc 1 周之前
父节点
当前提交
635a23908d
共有 1 个文件被更改,包括 33 次插入0 次删除
  1. 33 0
      src/App.vue

+ 33 - 0
src/App.vue

@@ -20,6 +20,7 @@ onMounted(() => {
   // 通过 code 获取登录信息
   let isGrantCode = getUrlParam(window.parent.location.href, 'grant_code')
   let ticket = getUrlParam(window.parent.location.href, 'ticket')
+  let userid = getUrlParam(window.parent.location.href, 'userid')
   axios.defaults.headers = { 'content-type': 'application/json;charset=utf-8' }
  
   if (isGrantCode) {
@@ -57,6 +58,8 @@ onMounted(() => {
           top.location.href = "https://bjt.baoan.edu.cn/manage/?baojiaotong=1&service=https://cloud.cocorobo.cn/ai.html"
         }
       })
+  }else if(userid){
+    selectUser2(userid)
   } else {
     linkLogin()
   }
@@ -207,6 +210,36 @@ const selectUser = (uid) => {
     }
 }
 
+const selectUser2 = (uid) => {
+    // 优先使用已存在的用户信息
+    var userInfo = topUserInfo.value;
+    var panId = userInfo && userInfo.accountNumber;
+    if (panId) {
+        return;
+    }
+
+    // 拉取用户信息并处理
+    const requestUser = () => {
+      axios.get(`https://pbl.cocorobo.cn/api/pbl/selectUser?userid=${uid}`)
+        .then(res => {
+            if (res && res.value && res.value.length && res.value[0].length && res.value[0][0].userid) {
+                // 拉取成功,存储用户信息
+                isShow.value = false;
+                topUserInfo.value = res.value[0][0];
+                store.setUserInfo(res.value[0][0]);
+            } else {
+                requestUser();
+            }
+      })
+    };
+
+    try {
+        requestUser();
+    } catch (error) {
+        requestUser();
+    }
+}
+
 const getUrlParam = (urlStr, urlKey) => {
   const url = new URL(urlStr) // 字符串转换成url格式
   const paramsStr = url.search.slice(1) // 获取'?'后面的参数字符串