feat:优化目录
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -41,6 +41,8 @@ package-lock.json
|
|||||||
|
|
||||||
# Third-part Files #
|
# Third-part Files #
|
||||||
**/node_modules/*
|
**/node_modules/*
|
||||||
|
dist/node_modules/*
|
||||||
|
webpack/*
|
||||||
**/bower_components/*
|
**/bower_components/*
|
||||||
**/src/vendors/*
|
**/src/vendors/*
|
||||||
|
|
||||||
|
|||||||
24
README.md
24
README.md
@@ -9,9 +9,9 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
# 智能识别收货地址Pro(支持省市区县街道/姓名/电话/邮编识别)
|
# 智能识别收货地址Pro(支持省市区县街道/姓名/电话/邮编识别)
|
||||||
### 文档地址:[doc](http://wzhichao.gitee.io/smart-doc/) | [gitee](http://wzhichao.gitee.io/smartParse) | [语雀](https://www.yuque.com/books/share/72418abc-287d-4a67-ae3c-dad10928c631?#)
|
### 文档地址:[doc](http://wzhichao.gitee.io/smart-doc/) | [备用(gitee)](http://wzhichao.gitee.io/smartParse) | [备用(语雀)](https://www.yuque.com/books/share/72418abc-287d-4a67-ae3c-dad10928c631?#)
|
||||||
|
|
||||||
### 在线预览: [示例一](https://wangzc.wang/smartParsePro/) | [示例二](http://wzhichao.gitee.io/smartparse/#/smartParse/smartParse/example1) | [备用地址1](http://wzhichao.gitee.io/smartparsepro/)
|
### 在线预览: [示例一](https://wangzc.wang/smartParsePro/) [备用地址](http://wzhichao.gitee.io/smartparsepro/)
|
||||||
|
|
||||||

|

|
||||||
## 地址数据来源(数据不对请更新此json)
|
## 地址数据来源(数据不对请更新此json)
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
### 1.api调用
|
### 1.api调用
|
||||||
>部署腾讯云,没有调用限制,需要自行部署请[点击](http://wzhichao.gitee.io/smartparse/#/smartParse/fq)
|
>部署腾讯云,没有调用限制,需要自行部署请[点击](http://wzhichao.gitee.io/smartparse/#/smartParse/fq)
|
||||||
|
|
||||||
```
|
```js
|
||||||
request url:https://wangzc.wang/smAddress
|
request url:https://wangzc.wang/smAddress
|
||||||
request methods: POST
|
request methods: POST
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ response:
|
|||||||
|
|
||||||
```
|
```
|
||||||
api使用推荐axios
|
api使用推荐axios
|
||||||
```
|
```js
|
||||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||||
|
|
||||||
axios({
|
axios({
|
||||||
@@ -133,35 +133,33 @@ axios({
|
|||||||
}).then(function (res) {});
|
}).then(function (res) {});
|
||||||
```
|
```
|
||||||
### 2.NPM
|
### 2.NPM
|
||||||
```
|
|
||||||
|
```sh
|
||||||
npm install address-smart-parse
|
npm install address-smart-parse
|
||||||
```
|
```
|
||||||
```
|
|
||||||
|
```js
|
||||||
import smart from 'address-smart-parse'
|
import smart from 'address-smart-parse'
|
||||||
|
|
||||||
// console.log(smart('xxxxxxx))
|
// console.log(smart('xxxxxxx))
|
||||||
```
|
```
|
||||||
### 3.js引入(建议下载demo查看引入js顺序以及调用方法或者在线预览)
|
### 3.script引入
|
||||||
[在codepen中在线预览](https://codepen.io/wzc570738205/pen/RwrjLbq)
|
[在codepen中在线预览](https://codepen.io/wzc570738205/pen/RwrjLbq)
|
||||||
```
|
```
|
||||||
<script src="js/pcasCode.js"></script>
|
<script src="js/pcasCode.js"></script>
|
||||||
<script src="js/zipCode.js"></script>
|
<script src="js/zipCode.js"></script>
|
||||||
<script src="js/address_parse.js"></script>
|
<script src="js/address_parse.js"></script>
|
||||||
|
|
||||||
//jsdelivr
|
//jsdelivr
|
||||||
<script src="https://cdn.jsdelivr.net/npm/address-smart-parse@1.0.0/pcasCode.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/address-smart-parse@1.0.0/pcasCode.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/address-smart-parse@1.0.0/zipCode.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/address-smart-parse@1.0.0/zipCode.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/address-smart-parse@1.0.0/address_parse.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/address-smart-parse@1.0.0/address_parse.js"></script>
|
||||||
|
|
||||||
//gitee
|
|
||||||
<script src="http://wzhichao.gitee.io/smartParsePro/js/pcasCode.js"></script>
|
|
||||||
<script src="http://wzhichao.gitee.io/smartParsePro/js/zipCode.js"></script>
|
|
||||||
<script src="http://wzhichao.gitee.io/smartParsePro/js/address_parse.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
smart("陕西省西安市雁塔区丈八沟街道高新四路高新大都荟710061 刘国良 13593464918 211381198512096810")
|
smart("陕西省西安市雁塔区丈八沟街道高新四路高新大都荟710061 刘国良 13593464918 211381198512096810")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Python调用
|
### 4.Python调用
|
||||||
```
|
```
|
||||||
import requests
|
import requests
|
||||||
URL='https://wangzc.wang/smAddress'
|
URL='https://wangzc.wang/smAddress'
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* @Author: wangzhichiao<https://github.com/wzc570738205>
|
|
||||||
* @Date: 2020-04-22 12:50:27
|
|
||||||
* @LastEditors: wangzhichiao<https://github.com/wzc570738205>
|
|
||||||
* @LastEditTime: 2020-04-22 13:32:45
|
|
||||||
*/
|
|
||||||
// pages/address/address.js
|
|
||||||
const app = getApp()
|
|
||||||
|
|
||||||
Page({
|
|
||||||
/**
|
|
||||||
* 页面的初始数据
|
|
||||||
*/
|
|
||||||
data: {
|
|
||||||
address: '陕西省西安市雁塔区丈八沟街道高新四路高新大都荟710061 刘国良 13593464918 211381198512096810',
|
|
||||||
addressObj:{}
|
|
||||||
},
|
|
||||||
onShow: function (options) {
|
|
||||||
app.getAddressData()//保险起见,手动挂载数据
|
|
||||||
},
|
|
||||||
subimt: function () {
|
|
||||||
var address = app.smart(this.data.address)
|
|
||||||
console.log(address)
|
|
||||||
this.setData({
|
|
||||||
addressObj: address
|
|
||||||
})
|
|
||||||
},
|
|
||||||
bindName: function (e) {
|
|
||||||
this.data.address = e.detail.value
|
|
||||||
this.setData({
|
|
||||||
address: this.data.address
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"usingComponents": {
|
|
||||||
"cu-custom": "/colorui/components/cu-custom"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<!--miniprogram/pages/add/add.wxml-->
|
|
||||||
<cu-custom bgColor="bg-gradual-blue">
|
|
||||||
<view slot="backText">返回</view>
|
|
||||||
<view slot="content">地址识别</view>
|
|
||||||
</cu-custom>
|
|
||||||
|
|
||||||
<form>
|
|
||||||
<textarea bindinput="bindName" value='{{address}}' placeholder="请输入地址"></textarea>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<view class="padding flex flex-direction">
|
|
||||||
<button class="cu-btn bg-blue margin-tb-sm lg" bindtap="subimt">识别</button>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<view class=" flex flex-direction" >
|
|
||||||
姓名:{{addressObj.name}}
|
|
||||||
</view>
|
|
||||||
<view class=" flex flex-direction" >
|
|
||||||
电话:{{addressObj.phone}}
|
|
||||||
</view>
|
|
||||||
<view class=" flex flex-direction" >
|
|
||||||
身份证:{{addressObj.idCard}}
|
|
||||||
</view>
|
|
||||||
<view class=" flex flex-direction" >
|
|
||||||
邮编:{{addressObj.zipCode}}
|
|
||||||
</view>
|
|
||||||
<view class=" flex flex-direction" >
|
|
||||||
省市区:{{addressObj.province}}/{{addressObj.city}}/{{addressObj.county}}/{{addressObj.street}}
|
|
||||||
</view>
|
|
||||||
<view class=" flex flex-direction" >
|
|
||||||
详细地址:{{addressObj.address}}
|
|
||||||
</view>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/* pages/address/address.wxss */
|
|
||||||
/* miniprogram/pages/add/add.wxss */
|
|
||||||
@import "../../colorui/animation.wxss";
|
|
||||||
|
|
||||||
image[class*="gif-"] {
|
|
||||||
border-radius: 6rpx;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.group-height {
|
|
||||||
min-height: 50rpx;
|
|
||||||
line-height: 50rpx !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flex-tag {
|
|
||||||
align-items: center;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
textarea{
|
|
||||||
width: 100%;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
font-size: 14px;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
@@ -1,13 +1,15 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
|
||||||
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||||
<title>地址智能识别</title>
|
<title>地址智能识别</title>
|
||||||
<link rel="icon" type="image/x-icon" href="img/smart.png" />
|
<link rel="icon" type="image/x-icon" href="img/smart.png" />
|
||||||
<link rel="stylesheet" href="css/bootstrap.min.css" />
|
<link rel="stylesheet" href="css/bootstrap.min.css" />
|
||||||
<script data-ad-client="ca-pub-9729613796142547" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
<script data-ad-client="ca-pub-9729613796142547" async
|
||||||
|
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#value .key {
|
#value .key {
|
||||||
@@ -32,21 +34,15 @@
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>
|
<h1>
|
||||||
地址智能识别
|
地址智能识别
|
||||||
<small>支持省市区街道/姓名/电话/邮编</small>
|
<small>支持省市区街道/姓名/电话/邮编</small>
|
||||||
<a
|
<a class="github-button" href="https://github.com/wzc570738205/smartParsePro" data-size="large"
|
||||||
class="github-button"
|
data-show-count="true" aria-label="Star wzc570738205/smartParsePro on GitHub">Star</a>
|
||||||
href="https://github.com/wzc570738205/smartParsePro"
|
|
||||||
data-size="large"
|
|
||||||
data-show-count="true"
|
|
||||||
aria-label="Star wzc570738205/smartParsePro on GitHub"
|
|
||||||
>Star</a
|
|
||||||
>
|
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -65,7 +61,7 @@
|
|||||||
地址:广东省珠海市香洲区盘山路28号幸福茶庄
|
地址:广东省珠海市香洲区盘山路28号幸福茶庄
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
姓名:阿克苏<br>
|
姓名:阿红<br>
|
||||||
电话:800-8585222<br>
|
电话:800-8585222<br>
|
||||||
收货地址:新疆阿克苏温宿县博孜墩柯尔克孜族乡吾斯塘博村一组306号
|
收货地址:新疆阿克苏温宿县博孜墩柯尔克孜族乡吾斯塘博村一组306号
|
||||||
</li>
|
</li>
|
||||||
@@ -77,15 +73,8 @@
|
|||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<textarea
|
<textarea class="form-control" onchange="getAddress()" onkeydown="getAddress()" cols="50" rows="5" id="textarea"
|
||||||
class="form-control"
|
placeholder="请粘贴或者输入你的地址"></textarea>
|
||||||
onchange="getAddress()"
|
|
||||||
onkeydown="getAddress()"
|
|
||||||
cols="50"
|
|
||||||
rows="5"
|
|
||||||
id="textarea"
|
|
||||||
placeholder="请粘贴或者输入你的地址"
|
|
||||||
></textarea>
|
|
||||||
<h4>省市区街道四级联动</h4>
|
<h4>省市区街道四级联动</h4>
|
||||||
<form class="form-inline">
|
<form class="form-inline">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -116,7 +105,8 @@
|
|||||||
<div id="response"></div>
|
<div id="response"></div>
|
||||||
<div id="value"></div>
|
<div id="value"></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
<script src="js/jquery.min.js"></script>
|
<script src="js/jquery.min.js"></script>
|
||||||
<script src="js/pcasCode.js"></script>
|
<script src="js/pcasCode.js"></script>
|
||||||
@@ -132,20 +122,10 @@
|
|||||||
$('#textarea').val($(this).text().trim())
|
$('#textarea').val($(this).text().trim())
|
||||||
getAddress()
|
getAddress()
|
||||||
})
|
})
|
||||||
|
|
||||||
function getAddress() {
|
function getAddress() {
|
||||||
let parse_list = smart($('#textarea').val())
|
let parse_list = smart($('#textarea').val())
|
||||||
let html = ''
|
let html = ''
|
||||||
/* for (let key in parse_list) {
|
|
||||||
if (parse_list[key]) {
|
|
||||||
html +=
|
|
||||||
`<p><span class="key">` +
|
|
||||||
key +
|
|
||||||
`</span>:<span class="value">` +
|
|
||||||
parse_list[key] +
|
|
||||||
`</span></p>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$("#value").html(html); */
|
|
||||||
|
|
||||||
axios({
|
axios({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
@@ -281,12 +261,10 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-119026906-1"></script>
|
||||||
async
|
|
||||||
src="https://www.googletagmanager.com/gtag/js?id=UA-119026906-1"
|
|
||||||
></script>
|
|
||||||
<script>
|
<script>
|
||||||
window.dataLayer = window.dataLayer || []
|
window.dataLayer = window.dataLayer || []
|
||||||
|
|
||||||
function gtag() {
|
function gtag() {
|
||||||
dataLayer.push(arguments)
|
dataLayer.push(arguments)
|
||||||
}
|
}
|
||||||
@@ -294,4 +272,3 @@
|
|||||||
|
|
||||||
gtag('config', 'UA-119026906-1')
|
gtag('config', 'UA-119026906-1')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
File diff suppressed because one or more lines are too long
484
dist/address_parse.js
vendored
484
dist/address_parse.js
vendored
File diff suppressed because one or more lines are too long
8
exportjs/pcasCode.js → dist/pcasCode.js
vendored
8
exportjs/pcasCode.js → dist/pcasCode.js
vendored
File diff suppressed because one or more lines are too long
13477
dist/zipCode.js
vendored
Normal file
13477
dist/zipCode.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,492 +0,0 @@
|
|||||||
import zipCode from './zipCode.js'
|
|
||||||
import pcassCode from './pcasCode.js'
|
|
||||||
|
|
||||||
var addressList = []; //地址列表
|
|
||||||
var zipCodeList = []; //邮编列表
|
|
||||||
/* zipCode = require("./zipCode");
|
|
||||||
pcassCode = require("./pcasCode"); */
|
|
||||||
//获取地址以及邮编json
|
|
||||||
/* const getJson = new Promise((res, rej) => {
|
|
||||||
$.getJSON("./json/pcas-code.json", data_address => {
|
|
||||||
$.getJSON("./json/zip-code.json", data_code => {
|
|
||||||
|
|
||||||
res({
|
|
||||||
'address': data_address,
|
|
||||||
'code': data_code
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
getJson.then((res) => {
|
|
||||||
addressList = res.address;
|
|
||||||
addressList.forEach(item => {
|
|
||||||
formatAddresList(item, 1, '')
|
|
||||||
})
|
|
||||||
zipCodeList = zipCodeFormat(res.code);
|
|
||||||
}) */
|
|
||||||
addressList = pcassCode;
|
|
||||||
addressList.forEach((item) => {
|
|
||||||
formatAddresList(item, 1, "");
|
|
||||||
});
|
|
||||||
zipCodeList = zipCodeFormat(zipCode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地址数据处理
|
|
||||||
* @param addressList-各级数据对象
|
|
||||||
* @param index-对应的省/市/县区/街道
|
|
||||||
* @param province-只有直辖市会处理为 北京市北京市
|
|
||||||
* @returns <array>
|
|
||||||
*/
|
|
||||||
function formatAddresList(addressList, index, province) {
|
|
||||||
if (index === 1) {
|
|
||||||
//省
|
|
||||||
addressList.province = addressList.name;
|
|
||||||
addressList.type = "province";
|
|
||||||
}
|
|
||||||
if (index === 2) {
|
|
||||||
//市
|
|
||||||
if (addressList.name == "市辖区") {
|
|
||||||
addressList.name = province.name;
|
|
||||||
}
|
|
||||||
addressList.city = addressList.name;
|
|
||||||
addressList.type = "city";
|
|
||||||
}
|
|
||||||
if (index === 3) {
|
|
||||||
//区或者县
|
|
||||||
addressList.county = addressList.name;
|
|
||||||
addressList.type = "county";
|
|
||||||
}
|
|
||||||
if (index === 4) {
|
|
||||||
//街道
|
|
||||||
addressList.street = addressList.name;
|
|
||||||
addressList.type = "street";
|
|
||||||
}
|
|
||||||
if (addressList.children) {
|
|
||||||
index++;
|
|
||||||
addressList.children.forEach((res) => {
|
|
||||||
formatAddresList(res, index, addressList);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 解析邮编
|
|
||||||
* @param
|
|
||||||
* @returns <array>
|
|
||||||
*/
|
|
||||||
function zipCodeFormat(zipCode) {
|
|
||||||
let list = [];
|
|
||||||
zipCode.forEach((el) => {
|
|
||||||
if (el.child) {
|
|
||||||
el.child.forEach((event) => {
|
|
||||||
if (event.child) {
|
|
||||||
event.child.forEach((element) => {
|
|
||||||
list.push(element.zipcode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
var smartObj = {};
|
|
||||||
/**
|
|
||||||
* 解析邮编
|
|
||||||
* @param event识别的地址
|
|
||||||
* @returns <obj>
|
|
||||||
*/
|
|
||||||
function smart(event) {
|
|
||||||
event = stripscript(event); //过滤特殊字符
|
|
||||||
let obj = {};
|
|
||||||
let copyaddress = JSON.parse(JSON.stringify(event));
|
|
||||||
copyaddress = copyaddress.split(" ");
|
|
||||||
|
|
||||||
copyaddress.forEach((res, index) => {
|
|
||||||
if (res) {
|
|
||||||
if (res.length == 1) {
|
|
||||||
res += "XX"; // 过滤掉一位的名字或者地址
|
|
||||||
}
|
|
||||||
let addressObj = smatrAddress(res);
|
|
||||||
obj = Object.assign(obj, addressObj);
|
|
||||||
if (JSON.stringify(addressObj) === "{}") {
|
|
||||||
obj.name = res.replace("XX", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
function smatrAddress(event) {
|
|
||||||
smartObj = {};
|
|
||||||
let address = event;
|
|
||||||
//address= event.replace(/\s/g, ''); //去除空格
|
|
||||||
address = stripscript(address); //过滤特殊字符
|
|
||||||
|
|
||||||
//身份证号匹配
|
|
||||||
if (IdentityCodeValid(address)) {
|
|
||||||
smartObj.idCard = address;
|
|
||||||
address = address.replace(address, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//电话匹配
|
|
||||||
let phone = address.match(
|
|
||||||
/(86-[1][0-9]{10}) | (86[1][0-9]{10})|([1][0-9]{10})/g
|
|
||||||
);
|
|
||||||
if (phone) {
|
|
||||||
smartObj.phone = phone[0];
|
|
||||||
address = address.replace(phone[0], "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//邮编匹配
|
|
||||||
zipCodeList.forEach((res) => {
|
|
||||||
if (address.indexOf(res) != -1) {
|
|
||||||
let num = address.indexOf(res);
|
|
||||||
let code = address.slice(num, num + 6);
|
|
||||||
smartObj.zipCode = code;
|
|
||||||
address = address.replace(code, "");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let matchAddress = "";
|
|
||||||
//省匹配 比如输入北京市朝阳区,会用北 北京 北京市 北京市朝 以此类推在addressList里的province中做匹配,会得到北京市 河北省 天津市等等;
|
|
||||||
let matchProvince = []; //粗略匹配上的省份
|
|
||||||
// for (let begIndex = 0; begIndex < address.length; begIndex++) {
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
// if (endIndex > begIndex) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 2);
|
|
||||||
addressList.forEach((res) => {
|
|
||||||
if (res["province"].indexOf(matchAddress) != -1) {
|
|
||||||
matchProvince.push({
|
|
||||||
province: res.province,
|
|
||||||
provinceCode: res.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
|
|
||||||
//统计筛选初略统计出的省份
|
|
||||||
matchProvince.forEach((res) => {
|
|
||||||
res.index = 0;
|
|
||||||
matchProvince.forEach((el) => {
|
|
||||||
if (res.province == el.province) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (matchProvince.length != 0) {
|
|
||||||
let province = matchProvince.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.province = province.province;
|
|
||||||
smartObj.provinceCode = province.provinceCode;
|
|
||||||
address = address.replace(province.matchValue, "");
|
|
||||||
}
|
|
||||||
//市查找
|
|
||||||
let matchCity = []; //粗略匹配上的市
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 2);
|
|
||||||
addressList.forEach((el) => {
|
|
||||||
// if (el.name == smartObj.province) {
|
|
||||||
if (el.code == smartObj.provinceCode || !smartObj.provinceCode) {
|
|
||||||
if (
|
|
||||||
smartObj.province == "北京市" ||
|
|
||||||
smartObj.province == "天津市" ||
|
|
||||||
smartObj.province == "上海市" ||
|
|
||||||
smartObj.province == "重庆市"
|
|
||||||
) {
|
|
||||||
el.children.forEach((item) => {
|
|
||||||
item.children.forEach((res) => {
|
|
||||||
if (res["county"].indexOf(matchAddress) != -1) {
|
|
||||||
matchCity.push({
|
|
||||||
county: res.county,
|
|
||||||
countyCode: res.code,
|
|
||||||
city: item.city,
|
|
||||||
cityCode: item.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
el.children.forEach((res) => {
|
|
||||||
if (res["city"].indexOf(matchAddress) != -1) {
|
|
||||||
matchCity.push({
|
|
||||||
city: res.city,
|
|
||||||
cityCode: res.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//统计筛选初略统计出的市
|
|
||||||
matchCity.forEach((res) => {
|
|
||||||
res.index = 0;
|
|
||||||
matchCity.forEach((el) => {
|
|
||||||
if (res.city == el.city) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (matchCity.length != 0) {
|
|
||||||
let city = matchCity.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.city = city.city;
|
|
||||||
smartObj.cityCode = city.cityCode;
|
|
||||||
smartObj.county = city.county;
|
|
||||||
smartObj.countyCode = city.countyCode;
|
|
||||||
if (!smartObj.province) {
|
|
||||||
smartObj.province = city.province;
|
|
||||||
smartObj.provinceCode = city.provinceCode;
|
|
||||||
}
|
|
||||||
address = address.replace(city.matchValue, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//区县查找
|
|
||||||
let matchCounty = []; //粗略匹配上的区县
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 2);
|
|
||||||
addressList.forEach((el) => {
|
|
||||||
// if (el.name == smartObj.province) {
|
|
||||||
if (
|
|
||||||
smartObj.province == "北京市" ||
|
|
||||||
smartObj.province == "天津市" ||
|
|
||||||
smartObj.province == "上海市" ||
|
|
||||||
smartObj.province == "重庆市"
|
|
||||||
) {
|
|
||||||
//nothing
|
|
||||||
} else {
|
|
||||||
el.children.forEach((item) => {
|
|
||||||
// if (item.name == smartObj.city) {
|
|
||||||
item.children.forEach((res) => {
|
|
||||||
if (res["county"].indexOf(matchAddress) != -1) {
|
|
||||||
//省/市 || 省
|
|
||||||
if (smartObj.province) {
|
|
||||||
if (res.code.slice(0, 4) == smartObj.cityCode) {
|
|
||||||
matchCounty.push({
|
|
||||||
county: res.county,
|
|
||||||
countyCode: res.code,
|
|
||||||
city: item.city,
|
|
||||||
cityCode: item.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (!smartObj.province && !smartObj.city) {
|
|
||||||
matchCounty.push({
|
|
||||||
county: res.county,
|
|
||||||
countyCode: res.code,
|
|
||||||
city: item.city,
|
|
||||||
cityCode: item.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//统计筛选初略统计出的区县
|
|
||||||
matchCounty.forEach((res) => {
|
|
||||||
res.index = 0;
|
|
||||||
matchCounty.forEach((el) => {
|
|
||||||
if (res.city == el.city) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (matchCounty.length != 0) {
|
|
||||||
let city = matchCounty.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.county = city.county;
|
|
||||||
smartObj.countyCode = city.countyCode;
|
|
||||||
if (!smartObj.province) {
|
|
||||||
smartObj.province = city.province;
|
|
||||||
smartObj.provinceCode = city.provinceCode;
|
|
||||||
}
|
|
||||||
if (!smartObj.city) {
|
|
||||||
smartObj.city = city.city;
|
|
||||||
smartObj.cityCode = city.cityCode;
|
|
||||||
}
|
|
||||||
address = address.replace(city.matchValue, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//街道查找
|
|
||||||
let matchStreet = []; //粗略匹配上的街道查
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 3);
|
|
||||||
addressList.forEach((el) => {
|
|
||||||
if (el.name == smartObj.province) {
|
|
||||||
if (
|
|
||||||
smartObj.province == "北京市" ||
|
|
||||||
smartObj.province == "天津市" ||
|
|
||||||
smartObj.province == "上海市" ||
|
|
||||||
smartObj.province == "重庆市"
|
|
||||||
) {
|
|
||||||
//nothing
|
|
||||||
} else {
|
|
||||||
el.children.forEach((element) => {
|
|
||||||
if (element.name == smartObj.city) {
|
|
||||||
element.children.forEach((item) => {
|
|
||||||
if (item.name == smartObj.county) {
|
|
||||||
item.children.forEach((res) => {
|
|
||||||
if (res["street"].indexOf(matchAddress) != -1) {
|
|
||||||
matchStreet.push({
|
|
||||||
street: res.street,
|
|
||||||
streetCode: res.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//统计筛选初略统计出的区县
|
|
||||||
matchStreet.forEach((res) => {
|
|
||||||
res.index = 0;
|
|
||||||
matchStreet.forEach((el) => {
|
|
||||||
if (res.city == el.city) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (matchStreet.length != 0) {
|
|
||||||
let city = matchStreet.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.street = city.street;
|
|
||||||
smartObj.streetCode = city.streetCode;
|
|
||||||
address = address.replace(city.matchValue, "");
|
|
||||||
}
|
|
||||||
//姓名查找
|
|
||||||
if (smartObj.province) {
|
|
||||||
smartObj.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
return smartObj;
|
|
||||||
}
|
|
||||||
////过滤特殊字符
|
|
||||||
function stripscript(s) {
|
|
||||||
s = s.replace(/(\d{3})-(\d{4})-(\d{4})/g, "$1$2$3");
|
|
||||||
s = s.replace(/(\d{3}) (\d{4}) (\d{4})/g, "$1$2$3");
|
|
||||||
var pattern = new RegExp(
|
|
||||||
"[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“’。,、?-]"
|
|
||||||
);
|
|
||||||
var rs = "";
|
|
||||||
for (var i = 0; i < s.length; i++) {
|
|
||||||
rs = rs + s.substr(i, 1).replace(pattern, " ");
|
|
||||||
}
|
|
||||||
rs = rs.replace(/[\r\n]/g, "");
|
|
||||||
return rs;
|
|
||||||
}
|
|
||||||
|
|
||||||
function IdentityCodeValid(code) {
|
|
||||||
let pass;
|
|
||||||
var city = {
|
|
||||||
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: "国外 ",
|
|
||||||
};
|
|
||||||
var tip = "";
|
|
||||||
pass = true;
|
|
||||||
|
|
||||||
if (!code || !/^\d{17}(\d|X)$/i.test(code)) {
|
|
||||||
tip = "身份证号格式错误";
|
|
||||||
pass = false;
|
|
||||||
} else if (!city[code.substr(0, 2)]) {
|
|
||||||
tip = "地址编码错误";
|
|
||||||
pass = false;
|
|
||||||
} else {
|
|
||||||
//18位身份证需要验证最后一位校验位
|
|
||||||
if (code.length == 18) {
|
|
||||||
code = code.split("");
|
|
||||||
//∑(ai×Wi)(mod 11)
|
|
||||||
//加权因子
|
|
||||||
var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
||||||
//校验位
|
|
||||||
var parity = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2];
|
|
||||||
var sum = 0;
|
|
||||||
var ai = 0;
|
|
||||||
var wi = 0;
|
|
||||||
for (var i = 0; i < 17; i++) {
|
|
||||||
ai = code[i];
|
|
||||||
wi = factor[i];
|
|
||||||
sum += ai * wi;
|
|
||||||
}
|
|
||||||
var last = parity[sum % 11];
|
|
||||||
if (parity[sum % 11] != code[17]) {
|
|
||||||
tip = "校验位错误";
|
|
||||||
pass = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pass;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default smart;
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,84 +0,0 @@
|
|||||||
<!--
|
|
||||||
* @Author: wangzhichiao<https://github.com/wzc570738205>
|
|
||||||
* @Date: 2020-05-12 15:58:29
|
|
||||||
* @LastEditors: wangzhichiao<https://github.com/wzc570738205>
|
|
||||||
* @LastEditTime: 2020-05-12 17:21:58
|
|
||||||
-->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
||||||
<title>地址智能识别</title>
|
|
||||||
<link rel="icon" type="image/x-icon" href="img/smart.png">
|
|
||||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
|
||||||
<script src="js/jquery.min.js"></script>
|
|
||||||
<script src="js/pcasCode.js"></script>
|
|
||||||
<script src="js/zipCode.js"></script>
|
|
||||||
<script src="js/address_parse.js"></script>
|
|
||||||
<script src="js/bootstrap.min.js"></script>
|
|
||||||
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
|
||||||
<style>
|
|
||||||
#value .key {
|
|
||||||
color: #ff5722;
|
|
||||||
display: inline-block;
|
|
||||||
width: 111px;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
#value .value {
|
|
||||||
color: #366500;
|
|
||||||
padding-left: 10px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<form>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="name">请复制淘宝地址</label>
|
|
||||||
<textarea class="form-control" onchange="getAddress()" cols="50" rows="7" id='textarea'
|
|
||||||
placeholder="请粘贴你的地址"></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="name">姓名</label>
|
|
||||||
<input type="text" id="name" class="form-control" id="name" placeholder="Email">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="phone">姓名</label>
|
|
||||||
<input type="text" id="phone" class="form-control" id="phone" placeholder="Email">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="phone">详细地址</label>
|
|
||||||
<input type="text" id="address" class="form-control" id="phone" placeholder="Email">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<div id="value"></div>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
<script>
|
|
||||||
function autoInput(data){
|
|
||||||
$('#name').val(data.name)
|
|
||||||
$('#phone').val(data.phone)
|
|
||||||
$('#address').val(data.address)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAddress(address) {
|
|
||||||
let parse_list = smart($('#textarea').val())
|
|
||||||
let html = '';
|
|
||||||
for (let key in parse_list) {
|
|
||||||
if (parse_list[key]) {
|
|
||||||
html += `<p><span class="key">` + key + `</span>:<span class="value">` + parse_list[key] + `</span></p>`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$('#value').html(html);
|
|
||||||
|
|
||||||
autoInput(parse_list)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
<!--
|
|
||||||
* @Author: wangzhichiao<https://github.com/wzc570738205>
|
|
||||||
* @Date: 2020-04-21 14:24:59
|
|
||||||
* @LastEditors: wangzhichiao<https://github.com/wzc570738205>
|
|
||||||
* @LastEditTime: 2020-05-22 10:24:03
|
|
||||||
-->
|
|
||||||
|
|
||||||
# 建议使用api接口,此方法暂不推荐
|
|
||||||
## demo
|
|
||||||
|
|
||||||
详见```demo```文件夹
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## 小程序引入
|
|
||||||
务必勾选不检验域名等等
|
|
||||||

|
|
||||||
|
|
||||||
将仓库中的```smartWeChat```文件夹拷贝到项目中```app.js```的同级目录
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
> smartWeChat/js/address_parse.js(自建后台)
|
|
||||||
|
|
||||||
如需要自行构建后台,json文件在demo/后台json/database_export-sw0HKSJkxA1j.json
|
|
||||||
|
|
||||||
这里需要将demo里的接口替换为后台提供的接口,接口格式返回可以参考https://wangzc.wang/addressJson/1
|
|
||||||
|
|
||||||
后台json文件···demo/后台json/database_export-sw0HKSJkxA1j.json```
|
|
||||||
|
|
||||||
> app.js
|
|
||||||
```
|
|
||||||
var address_parse = require("./smartWeChat/js/address_parse");
|
|
||||||
|
|
||||||
...
|
|
||||||
...
|
|
||||||
...
|
|
||||||
|
|
||||||
App({
|
|
||||||
....
|
|
||||||
smart: function (val){
|
|
||||||
return address_parse.method(val || '')
|
|
||||||
},
|
|
||||||
getAddressData:function(){//手动重新挂载数据
|
|
||||||
address_parse.getData()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
> 调用.js
|
|
||||||
```
|
|
||||||
const app = getApp()
|
|
||||||
//注意!!省市区文件加载时间可能略长
|
|
||||||
//需要识别调用
|
|
||||||
app.smart('新疆阿克苏温宿县博孜墩柯尔克孜族乡吾斯塘博村一组306号 150-3569-6956 马云')
|
|
||||||
|
|
||||||
//ex
|
|
||||||
//这里改为事件触发即可
|
|
||||||
onLoad: function() {
|
|
||||||
setTimeout(function(){
|
|
||||||
app.getAddressData()//保险起见,手动挂载数据
|
|
||||||
var address = app.smart('广东省珠海市香洲区盘山路28号幸福茶庄,陈景勇,13593464918')
|
|
||||||
console.log(address)
|
|
||||||
},10000)
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
### 数据源跟换
|
|
||||||
|
|
||||||
由于小程序限制文件大小不能超过2MB,所以数据以接口返回,若需要更新请加群联系作者
|
|
||||||
|
|
||||||
### 注,初次加载会调用接口请求数据,后续会从缓存中读取
|
|
||||||
### 接口地址 https://wangzc.wang/addressJson/x
|
|
||||||
@@ -1,513 +0,0 @@
|
|||||||
var addressList = []; //地址列表
|
|
||||||
var zipCodeList = []; //邮编列表
|
|
||||||
var zipCode = require("./zipCode.js");
|
|
||||||
|
|
||||||
console.log("正在加载省市区数据...");
|
|
||||||
|
|
||||||
const wx_getaddress = () => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let array = [];
|
|
||||||
let index = 0;
|
|
||||||
let length = 7;
|
|
||||||
// console.log('共计' + length + '条数据')
|
|
||||||
for (let i = 0; i < length; i++) {
|
|
||||||
if (wx.getStorageSync(i + "")) {
|
|
||||||
index++;
|
|
||||||
// console.log('第' + index + '条数据在缓存中读取完毕')
|
|
||||||
array = [...array, ...JSON.parse(wx.getStorageSync(i + ""))];
|
|
||||||
if (index == length) {
|
|
||||||
resolve(array);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setTimeout(() => {
|
|
||||||
wx.request({
|
|
||||||
url: "https://wangzc.wang/addressJson/" + i,
|
|
||||||
method: "GET",
|
|
||||||
success: function(res) {
|
|
||||||
index++;
|
|
||||||
wx.setStorage({
|
|
||||||
key: i + "",
|
|
||||||
data: JSON.stringify(res.data)
|
|
||||||
});
|
|
||||||
// console.log('第' + index + '条数据加载完毕')
|
|
||||||
array = [...array, ...res.data];
|
|
||||||
if (index == length) {
|
|
||||||
resolve(array);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 2000 * i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function getData() {
|
|
||||||
wx_getaddress().then(res => {
|
|
||||||
addressList = res;//地址赋值;这里可以加入自己写的接口进行赋值
|
|
||||||
addressList.forEach(item => {
|
|
||||||
formatAddresList(item, 1, "");
|
|
||||||
});
|
|
||||||
console.log(addressList);
|
|
||||||
zipCodeList = zipCodeFormat(zipCode.variable);
|
|
||||||
console.log("省市区数据挂载完毕!!");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getData();
|
|
||||||
/**
|
|
||||||
* 地址数据处理
|
|
||||||
* @param addressList-各级数据对象
|
|
||||||
* @param index-对应的省/市/县区/街道
|
|
||||||
* @param province-只有直辖市会处理为 北京市北京市
|
|
||||||
* @returns <array>
|
|
||||||
*/
|
|
||||||
function formatAddresList(addressList, index, province) {
|
|
||||||
if (index === 1) {
|
|
||||||
//省
|
|
||||||
addressList.province = addressList.name;
|
|
||||||
}
|
|
||||||
if (index === 2) {
|
|
||||||
//市
|
|
||||||
if (addressList.name == "市辖区") {
|
|
||||||
addressList.name = province.name;
|
|
||||||
}
|
|
||||||
addressList.city = addressList.name;
|
|
||||||
}
|
|
||||||
if (index === 3) {
|
|
||||||
//区或者县
|
|
||||||
addressList.county = addressList.name;
|
|
||||||
}
|
|
||||||
if (index === 4) {
|
|
||||||
//街道
|
|
||||||
addressList.street = addressList.name;
|
|
||||||
}
|
|
||||||
if (addressList.children) {
|
|
||||||
index++;
|
|
||||||
addressList.children.forEach(res => {
|
|
||||||
formatAddresList(res, index, addressList);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 解析邮编
|
|
||||||
* @param
|
|
||||||
* @returns <array>
|
|
||||||
*/
|
|
||||||
function zipCodeFormat(zipCode) {
|
|
||||||
let list = [];
|
|
||||||
zipCode.forEach(el => {
|
|
||||||
if (el.child) {
|
|
||||||
el.child.forEach(event => {
|
|
||||||
if (event.child) {
|
|
||||||
event.child.forEach(element => {
|
|
||||||
list.push(element.zipcode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
var smartObj = {};
|
|
||||||
/**
|
|
||||||
* 解析邮编
|
|
||||||
* @param event识别的地址
|
|
||||||
* @returns <obj>
|
|
||||||
*/
|
|
||||||
function smart(event) {
|
|
||||||
event = stripscript(event); //过滤特殊字符
|
|
||||||
let obj = {};
|
|
||||||
let copyaddress = JSON.parse(JSON.stringify(event));
|
|
||||||
copyaddress = copyaddress.split(" ");
|
|
||||||
|
|
||||||
copyaddress.forEach((res, index) => {
|
|
||||||
if (res) {
|
|
||||||
if (res.length == 1) {
|
|
||||||
res += "XX"; // 过滤掉一位的名字或者地址
|
|
||||||
}
|
|
||||||
let addressObj = smatrAddress(res);
|
|
||||||
obj = Object.assign(obj, addressObj);
|
|
||||||
if (JSON.stringify(addressObj) === "{}") {
|
|
||||||
obj.name = res.replace("XX", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
function smatrAddress(event) {
|
|
||||||
smartObj = {};
|
|
||||||
let address = event;
|
|
||||||
//address= event.replace(/\s/g, ''); //去除空格
|
|
||||||
address = stripscript(address); //过滤特殊字符
|
|
||||||
|
|
||||||
//身份证号匹配
|
|
||||||
if (IdentityCodeValid(address)) {
|
|
||||||
smartObj.idCard = address;
|
|
||||||
address = address.replace(address, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//电话匹配
|
|
||||||
let phone = address.match(
|
|
||||||
/(86-[1][0-9]{10}) | (86[1][0-9]{10})|([1][0-9]{10})/g
|
|
||||||
);
|
|
||||||
if (phone) {
|
|
||||||
smartObj.phone = phone[0];
|
|
||||||
address = address.replace(phone[0], "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//邮编匹配
|
|
||||||
zipCodeList.forEach(res => {
|
|
||||||
if (address.indexOf(res) != -1) {
|
|
||||||
let num = address.indexOf(res);
|
|
||||||
let code = address.slice(num, num + 6);
|
|
||||||
smartObj.zipCode = code;
|
|
||||||
address = address.replace(code, "");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let matchAddress = "";
|
|
||||||
//省匹配 比如输入北京市朝阳区,会用北 北京 北京市 北京市朝 以此类推在addressList里的province中做匹配,会得到北京市 河北省 天津市等等;
|
|
||||||
let matchProvince = []; //粗略匹配上的省份
|
|
||||||
// for (let begIndex = 0; begIndex < address.length; begIndex++) {
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
// if (endIndex > begIndex) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 2);
|
|
||||||
addressList.forEach(res => {
|
|
||||||
if (res["province"].indexOf(matchAddress) != -1) {
|
|
||||||
matchProvince.push({
|
|
||||||
province: res.province,
|
|
||||||
provinceCode: res.code,
|
|
||||||
matchValue: matchAddress
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
|
|
||||||
//统计筛选初略统计出的省份
|
|
||||||
matchProvince.forEach(res => {
|
|
||||||
res.index = 0;
|
|
||||||
matchProvince.forEach(el => {
|
|
||||||
if (res.province == el.province) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (matchProvince.length != 0) {
|
|
||||||
let province = matchProvince.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.province = province.province;
|
|
||||||
smartObj.provinceCode = province.provinceCode;
|
|
||||||
address = address.replace(province.matchValue, "");
|
|
||||||
}
|
|
||||||
//市查找
|
|
||||||
let matchCity = []; //粗略匹配上的市
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 2);
|
|
||||||
addressList.forEach(el => {
|
|
||||||
// if (el.name == smartObj.province) {
|
|
||||||
if (el.code == smartObj.provinceCode || !smartObj.provinceCode) {
|
|
||||||
if (
|
|
||||||
smartObj.province == "北京市" ||
|
|
||||||
smartObj.province == "天津市" ||
|
|
||||||
smartObj.province == "上海市" ||
|
|
||||||
smartObj.province == "重庆市"
|
|
||||||
) {
|
|
||||||
el.children.forEach(item => {
|
|
||||||
item.children.forEach(res => {
|
|
||||||
if (res["county"].indexOf(matchAddress) != -1) {
|
|
||||||
matchCity.push({
|
|
||||||
county: res.county,
|
|
||||||
countyCode: res.code,
|
|
||||||
city: item.city,
|
|
||||||
cityCode: item.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
el.children.forEach(res => {
|
|
||||||
if (res["city"].indexOf(matchAddress) != -1) {
|
|
||||||
matchCity.push({
|
|
||||||
city: res.city,
|
|
||||||
cityCode: res.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//统计筛选初略统计出的市
|
|
||||||
matchCity.forEach(res => {
|
|
||||||
res.index = 0;
|
|
||||||
matchCity.forEach(el => {
|
|
||||||
if (res.city == el.city) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (matchCity.length != 0) {
|
|
||||||
let city = matchCity.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.city = city.city;
|
|
||||||
smartObj.cityCode = city.cityCode;
|
|
||||||
smartObj.county = city.county;
|
|
||||||
smartObj.countyCode = city.countyCode;
|
|
||||||
if (!smartObj.province) {
|
|
||||||
smartObj.province = city.province;
|
|
||||||
smartObj.provinceCode = city.provinceCode;
|
|
||||||
}
|
|
||||||
address = address.replace(city.matchValue, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//区县查找
|
|
||||||
let matchCounty = []; //粗略匹配上的区县
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 2);
|
|
||||||
addressList.forEach(el => {
|
|
||||||
// if (el.name == smartObj.province) {
|
|
||||||
if (
|
|
||||||
smartObj.province == "北京市" ||
|
|
||||||
smartObj.province == "天津市" ||
|
|
||||||
smartObj.province == "上海市" ||
|
|
||||||
smartObj.province == "重庆市"
|
|
||||||
) {
|
|
||||||
//nothing
|
|
||||||
} else {
|
|
||||||
el.children.forEach(item => {
|
|
||||||
// if (item.name == smartObj.city) {
|
|
||||||
item.children.forEach(res => {
|
|
||||||
if (res["county"].indexOf(matchAddress) != -1) {
|
|
||||||
//省/市 || 省
|
|
||||||
if (smartObj.province) {
|
|
||||||
if (res.code.slice(0, 2) == smartObj.provinceCode) {
|
|
||||||
matchCounty.push({
|
|
||||||
county: res.county,
|
|
||||||
countyCode: res.code,
|
|
||||||
city: item.city,
|
|
||||||
cityCode: item.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (!smartObj.province && !smartObj.city) {
|
|
||||||
matchCounty.push({
|
|
||||||
county: res.county,
|
|
||||||
countyCode: res.code,
|
|
||||||
city: item.city,
|
|
||||||
cityCode: item.code,
|
|
||||||
matchValue: matchAddress,
|
|
||||||
province: el.province,
|
|
||||||
provinceCode: el.code
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//统计筛选初略统计出的区县
|
|
||||||
matchCounty.forEach(res => {
|
|
||||||
res.index = 0;
|
|
||||||
matchCounty.forEach(el => {
|
|
||||||
if (res.city == el.city) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (matchCounty.length != 0) {
|
|
||||||
let city = matchCounty.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.county = city.county;
|
|
||||||
smartObj.countyCode = city.countyCode;
|
|
||||||
if (!smartObj.province) {
|
|
||||||
smartObj.province = city.province;
|
|
||||||
smartObj.provinceCode = city.provinceCode;
|
|
||||||
}
|
|
||||||
if (!smartObj.city) {
|
|
||||||
smartObj.city = city.city;
|
|
||||||
smartObj.cityCode = city.cityCode;
|
|
||||||
}
|
|
||||||
address = address.replace(city.matchValue, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//街道查找
|
|
||||||
let matchStreet = []; //粗略匹配上的街道查
|
|
||||||
matchAddress = "";
|
|
||||||
for (let endIndex = 0; endIndex < address.length; endIndex++) {
|
|
||||||
matchAddress = address.slice(0, endIndex + 3);
|
|
||||||
addressList.forEach(el => {
|
|
||||||
if (el.name == smartObj.province) {
|
|
||||||
if (
|
|
||||||
smartObj.province == "北京市" ||
|
|
||||||
smartObj.province == "天津市" ||
|
|
||||||
smartObj.province == "上海市" ||
|
|
||||||
smartObj.province == "重庆市"
|
|
||||||
) {
|
|
||||||
//nothing
|
|
||||||
} else {
|
|
||||||
el.children.forEach(element => {
|
|
||||||
if (element.name == smartObj.city) {
|
|
||||||
element.children.forEach(item => {
|
|
||||||
if (item.name == smartObj.county) {
|
|
||||||
item.children.forEach(res => {
|
|
||||||
if (res["street"].indexOf(matchAddress) != -1) {
|
|
||||||
matchStreet.push({
|
|
||||||
street: res.street,
|
|
||||||
streetCode: res.code,
|
|
||||||
matchValue: matchAddress
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//统计筛选初略统计出的区县
|
|
||||||
matchStreet.forEach(res => {
|
|
||||||
res.index = 0;
|
|
||||||
matchStreet.forEach(el => {
|
|
||||||
if (res.city == el.city) {
|
|
||||||
el.index++;
|
|
||||||
if (res.matchValue.length > el.matchValue.length) {
|
|
||||||
el.matchValue = res.matchValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (matchStreet.length != 0) {
|
|
||||||
let city = matchStreet.reduce((p, v) => (p.index < v.index ? v : p));
|
|
||||||
smartObj.street = city.street;
|
|
||||||
smartObj.streetCode = city.streetCode;
|
|
||||||
address = address.replace(city.matchValue, "");
|
|
||||||
}
|
|
||||||
//姓名查找
|
|
||||||
if (smartObj.province) {
|
|
||||||
smartObj.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
return smartObj;
|
|
||||||
}
|
|
||||||
////过滤特殊字符
|
|
||||||
function stripscript(s) {
|
|
||||||
s = s.replace(/(\d{3})-(\d{4})-(\d{4})/g, "$1$2$3");
|
|
||||||
s = s.replace(/(\d{3}) (\d{4}) (\d{4})/g, "$1$2$3");
|
|
||||||
var pattern = new RegExp(
|
|
||||||
"[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“’。,、?-]"
|
|
||||||
);
|
|
||||||
var rs = "";
|
|
||||||
for (var i = 0; i < s.length; i++) {
|
|
||||||
rs = rs + s.substr(i, 1).replace(pattern, " ");
|
|
||||||
}
|
|
||||||
rs = rs.replace(/[\r\n]/g, "");
|
|
||||||
return rs;
|
|
||||||
}
|
|
||||||
|
|
||||||
function IdentityCodeValid(code) {
|
|
||||||
let pass;
|
|
||||||
var city = {
|
|
||||||
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: "国外 "
|
|
||||||
};
|
|
||||||
var tip = "";
|
|
||||||
pass = true;
|
|
||||||
|
|
||||||
if (!code || !/^\d{17}(\d|X)$/i.test(code)) {
|
|
||||||
tip = "身份证号格式错误";
|
|
||||||
pass = false;
|
|
||||||
} else if (!city[code.substr(0, 2)]) {
|
|
||||||
tip = "地址编码错误";
|
|
||||||
pass = false;
|
|
||||||
} else {
|
|
||||||
//18位身份证需要验证最后一位校验位
|
|
||||||
if (code.length == 18) {
|
|
||||||
code = code.split("");
|
|
||||||
//∑(ai×Wi)(mod 11)
|
|
||||||
//加权因子
|
|
||||||
var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
||||||
//校验位
|
|
||||||
var parity = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2];
|
|
||||||
var sum = 0;
|
|
||||||
var ai = 0;
|
|
||||||
var wi = 0;
|
|
||||||
for (var i = 0; i < 17; i++) {
|
|
||||||
ai = code[i];
|
|
||||||
wi = factor[i];
|
|
||||||
sum += ai * wi;
|
|
||||||
}
|
|
||||||
var last = parity[sum % 11];
|
|
||||||
if (parity[sum % 11] != code[17]) {
|
|
||||||
tip = "校验位错误";
|
|
||||||
pass = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pass;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
method: smart,
|
|
||||||
getData: getData
|
|
||||||
};
|
|
||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user