加密配置更改
This commit is contained in:
parent
c7c5012d6c
commit
aa29ef5646
|
|
@ -45,6 +45,7 @@
|
||||||
"axios": "0.24.0",
|
"axios": "0.24.0",
|
||||||
"clipboard": "2.0.8",
|
"clipboard": "2.0.8",
|
||||||
"core-js": "^3.38.0",
|
"core-js": "^3.38.0",
|
||||||
|
"crypto-js": "^4.2.0",
|
||||||
"echarts": "5.4.0",
|
"echarts": "5.4.0",
|
||||||
"element-ui": "2.15.13",
|
"element-ui": "2.15.13",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
|
|
@ -60,6 +61,7 @@
|
||||||
"qrcodejs2": "0.0.2",
|
"qrcodejs2": "0.0.2",
|
||||||
"quill": "1.3.7",
|
"quill": "1.3.7",
|
||||||
"screenfull": "5.0.2",
|
"screenfull": "5.0.2",
|
||||||
|
"sm-crypto": "^0.3.13",
|
||||||
"sortablejs": "1.10.2",
|
"sortablejs": "1.10.2",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"vue": "2.6.12",
|
"vue": "2.6.12",
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@
|
||||||
<title>
|
<title>
|
||||||
<%= webpackConfig.name %>
|
<%= webpackConfig.name %>
|
||||||
</title>
|
</title>
|
||||||
<!-- <script src="/static/map/map_load.js" type="text/javascript"></script> -->
|
<script src="<%= BASE_URL %>/static/map/map_load.js" type="text/javascript"></script>
|
||||||
<script async src="https://api.map.baidu.com/api?v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
<!-- <script async src="https://api.map.baidu.com/api?v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
||||||
<script src="https://api.map.baidu.com/api?type=webgl&v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
<script src="https://api.map.baidu.com/api?type=webgl&v=2.0&ak=cClgLBaLgGUdQDilX9dGvieL"></script>
|
||||||
<script type="text/javascript" src="//api.map.baidu.com/library/TrackAnimation/src/TrackAnimation_min.js"></script>
|
<script type="text/javascript" src="//api.map.baidu.com/library/TrackAnimation/src/TrackAnimation_min.js"></script> -->
|
||||||
<!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
|
<!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* 离线地图城市坐标
|
|
||||||
* 文本文件必须以UTF-8编码存储,建议用Notepad++编辑
|
|
||||||
* 格式:城市名称 经度 纬度
|
|
||||||
*/
|
|
||||||
var offlinemap_cities = [
|
|
||||||
['北京', 116.427265, 39.918698]
|
|
||||||
,['上海', 121.472724, 31.239761]
|
|
||||||
,['武汉', 114.28398, 30.601327]
|
|
||||||
,['成都', 104.070606, 30.59138]
|
|
||||||
,['广州', 113.270404, 23.159763]
|
|
||||||
,['重庆', 106.595635, 29.619598]
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/* 城市数据映射
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
var offlinemap_cityobj = new Object();
|
|
||||||
for(var i=0; i<offlinemap_cities.length; i++){
|
|
||||||
offlinemap_cityobj[ offlinemap_cities[i][0] ] = [offlinemap_cities[i][1], offlinemap_cities[i][2]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 获得城市坐标
|
|
||||||
* 城市的坐标必须先存储在map_city.js
|
|
||||||
*/
|
|
||||||
var i_getCityPoint = function(a) {
|
|
||||||
if( a in offlinemap_cityobj ){
|
|
||||||
var pt = new BMap.Point(offlinemap_cityobj[a][0], offlinemap_cityobj[a][1]);
|
|
||||||
return pt;
|
|
||||||
}
|
|
||||||
alert('map_city.js中未定义城市坐标:'+ a);
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 设置地图中心为某个城市
|
|
||||||
* 城市的坐标必须先存储在map_city.js
|
|
||||||
*/
|
|
||||||
var i_setCurrentCity = function(map, a) {
|
|
||||||
var pt = i_getCityPoint(a);
|
|
||||||
if( pt ){
|
|
||||||
map.setCenter( pt );
|
|
||||||
return pt;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
@ -15,9 +15,6 @@ bmapcfg.home = JS__FILE__.substr(0, JS__FILE__.lastIndexOf("/")+1); //地图API
|
||||||
window.BMap_loadScriptTime = (new Date).getTime();
|
window.BMap_loadScriptTime = (new Date).getTime();
|
||||||
//加载地图API主文件
|
//加载地图API主文件
|
||||||
document.write('<script type="text/javascript" src="'+bmapcfg.home+'bmap_offline_api_v3.0_min.js"></script>');
|
document.write('<script type="text/javascript" src="'+bmapcfg.home+'bmap_offline_api_v3.0_min.js"></script>');
|
||||||
//加载扩展函数
|
|
||||||
document.write('<script type="text/javascript" src="'+bmapcfg.home+'map_plus.js"></script>');
|
|
||||||
//加载城市坐标
|
|
||||||
document.write('<script type="text/javascript" src="'+bmapcfg.home+'map_city.js"></script>');
|
|
||||||
})();
|
})();
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
/*
|
|
||||||
* 离线地图扩展功能函数
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
@ -234,23 +234,23 @@ export default {
|
||||||
console.log(list, 'coord')
|
console.log(list, 'coord')
|
||||||
let this_ = this
|
let this_ = this
|
||||||
this.$nextTick(() => {//BMapGL window.BMap
|
this.$nextTick(() => {//BMapGL window.BMap
|
||||||
this_.map = new BMapGL.Map('map-container') // 创建地图实例
|
this_.map = new window.BMap.Map('map-container') // 创建地图实例
|
||||||
var pointFirst = new BMapGL.Point(116.404, 39.915); // 创建点坐标
|
var pointFirst = new window.BMap.Point(116.404, 39.915); // 创建点坐标
|
||||||
this_.map.centerAndZoom(pointFirst, 14) // 初始化地图,设置中心点坐标和地图级别
|
this_.map.centerAndZoom(pointFirst, 14) // 初始化地图,设置中心点坐标和地图级别
|
||||||
this_.map.enableScrollWheelZoom(true) // 启用滚轮放大缩小
|
this_.map.enableScrollWheelZoom(true) // 启用滚轮放大缩小
|
||||||
this_.map.setMinZoom(14) // 启用滚轮放大缩小
|
this_.map.setMinZoom(14) // 启用滚轮放大缩小
|
||||||
this_.map.setMaxZoom(14) // 启用滚轮放大缩小
|
this_.map.setMaxZoom(14) // 启用滚轮放大缩小
|
||||||
// this_.map.setHeading(0) //设置地图旋转角度
|
// this_.map.setHeading(0) //设置地图旋转角度
|
||||||
// this_.map.setTilt(0) //设置地图的倾斜角度
|
// this_.map.setTilt(0) //设置地图的倾斜角度
|
||||||
var geoc = new BMapGL.Geocoder()
|
var geoc = new window.BMap.Geocoder()
|
||||||
if(list.length>0){
|
if(list.length>0){
|
||||||
if(list[0].lon&&list[0].lat){
|
if(list[0].lon&&list[0].lat){
|
||||||
let point = new BMapGL.Point(list[0].lon, list[0].lat) // 创建点坐标
|
let point = new window.BMap.Point(list[0].lon, list[0].lat) // 创建点坐标
|
||||||
this_.map.centerAndZoom(point, 14) // 初始化地图,设置中心点坐标和地图级别
|
this_.map.centerAndZoom(point, 14) // 初始化地图,设置中心点坐标和地图级别
|
||||||
}
|
}
|
||||||
list.forEach((item) => {
|
list.forEach((item) => {
|
||||||
let point = new BMapGL.Point(item.lon, item.lat)
|
let point = new window.BMap.Point(item.lon, item.lat)
|
||||||
let marker = new BMapGL.Marker(point)
|
let marker = new window.BMap.Marker(point)
|
||||||
this.map.addOverlay(marker)
|
this.map.addOverlay(marker)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -261,8 +261,8 @@ export default {
|
||||||
console.log(res, 'res')
|
console.log(res, 'res')
|
||||||
})
|
})
|
||||||
this_.map.clearOverlays()
|
this_.map.clearOverlays()
|
||||||
point = new BMapGL.Point(e.latlng.lng, e.latlng.lat)
|
point = new window.BMap.Point(e.latlng.lng, e.latlng.lat)
|
||||||
let marker = new BMapGL.Marker(point) // 创建标点
|
let marker = new window.BMap.Marker(point) // 创建标点
|
||||||
this_.map.addOverlay(marker)
|
this_.map.addOverlay(marker)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -273,8 +273,8 @@ export default {
|
||||||
this.coordList.forEach((item) => {
|
this.coordList.forEach((item) => {
|
||||||
if (item.relName === v.peopleName) {
|
if (item.relName === v.peopleName) {
|
||||||
this.map.clearOverlays()
|
this.map.clearOverlays()
|
||||||
let point = new BMapGL.Point(item.lon, item.lat)
|
let point = new window.BMap.Point(item.lon, item.lat)
|
||||||
let marker = new BMapGL.Marker(point)
|
let marker = new window.BMap.Marker(point)
|
||||||
this.map.addOverlay(marker)
|
this.map.addOverlay(marker)
|
||||||
this.map.centerAndZoom(point, 14)
|
this.map.centerAndZoom(point, 14)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,23 +229,23 @@ export default {
|
||||||
|
|
||||||
let this_ = this
|
let this_ = this
|
||||||
this.$nextTick(() => {//BMapGL window.BMap
|
this.$nextTick(() => {//BMapGL window.BMap
|
||||||
this_.map = new BMapGL.Map('map-container') // 创建地图实例
|
this_.map = new window.BMap.Map('map-container') // 创建地图实例
|
||||||
var pointFirst = new BMapGL.Point(116.404, 39.915); // 创建点坐标
|
var pointFirst = new window.BMap.Point(116.404, 39.915); // 创建点坐标
|
||||||
this_.map.centerAndZoom(pointFirst, 14) // 初始化地图,设置中心点坐标和地图级别
|
this_.map.centerAndZoom(pointFirst, 14) // 初始化地图,设置中心点坐标和地图级别
|
||||||
this_.map.enableScrollWheelZoom(true) // 启用滚轮放大缩小
|
this_.map.enableScrollWheelZoom(true) // 启用滚轮放大缩小
|
||||||
this_.map.setMinZoom(14) // 启用滚轮放大缩小
|
this_.map.setMinZoom(14) // 启用滚轮放大缩小
|
||||||
this_.map.setMaxZoom(14) // 启用滚轮放大缩小
|
this_.map.setMaxZoom(14) // 启用滚轮放大缩小
|
||||||
// this_.map.setHeading(0) //设置地图旋转角度
|
// this_.map.setHeading(0) //设置地图旋转角度
|
||||||
// this_.map.setTilt(0) //设置地图的倾斜角度
|
// this_.map.setTilt(0) //设置地图的倾斜角度
|
||||||
var geoc = new BMapGL.Geocoder()
|
var geoc = new window.BMap.Geocoder()
|
||||||
if(list.length>0){
|
if(list.length>0){
|
||||||
if(list[0].lon&&list[0].lat){
|
if(list[0].lon&&list[0].lat){
|
||||||
let point = new BMapGL.Point(list[0].lon, list[0].lat) // 创建点坐标
|
let point = new window.BMap.Point(Number(list[0].lon), Number(list[0].lat)) // 创建点坐标
|
||||||
this_.map.centerAndZoom(point, 14) // 初始化地图,设置中心点坐标和地图级别
|
this_.map.centerAndZoom(point, 14) // 初始化地图,设置中心点坐标和地图级别
|
||||||
}
|
}
|
||||||
list.forEach(item => {
|
list.forEach(item => {
|
||||||
let point = new BMapGL.Point(item.lon, item.lat)
|
let point = new window.BMap.Point(Number(item.lon), Number(item.lat))
|
||||||
let marker = new BMapGL.Marker(point)
|
let marker = new window.BMap.Marker(point)
|
||||||
this.map.addOverlay(marker)
|
this.map.addOverlay(marker)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -261,8 +261,8 @@ export default {
|
||||||
// this_.form.latitude = e.latlng.lat */
|
// this_.form.latitude = e.latlng.lat */
|
||||||
// })
|
// })
|
||||||
// this_.map.clearOverlays()
|
// this_.map.clearOverlays()
|
||||||
// point = new BMapGL.Point(e.latlng.lng, e.latlng.lat)
|
// point = new window.BMap.Point(e.latlng.lng, e.latlng.lat)
|
||||||
// let marker = new BMapGL.Marker(point) // 创建标点
|
// let marker = new window.BMap.Marker(point) // 创建标点
|
||||||
// this_.map.addOverlay(marker)
|
// this_.map.addOverlay(marker)
|
||||||
// })
|
// })
|
||||||
})
|
})
|
||||||
|
|
@ -273,8 +273,8 @@ export default {
|
||||||
this.coordList.forEach(item => {
|
this.coordList.forEach(item => {
|
||||||
if(item.relName === v.peopleName) {
|
if(item.relName === v.peopleName) {
|
||||||
this.map.clearOverlays()
|
this.map.clearOverlays()
|
||||||
let point = new BMapGL.Point(item.lon, item.lat)
|
let point = new window.BMap.Point(Number(item.lon), Number(item.lat))
|
||||||
let marker = new BMapGL.Marker(point)
|
let marker = new window.BMap.Marker(point)
|
||||||
this.map.addOverlay(marker)
|
this.map.addOverlay(marker)
|
||||||
this.map.centerAndZoom(point, 14)
|
this.map.centerAndZoom(point, 14)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/main.js
12
src/main.js
|
|
@ -16,20 +16,12 @@ import router from './router'
|
||||||
import directive from './directive' // directive
|
import directive from './directive' // directive
|
||||||
import plugins from './plugins' // plugins
|
import plugins from './plugins' // plugins
|
||||||
import { download, downloadJson } from '@/utils/request'
|
import { download, downloadJson } from '@/utils/request'
|
||||||
|
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree, indexContinuation } from "@/utils/bonus";
|
||||||
import './assets/icons' // icon
|
import './assets/icons' // icon
|
||||||
import './permission' // permission control
|
import './permission' // permission control
|
||||||
import { getDicts } from '@/api/system/dict/data'
|
import { getDicts } from '@/api/system/dict/data'
|
||||||
import { getConfigKey } from '@/api/system/config'
|
import { getConfigKey } from '@/api/system/config'
|
||||||
import {
|
|
||||||
parseTime,
|
|
||||||
resetForm,
|
|
||||||
addDateRange,
|
|
||||||
selectDictLabel,
|
|
||||||
selectDictLabels,
|
|
||||||
handleTree,
|
|
||||||
indexContinuation,
|
|
||||||
} from '@/utils/ruoyi'
|
|
||||||
// 分页组件
|
// 分页组件
|
||||||
import Pagination from '@/components/Pagination'
|
import Pagination from '@/components/Pagination'
|
||||||
// 自定义表格工具组件
|
// 自定义表格工具组件
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
import * as CryptoJS from 'crypto-js'
|
||||||
|
import { AES_CONFIG } from './configure'
|
||||||
|
const cbc_key = CryptoJS.enc.Utf8.parse(AES_CONFIG.AES_KEY)
|
||||||
|
const cbc_iv = CryptoJS.enc.Utf8.parse(AES_CONFIG.AES_IV)
|
||||||
|
/**
|
||||||
|
* 加解密开关
|
||||||
|
* 默认参数需要加密
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
const encryptEnabled= false;
|
||||||
|
// /**
|
||||||
|
// * 默认后台会自动加密
|
||||||
|
// * @type {boolean}
|
||||||
|
// */
|
||||||
|
// const decryptEnabled=true;
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
* @param word
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
export const encryptCBC = function(word) {
|
||||||
|
const srcs = CryptoJS.enc.Utf8.parse(word)
|
||||||
|
const encrypted = CryptoJS.AES.encrypt(srcs, cbc_key, {
|
||||||
|
iv: cbc_iv,
|
||||||
|
mode: CryptoJS.mode.CBC,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
})
|
||||||
|
return encrypted.toString()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
* @param word
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
export const decryptCBC = function(word) {
|
||||||
|
// if(!decryptEnabled){
|
||||||
|
// return word;
|
||||||
|
// }
|
||||||
|
const encrypted = CryptoJS.AES.decrypt(word, cbc_key, {
|
||||||
|
iv: cbc_iv,
|
||||||
|
mode: CryptoJS.mode.CBC,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
})
|
||||||
|
return encrypted.toString(CryptoJS.enc.Utf8)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,234 @@
|
||||||
|
/**
|
||||||
|
* 通用js方法封装处理
|
||||||
|
* Copyright (c) 2019 bonus
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 日期格式化
|
||||||
|
export function parseTime(time, pattern) {
|
||||||
|
if (arguments.length === 0 || !time) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
|
||||||
|
let date
|
||||||
|
if (typeof time === 'object') {
|
||||||
|
date = time
|
||||||
|
} else {
|
||||||
|
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
|
||||||
|
time = parseInt(time)
|
||||||
|
} else if (typeof time === 'string') {
|
||||||
|
time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '')
|
||||||
|
}
|
||||||
|
if ((typeof time === 'number') && (time.toString().length === 10)) {
|
||||||
|
time = time * 1000
|
||||||
|
}
|
||||||
|
date = new Date(time)
|
||||||
|
}
|
||||||
|
const formatObj = {
|
||||||
|
y: date.getFullYear(),
|
||||||
|
m: date.getMonth() + 1,
|
||||||
|
d: date.getDate(),
|
||||||
|
h: date.getHours(),
|
||||||
|
i: date.getMinutes(),
|
||||||
|
s: date.getSeconds(),
|
||||||
|
a: date.getDay()
|
||||||
|
}
|
||||||
|
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
|
||||||
|
let value = formatObj[key]
|
||||||
|
// Note: getDay() returns 0 on Sunday
|
||||||
|
if (key === 'a') {
|
||||||
|
return ['日', '一', '二', '三', '四', '五', '六'][value]
|
||||||
|
}
|
||||||
|
if (result.length > 0 && value < 10) {
|
||||||
|
value = '0' + value
|
||||||
|
}
|
||||||
|
return value || 0
|
||||||
|
})
|
||||||
|
return time_str
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单重置
|
||||||
|
export function resetForm(refName) {
|
||||||
|
if (this.$refs[refName]) {
|
||||||
|
this.$refs[refName].resetFields()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加日期范围
|
||||||
|
export function addDateRange(params, dateRange, propName) {
|
||||||
|
let search = params
|
||||||
|
search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {}
|
||||||
|
dateRange = Array.isArray(dateRange) ? dateRange : []
|
||||||
|
if (typeof (propName) === 'undefined') {
|
||||||
|
search.params['beginTime'] = dateRange[0]
|
||||||
|
search.params['endTime'] = dateRange[1]
|
||||||
|
} else {
|
||||||
|
search.params['begin' + propName] = dateRange[0]
|
||||||
|
search.params['end' + propName] = dateRange[1]
|
||||||
|
}
|
||||||
|
return search
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回显数据字典
|
||||||
|
export function selectDictLabel(datas, value) {
|
||||||
|
if (value === undefined) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
var actions = []
|
||||||
|
Object.keys(datas).some((key) => {
|
||||||
|
if (datas[key].value == ('' + value)) {
|
||||||
|
actions.push(datas[key].label)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (actions.length === 0) {
|
||||||
|
actions.push(value)
|
||||||
|
}
|
||||||
|
return actions.join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回显数据字典(字符串、数组)
|
||||||
|
export function selectDictLabels(datas, value, separator) {
|
||||||
|
if (value === undefined || value.length === 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
value = value.join(',')
|
||||||
|
}
|
||||||
|
var actions = []
|
||||||
|
var currentSeparator = undefined === separator ? ',' : separator
|
||||||
|
var temp = value.split(currentSeparator)
|
||||||
|
Object.keys(value.split(currentSeparator)).some((val) => {
|
||||||
|
var match = false
|
||||||
|
Object.keys(datas).some((key) => {
|
||||||
|
if (datas[key].value == ('' + temp[val])) {
|
||||||
|
actions.push(datas[key].label + currentSeparator)
|
||||||
|
match = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!match) {
|
||||||
|
actions.push(temp[val] + currentSeparator)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return actions.join('').substring(0, actions.join('').length - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 字符串格式化(%s )
|
||||||
|
export function sprintf(str) {
|
||||||
|
var args = arguments, flag = true, i = 1
|
||||||
|
str = str.replace(/%s/g, function() {
|
||||||
|
var arg = args[i++]
|
||||||
|
if (typeof arg === 'undefined') {
|
||||||
|
flag = false
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return arg
|
||||||
|
})
|
||||||
|
return flag ? str : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换字符串,undefined,null等转化为""
|
||||||
|
export function parseStrEmpty(str) {
|
||||||
|
if (!str || str == 'undefined' || str == 'null') {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据合并
|
||||||
|
export function mergeRecursive(source, target) {
|
||||||
|
for (var p in target) {
|
||||||
|
try {
|
||||||
|
if (target[p].constructor == Object) {
|
||||||
|
source[p] = mergeRecursive(source[p], target[p])
|
||||||
|
} else {
|
||||||
|
source[p] = target[p]
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
source[p] = target[p]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return source
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造树型结构数据
|
||||||
|
* @param {*} data 数据源
|
||||||
|
* @param {*} id id字段 默认 'id'
|
||||||
|
* @param {*} parentId 父节点字段 默认 'parentId'
|
||||||
|
* @param {*} children 孩子节点字段 默认 'children'
|
||||||
|
*/
|
||||||
|
export function handleTree(data, id, parentId, children) {
|
||||||
|
let config = {
|
||||||
|
id: id || 'id',
|
||||||
|
parentId: parentId || 'parentId',
|
||||||
|
childrenList: children || 'children'
|
||||||
|
}
|
||||||
|
|
||||||
|
var childrenListMap = {}
|
||||||
|
var nodeIds = {}
|
||||||
|
var tree = []
|
||||||
|
|
||||||
|
for (let d of data) {
|
||||||
|
let parentId = d[config.parentId]
|
||||||
|
if (childrenListMap[parentId] == null) {
|
||||||
|
childrenListMap[parentId] = []
|
||||||
|
}
|
||||||
|
nodeIds[d[config.id]] = d
|
||||||
|
childrenListMap[parentId].push(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let d of data) {
|
||||||
|
let parentId = d[config.parentId]
|
||||||
|
if (nodeIds[parentId] == null) {
|
||||||
|
tree.push(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let t of tree) {
|
||||||
|
adaptToChildrenList(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
function adaptToChildrenList(o) {
|
||||||
|
if (childrenListMap[o[config.id]] !== null) {
|
||||||
|
o[config.childrenList] = childrenListMap[o[config.id]]
|
||||||
|
}
|
||||||
|
if (o[config.childrenList]) {
|
||||||
|
for (let c of o[config.childrenList]) {
|
||||||
|
adaptToChildrenList(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tree
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数处理
|
||||||
|
* @param {*} params 参数
|
||||||
|
*/
|
||||||
|
export function tansParams(params) {
|
||||||
|
let result = ''
|
||||||
|
for (const propName of Object.keys(params)) {
|
||||||
|
const value = params[propName]
|
||||||
|
var part = encodeURIComponent(propName) + '='
|
||||||
|
if (value !== null && value !== '' && typeof (value) !== 'undefined') {
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
for (const key of Object.keys(value)) {
|
||||||
|
if (value[key] !== null && value[key] !== '' && typeof (value[key]) !== 'undefined') {
|
||||||
|
let params = propName + '[' + key + ']'
|
||||||
|
var subPart = encodeURIComponent(params) + '='
|
||||||
|
result += subPart + encodeURIComponent(value[key]) + '&'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result += part + encodeURIComponent(value) + '&'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证是否为blob格式
|
||||||
|
export function blobValidate(data) {
|
||||||
|
return data.type !== 'application/json'
|
||||||
|
}
|
||||||
|
|
@ -2,9 +2,17 @@ import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
|
||||||
|
|
||||||
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||||
|
|
||||||
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
|
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
|
||||||
|
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
|
||||||
|
|
||||||
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y='
|
const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
|
||||||
|
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
|
||||||
|
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
|
||||||
|
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
|
||||||
|
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
|
||||||
|
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
|
||||||
|
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
|
||||||
|
'UP8iWi1Qw0Y='
|
||||||
|
|
||||||
// 加密
|
// 加密
|
||||||
export function encrypt(txt) {
|
export function encrypt(txt) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
// src/config/passwordConfig.js
|
||||||
|
export default {
|
||||||
|
minLength: 8, // 密码最小长度
|
||||||
|
maxLength: 16, // 密码最大长度
|
||||||
|
requireUpperCase: true, // 是否需要大写字母
|
||||||
|
requireLowerCase: true, // 是否需要小写字母
|
||||||
|
requireDigit: true, // 是否需要数字
|
||||||
|
requireSpecialChar: true, // 是否需要特殊字符
|
||||||
|
weakPasswords: ['123456', 'password', 'qwerty'], // 弱密码列表
|
||||||
|
restrictConsecutiveChars: true, // 是否限制连续字符
|
||||||
|
maxConsecutiveChars: 3, // 最大连续字符数
|
||||||
|
excludeUsernameInPassword: true, // 是否不允许密码包含用户名
|
||||||
|
passwordHistoryLimit: 5 // 历史密码限制条数
|
||||||
|
}
|
||||||
|
|
@ -15,10 +15,8 @@ export function checkPermi(value) {
|
||||||
return all_permission === permission || permissionDatas.includes(permission)
|
return all_permission === permission || permissionDatas.includes(permission)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!hasPermission) {
|
return hasPermission;
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} else {
|
} else {
|
||||||
console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
|
console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
|
||||||
return false
|
return false
|
||||||
|
|
@ -40,10 +38,8 @@ export function checkRole(value) {
|
||||||
return super_admin === role || permissionRoles.includes(role)
|
return super_admin === role || permissionRoles.includes(role)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!hasRole) {
|
return hasRole;
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} else {
|
} else {
|
||||||
console.error(`need roles! Like checkRole="['admin','editor']"`)
|
console.error(`need roles! Like checkRole="['admin','editor']"`)
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,21 @@ import { Notification, MessageBox, Message, Loading } from 'element-ui'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from '@/utils/auth'
|
||||||
import errorCode from '@/utils/errorCode'
|
import errorCode from '@/utils/errorCode'
|
||||||
import { tansParams, blobValidate } from "@/utils/ruoyi";
|
import { tansParams, blobValidate } from '@/utils/bonus'
|
||||||
import cache from '@/plugins/cache'
|
import cache from '@/plugins/cache'
|
||||||
import { saveAs } from 'file-saver'
|
import { saveAs } from 'file-saver'
|
||||||
|
import { encryptCBC, decryptCBC } from '@/utils/aescbc'
|
||||||
|
import { CONFIG } from '@/utils/configure'
|
||||||
|
import { hashWithSM3AndSalt } from '@/utils/sm'
|
||||||
|
|
||||||
let downloadLoadingInstance;
|
//let token = localStorage.getItem("tokens");
|
||||||
|
|
||||||
|
let downloadLoadingInstance
|
||||||
// 是否显示重新登录
|
// 是否显示重新登录
|
||||||
export let isRelogin = { show: false };
|
export let isRelogin = { show: false }
|
||||||
|
|
||||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
||||||
|
|
||||||
// 创建axios实例
|
// 创建axios实例
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||||
|
|
@ -20,15 +26,47 @@ const service = axios.create({
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
})
|
})
|
||||||
|
|
||||||
// request拦截器
|
// request 拦截器
|
||||||
service.interceptors.request.use(config => {
|
service.interceptors.request.use(config => {
|
||||||
// 是否需要设置 token
|
// 提取 headers 和方法
|
||||||
const isToken = (config.headers || {}).isToken === false
|
const headers = config.headers || {}
|
||||||
// 是否需要防止数据重复提交
|
const {
|
||||||
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
|
isToken = true,
|
||||||
if (getToken() && !isToken) {
|
encryptRequest = true,
|
||||||
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
checkIntegrity = true,
|
||||||
|
encryptResponse = true,
|
||||||
|
repeatSubmit = false
|
||||||
|
} = headers
|
||||||
|
|
||||||
|
// 设置请求头
|
||||||
|
//入参加密
|
||||||
|
config.headers['encryptRequest'] = CONFIG.dataSettings.encryptRequest && encryptRequest ? 'true' : 'false'
|
||||||
|
// 数据完整性校验
|
||||||
|
config.headers['checkIntegrity'] = CONFIG.dataSettings.integrityCheck && checkIntegrity ? 'true' : 'false'
|
||||||
|
//回参是否加密
|
||||||
|
config.headers['encryptResponse'] = CONFIG.dataSettings.encryptResponse && encryptResponse ? 'true' : 'false'
|
||||||
|
|
||||||
|
const isRepeatSubmit = repeatSubmit
|
||||||
|
// 处理 Token
|
||||||
|
if (getToken() && isToken) {
|
||||||
|
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义 token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // 处理 GET 请求
|
||||||
|
// if (config.method === 'get' && config.params) {
|
||||||
|
// let params = tansParams(config.params).slice(0, -1)
|
||||||
|
// // 数据完整性校验
|
||||||
|
// if (CONFIG.dataSettings.integrityCheck && checkIntegrity) {
|
||||||
|
// config.headers['Params-Hash'] = hashWithSM3AndSalt(params)
|
||||||
|
// }
|
||||||
|
// // 加密参数
|
||||||
|
// if (CONFIG.dataSettings.encryptRequest && encryptRequest) {
|
||||||
|
// params = encryptCBC(params)
|
||||||
|
// }
|
||||||
|
// config.url = `${config.url}?${params}`
|
||||||
|
// config.params = {}
|
||||||
|
// }
|
||||||
|
|
||||||
// get请求映射params参数
|
// get请求映射params参数
|
||||||
if (config.method === 'get' && config.params) {
|
if (config.method === 'get' && config.params) {
|
||||||
let url = config.url + '?' + tansParams(config.params);
|
let url = config.url + '?' + tansParams(config.params);
|
||||||
|
|
@ -36,89 +74,97 @@ service.interceptors.request.use(config => {
|
||||||
config.params = {};
|
config.params = {};
|
||||||
config.url = url;
|
config.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
||||||
const requestObj = {
|
let data = typeof config.data === 'object' ? JSON.stringify(config.data) : config.data
|
||||||
url: config.url,
|
let contentType = config.headers['Content-Type']
|
||||||
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
if (contentType.includes('application/json')) {
|
||||||
time: new Date().getTime()
|
// 数据完整性校验
|
||||||
}
|
if (CONFIG.dataSettings.integrityCheck && checkIntegrity) {
|
||||||
const requestSize = Object.keys(JSON.stringify(requestObj)).length; // 请求数据大小
|
config.headers['Params-Hash'] = hashWithSM3AndSalt(data)
|
||||||
const limitSize = 5 * 1024 * 1024; // 限制存放数据5M
|
config.data = data
|
||||||
if (requestSize >= limitSize) {
|
}
|
||||||
console.warn(`[${config.url}]: ` + '请求数据大小超出允许的5M限制,无法进行防重复提交验证。')
|
// 加密数据
|
||||||
return config;
|
if (CONFIG.dataSettings.encryptRequest && encryptRequest) {
|
||||||
}
|
config.data = encryptCBC(data)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 检查请求数据大小
|
||||||
|
const requestSize = JSON.stringify({ url: config.url, data: data, time: Date.now() }).length
|
||||||
|
const limitSize = 1000 * 1024 * 1024 // 限制存放数据 5MB
|
||||||
|
|
||||||
|
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
|
return config
|
||||||
}, error => {
|
}, error => {
|
||||||
console.log(error)
|
console.error(error)
|
||||||
Promise.reject(error)
|
return Promise.reject(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
service.interceptors.response.use(res => {
|
service.interceptors.response.use(res => {
|
||||||
// 未设置状态码则默认成功状态
|
if (res.headers.encryptresponse) {
|
||||||
const code = res.data.code || 200;
|
res.data = JSON.parse(decryptCBC(res.data))
|
||||||
// 获取错误信息
|
|
||||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
||||||
// 二进制数据则直接返回
|
|
||||||
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(() => {
|
|
||||||
isRelogin.show = false;
|
|
||||||
store.dispatch('LogOut').then(() => {
|
|
||||||
// location.href = '/login';
|
|
||||||
// location.href = '/gl/login';
|
|
||||||
|
|
||||||
location.href = process.env.VUE_APP_ENV+'login'
|
|
||||||
})
|
|
||||||
}).catch(() => {
|
|
||||||
isRelogin.show = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
// 未设置状态码则默认成功状态
|
||||||
} else if (code === 500) {
|
const code = res.data.code || 200
|
||||||
Message({ message: msg, type: 'error' })
|
// 获取错误信息
|
||||||
return Promise.reject(new Error(msg))
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||||
} else if (code === 601) {
|
// 二进制数据则直接返回
|
||||||
Message({ message: msg, type: 'warning' })
|
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||||
return Promise.reject('error')
|
return res.data
|
||||||
} else if (code !== 200) {
|
}
|
||||||
Notification.error({ title: msg })
|
if (code === 401) {
|
||||||
return Promise.reject('error')
|
if (!isRelogin.show) {
|
||||||
} else {
|
isRelogin.show = true
|
||||||
return res.data
|
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
||||||
}
|
confirmButtonText: '重新登录',
|
||||||
},
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
isRelogin.show = false
|
||||||
|
store.dispatch('LogOut').then(() => {
|
||||||
|
location.href = '/index'
|
||||||
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
isRelogin.show = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
||||||
|
} else if (code === 500) {
|
||||||
|
Message({ message: msg, type: 'error' })
|
||||||
|
return Promise.reject(new Error(msg))
|
||||||
|
} else if (code === 601) {
|
||||||
|
Message({ message: msg, type: 'warning' })
|
||||||
|
return Promise.reject('error')
|
||||||
|
} else if (code !== 200) {
|
||||||
|
Notification.error({ title: msg })
|
||||||
|
return Promise.reject('error')
|
||||||
|
} else {
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error)
|
console.log('err' + error)
|
||||||
let { message } = error;
|
let { message } = error
|
||||||
if (message == "Network Error") {
|
if (message == 'Network Error') {
|
||||||
message = "后端接口连接异常";
|
message = '后端接口连接异常'
|
||||||
} else if (message.includes("timeout")) {
|
} else if (message.includes('timeout')) {
|
||||||
message = "系统接口请求超时";
|
message = '系统接口请求超时'
|
||||||
} else if (message.includes("Request failed with status code")) {
|
} else if (message.includes('Request failed with status code')) {
|
||||||
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
message = '系统接口' + message.substr(message.length - 3) + '异常'
|
||||||
}
|
}
|
||||||
Message({ message: message, type: 'error', duration: 5 * 1000 })
|
Message({ message: message, type: 'error', duration: 5 * 1000 })
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
|
|
@ -127,55 +173,35 @@ service.interceptors.response.use(res => {
|
||||||
|
|
||||||
// 通用下载方法
|
// 通用下载方法
|
||||||
export function download(url, params, filename, config) {
|
export function download(url, params, filename, config) {
|
||||||
downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })
|
downloadLoadingInstance = Loading.service({
|
||||||
|
text: '正在下载数据,请稍候',
|
||||||
|
spinner: 'el-icon-loading',
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)'
|
||||||
|
})
|
||||||
return service.post(url, params, {
|
return service.post(url, params, {
|
||||||
transformRequest: [(params) => { return tansParams(params) }],
|
transformRequest: [(params) => {
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
return tansParams(params)
|
||||||
|
}],
|
||||||
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded', encryptResponse: false},
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
...config
|
...config
|
||||||
}).then(async (data) => {
|
}).then(async(data) => {
|
||||||
const isBlob = blobValidate(data);
|
const isBlob = blobValidate(data)
|
||||||
if (isBlob) {
|
if (isBlob) {
|
||||||
const blob = new Blob([data])
|
const blob = new Blob([data])
|
||||||
saveAs(blob, filename)
|
saveAs(blob, filename)
|
||||||
} else {
|
} else {
|
||||||
const resText = await data.text();
|
const resText = await data.text()
|
||||||
const rspObj = JSON.parse(resText);
|
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);
|
Message.error(errMsg)
|
||||||
}
|
}
|
||||||
downloadLoadingInstance.close();
|
downloadLoadingInstance.close()
|
||||||
}).catch((r) => {
|
}).catch((r) => {
|
||||||
console.error(r)
|
console.error(r)
|
||||||
Message.error('下载文件出现错误,请联系管理员!')
|
Message.error('下载文件出现错误,请联系管理员!')
|
||||||
downloadLoadingInstance.close();
|
downloadLoadingInstance.close()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通用下载方法
|
|
||||||
export function downloadJson(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 params }],
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
responseType: 'blob',
|
|
||||||
...config
|
|
||||||
}).then(async (data) => {
|
|
||||||
const isBlob = blobValidate(data);
|
|
||||||
if (isBlob) {
|
|
||||||
const blob = new Blob([data])
|
|
||||||
saveAs(blob, filename)
|
|
||||||
} else {
|
|
||||||
const resText = await data.text();
|
|
||||||
const rspObj = JSON.parse(resText);
|
|
||||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
|
||||||
Message.error(errMsg);
|
|
||||||
}
|
|
||||||
downloadLoadingInstance.close();
|
|
||||||
}).catch((r) => {
|
|
||||||
console.error(r)
|
|
||||||
Message.error('下载文件出现错误,请联系管理员!')
|
|
||||||
downloadLoadingInstance.close();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
export default service
|
export default service
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
// src/utils/encryption.js
|
||||||
|
import sm3 from 'sm-crypto/src/sm3'
|
||||||
|
import { SM_CONFIG } from './configure'
|
||||||
|
|
||||||
|
// SM3 哈希
|
||||||
|
export function hashSM3(text) {
|
||||||
|
// 对数据进行哈希计算
|
||||||
|
return sm3(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 SM3 进行哈希并加入盐值
|
||||||
|
export function hashWithSM3AndSalt(text) {
|
||||||
|
// 将文本和盐值拼接在一起
|
||||||
|
const textWithSalt = SM_CONFIG.SALT + text
|
||||||
|
// 使用 SM3 进行哈希
|
||||||
|
return hashSM3(textWithSalt)
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { CONFIG } from '@/utils/configure'
|
||||||
|
import passwordConfig from '@/utils/passwordConfig'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} path
|
* @param {string} path
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
|
|
@ -65,10 +68,7 @@ export function validEmail(email) {
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
export function isString(str) {
|
export function isString(str) {
|
||||||
if (typeof str === 'string' || str instanceof String) {
|
return typeof str === 'string' || str instanceof String
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -83,12 +83,129 @@ export function isArray(arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} str
|
* 密码的正则表达式 最少8个字符,最多20个字符,至少一个字母,一个数字和一个特殊字符:
|
||||||
|
* @param {string} password
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
export function validPwd(value) {
|
||||||
|
const reg = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,20}$/
|
||||||
|
return reg.test(value)
|
||||||
|
}
|
||||||
|
|
||||||
// 密码规则:8-20位,必须包含字母、数字、特殊字符中的两种
|
/**
|
||||||
export function validPassword(str) {
|
* 弱:长度至少为8个字符。
|
||||||
const reg = /^(?!.*(?:111|888|123|234|345|456|567|678|789|1234|2345|3456|4567|5678|6789|12345|23456|34567|45678|56789|abc|abcd|abcde|abcdef|abcdefg|qwe|qwer|qwert|qwerty|asdf|asdfg|asdfgh|password|passw0rd|letmein|welcome|admin|user|test|pass|root|login))(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*()_+{}\[\]:;"'|\\,.<>\/?~-]).{8,16}$/
|
* 一般:长度至少为8个字符,并包含至少一种字符类型。
|
||||||
return reg.test(str)
|
* 强:长度至少为8个字符,并包含至少两种字符类型。
|
||||||
}
|
* 非常强:长度至少为8个字符,并包含所有四种字符类型。
|
||||||
|
* @param rule
|
||||||
|
* @param value
|
||||||
|
* @param callback
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function validatePassword(rule, value, callback) {
|
||||||
|
if (!value) {
|
||||||
|
return callback(new Error('请输入密码'))
|
||||||
|
}
|
||||||
|
|
||||||
|
const lengthRegex = /^.{8,20}$/
|
||||||
|
const uppercaseRegex = /[A-Z]/
|
||||||
|
const lowercaseRegex = /[a-z]/
|
||||||
|
const digitRegex = /\d/
|
||||||
|
const specialCharRegex = /[!@#$%^&*(),.?":{}|<>]/
|
||||||
|
|
||||||
|
if (!lengthRegex.test(value)) {
|
||||||
|
return callback(new Error('密码长度必须为8到20位'))
|
||||||
|
}
|
||||||
|
|
||||||
|
const checks = [
|
||||||
|
{ regex: uppercaseRegex, message: '必须包含至少一个大写字母' },
|
||||||
|
{ regex: lowercaseRegex, message: '必须包含至少一个小写字母' },
|
||||||
|
{ regex: digitRegex, message: '必须包含至少一个数字' },
|
||||||
|
{ regex: specialCharRegex, message: '必须包含至少一个特殊字符' }
|
||||||
|
]
|
||||||
|
|
||||||
|
let passedChecks = checks.filter(check => check.regex.test(value)).length
|
||||||
|
|
||||||
|
let requiredChecks
|
||||||
|
switch (CONFIG.STRENGTH) {
|
||||||
|
case 'weak':
|
||||||
|
requiredChecks = 1
|
||||||
|
break
|
||||||
|
case 'medium':
|
||||||
|
requiredChecks = 2
|
||||||
|
break
|
||||||
|
case 'strong':
|
||||||
|
requiredChecks = 3
|
||||||
|
break
|
||||||
|
case 'very-strong':
|
||||||
|
requiredChecks = 4
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return callback(new Error('请选择有效的密码强度'))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passedChecks < requiredChecks) {
|
||||||
|
return callback(new Error(`密码至少包含 ${requiredChecks} 类字符(大写字母,小写字母,数字,特殊字符)`))
|
||||||
|
}
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validateNewPassword(rule, value, callback) {
|
||||||
|
// 使用配置文件中的策略进行验证
|
||||||
|
|
||||||
|
// 1. 检查密码长度
|
||||||
|
if (value.length < passwordConfig.minLength || value.length > passwordConfig.maxLength) {
|
||||||
|
callback(new Error('密码长度应为' + passwordConfig.minLength + '至' + passwordConfig.maxLength + '位!'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 检查密码复杂度
|
||||||
|
const hasUpperCase = /[A-Z]/.test(value)
|
||||||
|
const hasLowerCase = /[a-z]/.test(value)
|
||||||
|
const hasDigit = /\d/.test(value)
|
||||||
|
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(value)
|
||||||
|
|
||||||
|
if (passwordConfig.requireUpperCase && !hasUpperCase) {
|
||||||
|
callback(new Error('密码必须包含大写字母!'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (passwordConfig.requireLowerCase && !hasLowerCase) {
|
||||||
|
callback(new Error('密码必须包含小写字母!'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (passwordConfig.requireDigit && !hasDigit) {
|
||||||
|
callback(new Error('密码必须包含数字!'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (passwordConfig.requireSpecialChar && !hasSpecialChar) {
|
||||||
|
callback(new Error('密码必须包含特殊字符!'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 3. 检查是否包含弱密码
|
||||||
|
for (const weakPwd of passwordConfig.weakPasswords) {
|
||||||
|
if (value.includes(weakPwd)) {
|
||||||
|
callback(new Error(`密码包含常见的弱密码片段: ${weakPwd}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 4. 检查是否包含超过规定数量的连续字符
|
||||||
|
if (passwordConfig.restrictConsecutiveChars && containsConsecutiveCharacters(value, passwordConfig.maxConsecutiveChars)) {
|
||||||
|
callback(new Error(`密码不能包含超过${passwordConfig.maxConsecutiveChars}位连续字符!`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
callback() // 验证成功
|
||||||
|
}
|
||||||
|
|
||||||
|
function containsConsecutiveCharacters(password, maxConsecutive) {
|
||||||
|
let count = 1
|
||||||
|
for (let i = 1; i < password.length; i++) {
|
||||||
|
if (password[i] === password[i - 1]) {
|
||||||
|
count++
|
||||||
|
if (count > maxConsecutive) return true
|
||||||
|
} else {
|
||||||
|
count = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue