diff --git a/pages/aroundDetail/index.vue b/pages/aroundDetail/index.vue index 308b21f..5c41b9d 100644 --- a/pages/aroundDetail/index.vue +++ b/pages/aroundDetail/index.vue @@ -113,12 +113,22 @@ 导航前往 - - - 分享 + + + 分享 + + + @@ -158,6 +168,10 @@ export default { status: 1 }, local: null, + showLocationModal: false, + locationModalContent: '我们需要获取您的位置信息,以便提供更精准的服务', + userLocation: null, + isRequestingLocation: false } }, computed: { @@ -188,10 +202,17 @@ export default { } }, 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(); @@ -207,26 +228,147 @@ export default { }, async getAroundDetail() { - try { - const res = await get(`/api/v1/apps/surrounding/${this.Id}`); - if (!res || !res.success) { - throw new Error('获取详情失败'); - } - - if (res.data.storeCover) { - res.data.storeCover = res.data.storeCover.startsWith('http') ? res.data.storeCover : IMAGE_BASE_URL + res.data.storeCover; - } - - this.detailInfo = {...this.detailInfo, ...res.data}; - } catch (err) { - console.error('获取详情失败:', err); - uni.showToast({ - title: '获取详情失败', - icon: 'none' - }); - } + 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) { diff --git a/pages/aroundList/index.vue b/pages/aroundList/index.vue index d195d64..4a86a73 100644 --- a/pages/aroundList/index.vue +++ b/pages/aroundList/index.vue @@ -1,147 +1,195 @@ - - - - - - - {{ item.name }} - - - 人均¥{{ item.perCapita }} - 直线{{ item.distance }}m - - - {{ "“" + item.desc + "”" }} - - - - - - - - - - \ No newline at end of file diff --git a/pages/neighbor/index.vue b/pages/neighbor/index.vue index 8f3fe39..f598ef4 100644 --- a/pages/neighbor/index.vue +++ b/pages/neighbor/index.vue @@ -3,7 +3,7 @@ - + {{item.label}} @@ -38,7 +38,9 @@ data() { return { IMAGE_BASE_URL, - aroundList:[] + aroundList:[], + longitude:null, + latitude:null, } }, onLoad() {}, @@ -51,6 +53,11 @@ url: `/pages/aroundDetail/index?Id=${id}&local=${local}`, }); }, + goPage(id){ + uni.navigateTo({ + url: `/pages/aroundList/index?Id=${id}&latitude=${this.latitude}&longitude=${this.longitude}`, + }); + }, formatDistance(distance) { if (!distance) return '未知距离'; if (distance < 1000) { @@ -61,6 +68,8 @@ }, async surroundingList() { const position = await this.getCurrentPosition(); + this.latitude = position.latitude; + this.longitude = position.longitude; let params = { current: 1, pageSize: 10,