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.

165 lines
4.8 KiB

3 years ago
// index.js
3 years ago
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
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: '',
3 years ago
fileList: [],
token: '',
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() {
3 years ago
this.setData({token: wx.getStorageSync('token')})
3 years ago
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'),
3 years ago
token: wx.getStorageSync('token')
3 years ago
}
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", "");
3 years ago
wx.setStorageSync("authority", []);
that.setData({token: ''});
3 years ago
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
},
toProfile() {
if(wx.getStorageSync('token')) {
wx.navigateTo({
url: '/pages/mine/pages/profile/profile'
})
} else {
Dialog.alert({
selector:'#myDialog',
title: '未登录',
message: '您尚未登录,请前往登录',
});
}
},
toRegister() {
wx.navigateTo({
url: '/pages/mine/pages/register/register',
})
},
toReport() {
if(wx.getStorageSync('token')) {
wx.navigateTo({
url: '/pages/mine/pages/myReport/index'
})
} else {
Dialog.alert({
selector:'#myDialog',
title: '未登录',
message: '您尚未登录,请前往登录',
});
}
},
toSetting() {
if(wx.getStorageSync('token')) {
wx.navigateTo({
url: '/subPackages/pages/logs/PushSettings/index'
})
} else {
Dialog.alert({
selector:'#myDialog',
title: '未登录',
message: '您尚未登录,请前往登录',
});
}
3 years ago
}
});