refactor(fe): Phase A —— tab 换成「我的」,计划降级,设置拆出来
## tab 结构
首页 / 记录 / 报告 / 社区 / 我的。计划从 tab 移出变二级页(导航栏补了
返回键),从「我的 → 养护计划」进。
## 消灭 5 处硬编码
tabBar 高亮原来靠每个 tab 页在 onShow 里写死 selected: 0/1/2/3/4,
调一次顺序就得同时改五个文件,漏一个就高亮错位——这次把计划换成我的
正好会踩到。改成 tabBar 组件在 pageLifetimes.show 里按当前 route 自己
匹配,五处硬编码全删。
## profile 拆成两页
原来的 profile 混了两类东西:「我是谁」和「怎么设置」。拆开:
pages/mine(tab) 个人名片(头像/昵称/签名/关注粉丝记录三个数)
+ 我的毛孩子列表 + 常用入口 + 齿轮进设置
pages/settings 提醒设置、会员权益、数据导出、意见反馈、关于我们
「我的」上放了个「看看别人眼里的我」,点进去就是 pages/user 那个公开
主页——自己看和别人看必须是同一个页面同一套渲染,否则两边会慢慢长歪。
这也是 Phase D 装扮功能的落点。
首页齿轮从「进 profile」改成「进设置」(个人页已经在 tab 上了)。
旧的 pages/profile 整个删掉,没留兼容层。
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
const store = require('../../utils/store.js');
|
||||
const api = require('../../utils/api.js');
|
||||
const { toastErr } = require('../../utils/ui.js');
|
||||
|
||||
Page({
|
||||
data: { user: {}, pets: [], summary: {}, initial: '', sheetShow: false, sheetType: '' },
|
||||
onLoad() {
|
||||
this._unsub = store.subscribe(() => this.applyUser());
|
||||
},
|
||||
onUnload() {
|
||||
if (this._unsub) this._unsub();
|
||||
},
|
||||
onShow() {
|
||||
store
|
||||
.ready()
|
||||
.then(() => {
|
||||
this.applyUser();
|
||||
this.loadSummary();
|
||||
})
|
||||
.catch((e) => toastErr(e));
|
||||
},
|
||||
applyUser() {
|
||||
const user = store.getUser() || {};
|
||||
// WXML 取不了字符串下标,首字在这里算
|
||||
this.setData({ pets: store.getPets(), user, initial: (user.nickname || '?').slice(0, 1) });
|
||||
},
|
||||
loadSummary() {
|
||||
api
|
||||
.userSummary()
|
||||
.then((summary) => this.setData({ summary }))
|
||||
.catch(() => {});
|
||||
},
|
||||
// 看自己的公开主页,和别人看到的是同一个页面、同一套渲染
|
||||
previewPublic() {
|
||||
const uid = this.data.user && this.data.user.id;
|
||||
if (uid) wx.navigateTo({ url: `/pages/user/user?id=${uid}` });
|
||||
},
|
||||
goSettings() {
|
||||
wx.navigateTo({ url: '/pages/settings/settings' });
|
||||
},
|
||||
goRelations(e) {
|
||||
const uid = (this.data.user && this.data.user.id) || '';
|
||||
if (!uid) return wx.showToast({ title: '登录信息还没就绪', icon: 'none' });
|
||||
wx.navigateTo({ url: `/pages/relations/relations?id=${uid}&kind=${e.currentTarget.dataset.kind}` });
|
||||
},
|
||||
goPlan() {
|
||||
wx.navigateTo({ url: '/pages/plan/plan' });
|
||||
},
|
||||
goRecord() {
|
||||
wx.switchTab({ url: '/pages/record/record' });
|
||||
},
|
||||
onPickPet(e) {
|
||||
store.switchPet(e.currentTarget.dataset.id);
|
||||
wx.switchTab({ url: '/pages/home/home' });
|
||||
},
|
||||
openSheet(e) {
|
||||
this.setData({ sheetType: e.currentTarget.dataset.type, sheetShow: true });
|
||||
},
|
||||
closeSheet() {
|
||||
this.setData({ sheetShow: false });
|
||||
},
|
||||
onAddPet() {
|
||||
this.setData({ sheetType: 'addPet', sheetShow: true });
|
||||
},
|
||||
onFab() {
|
||||
wx.navigateTo({ url: '/pages/ai/ai' });
|
||||
},
|
||||
onShareAppMessage() {
|
||||
return { title: '肉垫计划 · 每天照顾好毛孩子', path: '/pages/home/home' };
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"nav-bar": "/components/nav-bar/nav-bar",
|
||||
"bottom-sheet": "/components/bottom-sheet/bottom-sheet",
|
||||
"fab": "/components/fab/fab",
|
||||
"pt-icon": "/components/pt-icon/index"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<nav-bar title="我的"></nav-bar>
|
||||
|
||||
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
|
||||
<view class="page-body">
|
||||
<!-- 个人名片。点进去看的是「别人眼里的我」,和 pages/user 同一个页面 -->
|
||||
<view class="card me-card">
|
||||
<view class="me-top">
|
||||
<view class="me-av">
|
||||
<image wx:if="{{user.avatar_url}}" class="me-av-img" src="{{user.avatar_url}}" mode="aspectFill"></image>
|
||||
<block wx:else>{{initial}}</block>
|
||||
</view>
|
||||
<view class="me-main">
|
||||
<view class="me-name">{{user.nickname || '毛孩子家长'}}</view>
|
||||
<view class="me-bio">{{user.bio || '还没有个性签名'}}</view>
|
||||
</view>
|
||||
<view class="me-gear" catchtap="goSettings"><pt-icon name="settings" size="{{36}}"></pt-icon></view>
|
||||
</view>
|
||||
|
||||
<view class="me-stats">
|
||||
<view class="me-stat" data-kind="following" bindtap="goRelations">
|
||||
<text class="me-n">{{summary.following || 0}}</text><text class="me-l">关注</text>
|
||||
</view>
|
||||
<view class="me-stat" data-kind="followers" bindtap="goRelations">
|
||||
<text class="me-n">{{summary.followers || 0}}</text><text class="me-l">粉丝</text>
|
||||
</view>
|
||||
<view class="me-stat" bindtap="goRecord">
|
||||
<text class="me-n">{{summary.records || 0}}</text><text class="me-l">记录</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="btn btn-ghost btn-block" bindtap="previewPublic">
|
||||
<pt-icon name="user" size="{{30}}"></pt-icon>看看别人眼里的我
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 我的毛孩子 -->
|
||||
<view class="card">
|
||||
<view class="section-head">
|
||||
<view class="sh-title">我的毛孩子</view>
|
||||
<view class="link" bindtap="onAddPet">+ 添加</view>
|
||||
</view>
|
||||
<view wx:for="{{pets}}" wx:key="id" class="pet-row" data-id="{{item.id}}" bindtap="onPickPet">
|
||||
<view class="pet-emoji">{{item.emoji}}</view>
|
||||
<view class="pet-info">
|
||||
<view class="tt-b">{{item.name}}</view>
|
||||
<view class="tt-p">{{item.age}}|{{item.weight}}|{{item.stage}}</view>
|
||||
</view>
|
||||
<view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
|
||||
</view>
|
||||
<view wx:if="{{!pets.length}}" class="empty">还没有毛孩子,先建一份档案</view>
|
||||
</view>
|
||||
|
||||
<!-- 常用入口。设置类的都收进设置页了,这里只留高频的 -->
|
||||
<view class="profile-list">
|
||||
<view class="profile-row" data-type="editPet" bindtap="openSheet">
|
||||
<view class="pr-ic"><pt-icon name="user" size="{{34}}"></pt-icon></view>
|
||||
<text class="pr-label">宠物档案</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
|
||||
</view>
|
||||
<view class="profile-row" bindtap="goPlan">
|
||||
<view class="pr-ic"><pt-icon name="plan" size="{{34}}"></pt-icon></view>
|
||||
<text class="pr-label">养护计划</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
|
||||
</view>
|
||||
<view class="profile-row" data-type="managePets" bindtap="openSheet">
|
||||
<view class="pr-ic"><pt-icon name="community" size="{{34}}"></pt-icon></view>
|
||||
<text class="pr-label">多宠物管理</text><text class="pr-val">{{summary.pets || 0}} 只</text>
|
||||
<view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
|
||||
</view>
|
||||
<view class="profile-row" bindtap="goSettings">
|
||||
<view class="pr-ic"><pt-icon name="settings" size="{{34}}"></pt-icon></view>
|
||||
<text class="pr-label">设置</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<fab bind:tap="onFab"></fab>
|
||||
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" bind:close="closeSheet"></bottom-sheet>
|
||||
@@ -0,0 +1,25 @@
|
||||
.me-card{padding:var(--sp-5)}
|
||||
.me-top{display:flex;align-items:center;gap:var(--sp-3)}
|
||||
.me-av{
|
||||
width:110rpx;height:110rpx;border-radius:50%;flex:none;overflow:hidden;
|
||||
display:flex;align-items:center;justify-content:center;
|
||||
background:var(--primary-soft);color:var(--primary-ink);font-size:44rpx;font-weight:var(--fw-b);
|
||||
}
|
||||
.me-av-img{width:100%;height:100%}
|
||||
.me-main{flex:1;min-width:0}
|
||||
.me-name{font-size:var(--fs-lg);font-weight:var(--fw-b)}
|
||||
.me-bio{color:var(--muted);font-size:var(--fs-sm);margin-top:6rpx}
|
||||
.me-gear{flex:none;color:var(--muted)}
|
||||
.me-stats{display:flex;margin:var(--sp-4) 0}
|
||||
.me-stat{flex:1;display:flex;flex-direction:column;align-items:center;gap:4rpx}
|
||||
.me-n{font-size:var(--fs-lg);font-weight:var(--fw-b)}
|
||||
.me-l{font-size:var(--fs-cap);color:var(--muted)}
|
||||
|
||||
.pet-row{display:flex;align-items:center;gap:var(--sp-3);padding:var(--sp-3) 0;border-bottom:1rpx solid var(--line)}
|
||||
.pet-row:last-child{border-bottom:0}
|
||||
.pet-emoji{
|
||||
width:76rpx;height:76rpx;border-radius:var(--r-sm);flex:none;
|
||||
display:flex;align-items:center;justify-content:center;
|
||||
background:var(--primary-soft);font-size:40rpx;
|
||||
}
|
||||
.pet-info{flex:1;min-width:0}
|
||||
Reference in New Issue
Block a user