Initial commit: gmTouringMiniApp project

This commit is contained in:
周瑞哲
2026-07-30 16:04:34 +08:00
commit ebcae02d35
201 changed files with 49545 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
// app.js
App({
onLaunch() {
// 可以在此做全局初始化,如上报启动日志等
},
globalData: {}
});
+14
View File
@@ -0,0 +1,14 @@
{
"pages": [
"pages/poi/poi",
"pages/badges/badges"
],
"window": {
"navigationBarBackgroundColor": "#fff8ec",
"navigationBarTitleText": "打卡小程序",
"navigationBarTextStyle": "black",
"backgroundColor": "#fff8ec"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
+11
View File
@@ -0,0 +1,11 @@
/**app.wxss**/
page {
font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
color: #333;
background: #fff8ec;
}
/* 通用按钮重置:去掉小程序 button 默认的边框和圆角 */
button::after {
border: none;
}
+52
View File
@@ -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())}`;
}
});
+6
View File
@@ -0,0 +1,6 @@
{
"navigationBarTitleText": "我的徽章",
"navigationBarBackgroundColor": "#fff8ec",
"navigationBarTextStyle": "black",
"backgroundColor": "#fff8ec"
}
+37
View File
@@ -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>
+127
View File
@@ -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;
}
+80
View File
@@ -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' });
}
}
});
}
});
+6
View File
@@ -0,0 +1,6 @@
{
"navigationBarTitleText": "景点打卡",
"navigationBarBackgroundColor": "#fff8ec",
"navigationBarTextStyle": "black",
"backgroundColor": "#fff8ec"
}
+49
View File
@@ -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>
+156
View File
@@ -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;
}
+40
View File
@@ -0,0 +1,40 @@
{
"miniprogramRoot": "./",
"projectname": "打卡",
"appid": "wxa3abd3957b0eb47b",
"description": "景点打卡示例",
"setting": {
"es6": true,
"enhance": true,
"postcss": true,
"minified": true,
"urlCheck": true,
"compileHotReLoad": true,
"compileWorklet": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"minifyWXML": true,
"localPlugins": false,
"disableUseStrict": false,
"useCompilerPlugins": false,
"condition": false,
"swc": false,
"disableSWC": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"compileType": "miniprogram",
"libVersion": "3.0.0",
"simulatorPluginLibVersion": {},
"packOptions": {
"ignore": [],
"include": []
},
"editorSetting": {}
}
+8
View File
@@ -0,0 +1,8 @@
{
"rules": [
{
"action": "allow",
"page": "*"
}
]
}
+113
View File
@@ -0,0 +1,113 @@
// userStore.js
// 用户数据管理模块:负责积分、徽章、打卡记录的本地存储与业务逻辑
const STORAGE_KEY = 'USER_DATA';
// 默认的用户数据结构
const defaultUserData = {
points: 0, // 用户积分
badges: [], // 用户徽章列表,元素形如 { name, obtainedAt }
checkIns: [] // 打卡记录,元素形如 { poiId, poiName, time }
};
/**
* 获取完整的用户数据
* 如果本地没有数据,返回默认结构
* @returns {{points:number, badges:Array, checkIns:Array}}
*/
function getUserData() {
try {
const data = wx.getStorageSync(STORAGE_KEY);
if (data && typeof data === 'object') {
// 兼容旧数据:补齐可能缺失的字段
return Object.assign({}, defaultUserData, data);
}
} catch (e) {
console.error('[userStore] 读取用户数据失败:', e);
}
// 深拷贝默认数据,避免外部修改影响默认值
return JSON.parse(JSON.stringify(defaultUserData));
}
/**
* 保存用户数据到本地
* @param {Object} data
*/
function saveUserData(data) {
try {
wx.setStorageSync(STORAGE_KEY, data);
} catch (e) {
console.error('[userStore] 保存用户数据失败:', e);
}
}
/**
* 判断某个景点是否已经打卡过
* @param {string|number} poiId
* @returns {boolean}
*/
function hasCheckedIn(poiId) {
const data = getUserData();
return data.checkIns.some(item => item.poiId === poiId);
}
/**
* 判断是否已经拥有某个徽章
* @param {Object} data 用户数据
* @param {string} badgeName
* @returns {boolean}
*/
function hasBadge(data, badgeName) {
return data.badges.some(b => b.name === badgeName);
}
/**
* 处理打卡逻辑
* 检查是否已打卡;如未打卡则 +10 积分,添加“探索者”徽章(如没有),保存数据
* @param {string|number} poiId 景点 ID
* @param {string} poiName 景点名称
* @returns {{success:boolean, message:string, data?:Object}}
*/
function checkIn(poiId, poiName) {
if (!poiId) {
return { success: false, message: '景点 ID 无效' };
}
const data = getUserData();
// 已打卡则不再重复奖励
if (data.checkIns.some(item => item.poiId === poiId)) {
return { success: false, message: '你已经打卡过该景点', data };
}
// 增加打卡记录
data.checkIns.push({
poiId,
poiName: poiName || '',
time: Date.now()
});
// 增加 10 积分
data.points += 10;
// 添加“探索者”徽章(若尚未拥有)
const BADGE_NAME = '探索者';
if (!hasBadge(data, BADGE_NAME)) {
data.badges.push({
name: BADGE_NAME,
obtainedAt: Date.now()
});
}
// 保存到本地
saveUserData(data);
return { success: true, message: '打卡成功,积分 +10', data };
}
module.exports = {
getUserData,
saveUserData,
hasCheckedIn,
checkIn
};