const app = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { showewm: false, showzs: false, kcArr: [], ewmurl: '', istask1: false, istask2: false, istask3: false, istask4: false, istask5: false }, 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.showModal({ // showCancel: false, // content: "敬请期待", // success(res) {} // }) wx.navigateTo({ url: '../studentRegistration/studentRegistration' }) }, goWrite2() { // wx.showModal({ // showCancel: false, // content: "敬请期待", // success(res) {} // }) wx.navigateTo({ url: '../feedBack/feedBack' }) }, lq() { wx.showToast({ title: '领取成功' }) // this.setData({ // showzs: true // }); }, // 跳转直播点播页面 goStudy(e) { // console.log(e.currentTarget.dataset.item.id) let id = e.currentTarget.dataset.item.id if (e.currentTarget.dataset.item.isLive == 1) { wx.navigateTo({ url: '../zbDetails/zbDetails?id=' + id }) } else { wx.navigateTo({ url: '../dbDetails/dbDetails?id=' + id }) } }, 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 }); } }) }, // 学员身份认证 checkTaskList(sessionKey) { var _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selStudentSessionKey', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res.data, "wwwwww") if (res.data.code == 0) { if (res.data.data.remark == 1) { _this.setData({ istask1: true }) } } } }) }, isClass(sessionKey) { wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selAllClas', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res.data, "我是返回的班级列表") let 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; } } }) }, // 记录二维码已经点击 ewmClick(sessionKey) { let _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/wxGroup', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res) _this.setData({ showewm: true }) } }) }, ewmGet(sessionKey) { let _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selAllClas', method: "post", data: { sessionKey: sessionKey }, success: function (res) { console.log(res.data.data, "22222222") var filterArr = res.data.data.claList.filter(o => o.isActive == 5) console.log(filterArr, "111111111111") if (filterArr.length !== 0) { _this.setData({ ewmurl: filterArr[0].codeImg }) } } }) }, showEwm() { var sessionKey = ""; var _this = this; wx.checkSession({ success: () => { console.log("我有缓存") sessionKey = wx.getStorageSync('sessionKey'); // console.log(sessionKey) _this.ewmClick(sessionKey) _this.ewmGet(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) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); _this.ewmClick(sessionKey) _this.ewmGet(sessionKey) } }) } }) } }) }, 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.checkTaskList(sessionKey) _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }) } }) } else { _this.checkTaskList(sessionKey) _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.checkTaskList(sessionKey) _this.isClass(sessionKey); _this.getMycourse(sessionKey); } }) } }) } }) }, onClose() { wx.hideLoading() this.setData({ showewm: false }); }, onClose1() { this.setData({ showzs: false }); }, /** * 生命周期函数--监听页面初次渲染完成 */ saveImg() { let _this = this; console.log(_this.data.ewmurl) wx.getSetting({ success(res) { if (!res.authSetting['scope.writePhotosAlbum']) { wx.authorize({ scope: 'scope.writePhotosAlbum', success() { console.log(res, "我点击同意啦") wx.showLoading({ title: '保存中...' }) var imgSrc = _this.data.ewmurl; 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 = _this.data.ewmurl 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 () { } })