You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.4 KiB

3 years ago
// index.js
3 years ago
const app = getApp()
3 years ago
Page({
data: {
3 years ago
imageUrl: getApp().globalData.imageUrl,
3 years ago
bgImage: "background-image: url(" + getApp().globalData.imageUrl + "/img_mybg.png)",
statusBarHeight: 0,
3 years ago
nickName: "未登录",
3 years ago
avatarUrl: "",
3 years ago
btnShow: false,
userName: '',
headImg: '',
fileList: []
3 years ago
},
3 years ago
onLoad: function () {
3 years ago
wx.getSystemInfo({
3 years ago
success: (res) => {
let statusBarHeight = res.statusBarHeight
this.setData({
statusBarHeight: statusBarHeight
})
}
3 years ago
})
3 years ago
},
onShow() {
this.getTabBar().init();
3 years ago
this.getUser();
3 years ago
},
3 years ago
// 上传头像的验证
beforeRead(event) {
3 years ago
const {
file,
callback
} = event.detail;
3 years ago
callback(file.type === 'image');
},
// 上传图片
afterRead(event) {
3 years ago
const {
file
} = event.detail;
3 years ago
let url = file.url;
let base64 = wx.getFileSystemManager().readFileSync(url, "base64");
let unionID = wx.getStorageSync('unionID');
3 years ago
if (!unionID) {
3 years ago
return false;
}
let obj = {
action: 'updImg',
unionID: unionID,
base64: base64,
token: wx.getStorageSync('token') || 't%2BrswgjvzGM='
}
app.globalData.request(obj).then(res => {
let userInfo = wx.getStorageSync("userInfo");
userInfo.headImg = res;
wx.setStorageSync('userInfo', userInfo);
this.setData({
headImg: res
})
})
},
3 years ago
getUser() {
3 years ago
if (wx.getStorageSync("userInfo")) {
3 years ago
let userInfo = wx.getStorageSync("userInfo");
this.setData({
nickName: userInfo.nickName,
avatarUrl: userInfo.avatarUrl,
3 years ago
userName: userInfo.UserName,
headImg: userInfo.headImg,
3 years ago
btnShow: true
})
3 years ago
} else {
this.setData({
nickName: '',
avatarUrl: '',
3 years ago
btnShow: false,
headImg: '',
userName: ''
3 years ago
})
3 years ago
}
3 years ago
},
layout() {
let that = this;
3 years ago
let obj = {
action: 'LogOut',
openid: wx.getStorageSync('openid'),
token: wx.getStorageSync('token') || 't%2BrswgjvzGM='
}
3 years ago
return new Promise((resolve, reject) => {
app.globalData.request(obj, (res) => {
if (res.Code == 1) {
wx.showModal({
title: '提示',
content: "确定要退出嘛?",
success(res) {
if (res.confirm) {
wx.setStorageSync("userInfo", null);
wx.setStorageSync("token", "");
wx.setStorageSync("openid", "");
that.getUser();
}
3 years ago
}
3 years ago
})
}
resolve(true)
}).catch(err => {
3 years ago
wx.showModal({
title: '提示',
content: err.Msg,
})
3 years ago
reject(false)
})
})
3 years ago
}
});