This commit is contained in:
2026-06-25 18:24:29 +08:00
commit a1190d7d9a
90 changed files with 5459 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
// pages/home/home — 1 我的Tab启动默认页
const { call } = require('../../utils/cloud.js');
const store = require('../../utils/store.js');
Page({
data: {
userInfo: null,
joinDays: 0,
dogs: [],
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 1, walkState: (store.getWalkSession() || {}).status || 'idle' });
}
this.ensureUser();
this.loadDogs();
},
// 兜底:若直接进首页(未经登录页)补一次 login 拿 userInfo
async ensureUser() {
let userInfo = store.getState().userInfo;
if (!userInfo) {
const res = await call('login');
if (res.ok) {
userInfo = res.data.userInfo;
store.set({ userInfo });
}
}
if (userInfo) {
const joinDays = Math.max(0, Math.floor((Date.now() - userInfo.joinedAt) / 86400000));
this.setData({ userInfo, joinDays });
}
},
async loadDogs() {
const res = await call('dogManage', { action: 'list' });
if (res.ok) {
store.set({ dogs: res.data });
this.setData({ dogs: res.data });
}
},
goDogDetail(e) {
const id = e.currentTarget.dataset.id;
wx.navigateTo({ url: `/pages/dog-detail/dog-detail?id=${id}` });
},
goAddDog() {
wx.navigateTo({ url: '/pages/dog-edit/dog-edit' });
},
goHistory() {
wx.navigateTo({ url: '/pages/history/history' });
},
goAchievements() {
const id = this.data.dogs[0] && this.data.dogs[0]._id;
wx.navigateTo({ url: `/pages/achievements/achievements${id ? '?dogId=' + id : ''}` });
},
});

View File

@@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "我的"
}

View File

@@ -0,0 +1,37 @@
<view class="page">
<!-- 用户卡 -->
<view class="user-row">
<view class="user-avatar">😀</view>
<view class="user-meta">
<view class="user-name">{{userInfo.nickname || '铲屎官'}}</view>
<view class="user-sub">遛狗 {{userInfo.walkCount || 0}} 次 · 加入 {{joinDays}} 天</view>
</view>
<view class="chev"></view>
</view>
<!-- 我的狗狗 -->
<view class="section-title">我的狗狗</view>
<view class="dogs">
<view wx:for="{{dogs}}" wx:key="_id" class="card dog-card" data-id="{{item._id}}" bindtap="goDogDetail">
<image wx:if="{{item.avatar}}" class="dog-avatar" src="{{item.avatar}}" mode="aspectFill" />
<view wx:else class="dog-avatar">🐶</view>
<view class="dog-meta">
<view class="dog-name">{{item.name}}</view>
<view class="dog-sub">
<text wx:if="{{item.stats.currentStreak > 0}}" class="streak">● 连续 {{item.stats.currentStreak}} 天</text>
<text wx:if="{{item.stats.currentStreak > 0}}"> · </text>{{item.breed}}
</view>
</view>
<view class="chev"></view>
</view>
<view class="add-dog" bindtap="goAddDog"> 添加狗狗</view>
</view>
<!-- 功能入口 -->
<view class="list">
<view class="listrow" bindtap="goHistory"><text class="lbl">遛狗历史</text><text class="chev"></text></view>
<view class="listrow" bindtap="goAchievements"><text class="lbl">成就</text><text class="chev"></text></view>
<view class="listrow"><text class="lbl">设置</text><text class="chev"></text></view>
</view>
</view>

View File

@@ -0,0 +1,52 @@
.page { min-height: 100vh; padding-bottom: calc(180rpx + env(safe-area-inset-bottom)); }
/* 用户卡 */
.user-row {
display: flex; align-items: center; gap: 24rpx;
padding: 32rpx;
border-bottom: 1rpx solid var(--line);
}
.user-avatar {
width: 100rpx; height: 100rpx; border-radius: 50%;
background: var(--surface-2);
display: flex; align-items: center; justify-content: center;
font-size: 52rpx;
}
.user-meta { flex: 1; }
.user-name { font-size: 30rpx; font-weight: 600; }
.user-sub { margin-top: 6rpx; font-size: 22rpx; color: var(--ink-2); }
.section-title { font-size: 24rpx; color: var(--ink-2); padding: 28rpx 32rpx 12rpx; }
/* 狗狗卡 */
.dogs { padding: 0 32rpx; }
.dog-card { display: flex; align-items: center; gap: 24rpx; padding: 24rpx; }
.dog-avatar {
width: 88rpx; height: 88rpx; border-radius: 50%;
background: var(--surface-2);
display: flex; align-items: center; justify-content: center;
font-size: 44rpx;
}
.dog-meta { flex: 1; }
.dog-name { font-size: 28rpx; font-weight: 600; }
.dog-sub { margin-top: 6rpx; font-size: 22rpx; color: var(--ink-2); }
.dog-sub .streak { color: var(--success); }
.add-dog {
margin-top: 20rpx;
border: 1rpx dashed var(--line-2);
border-radius: var(--radius);
padding: 24rpx;
text-align: center;
font-size: 26rpx; color: var(--ink-2);
}
/* 功能入口 */
.list { margin-top: 24rpx; border-top: 1rpx solid var(--line); }
.listrow {
display: flex; align-items: center;
padding: 28rpx 32rpx;
border-bottom: 1rpx solid var(--line);
}
.listrow .lbl { flex: 1; font-size: 28rpx; }
.chev { color: var(--ink-3); width: var(--icon-size); font-size: var(--icon-size); line-height: 1; text-align: center; }