From ce4d63be55efa0e2489e4c6356c1b36a7f5f112f Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Thu, 27 Apr 2023 16:25:08 +0800 Subject: [PATCH 01/10] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96oauth=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 8 ++++--- src/utils/request.ts | 19 +++++++++++----- src/views/oauth/index.vue | 47 ++++++++++++++++++++++++--------------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 1ecbc43e..fb09a885 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,5 +1,5 @@ import { createRouter, createWebHashHistory } from 'vue-router' -import menus, { AccountCenterBindPath, InitHomePath, LoginPath } from './menu' +import menus, { AccountCenterBindPath, InitHomePath, LoginPath, OauthPath } from './menu' import { cleanToken, getToken } from '@/utils/comm' import { useUserInfo } from '@/store/userInfo' import { useSystem } from '@/store/system' @@ -14,12 +14,14 @@ const router = createRouter({ } }) -const filterPath = [ InitHomePath, AccountCenterBindPath ] +const filterPath = [ InitHomePath ] +const noTokenPath = [ AccountCenterBindPath, OauthPath ] router.beforeEach((to, from, next) => { // TODO 切换路由取消请求 const token = getToken() - if (to.path === AccountCenterBindPath) { + console.log(to.path, noTokenPath.includes(to.path)) + if (noTokenPath.includes(to.path)) { next() } else if (token) { if (to.path === LoginPath) { diff --git a/src/utils/request.ts b/src/utils/request.ts index a74fb062..c7ffca50 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -13,7 +13,16 @@ interface AxiosResponseRewrite extends AxiosResponse { export const SUCCESS_CODE = 200 // 成功代码 -const filterApiUrl = ['/system/version', '/system/config/front', '/authorize/captcha/config', '/application/sso/_all', '/authorize/captcha/image', '/application/sso/bind-code', '/authorize/login'] +const filterApiUrl = [ + '/system/version', + '/system/config/front', + '/authorize/captcha/config', + '/application/sso/_all', + '/authorize/captcha/image', + '/application/sso/bind-code', + '/authorize/login', + '/application/' +] export const request = axios.create({ withCredentials: false, @@ -148,10 +157,10 @@ const errorHandler = (error: any) => { } else if (status === 401) { showNotification('Unauthorized', '用户未登录', '401') setTimeout(() => { - cleanToken() - router.replace({ - path: LoginPath - }) + // cleanToken() + // router.replace({ + // path: LoginPath + // }) }, 0) } else if (status === 404) { showNotification(error?.code, error?.response?.data?.message, '404') diff --git a/src/views/oauth/index.vue b/src/views/oauth/index.vue index 547796f1..4e431e68 100644 --- a/src/views/oauth/index.vue +++ b/src/views/oauth/index.vue @@ -74,7 +74,7 @@ import { TOKEN_KEY } from '@/utils/variable' import { config, code, getOAuth2, initApplication, authLogin } from '@/api/login' import { getMe_api } from '@/api/home' -import { getImage } from '@/utils/comm' +import { getImage, getToken } from '@/utils/comm' const spinning = ref(true) const isLogin = ref(false) @@ -106,11 +106,14 @@ const captcha = reactive<{base64?: string, key?: string }>({ const getApplication = async (clientId: string) => { const res = await initApplication(clientId) - if (res.success) { + if (res.success && res.result) { appName.value = res.result.name } } +/** + * 获取验证码配置 + */ const getCode = async () => { const resp = await config() if (resp.result?.enabled) { @@ -138,26 +141,33 @@ const changeAccount = () => { } const getLoginUser = async (data?: any) => { - const res = await getMe_api() - if (res.success) { - userName.value = res.result?.user.name - isLogin.value = true - getApplication(data.client_id || params.value.client_id) - if (data.internal === 'true' || internal.value === 'true') { // 是否走oauth2 - goOAuth2Fn(data) + console.log(getToken()) + if (getToken()) { // 未登录 + const res = await getMe_api() + if (res.success) { + userName.value = res.result?.user.name + isLogin.value = true + getApplication(data.client_id || params.value.client_id) + if (data.internal === 'true' || internal.value === 'true') { // 是否走oauth2 + goOAuth2Fn(data) + } + } else if (res.status === 401) { + setTimeout(() => { + spinning.value = false + }) + getCode() + getApplication(data.client_id || params.value.client_id) + } else { + setTimeout(() => { + spinning.value = false + }) } - } else if (res.status === 401) { - setTimeout(() => { - spinning.value = false - }) - getCode() - getApplication(data.client_id || params.value.client_id) } else { + getApplication(data.client_id || params.value.client_id) setTimeout(() => { spinning.value = false }) } - } const getQueryVariable = (variable: any) => { @@ -178,9 +188,9 @@ const doLogin = async () => { ...formModel }) if (res.success) { - getLoginUser() const token = res.result.token localStorage.setItem(TOKEN_KEY, token) + getLoginUser() goOAuth2Fn() } else { getCode() @@ -189,6 +199,7 @@ const doLogin = async () => { const initPage = async () => { let redirectUrl + // 获取url中的配置信息 const items = { client_id: getQueryVariable('client_id'), state: getQueryVariable('state'), @@ -204,7 +215,7 @@ const initPage = async () => { redirectUrl = items.redirect_uri console.log(origin, items.redirect_uri) } - + // 获取用户信息 getLoginUser({ ...items, internal: getQueryVariable('internal'), From b59ad04c37280b9e403a661ac60ba5e90db53537 Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Thu, 27 Apr 2023 17:51:44 +0800 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Diot=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E6=97=A0=E6=B3=95=E7=99=BB=E5=BD=95=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.ts | 2 +- src/router/index.ts | 1 - src/views/oauth/index.vue | 68 ++++++++++++++++++++++++++------------- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/config/config.ts b/config/config.ts index 9a3c3b8a..6b94b56b 100644 --- a/config/config.ts +++ b/config/config.ts @@ -6,7 +6,7 @@ export default { title: 'Jetlinks', // 浏览器标签页title layout: { title: '物联网平台', // 平台title - logo: '/icons/icon-192x192.png', // 平台logo + logo: '/logo.png', // 平台logo siderWidth: 208, // 左侧菜单栏宽度 headerHeight: 48, // 头部高度 collapsedWidth: 48, diff --git a/src/router/index.ts b/src/router/index.ts index fb09a885..1641803e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -20,7 +20,6 @@ const noTokenPath = [ AccountCenterBindPath, OauthPath ] router.beforeEach((to, from, next) => { // TODO 切换路由取消请求 const token = getToken() - console.log(to.path, noTokenPath.includes(to.path)) if (noTokenPath.includes(to.path)) { next() } else if (token) { diff --git a/src/views/oauth/index.vue b/src/views/oauth/index.vue index 4e431e68..6fc36ac6 100644 --- a/src/views/oauth/index.vue +++ b/src/views/oauth/index.vue @@ -14,9 +14,10 @@
+

授权登录

- 您正在授权登录,{{ appName }}将获得以下权限: + 您正在授权登录, {{ appName }} 将获得以下权限:
  • 关联{{userName}}账号
  • @@ -32,15 +33,16 @@
    +

    授权登录