WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2023-07-31 ad01ea7d8ea42d9df787b6847c2d4272c5740c5b
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,9 +172,8 @@
        return false;
    }
    _parseAddress(content) {
    _parseAddress(chinaTree, content) {
        content = content.replace('中国', '');
        const chinaTree = ChinaLocations.getLocationTree();
        // 省份处理 ---
        const provinceTailReg = /特别行政区|自治区|省|市$/;
        for (let province of chinaTree) {
@@ -221,6 +221,5 @@
            this.wordData.street = content;
        }
    }
}