diff --git a/sgzb-ui/src/App.vue b/sgzb-ui/src/App.vue index ba8416e6..08a0b283 100644 --- a/sgzb-ui/src/App.vue +++ b/sgzb-ui/src/App.vue @@ -16,6 +16,7 @@ import ThemePicker from '@/components/ThemePicker' import Notice from '@/components/Notice' import { getHomeNoticeApi } from '@/api/system/notice.js' import { getToken } from '@/utils/auth' +import { getConfigApi } from '@/utils/config' export default { name: 'App', @@ -42,6 +43,10 @@ export default { noticeList: [], } }, + created() { + // 获取配置信息 + getConfigApi() + }, updated() { // 判断是否需要获取通知信息 if ( diff --git a/sgzb-ui/src/api/login.js b/sgzb-ui/src/api/login.js index 6fdd2799..173be249 100644 --- a/sgzb-ui/src/api/login.js +++ b/sgzb-ui/src/api/login.js @@ -121,3 +121,10 @@ export function checkPasswordStatusApi(data) { }) } +// 获取系统配置 +export const getConfig = () => { + return request({ + url: '/auth/getConfig', + method: 'get' + }) +} \ No newline at end of file diff --git a/sgzb-ui/src/utils/config.js b/sgzb-ui/src/utils/config.js new file mode 100644 index 00000000..05520025 --- /dev/null +++ b/sgzb-ui/src/utils/config.js @@ -0,0 +1,11 @@ +import { getConfig } from '@/api/login' +export function getConfigApi() { + getConfig() + .then((response) => { + console.log(response) + localStorage.setItem('systemConfig', JSON.stringify(response.data)) + }) + .catch((error) => { + console.error('Failed to fetch config:', error) + }) +} diff --git a/sgzb-ui/src/utils/request.js b/sgzb-ui/src/utils/request.js index 58c6db37..da376cca 100644 --- a/sgzb-ui/src/utils/request.js +++ b/sgzb-ui/src/utils/request.js @@ -8,6 +8,10 @@ import cache from '@/plugins/cache' import { saveAs } from 'file-saver' import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm' +const systemConfig = JSON.parse(localStorage.getItem('systemConfig')) || { + requestConfig: { encryptRequest: false, checkIntegrity: false, encryptResponse: false } +}; + let downloadLoadingInstance; // 是否显示重新登录 export let isRelogin = { show: false }; @@ -27,11 +31,11 @@ service.interceptors.request.use(config => { const checkIntegrity = false const encryptResponse = false //入参加密 - config.headers['encryptRequest'] = encryptRequest ? 'true' : 'false' + config.headers['encryptRequest'] = systemConfig.requestConfig.encryptRequest && encryptRequest ? 'true' : 'false' // 数据完整性校验 - config.headers['checkIntegrity'] = checkIntegrity ? 'true' : 'false' + config.headers['checkIntegrity'] = systemConfig.requestConfig.checkIntegrity && checkIntegrity ? 'true' : 'false' //回参是否加密 - config.headers['encryptResponse'] = encryptResponse ? 'true' : 'false' + config.headers['encryptResponse'] = systemConfig.requestConfig.encryptResponse && encryptResponse ? 'true' : 'false' // console.log('🚀 ~ config:', config) // 是否需要设置 token @@ -58,8 +62,8 @@ service.interceptors.request.use(config => { // console.log('🚀 ~ contentType:', contentType, requestObj.data) if (contentType.includes('application/json') && typeof requestObj.data !== 'undefined') { // 加密数据 - if (encryptRequest) { - console.log(hashWithSM3AndSalt(requestObj.data)); + if (systemConfig.requestConfig.encryptRequest && encryptRequest) { + // console.log(hashWithSM3AndSalt(requestObj.data)); config.data = encryptWithSM4(requestObj.data+"|"+hashWithSM3AndSalt(requestObj.data)) } } @@ -108,6 +112,11 @@ service.interceptors.response.use(res => { } if (code === 401) { if (!isRelogin.show) { + // 判断当前是否已经在登录页面, 在的话阻止继续执行 + if (window.location.href.indexOf('/login') !== -1) { + isRelogin.show = false + return + } isRelogin.show = true; MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => { isRelogin.show = false;