first commit

This commit is contained in:
ytc1012
2026-02-04 16:11:55 +08:00
commit 0f3ee050dc
165 changed files with 25795 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
const app = getApp()
const db = wx.cloud.database()
Page({
data: {
roomId: '',
center: { latitude: 39.9, longitude: 116.4 },
markers: [],
recommendations: [],
scale: 13,
selectedIndex: -1 // 当前选中的索引
},
onLoad: function (options) {
this.setData({ roomId: options.roomId })
this.fetchResult()
},
async fetchResult() {
wx.showLoading({ title: '加载结果...' })
try {
const res = await db.collection('rooms').doc(this.data.roomId).get()
const data = res.data
if (data && data.result && data.result.success) {
const result = data.result
const center = result.center
const recommendations = result.recommendations || []
// 构建 Markers
const markers = []
// 中心点 Marker
markers.push({
id: 0,
latitude: center.lat,
longitude: center.lng,
iconPath: '',
width: 0,
height: 0,
callout: {
content: '最佳中心点',
display: 'ALWAYS',
padding: 8,
borderRadius: 4,
bgColor: '#FF6B6B',
color: '#FFFFFF',
fontSize: 12
}
})
// 推荐点 Markers
recommendations.forEach((place, index) => {
markers.push({
id: index + 1, // ID 从 1 开始
latitude: place.location.lat,
longitude: place.location.lng,
iconPath: '',
width: 0,
height: 0,
callout: {
content: `${index + 1}`, // 默认只显示序号
display: 'ALWAYS',
padding: 6,
borderRadius: 4,
bgColor: '#4CAF50',
color: '#FFFFFF',
fontSize: 11
}
})
})
this.setData({
center: { latitude: center.lat, longitude: center.lng },
recommendations: recommendations,
markers: markers
})
} else {
wx.showToast({ title: '暂无结果', icon: 'none' })
}
wx.hideLoading()
} catch (err) {
console.error(err)
wx.hideLoading()
wx.showToast({ title: '加载失败', icon: 'none' })
}
},
onListTap(e) {
const index = e.currentTarget.dataset.index
const place = this.data.recommendations[index]
// 如果点击已选中的,取消选中
const newSelectedIndex = this.data.selectedIndex === index ? -1 : index
// 更新选中状态
this.setData({ selectedIndex: newSelectedIndex })
// 更新地图标记的 callout
const markers = this.data.markers
markers.forEach((marker, markerIndex) => {
if (marker.id > 0) { // 推荐点 MarkerID 从 1 开始)
const placeIndex = marker.id - 1
if (newSelectedIndex === placeIndex) {
// 选中的地点显示名称
markers[markerIndex].callout.content = `${index + 1}. ${place.name}`
markers[markerIndex].callout.bgColor = '#FF6B6B' // 红色背景
markers[markerIndex].callout.fontSize = 12
} else {
// 未选中的地点只显示序号
markers[markerIndex].callout.content = `${placeIndex + 1}`
markers[markerIndex].callout.bgColor = '#4CAF50' // 绿色背景
markers[markerIndex].callout.fontSize = 11
}
}
})
// 更新 markers 数据
this.setData({ markers })
// 移动地图到选中地点
if (newSelectedIndex >= 0) {
this.setData({
center: { latitude: place.location.lat, longitude: place.location.lng }
})
}
}
})

View File

@@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "推荐结果"
}

View File

@@ -0,0 +1,36 @@
<view class="container">
<map
id="mapResult"
class="map"
latitude="{{center.latitude}}"
longitude="{{center.longitude}}"
scale="{{scale}}"
markers="{{markers}}"
bindmarkertap="onMarkerTap"
>
</map>
<!-- 底部推荐列表 -->
<scroll-view scroll-y class="rec-list">
<block wx:for="{{recommendations}}" wx:key="id">
<view class="rec-card {{selectedIndex === index ? 'selected' : ''}}" bindtap="onListTap" data-index="{{index}}">
<view class="rec-header">
<view class="rec-rank {{selectedIndex === index ? 'selected' : ''}}">{{index+1}}</view>
<view class="rec-info-right">
<view class="rec-name">{{item.name}}</view>
<view class="rec-info">
<text class="rating">{{item.rating}}分</text>
<text class="divider">|</text>
<text class="distance">{{item.distance}}米</text>
</view>
</view>
</view>
<view class="rec-address">{{item.address}}</view>
<view class="rec-tags" wx:if="{{item.tags && item.tags.length}}">
<text class="tag" wx:for="{{item.tags}}" wx:key="*this" wx:for-item="tag">{{tag}}</text>
</view>
<view class="rec-reason" wx:if="{{item.reason}}">{{item.reason}}</view>
</view>
</block>
</scroll-view>
</view>

View File

@@ -0,0 +1,141 @@
.container {
height: 100vh;
display: flex;
flex-direction: column;
padding: 0 !important;
box-sizing: border-box;
align-items: stretch !important;
justify-content: flex-start !important;
}
.map {
flex: 1;
width: 100%;
}
.rec-list {
background-color: #fff;
padding: 20rpx;
height: 60vh;
box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
box-sizing: border-box;
}
.rec-card {
display: flex;
flex-direction: column;
background-color: #f9f9f9;
margin-bottom: 16rpx;
padding: 20rpx;
border-radius: 12rpx;
box-sizing: border-box;
transition: all 0.3s;
border: 2rpx solid transparent;
}
.rec-card.selected {
background-color: #fff5f5;
border-color: #FF6B6B;
box-shadow: 0 4rpx 12rpx rgba(255, 107, 107, 0.15);
}
.rec-card:active {
background-color: #f0f0f0;
}
.rec-header {
display: flex;
align-items: flex-start;
margin-bottom: 12rpx;
}
.rec-rank {
width: 44rpx;
height: 44rpx;
background-color: #667eea;
color: white;
font-size: 24rpx;
font-weight: bold;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16rpx;
flex-shrink: 0;
}
.rec-rank.selected {
background-color: #FF6B6B;
transform: scale(1.1);
}
.rec-info-right {
flex: 1;
min-width: 0;
}
.rec-name {
font-size: 30rpx;
font-weight: bold;
color: #333;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-bottom: 8rpx;
}
.rec-info {
display: flex;
align-items: center;
font-size: 24rpx;
}
.rec-info .rating {
color: #ff9800;
font-weight: 500;
}
.rec-info .divider {
color: #ddd;
margin: 0 8rpx;
}
.rec-info .distance {
color: #666;
}
.rec-address {
font-size: 24rpx;
color: #666;
margin-bottom: 10rpx;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.rec-tags {
display: flex;
flex-wrap: wrap;
margin-bottom: 10rpx;
}
.tag {
font-size: 22rpx;
background-color: #e8f7f0;
color: #07c160;
padding: 4rpx 10rpx;
border-radius: 8rpx;
margin-right: 8rpx;
margin-bottom: 6rpx;
}
.rec-reason {
background-color: #fffbf0;
color: #d97a00;
padding: 12rpx;
border-radius: 8rpx;
font-size: 24rpx;
line-height: 1.5;
}