feat: 位置信息处理
This commit is contained in:
@@ -138,23 +138,49 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
formatLocation(address, name) {
|
formatLocation(address, name) {
|
||||||
if (!address) return name || '';
|
if (!address && !name) return '';
|
||||||
|
|
||||||
// Municipalities
|
const source = address || '';
|
||||||
|
|
||||||
|
// 直辖市
|
||||||
const munis = ['北京', '上海', '天津', '重庆'];
|
const munis = ['北京', '上海', '天津', '重庆'];
|
||||||
for (let m of munis) {
|
for (let m of munis) {
|
||||||
if (address.startsWith(m)) {
|
if (source.startsWith(m + '市') || source.startsWith(m)) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard: Prov + City (Simplify names)
|
// 特别行政区
|
||||||
const match = address.match(/^(.+?)(?:省|自治区)(.+?)(?:市|自治州|地区|盟)/);
|
if (source.startsWith('香港') || source.startsWith('澳门')) {
|
||||||
if (match) {
|
return source.substring(0, 2);
|
||||||
return `${match[1]}.${match[2]}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return name || address;
|
// 自治区:提取简称
|
||||||
|
const autoRegions = [
|
||||||
|
{ prefix: '内蒙古', full: '内蒙古自治区' },
|
||||||
|
{ prefix: '广西', full: '广西壮族自治区' },
|
||||||
|
{ prefix: '西藏', full: '西藏自治区' },
|
||||||
|
{ prefix: '宁夏', full: '宁夏回族自治区' },
|
||||||
|
{ prefix: '新疆', full: '新疆维吾尔自治区' }
|
||||||
|
];
|
||||||
|
for (let region of autoRegions) {
|
||||||
|
if (source.startsWith(region.prefix)) {
|
||||||
|
return region.prefix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标准省份:只提取省名
|
||||||
|
const provinceMatch = source.match(/^(.+?)省/);
|
||||||
|
if (provinceMatch) {
|
||||||
|
return provinceMatch[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果都不匹配,截取短地址
|
||||||
|
if (source.length > 6) {
|
||||||
|
return source.substring(0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
return source || name || '';
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleTopic(e) {
|
toggleTopic(e) {
|
||||||
@@ -236,11 +262,11 @@ Page({
|
|||||||
wx.hideLoading();
|
wx.hideLoading();
|
||||||
wx.showToast({ title: '发布成功', icon: 'success' });
|
wx.showToast({ title: '发布成功', icon: 'success' });
|
||||||
|
|
||||||
// Refresh previous page
|
// 直接通知上一页(社区列表页)刷新数据
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
const prevPage = pages[pages.length - 2];
|
const communityPage = pages[pages.length - 2];
|
||||||
if (prevPage && prevPage.onRefresh) {
|
if (communityPage && communityPage.onRefresh) {
|
||||||
prevPage.onRefresh();
|
communityPage.onRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user