- 建立 Lucide 子集 iconfont(49 字形),全站 emoji 替换为 fc-icon 组件 - 重塑 Design Token(冷中性近黑底 + Volt 荧光绿 #B6F24E),消除硬编码颜色 - 首页登录后个性化:我的计划 / 我的收藏 / 今日推荐(纯前端复用现有 API) - 后端 DEFAULT_EMOJI→Lucide 名,PALETTE 对齐 Kinetic Dark 语义色板 - 修复 person-standing 缺失字形;14 个官方组合 seed emoji 全部映射到现有字形
132 lines
3.5 KiB
JavaScript
132 lines
3.5 KiB
JavaScript
const app = getApp();
|
||
const auth = require('../../utils/auth');
|
||
const favSvc = require('../../services/favorite');
|
||
const planSvc = require('../../services/plan');
|
||
|
||
// UGC 头像图标选择器:Lucide 运动子集(非 emoji)
|
||
const ICONS = ['dumbbell', 'accessibility', 'person-standing', 'bike', 'heart', 'flame',
|
||
'target', 'medal', 'trophy', 'award', 'star', 'activity', 'sparkles', 'zap', 'trending-up'];
|
||
|
||
Page({
|
||
data: {
|
||
statusBarHeight: 20,
|
||
loggedIn: false,
|
||
profile: { nickname: '', avatar: 'user' },
|
||
counts: { fav: 0, plans: 0, favPlans: 0 },
|
||
loading: false,
|
||
// 编辑态
|
||
showEmojiPicker: false,
|
||
emojis: ICONS,
|
||
draftNickname: '',
|
||
draftAvatar: 'user'
|
||
},
|
||
|
||
onLoad() {
|
||
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20 });
|
||
},
|
||
|
||
onShow() {
|
||
this.loadData();
|
||
},
|
||
|
||
loadData() {
|
||
if (!auth.isLogin()) {
|
||
this.setData({ loggedIn: false });
|
||
return;
|
||
}
|
||
const profile = auth.getProfile();
|
||
this.setData({ loggedIn: true, profile, loading: true });
|
||
Promise.all([
|
||
favSvc.listExercises().catch(() => []),
|
||
planSvc.listMine().catch(() => []),
|
||
favSvc.listPlans().catch(() => [])
|
||
]).then(([fav, plans, favPlans]) => {
|
||
this.setData({
|
||
counts: {
|
||
fav: (fav || []).length,
|
||
plans: (plans || []).length,
|
||
favPlans: (favPlans || []).length
|
||
},
|
||
loading: false
|
||
});
|
||
}).catch(() => {
|
||
this.setData({ loading: false });
|
||
});
|
||
},
|
||
|
||
onLogin() {
|
||
auth.login().then(() => {
|
||
this.loadData();
|
||
wx.showToast({ title: '登录成功', icon: 'success' });
|
||
}).catch(() => {});
|
||
},
|
||
|
||
onEdit() {
|
||
const cur = this.data.profile;
|
||
wx.showModal({
|
||
title: '修改昵称',
|
||
editable: true,
|
||
placeholderText: '输入昵称',
|
||
content: cur.nickname || '',
|
||
success: (res) => {
|
||
if (res.confirm) {
|
||
this.setData({
|
||
draftNickname: (res.content || '').trim() || cur.nickname,
|
||
draftAvatar: cur.avatar || 'user',
|
||
showEmojiPicker: true
|
||
});
|
||
}
|
||
}
|
||
});
|
||
},
|
||
|
||
onPickEmoji(e) {
|
||
this.setData({ draftAvatar: e.currentTarget.dataset.emoji });
|
||
},
|
||
|
||
onCancelEdit() {
|
||
this.setData({ showEmojiPicker: false });
|
||
},
|
||
|
||
onConfirmEdit() {
|
||
const nickname = (this.data.draftNickname || '').trim();
|
||
const avatar = this.data.draftAvatar;
|
||
if (!nickname) {
|
||
wx.showToast({ title: '昵称不能为空', icon: 'none' });
|
||
return;
|
||
}
|
||
wx.showLoading({ title: '保存中…', mask: true });
|
||
auth.updateProfile({ nickname, avatar }).then((p) => {
|
||
wx.hideLoading();
|
||
this.setData({ profile: p, showEmojiPicker: false });
|
||
wx.showToast({ title: '已保存', icon: 'success' });
|
||
}).catch(() => {
|
||
wx.hideLoading();
|
||
});
|
||
},
|
||
|
||
onLogout() {
|
||
wx.showModal({
|
||
title: '退出登录',
|
||
content: '确定要退出当前账号吗?',
|
||
success: (res) => {
|
||
if (res.confirm) {
|
||
auth.logout();
|
||
this.setData({
|
||
loggedIn: false,
|
||
profile: { nickname: '', avatar: 'user' },
|
||
counts: { fav: 0, plans: 0, favPlans: 0 }
|
||
});
|
||
}
|
||
}
|
||
});
|
||
},
|
||
|
||
goFav() { wx.navigateTo({ url: '/pages/favorites/favorites' }); },
|
||
goPlans() { wx.navigateTo({ url: '/pages/my-plans/my-plans' }); },
|
||
goFavPlans() { wx.navigateTo({ url: '/pages/plan-favorites/plan-favorites' }); },
|
||
goOfficial() { wx.navigateTo({ url: '/pages/collection/collection' }); },
|
||
|
||
noop() {}
|
||
});
|