This commit is contained in:
浅念
2025-12-12 18:34:44 +08:00
parent 2c10e621aa
commit 5112803313
49 changed files with 3677 additions and 2571 deletions
+163 -6
View File
@@ -13,10 +13,41 @@
<view class="cell1">
<view>{{$t('mine.nickname')}}</view>
<view class="right select">
<input :placeholder="$t('mine.nickinput')" v-model="userinfo.nickname"></input>
<input :placeholder="$t('mine.nickinput')" v-model="userinfo.nickname" />
<uni-icons type="right" size="18"></uni-icons>
</view>
</view>
<view class="cell1">
<view>店铺名称</view>
<view class="right select">
<input placeholder="请填写名称" v-model="userinfo.shop_name" />
<uni-icons type="right" size="18"></uni-icons>
</view>
</view>
<view class="cell1">
<view>店铺电话</view>
<view class="right select">
<input placeholder="请填写店铺电话" v-model="userinfo.mobile" />
<uni-icons type="right" size="18"></uni-icons>
</view>
</view>
<view class="cell1">
<view>店铺位置</view>
<view class="right select">
<input placeholder="请选择店铺位置" v-model="userinfo.location_name" disabled="disabled" @focus="showMap = true" @click="showMap = true" />
<uni-icons type="right" size="18"></uni-icons>
</view>
</view>
<view v-show="showMap" style="height: 300px; margin: 0 20px 20px 20px;">
<map
style="width: 100%; height: 100%;"
:latitude="centerLat"
:longitude="centerLng"
:markers="markers"
scale="14"
@tap="onMapTap"
/>
</view>
</view>
<view class="foot">
<button class="btn" @click="bcFn">{{$t('button.save')}}</button>
@@ -28,6 +59,12 @@
export default {
data() {
return {
centerLat: 39.9042,
centerLng: 116.4074,
markers: [],
// 若需逆地理,请配置腾讯地图 key(可存储在此或通过 storage 注入)
qqMapKey: 'HQBBZ-SC76W-YUNRZ-34IAD-ARN6K-TZBZ4',
showMap: false,
imageStyles: {
width: 40,
height: 40,
@@ -38,8 +75,12 @@
userinfo:{
nickname:'',
avatar:'',
company:'',
phone:'',
shop_name:'',
mobile:'',
location_name:'',
latitude: null,
longitude: null
},
}
@@ -48,13 +89,124 @@
this.getinfo()
},
methods: {
getFuzzy() {
return new Promise((resolve, reject) => {
wx.getSetting({
success: (st) => {
const ok = st.authSetting['scope.userFuzzyLocation'];
const run = () => wx.getFuzzyLocation({
type: 'wgs84',
success: resolve,
fail: reject
});
if (ok) return run();
wx.authorize({
scope: 'scope.userFuzzyLocation',
success: run,
fail: () => wx.openSetting({ success: () => reject(new Error('未授权')) })
});
},
fail: reject
});
});
},
// 地图点选:更新“选点位置”marker
onMapTap(e) {
const { latitude, longitude } = e.detail || {};
if (typeof latitude !== 'number' || typeof longitude !== 'number') return;
// 用 id 2 表示“选点”
const picked = {
id: 2,
latitude,
longitude,
title: '选点位置'
};
// 只保留当前选点作为唯一标记
this.markers = [picked];
// 也可以把地图中心移动到选点
this.centerLat = latitude;
this.centerLng = longitude;
this.userinfo.latitude = latitude
this.userinfo.longitude = longitude
this.reverseGeocode(latitude, longitude)
},
getinfo(){
var that= this;
request({
url:'common/user/info',
method:'POST',
}).then(res => {
this.userinfo=res.data.data.user
this.userinfo = res.data.data.user || {}
const lat = parseFloat(this.userinfo.latitude)
const lng = parseFloat(this.userinfo.longitude)
if (!isNaN(lat) && !isNaN(lng)) {
this.centerLat = lat
this.centerLng = lng
this.markers = [{
id: 1,
latitude: lat,
longitude: lng,
title: this.userinfo.location_name || '店铺位置'
}]
} else {
this.initFuzzyLocation()
}
}).catch(() => {
this.initFuzzyLocation()
})
},
// 优先使用接口位置,没有时回退到模糊定位
initFuzzyLocation() {
try {
this.getFuzzy().then(res => {
this.centerLat = res.latitude;
this.centerLng = res.longitude;
console.log(res)
// 默认给一个“当前位置(模糊)”标记
this.markers = [{
id: 1,
latitude: res.latitude,
longitude: res.longitude,
title: '当前位置(模糊)'
}];
}).catch(err => console.error(err));
} catch (e) {
console.error(e);
}
},
// 逆地理:将经纬度转为位置文本,失败则回退为经纬度字符串
reverseGeocode(lat, lng) {
const key = this.qqMapKey || uni.getStorageSync('qqMapKey') || ''
if (!key) {
this.userinfo.location_name = `${lat.toFixed(6)}, ${lng.toFixed(6)}`
return
}
uni.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1/',
method: 'GET',
data: {
location: `${lat},${lng}`,
key
},
success: (res) => {
if (res.data && res.data.status === 0) {
const result = res.data.result || {}
const formatted = (result.formatted_addresses && result.formatted_addresses.recommend) || result.address
this.userinfo.location_name = formatted || `${lat.toFixed(6)}, ${lng.toFixed(6)}`
} else {
this.userinfo.location_name = `${lat.toFixed(6)}, ${lng.toFixed(6)}`
}
},
fail: () => {
this.userinfo.location_name = `${lat.toFixed(6)}, ${lng.toFixed(6)}`
}
})
},
uploadfn(imgUrl){
@@ -71,7 +223,7 @@
});
},
delfn(){
that.userinfo.avatar =''
this.userinfo.avatar =''
},
select(e){
const tempFilePaths = e.tempFilePaths;
@@ -87,7 +239,12 @@
method:'POST',
data:{
nickname:this.userinfo.nickname,
avatar:this.userinfo.avatar
avatar:this.userinfo.avatar,
mobile:this.userinfo.mobile,
shop_name:this.userinfo.shop_name,
location_name:this.userinfo.location_name,
latitude:this.userinfo.latitude,
longitude:this.userinfo.longitude
}
}).then(res => {
uni.showToast({