加密处理
This commit is contained in:
parent
298a1b771c
commit
077c3518b4
|
|
@ -16,6 +16,7 @@ import ThemePicker from '@/components/ThemePicker'
|
||||||
import Notice from '@/components/Notice'
|
import Notice from '@/components/Notice'
|
||||||
import { getHomeNoticeApi } from '@/api/system/notice.js'
|
import { getHomeNoticeApi } from '@/api/system/notice.js'
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from '@/utils/auth'
|
||||||
|
import { getConfigApi } from '@/utils/config'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
|
|
@ -42,6 +43,10 @@ export default {
|
||||||
noticeList: [],
|
noticeList: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
// 获取配置信息
|
||||||
|
getConfigApi()
|
||||||
|
},
|
||||||
updated() {
|
updated() {
|
||||||
// 判断是否需要获取通知信息
|
// 判断是否需要获取通知信息
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
|
|
@ -121,3 +121,10 @@ export function checkPasswordStatusApi(data) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取系统配置
|
||||||
|
export const getConfig = () => {
|
||||||
|
return request({
|
||||||
|
url: '/auth/getConfig',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,10 @@ import cache from '@/plugins/cache'
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm'
|
import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm'
|
||||||
|
|
||||||
|
const systemConfig = JSON.parse(localStorage.getItem('systemConfig')) || {
|
||||||
|
requestConfig: { encryptRequest: false, checkIntegrity: false, encryptResponse: false }
|
||||||
|
};
|
||||||
|
|
||||||
let downloadLoadingInstance;
|
let downloadLoadingInstance;
|
||||||
// 是否显示重新登录
|
// 是否显示重新登录
|
||||||
export let isRelogin = { show: false };
|
export let isRelogin = { show: false };
|
||||||
|
|
@ -27,11 +31,11 @@ service.interceptors.request.use(config => {
|
||||||
const checkIntegrity = false
|
const checkIntegrity = false
|
||||||
const encryptResponse = 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)
|
// console.log('🚀 ~ config:', config)
|
||||||
|
|
||||||
// 是否需要设置 token
|
// 是否需要设置 token
|
||||||
|
|
@ -58,8 +62,8 @@ service.interceptors.request.use(config => {
|
||||||
// console.log('🚀 ~ contentType:', contentType, requestObj.data)
|
// console.log('🚀 ~ contentType:', contentType, requestObj.data)
|
||||||
if (contentType.includes('application/json') && typeof requestObj.data !== 'undefined') {
|
if (contentType.includes('application/json') && typeof requestObj.data !== 'undefined') {
|
||||||
// 加密数据
|
// 加密数据
|
||||||
if (encryptRequest) {
|
if (systemConfig.requestConfig.encryptRequest && encryptRequest) {
|
||||||
console.log(hashWithSM3AndSalt(requestObj.data));
|
// console.log(hashWithSM3AndSalt(requestObj.data));
|
||||||
config.data = encryptWithSM4(requestObj.data+"|"+hashWithSM3AndSalt(requestObj.data))
|
config.data = encryptWithSM4(requestObj.data+"|"+hashWithSM3AndSalt(requestObj.data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,6 +112,11 @@ service.interceptors.response.use(res => {
|
||||||
}
|
}
|
||||||
if (code === 401) {
|
if (code === 401) {
|
||||||
if (!isRelogin.show) {
|
if (!isRelogin.show) {
|
||||||
|
// 判断当前是否已经在登录页面, 在的话阻止继续执行
|
||||||
|
if (window.location.href.indexOf('/login') !== -1) {
|
||||||
|
isRelogin.show = false
|
||||||
|
return
|
||||||
|
}
|
||||||
isRelogin.show = true;
|
isRelogin.show = true;
|
||||||
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
||||||
isRelogin.show = false;
|
isRelogin.show = false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue