!207 optimize request encapsulation logic
From: @hu-gang Reviewed-by: @Lostwayzxc Signed-off-by: @Lostwayzxc
This commit is contained in:
commit
7d8598558a
105
0002-set-the-default-language-for-requests.patch
Normal file
105
0002-set-the-default-language-for-requests.patch
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
From d18757fd6acf0315052267c8cf60061d9bd0285b Mon Sep 17 00:00:00 2001
|
||||||
|
From: Hu Gang <18768366022@163.com>
|
||||||
|
Date: Mon, 2 Dec 2024 15:43:31 +0800
|
||||||
|
Subject: [PATCH] fix: Coset the default language for requests
|
||||||
|
|
||||||
|
---
|
||||||
|
.eslintrc.js | 1 -
|
||||||
|
src/api/request.ts | 34 ++++++++++++++++++++--------------
|
||||||
|
src/views/account/Auth.vue | 2 +-
|
||||||
|
3 files changed, 21 insertions(+), 16 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/.eslintrc.js b/.eslintrc.js
|
||||||
|
index 5942158..b4dbe94 100644
|
||||||
|
--- a/.eslintrc.js
|
||||||
|
+++ b/.eslintrc.js
|
||||||
|
@@ -29,7 +29,6 @@ module.exports = {
|
||||||
|
},
|
||||||
|
plugins: ["@typescript-eslint", "vue"],
|
||||||
|
rules: {
|
||||||
|
- indent: ["error", 2],
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"@typescript-eslint/no-unused-expressions": 'off',
|
||||||
|
"vue/valid-define-props": "off",
|
||||||
|
diff --git a/src/api/request.ts b/src/api/request.ts
|
||||||
|
index 9644c2f..d7f93db 100644
|
||||||
|
--- a/src/api/request.ts
|
||||||
|
+++ b/src/api/request.ts
|
||||||
|
@@ -56,7 +56,7 @@ request.interceptors.request.use(
|
||||||
|
}
|
||||||
|
|
||||||
|
const { lang } = useLangStore()
|
||||||
|
- config.headers['Accept-Language'] = lang === 'zh_cn' ? 'zh' : 'en'
|
||||||
|
+ config.headers['Accept-Language'] = lang === 'en' ? 'en' : 'zh'
|
||||||
|
|
||||||
|
const aopsInfo = localStorage.getItem('aops')
|
||||||
|
if (aopsInfo) {
|
||||||
|
@@ -96,6 +96,7 @@ function dealBlobResponse(resp: AxiosResponse<any, any>) {
|
||||||
|
}
|
||||||
|
downloadBlobFile(resp.data, filename)
|
||||||
|
}
|
||||||
|
+let isAuthing = false
|
||||||
|
|
||||||
|
request.interceptors.response.use(
|
||||||
|
async (response: AxiosResponse<any, any>): Promise<any> => {
|
||||||
|
@@ -125,19 +126,23 @@ request.interceptors.response.use(
|
||||||
|
if (!code.toString().match(/^2\d{2}$/)) {
|
||||||
|
switch (Number(code)) {
|
||||||
|
case 1201:
|
||||||
|
- notification.error({
|
||||||
|
- message: `${t('account.sentence.validationFailed')}`,
|
||||||
|
- description: response.data.message,
|
||||||
|
- })
|
||||||
|
- setTimeout(async () => {
|
||||||
|
- const { clearInfo } = useAccountStore()
|
||||||
|
- const { getAuthRedirectUrl } = useAccountStore()
|
||||||
|
- const url = await getAuthRedirectUrl()
|
||||||
|
- if (url) {
|
||||||
|
- clearInfo()
|
||||||
|
- window.location.href = url
|
||||||
|
- }
|
||||||
|
- }, 1000)
|
||||||
|
+ if (!isAuthing) {
|
||||||
|
+ notification.error({
|
||||||
|
+ message: `${t('account.sentence.validationFailed')}`,
|
||||||
|
+ description: response.data.message,
|
||||||
|
+ })
|
||||||
|
+ isAuthing = true
|
||||||
|
+ setTimeout(async () => {
|
||||||
|
+ const { clearInfo } = useAccountStore()
|
||||||
|
+ const { getAuthRedirectUrl } = useAccountStore()
|
||||||
|
+ const url = await getAuthRedirectUrl()
|
||||||
|
+ if (url) {
|
||||||
|
+ clearInfo()
|
||||||
|
+ window.location.href = url
|
||||||
|
+ }
|
||||||
|
+ }, 1000)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
break
|
||||||
|
case 1207:
|
||||||
|
if (response.config.url !== `/accounts/refreshtoken`) {
|
||||||
|
@@ -189,6 +194,7 @@ request.interceptors.response.use(
|
||||||
|
}
|
||||||
|
return Promise.reject(result)
|
||||||
|
}
|
||||||
|
+ isAuthing = false
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
(error: AxiosError) => {
|
||||||
|
diff --git a/src/views/account/Auth.vue b/src/views/account/Auth.vue
|
||||||
|
index 55f81cc..4b8a33b 100644
|
||||||
|
--- a/src/views/account/Auth.vue
|
||||||
|
+++ b/src/views/account/Auth.vue
|
||||||
|
@@ -21,7 +21,7 @@ async function auth(code: string) {
|
||||||
|
type: res.type || '',
|
||||||
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
- router.push('/dashboard')
|
||||||
|
+ router.replace('/')
|
||||||
|
isAuthing.value = false
|
||||||
|
}, 1000)
|
||||||
|
} else {
|
||||||
|
--
|
||||||
|
2.33.0
|
||||||
|
|
||||||
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
Name: aops-hermes
|
Name: aops-hermes
|
||||||
Version: v2.1.1
|
Version: v2.1.1
|
||||||
Release: 2
|
Release: 3
|
||||||
Summary: Web for an intelligent diagnose frame
|
Summary: Web for an intelligent diagnose frame
|
||||||
License: MulanPSL2
|
License: MulanPSL2
|
||||||
URL: https://gitee.com/openeuler/%{name}
|
URL: https://gitee.com/openeuler/%{name}
|
||||||
Source0: %{name}-%{version}.tar.gz
|
Source0: %{name}-%{version}.tar.gz
|
||||||
Source1: node_modules.tar.gz
|
Source1: node_modules.tar.gz
|
||||||
Patch001: 0001-Modify-host-group-input-parameter-verification.patch
|
Patch001: 0001-Modify-host-group-input-parameter-verification.patch
|
||||||
|
Patch002: 0002-set-the-default-language-for-requests.patch
|
||||||
|
|
||||||
|
|
||||||
BuildRequires: nodejs
|
BuildRequires: nodejs
|
||||||
@ -37,6 +38,9 @@ cp -r deploy/aops-hermes.service %{buildroot}/usr/lib/systemd/system/
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Dec 2 2024 Hu gang<18768366022@163.com> - v2.1.1-3
|
||||||
|
- set the default language for requests
|
||||||
|
|
||||||
* Sat Nov 30 2024 Hu gang<18768366022@163.com> - v2.1.1-2
|
* Sat Nov 30 2024 Hu gang<18768366022@163.com> - v2.1.1-2
|
||||||
- modify host group input parameter verification
|
- modify host group input parameter verification
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user