|
@@ -14,11 +14,13 @@ const Current = userCurrent()
|
|
const name = ref('')
|
|
const name = ref('')
|
|
const isShow = ref(true)
|
|
const isShow = ref(true)
|
|
const setTimeState = ref(null)
|
|
const setTimeState = ref(null)
|
|
|
|
+const topUserInfo = ref({})
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
// 通过 code 获取登录信息
|
|
// 通过 code 获取登录信息
|
|
let isGrantCode = getUrlParam(window.parent.location.href, 'grant_code')
|
|
let isGrantCode = getUrlParam(window.parent.location.href, 'grant_code')
|
|
let ticket = getUrlParam(window.parent.location.href, 'ticket')
|
|
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' }
|
|
axios.defaults.headers = { 'content-type': 'application/json;charset=utf-8' }
|
|
|
|
|
|
if (isGrantCode) {
|
|
if (isGrantCode) {
|
|
@@ -56,6 +58,8 @@ onMounted(() => {
|
|
top.location.href = "https://bjt.baoan.edu.cn/manage/?baojiaotong=1&service=https://cloud.cocorobo.cn/ai.html"
|
|
top.location.href = "https://bjt.baoan.edu.cn/manage/?baojiaotong=1&service=https://cloud.cocorobo.cn/ai.html"
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+ }else if(userid){
|
|
|
|
+ selectUser2(userid)
|
|
} else {
|
|
} else {
|
|
linkLogin()
|
|
linkLogin()
|
|
}
|
|
}
|
|
@@ -153,14 +157,15 @@ const userInfo2 = (data) => {
|
|
}
|
|
}
|
|
|
|
|
|
const setStateUserinfo = (userid) => {
|
|
const setStateUserinfo = (userid) => {
|
|
|
|
+ selectUser(userid)
|
|
// setTimeState
|
|
// setTimeState
|
|
- setTimeState.value = setInterval(() => {
|
|
|
|
- if (JSON.stringify(top.US.userInfo) != '{}') {
|
|
|
|
- // store.user = top.US.userInfo
|
|
|
|
- settimeoutUserinfo()
|
|
|
|
- clearInterval(setTimeState.value)
|
|
|
|
- }
|
|
|
|
- }, 1000)
|
|
|
|
|
|
+ // setTimeState.value = setInterval(() => {
|
|
|
|
+ // if (JSON.stringify(top.US.userInfo) != '{}') {
|
|
|
|
+ // // store.user = top.US.userInfo
|
|
|
|
+ // settimeoutUserinfo()
|
|
|
|
+ // clearInterval(setTimeState.value)
|
|
|
|
+ // }
|
|
|
|
+ // }, 1000)
|
|
}
|
|
}
|
|
|
|
|
|
const settimeoutUserinfo = () => {
|
|
const settimeoutUserinfo = () => {
|
|
@@ -171,6 +176,71 @@ const settimeoutUserinfo = () => {
|
|
}, 1000)
|
|
}, 1000)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 优化selectUser,结合settimeoutUserinfo的逻辑,统一用户信息拉取和存储
|
|
|
|
+const selectUser = (uid) => {
|
|
|
|
+ // 优先使用已存在的用户信息
|
|
|
|
+ var userInfo = topUserInfo.value;
|
|
|
|
+ var panId = userInfo && userInfo.accountNumber;
|
|
|
|
+ if (panId) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 拉取用户信息并处理
|
|
|
|
+ const requestUser = () => {
|
|
|
|
+ top.U.A.Request(`${top.US.Config.pbl}selectUser?userid=${uid}`, [], function (res) {
|
|
|
|
+ if (res && res.value && res.value.length && res.value[0].length && res.value[0][0].userid) {
|
|
|
|
+ // 拉取成功,存储用户信息
|
|
|
|
+ isShow.value = false;
|
|
|
|
+ top.US.userInfo = res.value[0][0];
|
|
|
|
+ topUserInfo.value = res.value[0][0];
|
|
|
|
+ top.U.UF.Cookie.set("cocoroboLoginType=2");
|
|
|
|
+ store.setUserInfo(res.value[0][0]);
|
|
|
|
+ } else {
|
|
|
|
+ top.U.alert("获取用户信息失败,正在重试!");
|
|
|
|
+ requestUser();
|
|
|
|
+ }
|
|
|
|
+ }, [], { "type": "GET", "withCredentials": true });
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ requestUser();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ top.U.alert("登录失败,正在重试!");
|
|
|
|
+ requestUser();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+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 => {
|
|
|
|
+ console.log(res);
|
|
|
|
+ if (res && res.data && res.data.length && res.data[0].length && res.data[0][0].userid) {
|
|
|
|
+ // 拉取成功,存储用户信息
|
|
|
|
+ isShow.value = false;
|
|
|
|
+ topUserInfo.value = res.data[0][0];
|
|
|
|
+ store.setUserInfo(res.data[0][0]);
|
|
|
|
+ } else {
|
|
|
|
+ requestUser();
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ requestUser();
|
|
|
|
+ } catch (error) {
|
|
|
|
+ requestUser();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
const getUrlParam = (urlStr, urlKey) => {
|
|
const getUrlParam = (urlStr, urlKey) => {
|
|
const url = new URL(urlStr) // 字符串转换成url格式
|
|
const url = new URL(urlStr) // 字符串转换成url格式
|
|
const paramsStr = url.search.slice(1) // 获取'?'后面的参数字符串
|
|
const paramsStr = url.search.slice(1) // 获取'?'后面的参数字符串
|