chore: establish V1.1 recovery baseline
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 注销账号页
|
||||
* 在线便捷渠道,不设置障碍
|
||||
*/
|
||||
const api = require('../../utils/api');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
canWithdraw: false,
|
||||
blockers: [],
|
||||
reason: '',
|
||||
submitting: false,
|
||||
submitted: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.checkCanWithdraw();
|
||||
},
|
||||
|
||||
onReasonInput(e) {
|
||||
this.setData({ reason: e.detail.value });
|
||||
},
|
||||
|
||||
async checkCanWithdraw() {
|
||||
try {
|
||||
const token = wx.getStorageSync('accessToken');
|
||||
const res = await api.get('/account/can-withdraw', {}, { Authorization: `Bearer ${token}` });
|
||||
this.setData({
|
||||
canWithdraw: res.canWithdraw,
|
||||
blockers: Object.values(res.blockers || {})
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
},
|
||||
|
||||
async submitWithdraw() {
|
||||
if (!this.data.canWithdraw) return;
|
||||
this.setData({ submitting: true });
|
||||
try {
|
||||
const token = wx.getStorageSync('accessToken');
|
||||
await api.post('/account/close', { reason: this.data.reason.trim() }, {
|
||||
Authorization: `Bearer ${token}`
|
||||
});
|
||||
this.setData({ submitted: true });
|
||||
wx.setStorageSync('accessToken', '');
|
||||
wx.setStorageSync('userId', '');
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '注销失败', icon: 'none' });
|
||||
this.setData({ submitting: false });
|
||||
}
|
||||
},
|
||||
|
||||
goBack() {
|
||||
if (this.data.submitted) {
|
||||
wx.reLaunch({ url: '/pages/login/login' });
|
||||
} else {
|
||||
wx.navigateBack();
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user