addressParse.js 715 B

12345678910111213141516171819202122232425
  1. import { areaData } from '../config/index';
  2. const addressParse = (provinceName, cityName, countryName) => {
  3. return new Promise((resolve, reject) => {
  4. try {
  5. const province = areaData.find((v) => v.label === provinceName);
  6. const { value: provinceCode } = province;
  7. const city = province.children.find((v) => v.label === cityName);
  8. const { value: cityCode } = city;
  9. const country = city.children.find((v) => v.label === countryName);
  10. const { value: districtCode } = country;
  11. resolve({
  12. provinceCode,
  13. cityCode,
  14. districtCode,
  15. });
  16. } catch (error) {
  17. reject('地址解析失败');
  18. }
  19. });
  20. };
  21. module.exports = {
  22. addressParse,
  23. };