重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,380 @@
/**
* Purpose: shopApi supports index.js by holding or executing the shop api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopApi = require('../../api/shop')
/**
* Purpose: userApi loads contact information that is hidden until the customer explicitly asks for it.
* Usage: call getShopManagerContact from the contact button after login checks pass.
*/
const userApi = require('../../api/user')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
const { showRecoveryModal } = require('../../utils/recovery')
/**
* 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: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: true,
loadError: '',
shopId: '',
returnTo: '/pages/home/index',
shopInfo: null,
/**
* Purpose: managerContact stores the shop manager contact returned after a customer requests it.
* Usage: bind it to the contact card and keep it null until the API succeeds.
*/
managerContact: null,
distanceText: '',
trustProfile: null,
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 : '',
returnTo: options && options.returnTo ? decodeURIComponent(options.returnTo) : '/pages/home/index'
})
this.loadShopDetail()
},
async onPullDownRefresh() {
await this.loadShopDetail()
wx.stopPullDownRefresh()
},
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,
loadError: '门店 ID 不存在'
})
return
}
this.setData({
loading: true,
loadError: ''
})
try {
const shopInfo = await shopApi.getShopById(this.data.shopId)
const trustProfile = await shopApi.getTrustProfile(this.data.shopId).catch(() => null)
const trustImages = trustProfile && Array.isArray(trustProfile.environmentImages) ? trustProfile.environmentImages.filter(Boolean) : []
const shopImages = trustImages.length
? trustImages
: await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
const shopTheme = theme.resolveShopTheme(shopInfo)
this.setData(theme.pageThemeData(shopTheme))
if (shopTheme.backgroundImageFileId) {
try {
const backgroundImageUrl = await getSignedUrl(shopTheme.backgroundImageFileId)
if (backgroundImageUrl) {
this.setData(theme.pageThemeData(shopTheme, backgroundImageUrl))
}
} catch (error) {}
}
this.setData({
shopInfo,
trustProfile: this.normalizeTrustProfile(trustProfile),
shopImages,
distanceText: ''
})
this.loadCurrentDistance()
} catch (error) {
this.setData({
loadError: error.message || '门店详情加载失败'
})
} finally {
this.setData({
loading: false
})
}
},
/**
* Purpose: normalizeTrustProfile prepares backend trust fields for WXML display.
* Usage: call after getTrustProfile so metrics and lists have safe defaults.
*/
normalizeTrustProfile(profile) {
if (!profile) {
return null
}
const stats = profile.stats || {}
return {
...profile,
ratingText: Number(stats.averageRating || 0) > 0 ? Number(stats.averageRating).toFixed(1) : '暂无',
reviewCount: Number(stats.reviewCount || 0),
productCount: Number(stats.productCount || 0),
availabilityText: profile.availabilitySummary && profile.availabilitySummary.summaryText
? profile.availabilitySummary.summaryText
: '预约前会再次确认档期',
featuredProducts: (Array.isArray(profile.featuredProducts) ? profile.featuredProducts : []).map(item => ({
...item,
priceText: Number(item.price || 0).toFixed(2)
})),
recentReviews: (Array.isArray(profile.recentReviews) ? profile.recentReviews : []).map(item => ({
...item,
ratingText: Number(item.ratingScore || 0) > 0 ? Number(item.ratingScore).toFixed(1) : '暂无',
submittedText: item.submittedAt ? String(item.submittedAt).replace('T', ' ').slice(0, 16) : ''
}))
}
},
/**
* Purpose: handleOpenProduct navigates from trust-profile cards to product details.
* Usage: bind product cards to this method with data-id.
*/
handleOpenProduct(event) {
const productId = event.currentTarget.dataset.id
if (!productId) {
return
}
navigation.navigate('/pages/product-detail/index', { id: productId })
},
/**
* `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
}
previewImagesSafely(url, this.data.shopImages)
},
/**
* Purpose: handleContactManager retrieves and shows the current shop manager contact.
* Usage: bind it to the contact button and require login before exposing phone data.
*/
async handleContactManager() {
const shopInfo = this.data.shopInfo
if (!shopInfo || !shopInfo.id || !navigation.ensureLogin('联系店长')) {
return
}
try {
const contact = await userApi.getShopManagerContact(shopInfo.id)
this.setData({ managerContact: contact })
if (contact && contact.phoneAvailable && contact.phone) {
wx.showModal({
title: contact.contactName || '店长联系方式',
content: `${contact.roleLabel || '店长'}:${contact.phone}`,
confirmText: '拨打',
cancelText: '复制',
success: res => {
if (res.confirm) {
wx.makePhoneCall({ phoneNumber: contact.phone })
} else {
wx.setClipboardData({ data: contact.phone })
}
}
})
return
}
wx.showToast({
title: (contact && contact.platformContactText) || '暂无可用联系方式',
icon: 'none'
})
} catch (error) {
showRecoveryModal({
title: '联系方式获取失败',
message: error.message || '暂时没有拿到联系方式,请重试;也可以先复制门店名,稍后从“我的”页联系客服。',
actions: [
{ key: 'retry', text: '重试联系' },
{ key: 'profile', text: '去我的' }
]
}).then(action => {
if (action && action.key === 'retry') {
this.handleContactManager()
return
}
if (action && action.key === 'profile') {
navigation.switchTab('/pages/profile/index')
}
})
}
},
/**
* `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
}
wx.setClipboardData({
data: shopInfo.shopName
})
},
/**
* `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
}
wx.setClipboardData({
data: shopInfo.address
})
},
/**
* Purpose: handleOpenLocation supports index.js by holding or executing the handle open location page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
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
})
},
/**
* Purpose: handleOpenAmapNavigation supports index.js by holding or executing the handle open amap navigation page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
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'
})
}
})
},
/**
* Purpose: handleCopyTencentNavigation copies a browser/Tencent-compatible navigation link when provided by the backend.
* Usage: bind it to the navigation row as a fallback for users who prefer another map app.
*/
handleCopyTencentNavigation() {
const shopInfo = this.data.shopInfo
const url = shopInfo && shopInfo.navigationUrls && (shopInfo.navigationUrls.TENCENT || shopInfo.navigationUrls.BROWSER)
if (!url) {
wx.showToast({
title: '店铺暂未设置备用导航链接',
icon: 'none'
})
return
}
wx.setClipboardData({
data: url,
success: () => {
wx.showToast({
title: '导航链接已复制',
icon: 'none'
})
}
})
},
/**
* Purpose: loadCurrentDistance supports index.js by holding or executing the load current distance page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
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))
})
}
})
},
/**
* Purpose: formatDistance supports index.js by holding or executing the format distance page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
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`
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,150 @@
<navigation-bar title="{{shopInfo ? shopInfo.shopName : '门店详情'}}" showBack="{{true}}" fallbackPath="{{returnTo || '/pages/home/index'}}" color="#ffffff" background="transparent" safeAreaMode="overlay"></navigation-bar>
<view class="page-shell shop-page" style="{{themeVars}}">
<view class="shop-hero">
<image wx:if="{{shopImages.length}}" class="shop-hero-image" src="{{shopImages[0]}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="shop-hero-mask"></view>
</view>
<view wx:if="{{loadError}}" class="page-content shop-content">
<view class="page-card empty-card">
<text class="empty-title">暂时无法查看门店详情</text>
<text class="empty-desc">{{loadError}}</text>
<view class="ghost-btn" bindtap="handleBack">返回上一页</view>
</view>
</view>
<view wx:elif="{{shopInfo}}" class="page-content shop-content">
<view class="page-card shop-card">
<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 wx:if="{{trustProfile}}" class="trust-grid">
<view class="trust-card">
<text class="trust-value">{{trustProfile.ratingText}}</text>
<text class="trust-label">{{trustProfile.reviewCount}} 条评价</text>
</view>
<view class="trust-card">
<text class="trust-value">{{trustProfile.productCount}}</text>
<text class="trust-label">在售作品</text>
</view>
<view class="trust-card">
<text class="trust-value">{{trustProfile.businessStatusText || '可浏览'}}</text>
<text class="trust-label">{{trustProfile.availabilityText}}</text>
</view>
</view>
<view class="summary-strip shop-summary">
<view class="summary-metric">
<text class="summary-label">营业时间</text>
<text class="summary-value shop-summary-value">{{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}}</text>
<text class="summary-note">以到店服务时间为准</text>
</view>
<view class="summary-metric">
<text class="summary-label">环境图片</text>
<text class="summary-value shop-summary-value">{{shopImages.length ? shopImages.length : 0}} 张</text>
<text class="summary-note">支持点击放大查看</text>
</view>
</view>
<view class="detail-group">
<view class="detail-label">营业时间</view>
<view class="detail-value">{{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}}</view>
</view>
<view class="detail-group">
<view class="detail-label">门店介绍</view>
<view class="detail-value">{{shopInfo.description || '门店介绍待补充'}}</view>
</view>
<view class="copy-row">
<view class="ghost-btn" bindtap="handleCopyName">复制门店名</view>
<view class="ghost-btn" bindtap="handleCopyAddress">复制地址</view>
</view>
<view class="contact-row">
<view class="primary-btn contact-btn" bindtap="handleContactManager">联系店长</view>
<view wx:if="{{managerContact}}" class="contact-copy">
{{managerContact.contactName || '店长'}} · {{managerContact.phoneAvailable ? managerContact.phone : (managerContact.platformContactText || '暂无电话')}}
</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 class="ghost-btn map-btn" bindtap="handleCopyTencentNavigation">复制备用导航</view>
</view>
</view>
<view wx:if="{{trustProfile && trustProfile.featuredProducts.length}}" class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">可预约作品</text>
<text class="section-title">先看看本店热门款</text>
<text class="section-subtitle">{{trustProfile.availabilityText}}</text>
</view>
</view>
<view class="featured-list">
<view
wx:for="{{trustProfile.featuredProducts}}"
wx:key="id"
class="featured-card"
data-id="{{item.id}}"
bindtap="handleOpenProduct"
>
<image wx:if="{{item.imageUrl}}" class="featured-cover" src="{{item.imageUrl}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view wx:else class="featured-cover placeholder">作</view>
<view class="featured-info">
<text class="featured-title">{{item.title || '美甲作品'}}</text>
<text class="featured-price">¥{{item.priceText}}</text>
<text class="featured-hint">{{item.bookingHint || '下单前选择美甲师和时间'}}</text>
</view>
</view>
</view>
</view>
<view wx:if="{{trustProfile && trustProfile.recentReviews.length}}" class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">近期评价</text>
<text class="section-title">真实体验反馈</text>
</view>
</view>
<view class="review-list">
<view wx:for="{{trustProfile.recentReviews}}" wx:key="id" class="review-card">
<view class="review-head">
<text>{{item.productTitle || '订单评价'}}</text>
<text>{{item.ratingText}}</text>
</view>
<text class="review-content">{{item.content || '用户已完成评价'}}</text>
<text class="review-time">{{item.submittedText}}</text>
</view>
</view>
</view>
<view class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">实景展示</text>
<text class="section-title">门店环境图</text>
<text class="section-subtitle">点击图片可以放大查看,更直观地感受门店氛围。</text>
</view>
</view>
<view class="gallery-list">
<image
wx:for="{{shopImages}}"
wx:key="*this"
class="gallery-image"
src="{{item}}"
mode="aspectFill"
data-url="{{item}}"
bindtap="handlePreviewImage"
lazy-load="{{true}}"
></image>
</view>
</view>
</view>
</view>
@@ -0,0 +1,236 @@
.shop-page {
background: var(--theme-page-bg);
}
.shop-hero {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 320rpx;
background: var(--theme-gradient);
}
.shop-hero-image {
width: 100%;
height: 100%;
}
.shop-hero-mask {
position: absolute;
inset: 0;
background: linear-gradient(180deg, rgba(34, 21, 27, 0.12), rgba(34, 21, 27, 0.42));
}
.shop-content {
position: relative;
z-index: 1;
padding-top: 160rpx;
}
.shop-card {
padding: 30rpx;
}
.shop-title {
font-size: 42rpx;
font-weight: 700;
line-height: 1.4;
color: var(--text-primary);
}
.shop-address {
margin-top: 16rpx;
font-size: 26rpx;
color: var(--text-secondary);
line-height: 1.7;
}
.shop-distance {
margin-top: 8rpx;
color: #8f6e7a;
font-size: 24rpx;
line-height: 1.5;
}
.shop-summary {
margin-top: 24rpx;
}
.trust-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 14rpx;
margin-top: 24rpx;
}
.trust-card {
display: grid;
gap: 8rpx;
min-height: 112rpx;
padding: 18rpx;
border-radius: 16rpx;
background: var(--theme-primary-soft);
}
.trust-value {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 700;
}
.trust-label {
color: var(--text-secondary);
font-size: 22rpx;
line-height: 1.35;
}
.shop-summary-value {
font-size: 26rpx;
line-height: 1.6;
}
.detail-group {
margin-top: 24rpx;
}
.detail-label {
font-size: 24rpx;
color: var(--text-secondary);
}
.detail-value {
margin-top: 12rpx;
font-size: 28rpx;
color: var(--text-primary);
line-height: 1.8;
}
.copy-row {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16rpx;
margin-top: 26rpx;
}
.map-row {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 16rpx;
margin-top: 18rpx;
}
.contact-row {
display: grid;
gap: 12rpx;
margin-top: 18rpx;
}
.contact-btn {
width: 100%;
}
.contact-copy {
color: var(--text-secondary);
font-size: 24rpx;
line-height: 1.6;
}
.copy-row .ghost-btn,
.map-btn {
min-width: 0;
width: 100%;
}
.gallery-list {
display: flex;
flex-wrap: wrap;
gap: 18rpx;
}
.featured-list,
.review-list {
display: grid;
gap: 18rpx;
}
.featured-card {
display: grid;
grid-template-columns: 150rpx minmax(0, 1fr);
gap: 18rpx;
padding: 18rpx;
border-radius: 24rpx;
background: #fff;
}
.featured-cover {
width: 150rpx;
height: 150rpx;
border-radius: 20rpx;
background: var(--theme-primary-soft);
}
.featured-cover.placeholder {
display: flex;
align-items: center;
justify-content: center;
color: var(--theme-primary);
font-size: 40rpx;
font-weight: 700;
}
.featured-info {
display: grid;
align-content: center;
gap: 10rpx;
min-width: 0;
}
.featured-title {
color: var(--text-primary);
font-size: 28rpx;
font-weight: 700;
}
.featured-price {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 700;
}
.featured-hint,
.review-time {
color: var(--text-secondary);
font-size: 22rpx;
line-height: 1.5;
}
.review-card {
display: grid;
gap: 12rpx;
padding: 22rpx;
border-radius: 24rpx;
background: #fff;
}
.review-head {
display: flex;
justify-content: space-between;
gap: 16rpx;
color: var(--text-primary);
font-size: 26rpx;
font-weight: 700;
}
.review-content {
color: #5d4b55;
font-size: 25rpx;
line-height: 1.6;
}
.gallery-image {
width: calc(50% - 9rpx);
height: 240rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
}