赞
踩
// 0~999数字,支持2位小数 // /^0$|^[1-9]{1}\d{0,2}(\.\d{1,2})?$|0\.\d{1,2}$/ // 支持输入中文或英文,允许中文包含间隔符和横杠、英文包含空格 // /(^(?:[\u4e00-\u9fa5]+)[\.·\-:●]*(?:[\u4e00-\u9fa5]+)*$|^[a-zA-Z0-9]+\s?[\.·\-()a-zA-Z]*[a-zA-Z]+$)/ // 删除多余连接符> '>0>0>'.replace(/(>{2,}|^>|>$)/g, '') // 匹配路径查询参数:name=value new RegExp('(^|&)' + name + '=([^&]*)(&|$)') // 身份证号码判断性别 export function idNum2Sex(string) { if (isIDnum(string)) { return } let sexNum = string.length == 18 ? value.slice(-2, -1) : value.slice(-1) return parseInt(sexNum) % 2 === 0 ? 'woman' : 'man' } /** * 生成验证码 * @param length 长度 * @param el 显示html元素的css选择器 */ export function createCode(length = 4, el) { var code = ""; var codeLength = parseInt(length); var checkCode = document.querySelector(el); var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, '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'); for (var i = 0; i < codeLength; i++) { var charNum = Math.floor(Math.random() * 62); code += codeChars[charNum]; } if (checkCode) { checkCode.innerHTML = code; } } //手机号识别并返回 export function isPhoneNumber(num) { if (!num) { return false }; let str = num.toString(); let val = str.replace(/[^0-9]/ig, ""); if (val.length !== 11) { return false }; var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1})|)+\d{8})$/; if (!myreg.test(val)) { return false } else { return val } } //给号码加上空格 export function mobileInput(num) { if (!num) { return }; let newMobile = num.toString().replace(/[^0-9]/g, ''); let str = newMobile.toString() let L = str.length; let mobile = num; if (L <= 3) { mobile = newMobile; } else if (L > 3 && L <= 7) { mobile = str.substring(0, 3) + ' ' + str.substring(3, 7) } else if (L > 7 && L <= 11) { mobile = str.substring(0, 3) + ' ' + str.substring(3, 7) + ' ' + str.substring(7, 11); } return mobile; } //银行卡号加上空格 export function BankInput(num) { if (!num) { return }; let newBank = num.toString().replace(/[^0-9]/g, ''); let str = newBank.toString() let L = str.length; let bank = num; if (L <= 4) { bank = newBank; } else if (L > 4 && L <= 8) { bank = str.substring(0, 4) + ' ' + str.substring(4, 8) } else if (L > 8 && L <= 12) { bank = str.substring(0, 4) + ' ' + str.substring(4, 8) + ' ' + str.substring(8, 12); } else if (L > 12 && L <= 16) { bank = str.substring(0, 4) + ' ' + str.substring(4, 8) + ' ' + str.substring(8, 12) + ' ' + str.substring(12, 16); } else if (L > 16 && L <= 19) { bank = str.substring(0, 4) + ' ' + str.substring(4, 8) + ' ' + str.substring(8, 12) + ' ' + str.substring(12, 16) + ' ' + str.substring(16, 19); } return bank; } /** 验证身份证号是否正确 **/ export function isIDnum(string) { var len = string.length if (len < 15 || len > 18) { return false } var re15 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/ var re18 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|\X){1}$/g var res = re15.test(string) || re18.test(string) return res } /** * 验证是否为电子邮箱 * * @param {} source */ export function isEmail(str) { var regex = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; return str.search(regex) != -1; } /** * 校验Ip地址格式 * * @param {} ipvale */ export function isIp(ipvale) { var regex = /^([1-9]|[1-9]\d|1\d{2}|2[0-1]\d|22[0-3])(\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3}$/; var b = regex.test(ipvale); return b; } //base64位转blob export function convertBase64UrlToBlob(urlData) { let bytes = window.atob(urlData.split(',')[1]); //去掉url的头,并转换为byte //处理异常,将ascii码小于0的转换为大于0 let ab = new ArrayBuffer(bytes.length); let ia = new Uint8Array(ab); for (let i = 0; i < bytes.length; i++) { ia[i] = bytes.charCodeAt(i); } return new Blob([ab], { type: this.type }); } //输入区内容合法验证 export function checkInput(val) { val = String(val); var reg = /(script|href|on|iframe|frameset)/gi; return !reg.test(val); //合法返回true } // 非法字符替换 export function replaceNo(val) { var reg = /(script|href|on|iframe|frameset)/gi; return String(val).replace(reg, ""); //返回替换后合法的字串 } //图片格式判断 export function checkPic(str) { if (typeof str !== "string") { return; } let reg = /\.(jpg|png|jpeg|gif)$/i; return reg.test(str); } //视频格式判断 export function checkVideo(str) { if (typeof str !== "string") { return; } let reg = /\.(mp4)$/i; return reg.test(str); } /**提取图片 * @str 图文内容 * @num 图片最大数量 */ export function extractImg(str, num = 3) { if (typeof str !== "string") { return; } // 提取含img标签的src 路径 let reg = /<img[^(img)]*src=[\'\"]?([^\'\"]*)[\'\"]?/gi, arr = str.match(reg), srcList = []; if (arr && arr.length) { arr.length > num && (arr.length = num) arr.forEach((item, index) => { // 提取src 路径并替换amp转义字符 srcList.push(item.replace(/<img.*src=[\'\"]|[\'\"]|amp;/ig, "")); }) } return srcList; } /** * 头像URL过滤处理 * @param {[string]} url [description] * @return {[string]} [处理后的URL] */ export function headerImgFilter(url) { let reg = /^http/i; if (!reg.test(url)) { url = url ? config.fileRoot + '/' + url : require('@/assets/images/user_head.jpg'); } return url; } /** * 大数字转换为K/W简写 * @param Number num [description] * @return String/Number [description] */ export function numConvertText(num) { if (typeof num !== "number") { return; } if (num >= 10000) { return (num / 10000).toFixed(1) + 'w'; } /*if (num >= 1000) { return (num/1000).toFixed(1) + 'k'; }*/ return num; } /** * @param {Array} arr1 * @param {Array} arr2 * @description 得到两个数组的交集, 两个数组的元素为数值或字符串 */ export const getIntersection = (arr1, arr2) => { let len = Math.min(arr1.length, arr2.length) let i = -1 let res = [] while (++i < len) { const item = arr2[i] if (arr1.indexOf(item) > -1) res.push(item) } return res } /** * @param {Array} arr1 * @param {Array} arr2 * @description 得到两个数组的并集, 两个数组的元素为数值或字符串 */ export const getUnion = (arr1, arr2) => { return Array.from(new Set([...arr1, ...arr2])) } /** * @param {Array} target 目标数组 * @param {Array} arr 需要查询的数组 * @description 判断要查询的数组是否至少有一个元素包含在目标数组中 */ export const hasOneOf = (targetarr, arr) => { return targetarr.some(_ => arr.indexOf(_) > -1) } /** * @param {Number} timeStamp 判断时间戳格式是否是毫秒 * @returns {Boolean} */ const isMillisecond = timeStamp => { const timeStr = String(timeStamp) return timeStr.length > 10 } /** * @param {Number} timeStamp 传入的时间戳 * @param {Number} currentTime 当前时间时间戳 * @returns {Boolean} 传入的时间戳是否早于当前时间戳 */ const isEarly = (timeStamp, currentTime) => { return timeStamp < currentTime } /** * @param {Number} num 数值 * @returns {String} 处理后的字符串 * @description 如果传入的数值小于10,即位数只有1位,则在前面补充0 */ const getHandledValue = num => { return num < 10 ? '0' + num : num } /** * @param {String|Number} timeStamp 时间戳 * @returns {String} 相对时间字符串 */ export const getRelativeTime = timeStamp => { // 判断当前传入的时间戳是秒格式还是毫秒 const IS_MILLISECOND = isMillisecond(timeStamp) // 如果是毫秒格式则转为秒格式 if (IS_MILLISECOND) Math.floor(timeStamp /= 1000) // 传入的时间戳可以是数值或字符串类型,这里统一转为数值类型 timeStamp = Number(timeStamp) // 获取当前时间时间戳 const currentTime = Math.floor(Date.parse(new Date()) / 1000) // 判断传入时间戳是否早于当前时间戳 const IS_EARLY = isEarly(timeStamp, currentTime) // 获取两个时间戳差值 let diff = currentTime - timeStamp // 如果IS_EARLY为false则差值取反 if (!IS_EARLY) diff = -diff let resStr = '' const dirStr = IS_EARLY ? '前' : '后' // 少于等于59秒 if (diff <= 59) resStr = diff + '秒' + dirStr // 多于59秒,少于等于59分钟59秒 else if (diff > 59 && diff <= 3599) resStr = Math.floor(diff / 60) + '分钟' + dirStr // 多于59分钟59秒,少于等于23小时59分钟59秒 else if (diff > 3599 && diff <= 86399) resStr = Math.floor(diff / 3600) + '小时' + dirStr // 多于23小时59分钟59秒,少于等于29天59分钟59秒 else if (diff > 86399 && diff <= 2623859) resStr = Math.floor(diff / 86400) + '天' + dirStr // 多于29天59分钟59秒,少于364天23小时59分钟59秒,且传入的时间戳早于当前 else if (diff > 2623859 && diff <= 31567859 && IS_EARLY) resStr = getDate(timeStamp) else resStr = getDate(timeStamp, 'year') return resStr } /** * 发布时间格式化 * @dateString:"2018-1-6 15:25:42" */ export function publishTimeFormat(dateString) { if (typeof dateString !== "string") { return; } let pubDate = new Date(dateString.replace(/-/g, '/')), curDate = new Date(), pubMillis = +pubDate, pubYear = pubDate.getFullYear(), curMillis = +curDate, curYear = curDate.getFullYear(), difference = curMillis - pubMillis; if (difference < 4.32e+7) { //12小时内 if (difference < 3.6e+6) { //60分钟内 if (difference < 60000) { //60秒内 dateString = "刚刚"; } else { dateString = Math.floor(difference / 60000) + "分钟前"; } } else { dateString = Math.floor(difference / 3600000) + "小时前"; } } else if (pubYear == curYear) { dateString = dateString.substr(5); } return dateString; } // 日期时间字符串转为yyyy-mm-dd HH:mm:ss w格式 export function dateFormat(dateString, fmt = 'yyyy-MM-dd hh:mm:ss') { if (!dateString) { return } var date = new Date(dateString.replace(/-/g, '/')) 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(), //毫秒 'w+': '星期' + '日一二三四五六'.charAt(date.getDay()) //星期 } 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 || String(o[k]).length > 1 ? o[k] : '0' + o[k]) } } return fmt } // 简易时间格式化:2020-02-02 20:20:20 export function dateFormat(dateString) { if (!dateString) { return } var date = new Date(dateString.replace(/-/g, '/')) date.setMinutes(date.getMinutes() - date.getTimezoneOffset()) // toJSON 的时区补偿 return date.toJSON().substring(0, 19).replace(/[T]/g, ' ') } /** * @returns {String} 当前浏览器名称 */ export const getExplorer = () => { const ua = window.navigator.userAgent const isExplorer = (exp) => { return ua.indexOf(exp) > -1 } if (isExplorer('MSIE')) return 'IE' else if (isExplorer('Firefox')) return 'Firefox' else if (isExplorer('Chrome')) return 'Chrome' else if (isExplorer('Opera')) return 'Opera' else if (isExplorer('Safari')) return 'Safari' } /** * 判断一个对象是否存在key,如果传入第二个参数key,则是判断这个obj对象是否存在key这个属性 * 如果没有传入key这个参数,则判断obj对象是否有键值对 */ export const hasKey = (obj, key) => { if (key) return key in obj else { let keysArr = Object.keys(obj) return keysArr.length } } /** * @param {*} obj1 对象 * @param {*} obj2 对象 * @description 判断两个对象是否相等,这两个对象的值只能是数字或字符串 */ export const objEqual = (obj1, obj2) => { const keysArr1 = Object.keys(obj1) const keysArr2 = Object.keys(obj2) if (keysArr1.length !== keysArr2.length) return false else if (keysArr1.length === 0 && keysArr2.length === 0) return true /* eslint-disable-next-line */ else return !keysArr1.some(key => obj1[key] != obj2[key]) } /** * 合法uri * @param {String} url 路径 */ export function validateURL(url) { const reg = /^(https|http|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|xyz|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/ // const reg = /([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|xyz|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/ return reg.test(url) } /** * logo 过滤处理 * @param {*} str url */ export function transLogo(str) { if (str) return str else return require('@/assets/images/defaultLogo.jpg') } /** * 文件体积格式化 * @param {*} num 体积大小,单位Byte */ export function formatFileSize(num) { num = parseInt(num) if (num < 1e+3) { num += 'B' } else if (num < 1e+6) { num = (num / 1e+3).toFixed(2) + 'KB' } else if (num < 1e+9) { num = (num / 1e+6).toFixed(2) + 'M' } else { num = (num / 1e+9).toFixed(2) + 'G' } return num } // 创建唯一字符串 export function createUniqueString() { const timestamp = +new Date() + '' const randomNum = parseInt((1 + Math.random()) * 65536) + '' return (+(randomNum + timestamp)).toString(32) } /** * 对象合并 * @param {*} target 合并到的目标对象 * @param {*} source 被合并到的对象 */ export function objectMerge(target, source) { /* Merges two objects, giving the last one precedence */ if (typeof target !== 'object') { target = {} } if (Array.isArray(source)) { return source.slice() } Object.keys(source).forEach(property => { const sourceProperty = source[property] if (typeof sourceProperty === 'object') { target[property] = objectMerge(target[property], sourceProperty) } else { target[property] = sourceProperty } }) return target } /** * 请求路径参数转为对象 * @param {*} url */ export function query2obj(url) { url = url == null ? window.location.href : url let search = url.substring(url.indexOf('?') + 1) let obj = {} let reg = /([^?&#=]+)=([^?&#=]*)/g search?.replace(reg, (rs, $1, $2) => { const name = decodeURIComponent($1) let val = decodeURIComponent($2) val = String(val) obj[name] = val return rs }) return obj } /** * Obj转为路径query请求参数 * @param {*} obj */ export function obj2query(obj) { if (!obj) return '' return cleanArray( Object.keys(obj).map(key => { if (obj[key] === undefined) return '' return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]) }) ).join('&') } /** * 获取query请求参数中name对应的值 * @param string name */ export function getQueryValue(name, str) { try { let url = str || window.location.href // let search = url.split('?')[1] // search = search && search.split('#')[0] // if (!search) { // return '' // } let reg = new RegExp('(^|&|\\?)' + name + '=([^&#]*)(&|#|$)') let r = url.match(reg) if (r != null) { return decodeURIComponent(r[2]) } return '' } catch (error) { alert(error) } } /** * @param {Sting} input value * @returns {number} output value */ export function byteLength(str) { // returns the byte length of an utf8 string let s = str.length for (var i = str.length - 1; i >= 0; i--) { const code = str.charCodeAt(i) if (code > 0x7f && code <= 0x7ff) s++ else if (code > 0x7ff && code <= 0xffff) s += 2 if (code >= 0xDC00 && code <= 0xDFFF) i-- } return s } /** * 判断当前系统类型 */ export function judgeSystem() { if (navigator.userAgent.indexOf('MicroMessenger') > -1) { return 'weChat' } else if (!!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) { return 'ios' } else if (navigator.userAgent.indexOf('Android') > -1) { return 'android' } else if (location.protocol.toLowerCase().indexOf('file') > -1) { return 'native' } else if (!!location.href.match('192')) { return 'ip' } else if (/iphone/gi.test(navigator.userAgent) && (screen.height === 812 && screen.width === 375)) { return 'iPhoneX' } } /** * 数组转为树结构 * @param {*} data 数据源 * @param {*} id id字段 默认 'id' * @param {*} parentId 父节点字段 默认 'parentId' * @param {*} children 孩子节点字段 默认 'children' */ export function arrToTree(data, id, parentId, children) { id = id || 'id' parentId = parentId || 'parentId' children = children || 'children' let result = [] if (!Array.isArray(data)) { return result } data.forEach(item => { delete item[children]; }); let map = {}; data.forEach(item => { map[item[id]] = item; }); data.forEach(item => { let parent = map[item[parentId]]; if (parent) { (parent[children] || (parent[children] = [])).push(item); } else { result.push(item); } }); return result; } /** * 将秒转换为 分:秒 * s int 秒数 */ export function secondToTime(s) { var h; h = Math.floor(s / 60); s = s % 60; h += ''; s += ''; h = (h.length == 1) ? '0' + h : h; s = (s.length == 1) ? '0' + s : s; return h + ':' + s; } // const tool = { // transLogo // } // export default { // install(Vue) { // Vue.prototype.$Tool = tool // } // } 1 // ArrayBuffer 转为字符串,参数为 ArrayBuffer 对象 // ArrayBuffer转为字符串,或者字符串转为ArrayBuffer,有一个前提,即字符串的编码方法是确定的。假定字符串采用 UTF-16 编码(JavaScript 的内部编码方式) 2 function ab2str(buf) { 3 // 注意,如果是大型二进制数组,为了避免溢出, 4 // 必须一个一个字符地转 5 if (buf && buf.byteLength < 1024) { 6 return String.fromCharCode.apply(null, new Uint16Array(buf)); 7 } 8 9 const bufView = new Uint16Array(buf); 10 const len = bufView.length; 11 const bstr = new Array(len); 12 for (let i = 0; i < len; i++) { 13 bstr[i] = String.fromCharCode.call(null, bufView[i]); 14 } 15 return bstr.join(''); 16 } 17 18 // 字符串转为 ArrayBuffer 对象,参数为字符串 19 function str2ab(str) { 20 const buf = new ArrayBuffer(str.length * 2); // 每个字符占用2个字节 21 const bufView = new Uint16Array(buf); 22 for (let i = 0, strLen = str.length; i < strLen; i++) { 23 bufView[i] = str.charCodeAt(i); 24 } 25 return buf; 26 } // 判断是否为移动端 export function isMobile() { let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i ) return flag } // RSA加密 import JSEncrypt from 'jsencrypt/bin/jsencrypt' // 密钥对生成 http://web.chacuo.net/netrsakeypair const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' + 'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==' 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) { const encryptor = new JSEncrypt() encryptor.setPublicKey(publicKey) // 设置公钥 return encryptor.encrypt(txt) // 对数据进行加密 } // 解密 export function decrypt(txt) { const encryptor = new JSEncrypt() encryptor.setPrivateKey(privateKey) // 设置私钥 return encryptor.decrypt(txt) // 对数据进行解密 } // AES加密 import CryptoJS from 'crypto-js' let keyAES = 'qykj@20221101_te' //加密 export function encryptAES(str) { var key = CryptoJS.enc.Utf8.parse(keyAES) var srcs = CryptoJS.enc.Utf8.parse(str) var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7, }) return encrypted.toString() } //解密 export function decryptAES(str) { var key = CryptoJS.enc.Utf8.parse(keyAES) var decrypt = CryptoJS.AES.decrypt(str, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7, }) return CryptoJS.enc.Utf8.stringify(decrypt).toString() } // base64加密 export function encryptB64(str) { return window.btoa( encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { return String.fromCharCode('0x' + p1) }) ) } // base64解密 export function decryptB64(str) { const keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' function utf8_decode(utftext) { var string = '' var i = 0 var c = 0 var c1 = 0 var c2 = 0 while (i < utftext.length) { c = utftext.charCodeAt(i) if (c < 128) { string += String.fromCharCode(c) i++ } else if (c > 191 && c < 224) { c1 = utftext.charCodeAt(i + 1) string += String.fromCharCode(((c & 31) << 6) | (c1 & 63)) i += 2 } else { c1 = utftext.charCodeAt(i + 1) c2 = utftext.charCodeAt(i + 2) string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63)) i += 3 } } return string } function decode(input) { var output = '' var chr1, chr2, chr3 var enc1, enc2, enc3, enc4 var i = 0 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '') while (i < input.length) { enc1 = keyStr.indexOf(input.charAt(i++)) enc2 = keyStr.indexOf(input.charAt(i++)) enc3 = keyStr.indexOf(input.charAt(i++)) enc4 = keyStr.indexOf(input.charAt(i++)) chr1 = (enc1 << 2) | (enc2 >> 4) chr2 = ((enc2 & 15) << 4) | (enc3 >> 2) chr3 = ((enc3 & 3) << 6) | enc4 output = output + String.fromCharCode(chr1) if (enc3 != 64) { output = output + String.fromCharCode(chr2) } if (enc4 != 64) { output = output + String.fromCharCode(chr3) } } output = utf8_decode(output) return output } return decode(str) }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。