|
|
|
|
const app = getApp();
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
version: global.config.version,
|
|
|
|
|
imgDir: global.config.imgDir,
|
|
|
|
|
eduImgDir: global.config.eduImgDir,
|
|
|
|
|
user: {},
|
|
|
|
|
showModal: false,
|
|
|
|
|
auto_attendance: false
|
|
|
|
|
},
|
|
|
|
|
enterPage({ target: { dataset: { path } } }) {
|
|
|
|
|
console.log("enterPage");
|
|
|
|
|
if (!path) return;
|
|
|
|
|
let { id } = this.data.user;
|
|
|
|
|
if (!id || id == 2)
|
|
|
|
|
return wx.showToast({ title: "请先登录哦", icon: "none" });
|
|
|
|
|
app.navigateTo({ url: `{${path}}` });
|
|
|
|
|
},
|
|
|
|
|
onTapVersion() {
|
|
|
|
|
let { envVersion, env } = global.config;
|
|
|
|
|
if (envVersion && envVersion != "release") {
|
|
|
|
|
wx.showActionSheet({
|
|
|
|
|
itemList: [env != "release" ? "切换为发布环境" : "切换为开发环境"],
|
|
|
|
|
success: res => {
|
|
|
|
|
global.config.switchEnv(env != "release" ? "release" : "trial");
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '切换成功'
|
|
|
|
|
});
|
|
|
|
|
this.logout({ showToast: 0 });
|
|
|
|
|
let { version, eduImgDir } = global.config;
|
|
|
|
|
this.setData({ version, eduImgDir });
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const updateManager = wx.getUpdateManager()
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '检查更新中...', icon: "none"
|
|
|
|
|
});
|
|
|
|
|
updateManager.onCheckForUpdate(res => {
|
|
|
|
|
if (res.hasUpdate) {
|
|
|
|
|
wx.hideToast();
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '更新提示',
|
|
|
|
|
content: "(●'◡'●)\n有新版本哦,是否使用最新的小程序呢?",
|
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
title: '准备中'
|
|
|
|
|
});
|
|
|
|
|
updateManager.onUpdateReady(() => {
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
updateManager.applyUpdate()
|
|
|
|
|
})
|
|
|
|
|
updateManager.onUpdateFailed(() => {
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '>︿<\n更新失败', icon: "none"
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '你用的是最新版本哦', icon: "none"
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
onTapAvatar: function ({ currentTarget: { dataset } }) {
|
|
|
|
|
wx.showActionSheet({
|
|
|
|
|
itemList: ["查看图片", "更改头像"],
|
|
|
|
|
success: res => {
|
|
|
|
|
switch (res.tapIndex) {
|
|
|
|
|
case 0:
|
|
|
|
|
wx.previewImage({
|
|
|
|
|
urls: [global.eduImgDir + dataset.url],
|
|
|
|
|
});
|
|
|
|
|
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 ({ showToast = 1 }) {
|
|
|
|
|
app.callApi({
|
|
|
|
|
name: "accounts.logout", success: res => {
|
|
|
|
|
console.log("注销成功");
|
|
|
|
|
console.log(res);
|
|
|
|
|
if (showToast)
|
|
|
|
|
app.showMsg(res);
|
|
|
|
|
this.onShow();
|
|
|
|
|
},
|
|
|
|
|
fail: error => {
|
|
|
|
|
console.error("注销失败");
|
|
|
|
|
console.error(error);
|
|
|
|
|
if (showToast)
|
|
|
|
|
app.showError(e);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
enter_login: function (event) {
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/account/pages/account/account?action=login', fail: console.error
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
showModal: function (event) {
|
|
|
|
|
let {id} = this.data.user;
|
|
|
|
|
if (!id || id == 2)
|
|
|
|
|
return wx.showToast({ title: "请先登录哦", icon: "none" });
|
|
|
|
|
this.setData({ showModal: 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 () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|