forked from zhouruizhe/gmTouringMiniApp
Initial commit: gmTouringMiniApp project
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// pages/badges/badges.js
|
||||
const userStore = require('../../userStore.js');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
points: 0,
|
||||
badges: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
// 每次显示都刷新一次,保证从其他页面打卡回来后数据是最新的
|
||||
onShow() {
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
refresh() {
|
||||
const data = userStore.getUserData();
|
||||
|
||||
// 将徽章数据处理为渲染友好的结构(格式化获得时间、补默认图标)
|
||||
const badges = (data.badges || []).map(b => ({
|
||||
name: b.name,
|
||||
icon: this.getBadgeIcon(b.name),
|
||||
obtainedAtText: this.formatTime(b.obtainedAt)
|
||||
}));
|
||||
|
||||
this.setData({
|
||||
points: data.points || 0,
|
||||
badges
|
||||
});
|
||||
},
|
||||
|
||||
// 根据徽章名称返回对应的 emoji 图标(也可换成图片路径)
|
||||
getBadgeIcon(name) {
|
||||
const map = {
|
||||
'探索者': '🧭',
|
||||
'旅行家': '🌍',
|
||||
'打卡达人': '🏆'
|
||||
};
|
||||
return map[name] || '🎖️';
|
||||
},
|
||||
|
||||
// 格式化时间戳为 "YYYY-MM-DD HH:mm"
|
||||
formatTime(ts) {
|
||||
if (!ts) return '';
|
||||
const d = new Date(ts);
|
||||
const pad = n => (n < 10 ? '0' + n : '' + n);
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"navigationBarTitleText": "我的徽章",
|
||||
"navigationBarBackgroundColor": "#fff8ec",
|
||||
"navigationBarTextStyle": "black",
|
||||
"backgroundColor": "#fff8ec"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<!--pages/badges/badges.wxml-->
|
||||
<view class="page">
|
||||
|
||||
<!-- 顶部积分卡片 -->
|
||||
<view class="header-card">
|
||||
<view class="header-label">我的总积分</view>
|
||||
<view class="header-points">
|
||||
<text class="points-num">{{points}}</text>
|
||||
<text class="points-unit"> 分</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 徽章墙标题 -->
|
||||
<view class="section-title">
|
||||
<text>徽章墙</text>
|
||||
<text class="section-count">共 {{badges.length}} 枚</text>
|
||||
</view>
|
||||
|
||||
<!-- 徽章网格 -->
|
||||
<block wx:if="{{badges.length > 0}}">
|
||||
<view class="badge-grid">
|
||||
<view class="badge-item" wx:for="{{badges}}" wx:key="name">
|
||||
<view class="badge-icon">{{item.icon}}</view>
|
||||
<view class="badge-name">{{item.name}}</view>
|
||||
<view class="badge-time">{{item.obtainedAtText}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view class="empty" wx:else>
|
||||
<view class="empty-icon">🎖️</view>
|
||||
<view class="empty-text">还没有获得徽章</view>
|
||||
<view class="empty-tip">去景点打卡,赢取你的第一枚徽章吧~</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
@@ -0,0 +1,127 @@
|
||||
/* pages/badges/badges.wxss */
|
||||
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 24rpx;
|
||||
box-sizing: border-box;
|
||||
background: #fff8ec;
|
||||
}
|
||||
|
||||
/* 顶部积分卡片 */
|
||||
.header-card {
|
||||
background: linear-gradient(135deg, #ffb347 0%, #ff7e5f 100%);
|
||||
border-radius: 24rpx;
|
||||
padding: 40rpx 32rpx;
|
||||
color: #fff;
|
||||
box-shadow: 0 8rpx 24rpx rgba(255, 126, 95, 0.25);
|
||||
}
|
||||
|
||||
.header-label {
|
||||
font-size: 28rpx;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.header-points {
|
||||
margin-top: 12rpx;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.points-num {
|
||||
font-size: 72rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.points-unit {
|
||||
font-size: 30rpx;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
/* 分区标题 */
|
||||
.section-title {
|
||||
margin: 40rpx 8rpx 20rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.section-count {
|
||||
font-size: 24rpx;
|
||||
font-weight: 400;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 徽章网格 */
|
||||
.badge-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.badge-item {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 28rpx 12rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.badge-item:active {
|
||||
transform: scale(0.96);
|
||||
}
|
||||
|
||||
.badge-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #fff2d6, #ffe0b3);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 56rpx;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.badge-name {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
margin-bottom: 6rpx;
|
||||
}
|
||||
|
||||
.badge-time {
|
||||
font-size: 20rpx;
|
||||
color: #999;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty {
|
||||
margin-top: 120rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 120rpx;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
margin-top: 24rpx;
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
margin-top: 12rpx;
|
||||
font-size: 24rpx;
|
||||
color: #aaa;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// pages/poi/poi.js
|
||||
const userStore = require('../../userStore.js');
|
||||
|
||||
// 模拟的景点数据,实际项目中可以来自云端接口
|
||||
const POI_LIST = [
|
||||
{ id: 'poi_001', name: '西湖', icon: '🌊', desc: '杭州最著名的湖泊' },
|
||||
{ id: 'poi_002', name: '灵隐寺', icon: '🛕', desc: '千年古刹,禅意悠远' },
|
||||
{ id: 'poi_003', name: '雷峰塔', icon: '🗼', desc: '白娘子传说所在地' },
|
||||
{ id: 'poi_004', name: '西溪湿地', icon: '🌾', desc: '城市中的绿色湿地' },
|
||||
{ id: 'poi_005', name: '千岛湖', icon: '🏝️', desc: '碧水青山,湖光山色' }
|
||||
];
|
||||
|
||||
Page({
|
||||
data: {
|
||||
points: 0,
|
||||
badgeCount: 0,
|
||||
pois: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
// 每次刷新:把打卡状态合并到景点列表中,同时更新顶部积分/徽章数
|
||||
refresh() {
|
||||
const data = userStore.getUserData();
|
||||
const checkedSet = new Set(data.checkIns.map(c => c.poiId));
|
||||
|
||||
const pois = POI_LIST.map(p => ({
|
||||
...p,
|
||||
checked: checkedSet.has(p.id)
|
||||
}));
|
||||
|
||||
this.setData({
|
||||
points: data.points,
|
||||
badgeCount: data.badges.length,
|
||||
pois
|
||||
});
|
||||
},
|
||||
|
||||
// 点击打卡按钮
|
||||
onCheckIn(e) {
|
||||
const { id, name } = e.currentTarget.dataset;
|
||||
const res = userStore.checkIn(id, name);
|
||||
|
||||
wx.showToast({
|
||||
title: res.message,
|
||||
icon: res.success ? 'success' : 'none',
|
||||
duration: 1500
|
||||
});
|
||||
|
||||
if (res.success) {
|
||||
this.refresh();
|
||||
}
|
||||
},
|
||||
|
||||
// 跳转到徽章页面
|
||||
goBadges() {
|
||||
wx.navigateTo({ url: '/pages/badges/badges' });
|
||||
},
|
||||
|
||||
// 调试用:清空本地数据
|
||||
onResetData() {
|
||||
wx.showModal({
|
||||
title: '确认清空',
|
||||
content: '将清除所有积分、徽章和打卡记录',
|
||||
success: (r) => {
|
||||
if (r.confirm) {
|
||||
wx.clearStorageSync();
|
||||
this.refresh();
|
||||
wx.showToast({ title: '已清空', icon: 'success' });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"navigationBarTitleText": "景点打卡",
|
||||
"navigationBarBackgroundColor": "#fff8ec",
|
||||
"navigationBarTextStyle": "black",
|
||||
"backgroundColor": "#fff8ec"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<!--pages/poi/poi.wxml-->
|
||||
<view class="page">
|
||||
|
||||
<!-- 顶部用户信息卡片 -->
|
||||
<view class="header-card" bindtap="goBadges">
|
||||
<view class="header-left">
|
||||
<view class="header-label">我的积分</view>
|
||||
<view class="header-points">
|
||||
<text class="points-num">{{points}}</text>
|
||||
<text class="points-unit"> 分</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="header-right">
|
||||
<view class="badge-count">
|
||||
<text class="badge-count-num">{{badgeCount}}</text>
|
||||
<text class="badge-count-label">枚徽章</text>
|
||||
</view>
|
||||
<view class="arrow">查看 ›</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 景点列表 -->
|
||||
<view class="section-title">热门景点</view>
|
||||
|
||||
<view class="poi-list">
|
||||
<view class="poi-item" wx:for="{{pois}}" wx:key="id">
|
||||
<view class="poi-icon">{{item.icon}}</view>
|
||||
<view class="poi-info">
|
||||
<view class="poi-name">{{item.name}}</view>
|
||||
<view class="poi-desc">{{item.desc}}</view>
|
||||
</view>
|
||||
<button
|
||||
class="poi-btn {{item.checked ? 'poi-btn-done' : ''}}"
|
||||
disabled="{{item.checked}}"
|
||||
data-id="{{item.id}}"
|
||||
data-name="{{item.name}}"
|
||||
bindtap="onCheckIn"
|
||||
>
|
||||
{{item.checked ? '已打卡' : '打卡 +10'}}
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 调试按钮:清空数据 -->
|
||||
<view class="reset-wrap">
|
||||
<button class="reset-btn" bindtap="onResetData">清空本地数据(调试)</button>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
@@ -0,0 +1,156 @@
|
||||
/* pages/poi/poi.wxss */
|
||||
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 24rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* 顶部积分卡片 */
|
||||
.header-card {
|
||||
background: linear-gradient(135deg, #ffb347 0%, #ff7e5f 100%);
|
||||
border-radius: 24rpx;
|
||||
padding: 36rpx 32rpx;
|
||||
color: #fff;
|
||||
box-shadow: 0 8rpx 24rpx rgba(255, 126, 95, 0.25);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.header-label {
|
||||
font-size: 26rpx;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.header-points {
|
||||
margin-top: 8rpx;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.points-num {
|
||||
font-size: 64rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.points-unit {
|
||||
font-size: 28rpx;
|
||||
margin-left: 6rpx;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.badge-count-num {
|
||||
font-size: 40rpx;
|
||||
font-weight: 700;
|
||||
margin-right: 6rpx;
|
||||
}
|
||||
|
||||
.badge-count-label {
|
||||
font-size: 24rpx;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
margin-top: 12rpx;
|
||||
font-size: 22rpx;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* 分区标题 */
|
||||
.section-title {
|
||||
margin: 40rpx 8rpx 20rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* 景点列表 */
|
||||
.poi-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.poi-item {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 24rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.poi-icon {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #fff2d6, #ffe0b3);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 52rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.poi-info {
|
||||
flex: 1;
|
||||
margin: 0 24rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.poi-name {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.poi-desc {
|
||||
margin-top: 6rpx;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* 打卡按钮 */
|
||||
.poi-btn {
|
||||
min-width: 160rpx;
|
||||
height: 64rpx;
|
||||
line-height: 64rpx;
|
||||
padding: 0 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, #ffb347, #ff7e5f);
|
||||
border-radius: 32rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.poi-btn-done {
|
||||
background: #e5e5e5 !important;
|
||||
color: #999 !important;
|
||||
}
|
||||
|
||||
.poi-btn[disabled] {
|
||||
background: #e5e5e5 !important;
|
||||
color: #999 !important;
|
||||
}
|
||||
|
||||
/* 调试按钮 */
|
||||
.reset-wrap {
|
||||
margin: 60rpx 0 40rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
background: transparent;
|
||||
padding: 12rpx 32rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user