From 64636d0eab6b5d8932d8ff927a17b51ddf9b01bf Mon Sep 17 00:00:00 2001 From: weiwei Date: Tue, 1 Apr 2025 14:19:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AF=97=E7=94=BB=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=BA=AB=E4=BB=BD=E9=80=89=E6=8B=A9=E5=92=8C?= =?UTF-8?q?tabbar=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 241 +++++++++++++++++++------------ src/pages.json | 25 ++-- src/pages/tabbar/userRole.vue | 3 - src/pages/user/userRole.vue | 54 +++++++ src/static/page/merchantRole.svg | 33 +++++ src/static/page/userRole.svg | 21 +++ 6 files changed, 270 insertions(+), 107 deletions(-) delete mode 100644 src/pages/tabbar/userRole.vue create mode 100644 src/pages/user/userRole.vue create mode 100644 src/static/page/merchantRole.svg create mode 100644 src/static/page/userRole.svg diff --git a/src/App.vue b/src/App.vue index 9f0d742..d9dc173 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,7 +6,6 @@ import isDevEnv from "./sheep/utils/isDevEnv" // onShow(() => {}) // onHide(() => {}) -// zhezhengding:浙政钉 | shihua:诗画 const tabbar = [ { pagePath: "pages/tabbar/canteen", @@ -14,7 +13,7 @@ const tabbar = [ iconPath: "/static/tabbar/canteen.png", selectedIconPath: "/static/tabbar/canteen-select.png", authPath: ["pages/tabbar/canteen"], - auth: ["zhezhengding"], + auth: [], }, { pagePath: "pages/tabbar/selfMerchant", @@ -22,7 +21,7 @@ const tabbar = [ iconPath: "/static/tabbar/selfMerchant.png", selectedIconPath: "/static/tabbar/selfMerchant-select.png", authPath: ["pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: [], }, { pagePath: "pages/tabbar/coopMerchant", @@ -30,7 +29,7 @@ const tabbar = [ iconPath: "/static/tabbar/coopMerchant.png", selectedIconPath: "/static/tabbar/coopMerchant-select.png", authPath: ["pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: ["user"], }, { pagePath: "pages/tabbar/order", @@ -38,7 +37,7 @@ const tabbar = [ iconPath: "/static/tabbar/order.png", selectedIconPath: "/static/tabbar/order-select.png", authPath: ["pages/tabbar/canteen", "pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: ["user"], }, { pagePath: "pages/tabbar/flowStatistics", @@ -46,7 +45,7 @@ const tabbar = [ iconPath: "/static/tabbar/order.png", selectedIconPath: "/static/tabbar/order-select.png", authPath: [], - auth: [], + auth: ["merchant"], }, { pagePath: "pages/tabbar/individualOrder", @@ -54,7 +53,7 @@ const tabbar = [ iconPath: "/static/tabbar/order.png", selectedIconPath: "/static/tabbar/order-select.png", authPath: [], - auth: [], + auth: ["merchant"], }, { pagePath: "pages/tabbar/my", @@ -62,112 +61,172 @@ const tabbar = [ iconPath: "/static/tabbar/my.png", selectedIconPath: "/static/tabbar/my-select.png", authPath: ["pages/tabbar/canteen", "pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: ["user", "merchant"], }, ] export default { onLaunch() { console.log("环境判断") - // ;(window as any).CP2.getUserInfo().then((res) => { - // console.log(res) - // if (res.code == 0) { - // uni.showToast({ title: res.msg || "当前环境不支持", icon: "none" }) - // } - // }) - - const launchParam = new URL(window.location.href).searchParams.get("launchParam") - console.log("app launch 启动路径参数", launchParam) - switch (launchParam) { - case "canteen": - uni.switchTab({ url: "/pages/tabbar/canteen" }) - break - case "selfMerchant": - uni.switchTab({ url: "/pages/tabbar/selfMerchant" }) - break - default: - break - } + // 诗画浦江获取用户信息进行环境判断 + ;(window as any).CP2.getUserInfo().then((res) => { + if (res.code !== 0) { + // 不是诗画环境 + const launchParam = new URL(window.location.href).searchParams.get("launchParam") + console.log("app launch 启动路径参数", launchParam) + switch (launchParam) { + case "canteen": + uni.switchTab({ url: "/pages/tabbar/canteen" }) + break + case "selfMerchant": + uni.switchTab({ url: "/pages/tabbar/selfMerchant" }) + break + default: + break + } + } else { + // 是诗画环境 + return uni.redirectTo({ url: "/pages/user/userRole" }) + } + }) }, onShow() {}, onHide() {}, methods: { _initTabbar() { - // console.log("环境判断") - // let appEnv = 1 // 1:浙政钉 2:诗画 - // const launchPath = uni.getLaunchOptionsSync().path // console.log("启动路径", launchPath) const launchParam = new URL(window.location.href).searchParams.get("launchParam") console.log("tabbar launch 启动路径参数", launchParam) - if (isDevEnv()) { - tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: true, - }) - }) - } else { - switch (launchParam) { - case "canteen": - tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { - if (authPath.includes("pages/tabbar/canteen")) { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: true, - }) - } else { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: false, - }) - } + // 诗画浦江获取用户信息进行环境判断 + ;(window as any).CP2.getUserInfo().then((res) => { + if (res.code !== 0) { + // 不是诗画环境 + if (isDevEnv()) { + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) }) - break - case "selfMerchant": - tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { - if (authPath.includes("pages/tabbar/selfMerchant")) { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: true, + } else { + switch (launchParam) { + case "canteen": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { + if (authPath.includes("pages/tabbar/canteen")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } }) - } else { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: false, + break + case "selfMerchant": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { + if (authPath.includes("pages/tabbar/selfMerchant")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } }) - } - }) - break - default: - uni.hideTabBar() - uni.showToast({ title: "启动参数不合法", icon: "none" }) - break + break + default: + uni.hideTabBar() + uni.showToast({ title: "启动参数不合法", icon: "none" }) + break + } + } + } else { + // 是诗画环境 + const userRole = uni.getStorageSync("userRole") + switch (userRole) { + case "user": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { + if (auth.includes("user")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } + }) + break + case "merchant": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { + if (auth.includes("merchant")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } + }) + break + default: + uni.hideTabBar() + uni.showToast({ title: "用户身份未确认", icon: "none" }) + break + } } - } + }) }, }, } diff --git a/src/pages.json b/src/pages.json index 191b91e..b193088 100644 --- a/src/pages.json +++ b/src/pages.json @@ -9,13 +9,6 @@ } }, "pages": [ - // { - // "path": "pages/tabbar/userRole", - // "style": { - // "navigationBarTitleText": "用户角色", - // "disableScroll": true - // } - // }, { "path": "pages/tabbar/canteen", "style": { @@ -292,6 +285,18 @@ } ] }, + { + "root": "pages/user", + "pages": [ + { + "path": "userRole", + "style": { + "navigationBarTitleText": "用户身份", + "disableScroll": true + } + } + ] + }, { "root": "pages/pay", "pages": [ @@ -321,12 +326,6 @@ }, "tabBar": { "list": [ - // { - // "pagePath": "pages/tabbar/userRole", - // "text": "", - // "iconPath": "", - // "selectedIconPath": "" - // }, { "pagePath": "pages/tabbar/canteen", "text": "", diff --git a/src/pages/tabbar/userRole.vue b/src/pages/tabbar/userRole.vue deleted file mode 100644 index bf91dd0..0000000 --- a/src/pages/tabbar/userRole.vue +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/pages/user/userRole.vue b/src/pages/user/userRole.vue new file mode 100644 index 0000000..5e096cc --- /dev/null +++ b/src/pages/user/userRole.vue @@ -0,0 +1,54 @@ + + + diff --git a/src/static/page/merchantRole.svg b/src/static/page/merchantRole.svg new file mode 100644 index 0000000..0ec265d --- /dev/null +++ b/src/static/page/merchantRole.svg @@ -0,0 +1,33 @@ + + + + + + + + \ No newline at end of file diff --git a/src/static/page/userRole.svg b/src/static/page/userRole.svg new file mode 100644 index 0000000..613b7b4 --- /dev/null +++ b/src/static/page/userRole.svg @@ -0,0 +1,21 @@ + + + + \ No newline at end of file From c64d88ee3a04ad54f54b0e1f131cdfed823ad18c Mon Sep 17 00:00:00 2001 From: weiwei Date: Tue, 1 Apr 2025 16:06:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AF=97=E7=94=BB=E5=8D=95=E7=82=B9?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 8 +- src/pages/tabbar/my.vue | 41 +++--- src/sheep/api/user.ts | 4 +- src/sheep/utils/request.ts | 266 ++++++++++++++++++++++++++----------- 4 files changed, 218 insertions(+), 101 deletions(-) diff --git a/src/App.vue b/src/App.vue index d9dc173..31363ba 100644 --- a/src/App.vue +++ b/src/App.vue @@ -69,8 +69,8 @@ export default { onLaunch() { console.log("环境判断") // 诗画浦江获取用户信息进行环境判断 - ;(window as any).CP2.getUserInfo().then((res) => { - if (res.code !== 0) { + ;(window as any).CP2.getAppInfo().then((res) => { + if (res.code == 0) { // 不是诗画环境 const launchParam = new URL(window.location.href).searchParams.get("launchParam") console.log("app launch 启动路径参数", launchParam) @@ -102,8 +102,8 @@ export default { console.log("tabbar launch 启动路径参数", launchParam) // 诗画浦江获取用户信息进行环境判断 - ;(window as any).CP2.getUserInfo().then((res) => { - if (res.code !== 0) { + ;(window as any).CP2.getAppInfo().then((res) => { + if (res.code == 0) { // 不是诗画环境 if (isDevEnv()) { tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { diff --git a/src/pages/tabbar/my.vue b/src/pages/tabbar/my.vue index a37bb6d..9477f37 100644 --- a/src/pages/tabbar/my.vue +++ b/src/pages/tabbar/my.vue @@ -75,13 +75,16 @@ const onTabLogin = () => (isDevEnv() ? router.jump("/pages/test/login") : checkA const loginMethods = { // 诗画环境登录 async shihuaLogin() { - // const appInfo = await (window as any).CP2.getAppInfo() - // if (appInfo.code !== 0) return false - - // const userInfo = await (window as any).CP2.getUserInfo() - // const { accountId, sessionId } = userInfo.data - // return doLogin(1, null, accountId, sessionId) - return false + const appInfo = await (window as any).CP2.getAppInfo() + if (appInfo.code == 0) return false + const userInfo = await (window as any).CP2.getUserInfo() + if (userInfo.code == 0) { + return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" }) + } else { + const { accountId, sessionId } = userInfo.data + return doLogin(1, "", accountId, sessionId) + // return doLogin(1, "", "67186e49d63fea141aad6772", "67186e49d63fea141aad6776") + } }, // 浙政钉登录 @@ -89,7 +92,7 @@ const loginMethods = { const params = new URL(window.location.href).searchParams const token = params.get("uabaseToken") if (token) { - return doLogin(2, token, null, null) + return doLogin(2, token, "", "") } return false }, @@ -113,7 +116,7 @@ const checkAppInfo = async () => { } // loginType 1:诗画登录 2:浙政钉登录 -const doLogin = async (loginType: number, token: string, accountId: string | null, sessionId: string | null) => { +const doLogin = async (loginType: number, token: string, accountId: string, sessionId: string) => { const tokenKey = constant.storageConstant.TOKEN const userInfoKey = constant.storageConstant.USERINFO const tokenStorage = uni.getStorageSync(tokenKey) @@ -121,14 +124,22 @@ const doLogin = async (loginType: number, token: string, accountId: string | nul switch (loginType) { case 1: // 诗画 - // const params = { - // accountId: accountId, - // sessionId: sessionId, - // } - // const response = await userApi.authsh(params) - // authData = response.data + uni.showLoading({ title: "登录中...", mask: true }) + const response = await userApi.authsh({ accountId, sessionId }) + if (response.code == 0) { + uni.setStorageSync(tokenKey, { accessToken: response.data.accessToken }) + uni.hideLoading() + uni.showToast({ title: "登录成功", icon: "none" }) + const { data: userData } = await userApi.userInfo() + uni.setStorageSync(userInfoKey, userData) + getStorageUserInfo() + } else { + uni.hideLoading() + uni.showToast({ title: "登录失败", icon: "none" }) + } break case 2: + // 浙政钉 if (isEmpty(tokenStorage) || isEmpty(userStorage)) { try { uni.showLoading({ title: "登录中...", mask: true }) diff --git a/src/sheep/api/user.ts b/src/sheep/api/user.ts index 7db0e42..c58e76a 100644 --- a/src/sheep/api/user.ts +++ b/src/sheep/api/user.ts @@ -38,9 +38,9 @@ export default { }), // 诗画授权 - authsh: (params: { accountId: string; sessionId: string }) => + authsh: (params: { accountId: string; sessionId: string }): Promise => request({ - url: `/sys/auth/shjnsso`, + url: `/thirdparty/thirdPartyOAth2/shjnsso`, method: "POST", custom: { showLoading: false, diff --git a/src/sheep/utils/request.ts b/src/sheep/utils/request.ts index 2ebeba6..ed26edf 100644 --- a/src/sheep/utils/request.ts +++ b/src/sheep/utils/request.ts @@ -64,32 +64,57 @@ const checkAndRefreshToken = async (tokenStorage: any) => { // console.log("现在的时间大于过期时间吗:", new Date().getTime() >= expiresDate) if (new Date().getTime() >= expiresDate) { - try { - uni.showLoading({ title: "加载中...", mask: true }) - const params = new URL(window.location.href).searchParams - const token = params.get("uabaseToken") - if (token) { - const res = await userApi.auth(token) - if (res?.code === 0) { - uni.setStorageSync(TOKEN_KEY, res.data) - } else { - uni.removeStorageSync(TOKEN_KEY) - uni.removeStorageSync(USER_INFO_KEY) - uni.showToast({ title: res.msg, icon: "none" }) + const appInfo = await (window as any).CP2.getAppInfo() + if (appInfo.code == 0) { + try { + uni.showLoading({ title: "加载中...", mask: true }) + const params = new URL(window.location.href).searchParams + const token = params.get("uabaseToken") + if (token) { + const res = await userApi.auth(token) + if (res?.code === 0) { + uni.setStorageSync(TOKEN_KEY, res.data) + } else { + uni.removeStorageSync(TOKEN_KEY) + uni.removeStorageSync(USER_INFO_KEY) + uni.showToast({ title: res.msg, icon: "none" }) + } } + } catch (error) { + uni.showToast({ title: "错误", icon: "none" }) + } finally { + uni.hideLoading() + } + } else { + // 诗画 + try { + uni.showLoading({ title: "登录中...", mask: true }) + const userInfo = await (window as any).CP2.getUserInfo() + if (userInfo.code == 0) { + return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" }) + } else { + const { accountId, sessionId } = userInfo.data + const response = await userApi.authsh({ accountId, sessionId }) + if (response.code == 0) { + uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken }) + uni.showToast({ title: "登录成功", icon: "none" }) + const { data: userData } = await userApi.userInfo() + uni.setStorageSync(USER_INFO_KEY, userData) + } else { + uni.showToast({ title: "获取用户信息失败", icon: "none" }) + } + } + } catch (error) { + uni.showToast({ title: "错误", icon: "none" }) + } finally { + uni.hideLoading() } - } catch (error) { - uni.showToast({ title: "错误", icon: "none" }) - } finally { - uni.hideLoading() } } } // 请求拦截器 http.interceptors.request.use(async (config) => { - console.log("请求之前") - const tokenStorage = uni.getStorageSync(TOKEN_KEY) const config_header: any = config?.header || {} @@ -113,7 +138,7 @@ http.interceptors.request.use(async (config) => { // 设置认证头 if ( - !config.url?.startsWith("/thirdparty/thirdPartyOAth2/zzdsso") && + !config.url?.startsWith("/thirdparty/thirdPartyOAth2") && config.url !== "/sys/auth/refresh-token" && config.url !== "/auth/oauth2/token" ) { @@ -127,24 +152,51 @@ http.interceptors.request.use(async (config) => { } } else { // token不存在,则发起登录 - const params = new URL(window.location.href).searchParams - const token = params.get("uabaseToken") + const appInfo = await (window as any).CP2.getAppInfo() + if (appInfo.code == 0) { + // 浙政钉 + const params = new URL(window.location.href).searchParams + const token = params.get("uabaseToken") + if (token) { + try { + uni.showLoading({ title: "加载中...", mask: true }) + const res = await userApi.auth(token) + if (res.code == 0) { + uni.setStorageSync(TOKEN_KEY, res.data) + const { data: userData } = await userApi.userInfo() + uni.setStorageSync(USER_INFO_KEY, userData) - if (token) { - try { - uni.showLoading({ title: "加载中...", mask: true }) - const res = await userApi.auth(token) - if (res.code == 0) { - uni.setStorageSync(TOKEN_KEY, res.data) - const { data: userData } = await userApi.userInfo() - uni.setStorageSync(USER_INFO_KEY, userData) - - const authHeader = getAuthHeader(tokenStorage) - if (authHeader) { - config_header.Authorization = authHeader + const authHeader = getAuthHeader(tokenStorage) + if (authHeader) { + config_header.Authorization = authHeader + } + } else { + uni.showToast({ title: "获取浙政钉用户信息失败", icon: "none" }) } + } catch (error) { + uni.showToast({ title: "错误", icon: "none" }) + } finally { + uni.hideLoading() + } + } + } else { + // 诗画 + try { + uni.showLoading({ title: "登录中...", mask: true }) + const userInfo = await (window as any).CP2.getUserInfo() + if (userInfo.code == 0) { + return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" }) } else { - uni.showToast({ title: "获取浙政钉用户信息失败", icon: "none" }) + const { accountId, sessionId } = userInfo.data + const response = await userApi.authsh({ accountId, sessionId }) + if (response.code == 0) { + uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken }) + uni.showToast({ title: "登录成功", icon: "none" }) + const { data: userData } = await userApi.userInfo() + uni.setStorageSync(USER_INFO_KEY, userData) + } else { + uni.showToast({ title: "获取用户信息失败", icon: "none" }) + } } } catch (error) { uni.showToast({ title: "错误", icon: "none" }) @@ -159,7 +211,7 @@ http.interceptors.request.use(async (config) => { }, Promise.reject) // 处理错误响应 -const handleErrorResponse = (response: any) => { +const handleErrorResponse = async (response: any) => { if (!response.config?.custom?.showError) return switch (response.data.code) { @@ -172,28 +224,55 @@ const handleErrorResponse = (response: any) => { }, 500) break case 424: - try { - const params = new URL(window.location.href).searchParams - const token = params.get("uabaseToken") - if (token) { - userApi.auth(token).then((res) => { - if (res?.code === 0) { - uni.setStorageSync(TOKEN_KEY, res.data) - } else { - uni.removeStorageSync(TOKEN_KEY) - uni.removeStorageSync(USER_INFO_KEY) - // uni.showToast({ title: "登录已过期", icon: "none" }) - return Promise.resolve({ - code: 1, - data: "登录已过期", - msg: "登录已过期", - }) - } - }) + const appInfo = await (window as any).CP2.getAppInfo() + if (appInfo.code == 0) { + try { + const params = new URL(window.location.href).searchParams + const token = params.get("uabaseToken") + if (token) { + userApi.auth(token).then((res) => { + if (res?.code === 0) { + uni.setStorageSync(TOKEN_KEY, res.data) + } else { + uni.removeStorageSync(TOKEN_KEY) + uni.removeStorageSync(USER_INFO_KEY) + // uni.showToast({ title: "登录已过期", icon: "none" }) + return Promise.resolve({ + code: 1, + data: "登录已过期", + msg: "登录已过期", + }) + } + }) + } + } catch (error) { + uni.hideLoading() + uni.showToast({ title: "错误", icon: "none" }) + } + } else { + // 诗画 + try { + uni.showLoading({ title: "登录中...", mask: true }) + const userInfo = await (window as any).CP2.getUserInfo() + if (userInfo.code == 0) { + return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" }) + } else { + const { accountId, sessionId } = userInfo.data + const response = await userApi.authsh({ accountId, sessionId }) + if (response.code == 0) { + uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken }) + uni.showToast({ title: "登录成功", icon: "none" }) + const { data: userData } = await userApi.userInfo() + uni.setStorageSync(USER_INFO_KEY, userData) + } else { + uni.showToast({ title: "获取用户信息失败", icon: "none" }) + } + } + } catch (error) { + uni.showToast({ title: "错误", icon: "none" }) + } finally { + uni.hideLoading() } - } catch (error) { - uni.hideLoading() - uni.showToast({ title: "错误", icon: "none" }) } break default: @@ -244,7 +323,7 @@ http.interceptors.response.use( return Promise.resolve(response.data) }, - (error) => { + async (error) => { // 处理 424 错误(token过期) if (error.statusCode === 424) { if (isDevEnv()) { @@ -255,30 +334,57 @@ http.interceptors.response.use( router.jump("/pages/test/login") return false } else { - try { - uni.showLoading({ title: "加载中...", mask: true }) - const params = new URL(window.location.href).searchParams - const token = params.get("uabaseToken") - if (token) { - userApi.auth(token).then((res) => { - if (res?.code === 0) { - uni.setStorageSync(TOKEN_KEY, res.data) - } else { - uni.removeStorageSync(TOKEN_KEY) - uni.removeStorageSync(USER_INFO_KEY) - // uni.showToast({ title: "登录已过期", icon: "none" }) - return Promise.resolve({ - code: 1, - data: "登录已过期", - msg: "登录已过期", - }) - } - }) + const appInfo = await (window as any).CP2.getAppInfo() + if (appInfo.code == 0) { + try { + uni.showLoading({ title: "加载中...", mask: true }) + const params = new URL(window.location.href).searchParams + const token = params.get("uabaseToken") + if (token) { + userApi.auth(token).then((res) => { + if (res?.code === 0) { + uni.setStorageSync(TOKEN_KEY, res.data) + } else { + uni.removeStorageSync(TOKEN_KEY) + uni.removeStorageSync(USER_INFO_KEY) + // uni.showToast({ title: "登录已过期", icon: "none" }) + return Promise.resolve({ + code: 1, + data: "登录已过期", + msg: "登录已过期", + }) + } + }) + } + } catch (error) { + uni.showToast({ title: "错误", icon: "none" }) + } finally { + uni.hideLoading() + } + } else { + // 诗画 + try { + uni.showLoading({ title: "登录中...", mask: true }) + const userInfo = await (window as any).CP2.getUserInfo() + if (userInfo.code == 0) { + return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" }) + } else { + const { accountId, sessionId } = userInfo.data + const response = await userApi.authsh({ accountId, sessionId }) + if (response.code == 0) { + uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken }) + uni.showToast({ title: "登录成功", icon: "none" }) + const { data: userData } = await userApi.userInfo() + uni.setStorageSync(USER_INFO_KEY, userData) + } else { + uni.showToast({ title: "获取用户信息失败", icon: "none" }) + } + } + } catch (error) { + uni.showToast({ title: "错误", icon: "none" }) + } finally { + uni.hideLoading() } - } catch (error) { - uni.showToast({ title: "错误", icon: "none" }) - } finally { - uni.hideLoading() } } } From 374717bc5c20985f16d65b132b0fd4d7d519e05b Mon Sep 17 00:00:00 2001 From: weiwei Date: Tue, 1 Apr 2025 20:13:36 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=95=86=E6=88=B7=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 -- src/App.vue | 21 ++++++++++++++++++--- src/sheep/api/user.ts | 9 +++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.env b/.env index 0638fa6..a089ef7 100644 --- a/.env +++ b/.env @@ -19,7 +19,6 @@ VITE_OAUTH2_APP_CLIENT='mini:mini' # 图片访问基础地址 #VITE_IMAGE_BASE_PATH = http://localhost:9999 # VITE_IMAGE_BASE_PATH = http://192.168.101.81:9999 # 邓-本地 -# VITE_IMAGE_BASE_PATH = https://123.156.230.15:8089/api # 线上 # VITE_IMAGE_BASE_PATH = http://220.191.229.171:8090/api # 线上 # VITE_IMAGE_BASE_PATH = http://pjcloud.center.takin.cc # 张 #VITE_IMAGE_BASE_PATH = http://59.202.170.152:81/api # 信创线上 @@ -30,7 +29,6 @@ VITE_IMAGE_BASE_PATH = https://stgl.pj.gov.cn/api # 域名线上 VITE_APP_DEV_SERVICE = https://stgl.pj.gov.cn/api # 域名线上 # VITE_APP_DEV_SERVICE = http://192.168.101.81:9999 # 邓-本地 # VITE_APP_DEV_SERVICE = http://127.0.0.1:9999 -# VITE_APP_DEV_SERVICE = http://123.156.230.15:8089/api/ # 线上 # VITE_APP_DEV_SERVICE = http://220.191.229.171:8090/api # 线上 # VITE_APP_DEV_SERVICE = http://localhost:9999 # ******************** end 开发环境 end ******************** diff --git a/src/App.vue b/src/App.vue index 31363ba..75f3258 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,4 +1,5 @@