功能:同步小程序流程
This commit is contained in:
@@ -1,7 +1,24 @@
|
||||
/**
|
||||
* 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 } = require('../../utils/file')
|
||||
const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file')
|
||||
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
|
||||
|
||||
/**
|
||||
@@ -15,6 +32,11 @@ Page({
|
||||
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: '',
|
||||
shopImages: []
|
||||
}),
|
||||
@@ -106,10 +128,47 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
wx.previewImage({
|
||||
current: url,
|
||||
urls: this.data.shopImages
|
||||
})
|
||||
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) {
|
||||
wx.showToast({
|
||||
title: error.message || '联系方式获取失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -150,6 +209,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
@@ -169,6 +232,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -190,6 +257,35 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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') {
|
||||
@@ -205,6 +301,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 ''
|
||||
|
||||
@@ -49,9 +49,17 @@
|
||||
<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>
|
||||
|
||||
|
||||
@@ -87,11 +87,27 @@
|
||||
|
||||
.map-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
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: #8d7a84;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.copy-row .ghost-btn,
|
||||
.map-btn {
|
||||
min-width: 0;
|
||||
|
||||
Reference in New Issue
Block a user