功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
+112 -1
View File
@@ -3,6 +3,10 @@ const navigation = require('../../utils/navigation')
const { resolveImageList } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
/**
* shop-detail page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: {
loading: true,
@@ -10,9 +14,14 @@ Page({
shopId: '',
returnTo: '/pages/home/index',
shopInfo: null,
distanceText: '',
shopImages: []
},
/**
* `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onLoad(options) {
this.setData({
shopId: options && options.id ? options.id : '',
@@ -27,6 +36,10 @@ Page({
},
async loadShopDetail() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.shopId) {
this.setData({
loading: false,
@@ -45,8 +58,10 @@ Page({
const shopImages = await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
this.setData({
shopInfo,
shopImages
shopImages,
distanceText: ''
})
this.loadCurrentDistance()
} catch (error) {
this.setData({
loadError: error.message || '门店详情加载失败'
@@ -58,12 +73,24 @@ Page({
}
},
/**
* `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleBack() {
navigation.goBack(this.data.returnTo || '/pages/home/index')
},
/**
* `handlePreviewImage` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handlePreviewImage(event) {
const url = event.currentTarget.dataset.url
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!url) {
return
}
@@ -74,8 +101,16 @@ Page({
})
},
/**
* `handleCopyName` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleCopyName() {
const shopInfo = this.data.shopInfo
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopInfo || !shopInfo.shopName) {
return
}
@@ -85,8 +120,16 @@ Page({
})
},
/**
* `handleCopyAddress` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleCopyAddress() {
const shopInfo = this.data.shopInfo
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopInfo || !shopInfo.address) {
return
}
@@ -94,5 +137,73 @@ Page({
wx.setClipboardData({
data: shopInfo.address
})
},
handleOpenLocation() {
const shopInfo = this.data.shopInfo
if (!shopInfo || !shopInfo.latitude || !shopInfo.longitude) {
wx.showToast({
title: '店铺暂未设置地图位置',
icon: 'none'
})
return
}
wx.openLocation({
latitude: Number(shopInfo.latitude),
longitude: Number(shopInfo.longitude),
name: shopInfo.shopName || '店铺位置',
address: shopInfo.address || '',
scale: 16
})
},
handleOpenAmapNavigation() {
const shopInfo = this.data.shopInfo
const amapUrl = shopInfo && shopInfo.navigationUrls && shopInfo.navigationUrls.AMAP
if (!amapUrl) {
wx.showToast({
title: '店铺暂未设置地图位置',
icon: 'none'
})
return
}
wx.setClipboardData({
data: amapUrl,
success: () => {
wx.showToast({
title: '高德导航链接已复制',
icon: 'none'
})
}
})
},
loadCurrentDistance() {
const shopInfo = this.data.shopInfo
if (!shopInfo || !shopInfo.latitude || !shopInfo.longitude || typeof wx.getLocation !== 'function') {
return
}
wx.getLocation({
type: 'gcj02',
success: (res) => {
this.setData({
distanceText: this.formatDistance(res.latitude, res.longitude, Number(shopInfo.latitude), Number(shopInfo.longitude))
})
}
})
},
formatDistance(currentLat, currentLng, shopLat, shopLng) {
if (![currentLat, currentLng, shopLat, shopLng].every(Number.isFinite)) {
return ''
}
const toRad = value => value * Math.PI / 180
const earthRadius = 6371000
const dLat = toRad(shopLat - currentLat)
const dLng = toRad(shopLng - currentLng)
const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(currentLat)) * Math.cos(toRad(shopLat)) * Math.sin(dLng / 2) ** 2
const meters = 2 * earthRadius * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
return meters >= 1000 ? `距你约 ${(meters / 1000).toFixed(1)} km` : `距你约 ${Math.round(meters)} m`
}
})
@@ -19,6 +19,7 @@
<view class="section-kicker">门店详情</view>
<view class="shop-title">{{shopInfo.shopName}}</view>
<view class="shop-address" bindtap="handleCopyAddress">{{shopInfo.address || '门店地址待补充'}}</view>
<view wx:if="{{distanceText}}" class="shop-distance">{{distanceText}}</view>
<view class="summary-strip shop-summary">
<view class="summary-metric">
@@ -47,6 +48,11 @@
<view class="ghost-btn" bindtap="handleCopyName">复制门店名</view>
<view class="ghost-btn" bindtap="handleCopyAddress">复制地址</view>
</view>
<view wx:if="{{shopInfo.longitude && shopInfo.latitude}}" class="map-row">
<view class="primary-btn map-btn" bindtap="handleOpenLocation">查看地图位置</view>
<view class="ghost-btn map-btn" bindtap="handleOpenAmapNavigation">复制高德导航链接</view>
</view>
</view>
<view class="section-block">
@@ -46,6 +46,13 @@
line-height: 1.7;
}
.shop-distance {
margin-top: 8rpx;
color: #8f6e7a;
font-size: 24rpx;
line-height: 1.5;
}
.shop-summary {
margin-top: 24rpx;
}
@@ -77,6 +84,17 @@
margin-top: 26rpx;
}
.map-row {
display: grid;
grid-template-columns: 1fr;
gap: 16rpx;
margin-top: 18rpx;
}
.map-btn {
width: 100%;
}
.gallery-list {
display: flex;
flex-wrap: wrap;