- 新增系统设置、壁纸、图标包、设备管理、通讯录、通话、短信、相册、文件、应用、告警、信息、首页布局、账号安全、绑定手机号、法律条款等页面 - utils/api.ts 补齐设备操作、策略、壁纸、图标包等 /api/v1/client/** 接口,新增多文件上传 - 新增 utils/sse.ts 与 utils/wx-session.ts - 「更多/进入」指示统一改为图片箭头,首卡统一 .hero-card 高度,页面首卡贴顶 - AGENTS.md 补充功能对接状态与小程序 UI 约定
112 lines
2.8 KiB
TypeScript
112 lines
2.8 KiB
TypeScript
import type { AuthToken } from '../../utils/api'
|
|
import {
|
|
changePassword,
|
|
changePasswordBySmsCode,
|
|
sendPasswordSmsCode
|
|
} from '../../utils/api'
|
|
import { saveAuthToken } from '../../utils/auth'
|
|
|
|
type Mode = 'password' | 'sms'
|
|
|
|
let countdownTimer = 0
|
|
|
|
Page({
|
|
data: {
|
|
mode: 'password' as Mode,
|
|
oldPassword: '',
|
|
newPassword: '',
|
|
confirmPassword: '',
|
|
code: '',
|
|
countdown: 0,
|
|
submitting: false
|
|
},
|
|
|
|
onUnload() {
|
|
if (countdownTimer) {
|
|
clearInterval(countdownTimer)
|
|
countdownTimer = 0
|
|
}
|
|
},
|
|
|
|
onSwitchMode(e: WechatMiniprogram.TouchEvent) {
|
|
const { mode } = e.currentTarget.dataset as { mode: Mode }
|
|
this.setData({ mode })
|
|
},
|
|
|
|
onInput(e: WechatMiniprogram.Input) {
|
|
const { field } = e.currentTarget.dataset as { field: string }
|
|
this.setData({ [field]: e.detail.value })
|
|
},
|
|
|
|
async onSendCode() {
|
|
if (this.data.countdown > 0) return
|
|
try {
|
|
await sendPasswordSmsCode()
|
|
this.toast('验证码已发送到当前手机号')
|
|
if (countdownTimer) clearInterval(countdownTimer)
|
|
this.setData({ countdown: 60 })
|
|
countdownTimer = setInterval(() => {
|
|
const next = this.data.countdown - 1
|
|
if (next <= 0) {
|
|
clearInterval(countdownTimer)
|
|
countdownTimer = 0
|
|
this.setData({ countdown: 0 })
|
|
return
|
|
}
|
|
this.setData({ countdown: next })
|
|
}, 1000) as unknown as number
|
|
} catch (err) {
|
|
this.toast((err as Error).message || '验证码发送失败')
|
|
}
|
|
},
|
|
|
|
async onSubmit() {
|
|
const newPassword = this.data.newPassword
|
|
const confirmPassword = this.data.confirmPassword
|
|
if (newPassword.length < 6) {
|
|
this.toast('新密码至少 6 位')
|
|
return
|
|
}
|
|
if (newPassword !== confirmPassword) {
|
|
this.toast('两次输入的新密码不一致')
|
|
return
|
|
}
|
|
if (this.data.submitting) return
|
|
|
|
this.setData({ submitting: true })
|
|
wx.showLoading({ title: '提交中' })
|
|
try {
|
|
const token =
|
|
this.data.mode === 'password'
|
|
? await changePassword(
|
|
this.data.oldPassword,
|
|
newPassword,
|
|
confirmPassword
|
|
)
|
|
: await changePasswordBySmsCode(
|
|
this.data.code.trim(),
|
|
newPassword,
|
|
confirmPassword
|
|
)
|
|
saveAuthToken(token as AuthToken)
|
|
this.setData({
|
|
oldPassword: '',
|
|
newPassword: '',
|
|
confirmPassword: '',
|
|
code: ''
|
|
})
|
|
this.toast('密码已修改,请重新登录')
|
|
setTimeout(() => wx.reLaunch({ url: '/pages/login/index' }), 800)
|
|
} catch (err) {
|
|
this.toast((err as Error).message || '修改失败')
|
|
} finally {
|
|
wx.hideLoading()
|
|
this.setData({ submitting: false })
|
|
}
|
|
},
|
|
|
|
toast(title: string) {
|
|
wx.showToast({ title, icon: 'none', duration: 1800 })
|
|
}
|
|
})
|