import { clearUser } from '../../utils/auth'; Page({ onClearProfile() { wx.showModal({ title: '确认删除', content: '删除后头像和昵称将恢复为默认状态,是否继续?', confirmColor: '#e53e3e', success: (res) => { if (res.confirm) { this.doClearProfile(); } }, }); }, async doClearProfile() { wx.showLoading({ title: '处理中...', mask: true }); try { const res = await wx.cloud.callFunction({ name: 'userSettings', data: { action: 'clearProfile' }, }); const result = (res?.result as any) || {}; if (result.code !== 0) { throw new Error(result.message || '操作失败'); } clearUser(); 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 { const res = await wx.cloud.callFunction({ name: 'userSettings', data: { action: 'deleteAccount' }, }); const result = (res?.result as any) || {}; if (result.code !== 0) { throw new Error(result.message || '操作失败'); } clearUser(); wx.hideLoading(); wx.reLaunch({ url: '/pages/home/home' }); } catch (e) { wx.hideLoading(); console.error('deleteAccount failed', e); wx.showToast({ title: '操作失败,请稍后重试', icon: 'none' }); } }, });