const app = getApp() Page({ data: { popupShow: false, popupType: 'stayTuned', popupParams: {}, }, onLoad() { app.waitLogin().then(() => { app.getUserInfo().then((userInfo) => { this.setData({ userInfo, }) }) }) }, onChooseAvatar(e) { const { avatarUrl } = e.detail const url = `${app.globalData.upFileUrl}?r=file-service/upload-img` wx.showLoading({ title: '上传中', }) wx.uploadFile({ url, filePath: avatarUrl, name: 'file', success: (res) => { const data = JSON.parse(res.data) const avatarUrl = data.data.Url wx.ajax({ method: 'POST', url: '?r=wtx/user/update-avatar', data: { Avatar: avatarUrl, }, }) .then(() => { wx.hideLoading() wx.showToast({ title: '头像更新成功!', icon: 'none', }) this.setData({ 'userInfo.Avatar': avatarUrl, }) }) .catch(() => { wx.hideLoading() }) }, fail() { wx.hideLoading() }, }) }, handlePopupCancel() { this.setData({ popupShow: false, }) }, routerTo(e) { const { url } = e.currentTarget.dataset wx.navigateTo({ url, }) }, handleNone() { this.setData({ popupShow: true, popupType: 'stayTuned', }) }, }) export {}