feat(auth): access token 缩到 2 小时 + refresh token 机制 #3

Merged
Blizzard merged 58 commits from feat/dev into main 2026-07-30 10:18:07 +00:00
18 changed files with 242 additions and 78 deletions
Showing only changes of commit 60baff8a2b - Show all commits
+6 -5
View File
@@ -8,7 +8,8 @@
"pages/community/community",
"pages/learn/learn",
"pages/article/article",
"pages/profile/profile",
"pages/mine/mine",
"pages/settings/settings",
"pages/ai/ai",
"pages/user/user",
"pages/relations/relations"
@@ -28,10 +29,6 @@
"pagePath": "pages/home/home",
"text": "首页"
},
{
"pagePath": "pages/plan/plan",
"text": "计划"
},
{
"pagePath": "pages/record/record",
"text": "记录"
@@ -43,6 +40,10 @@
{
"pagePath": "pages/community/community",
"text": "社区"
},
{
"pagePath": "pages/mine/mine",
"text": "我的"
}
]
},
+30 -13
View File
@@ -1,20 +1,37 @@
Component({
data: {
selected: 0,
hidden: false,
list: [
const LIST = [
{ pagePath: '/pages/home/home', text: '首页', icon: 'home' },
{ pagePath: '/pages/plan/plan', text: '计划', icon: 'plan' },
{ pagePath: '/pages/record/record', text: '记录', icon: 'record' },
{ pagePath: '/pages/report/report', text: '报告', icon: 'report' },
{ pagePath: '/pages/community/community', text: '社区', icon: 'community' }
]
{ pagePath: '/pages/community/community', text: '社区', icon: 'community' },
{ pagePath: '/pages/mine/mine', text: '我的', icon: 'user' },
];
Component({
data: { selected: 0, hidden: false, list: LIST },
// 高亮由当前页面路径自己算出来。
// 原来每个 tab 页在 onShow 里硬写 selected: 0/1/2/3/4,调一次顺序就要同时改
// 五个文件,漏一个就高亮错位——这次把计划换成我的正好会踩到。
pageLifetimes: {
show() {
this.syncSelected();
},
},
lifetimes: {
attached() {
this.syncSelected();
},
},
methods: {
syncSelected() {
const pages = getCurrentPages();
const cur = pages[pages.length - 1];
if (!cur) return;
const path = '/' + cur.route;
const i = LIST.findIndex((t) => t.pagePath === path);
if (i >= 0 && i !== this.data.selected) this.setData({ selected: i });
},
switchTab(e) {
const idx = e.currentTarget.dataset.index;
const path = this.data.list[idx].pagePath;
wx.switchTab({ url: path });
}
}
wx.switchTab({ url: LIST[e.currentTarget.dataset.index].pagePath });
},
},
});
-3
View File
@@ -61,9 +61,6 @@ Page({
if (this._unsub) this._unsub();
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 4 });
}
store
.ready()
.then(() => {
+2 -5
View File
@@ -72,9 +72,6 @@ Page({
if (this._unsub) this._unsub();
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 0 });
}
store
.ready()
.then(() => {
@@ -196,8 +193,8 @@ Page({
onFab() {
wx.navigateTo({ url: '/pages/ai/ai' });
},
goProfile() {
wx.navigateTo({ url: '/pages/profile/profile' });
goSettings() {
wx.navigateTo({ url: '/pages/settings/settings' });
},
goLearn() {
wx.navigateTo({ url: '/pages/learn/learn' });
+1 -1
View File
@@ -11,7 +11,7 @@
</view>
<view class="icon-stack">
<view class="icon-btn" data-type="reminders" bindtap="openSheet"><pt-icon name="bell" size="{{36}}"></pt-icon></view>
<view class="icon-btn" bindtap="goProfile"><pt-icon name="settings" size="{{36}}"></pt-icon></view>
<view class="icon-btn" bindtap="goSettings"><pt-icon name="settings" size="{{36}}"></pt-icon></view>
</view>
</view>
+71
View File
@@ -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' };
},
});
+77
View File
@@ -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>
+25
View File
@@ -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}
-3
View File
@@ -61,9 +61,6 @@ Page({
if (this._unsub) this._unsub();
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 1 });
}
store
.ready()
.then(() => {
+1 -1
View File
@@ -1,4 +1,4 @@
<nav-bar title="养宠计划"></nav-bar>
<nav-bar title="养宠计划" show-back="{{true}}"></nav-bar>
<view class="top-bar"><pet-switch bind:add="onAddPet"></pet-switch></view>
-39
View File
@@ -1,39 +0,0 @@
<nav-bar title="我的" show-back="{{true}}"></nav-bar>
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
<view class="page-body">
<view class="profile-header">
<view class="avatar ph-avatar" bindtap="onPickAvatar">
<image wx:if="{{user.avatar_url}}" class="ph-avatar-img" src="{{user.avatar_url}}" mode="aspectFill"></image>
<block wx:else>{{pet.emoji}}</block>
<view class="ph-avatar-cam"><pt-icon name="photo" size="{{28}}"></pt-icon></view>
</view>
<view class="ph-name">{{pet.name}}</view>
<view class="muted ph-meta">{{pet.age}}{{pet.weight}}{{pet.stage}}</view>
<view wx:if="{{pet.breed || pet.color}}" class="muted ph-meta">{{pet.breed}}{{pet.breed && pet.color ? ' · ' : ''}}{{pet.color}}</view>
</view>
<button class="btn btn-ghost btn-block" style="margin-bottom:28rpx" bindtap="onAddPet"><pt-icon name="plus" size="{{30}}"></pt-icon>添加毛孩子</button>
<view class="profile-list">
<view class="profile-row" bindtap="onEditPet"><view class="pr-ic"><pt-icon name="user" size="{{34}}"></pt-icon></view><text class="pr-label">宠物档案(编辑)</text><text class="pr-val">已完善 {{profilePct}}%</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-type="reminders" bindtap="openSheet"><view class="pr-ic"><pt-icon name="bell" size="{{34}}"></pt-icon></view><text class="pr-label">提醒设置</text><text class="pr-val">{{summary.reminders}} 条</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" bindtap="goRecord"><view class="pr-ic"><pt-icon name="note" size="{{34}}"></pt-icon></view><text class="pr-label">健康记录</text><text class="pr-val">{{summary.records}} 条</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}} 只</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-kind="following" bindtap="goRelations"><view class="pr-ic"><pt-icon name="community" size="{{34}}"></pt-icon></view><text class="pr-label">我的关注</text><text class="pr-val">{{summary.following || 0}} 人</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-kind="followers" bindtap="goRelations"><view class="pr-ic"><pt-icon name="user" size="{{34}}"></pt-icon></view><text class="pr-label">我的粉丝</text><text class="pr-val">{{summary.followers || 0}} 人</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
</view>
<view class="profile-list">
<view class="profile-row" data-type="pro" bindtap="openSheet"><view class="pr-ic"><pt-icon name="like" size="{{34}}"></pt-icon></view><text class="pr-label">会员权益</text><text class="pr-val">{{summary.pro_status === 'active' ? '已开通' : '未开通'}}</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-type="exportData" bindtap="openSheet"><view class="pr-ic"><pt-icon name="doc" size="{{34}}"></pt-icon></view><text class="pr-label">数据导出</text><text class="pr-val">文本</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-type="feedback" bindtap="openSheet"><view class="pr-ic"><pt-icon name="comment" size="{{34}}"></pt-icon></view><text class="pr-label">意见反馈</text><text class="pr-val">去填写</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-type="about" bindtap="openSheet"><view class="pr-ic"><pt-icon name="book" size="{{34}}"></pt-icon></view><text class="pr-label">关于我们</text><text class="pr-val">v0.2</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
</view>
<button class="btn btn-ghost btn-block" data-type="pro" bindtap="openSheet">Pro 会员(即将开放)</button>
</view>
</scroll-view>
<fab bind:tap="onFab"></fab>
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" bind:close="closeSheet"></bottom-sheet>
-3
View File
@@ -131,9 +131,6 @@ Page({
if (this._unsub) this._unsub();
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 2 });
}
store
.ready()
.then(() => {
-3
View File
@@ -22,9 +22,6 @@ Page({
if (this._unsub) this._unsub();
},
onShow() {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({ selected: 3 });
}
store
.ready()
.then(() => {
+8
View File
@@ -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"
}
}
+19
View File
@@ -0,0 +1,19 @@
<nav-bar title="设置" show-back="{{true}}"></nav-bar>
<scroll-view class="page-scroll" scroll-y="{{true}}" enhanced="{{true}}" show-scrollbar="{{false}}">
<view class="page-body no-fab">
<view class="profile-list">
<view class="profile-row" data-type="reminders" bindtap="openSheet"><view class="pr-ic"><pt-icon name="bell" size="{{34}}"></pt-icon></view><text class="pr-label">提醒设置</text><text class="pr-val">{{summary.reminders}} 条</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
</view>
<view class="profile-list">
<view class="profile-row" data-type="pro" bindtap="openSheet"><view class="pr-ic"><pt-icon name="like" size="{{34}}"></pt-icon></view><text class="pr-label">会员权益</text><text class="pr-val">{{summary.pro_status === 'active' ? '已开通' : '未开通'}}</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-type="exportData" bindtap="openSheet"><view class="pr-ic"><pt-icon name="doc" size="{{34}}"></pt-icon></view><text class="pr-label">数据导出</text><text class="pr-val">文本</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-type="feedback" bindtap="openSheet"><view class="pr-ic"><pt-icon name="comment" size="{{34}}"></pt-icon></view><text class="pr-label">意见反馈</text><text class="pr-val">去填写</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
<view class="profile-row" data-type="about" bindtap="openSheet"><view class="pr-ic"><pt-icon name="book" size="{{34}}"></pt-icon></view><text class="pr-label">关于我们</text><text class="pr-val">v0.2</text><view class="pr-arrow"><pt-icon name="next" size="{{28}}"></pt-icon></view></view>
</view>
</view>
</scroll-view>
<bottom-sheet show="{{sheetShow}}" type="{{sheetType}}" bind:close="closeSheet"></bottom-sheet>