From 433cf5bfd7d0bd602c3147c15720a654ea47b028 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Mon, 24 Mar 2025 18:31:32 +0800 Subject: [PATCH] Merge branch 'master' of ssh://dev.zhiheiot.com:29418/mob-components --- forms/chinaArea/SmartAddress.js | 60 +++++++++++++++++++++++++++++++----------------------------- 1 files changed, 31 insertions(+), 29 deletions(-) diff --git a/forms/chinaArea/SmartAddress.js b/forms/chinaArea/SmartAddress.js index 750a6ac..1b41fcb 100644 --- a/forms/chinaArea/SmartAddress.js +++ b/forms/chinaArea/SmartAddress.js @@ -3,7 +3,7 @@ * @author Tevin */ -import ChinaLocations from '@components/forms/chinaArea/ChinaLocations'; +import { $locations } from '@components/forms/chinaArea/ChinaLocations'; import { Tools } from '@components/common/Tools'; export class SmartAddress { @@ -18,7 +18,7 @@ } this.wordData = {}; const wordArr = this._splitWord(word); - ChinaLocations.onReady(() => { + $locations.onReady(() => { this._checkPhone(wordArr); this._checkCompany(wordArr); this._checkUser(wordArr); @@ -139,30 +139,31 @@ _checkAddress(list) { const adrLabelReg = /地址|详细地址|公司地址|联系地址|地区|所在地区/; - for (let i = 0, item; (item = list[i]); i++) { - if (!item.content) { - continue; - } - if (item.label) { - if (adrLabelReg.test(item.label)) { - this._parseAddress(item.content); - list.splice(i, 1); - break; + $locations.getLocationTree(3, chinaTree => { + for (let i = 0, item; (item = list[i]); i++) { + if (!item.content) { + continue; } - } else { - if (this._isAddress(item.content)) { - this._parseAddress(item.content); - list.splice(i, 1); - break; + if (item.label) { + if (adrLabelReg.test(item.label)) { + this._parseAddress(item.content); + list.splice(i, 1); + break; + } + } else { + if (this._isAddress(chinaTree, item.content)) { + this._parseAddress(chinaTree, item.content); + list.splice(i, 1); + break; + } } } - } + }); } - _isAddress(content) { + _isAddress(tree, content) { content = content.replace('中国', ''); - const provinceNames = ChinaLocations.getLocationTree() - .map(lv1 => lv1.label.replace('特别行政区', '').replace('省', '')); + const provinceNames = tree.map(lv1 => lv1.label.replace('特别行政区', '').replace('省', '')); for (let province of provinceNames) { if (content.indexOf(province) >= 0) { return true; @@ -171,11 +172,11 @@ return false; } - _parseAddress(content) { + _parseAddress(chinaTree, content) { content = content.replace('中国', ''); - const chinaTree = ChinaLocations.getLocationTree(); // 省份处理 --- - const provinceTailReg = /特别行政区|自治区|省|市$/; + const provinceTail = '特别行政区|壮族自治区|回族自治区|维吾尔自治区|自治区|省|市'; + const provinceTailReg = new RegExp(provinceTail + '$'); for (let province of chinaTree) { const provinceStr = province.label.replace(provinceTailReg, ''); // 省份匹配 @@ -184,10 +185,11 @@ this.wordData.province = province.label; this.wordData.provinceCode = province.value; // 移除省份 - const provinceNameReg = new RegExp('^' + provinceStr + '(特别行政区|自治区|省|市)?'); + const provinceNameReg = new RegExp('^' + provinceStr + '(' + provinceTail + ')?'); content = content.replace(provinceNameReg, ''); // 市级处理 --- - const cityTailReg = /市|区|县|自治县|自治州|地区$/; + const cityTail = '市|区|县|自治县|自治州|地区'; + const cityTailReg = new RegExp(cityTail + '$'); for (let city of province.children) { const cityStr = city.label.replace(cityTailReg, ''); // 市级匹配 @@ -196,10 +198,11 @@ this.wordData.city = city.label; this.wordData.cityCode = city.value; // 移除市级 - const cityNameReg = new RegExp('^' + cityStr + '(市|区|县|自治县|自治州|地区)?'); + const cityNameReg = new RegExp('^' + cityStr + '(' + cityTail + ')?'); content = content.replace(cityNameReg, ''); // 区级处理 --- - const distTailReg = /市|区|县|镇|乡|自治县|开发区|新区|矿区|旗|自治旗$/; + const distTail = '市|区|县|镇|乡|自治县|开发区|新区|矿区|旗|自治旗'; + const distTailReg = new RegExp(distTail + '$'); for (let dist of city.children) { const distStr = dist.label.replace(distTailReg, ''); // 区级匹配 @@ -208,7 +211,7 @@ this.wordData.dist = dist.label; this.wordData.distCode = dist.value; // 移除区级 - const distNameReg = new RegExp('^' + distStr + '(市|区|县|镇|乡|自治县|开发区|新区|矿区|旗|自治旗)?'); + const distNameReg = new RegExp('^' + distStr + '(' + distTail + ')?'); content = content.replace(distNameReg, ''); } } @@ -221,6 +224,5 @@ this.wordData.street = content; } } - } \ No newline at end of file -- Gitblit v1.9.1