赞
踩
export default { /**判断是否为空 * method isEmpty * */ isEmpty(obj) { if (obj == undefined || obj == null) { return true; } else if (typeof obj != "object") { if (typeof obj == "string") { return obj.trim() == ""; } return obj == null; } else if (JSON.stringify(obj) == "{}") { return true; } else if (Array.isArray(obj)) { return obj.length == 0; } else if (JSON.stringify(obj) == "[]") { return true; } }, /**判断是否为非空 * method isNotEmpty * */ isNotEmpty(obj) { return !this.isEmpty(obj); }, /**解密 * params word:解密字段 key:该数据工号 * method decrypt */ decrypt(word,key){ try{ return aes.decrypt( word, key ) }catch(e){ return word } }, /**获取token * method getToken * */ // getToken() { // return sessionStorage.getItem('x-access-token') // }, getToken(){ return Vue.prototype.$axios({ url: process.env.VUE_APP_FILE_TOKEN, method: "get" }); }, /**更新富文本中url的token值 * method setNewHtml * */ setNewHtml(value,token){ // value为空,返回value || value无img标签,返回value if( this.isEmpty(value) || value.indexOf("img")== -1 ){ return value } //value存在img标签,更新url中token值 let newValue=value.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match,capture)=>{ //capture返回每个匹配的字符串(html中img标签的url) let url= capture.substr(0,capture.indexOf('?')) var newUrl= `<img src="${url}?token=${token}" />`; return newUrl; }); return newValue }, /**获取图片展示环境变量 展示url+token * method getPicUrl * */ getPicUrl(path){ return path ? `${process.env.VUE_APP_FILE_HOST}/file/frontend/${path}` : "" }, /**替换空格 * method trim * */ trim(str, char, type) { if (!str) { return str; } if (char) { if (type == 'left') { return str.replace(new RegExp('^\\' + char + '+', 'g'), ''); } else if (type == 'right') { return str.replace(new RegExp('\\' + char + '+$', 'g'), ''); } return str.replace(new RegExp('^\\' + char + '+|\\' + char + '+$', 'g'), ''); } return str.replace(/^\s+|\s+$/g, ''); }, /**下载流文件 * params res:文件数据;fileName:文件名 * method downloadFile */ downloadFile(res, fileName) { let fileBolb = res.data; let headers = res.headers; // let fileName = commonFun.trim(decodeURI(escape(headers["content-disposition"].split("=")[1])).trim("\""), "\""); // if(!!newFileName){ // fileName = newFileName; // } if (window.navigator.msSaveBlob) { try { window.navigator.msSaveBlob(fileBolb, fileName); } catch (e) { console.error(e); this.$message({ type: 'error', message: '文件下载失败' }); } } else { try { const link = document.createElement('a'); let blob = new Blob([fileBolb], { type: headers["content-type"] }); link.style.display = 'none'; link.href = URL.createObjectURL(blob); //创建下载的链接 link.setAttribute('download', fileName); //下载后文件名 document.body.appendChild(link); link.click(); //模拟在按钮上的一次鼠标单击 document.body.removeChild(link) //释放URL 对象 } catch (e) { console.error(e); this.$message({ type: 'error', message: '文件下载失败' }); } } }, deepClone(data) { let _data = JSON.stringify(data), dataClone = JSON.parse(_data); return dataClone; }, /**获取用户信息 * method getLoginUser */ getLoginUser(){ return JSON.parse(localStorage.userInfo) }, //获取验证规则,验证错误提示 validate(type){ let regArray= []; switch(type) { //手机号 case "phone": regArray= [/^1\d{10}$/,'请输入11位手机号!']; // regArray= [/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/,'请输入11位手机号!']; break; //电话 case "telephone": regArray= [/^\d{3}-\d{8}|\d{4}-\d{7}$/,'请输入正确电话号码!']; break; //密码 case "password": //6-16位字母数字特殊字符的组合 regArray= [/^(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,16}$/,'请输入6-16位字母数字特殊字符的组合']; //6-16位字母数字的组合s break; //身份证号 case "idCard": //复杂 regArray= [/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/,'请输入正确身份证号!']; //简单 // regArray= [/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,'请输入正确身份证号!'] break; // //版本号 case "version": regArray= [/^(V)([1-9]\d|[1-9])(.([1-9]\d|\d)){1}$/,'请输入V1.0或V1.10!']; break; //邮箱 case "email": regArray= [/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/,'请输入包含@和.的正确邮箱!']; break; //浮点数,小数点后两位数 case "float": regArray= [/^([1-9][0-9]*)+(.[0-9]{1,2})?$/,'请输入整数或保留两位小数的浮点数!']; break; //正整数 case "positiveInteger": // regArray= [/^[0-9]*[1-9][0-9]*$/,'请输入正整数!']; regArray= [/^([1-9][0-9]{0,7})$/,'请输入不超过8位数的正整数!']; break; //金额-整数 case "moneyInteger": regArray= [/^([0-9][0-9]{0,7})$/,'请输入不超过8位数的整数!']; break; //金额-保留小数 case "money": // regArray= [/^[0-9]*[1-9][0-9]*$/,'请输入正整数!']; regArray= [/^([0-9][0-9]{0,7}(\.\d{1,2})?)$/,'正确格式小数点前8位小数点后2位!']; break; //正数 case "positiveNum": regArray= [/^([1-9][0-9]*)(\.\d+)?$/,'请输入正数!']; break; //字母 case "letter": regArray= [/^([a-zA-Z]*_[a-zA-Z]*){1,}$/,'请输入字母与下划线的组合!']; break; //统一社会信用代码 case "creditCode": regArray= [/^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/,'请输入正确统一社会信用代码!']; break; default: regArray= "" } return regArray }, //解析字符(专用勿删) htmlStr(data,token){ let list = []; let newContent = ''; let content = data.split(";"); if(content&&content.length){ content.forEach((item) => { if ( item.indexOf("https") !== -1 && item.indexOf("=") !== -1 ) { let strs = item.split("="); if (strs) { strs[1] = token; item = strs[0] + "=" + strs[1]; } } list.push(item); }); } newContent = list.join(";"); return newContent; }, listIC(fieldName) { try { let inputChoiceDec = store.state.inputChoiceDec; if (!inputChoiceDec.hasOwnProperty(fieldName)) { return null; } let ics = inputChoiceDec[fieldName]; if (!this.isEmpty(ics)) { // let userWorkLanguage = store.getters.userWorkLanguage; let keys = Object.keys(ics); let res = {}; for (let key of keys) { let ic = ics[key]; ic.code = key; ic.value = ic.chineseValue; // if (userWorkLanguage == lang.EN) { // ic.value = ic.englishValue; // } else { // ic.value = ic.chineseValue; // } res[key] = ic; } return res; } } catch (e) { console.error(e); } return null; }, tableIC(fieldName, code) { try { let ic = store.state.inputChoiceDec[fieldName][code]; if (!this.isEmpty(ic)) { return ic.chineseValue; } } catch (e) { console.log(e); } return null; }, }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。