Initial commit
This commit is contained in:
46
miniprogram/pages/edit-profile/edit-profile.ts
Normal file
46
miniprogram/pages/edit-profile/edit-profile.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
const app = getApp<{ userInfo: any }>()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 0,
|
||||
form: { nickName: '', bio: '', location: '' },
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const info = wx.getSystemInfoSync()
|
||||
this.setData({ statusBarHeight: info.statusBarHeight })
|
||||
const user = app.globalData?.userInfo
|
||||
if (user) {
|
||||
this.setData({
|
||||
form: { nickName: user.nickName || '', bio: user.bio || '', location: user.location || '' },
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
onField(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ [`form.${e.currentTarget.dataset.key}`]: e.detail.value })
|
||||
},
|
||||
|
||||
async onSave() {
|
||||
const { form } = this.data
|
||||
if (!form.nickName.trim()) {
|
||||
wx.showToast({ title: '昵称不能为空', icon: 'none' })
|
||||
return
|
||||
}
|
||||
wx.showLoading({ title: '保存中...' })
|
||||
try {
|
||||
await wx.cloud.callFunction({ name: 'updateProfile', data: form })
|
||||
if (app.globalData.userInfo) {
|
||||
Object.assign(app.globalData.userInfo, form)
|
||||
}
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||
setTimeout(() => wx.navigateBack(), 800)
|
||||
} catch {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
|
||||
onBack() { wx.navigateBack() },
|
||||
})
|
||||
Reference in New Issue
Block a user