通过微信开发者工具 商城模板 创建新小程序
This commit is contained in:
25
mini-program/utils/addressParse.js
Normal file
25
mini-program/utils/addressParse.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { areaData } from '../config/index';
|
||||
|
||||
const addressParse = (provinceName, cityName, countryName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const province = areaData.find((v) => v.label === provinceName);
|
||||
const { value: provinceCode } = province;
|
||||
const city = province.children.find((v) => v.label === cityName);
|
||||
const { value: cityCode } = city;
|
||||
const country = city.children.find((v) => v.label === countryName);
|
||||
const { value: districtCode } = country;
|
||||
resolve({
|
||||
provinceCode,
|
||||
cityCode,
|
||||
districtCode,
|
||||
});
|
||||
} catch (error) {
|
||||
reject('地址解析失败');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addressParse,
|
||||
};
|
Reference in New Issue
Block a user