//清除空键值对 //自定义判断元素类型 function toType(obj) { return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase(); } export const filter_param = (o) => { for (var key in o) { if (o[key] == null) delete o[key]; if (toType(o[key]) == "string") { o[key] = o[key].trim(); if (o[key].length == 0) { delete o[key]; } } } return o; } export const toChinesNum = (num) => { let changeNum = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']; let unit = ["", "拾", "佰", "仟", "万"]; let sUnit = ["角", "分", "厘"]; let newSNum = ""; let otNum = num; num = parseInt(num); let getWan = (temp) => { let strArr = temp.toString().split("").reverse(); let newNum = ""; for (let i = 0; i < strArr.length; i++) { newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (unit[i]))) + newNum; } return newNum; } let overWan = Math.floor(num / 10000); let noWan = num % 10000; if (noWan.toString().length < 4) { noWan = "0" + noWan; } if (otNum.toString().split('.').length > 1) { let sNum = otNum.toString().split('.')[1].split(""); for (let i = 0; i < sNum.length; i++) { newSNum += i > 0 && sNum[i] == 0 && sNum[i - 1] == 0 ? "" : changeNum[sNum[i]] + sUnit[i]; } if (otNum.toString().split('.')[0] == "0") { return '零' + (overWan ? getWan(overWan) + "万" + getWan(noWan) + '元' + newSNum : getWan(num) + '元' + newSNum); } else { return overWan ? getWan(overWan) + "万" + getWan(noWan) + '元' + newSNum : getWan(num) + '元' + newSNum; } } else { return overWan ? getWan(overWan) + "万" + getWan(noWan) + '元整' : getWan(num) + "元整"; } } export const phoneFun = function (phones) { var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/; if (!myreg.test(phones)) { console.log('手机号格式不正确') return false; } else { console.log('手机号格式正确') return true; } }