|
@@ -49,17 +49,22 @@ Page({
|
|
|
async toAvatarUrl(e) {
|
|
|
const that = this;
|
|
|
const { avatarUrl } = e.detail
|
|
|
- let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
|
|
|
- res = JSON.parse(res);
|
|
|
- if (res.errcode == '0') {
|
|
|
- let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
|
|
|
- let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
|
|
|
- if (arr.errcode == '0') {
|
|
|
- wx.showToast({ title: `头像上传成功`, icon: 'success' });
|
|
|
- that.search()
|
|
|
- } else {
|
|
|
- wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
|
|
|
+ if (that.data.user._id) {
|
|
|
+ let res = await app.$apifile('files/ball/users/upload', null, avatarUrl)
|
|
|
+ res = JSON.parse(res);
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ let icon = [{ id: res.id, name: res.name, uri: res.uri, url: `${app.globalData.fileserverUrl}` + res.uri }]
|
|
|
+ let arr = await app.$api(`user/${that.data.user._id}`, 'POST', { icon: icon });
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ wx.setStorage({ key: "token", data: arr.data })// 存用户信息到storage,以便之后判断用户是否登录
|
|
|
+ wx.showToast({ title: `头像上传成功`, icon: 'success' });
|
|
|
+ that.search()
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${arr.errmsg}`, icon: 'error' });
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ wx.navigateTo({ url: '/pagesCommon/login/index' })
|
|
|
}
|
|
|
},
|
|
|
/**
|