61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
/**
|
|
* 隐私设置页 U43
|
|
*/
|
|
const api = require('../../utils/api');
|
|
|
|
Page({
|
|
data: {
|
|
visibleInRecommendations: true,
|
|
allowActivityInvitation: true,
|
|
showLastOnline: false,
|
|
saving: false
|
|
},
|
|
|
|
onLoad() {
|
|
this.loadSettings();
|
|
},
|
|
|
|
async loadSettings() {
|
|
try {
|
|
const token = wx.getStorageSync('accessToken');
|
|
const res = await api.get('/account/privacy-settings', {}, { Authorization: `Bearer ${token}` });
|
|
this.setData({
|
|
visibleInRecommendations: res.visibleInRecommendations !== false,
|
|
allowActivityInvitation: res.allowActivityInvitation !== false,
|
|
showLastOnline: res.showLastOnline === true
|
|
});
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
},
|
|
|
|
onVisibleChange(e) {
|
|
this.setData({ visibleInRecommendations: e.detail.value });
|
|
},
|
|
|
|
onActivityInvitationChange(e) {
|
|
this.setData({ allowActivityInvitation: e.detail.value });
|
|
},
|
|
|
|
onShowLastOnlineChange(e) {
|
|
this.setData({ showLastOnline: e.detail.value });
|
|
},
|
|
|
|
async saveSettings() {
|
|
this.setData({ saving: true });
|
|
try {
|
|
const token = wx.getStorageSync('accessToken');
|
|
await api.put('/account/privacy-settings', {
|
|
visibleInRecommendations: this.data.visibleInRecommendations,
|
|
allowActivityInvitation: this.data.allowActivityInvitation,
|
|
showLastOnline: this.data.showLastOnline
|
|
}, { Authorization: `Bearer ${token}` });
|
|
wx.showToast({ title: '保存成功', icon: 'success' });
|
|
} catch (err) {
|
|
wx.showToast({ title: '保存失败', icon: 'none' });
|
|
} finally {
|
|
this.setData({ saving: false });
|
|
}
|
|
}
|
|
});
|