|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
import cookies from './util.cookies' |
|
|
|
|
import {_local,_session} from './util.db' |
|
|
|
|
import { _local, _session } from './util.db' |
|
|
|
|
import { Message } from 'element-ui' |
|
|
|
|
|
|
|
|
|
const util = { |
|
|
|
@ -7,53 +7,53 @@ const util = { |
|
|
|
|
local: _local, |
|
|
|
|
session: _session, |
|
|
|
|
// 传入身份证获取生日
|
|
|
|
|
getBirth(idCard) { |
|
|
|
|
getBirth (idCard) { |
|
|
|
|
var birthday = ""; |
|
|
|
|
if(idCard != null && idCard != ""){ |
|
|
|
|
if(idCard.length == 15){ |
|
|
|
|
birthday = "19"+idCard.slice(6,12); |
|
|
|
|
} else if(idCard.length == 18){ |
|
|
|
|
birthday = idCard.slice(6,14); |
|
|
|
|
if (idCard != null && idCard != "") { |
|
|
|
|
if (idCard.length == 15) { |
|
|
|
|
birthday = "19" + idCard.slice(6, 12); |
|
|
|
|
} else if (idCard.length == 18) { |
|
|
|
|
birthday = idCard.slice(6, 14); |
|
|
|
|
} |
|
|
|
|
birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-"); |
|
|
|
|
birthday = birthday.replace(/(.{4})(.{2})/, "$1-$2-"); |
|
|
|
|
//通过正则表达式来指定输出格式为:1990-01-01
|
|
|
|
|
} |
|
|
|
|
return birthday; |
|
|
|
|
}, |
|
|
|
|
// new Date('2020-11-12 00:00:00') 在IE下失效,因此把-替换成/
|
|
|
|
|
dateCompatible(date) { |
|
|
|
|
dateCompatible (date) { |
|
|
|
|
return date.replace(/\-/g, '/') |
|
|
|
|
}, |
|
|
|
|
// 日期时间前面补零
|
|
|
|
|
formateTime(num) { |
|
|
|
|
formateTime (num) { |
|
|
|
|
return num < 10 ? `0${num}` : num |
|
|
|
|
}, |
|
|
|
|
//返回格式化时间,传参例如:"yyyy-MM-dd hh:mm:ss"
|
|
|
|
|
formatDate(fmt,date) { |
|
|
|
|
formatDate (fmt, date) { |
|
|
|
|
var date = date ? date : new Date() |
|
|
|
|
var o = { |
|
|
|
|
"M+" : date.getMonth()+1, //月份
|
|
|
|
|
"d+" : date.getDate(), //日
|
|
|
|
|
"h+" : date.getHours(), //小时
|
|
|
|
|
"m+" : date.getMinutes(), //分
|
|
|
|
|
"s+" : date.getSeconds(), //秒
|
|
|
|
|
"q+" : Math.floor((date.getMonth()+3)/3), //季度
|
|
|
|
|
"S" : date.getMilliseconds() //毫秒
|
|
|
|
|
"M+": date.getMonth() + 1, //月份
|
|
|
|
|
"d+": date.getDate(), //日
|
|
|
|
|
"h+": date.getHours(), //小时
|
|
|
|
|
"m+": date.getMinutes(), //分
|
|
|
|
|
"s+": date.getSeconds(), //秒
|
|
|
|
|
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
|
|
|
|
|
"S": date.getMilliseconds() //毫秒
|
|
|
|
|
}; |
|
|
|
|
if(/(y+)/.test(fmt)) { |
|
|
|
|
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
|
|
|
|
|
if (/(y+)/.test(fmt)) { |
|
|
|
|
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); |
|
|
|
|
} |
|
|
|
|
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))); |
|
|
|
|
} |
|
|
|
|
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; |
|
|
|
|
}, |
|
|
|
|
// 移除数组中指定值
|
|
|
|
|
removeByValue(arr, val) { |
|
|
|
|
removeByValue (arr, val) { |
|
|
|
|
let index = arr.indexOf(val) |
|
|
|
|
index>0?arr.splice(i, 1):'' |
|
|
|
|
index > 0 ? arr.splice(i, 1) : '' |
|
|
|
|
// for(var i=0; i<arr.length; i++) {
|
|
|
|
|
// if(arr[i] == val) {
|
|
|
|
|
// arr.splice(i, 1);
|
|
|
|
@ -62,52 +62,52 @@ const util = { |
|
|
|
|
// }
|
|
|
|
|
}, |
|
|
|
|
// 传入文件后缀判断是否是视频
|
|
|
|
|
isVideo(ext) { |
|
|
|
|
if('mp4,3gp,mov,m4v,avi,dat,mkv,flv,vob,rmvb,rm,qlv'.includes(ext)) return true |
|
|
|
|
isVideo (ext) { |
|
|
|
|
if ('mp4,3gp,mov,m4v,avi,dat,mkv,flv,vob,rmvb,rm,qlv'.includes(ext)) return true |
|
|
|
|
return false |
|
|
|
|
}, |
|
|
|
|
// 传入文件后缀判断是否是音频
|
|
|
|
|
isAudio(ext) { |
|
|
|
|
if('mp3,aac,ape,flac,wav,wma,amr,mid'.includes(ext)) return true |
|
|
|
|
isAudio (ext) { |
|
|
|
|
if ('mp3,aac,ape,flac,wav,wma,amr,mid'.includes(ext)) return true |
|
|
|
|
return false |
|
|
|
|
}, |
|
|
|
|
// 传入文件后缀判断是否是图片
|
|
|
|
|
isImg(ext) { |
|
|
|
|
if('jpg,jpeg,png,gif,svg,psd'.includes(ext)) return true |
|
|
|
|
isImg (ext) { |
|
|
|
|
if ('jpg,jpeg,png,gif,svg,psd'.includes(ext)) return true |
|
|
|
|
return false |
|
|
|
|
}, |
|
|
|
|
// 传入文件后缀判断是否是pdf以外的文档
|
|
|
|
|
isDoc(ext) { |
|
|
|
|
if(!util.isVideo(ext) && !util.isAudio(ext) && !util.isImg(ext) && ext != 'pdf') return true |
|
|
|
|
isDoc (ext) { |
|
|
|
|
if (!util.isVideo(ext) && !util.isAudio(ext) && !util.isImg(ext) && ext != 'pdf') return true |
|
|
|
|
return false |
|
|
|
|
}, |
|
|
|
|
// 循环去除html标签
|
|
|
|
|
removeHtmlTag(list,attr) { |
|
|
|
|
removeHtmlTag (list, attr) { |
|
|
|
|
list.map(n => { |
|
|
|
|
n[attr] = n[attr].replace(/<\/?.+?>/gi,'') |
|
|
|
|
n[attr] = n[attr].replace(/<\/?.+?>/gi, '') |
|
|
|
|
}) |
|
|
|
|
return list |
|
|
|
|
}, |
|
|
|
|
// 传入文件名获取文件后缀
|
|
|
|
|
getFileExt(fileName) { |
|
|
|
|
getFileExt (fileName) { |
|
|
|
|
return fileName.substring(fileName.lastIndexOf('.') + 1) |
|
|
|
|
}, |
|
|
|
|
// 传入文件名和路径,下载图片视频,支持跨域,a标签加download不支持跨域
|
|
|
|
|
downloadFile(fileName,url) { |
|
|
|
|
downloadFile (fileName, url) { |
|
|
|
|
var x = new XMLHttpRequest() |
|
|
|
|
x.open("GET", url, true) |
|
|
|
|
x.responseType = 'blob' |
|
|
|
|
x.onload=function(e) { |
|
|
|
|
var url = window.URL.createObjectURL(x.response) |
|
|
|
|
var a = document.createElement('a') |
|
|
|
|
a.href = url |
|
|
|
|
a.download = fileName |
|
|
|
|
a.click() |
|
|
|
|
x.onload = function (e) { |
|
|
|
|
var url = window.URL.createObjectURL(x.response) |
|
|
|
|
var a = document.createElement('a') |
|
|
|
|
a.href = url |
|
|
|
|
a.download = fileName |
|
|
|
|
a.click() |
|
|
|
|
} |
|
|
|
|
x.send() |
|
|
|
|
}, |
|
|
|
|
// 传入文件名和数据,下载文件
|
|
|
|
|
downloadFileDirect(fileName,data) { |
|
|
|
|
downloadFileDirect (fileName, data) { |
|
|
|
|
if ('download' in document.createElement('a')) { // 非IE下载
|
|
|
|
|
const elink = document.createElement('a') |
|
|
|
|
elink.download = fileName |
|
|
|
@ -122,17 +122,87 @@ const util = { |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 成功提示
|
|
|
|
|
successMsg(message,duration = 3000) { |
|
|
|
|
return Message.success({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration}) |
|
|
|
|
successMsg (message, duration = 3000) { |
|
|
|
|
return Message.success({ message, showClose: true, offset: (document.documentElement.clientHeight - 40) / 2, duration }) |
|
|
|
|
}, |
|
|
|
|
// 警告提示
|
|
|
|
|
warningMsg(message,duration = 3000) { |
|
|
|
|
return Message.warning({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration}) |
|
|
|
|
warningMsg (message, duration = 3000) { |
|
|
|
|
return Message.warning({ message, showClose: true, offset: (document.documentElement.clientHeight - 40) / 2, duration }) |
|
|
|
|
}, |
|
|
|
|
// 错误提示
|
|
|
|
|
errorMsg(message,duration = 3000) { |
|
|
|
|
return Message.error({message,showClose: true,offset: (document.documentElement.clientHeight - 40) / 2,duration}) |
|
|
|
|
}, |
|
|
|
|
errorMsg (message, duration = 3000) { |
|
|
|
|
return Message.error({ message, showClose: true, offset: (document.documentElement.clientHeight - 40) / 2, duration }) |
|
|
|
|
}, |
|
|
|
|
// 授信年限
|
|
|
|
|
creditTerms: [ |
|
|
|
|
{ |
|
|
|
|
id: 231, |
|
|
|
|
name: '1年' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 232, |
|
|
|
|
name: '3年' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 233, |
|
|
|
|
name: '5年' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 234, |
|
|
|
|
name: '10年' |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
// 还款方式
|
|
|
|
|
repaymentMethods: [ |
|
|
|
|
{ |
|
|
|
|
id: 235, |
|
|
|
|
name: '等额本金' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 236, |
|
|
|
|
name: '等额本息' |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
// 发放方式
|
|
|
|
|
distributionMethods: [ |
|
|
|
|
{ |
|
|
|
|
id: 238, |
|
|
|
|
name: '一次性到账' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 239, |
|
|
|
|
name: '随借随还' |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
// 担保方式
|
|
|
|
|
guaranteeMethods: [ |
|
|
|
|
{ |
|
|
|
|
id: 242, |
|
|
|
|
name: '质押' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 243, |
|
|
|
|
name: '抵押' |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
// 贷款期限
|
|
|
|
|
loanTerms: [ |
|
|
|
|
{ |
|
|
|
|
pointId: 244, |
|
|
|
|
id: 120, |
|
|
|
|
name: '120个月' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
pointId: 245, |
|
|
|
|
id: 240, |
|
|
|
|
name: '240个月' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
pointId: 246, |
|
|
|
|
id: 360, |
|
|
|
|
name: '360个月' |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default util |