From 27f5a5fb8ea20288cbced3bd4d8590b74dca98f0 Mon Sep 17 00:00:00 2001 From: zjf <1799650030@qq.com> Date: Tue, 26 Nov 2024 11:44:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E7=82=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/tabbar/my.vue | 49 ++++++++++++++++++++++++++++++++++------- src/sheep/api/user.ts | 11 ++++++++- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/pages/tabbar/my.vue b/src/pages/tabbar/my.vue index 8bafdfb..74f845a 100644 --- a/src/pages/tabbar/my.vue +++ b/src/pages/tabbar/my.vue @@ -23,6 +23,29 @@ const state = reactive({ onLoad((options) => { + window.CP2.getAppInfo().then((res) => { + console.log(res); + if (res.code==1){ + //诗画 + console.log("诗画环境") + window.CP2.getUserInfo().then((res) => { + let accountId=res.data.accountId; + let sessionId=res.sessionId; + doLogin(1,null,accountId,sessionId) + }); + }else { + //浙政钉或者h5 + const url = window.location.href; + const params = new URL(url).searchParams; + const token = params.get('uabaseToken'); // 获取 uabaseToken 参数值 + console.log('Token:', token); + if (null!=token){ + //浙政钉 + doLogin(2,token,null,null) + } + + } + }); }); onShow(() => { getUserInfo() @@ -36,7 +59,7 @@ const getUserInfo = () => { } } -const doLogin = async () => { +const doLogin = async (loginType,token, accountId, sessionId) => { const tokenKey = constant.storageConstant.TOKEN const userInfoKey = constant.storageConstant.USERINFO const tokenStorage = uni.getStorageSync(tokenKey) @@ -46,12 +69,23 @@ const doLogin = async () => { title: '登录中...', mask: true }); - - const url = window.location.href; - const params = new URL(url).searchParams; - const token = params.get('uabaseToken'); // 获取 uabaseToken 参数值 - console.log('Token:', token); - const { data: authData } = await userApi.auth(token); + let authData; + if (loginType==1){ + // 诗画 + const params = { + accountId:accountId, + sessionId:sessionId + } + const response = await userApi.authsh(params); + authData = response.data; + }else if (loginType==2){ + //浙政钉 + const response = await userApi.auth(token); + authData = response.data; + }else { + //后期手机号+验证码登录 + } + // const {data: authData} = await userApi.auth(token); uni.setStorageSync(tokenKey, authData) const { data: userData } = await userApi.userInfo(); uni.setStorageSync(userInfoKey, userData) @@ -74,7 +108,6 @@ const doLogout = async () => { uni.hideLoading() uni.showToast({ title: '退出登录成功', icon: "none" }); } - diff --git a/src/sheep/api/user.ts b/src/sheep/api/user.ts index 2c80c17..ce770b1 100644 --- a/src/sheep/api/user.ts +++ b/src/sheep/api/user.ts @@ -20,7 +20,16 @@ export default { loadingMsg: "授权中", }, }), - + authsh: (params: any) => + request({ + url: `/sys/auth/shjnsso`, + method: "POST", + custom: { + showLoading: false, + loadingMsg: "授权中", + }, + data:params, + }), refreshToken: (params: any) => request({ url: `/sys/auth/refresh-token`,