1
This commit is contained in:
61
miniprogram/pages/profile/index.js
Normal file
61
miniprogram/pages/profile/index.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const { request } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
form: {
|
||||
nickname: '',
|
||||
company: '',
|
||||
title: '',
|
||||
phone: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadProfile()
|
||||
},
|
||||
|
||||
async loadProfile() {
|
||||
const profile = await request({ url: '/user/profile' })
|
||||
this.setData({
|
||||
form: {
|
||||
nickname: profile.nickname || '',
|
||||
company: profile.company || '',
|
||||
title: profile.title || '',
|
||||
phone: profile.phone || '',
|
||||
password: ''
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
const field = e.currentTarget.dataset.field
|
||||
this.setData({ [`form.${field}`]: (e.detail.value || '').trim() })
|
||||
},
|
||||
|
||||
async save() {
|
||||
if (this.data.loading) return
|
||||
this.setData({ loading: true })
|
||||
|
||||
const payload = { ...this.data.form }
|
||||
if (!payload.password) {
|
||||
delete payload.password
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await request({
|
||||
url: '/user/profile',
|
||||
method: 'PUT',
|
||||
data: payload
|
||||
})
|
||||
const app = getApp()
|
||||
app.globalData.user = user
|
||||
wx.setStorageSync('user', user)
|
||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||
this.setData({ 'form.password': '' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user