From a34d7df0906a1b02c618cacd00b954d6e973cf21 Mon Sep 17 00:00:00 2001 From: Blizzard Date: Thu, 26 Feb 2026 11:51:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/community/create/index.js | 50 +++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/pages/community/create/index.js b/pages/community/create/index.js index f17260d..e1eefa9 100644 --- a/pages/community/create/index.js +++ b/pages/community/create/index.js @@ -138,23 +138,49 @@ Page({ }, formatLocation(address, name) { - if (!address) return name || ''; + if (!address && !name) return ''; - // Municipalities + const source = address || ''; + + // 直辖市 const munis = ['北京', '上海', '天津', '重庆']; for (let m of munis) { - if (address.startsWith(m)) { + if (source.startsWith(m + '市') || source.startsWith(m)) { return m; } } - // Standard: Prov + City (Simplify names) - const match = address.match(/^(.+?)(?:省|自治区)(.+?)(?:市|自治州|地区|盟)/); - if (match) { - return `${match[1]}.${match[2]}`; + // 特别行政区 + if (source.startsWith('香港') || source.startsWith('澳门')) { + return source.substring(0, 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) { @@ -236,11 +262,11 @@ Page({ wx.hideLoading(); wx.showToast({ title: '发布成功', icon: 'success' }); - // Refresh previous page + // 直接通知上一页(社区列表页)刷新数据 const pages = getCurrentPages(); - const prevPage = pages[pages.length - 2]; - if (prevPage && prevPage.onRefresh) { - prevPage.onRefresh(); + const communityPage = pages[pages.length - 2]; + if (communityPage && communityPage.onRefresh) { + communityPage.onRefresh(); } setTimeout(() => {