完成Salon小程序合规整改
This commit is contained in:
@@ -12,10 +12,51 @@ Page({
|
||||
codeLoading: false,
|
||||
countdown: 0,
|
||||
timer: null,
|
||||
smsExpanded: false
|
||||
smsExpanded: false,
|
||||
unbindMode: false,
|
||||
closureRequest: null
|
||||
},
|
||||
|
||||
onShow() { this.loadProfile() },
|
||||
onShow() { this.loadProfile(); this.loadClosureRequest() },
|
||||
|
||||
async loadClosureRequest() {
|
||||
try {
|
||||
const closureRequest = await userApi.getAccountClosure()
|
||||
this.setData({ closureRequest: closureRequest || null })
|
||||
} catch (error) {
|
||||
this.setData({ closureRequest: null })
|
||||
}
|
||||
},
|
||||
|
||||
async requestClosure() {
|
||||
const confirmed = await new Promise(resolve => wx.showModal({
|
||||
title: '申请注销账号',
|
||||
content: '申请提交后由管理人员处理。完成后会清理账号身份资料,必要业务记录仍按保存要求保留。你可以在处理前撤回。',
|
||||
confirmText: '提交申请',
|
||||
success: result => resolve(result.confirm),
|
||||
fail: () => resolve(false)
|
||||
}))
|
||||
if (!confirmed) return
|
||||
try {
|
||||
const closureRequest = await userApi.requestAccountClosure()
|
||||
this.setData({ closureRequest })
|
||||
wx.showToast({ title: '注销申请已提交' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '申请提交失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
async withdrawClosure() {
|
||||
const confirmed = await new Promise(resolve => wx.showModal({ title: '撤回注销申请', content: '确定撤回账号注销申请吗?', success: result => resolve(result.confirm), fail: () => resolve(false) }))
|
||||
if (!confirmed) return
|
||||
try {
|
||||
await userApi.withdrawAccountClosure()
|
||||
await this.loadClosureRequest()
|
||||
wx.showToast({ title: '申请已撤回' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '撤回失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
async loadProfile(options = {}) {
|
||||
this.setData({ loading: true })
|
||||
@@ -39,7 +80,11 @@ Page({
|
||||
},
|
||||
|
||||
toggleSms() {
|
||||
this.setData({ smsExpanded: !this.data.smsExpanded })
|
||||
this.setData({ smsExpanded: !this.data.smsExpanded, unbindMode: false })
|
||||
},
|
||||
|
||||
beginUnbind() {
|
||||
this.setData({ smsExpanded: true, unbindMode: true, 'smsForm.code': '' })
|
||||
},
|
||||
|
||||
async bindWechatPhone(event) {
|
||||
@@ -62,13 +107,14 @@ Page({
|
||||
|
||||
async sendCode() {
|
||||
const phone = String(this.data.smsForm.phone || '')
|
||||
if (!/^1[3-9]\d{9}$/.test(phone)) {
|
||||
if (!this.data.unbindMode && !/^1[3-9]\d{9}$/.test(phone)) {
|
||||
wx.showToast({ title: '请输入正确手机号', icon: 'none' }); return
|
||||
}
|
||||
if (this.data.codeLoading || this.data.countdown) return
|
||||
this.setData({ codeLoading: true })
|
||||
try {
|
||||
await userApi.sendBindPhoneCode(phone)
|
||||
if (this.data.unbindMode) await userApi.sendUnbindPhoneCode()
|
||||
else await userApi.sendBindPhoneCode(phone)
|
||||
this.startCountdown()
|
||||
wx.showToast({ title: '验证码已发送' })
|
||||
} catch (error) {
|
||||
@@ -107,6 +153,33 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async unbindSmsPhone() {
|
||||
const code = String(this.data.smsForm.code || '')
|
||||
if (!/^\d{6}$/.test(code)) {
|
||||
wx.showToast({ title: '请输入当前手机号收到的6位验证码', icon: 'none' }); return
|
||||
}
|
||||
const confirmed = await new Promise(resolve => wx.showModal({
|
||||
title: '解绑手机号',
|
||||
content: '解绑后手机号将从账号资料中删除,短信验证码仅用于验证当前手机号。确定继续吗?',
|
||||
confirmText: '确认解绑',
|
||||
success: result => resolve(result.confirm),
|
||||
fail: () => resolve(false)
|
||||
}))
|
||||
if (!confirmed) return
|
||||
this.setData({ binding: true })
|
||||
try {
|
||||
await userApi.unbindPhone(code)
|
||||
profileCache.invalidate()
|
||||
this.setData({ unbindMode: false, smsExpanded: false, 'smsForm.code': '' })
|
||||
await this.loadProfile({ force: true })
|
||||
wx.showToast({ title: '手机号已解绑' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '解绑失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ binding: false })
|
||||
}
|
||||
},
|
||||
|
||||
async logout() {
|
||||
const confirmed = await new Promise(resolve => wx.showModal({ title: '退出登录', content: '退出后将关闭自动登录,并清除本机提醒设置。', success: result => resolve(result.confirm), fail: () => resolve(false) }))
|
||||
if (!confirmed) return
|
||||
|
||||
Reference in New Issue
Block a user