加密功能添加
This commit is contained in:
parent
bedf4a59d4
commit
3320a56495
|
|
@ -1,10 +1,10 @@
|
|||
# 页面标题
|
||||
VUE_APP_TITLE = 若依管理系统
|
||||
VUE_APP_TITLE = 工程档案资料移交管理系统
|
||||
|
||||
# 开发环境配置
|
||||
ENV = 'development'
|
||||
|
||||
# 若依管理系统/开发环境
|
||||
# 工程档案资料移交管理系统/开发环境
|
||||
VUE_APP_BASE_API = '/dev-api'
|
||||
|
||||
# 路由懒加载
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# 页面标题
|
||||
VUE_APP_TITLE = 若依管理系统
|
||||
VUE_APP_TITLE = 工程档案资料移交管理系统
|
||||
|
||||
# 生产环境配置
|
||||
ENV = 'production'
|
||||
|
||||
# 若依管理系统/生产环境
|
||||
# 工程档案资料移交管理系统/生产环境
|
||||
VUE_APP_BASE_API = '/prod-api'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# 页面标题
|
||||
VUE_APP_TITLE = 若依管理系统
|
||||
VUE_APP_TITLE = 工程档案资料移交管理系统
|
||||
|
||||
BABEL_ENV = production
|
||||
|
||||
|
|
@ -8,5 +8,5 @@ NODE_ENV = production
|
|||
# 测试环境配置
|
||||
ENV = 'staging'
|
||||
|
||||
# 若依管理系统/测试环境
|
||||
# 工程档案资料移交管理系统/测试环境
|
||||
VUE_APP_BASE_API = '/stage-api'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
.DS_Store
|
||||
node_modules/
|
||||
.history/
|
||||
dist/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "ruoyi",
|
||||
"version": "3.9.0",
|
||||
"description": "若依管理系统",
|
||||
"author": "若依",
|
||||
"description": "工程档案资料移交管理系统",
|
||||
"author": "bonus",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "vue-cli-service serve",
|
||||
|
|
@ -39,6 +39,7 @@
|
|||
"nprogress": "0.2.0",
|
||||
"quill": "2.0.2",
|
||||
"screenfull": "5.0.2",
|
||||
"sm-crypto": "^0.3.13",
|
||||
"sortablejs": "1.10.2",
|
||||
"splitpanes": "2.4.1",
|
||||
"vue": "2.6.12",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import request from '@/utils/request'
|
||||
import { parseStrEmpty } from "@/utils/ruoyi";
|
||||
import { parseStrEmpty } from "@/utils/bonus";
|
||||
|
||||
// 查询用户列表
|
||||
export function listUser(query) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import './assets/icons' // icon
|
|||
import './permission' // permission control
|
||||
import { getDicts } from "@/api/system/dict/data"
|
||||
import { getConfigKey } from "@/api/system/config"
|
||||
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi"
|
||||
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/bonus"
|
||||
// 分页组件
|
||||
import Pagination from "@/components/Pagination"
|
||||
// 自定义表格工具组件
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {Loading, Message} from 'element-ui'
|
|||
import { saveAs } from 'file-saver'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
import { blobValidate } from "@/utils/ruoyi"
|
||||
import { blobValidate } from "@/utils/bonus"
|
||||
|
||||
const baseURL = process.env.VUE_APP_BASE_API
|
||||
let downloadLoadingInstance
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// SM 配置
|
||||
export const SM_CONFIG = {
|
||||
SALT: '2cc0c5f9f1749f1632efa9f63e902323', // SM3 盐值(16 字节)
|
||||
SM4_KEY:"78d1295afa99449b99d6f83820e6965c", // SM4 对称加密密钥
|
||||
SM4_SALT:"f555adf6c01d0ab0761e626a2dae34a2",
|
||||
SM2_PUBLIC_KEY: 'your-public-key', // SM2 公钥
|
||||
SM2_PRIVATE_KEY: 'your-private-key' // SM2 私钥
|
||||
}
|
||||
// AES 配置
|
||||
export const AES_CONFIG = {
|
||||
AES_KEY: 'zhgd@bonus@zhgd@bonus@1234567890', // AES key值
|
||||
AES_IV: '1234567812345678' // AES 偏移量
|
||||
}
|
||||
|
||||
export function generateUUID() {
|
||||
// 使用当前时间戳和随机数生成一个 UUID
|
||||
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0; // 生成随机数
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8); // 根据 UUID 规范生成相应的值
|
||||
return v.toString(16); // 转换为十六进制
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Vue from 'vue'
|
||||
import { mergeRecursive } from "@/utils/ruoyi"
|
||||
import { mergeRecursive } from "@/utils/bonus"
|
||||
import DictMeta from './DictMeta'
|
||||
import DictData from './DictData'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { mergeRecursive } from "@/utils/ruoyi"
|
||||
import { mergeRecursive } from "@/utils/bonus"
|
||||
import DictOptions from './DictOptions'
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { mergeRecursive } from "@/utils/ruoyi"
|
||||
import { mergeRecursive } from "@/utils/bonus"
|
||||
import dictConverter from './DictConverter'
|
||||
|
||||
export const options = {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { parseTime } from './ruoyi'
|
||||
import { parseTime } from './bonus'
|
||||
|
||||
/**
|
||||
* 表格时间格式化
|
||||
|
|
|
|||
|
|
@ -3,93 +3,179 @@ import { Notification, MessageBox, Message, Loading } from 'element-ui'
|
|||
import store from '@/store'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import errorCode from '@/utils/errorCode'
|
||||
import { tansParams, blobValidate } from "@/utils/ruoyi"
|
||||
import { tansParams, blobValidate } from '@/utils/bonus'
|
||||
import cache from '@/plugins/cache'
|
||||
import { saveAs } from 'file-saver'
|
||||
import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm'
|
||||
|
||||
const systemConfig = {
|
||||
requestConfig: {
|
||||
encryptRequest: process.env.VUE_APP_ENV === 'production' ? true : true,
|
||||
checkIntegrity: process.env.VUE_APP_ENV === 'production' ? true : true,
|
||||
encryptResponse: process.env.VUE_APP_ENV === 'production' ? true : true,
|
||||
},
|
||||
}
|
||||
|
||||
let downloadLoadingInstance
|
||||
// 是否显示重新登录
|
||||
export let isRelogin = { show: false }
|
||||
|
||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
||||
// 创建axios实例
|
||||
|
||||
const service = axios.create({
|
||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||
baseURL: process.env.VUE_APP_BASE_API,
|
||||
// 超时
|
||||
timeout: 10000
|
||||
timeout: 30000,
|
||||
})
|
||||
|
||||
// request拦截器
|
||||
service.interceptors.request.use(config => {
|
||||
// 是否需要设置 token
|
||||
const isToken = (config.headers || {}).isToken === false
|
||||
// 是否需要防止数据重复提交
|
||||
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
|
||||
if (getToken() && !isToken) {
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
// request 拦截器
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
const headers = config.headers || {}
|
||||
const {
|
||||
isToken = true,
|
||||
encryptRequest = true,
|
||||
checkIntegrity = true,
|
||||
encryptResponse = true,
|
||||
repeatSubmit = false,
|
||||
} = headers
|
||||
|
||||
// 设置请求头
|
||||
config.headers['encryptRequest'] = systemConfig.requestConfig.encryptRequest && encryptRequest ? 'true' : 'false'
|
||||
config.headers['checkIntegrity'] = systemConfig.requestConfig.checkIntegrity && checkIntegrity ? 'true' : 'false'
|
||||
config.headers['encryptResponse'] = systemConfig.requestConfig.encryptResponse && encryptResponse ? 'true' : 'false'
|
||||
|
||||
const isRepeatSubmit = repeatSubmit
|
||||
|
||||
// 处理 Token
|
||||
if (getToken() && isToken) {
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken()
|
||||
}
|
||||
// get请求映射params参数
|
||||
|
||||
// GET 请求处理 - 统一处理加密逻辑
|
||||
if (config.method === 'get' && config.params) {
|
||||
// 如果需要加密 GET 请求
|
||||
if (systemConfig.requestConfig.encryptRequest && encryptRequest) {
|
||||
// 将参数转换为查询字符串
|
||||
let paramsString = tansParams(config.params)
|
||||
// 移除末尾的 & 字符
|
||||
if (paramsString.endsWith('&')) {
|
||||
paramsString = paramsString.slice(0, -1)
|
||||
}
|
||||
|
||||
if (paramsString) {
|
||||
// 添加完整性校验哈希
|
||||
const hash = hashWithSM3AndSalt(paramsString)
|
||||
const encryptedParams = encryptWithSM4(paramsString + '|' + hash)
|
||||
|
||||
// 清空原始 params
|
||||
config.params = {}
|
||||
|
||||
// 如果 URL 已经有查询参数,需要先清理
|
||||
let baseUrl = config.url
|
||||
const questionMarkIndex = baseUrl.indexOf('?')
|
||||
if (questionMarkIndex !== -1) {
|
||||
baseUrl = baseUrl.substring(0, questionMarkIndex)
|
||||
}
|
||||
|
||||
// 设置加密后的查询参数
|
||||
config.url = baseUrl + '?params=' + encodeURIComponent(encryptedParams)
|
||||
}
|
||||
} else {
|
||||
// 不加密的情况,保持原有逻辑
|
||||
let url = config.url + '?' + tansParams(config.params)
|
||||
url = url.slice(0, -1)
|
||||
config.params = {}
|
||||
config.url = url
|
||||
}
|
||||
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
||||
const requestObj = {
|
||||
url: config.url,
|
||||
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
||||
time: new Date().getTime()
|
||||
}
|
||||
const requestSize = Object.keys(JSON.stringify(requestObj)).length // 请求数据大小
|
||||
const limitSize = 5 * 1024 * 1024 // 限制存放数据5M
|
||||
if (requestSize >= limitSize) {
|
||||
console.warn(`[${config.url}]: ` + '请求数据大小超出允许的5M限制,无法进行防重复提交验证。')
|
||||
return config
|
||||
}
|
||||
const sessionObj = cache.session.getJSON('sessionObj')
|
||||
if (sessionObj === undefined || sessionObj === null || sessionObj === '') {
|
||||
cache.session.setJSON('sessionObj', requestObj)
|
||||
} else {
|
||||
const s_url = sessionObj.url // 请求地址
|
||||
const s_data = sessionObj.data // 请求数据
|
||||
const s_time = sessionObj.time // 请求时间
|
||||
const interval = 1000 // 间隔时间(ms),小于此时间视为重复提交
|
||||
if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) {
|
||||
const message = '数据正在处理,请勿重复提交'
|
||||
console.warn(`[${s_url}]: ` + message)
|
||||
return Promise.reject(new Error(message))
|
||||
} else {
|
||||
cache.session.setJSON('sessionObj', requestObj)
|
||||
}
|
||||
}
|
||||
}
|
||||
return config
|
||||
}, error => {
|
||||
console.log(error)
|
||||
Promise.reject(error)
|
||||
})
|
||||
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(res => {
|
||||
// POST/PUT 请求处理
|
||||
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
||||
let data = typeof config.data === 'object' ? JSON.stringify(config.data) : config.data
|
||||
let contentType = config.headers['Content-Type']
|
||||
|
||||
if (contentType && contentType.includes('application/json') && typeof data !== 'undefined') {
|
||||
// 加密数据
|
||||
if (systemConfig.requestConfig.encryptRequest && encryptRequest) {
|
||||
config.data = encryptWithSM4(data + '|' + hashWithSM3AndSalt(data))
|
||||
}
|
||||
}
|
||||
|
||||
// 检查请求数据大小
|
||||
const requestSize = JSON.stringify({
|
||||
url: config.url,
|
||||
data: data,
|
||||
time: Date.now(),
|
||||
}).length
|
||||
const limitSize = 1000 * 1024 * 1024
|
||||
|
||||
if (requestSize >= limitSize) {
|
||||
console.warn(
|
||||
`[${config.url}]: 请求数据大小超出允许的5MB限制,无法进行防重复提交验证。`,
|
||||
)
|
||||
return config
|
||||
}
|
||||
|
||||
// 防止重复提交
|
||||
const sessionObj = cache.session.getJSON('sessionObj') || {}
|
||||
const requestObj = { url: config.url, data: data, time: Date.now() }
|
||||
|
||||
if (
|
||||
sessionObj.data === requestObj.data &&
|
||||
requestObj.time - sessionObj.time < 0 &&
|
||||
sessionObj.url === requestObj.url
|
||||
) {
|
||||
console.warn(`[${sessionObj.url}]: 数据正在处理,请勿重复提交`)
|
||||
return Promise.reject(new Error('数据正在处理,请勿重复提交'))
|
||||
}
|
||||
cache.session.setJSON('sessionObj', requestObj)
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
console.error(error)
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
// 响应拦截器(保持不变)
|
||||
service.interceptors.response.use(
|
||||
(res) => {
|
||||
if (res.headers.encryptresponse && !res.data.hasOwnProperty('code')) {
|
||||
res.data = JSON.parse(decryptWithSM4(res.data))
|
||||
}
|
||||
// 未设置状态码则默认成功状态
|
||||
const code = res.data.code || 200
|
||||
// 获取错误信息
|
||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||
// 二进制数据则直接返回
|
||||
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||
if (
|
||||
res.request.responseType === 'blob' ||
|
||||
res.request.responseType === 'arraybuffer'
|
||||
) {
|
||||
return res.data
|
||||
}
|
||||
if (code === 401) {
|
||||
if (!isRelogin.show) {
|
||||
isRelogin.show = true
|
||||
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
||||
MessageBox.confirm(
|
||||
'登录状态已过期,您可以继续留在该页面,或者重新登录',
|
||||
'系统提示',
|
||||
{
|
||||
confirmButtonText: '重新登录',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
},
|
||||
)
|
||||
.then(() => {
|
||||
isRelogin.show = false
|
||||
store.dispatch('LogOut').then(() => {
|
||||
location.href = '/index'
|
||||
location.href =
|
||||
process.env.VUE_APP_ENV === 'production'
|
||||
? '/smart-archiving/index'
|
||||
: '/index'
|
||||
})
|
||||
}).catch(() => {
|
||||
})
|
||||
.catch(() => {
|
||||
isRelogin.show = false
|
||||
})
|
||||
}
|
||||
|
|
@ -107,30 +193,42 @@ service.interceptors.response.use(res => {
|
|||
return res.data
|
||||
}
|
||||
},
|
||||
error => {
|
||||
console.log('err' + error)
|
||||
(error) => {
|
||||
let { message } = error
|
||||
if (message == "Network Error") {
|
||||
message = "后端接口连接异常"
|
||||
} else if (message.includes("timeout")) {
|
||||
message = "系统接口请求超时"
|
||||
} else if (message.includes("Request failed with status code")) {
|
||||
message = "系统接口" + message.substr(message.length - 3) + "异常"
|
||||
if (message == 'Network Error') {
|
||||
message = '后端接口连接异常'
|
||||
} else if (message.includes('timeout')) {
|
||||
message = '系统接口请求超时'
|
||||
} else if (message.includes('Request failed with status code')) {
|
||||
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
||||
}
|
||||
Message({ message: message, type: 'error', duration: 5 * 1000 })
|
||||
return Promise.reject(error)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
// 通用下载方法
|
||||
// 通用下载方法(保持不变)
|
||||
export function download(url, params, filename, config) {
|
||||
downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
|
||||
return service.post(url, params, {
|
||||
transformRequest: [(params) => { return tansParams(params) }],
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
downloadLoadingInstance = Loading.service({
|
||||
text: '正在下载数据,请稍候',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)',
|
||||
})
|
||||
return service
|
||||
.post(url, params, {
|
||||
transformRequest: [
|
||||
(params) => {
|
||||
return tansParams(params)
|
||||
},
|
||||
],
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
encryptResponse: false,
|
||||
},
|
||||
responseType: 'blob',
|
||||
...config
|
||||
}).then(async (data) => {
|
||||
...config,
|
||||
})
|
||||
.then(async (data) => {
|
||||
const isBlob = blobValidate(data)
|
||||
if (isBlob) {
|
||||
const blob = new Blob([data])
|
||||
|
|
@ -138,11 +236,13 @@ export function download(url, params, filename, config) {
|
|||
} else {
|
||||
const resText = await data.text()
|
||||
const rspObj = JSON.parse(resText)
|
||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
const errMsg =
|
||||
errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
Message.error(errMsg)
|
||||
}
|
||||
downloadLoadingInstance.close()
|
||||
}).catch((r) => {
|
||||
})
|
||||
.catch((r) => {
|
||||
console.error(r)
|
||||
Message.error('下载文件出现错误,请联系管理员!')
|
||||
downloadLoadingInstance.close()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
// src/utils/encryption.js
|
||||
import { sm2, sm3, sm4 } from 'sm-crypto'
|
||||
// 配置项,例如盐值、SM2 公私钥、SM4 密钥
|
||||
import { SM_CONFIG } from './configure'
|
||||
import SM4 from 'sm-crypto/src/sm4'
|
||||
import { hexToArray } from 'sm-crypto/src/sm2/utils'
|
||||
|
||||
// SM3 哈希
|
||||
export function hashSM3(text) {
|
||||
// 对数据进行哈希计算
|
||||
return sm3(text)
|
||||
}
|
||||
|
||||
// 使用 SM3 进行哈希并加入盐值
|
||||
export function hashWithSM3AndSalt(text) {
|
||||
// 将文本和盐值拼接在一起
|
||||
const textWithSalt = SM_CONFIG.SALT + text
|
||||
// 使用 SM3 进行哈希
|
||||
return hashSM3(textWithSalt)
|
||||
}
|
||||
|
||||
// SM2 加密
|
||||
export function encryptWithSM2(text) {
|
||||
// SM2 公钥加密
|
||||
return sm2.doEncrypt(text, SM_CONFIG.SM2_PUBLIC_KEY)
|
||||
}
|
||||
|
||||
// SM2 解密
|
||||
export function decryptWithSM2(encryptedText) {
|
||||
// SM2 私钥解密
|
||||
return sm2.doDecrypt(encryptedText, SM_CONFIG.SM2_PRIVATE_KEY)
|
||||
}
|
||||
/**
|
||||
* 加密函数
|
||||
* @param {string} plainText
|
||||
* @returns {string} 加密后的密文(Hex 编码格式)
|
||||
*/
|
||||
export function encryptWithSM4(plainText) {
|
||||
return sm4.encrypt(plainText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5',iv:SM_CONFIG.SM4_SALT});
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密函数
|
||||
* @param {string} cipherText
|
||||
* @returns {string} 解密后的明文
|
||||
*/
|
||||
export function decryptWithSM4(cipherText){
|
||||
return SM4.decrypt(cipherText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5' ,iv:SM_CONFIG.SM4_SALT});
|
||||
}
|
||||
|
||||
1049
src/views/index.vue
1049
src/views/index.vue
File diff suppressed because it is too large
Load Diff
|
|
@ -7,7 +7,7 @@ function resolve(dir) {
|
|||
|
||||
const CompressionPlugin = require('compression-webpack-plugin')
|
||||
|
||||
const name = process.env.VUE_APP_TITLE || '若依管理系统' // 网页标题
|
||||
const name = process.env.VUE_APP_TITLE || '工程档案资料移交管理系统' // 网页标题
|
||||
|
||||
const baseUrl = 'http://localhost:8080' // 后端接口
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue