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.

130 lines
3.3 KiB

5 years ago
const app = getApp();
Page({
data: {
version: global.config.version,
imgDir: global.config.imgDir,
eduImgDir: global.config.eduImgDir,
user: {},
show_join_course_modal: false,
auto_attendance:false
},
update() {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
if (!res.hasUpdate) {
wx.showToast({
title: '你用的是最新版本哦', icon: "none"
})
}
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: "(●'◡'●)\n新版本已经准备好了是否重启应用呢",
success(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
},
onTapAvatar: function ({ currentTarget: { dataset } }) {
wx.showActionSheet({
itemList: ["查看图片", "更改头像"],
success: res => {
switch (res.tapIndex) {
case 0:
wx.previewImage({
urls: [global.eduImgDir+dataset.src],
});
break;
case 1:
wx.chooseImage({
count: 1,
success: function (res) {
console.log("choose image")
console.log(res);
const src = res.tempFilePaths[0]
wx.navigateTo({
url: '/avatar/pages/image_crop/image_crop?src=' + src, fail: console.error
})
},
})
break;
}
}
})
},
logout: function () {
app.callApi({
name: "accounts.logout", success: res => {
console.log("注销成功");
console.log(res);
this.onShow();
},
fail: error => {
console.error("注销失败");
console.error(error);
}
})
},
enter_login: function (event) {
wx.navigateTo({
url: '/account/pages/login/login', fail: console.error
})
},
show_join_course_modal: function (event) {
this.setData({ show_join_course_modal: true });
},
onLoad(){
let data = wx.getStorageSync("auto-attendence");
if(data)
this.setData({auto_attendance:true});
},
onShow(){
app.syncUser().then(res => {
if(res.user.user_id!=2)
this.refresh();
else
this.setData({user:{}})
});
},
refresh: function () {
app.api("users.homepage_info")()
.then(res => {
console.log("get_homepage_info");
console.log(res)
this.setData({ user: res })
if (!res.attendance_signed && this.data.auto_attendance)
this.attendance({ show: 0 })
});
},
tapAutoAttendence(){
this.setData({auto_attendance:!this.data.auto_attendance});
if (!this.data.user.attendance_signed && this.data.auto_attendance)
this.attendance({ show: 1 })
wx.setStorage({
key: 'auto-attendence',
data: this.data.auto_attendance,
});
},
attendance({show=1}){
app.api("users.attendance")()
.then(res=>{
this.refresh();
res.message = "签到成功";
if(show)
app.showMsg(res);
})
},
onShareAppMessage: function () {
}
})