const app = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { showewm: false, showzs: false, kcArr: [] }, selectBtn0() { this.setData({ select: 0 }); }, selectBtn1() { this.setData({ select: 1 }); }, gokhAnswer() { wx.navigateTo({ url: '../answerAfterclass/answerAfterclass' }) }, gopjClass() { wx.navigateTo({ url: '../evaluationCourse/evaluationCourse' }) }, startAnswer() { wx.navigateTo({ url: '/pages/answerAfterclass/answerAfterclass', }) }, goWrite() { wx.navigateTo({ url: '../studentRegistration/studentRegistration' }) }, goWrite2() { wx.navigateTo({ url: '../feedBack/feedBack' }) }, lq() { this.setData({ showzs: true }); // wx.showToast({ // title: '领取成功' // }) }, /** * 生命周期函数--监听页面加载 */ getMycourse(sessionKey) { var _this = this; wx.request({ url: app.globalData.publicUrl + '/wx/course/selectBySessionKey', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res) _this.setData({ kcArr: res.data.list }); } }) }, isClass(sessionKey) { var _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selAllClas', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res.data, "我是返回的班级列表") var filterArr = res.data.data.claList.filter(o => o.isActive == 5) console.log(filterArr, "我是筛选出来的数组") if (filterArr.length == 0) { wx.showModal({ title: '您还未加入班级', content: '跳转至身份认证', success: function (res) { if (res.confirm) { wx.redirectTo({ url: '../Identity/Identity' }) } else { wx.switchTab({ url: '../index/index' }) } } }) return false; } } }) }, // onShow: function () { // var _this = this; // wx.checkSession({ // success: () => { // console.log("我有缓存") // var sessionKey = wx.getStorageSync('sessionKey'); // if (sessionKey == "") { // wx.login({ // success(res) { // console.log(res); // var code = res.code // wx.request({ // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', // method: "get", // data: { // code // }, // success: function (res) { // sessionKey = res.data.sessionKey; // wx.setStorageSync('sessionKey', res.data.sessionKey); // } // }) // } // }) // } else { // _this.getMycourse(sessionKey); // } // }, // fail() { // console.log("我没有缓存并去登录请求") // wx.login({ // success(res) { // console.log(res); // var code = res.code // wx.request({ // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', // method: "get", // data: { // code // }, // success: function (res) { // wx.setStorageSync('sessionKey', res.data.sessionKey); // var sessionKey = res.data.sessionKey; // _this.getMycourse(sessionKey); // } // }) // } // }) // } // }) // }, showEwm() { var sessionKey = ""; var _this = this; wx.checkSession({ success: () => { console.log("我有缓存") sessionKey = wx.getStorageSync('sessionKey'); console.log(sessionKey) wx.request({ url: app.globalData.publicUrl2 + '/wx/student/wxGroup', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res) _this.setData({ showewm: true }) } }) }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); wx.request({ url: app.globalData.publicUrl2 + '/wx/student/wxGroup', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res) _this.setData({ showewm: true }) } }) } }) } }) } }) // this.setData({ // showewm: true // }); }, // showzs(){ // }, onShow() { var _this = this; wx.checkSession({ success: () => { console.log("我有缓存") var sessionKey = wx.getStorageSync('sessionKey'); console.log(sessionKey, "我有缓存") if (sessionKey == "") { wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }) } }) } else { _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { wx.setStorageSync('sessionKey', res.data.sessionKey); var sessionKey = res.data.sessionKey; _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }) } }) } }) }, onClose() { wx.hideLoading() this.setData({ showewm: false }); }, onClose1() { this.setData({ showzs: false }); }, /** * 生命周期函数--监听页面初次渲染完成 */ saveImg() { wx.getSetting({ success(res) { if (!res.authSetting['scope.writePhotosAlbum']) { wx.authorize({ scope: 'scope.writePhotosAlbum', success() { console.log(res, "我点击同意啦") wx.showLoading({ title: '保存中...' }) var imgSrc = "http://yijiao.oss-cn-qingdao.aliyuncs.com/images/http://tmp/wx1b4e5e756cd48af1.o6zAJsws4grEQvYrWTjBigy-6QaU.0llhudiKSF2V955a1c48350d9328ef064b4d36d12746.jpg" wx.downloadFile({ url: imgSrc, success: function (res) { console.log(res, '我下载完成啦'); //图片保存到本地 wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: function (data) { console.log(data, '我保存成功啦') wx.hideLoading(); wx.showToast({ title: '保存成功', icon: 'success', duration: 2000 }) }, fail: function (err) { console.log(err, '我保存失败啦') wx.hideLoading(); if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") { console.log("当初用户拒绝,再次发起授权") wx.openSetting({ success(settingdata) { console.log(settingdata) if (settingdata.authSetting['scope.writePhotosAlbum']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示') } } }) } }, complete(res) { console.log(res); } }) } }) console.log('授权成功') } }) } else { var imgSrc = "http://yijiao.oss-cn-qingdao.aliyuncs.com/images/http://tmp/wx1b4e5e756cd48af1.o6zAJsws4grEQvYrWTjBigy-6QaU.0llhudiKSF2V955a1c48350d9328ef064b4d36d12746.jpg" wx.downloadFile({ url: imgSrc, success: function (res) { console.log(res, '我下载完成啦'); wx.hideLoading(); //图片保存到本地 wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: function (data) { console.log(data, '我保存成功啦') wx.hideLoading(); wx.showToast({ title: '保存成功', icon: 'success', duration: 2000 }) }, fail: function (err) { console.log(err, '我保存失败啦') wx.hideLoading(); if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") { console.log("当初用户拒绝,再次发起授权") wx.openSetting({ success(settingdata) { console.log(settingdata) if (settingdata.authSetting['scope.writePhotosAlbum']) { console.log('获取权限成功,给出再次点击图片保存到相册的提示。') } else { console.log('获取权限失败,给出不给权限就无法正常使用的提示') } } }) } }, complete(res) { console.log(res); } }) } }) } } }) }, onReady: function () { }, /** * 生命周期函数--监听页面显示 */ // onShow: function () { // }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })