自动发布开发环境 Nacos 配置 / publish (push) Successful in 25s
- 手机号/账号全场景一律脱敏:SensitiveFieldPolicy 删除完整值分支与 ADMIN_EDIT,SELF_PROFILE 同样脱敏;convertToVO 全调用点统一脱敏 - 联系信息接口不再返回号码:toContact 置空 phone 并给出 phoneAvailable,补齐 ensureUserCanSeeShop 真实可见范围校验 - 新增 POST /contact-info/dial,按 scene(SHOP_MANAGER/ORDER_ARTIST/PRODUCT_ARTIST/PLATFORM) 一次一取;DialTargetProvider 抽象直连/隐私号,未配置隐私号返回 9001 且不回退真实号;/contact-info/** 按用户限流并记录审计 - 验证码与换绑手机号改为服务端按当前登录用户取号,客户端 phone/oldPhone 参数兼容忽略;前端与小程序同步去掉回传 - 消息发布人昵称兜底改为脱敏账号,避免 account 明文写入 publisher_name - 新增 V5 账号加密与账号哈希、V6 协议文本改为全场景脱敏与单次拨号取号
370 lines
13 KiB
JavaScript
370 lines
13 KiB
JavaScript
/**
|
|
* 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 点击后才单次取号并拨号,页面不再保存或展示号码。
|
|
* Usage: 绑定到联系按钮,要求登录后由服务端按场景鉴权。
|
|
*/
|
|
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) {
|
|
const dial = await userApi.dialContact('SHOP_MANAGER', shopInfo.id)
|
|
wx.makePhoneCall({ phoneNumber: dial.dialNumber })
|
|
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`
|
|
}
|
|
})
|