From c39f16bbb61acc2e1e12a30bb1b6559d8f7623c4 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Tue, 12 Oct 2021 17:21:46 +0800 Subject: [PATCH] 升级地址模块,支持查询电话区码 --- forms/chinaArea/ChinaLocations.js | 32 +++++++++++++++++++++++++++++++- 1 files changed, 31 insertions(+), 1 deletions(-) diff --git a/forms/chinaArea/ChinaLocations.js b/forms/chinaArea/ChinaLocations.js index c5e6b98..61825ca 100644 --- a/forms/chinaArea/ChinaLocations.js +++ b/forms/chinaArea/ChinaLocations.js @@ -1,5 +1,5 @@ /** - * ChinaLocations + * ChinaLocations For Normal * @author Tevin */ @@ -18,6 +18,7 @@ const city = { label: children1[code2].name, value: code2, + area: children1[code2].area, // 电话区码 children: [], }; if (typeof children1[code2].children !== 'undefined') { @@ -121,4 +122,33 @@ } return codes; }, + // 电话区码 + getRegionsArea(regions) { + if (typeof regions === 'string') { + regions = regions.split(','); + } + if (!regions || regions.length === 0 || !regions[0]) { + return ''; + } + let area = ''; + // 省 + for (let provinceCode in ChinaLocationData) { + if (ChinaLocationData.hasOwnProperty(provinceCode)) { + if (provinceCode === regions[0]) { + // 市 + const provinceChildren = ChinaLocationData[provinceCode].children; + for (let cityCode in provinceChildren) { + if (provinceChildren.hasOwnProperty(cityCode)) { + if (cityCode === regions[1]) { + area = provinceChildren[cityCode].area; + break; + } + } + } + break; + } + } + } + return area; + } }; \ No newline at end of file -- Gitblit v1.9.1