- 新增系统设置、壁纸、图标包、设备管理、通讯录、通话、短信、相册、文件、应用、告警、信息、首页布局、账号安全、绑定手机号、法律条款等页面 - utils/api.ts 补齐设备操作、策略、壁纸、图标包等 /api/v1/client/** 接口,新增多文件上传 - 新增 utils/sse.ts 与 utils/wx-session.ts - 「更多/进入」指示统一改为图片箭头,首卡统一 .hero-card 高度,页面首卡贴顶 - AGENTS.md 补充功能对接状态与小程序 UI 约定
100 lines
2.6 KiB
TypeScript
100 lines
2.6 KiB
TypeScript
import type { Profile } from '../../utils/api'
|
|
import { updateProfile, uploadProfileAvatar } from '../../utils/api'
|
|
import { getCachedProfile, saveProfile } from '../../utils/token'
|
|
|
|
Page({
|
|
data: {
|
|
nickname: '',
|
|
signature: '',
|
|
avatar: '',
|
|
saving: false
|
|
},
|
|
|
|
onLoad() {
|
|
const cached = getCachedProfile<Profile>()
|
|
if (cached) {
|
|
this.setData({
|
|
nickname: cached.nickname || '',
|
|
signature: cached.signature || '',
|
|
avatar: cached.avatar || ''
|
|
})
|
|
}
|
|
},
|
|
|
|
onNicknameInput(e: WechatMiniprogram.Input) {
|
|
this.setData({ nickname: e.detail.value })
|
|
},
|
|
|
|
onSignatureInput(e: WechatMiniprogram.TextareaInput) {
|
|
this.setData({ signature: e.detail.value })
|
|
},
|
|
|
|
onChooseAvatar() {
|
|
wx.chooseImage({
|
|
count: 1,
|
|
sizeType: ['compressed'],
|
|
sourceType: ['album', 'camera'],
|
|
success: (res) => {
|
|
const filePath = res.tempFilePaths[0]
|
|
if (!filePath) return
|
|
wx.showLoading({ title: '上传头像' })
|
|
void uploadProfileAvatar(filePath)
|
|
.then((profile) => {
|
|
wx.hideLoading()
|
|
saveProfile(profile)
|
|
this.setData({
|
|
avatar: profile.avatar || '',
|
|
nickname: profile.nickname || this.data.nickname,
|
|
signature: profile.signature || this.data.signature
|
|
})
|
|
this.toast('头像已更新')
|
|
})
|
|
.catch((err: Error) => {
|
|
wx.hideLoading()
|
|
this.toast(err.message || '头像上传失败')
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
async onSave() {
|
|
const nickname = this.data.nickname.trim()
|
|
if (!nickname) {
|
|
this.toast('请输入昵称')
|
|
return
|
|
}
|
|
if (nickname.length > 64) {
|
|
this.toast('昵称不能超过 64 个字符')
|
|
return
|
|
}
|
|
if (this.data.signature.length > 200) {
|
|
this.toast('个性签名不能超过 200 个字符')
|
|
return
|
|
}
|
|
if (this.data.saving) return
|
|
|
|
this.setData({ saving: true })
|
|
wx.showLoading({ title: '保存中' })
|
|
try {
|
|
const profile = await updateProfile(nickname, this.data.signature.trim())
|
|
saveProfile(profile)
|
|
this.setData({
|
|
nickname: profile.nickname || nickname,
|
|
signature: profile.signature || '',
|
|
avatar: profile.avatar || this.data.avatar
|
|
})
|
|
this.toast('资料已保存')
|
|
setTimeout(() => wx.navigateBack(), 800)
|
|
} catch (err) {
|
|
this.toast((err as Error).message || '资料保存失败')
|
|
} finally {
|
|
wx.hideLoading()
|
|
this.setData({ saving: false })
|
|
}
|
|
},
|
|
|
|
toast(title: string) {
|
|
wx.showToast({ title, icon: 'none', duration: 1800 })
|
|
}
|
|
})
|