axios.js 里面的请求拦截器,响应拦截器可以处理一些需求
"use strict";
import Vue from 'vue';
import axios from "axios";
import router from '@/router'
import {clearLoginInfo} from '@/utils'
import {
Message,
Loading
} from 'element-ui'
// Full config: https://github.com/axios/axios#request-config
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// 超时时间
axios.defaults.timeout = 60000*120
// 跨域请求,允许保存cookie
axios.defaults.withCredentials = true
axios.defaults.headers = {'Content-Type': 'application/json; charset=utf-8'}
let loading
axios.interceptors.request.use(
config => {
console.log(config,111111);
let showLoading = true;
if (config.hideloading) {
showLoading = false
}
console.log(router.currentRoute.name)
if(location.href.indexOf("contrast")>-1){
showLoading = false;
}
config.headers["fromProject"] = window.SITE_CONFIG["projectKey"];//这个项目这边是添加token
if (window.top == window.self) {//判断ifarme嵌套
config.headers['token'] = Vue.cookie.get('token')
} else if (window.top !== window.self) {
config.headers['token'] = window.localStorage.getItem("token")
}
console.log(showLoading);
if (showLoading) {
loading = Loading.service({
text: config.loadtext||'加载中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
}
if(config.isFormData){
config.headers["Content-Type"] = "multipart/form-data"
}
if (!config.rest) {
config.url = window.SITE_CONFIG["baseUrl"]+config.url;
}else{
delete config.withCredentials;
}
console.log(config,router);
if(router.currentRoute.name=='compare'&&config.url.indexOf(window.SITE_CONFIG["esProUrl"])>-1){
let ndata = config.data;
ndata["highlight"] = 1;
ndata["excludes"] = ["content"];
config.data = ndata;
}
let type = config.method
let defaults = {}
if (type === 'post') {
// post请求参数处理
// json: 'application/json; charset=utf-8'
// form: 'application/x-www-form-urlencoded; charset=utf-8'
// config.data = config.isFormData ? config.data : JSON.stringify(config.data)
} else if (type === 'get') {
// get请求参数处理
// config.data = config.isFormData ? config.data : JSON.stringify(config.data)
// config.params = merge(defaults, config.params)
}
// Do something before request is sent
return config;
},
error => {
// Do something with request error
return Promise.reject(error);
}
);
// Add a response interceptor
axios.interceptors.response.use(
response=>{
if(loading){
loading.close()
}
console.log(response);
if (response.data instanceof Blob || response.config.url.split(".").pop().indexOf("txt") > -1 || response.config.url.split(".").pop().indexOf("downExcel") > -1 || response.config.url.split(".").pop().indexOf("downSameExcel") > -1 || response.config.url.split(".").pop().indexOf("exportByTableId") > -1 || response.config.url.split(".").pop().indexOf("exportExcel") > -1) {//这些处理一些情况 导出表格什么的
// console.log(response.data, 9898)
return response.data;
}
if(response.config.url.indexOf("china-map")>-1){
return response;
}
if (response.data && response.data.code === 401) { // 401, token失效
clearLoginInfo()
router.replace({path:"/login"});
// setTimeout(()=>{
// location.reload();
// },200)
}
let code = response.data.code;
let msg = response.data.result||response.data.message||response.data.msg;
if(!response.config.notip){
Message({
message: code=="0"||code=="0000"||response.data.success?"操作成功":msg,
type: code=="0"||code=="0000"||response.data.success?"success":'error',
showClose: true,
duration: 1500
})
}
// Do something with response data
return response;
},
error=> {
if(loading){
loading.close()
}
console.error(error);
if(typeof error == "object"&&error.response){
let msg = error.response.data.result;
Message({
message: msg,
type: 'error',
showClose: true,
duration: 1500
})
}
// Do something with response error
return Promise.reject(error);
}
);
export default axios;
utils/index.js 工具函数
import Vue from 'vue';
import router from '@/router'
import store from '@/store'
const base64ToBlob = function(base64Data) {
let arr = base64Data.split(','),
fileType = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
l = bstr.length,
u8Arr = new Uint8Array(l);
while (l--) {
u8Arr[l] = bstr.charCodeAt(l);
}
return new Blob([u8Arr], {
type: fileType
});
};
// blob转file
const blobToFile = function(newBlob, fileName) {
newBlob.lastModifiedDate = new Date();
newBlob.name = fileName;
return newBlob;
};
export function blobUrlToDataURL(blob,cb) {
var a = new FileReader();
a.readAsDataURL(blob);//读取文件保存在result中
a.onload = function (e) {
var getRes = e.target.result;//读取的结果在result中
cb&&cb(getRes);
}
}
export function deepclone(obj){
var o;
// 如果 他是对象object的话 , 因为null,object,array 也是'object';
if (typeof obj === 'object') {
// 如果 他是空的话
if (obj === null) {
o = null;
}
else {
// 如果 他是数组arr的话
if (obj instanceof Array) {
o = [];
for (var i = 0, len = obj.length; i < len; i++) {
o.push(deepclone(obj[ i ]));
}
}
// 如果 他是对象object的话
else {
o = {};
for (var j in obj) {
if(j!="root"&&j!="parent"){
o[ j ] = deepclone(obj[ j ]);
}
}
}
}
}
else {
o = obj;
}
return o;
};
/**
* 获取uuid
*/
export function getUUID () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
})
}
export function uintbase64(src) {
var toBase64 = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
];
let dstLen = Math.ceil(src.length * 4 / 3);
let dst = new Array(dstLen);
let pos = 0;
let dstIndex = 0;
let nextLeft = 0;
src.forEach( b => {
let r = 0;
if (pos == 0) {
r = b >> 2;
dst[dstIndex++] = toBase64[nextLeft + r];
nextLeft = (b & 0x03) << 4;
} else if (pos == 1) {
r = b >> 4;
dst[dstIndex++] = toBase64[nextLeft + r];
nextLeft = (b & 0x0F) << 2;
} else if (pos == 2) {
r = b >> 6;
dst[dstIndex++] = toBase64[nextLeft + r];
dst[dstIndex++] = toBase64[b & 0x3F];
nextLeft = 0;
}
pos++;
if (pos == 3) {
pos = 0;
}
});
if (pos != 0) {
dst[dstIndex] = toBase64[nextLeft];
}
return dst.join('');
}
export function getUUIDShort () {
var returnBase = function (number, base) {
return (number).toString(base).toLowerCase()
}
var rand = function (max) {
return Math.floor(Math.random() * (max + 1))
}
var getIntegerBits = function (val, start, end) {
var base16 = returnBase(val, 16)
var quadArray = new Array()
var quadString = ''
var i = 0
for (i = 0; i < base16.length; i++) {
quadArray.push(base16.substring(i, i + 1))
}
for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
if (!quadArray[i] || quadArray[i] == '') quadString += '0'
else quadString += quadArray[i]
}
return quadString
}
var dg = new Date(1582, 10, 15, 0, 0, 0, 0)
var dc = new Date()
var t = dc.getTime() - dg.getTime()
var tl = getIntegerBits(t, 0, 31)
var tm = getIntegerBits(t, 32, 47)
var thv = getIntegerBits(t, 48, 59) + '1' // version 1, security version is 2
var csar = getIntegerBits(rand(4095), 0, 7)
var csl = getIntegerBits(rand(4095), 0, 7)
var n = getIntegerBits(rand(8191), 0, 7) +
getIntegerBits(rand(8191), 8, 15) +
getIntegerBits(rand(8191), 0, 7) +
getIntegerBits(rand(8191), 8, 15) +
getIntegerBits(rand(8191), 0, 15) // this last number is two octets long
return tl + tm + thv + csar + csl + n
}
/**
* 清除登录信息
*/
export function clearLoginInfo (noToken) {
if(!noToken)Vue.cookie.delete('token');
console.log("执行清除")
store.commit('resetStore')
router.options.isAddDynamicMenuRoutes = false;
}
export function logout(vm){
vm.$confirm(`确定进行[退出]操作?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
clearLoginInfo(true)
vm.$http({
url: '/sys/logout',
method: 'post',
notip:true
}).then(({data}) => {
vm.$cookie.delete('token')
router.replace({path:"/login"});
setTimeout(()=>{
location.reload();
},200)
})
}).catch(() => {
})
}
//是否为合法的date
function isValidDate(date) {
return date instanceof Date && !isNaN(date.getTime())
}
export function datePattern (date, fmt) {
if(!date)return '';
if(!isValidDate(date))return '';
var o = {
'M+': date.getMonth() + 1, // 月份
'd+': date.getDate(), // 日
'h+': date.getHours() % 12 == 0 ? 12 : date.getHours() % 12, // 小时
'H+': date.getHours(), // 小时
'm+': date.getMinutes(), // 分
's+': date.getSeconds(), // 秒
'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
'S': date.getMilliseconds() // 毫秒
}
var week = {
'0': '\日',
'1': '\一',
'2': '\二',
'3': '\三',
'4': '\四',
'5': '\五',
'6': '\六'
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
if (/(E+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\星\期' : '\周') : '') + week[date.getDay() + ''])
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
}
}
return fmt
}
//获取星期
export function getWeek(dateString) {
var dateArray = dateString.split("-");
var date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
return "星期" + "日一二三四五六".charAt(date.getDay());
};
export function timestampToHHMMSS(value){
var theTime = parseInt(value);// 秒
var theTime1 = 0;// 分
var theTime2 = 0;// 小时
if(theTime > 60) {
theTime1 = parseInt(theTime/60);
theTime = parseInt(theTime%60);
if(theTime1 > 60) {
theTime2 = parseInt(theTime1/60);
theTime1 = parseInt(theTime1%60);
}
}
var result = parseInt(theTime)<10?("0"+parseInt(theTime)):parseInt(theTime);
if(theTime1 > 0) {
result = (parseInt(theTime1)<10?("0"+parseInt(theTime1)):parseInt(theTime1))+":"+result;
}else{
result = "00"+":"+result;
}
if(theTime2 > 0) {
result = (parseInt(theTime2)<10?("0"+parseInt(theTime2)):parseInt(theTime2))+":"+result;
}
return result;
}
export function sortLikeWin(v1,v2){
function commonCompare(v1, v2){
if(v1 === v2){
return 0;
}
else{
return v1<v2?-1:1;
}
}
var a = v1.name;
var b = v2.name;
var reg = /[0-9]+/g;
var lista = a.match(reg);
var listb = b.match(reg);
if (!lista || !listb) {
return commonCompare(a,b);
}
for (var i = 0, minLen = Math.min(lista.length, listb.length) ; i < minLen; i++) {
//数字所在位置序号
var indexa = a.indexOf(lista[i]);
var indexb = b.indexOf(listb[i]);
//数字前面的前缀
var prefixa = a.substring(0, indexa);
var prefixb = b.substring(0, indexb);
//数字的string
var stra = lista[i];
var strb = listb[i];
//数字的值
var numa = parseInt(stra);
var numb = parseInt(strb);
//如果数字的序号不等或前缀不等,属于前缀不同的情况,直接比较
if (indexa != indexb || prefixa != prefixb) {
return commonCompare(a,b);
}
else {
//数字的string全等
if (stra === strb) {
//如果是最后一个数字,比较数字的后缀
if (i == minLen - 1) {
return a.substring(indexa).localeCompare(b.substring(indexb));
}
//如果不是最后一个数字,则循环跳转到下一个数字,并去掉前面相同的部分
else {
a = a.substring(indexa + stra.length);
b = b.substring(indexa + stra.length);
}
}
//如果数字的string不全等,但值相等
else if (numa == numb) {
//直接比较数字前缀0的个数,多的更小
return strb.lastIndexOf(numb + '') - stra.lastIndexOf(numa + '');
}
else {
//如果数字不等,直接比较数字大小
return numa - numb;
}
}
}
}
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result;
const later = function() {
// 据上一次触发时间间隔
const last = +new Date() - timestamp;
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
if (last < wait && last > 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
if (!immediate) {
result = func.apply(context, args);
if (!timeout) context = args = null;
}
}
};
return function(...args) {
context = this;
timestamp = +new Date();
const callNow = immediate && !timeout;
// 如果延时不存在,重新设定延时
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
}
/**
* 树形数据转换
* @param {*} data
* @param {*} id
* @param {*} pid
*/
export function treeDataTranslate (data, id = 'id', pid = 'parentId',order,istyyw,caseId) {
let res = []
let temp = {}
for (let i = 0; i < data.length; i++) {
temp[data[i][id]] = data[i]
if(istyyw&&caseId){
if(data[i].pid==(caseId+"1")){
temp[data[i][id]]['_level'] = 1;
}
}
}
for (let k = 0; k < data.length; k++) {
if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
if (!temp[data[k][pid]]['children']) {
temp[data[k][pid]]['children'] = []
}
if (!temp[data[k][pid]]['_level']) {
temp[data[k][pid]]['_level'] = 1
}
data[k]['_level'] = temp[data[k][pid]]._level + 1
if(istyyw){
data[k]['catalogLevel'] = data[k]['_level'];
}
temp[data[k][pid]]['children'].push(data[k])
} else {
data[k]['_level'] = 1;
if(istyyw){
data[k]['catalogLevel'] = 1;
}
res.push(data[k])
}
}
function orderFunc(a,b){
if(!a[order])a[order] = 0;
if(!b[order])b[order] = 0;
return a[order] - b[order];
}
function sortDataHandle(arr){
arr = arr.sort(orderFunc);
for(var i = 0;i<arr.length;i++){
if(arr[i].children&&arr[i].children.length){
arr[i].children = sortDataHandle(arr[i].children);
}
}
return arr;
}
if(order)res = sortDataHandle(res);
// console.log(res);
return res
}
export function blobToBase64(blob, callback) {
var reader = new FileReader();
reader.onload = function() {
var dataUrl = reader.result;
var base64 = dataUrl.split(',')[1];
callback(base64);
};
reader.readAsDataURL(blob);
};
export function canvasToFile(base64Data,name){
var blob = base64ToBlob(base64Data);
var file = blobToFile(blob, name);
return file;
}
export function JSONToExcelConvertor(JSONData, FileName,title,keys,notital,titleH) {
if(!JSONData)
return;
//转化json为object
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var excel = "<table>";
//设置表头
var row = notital?"":"<tr><th style='border: 1px solid #000000;height:36px;line-height:36px;' align='center' colspan='"+title.length+"'>"+(titleH?titleH:"卷内文件目录")+"</th></tr><tr>";
if(title)
{
//使用标题项
for (var i in title) {
row += "<th style='border: 1px solid #000000;height:36px;line-height:36px;' align='center'>" + title[i] + '</th>';
}
}
else{
//不使用标题项
for (var i in arrData[0]) {
row += "<th style='border: 1px solid #000000;height:36px;line-height:36px;' align='center'>" + i + '</th>';
}
}
excel += row + "</tr>";
//设置数据
for (var i = 0; i < arrData.length; i++) {
var row = "<tr>";
for(var k in title){
if(!keys[k]){
row+= "<td style='border: 1px solid #000000;height:36px;line-height:36px;MSO-NUMBER-FORMAT:\"\@\"'></td>"
}else{
row += "<td style='border: 1px solid #000000;height:36px;line-height:36px;MSO-NUMBER-FORMAT:\"\@\"' align='center'>"+arrData[i][keys[k]]+"</td>"
}
}
// for (var index in arrData[i]) {
// //判断是否有过滤行
// if(filter)
// {
// if(filter.indexOf(index)==-1)
// {
// var value = arrData[i][index] == null ? "" : arrData[i][index];
// row += '<td>' + value + '</td>';
// }
// }
// else
// {
// var value = arrData[i][index] == null ? "" : arrData[i][index];
// row += "<td align='center'>" + value + "</td>";
// }
// }
excel += row + "</tr>";
}
excel += "</table>";
var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
excelFile += "<head>";
excelFile += "<!--[if gte mso 9]>";
excelFile += "<xml>";
excelFile += "<x:ExcelWorkbook>";
excelFile += "<x:ExcelWorksheets>";
excelFile += "<x:ExcelWorksheet>";
excelFile += "<x:Name>";
excelFile += "{worksheet}";
excelFile += "</x:Name>";
excelFile += "<x:WorksheetOptions>";
excelFile += "<x:DisplayGridlines/>";
excelFile += "</x:WorksheetOptions>";
excelFile += "</x:ExcelWorksheet>";
excelFile += "</x:ExcelWorksheets>";
excelFile += "</x:ExcelWorkbook>";
excelFile += "</xml>";
excelFile += "<![endif]-->";
excelFile += "</head>";
excelFile += "<body>";
excelFile += excel;
excelFile += "</body>";
excelFile += "</html>";
var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
var link = document.createElement("a");
link.href = uri;
link.style = "visibility:hidden";
link.download = FileName + ".xls";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
export function Print (dom, options) {
if (!(this instanceof Print)) return new Print(dom, options)
this.options = this.extend({
noPrint: '.no-print',
onStart: function () { },
onEnd: function () { }
}, options)
if ((typeof dom) === 'string') {
this.dom = document.querySelector(dom)
} else {
this.dom = dom
}
this.init()
};
Print.prototype = {
init: function () {
var content = this.getStyle() + this.getHtml()
this.writeIframe(content)
},
extend: function (obj, obj2) {
for (var k in obj2) {
obj[k] = obj2[k]
}
return obj
},
getStyle: function () {
var str = ''
var styles = document.querySelectorAll('style,link')
for (var i = 0; i < styles.length; i++) {
str += styles[i].outerHTML
}
str += '<style>' + (this.options.noPrint ? this.options.noPrint : '.no-print') + '{display:none;}</style>'
return str
},
getHtml: function () {
var inputs = document.querySelectorAll('input')
var textareas = document.querySelectorAll('textarea')
var selects = document.querySelectorAll('select')
for (var k in inputs) {
if (inputs[k].type == 'checkbox' || inputs[k].type == 'radio') {
if (inputs[k].checked == true) {
inputs[k].setAttribute('checked', 'checked')
} else {
inputs[k].removeAttribute('checked')
}
} else if (inputs[k].type == 'text') {
inputs[k].setAttribute('value', inputs[k].value)
}
}
for (var k2 in textareas) {
if (textareas[k2].type == 'textarea') {
textareas[k2].innerHTML = textareas[k2].value
}
}
for (var k3 in selects) {
if (selects[k3].type == 'select-one') {
var child = selects[k3].children
for (var i in child) {
if (child[i].tagName == 'OPTION') {
if (child[i].selected == true) {
child[i].setAttribute('selected', 'selected')
} else {
child[i].removeAttribute('selected')
}
}
}
}
}
return this.dom.outerHTML
},
writeIframe: function (content) {
var w, doc, iframe = document.createElement('iframe'),
f = document.body.appendChild(iframe)
iframe.id = 'myIframe'
iframe.style.position = "absolute";
iframe.style.width = "0";
iframe.style.height = "0";
iframe.style.top = "-10px";
iframe.style.left = "-10px";
// iframe.style = 'position:absolute;width:0;height:0;top:-10px;left:-10px;'
w = f.contentWindow || f.contentDocument
doc = f.contentDocument || f.contentWindow.document
doc.open()
doc.write(content)
doc.close()
this.toPrint(w, function () {
document.body.removeChild(iframe)
})
},
toPrint: function (w, cb) {
var _this = this
w.onload = function () {
try {
setTimeout(function () {
w.focus()
typeof _this.options.onStart === 'function' && _this.options.onStart()
if (!w.document.execCommand('print', false, null)) {
w.print()
}
typeof _this.options.onEnd === 'function' && _this.options.onEnd()
w.close()
cb && cb()
})
} catch (err) {
console.log('err', err)
}
}
}
}
const zS = function (t) {
if ("" == t) return "";
let e = "ae8b516cbffde62a74b726c82eb6748ad41d251480d84ce2e96ebf57ebaa8b22";
if (e = escape(e), null == t || t.length < 8) return void alert(
"A salt value could not be extracted from the encrypted message because it's length is too short. The message cannot be decrypted."
);
if (null == e || e.length <= 0) return void alert("Please enter a password with which to decrypt the message.");
let n = "";
for (let t = 0; t < e.length; t++) n += e.charCodeAt(t).toString();
const o = Math.floor(n.length / 5),
c = parseInt(n.charAt(o) + n.charAt(2 * o) + n.charAt(3 * o) + n.charAt(4 * o) + n.charAt(5 * o)),
l = Math.round(e.length / 2),
r = Math.pow(2, 31) - 1,
d = parseInt(t.substring(t.length - 8, t.length), 16);
for (t = t.substring(0, t.length - 8), n += d; n.length > 10;) n = (parseInt(n.substring(0, 10)) + parseInt(n.substring(
10, n.length))).toString();
n = (c * n + l) % r;
let m = "",
j = "";
for (let e = 0; e < t.length; e += 2) m = parseInt(parseInt(t.substring(e, e + 2), 16) ^ Math.floor(n / r * 255)),
j += String.fromCharCode(m), n = (c * n + l) % r;
return unescape(j)
};
const kD = function(e) {
if ("" == e)
return "";
e = escape(e);
var t = "ae8b516cbffde62a74b726c82eb6748ad41d251480d84ce2e96ebf57ebaa8b22";
if (null == (t = escape(t)) || t.length <= 0)
return alert("Please enter a password with which to encrypt the message."),
null;
for (var n = "", r = 0; r < t.length; r++)
n += t.charCodeAt(r).toString();
var o = Math.floor(n.length / 5)
, c = parseInt(n.charAt(o) + n.charAt(2 * o) + n.charAt(3 * o) + n.charAt(4 * o) + n.charAt(5 * o))
, l = Math.ceil(t.length / 2)
, d = Math.pow(2, 31) - 1;
if (c < 2)
return alert("Algorithm cannot find a suitable hash. Please choose a different password. /nPossible considerations are to choose a more complex or longer password."),
null;
var h = Math.round(1e9 * Math.random()) % 1e8;
for (n += h; n.length > 10; )
n = (parseInt(n.substring(0, 10)) + parseInt(n.substring(10, n.length))).toString();
n = (c * n + l) % d;
for (var f = "", m = "", v = 0; v < e.length; v++)
m += (f = parseInt(e.charCodeAt(v) ^ Math.floor(n / d * 255))) < 16 ? "0" + f.toString(16) : f.toString(16),
n = (c * n + l) % d;
for (h = h.toString(16); h.length < 8; )
h = "0" + h;
return m += h
};
export function $decodeGzipData(form){
let data = null;
try {
const e = atob(form);
data = pako.inflate(e, { to: "string" })
} catch (t) { console.log(t) }
return data
}
export function $urlEncrypt(e) {
if ("string" == typeof e) {
if (1 == e.split("?").length)
return e;
if (2 == e.split("?").length) {
var t = e.split("?");
return t[0] + "?" + kD(t[1])
}
} else if ("object" == typeof e) {
var n = {};
return n[kD(JSON.stringify(e))] = null,
n
}
}
export function openNewWindowLink (opts) { // 在新窗口中打开
opts = opts || {};
var xmlHttp = null;
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlHttp.open('GET', opts.url, true);
xmlHttp.responseType = 'blob';
xmlHttp.onload = function() {
var url = window.URL.createObjectURL(this.response);
var a = document.createElement('a');
a.style.display = 'none';
document.body.appendChild(a);
a.href = url;
a.download = opts.downName;
a.click();
a.remove();
}
xmlHttp.send();
// let a = document.createElement("a");// 创建a标签
// if ('download' in a) {
// a.download = opts.downName;// 设置下载文件的文件名
// }
// (document.body || document.documentElement).appendChild(a);
// a.href = opts.url;// downUrl为后台返回的下载地址
// a.target = '_blank';
// a.click();// 设置点击事件
// a.remove(); // 移除a标签
}
export function downloadFromServer(vm,reqData){
vm.$axios({
url: '/sys/downloadlog/download',
method: 'post',
timeout:1000*60*60,
data:reqData,
responseType: 'blob',
}).then(res => {
const content = res
const blob = new Blob([content],{type:reqData.params.length>1?"application/zip":"application/pdf"});
let fileName = vm.$route.matched[vm.$route.matched.length-1].meta.title+"_"+datePattern(new Date(),"yyyy_MM_dd_HH_mm_ss");
// if(reqData.params.length==1){
// fileName = reqData.params[0].filePath.split("/").pop()
// }
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else {
navigator.msSaveBlob(blob, fileName)
}
}).catch(() => {
});
}
export function getBddyForm(form) {
let e = null;
try {
e = JSON.parse(form)
} catch (t) {
e = JSON.parse($decodeGzipData(form))
}
return e
}
export function tyywUrlDecrypt(query){
if (query) {
const t = Object.keys(query);
if (!(t.length > 0)) return {};
if (query[t[0]]) return query;
const e = zS(t[0]);
if(e.indexOf("&")>-1&&e.indexOf("=")>-1){
const e1 = e.split("&"),
n = {};
for (let i = 0, t = e1.length; i < t; ++i) {
const param = e1[i].substring(e1[i].indexOf("=") + 1),
t = e1[i].slice(0, e1[i].indexOf("=")),
o = param.length > 0 ? param : "";
n[decodeURIComponent(t)] = decodeURIComponent(o)
}
return n
}
}
}
export function zipJson(str){
var binaryString = pako.gzip(encodeURIComponent(str), { to: 'string' })
return btoa(binaryString)
}
export function unzipJson(b64Data){
var strData = atob(b64Data);
// Convert binary string to character-number array
var charData = strData.split('').map(function(x){return x.charCodeAt(0);});
// Turn number array into byte-array
var binData = new Uint8Array(charData);
// // unzip
var data = pako.inflate(binData);
// Convert gunzipped byteArray back to ascii string:
// strData = String.fromCharCode.apply(null, new Uint16Array(data));
var array = new Uint16Array(data)
var res = '';
var chunk = 8 * 1024;
var i;
for (i = 0; i < array.length / chunk; i++) {
res += String.fromCharCode.apply(null, array.slice(i * chunk, (i + 1) * chunk));
}
res += String.fromCharCode.apply(null, array.slice(i * chunk));
strData = res
return decodeURIComponent(strData);
}
function handleChild(childs){
var nlist = [];
for(var j = 0;j<childs.length;j++){
var cd = childs[j];
// if(cd.menuId!="1005"&&cd.menuId!="1503"&&cd.menuId!="1504"&&cd.menuId!='1505'){
nlist.push(cd);
// }
}
return nlist;
}
export function handlerMenu(source){
var menuList = JSON.parse(JSON.stringify(source));
var nlist = [];
for(var i = 0;i<menuList.length;i++){
var v = menuList[i];
if(v.list){
v.list = handleChild(v.list);
}
if(v.children){
v.children = handleChild(v.children);
}
// if(v.menuId!="12"&&v.menuId!='14'&&v.menuId!="16"){
// if(v.menuId=='17'){
// if(window.SITE_CONFIG["mode"]!=2){
// nlist.push(v);
// }
// }else{
nlist.push(v);
// }
// }
}
// console.log(nlist);
return nlist;
}
/**
* 是否有权限
* @param {*} key
*/
export function isAuth (key) {
return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false
}
/**
* 根据userId翻译为realName
* @param userId
*/
export function transUser (userId) {
let userList = JSON.parse(sessionStorage.getItem('userList') || '[]')
if (userList.length > 0) {
for (let i = 0; i < userList.length; i++) {
if (userList[i].userId === userId) {
return userList[i].realName
}
}
}
return '--'
}
export function transDict (code, value) {
if (!value && value !== 0) {
return '--'
}
let dictList = JSON.parse(sessionStorage.getItem('dictList') || '[]')
if (dictList.length > 0) {
for (let i = 0; i < dictList.length; i++) {
if (dictList[i].code === code && dictList[i].value.toString() === value.toString()) {
return dictList[i].name
}
}
}
return '--'
}
/**
* 根据orgNo翻译为orgName
* @param orgNo
*/
export function transOrg (orgNo) {
let orgList = JSON.parse(sessionStorage.getItem('orgList') || '[]')
if (orgList.length > 0) {
for (let i = 0; i < orgList.length; i++) {
if (orgList[i].orgNo === orgNo) {
return orgList[i].orgName
}
}
}
return '--'
}
/**
* 根据api中的方法名字,获取方法内容中的请求参数列表
* @param {*} queryRest
* @returns
*/
export function getFuncInnerContent(queryRest){
let queryRestStr = queryRest.toLocaleString();
console.log(queryRestStr);
let jsonStr = queryRestStr.split("({")[1].split("})")[0];
jsonStr = jsonStr.replace(/\"/g,"'");
console.log(jsonStr);
let params = jsonStr.split(",");
console.log(params);
let obj = {};
params.map((v)=>{
let k = v.split(":")[0];
k = k.replace(/\n/g,"");
k = k.replace(/\s+/g,"");
let vv = v.split(":")[1];
vv = vv.replace(/\s+/g,"");
obj[k]= vv;
})
return obj;
}
md5.js
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
/*
* Calculate the MD5 of an array of little-endian words, and a bit length
*/
function core_md5(x, len) {
/* append padding */
x[len >> 5] |= 0x80 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
for (var i = 0; i < x.length; i += 16) {
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
}
return Array(a, b, c, d);
}
/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t) {
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
}
function md5_ff(a, b, c, d, x, s, t) {
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t) {
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t) {
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t) {
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}
/*
* Calculate the HMAC-MD5, of a key and some data
*/
function core_hmac_md5(key, data) {
var bkey = str2binl(key);
if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
var ipad = Array(16), opad = Array(16);
for (var i = 0; i < 16; i++) {
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5C5C5C5C;
}
var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
return core_md5(opad.concat(hash), 512 + 128);
}
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}
/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
*/
function str2binl(str) {
var bin = Array();
var mask = (1 << chrsz) - 1;
for (var i = 0; i < str.length * chrsz; i += chrsz)
bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
return bin;
}
/*
* Convert an array of little-endian words to a string
*/
function binl2str(bin) {
var str = "";
var mask = (1 << chrsz) - 1;
for (var i = 0; i < bin.length * 32; i += chrsz)
str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
return str;
}
/*
* Convert an array of little-endian words to a hex string.
*/
function binl2hex(binarray) {
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for (var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
}
return str;
}
/*
* Convert an array of little-endian words to a base-64 string
*/
function binl2b64(binarray) {
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var str = "";
for (var i = 0; i < binarray.length * 4; i += 3) {
var triplet = (((binarray[i >> 2] >> 8 * (i % 4)) & 0xFF) << 16)
| (((binarray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xFF) << 8)
| ((binarray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xFF);
for (var j = 0; j < 4; j++) {
if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
}
}
return str;
}
/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
export function hex_md5(s) {
return binl2hex(core_md5(str2binl(s), s.length * chrsz));
}
export function b64_md5(s) {
return binl2b64(core_md5(str2binl(s), s.length * chrsz));
}
export function str_md5(s) {
return binl2str(core_md5(str2binl(s), s.length * chrsz));
}
export function hex_hmac_md5(key, data) {
return binl2hex(core_hmac_md5(key, data));
}
export function b64_hmac_md5(key, data) {
return binl2b64(core_hmac_md5(key, data));
}
export function str_hmac_md5(key, data) {
return binl2str(core_hmac_md5(key, data));
}
/*
* Perform a simple self-test to see if the VM is working
*/
export function md5_vm_test() {
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}