diff --git a/pages/aroundDetail/index.vue b/pages/aroundDetail/index.vue index dc8d5d4..5c41b9d 100644 --- a/pages/aroundDetail/index.vue +++ b/pages/aroundDetail/index.vue @@ -1,20 +1,134 @@ @@ -22,90 +136,548 @@ import { get, post } from '@/utils/request'; import { IMAGE_BASE_URL, BASE_URL } from '@/utils/config'; import { formatTime, formatRelativeTime } from '@/utils/timeFormat'; + export default { data() { return { - formatTime, - IMAGE_BASE_URL, - Id:null, - detailInfo: {}, - local:null, + formatTime, + IMAGE_BASE_URL, + Id: null, + defaultCover: '/static/images/default-store-cover.png', + detailInfo: { + storeName: '', + storeCover: '', + storeAddress: '', + openAt: '', + content: '', + labels: [], + remark: '', + detailImages: [], + id: '', + createdAt: '', + updatedAt: '', + deletedAt: 0, + createdId: '', + deletedId: '', + typeId: '', + longitude: '', + latitude: '', + price: 0, + sequence: 0, + link: '', + status: 1 + }, + local: null, + showLocationModal: false, + locationModalContent: '我们需要获取您的位置信息,以便提供更精准的服务', + userLocation: null, + isRequestingLocation: false + } + }, + computed: { + statusText() { + const statusMap = { + 1: '营业中', + 2: '已关闭', + 3: '即将开业', + 0: '未知状态' + }; + return statusMap[this.detailInfo.status] || `状态: ${this.detailInfo.status}`; + }, + statusClass() { + const statusMap = { + 1: 'status-open', + 2: 'status-closed', + 3: 'status-soon' + }; + return statusMap[this.detailInfo.status] || 'status-default'; + }, + statusIcon() { + const iconMap = { + 1: 'home-fill', + 2: 'close-circle-fill', + 3: 'clock-fill' + }; + return iconMap[this.detailInfo.status] || 'question-circle-fill'; } }, onLoad(options) { - if (options && options.Id && options.local) { - this.Id = options.Id; - this.local = options.local; - } + if (options?.Id) { + this.Id = options.Id; + this.local = options.local || null; + this.getAroundDetail(); + } + + // 启用分享功能 + wx.showShareMenu({ + withShareTicket: true, + menus: ['shareAppMessage', 'shareTimeline'] + }); }, - mounted(){ - this.getAroundDetail(); + mounted() { + this.getAroundDetail(); }, methods: { - async getAroundDetail(){ - try { - const res = await get(`/api/v1/apps/surrounding/${this.Id}`); - if (!res || !res.success) { - throw new Error('获取详情失败'); - } - res.data.storeCover = IMAGE_BASE_URL + res.data.storeCover; - this.detailInfo = {...res.data}; - } catch (err) { - console.error('获取详情失败:', err); - } - - } + formatDistance(distance) { + if (!distance) return '未知距离'; + if (distance < 1000) { + return `${distance}米`; + } else { + return `${(distance / 1000).toFixed(1)}公里`; + } + }, + + async getAroundDetail() { + try { + const res = await get(`/api/v1/apps/surrounding/${this.Id}`); + if (res?.success) { + this.detailInfo = { + ...this.detailInfo, + ...res.data, + storeCover: res.data.storeCover?.startsWith('http') + ? res.data.storeCover + : IMAGE_BASE_URL + res.data.storeCover + }; + } + } catch (error) { + console.error('获取详情失败:', error); + uni.showToast({ title: '获取详情失败', icon: 'none' }); + } + }, + + // 处理分享按钮点击 + async handleShareClick() { + this.isRequestingLocation = true; + try { + await this.checkLocationPermission(); + } catch (error) { + console.error('位置授权异常:', error); + } finally { + this.isRequestingLocation = false; + } + }, + + // 检查位置权限 + async checkLocationPermission() { + const status = await this.getPermissionStatus(); + if (status === 'granted') { + await this.getUserLocation(); + return; + } + + if (status === 'none') { + // 首次请求授权 + this.requestLocationPermission(); + } else { + // 已拒绝过,显示提示 + this.showLocationModal = true; + } + }, + + // 获取权限状态 + getPermissionStatus() { + return new Promise((resolve) => { + uni.getSetting({ + success: (res) => { + if (res.authSetting['scope.userLocation'] === undefined) { + resolve('none'); + } else if (res.authSetting['scope.userLocation']) { + resolve('granted'); + } else { + resolve('denied'); + } + }, + fail: () => resolve('none') + }); + }); + }, + + // 请求位置授权 + requestLocationPermission() { + uni.authorize({ + scope: 'scope.userLocation', + success: () => this.getUserLocation(), + fail: (err) => { + console.error('授权失败:', err); + this.showLocationModal = true; + } + }); + }, + + // 获取用户位置 + getUserLocation() { + return new Promise((resolve, reject) => { + uni.getLocation({ + type: 'wgs84', + success: (res) => { + this.userLocation = { + latitude: res.latitude, + longitude: res.longitude + }; + resolve(res); + }, + fail: (err) => { + console.error('获取位置失败:', err); + reject(err); + } + }); + }); + }, + + // 处理授权确认 + handleAuthConfirm() { + uni.openSetting({ + success: (res) => { + if (res.authSetting['scope.userLocation']) { + this.getUserLocation().catch(() => { + uni.showToast({ title: '获取位置失败', icon: 'none' }); + }); + } + this.showLocationModal = false; + } + }); + }, + + // 处理授权取消 + handleAuthCancel() { + this.showLocationModal = false; + uni.showToast({ title: '已取消位置授权', icon: 'none' }); + }, + + // 微信分享好友 + onShareAppMessage() { + return { + title: this.detailInfo.storeName || '发现一个好地方', + path: `/pages/surrounding/detail?Id=${this.Id}`, + imageUrl: this.detailInfo.storeCover, + success: () => { + this.logShareEvent(); + }, + fail: (err) => { + console.error('分享失败:', err); + } + }; + }, + + // 朋友圈分享 + onShareTimeline() { + return { + title: this.detailInfo.storeName || '发现一个好地方', + query: `Id=${this.Id}`, + imageUrl: this.detailInfo.storeCover + }; + }, + + + openMap() { + const { latitude, longitude, storeName, storeAddress } = this.detailInfo; + if (latitude && longitude) { + uni.openLocation({ + latitude: Number(latitude), + longitude: Number(longitude), + name: storeName, + address: storeAddress, + success: () => { + console.log('打开地图成功'); + }, + fail: (err) => { + console.error('打开地图失败:', err); + uni.showToast({ + title: '打开地图失败', + icon: 'none' + }); + } + }); + } else { + uni.showToast({ + title: '暂无位置信息', + icon: 'none' + }); + } + }, + + previewImage(index) { + if (!this.detailInfo.detailImages || !this.detailInfo.detailImages.length) return; + + uni.previewImage({ + current: index, + urls: this.detailInfo.detailImages.map(img => img.startsWith('http') ? img : IMAGE_BASE_URL + img) + }); + }, + + handleShare() { + uni.showActionSheet({ + itemList: ['分享到微信', '分享到朋友圈', '复制链接'], + success: (res) => { + uni.showToast({ + title: `已选择: ${res.tapIndex === 0 ? '微信' : res.tapIndex === 1 ? '朋友圈' : '复制链接'}`, + icon: 'none' + }); + } + }); + } } } - \ No newline at end of file diff --git a/pages/index/index.vue b/pages/index/index.vue index 2683ef8..8656f72 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -87,7 +87,7 @@ + style="width: 76rpx;height: 76rpx; bottom: 32rpx;" > @@ -503,7 +503,7 @@ width: 90rpx; height: 90rpx; right: 24rpx; - bottom: 24rpx; + bottom: 20rpx; transition: all 0.3s ease; } diff --git a/pages/mine/index.vue b/pages/mine/index.vue index 7f8aee2..4231e67 100644 --- a/pages/mine/index.vue +++ b/pages/mine/index.vue @@ -1,843 +1,899 @@ - - - - - \ No newline at end of file diff --git a/pages/neighbor/index.vue b/pages/neighbor/index.vue index fbd2331..f598ef4 100644 --- a/pages/neighbor/index.vue +++ b/pages/neighbor/index.vue @@ -1,104 +1,96 @@ - - - - - \ No newline at end of file diff --git a/pages/neighborDetail/index.vue b/pages/neighborDetail/index.vue index 8867a8b..631c108 100644 --- a/pages/neighborDetail/index.vue +++ b/pages/neighborDetail/index.vue @@ -55,8 +55,7 @@ - {{ foldedComments.includes(comment.id) ? '展开' : '折叠' }} - {{ getChildCount(comment) }}条回复 + {{ getChildCount(comment) }}条回复{{ foldedComments.includes(comment.id) ? '展开' : '折叠' }} @@ -84,234 +83,269 @@ - \ No newline at end of file diff --git a/static/imgs/index/nav.png b/static/imgs/index/nav.png index d4f4a5f..3b657bb 100644 Binary files a/static/imgs/index/nav.png and b/static/imgs/index/nav.png differ