fix:修复bug

This commit is contained in:
2025-10-14 19:20:26 +08:00
parent 30e298d9d2
commit 4408673438
21 changed files with 1153 additions and 549 deletions
+273 -183
View File
@@ -1,40 +1,38 @@
<template>
<view class="container">
<!-- 顶部Logo区域 -->
<view class="header-section">
<view class="logo-container">
<image class="logo-image" src="/static/logo.png" mode="aspectFit" />
<text class="app-name">共享风扇</text>
</view>
<uv-notice-bar :text="noticeText" mode="link" :speed="50" :show-icon="true" color="#2196F3"
bg-color="#E3F2FD" icon="volume"></uv-notice-bar>
<view class="container fullscreen">
<view class="" style="font-size: 32rpx;font-weight: 600;margin: 15rpx 20rpx;">风电者共享风扇&充电宝</view>
<view class="map-notice" v-if="noticeText">
<uv-notice-bar :text="noticeText" :speed="50" :show-icon="true" color="#07c160" bg-color="#E8F8EF"
icon="volume"></uv-notice-bar>
</view>
<!-- 地图标题 -->
<!-- <view class="map-title">
<text>附近场地</text>
</view> -->
<!-- 地图组件 -->
<!-- 全屏地图组件 -->
<MapComponent v-if="!isLoading && userLocation" ref="mapRef" :userLocation="userLocation"
:positionList="positionList" :filteredPositions="filteredPositions" :searchKeyword="searchKeyword"
@relocate="handleRelocate" @scan="handleScan" @showList="showLocationList" @markerTap="selectPosition"
@mapCenterChange="onMapCenterChange" />
<!-- 操作步骤指引常驻显示 -->
<view class="steps-guide">
<view class="guide-header">
<text class="guide-title">使用指南</text>
</view>
<view class="steps-container">
<view class="step-item" v-for="(step, index) in guideSteps" :key="index">
<view class="step-number">{{ index + 1 }}</view>
<view class="step-content">
<text class="step-title">{{ step.title }}</text>
<text class="step-desc">{{ step.desc }}</text>
</view>
<!-- 底部操作栏附近设备 / 扫码使用 / 我的 -->
<view class="bottom-actions">
<view class="action-btn secondary small btn-nearby" @click="showLocationList">
<view class="icon-wrap">
<image class="action-icon" src="/static/map.png" mode="aspectFit" />
</view>
<text class="action-label">附近设备</text>
</view>
<view class="action-btn primary btn-scan" @click="handleScan">
<view class="icon-wrap">
<image class="action-icon" src="/static/scan-icon.png" mode="aspectFit" />
</view>
<text class="action-label">扫码使用</text>
</view>
<view class="action-btn secondary small btn-my" @click="goMy">
<view class="icon-wrap">
<image class="action-icon" src="/static/user-active.png" mode="aspectFit" />
</view>
<text class="action-label">个人中心</text>
</view>
</view>
@@ -46,6 +44,8 @@
</view>
</view>
<!-- 场地列表弹窗 -->
<view class="location-popup" v-if="showLocationPopup">
<view class="popup-mask" @click="hideLocationList"></view>
@@ -128,18 +128,23 @@
</template>
<script setup>
const redirectToLogin = () => {
try {
const pages = getCurrentPages()
const current = pages && pages.length ? pages[pages.length - 1] : null
const route = current && current.route ? ('/' + current.route) : '/pages/index/index'
const query = current && current.options ? Object.keys(current.options).map(k => `${k}=${encodeURIComponent(current.options[k])}`).join('&') : ''
const redirect = encodeURIComponent(query ? `${route}?${query}` : route)
uni.reLaunch({ url: `/pages/login/index?redirect=${redirect}` })
} catch (e) {
uni.reLaunch({ url: '/pages/login/index' })
}
}
const redirectToLogin = () => {
try {
const pages = getCurrentPages()
const current = pages && pages.length ? pages[pages.length - 1] : null
const route = current && current.route ? ('/' + current.route) : '/pages/index/index'
const query = current && current.options ? Object.keys(current.options).map(k =>
`${k}=${encodeURIComponent(current.options[k])}`).join('&') : ''
const redirect = encodeURIComponent(query ? `${route}?${query}` : route)
uni.reLaunch({
url: `/pages/login/index?redirect=${redirect}`
})
} catch (e) {
uni.reLaunch({
url: '/pages/login/index'
})
}
}
import {
ref,
computed,
@@ -155,7 +160,8 @@
} from "../../config/url.js"
import {
getDeviceInfo,
getPotionsDetail
getPotionsDetail,
getNoticeTextData
} from '../../config/user.js'
// 导入地图工具函数
import {
@@ -167,6 +173,13 @@
// 同样需要使用相对路径引入组件
// 注意:从 pages/index/ 目录访问 components/ 需要使用 ../../components/ 路径
import MapComponent from '../../components/MapComponent.vue'
// 开启右上角分享菜单(仅 mp-weixin 有效)
// #ifdef MP-WEIXIN
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
// #endif
// 响应式数据
const searchKeyword = ref('')
@@ -180,27 +193,20 @@
const showLocationPopup = ref(false)
// 使用指南步骤
const guideSteps = ref([{
title: '扫码使用',
desc: '找到附近设备,扫描设备上的二维码即可开始租借'
},
{
title: '免押金支付',
desc: '无需支付押金,使用支付分免押即可完成租借'
},
{
title: '开始使用',
desc: '设备自动解锁,风扇弹出后取出即可开始使用'
},
{
title: '归还设备',
desc: '使用完毕后,按照设备规格要求将风扇还入即可结束订单'
}
])
// 使用指南已取消
// 滚动通知内容
const noticeText = ref('消费规则:每小时5元,不足1小时按1小时计费,最高24小时封顶,请爱护设备,使用后请及时归还')
// const noticeText = ref('消费规则:每小时5元,不足1小时按1小时计费,最高24小时封顶,请爱护设备,使用后请及时归还')
const noticeText = ref('')
const getNoticeText = async()=>{
const parasm = {
'title':'用户端公告'
}
const res = await getNoticeTextData(parasm);
noticeText.value = res.data.noticeContent;
}
// 距离格式化函数
const formatDistance = (distanceInMeters) => {
if (distanceInMeters < 1000) {
@@ -239,7 +245,8 @@
if (process.env.NODE_ENV === 'development') {
testDistanceCalculation()
}
await getNoticeText();
// 1. 先获取用户位置
await getUserLocationAndAddress()
@@ -268,7 +275,7 @@
longitude: location.longitude,
latitude: location.latitude
}
console.log(userLocation.value);
// 将经纬度写入本地缓存(基础信息)
try {
@@ -329,11 +336,6 @@
const loadPositions = async () => {
try {
if (!uni.getStorageSync('token')) {
redirectToLogin()
return
}
const res = await uni.request({
url: `${URL}/device/position/app/list`,
method: 'GET',
@@ -348,7 +350,10 @@
})
console.log(res);
if (res.statusCode === 200 && res.data.code === 200) {
if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) {
redirectToLogin()
return
} else if (res.statusCode === 200 && res.data.code === 200) {
positionList.value = res.data.rows || []
calculateDistances()
filteredPositions.value = [...positionList.value]
@@ -399,14 +404,9 @@
const loadPositionsByCenter = async (center) => {
try {
if (!uni.getStorageSync('token')) {
redirectToLogin()
return
}
// 使用原有接口获取所有场地
const res = await uni.request({
url: `${URL}/device/position/list`,
url: `${URL}/device/position/app/list`,
method: 'GET',
header: {
'Authorization': "Bearer " + uni.getStorageSync('token'),
@@ -414,7 +414,10 @@
}
})
if (res.statusCode === 200 && res.data.code === 200) {
if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) {
redirectToLogin()
return
} else if (res.statusCode === 200 && res.data.code === 200) {
positionList.value = res.data.rows || []
// 基于地图中心计算距离
calculateDistances(center)
@@ -437,17 +440,43 @@
}
const handleRelocate = async () => {
uni.showLoading({
title: '定位中...'
})
// 直接重新加载当前页面
uni.reLaunch({
url: '/pages/index/index'
})
try {
uni.showLoading({
title: '定位中...'
})
const loc = await getUserLocation()
const center = {
longitude: Number(loc.longitude),
latitude: Number(loc.latitude)
}
userLocation.value = center
try {
uni.setStorageSync('userLocation', center)
} catch (_) {}
if (mapRef.value && typeof mapRef.value.moveToLocation === 'function') {
mapRef.value.moveToLocation(center)
}
await loadPositionsByCenter(center)
} catch (e) {
uni.showToast({
title: '定位失败',
icon: 'none'
})
} finally {
uni.hideLoading()
}
}
const onMapCenterChange = (center) => {
if (center && typeof center.longitude !== 'undefined' && typeof center.latitude !== 'undefined') {
userLocation.value = {
longitude: Number(center.longitude),
latitude: Number(center.latitude)
}
try {
uni.setStorageSync('userLocation', userLocation.value)
} catch (_) {}
}
loadPositionsByCenter(center)
}
@@ -467,6 +496,12 @@
})
}
const goMy = () => {
uni.navigateTo({
url: '/pages/my/index'
})
}
const selectPositionFromPopup = (position) => {
// 先关闭弹窗
hideLocationList()
@@ -524,11 +559,6 @@
return
}
if (!uni.getStorageSync('token')) {
redirectToLogin()
return
}
// 检查是否有使用中的订单
const inUseRes = await uni.request({
url: `${URL}/app/order/inUse`,
@@ -539,7 +569,10 @@
}
})
if (inUseRes.statusCode == 200 && inUseRes.data.code == 200 && inUseRes.data.data) {
if (inUseRes.statusCode === 401 || inUseRes.data?.code === 401 || inUseRes.data?.code === 40101) {
redirectToLogin()
return
} else if (inUseRes.statusCode == 200 && inUseRes.data.code == 200 && inUseRes.data.data) {
const inUseOrder = inUseRes.data.data
uni.reLaunch({
url: `/pages/return/index?orderId=${inUseOrder.orderId}&deviceId=${deviceNo || inUseOrder.deviceNo}`
@@ -557,7 +590,10 @@
}
})
if (orderRes.statusCode == 200 && orderRes.data.code == 200 && orderRes.data.data) {
if (orderRes.statusCode === 401 || orderRes.data?.code === 401 || orderRes.data?.code === 40101) {
redirectToLogin()
return
} else if (orderRes.statusCode == 200 && orderRes.data.code == 200 && orderRes.data.data) {
const unpaidOrder = orderRes.data.data
uni.navigateTo({
url: `/pages/order/payment?orderId=${unpaidOrder.orderId}`
@@ -603,10 +639,10 @@
}
} catch (error) {
console.error('扫码处理失败:', error)
uni.showToast({
title: '扫码失败',
icon: 'none'
})
// uni.showToast({
// title: '扫码失败',
// icon: 'none'
// })
}
}
@@ -625,15 +661,39 @@
}
</script>
<script>
// 选用 Page 级分享钩子(uni-app 需普通 script 导出)
export default {
// 分享给朋友
onShareAppMessage() {
return {
title: '风电者 - 共享风扇暖手充电宝',
path: '/pages/index/index',
// imageUrl: '/static/logo.png'
}
},
// 朋友圈
onShareTimeline() {
return {
title: '风电者 - 共享风扇暖手充电宝',
query: '',
// imageUrl: '/static/logo.png'
}
}
}
</script>
<style lang="scss" scoped>
.container {
height: 100%;
width: 100%;
background-color: #f6f7fb;
height: 100vh;
width: 100vw;
background-color: #fff;
display: flex;
flex-direction: column;
// align-items: center;
padding-top: 20rpx;
}
.fullscreen {
padding: 0;
}
/* 顶部Logo和通知栏 */
@@ -954,6 +1014,97 @@
}
}
/* 底部操作栏 */
.bottom-actions {
position: fixed;
left: 20rpx;
right: 20rpx;
bottom: 40rpx;
z-index: 1200;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
// gap: 16rpx;
padding: 0;
.action-btn {
display: flex;
flex-direction: column;
align-items: center;
align-content: center;
justify-content: center;
font-size: 26rpx;
font-weight: 600;
&.primary {
background: #07c160;
color: #fff;
border-radius: 64rpx;
height: 100rpx;
min-width: 320rpx;
// box-shadow: 0 16rpx 40rpx rgba(7, 193, 96, 0.35);
padding: 12rpx 24rpx;
.icon-wrap {
width: 50rpx;
height: 50rpx;
border-radius: 50%;
// background: rgba(255, 255, 255, 0.25);
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 10rpx;
}
}
&.secondary {
// background: rgba(255, 255, 255, 0.95);
color: #333;
border-radius: 24rpx;
height: 100rpx;
min-width: 180rpx;
// box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
padding: 12rpx 16rpx;
.icon-wrap {
width: 40rpx;
height: 40rpx;
border-radius: 50%;
background: #f7f8fa;
border: 2rpx solid #eaeaea;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 10rpx;
}
}
&.small {
height: 120rpx;
min-width: 180rpx;
border-radius: 28rpx;
}
}
.btn-nearby,
.btn-my {
gap: 10rpx;
}
.btn-scan {
flex-direction: row;
gap: 14rpx;
.icon-wrap {
margin-bottom: 0;
margin-right: 12rpx;
// background: rgba(255, 255, 255, 0.25);
box-shadow: none;
}
}
}
/* 加载状态 */
.loading-overlay {
position: fixed;
@@ -1119,90 +1270,29 @@
}
}
/* 操作步骤指引 */
.steps-guide {
align-items: center;
align-content: center;
background-color: rgba(255, 255, 255, 0.95);
.action-icon {
width: 42rpx;
height: 42rpx;
filter: none;
box-shadow: none;
}
.btn-scan .action-icon {
filter: brightness(0) invert(1);
}
.action-label {
line-height: 1;
}
.map-notice {
margin: 0 20rpx;
// position: absolute;
// left: 20rpx;
// right: 20rpx;
// top: 20rpx;
border-radius: 20rpx;
padding: 0;
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.12);
z-index: 10;
// max-width: calc(100% - 40rpx);
backdrop-filter: blur(15rpx);
border: 1rpx solid rgba(255, 255, 255, 0.9);
overflow: hidden;
width: 92%;
margin: 0 auto 20rpx;
}
.guide-header {
padding: 20rpx 24rpx;
background: linear-gradient(135deg, #2196F3, #1976D2);
border-bottom: 1rpx solid rgba(255, 255, 255, 0.2);
.guide-title {
font-size: 32rpx;
font-weight: 600;
color: #ffffff;
text-align: center;
display: block;
}
}
.steps-container {
display: flex;
flex-direction: column;
gap: 16rpx;
padding: 24rpx;
background-color: rgba(255, 255, 255, 0.9);
}
.step-item {
display: flex;
align-items: flex-start;
width: 100%;
padding: 16rpx 0;
border-bottom: 1rpx solid rgba(0, 0, 0, 0.05);
&:last-child {
border-bottom: none;
}
.step-number {
width: 40rpx;
height: 40rpx;
background: linear-gradient(135deg, #2196F3, #1976D2);
color: #ffffff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 24rpx;
font-weight: bold;
margin-right: 20rpx;
flex-shrink: 0;
box-shadow: 0 4rpx 12rpx rgba(33, 150, 243, 0.4);
}
.step-content {
flex: 1;
padding-top: 4rpx;
.step-title {
font-size: 30rpx;
font-weight: 600;
color: #333;
margin-bottom: 8rpx;
display: block;
}
.step-desc {
font-size: 26rpx;
color: #666;
display: block;
line-height: 1.5;
}
}
z-index: 15;
}
</style>