diff --git a/.env b/.env
index ef0d2d3..a089ef7 100644
--- a/.env
+++ b/.env
@@ -18,19 +18,17 @@ 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://192.168.101.81:9999 # 邓-本地
# 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 # 信创线上
-# VITE_IMAGE_BASE_PATH = https://stgl.pj.gov.cn/api # 域名线上
+VITE_IMAGE_BASE_PATH = https://stgl.pj.gov.cn/api # 域名线上
# ******************** start 开发环境 start ****************
#VITE_APP_DEV_SERVICE = http://59.202.170.152:81/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 = 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 9f0d742..75f3258 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,4 +1,5 @@
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/sheep/api/user.ts b/src/sheep/api/user.ts
index 7db0e42..376a2a7 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,
@@ -87,4 +87,13 @@ export default {
},
})
},
+ // 判断是否是商户角色
+ isMerchant: (): Promise =>
+ request({
+ url: "/admin/role/isMchUser",
+ method: "GET",
+ 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()
}
}
}
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