import { apiRequest } from '../../services/api-request'; import { disablePageShareMenu } from '../../base/pageMixin'; import { clearUser, refreshUser } from '../../utils/auth'; Page({ onLoad() { disablePageShareMenu(); }, onClearProfile() { wx.showModal({ title: '确认删除', content: '删除后头像和昵称将恢复为默认状态,是否继续?', confirmColor: '#e53e3e', success: (res) => { if (res.confirm) { this.doClearProfile(); } }, }); }, async doClearProfile() { wx.showLoading({ title: '处理中...', mask: true }); try { await apiRequest('/me/profile', { method: 'DELETE' }); await refreshUser(); wx.hideLoading(); wx.showToast({ title: '已删除', icon: 'success' }); } catch (e) { wx.hideLoading(); console.error('clearProfile failed', e); wx.showToast({ title: '操作失败,请稍后重试', icon: 'none' }); } }, onDeleteAccount() { wx.showModal({ title: '注销账户', content: '注销后您的所有数据(包括收藏、下载记录等)将被永久删除且无法恢复,确认要注销吗?', confirmText: '确认注销', confirmColor: '#e53e3e', success: (res) => { if (res.confirm) { this.doDeleteAccount(); } }, }); }, async doDeleteAccount() { wx.showLoading({ title: '处理中...', mask: true }); try { await apiRequest('/me', { method: 'DELETE' }); clearUser(true); wx.hideLoading(); wx.reLaunch({ url: '/pages/home/home' }); } catch (e) { wx.hideLoading(); console.error('deleteAccount failed', e); wx.showToast({ title: '操作失败,请稍后重试', icon: 'none' }); } }, });