1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import config from '@/config'
- const mapKey = config.mapKey;
- const appName = config.appName;
- /**
- * 腾讯位置服务地图选点
- */
- const chooseLocationInit = () => {
- const key = mapKey; //使用在腾讯位置服务申请的key
- const referer = appName; //调用插件的app的名称
- wx.navigateTo({
- url: `plugin://chooseLocation/index?key=${key}&referer=${referer}`,
- });
- }
- /**
- * 腾讯位置服务城市选择器
- * @param {*} city 城市名称
- */
- const citySelectorNavigateTo = (city) => {
- const key = mapKey; // 使用在腾讯位置服务申请的key
- const referer = appName; // 调用插件的app的名称
- const hotCitys = '重庆'; // 用户自定义的的热门城市
- wx.navigateTo({
- url: `plugin://citySelector/index?key=${key}&referer=${referer}&hotCitys=${hotCitys}`,
- })
- }
- function splitAddress(address) {
- // 处理直辖市(如北京市朝阳区)
- const directCityRegex = /^(北京|天津|上海|重庆)(市)?(.+?区)/;
- const directMatch = address.match(directCityRegex);
- if (directMatch) {
- return {
- province: directMatch[1],
- city: directMatch[1]+'市',
- district: directMatch[3],
- detail: address.replace(directCityRegex, '')
- }
- }
-
- // 常规拆分逻辑
- const provinceRegex = /(.+?(省|自治区|行政区|特别行政区))/;
- const cityRegex = /(.+?(市|自治州|州|盟))/;
-
- const province = address.match(provinceRegex)?.[1] || '';
- const city = address.replace(province, '').match(cityRegex)?.[1] || '';
- const remaining = address.replace(province + city, '');
- const district = remaining.match(/(.+?( 区|县|市|旗))/)?.[1] || '';
- const detail = remaining.replace(district, '').trim();
-
- return {province, city, district, detail};
- }
- export {
- chooseLocationInit,
- citySelectorNavigateTo,
- splitAddress
- }
|