diff --git a/project.config.json b/project.config.json index 15d90c1..839e034 100644 --- a/project.config.json +++ b/project.config.json @@ -2,7 +2,7 @@ "miniprogramRoot": "dist/", "projectname": "playBallTogether", "description": "playBallTogether", - "appid": "wx815b533167eb7b53", + "appid": "wx915ecf6c01bea4ec", "setting": { "urlCheck": true, "es6": true, diff --git a/src/publish_pages/publishBall/components/FormBasicInfo/FormBasicInfo.tsx b/src/publish_pages/publishBall/components/FormBasicInfo/FormBasicInfo.tsx index 72d2126..0f7151b 100644 --- a/src/publish_pages/publishBall/components/FormBasicInfo/FormBasicInfo.tsx +++ b/src/publish_pages/publishBall/components/FormBasicInfo/FormBasicInfo.tsx @@ -5,6 +5,7 @@ import img from '@/config/images'; import { FormFieldConfig } from '@/config/formSchema/publishBallFormSchema'; import SelectStadium from '../SelectStadium/SelectStadium' import { Stadium } from '../SelectStadium/StadiumDetail' +import { normalize_address } from '@/utils/locationUtils' import './FormBasicInfo.scss' type PlayGame = { @@ -54,7 +55,7 @@ const FormBasicInfo: React.FC = ({ onChange({...value, venue_id, location_name: name, - location: address, + location: normalize_address(address || ''), latitude, longitude, court_type, diff --git a/src/publish_pages/publishBall/components/SelectStadium/SelectStadium.tsx b/src/publish_pages/publishBall/components/SelectStadium/SelectStadium.tsx index 0f6bd0d..866de82 100644 --- a/src/publish_pages/publishBall/components/SelectStadium/SelectStadium.tsx +++ b/src/publish_pages/publishBall/components/SelectStadium/SelectStadium.tsx @@ -4,7 +4,7 @@ import Taro from '@tarojs/taro' import { Loading } from '@nutui/nutui-react-taro' import StadiumDetail, { StadiumDetailRef } from './StadiumDetail' import { CommonPopup, CustomPopup } from '../../../../components' -import { getLocation } from '@/utils/locationUtils' +import { getLocation, normalize_address } from '@/utils/locationUtils' import PublishService from '@/services/publishService' import images from '@/config/images' import './SelectStadium.scss' @@ -100,7 +100,7 @@ const SelectStadium: React.FC = ({ success: (res) => { setSelectedStadium({ name: res.name, - address: res.address, + address: normalize_address(res.address || ''), longitude: res.longitude, latitude: res.latitude }) diff --git a/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx b/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx index 9a41c8b..b070e57 100644 --- a/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx +++ b/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx @@ -7,6 +7,7 @@ import TextareaTag from '@/components/TextareaTag' import UploadCover, { type CoverImageValue } from '@/components/UploadCover' import { useKeyboardHeight } from '@/store/keyboardStore' import { useDictionaryActions } from '@/store/dictionaryStore' +import { normalize_address } from '@/utils/locationUtils' import './StadiumDetail.scss' @@ -145,7 +146,7 @@ const StadiumDetail = forwardRef(({ setFormData({ ...formData, name: res.name, - address: res.address, + address: normalize_address(res.address || ''), latitude: res.latitude, longitude: res.longitude, istance: null diff --git a/src/utils/locationUtils.ts b/src/utils/locationUtils.ts index 62be26b..70bf76a 100644 --- a/src/utils/locationUtils.ts +++ b/src/utils/locationUtils.ts @@ -14,10 +14,20 @@ export interface LocationInfo { name?: string } +/** 规范化地址:去掉类似“上海市上海市...”的重复前缀 */ +export const normalize_address = (address: string): string => { + if (!address) return '' + // 去空格(包含全角空格) + const trimmed = address.replace(/[\s\u3000]+/g, '') + // 处理 “xx市xx市...” / “xx省xx省...” 等连续重复 + // 例:上海市上海市静安区... -> 上海市静安区... + return trimmed.replace(/^(.{2,6}?[市省])\1+/, '$1') +} + // 获取当前位置 export const getCurrentLocation = (): Promise => { return new Promise((resolve, reject) => { - Taro.getLocation({ + ;(Taro as any).getLocation({ type: 'wgs84', success: (res) => { console.log('===获取地理位置', res) @@ -27,7 +37,7 @@ export const getCurrentLocation = (): Promise => { resolve({ latitude: res.latitude, longitude: res.longitude, - address + address: normalize_address(address) }) }) .catch(() => { @@ -48,12 +58,12 @@ export const getCurrentLocation = (): Promise => { // 选择地图位置 export const chooseLocation = (): Promise => { return new Promise((resolve, reject) => { - Taro.chooseLocation({ + ;(Taro as any).chooseLocation({ success: (res) => { resolve({ latitude: res.latitude, longitude: res.longitude, - address: res.address, + address: normalize_address(res.address), name: res.name }) }, @@ -66,7 +76,7 @@ export const chooseLocation = (): Promise => { export const getLocation = (): Promise => { return new Promise((resolve, reject) => { - Taro.getLocation({ + ;(Taro as any).getLocation({ success: (res) => { resolve({ latitude: res.latitude,