From ad01ea7d8ea42d9df787b6847c2d4272c5740c5b Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Mon, 31 Jul 2023 18:44:49 +0800 Subject: [PATCH] 地址联动组件,地址识别跟随升级 --- forms/chinaArea/SmartAddress.js | 41 ++++++++++++++++++++--------------------- 1 files changed, 20 insertions(+), 21 deletions(-) diff --git a/forms/chinaArea/SmartAddress.js b/forms/chinaArea/SmartAddress.js index ee453ec..4c6ce09 100644 --- a/forms/chinaArea/SmartAddress.js +++ b/forms/chinaArea/SmartAddress.js @@ -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 = $locations.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,9 +172,8 @@ return false; } - _parseAddress(content) { + _parseAddress(chinaTree, content) { content = content.replace('中国', ''); - const chinaTree = $locations.getLocationTree(); // 省份处理 --- const provinceTailReg = /特别行政区|自治区|省|市$/; for (let province of chinaTree) { @@ -221,6 +221,5 @@ this.wordData.street = content; } } - } \ No newline at end of file -- Gitblit v1.9.1