04a99df434
settings 隐私政策入口改调 wx.openPrivacyContract;旧基础库或未配置时兜底 回内置 agreement 页。用户协议仍走内置页面。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
96 lines
3.1 KiB
JavaScript
96 lines
3.1 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' });
|
|
}
|
|
},
|
|
// 自己的关注/粉丝。之前只有帖子上的「+关注」按钮,关注完没有任何地方能看
|
|
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}` });
|
|
},
|
|
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' };
|
|
},
|
|
});
|