1 line
5.2 KiB
JavaScript
1 line
5.2 KiB
JavaScript
(()=>{var e=[],c=[];function o(e,c,t){1===c&&(e.province=e.name,e.type="province"),2===c&&("市辖区"==e.name&&(e.name=t.name),e.city=e.name,e.type="city"),3===c&&(e.county=e.name,e.type="county"),4===c&&(e.street=e.name,e.type="street"),e.children&&(c++,e.children.forEach((t=>{o(t,c,e)})))}(e=pcassCode).forEach((e=>{o(e,1,"")})),c=function(e){let c=[];return e.forEach((e=>{e.child&&e.child.forEach((e=>{e.child&&e.child.forEach((e=>{c.push(e.zipcode)}))}))})),c}(zipCode);var t={};function n(e){e=(e=e.replace(/(\d{3})-(\d{4})-(\d{4})/g,"$1$2$3")).replace(/(\d{3}) (\d{4}) (\d{4})/g,"$1$2$3");for(var c=new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“’。,、?-]"),o="",t=0;t<e.length;t++)o+=e.substr(t,1).replace(c," ");return o.replace(/[\r\n]/g,"")}window.smart=function(o){let i=o.match(/((\d{2,4}[-_-—])\d{3,8}([-_-—]?\d{3,8})?([-_-—]?\d{1,7})?)|(0?1\d{10})/g);i&&i.length>0&&(o=o.replace(i[0],"")),o=n(o);let r={},a=JSON.parse(JSON.stringify(o));return a=a.split(" "),a.forEach(((o,i)=>{if(o){1==o.length&&(o+="XX");let i=function(o){t={};let i=o;i=n(i),function(e){let c;if(c=!0,e&&/^\d{17}(\d|X)$/i.test(e))if({11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "}[e.substr(0,2)]){if(18==e.length){e=e.split("");for(var o=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],t=[1,0,"X",9,8,7,6,5,4,3,2],n=0,i=0;i<17;i++)n+=e[i]*o[i];t[n%11]!=e[17]&&(c=!1)}}else c=!1;else c=!1;return c}(i)&&(t.idCard=i,i=i.replace(i,""));let r=i.match(/(86-[1][0-9]{10}) | (86[1][0-9]{10})|([1][0-9]{10})/g);r&&(t.phone=r[0],i=i.replace(r[0],"")),c.forEach((e=>{if(-1!=i.indexOf(e)){let c=i.indexOf(e),o=i.slice(c,c+6);t.zipCode=o,i=i.replace(o,"")}}));let a="",d=[];a="";for(let c=0;c<i.length;c++)a=i.slice(0,c+2),e.forEach((e=>{-1!=e.province.indexOf(a)&&d.push({province:e.province,provinceCode:e.code,matchValue:a})}));if(d.forEach((e=>{e.index=0,d.forEach((c=>{e.province==c.province&&(c.index++,e.matchValue.length>c.matchValue.length&&(c.matchValue=e.matchValue))}))})),0!=d.length){let e=d.reduce(((e,c)=>e.index<c.index?c:e));t.province=e.province,t.provinceCode=e.provinceCode,i=i.replace(e.matchValue,"")}let l=[];a="";for(let c=0;c<i.length;c++)a=i.slice(0,c+2),e.forEach((e=>{e.code!=t.provinceCode&&t.provinceCode||("北京市"==t.province||"天津市"==t.province||"上海市"==t.province||"重庆市"==t.province?e.children.forEach((c=>{c.children.forEach((o=>{-1!=o.county.indexOf(a)&&l.push({county:o.county,countyCode:o.code,city:c.city,cityCode:c.code,matchValue:a,province:e.province,provinceCode:e.code})}))})):e.children.forEach((c=>{-1!=c.city.indexOf(a)&&l.push({city:c.city,cityCode:c.code,matchValue:a,province:e.province,provinceCode:e.code})})))}));if(l.forEach((e=>{e.index=0,l.forEach((c=>{e.city==c.city&&(c.index++,e.matchValue.length>c.matchValue.length&&(c.matchValue=e.matchValue))}))})),0!=l.length){let e=l.reduce(((e,c)=>e.index<c.index?c:e));t.city=e.city,t.cityCode=e.cityCode,t.county=e.county,t.countyCode=e.countyCode,t.province||(t.province=e.province,t.provinceCode=e.provinceCode),i=i.replace(e.matchValue,"")}let h=[];a="";for(let c=0;c<i.length;c++)a=i.slice(0,c+2),e.forEach((e=>{"北京市"==t.province||"天津市"==t.province||"上海市"==t.province||"重庆市"==t.province||e.children.forEach((c=>{c.children.forEach((o=>{-1!=o.county.indexOf(a)&&(t.province?o.code.slice(0,4)==t.cityCode&&h.push({county:o.county,countyCode:o.code,city:c.city,cityCode:c.code,matchValue:a,province:e.province,provinceCode:e.code}):t.province||t.city||h.push({county:o.county,countyCode:o.code,city:c.city,cityCode:c.code,matchValue:a,province:e.province,provinceCode:e.code}))}))}))}));if(h.forEach((e=>{e.index=0,h.forEach((c=>{e.city==c.city&&(c.index++,e.matchValue.length>c.matchValue.length&&(c.matchValue=e.matchValue))}))})),0!=h.length){let e=h.reduce(((e,c)=>e.index<c.index?c:e));t.county=e.county,t.countyCode=e.countyCode,t.province||(t.province=e.province,t.provinceCode=e.provinceCode),t.city||(t.city=e.city,t.cityCode=e.cityCode),i=i.replace(e.matchValue,"")}let p=[];a="";for(let c=0;c<i.length;c++)a=i.slice(0,c+3),e.forEach((e=>{e.name==t.province&&("北京市"==t.province||"天津市"==t.province||"上海市"==t.province||"重庆市"==t.province||e.children.forEach((e=>{e.name==t.city&&e.children.forEach((e=>{e.name==t.county&&e.children.forEach((e=>{-1!=e.street.indexOf(a)&&p.push({street:e.street,streetCode:e.code,matchValue:a})}))}))})))}));if(p.forEach((e=>{e.index=0,p.forEach((c=>{e.city==c.city&&(c.index++,e.matchValue.length>c.matchValue.length&&(c.matchValue=e.matchValue))}))})),0!=p.length){let e=p.reduce(((e,c)=>e.index<c.index?c:e));t.street=e.street,t.streetCode=e.streetCode,i=i.replace(e.matchValue,"")}return t.province&&(t.address=i),t}(o);r=Object.assign(r,i),"{}"===JSON.stringify(i)&&(r.name=o.replace("XX",""))}})),!r.phone&&i&&i.forEach((e=>{e.length>=8&&(r.phone=e)})),r}})(); |