f417962453
- 删除页面:community(社区)、comments(评论)、user(他人主页)、relations(关注/粉丝) - app.json 去掉四个页面注册与社区 tab;tabBar 只剩 首页/报告/我的 - bottom-sheet 移除发帖(createPost)与评论(comments)整块 UI 及对应 JS/数据/常量 - profile-head 移除帖子/关注/粉丝社交数与关注按钮 - mine 去掉「我的帖子」「别人眼里的我」及关注/粉丝跳转 - api.js 移除 posts/comments/follow/relations 等社区接口(保留 userCard 供我的页头部) 说明:后端社区接口未动(微信审核只看小程序包,前端已无任何引用); 完整社区代码保留在 feat/dev 分支与 git 历史。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
90 lines
2.8 KiB
JavaScript
90 lines
2.8 KiB
JavaScript
const store = require('../../utils/store.js');
|
|
const api = require('../../utils/api.js');
|
|
const upload = require('../../utils/upload.js');
|
|
|
|
function completion(pet) {
|
|
if (!pet) return 0;
|
|
const fields = ['name', 'emoji', 'type', 'gender', 'birthday', 'weight', 'stage', 'age', 'color', 'breed'];
|
|
const filled = fields.filter((f) => pet[f]).length;
|
|
return Math.round((filled / fields.length) * 100);
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
pet: {},
|
|
user: {},
|
|
summary: { pets: 0, records: 0, reminders: 0, pro_status: 'none' },
|
|
profilePct: 0,
|
|
sheetShow: false,
|
|
sheetType: '',
|
|
},
|
|
onLoad() {
|
|
this._unsub = store.subscribe((pet) => this.setData({ pet, profilePct: completion(pet) }));
|
|
},
|
|
onUnload() {
|
|
if (this._unsub) this._unsub();
|
|
},
|
|
onShow() {
|
|
store
|
|
.ready()
|
|
.then(() => {
|
|
const pet = store.getPet();
|
|
this.setData({ pet, user: store.getUser() || {}, profilePct: completion(pet) });
|
|
this.loadSummary();
|
|
})
|
|
.catch((e) => wx.showToast({ title: e.message || '加载失败', icon: 'none' }));
|
|
},
|
|
loadSummary() {
|
|
api.userSummary().then((summary) => this.setData({ summary })).catch(() => {});
|
|
},
|
|
openSheet(e) {
|
|
this.setData({ sheetType: e.currentTarget.dataset.type, sheetShow: true });
|
|
},
|
|
// 用户协议:走我们自己的页面
|
|
goAgreement(e) {
|
|
wx.navigateTo({ url: '/pages/agreement/agreement?type=' + e.currentTarget.dataset.type });
|
|
},
|
|
// 隐私政策:直接打开微信公众平台后台配置的《用户隐私保护指引》。
|
|
// 旧基础库没有该接口时,兜底用内置页面
|
|
openPrivacy() {
|
|
if (wx.openPrivacyContract) {
|
|
wx.openPrivacyContract({
|
|
fail: () => wx.navigateTo({ url: '/pages/agreement/agreement?type=privacy' }),
|
|
});
|
|
} else {
|
|
wx.navigateTo({ url: '/pages/agreement/agreement?type=privacy' });
|
|
}
|
|
},
|
|
goRecord() {
|
|
wx.navigateTo({ url: '/pages/record/record' });
|
|
},
|
|
onPickAvatar() {
|
|
upload
|
|
.chooseAndUploadImage()
|
|
.then((f) => api.updateProfile({ avatar_file_id: f.id }))
|
|
.then((user) => {
|
|
this.setData({ user });
|
|
store.setUser(user);
|
|
wx.showToast({ title: '头像已更新', icon: 'success' });
|
|
})
|
|
.catch((e) => {
|
|
if (e && e.canceled) return;
|
|
wx.showToast({ title: (e && e.message) || '上传失败', icon: 'none' });
|
|
});
|
|
},
|
|
onAddPet() {
|
|
wx.navigateTo({ url: '/pages/petform/petform' });
|
|
},
|
|
onEditPet() {
|
|
const id = store.currentPetId();
|
|
wx.navigateTo({ url: '/pages/petform/petform' + (id ? '?id=' + id : '') });
|
|
},
|
|
closeSheet() {
|
|
this.setData({ sheetShow: false });
|
|
this.loadSummary();
|
|
},
|
|
onShareAppMessage() {
|
|
return { title: '肉垫计划 · 新手养宠助手', path: '/pages/home/home' };
|
|
},
|
|
});
|