myMission.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. const app = require('../../utils/util.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. showewm: false,
  8. showzs: false,
  9. kcArr: [],
  10. ewmurl: '',
  11. sfmArr: [],
  12. className: '',
  13. istask1: false,
  14. istask2: false,
  15. istask3: false,
  16. istask4: false,
  17. istask5: false
  18. },
  19. selectBtn0() {
  20. this.setData({
  21. select: 0
  22. });
  23. },
  24. selectBtn1() {
  25. this.setData({
  26. select: 1
  27. });
  28. },
  29. gokhAnswer() {
  30. wx.navigateTo({
  31. url: '../answerAfterclass/answerAfterclass'
  32. })
  33. },
  34. gopjClass() {
  35. wx.navigateTo({
  36. url: '../evaluationCourse/evaluationCourse'
  37. })
  38. },
  39. startAnswer() {
  40. wx.navigateTo({
  41. url: '/pages/answerAfterclass/answerAfterclass',
  42. })
  43. },
  44. goWrite() {
  45. // wx.showModal({
  46. // showCancel: false,
  47. // content: "敬请期待",
  48. // success(res) {}
  49. // })
  50. wx.navigateTo({
  51. url: '../studentRegistration/studentRegistration'
  52. })
  53. },
  54. goWrite2() {
  55. // wx.showModal({
  56. // showCancel: false,
  57. // content: "敬请期待",
  58. // success(res) {}
  59. // })
  60. wx.navigateTo({
  61. url: '../feedBack/feedBack'
  62. })
  63. },
  64. lq() {
  65. // wx.showModal({
  66. // showCancel: false,
  67. // content: "此功能暂时还未开放哦",
  68. // success(res) {}
  69. // })
  70. this.setData({
  71. showzs: true
  72. });
  73. },
  74. // 跳转直播点播页面
  75. goStudy(e) {
  76. wx.showModal({
  77. showCancel: false,
  78. content: "您有未完成的学习课程,请先完成学习任务后再进行其他课程学习!",
  79. success(res) {}
  80. })
  81. // let id = e.currentTarget.dataset.item.id
  82. // if (e.currentTarget.dataset.item.isLive == 1) {
  83. // if (e.currentTarget.dataset.item.isActive == 1) {
  84. // wx.navigateTo({
  85. // url: '../zbDetails/zbDetails?id=' + id
  86. // })
  87. // } else {
  88. // wx.showModal({
  89. // showCancel: false,
  90. // content: "直播还未开始哦",
  91. // success(res) {}
  92. // })
  93. // }
  94. // } else {
  95. // wx.navigateTo({
  96. // url: '../dbDetails/dbDetails?id=' + id
  97. // })
  98. // }
  99. },
  100. getMycourse(sessionKey) {
  101. var _this = this;
  102. wx.request({
  103. url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
  104. method: "post",
  105. data: {
  106. sessionKey: sessionKey
  107. },
  108. success: function (res) {
  109. if (res.data.code == 0 && res.data.list.length !== 0) {
  110. _this.setData({
  111. kcArr: res.data.list,
  112. istask3: res.data.allDone
  113. });
  114. let result = [];
  115. if (res.data.list)
  116. for (var i = 0; i < res.data.list.length; i++) {
  117. result.push({
  118. courseTime: res.data.list[i].courseTime
  119. });
  120. }
  121. const timesArr = result.map((item) => {
  122. return item.courseTime;
  123. });
  124. let sfmArr = [];
  125. for (let i = 0; i < timesArr.length; i++) {
  126. let value = timesArr[i];
  127. const resultValue = _this.handler(value);
  128. sfmArr.push({
  129. courseTime: resultValue
  130. })
  131. _this.setData({
  132. sfmArr: sfmArr
  133. })
  134. }
  135. }
  136. }
  137. })
  138. },
  139. handler(value) {
  140. //换算为秒 进制1000
  141. const second = Math.floor(value / 1000); //判断是否够1秒
  142. if (second < 1) {
  143. return "0秒";
  144. }
  145. const secondValue = second % 60; // 秒
  146. const minutes = Math.floor(second / 60); //判断是否够1分钟
  147. if (minutes < 1) {
  148. return `${secondValue}秒`;
  149. }
  150. const minutesValue = minutes % 60; //分
  151. const hours = Math.floor(minutes / 60); //判断是否够1小时
  152. if (hours < 1) {
  153. return `${minutesValue}分${secondValue}秒`;
  154. }
  155. const hoursValue = hours % 60; //小时
  156. return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  157. },
  158. // 学员身份认证 检查第一个任务
  159. checkTaskList(sessionKey) {
  160. var _this = this;
  161. wx.request({
  162. url: app.globalData.publicUrl2 + '/wx/student/selStudentSessionKey',
  163. method: "post",
  164. data: {
  165. sessionKey: sessionKey
  166. },
  167. success: function (res) {
  168. console.log(res.data, "wwwwww")
  169. if (res.data.code == 0) {
  170. if (res.data.data.remark == 1) {
  171. _this.setData({
  172. istask1: true
  173. })
  174. }
  175. }
  176. }
  177. })
  178. },
  179. // 查询我是否有班&&班级名字
  180. isClass(sessionKey) {
  181. var _this = this;
  182. wx.request({
  183. url: app.globalData.publicUrl2 + '/wx/student/selMyClas',
  184. method: "post",
  185. data: {
  186. sessionKey: sessionKey
  187. },
  188. success: function (res) {
  189. console.log(res, "我是返回是否有班级")
  190. if (res.data.code == 0) {
  191. _this.setData({
  192. className: res.data.data.clasName,
  193. ewmurl: res.data.data.codeImg
  194. })
  195. } else {
  196. wx.showModal({
  197. content: "您当前还没有开放的班级!",
  198. showCancel: false,
  199. success(res) {
  200. if (res.confirm) {
  201. wx.switchTab({
  202. url: '../index/index'
  203. })
  204. }
  205. }
  206. })
  207. return false;
  208. }
  209. }
  210. })
  211. },
  212. // 记录二维码已经点击
  213. ewmClick(sessionKey) {
  214. let _this = this;
  215. wx.request({
  216. url: app.globalData.publicUrl2 + '/wx/student/wxGroup',
  217. method: "post",
  218. data: {
  219. sessionKey: sessionKey
  220. },
  221. success: function (res) {
  222. console.log(res)
  223. _this.setData({
  224. showewm: true,
  225. istask1: true
  226. })
  227. }
  228. })
  229. },
  230. // ewmGet(sessionKey) {
  231. // let _this = this;
  232. // wx.request({
  233. // url: app.globalData.publicUrl2 + '/wx/student/selAllClas',
  234. // method: "post",
  235. // data: {
  236. // sessionKey: sessionKey
  237. // },
  238. // success: function (res) {
  239. // console.log(res.data.data, "22222222")
  240. // var filterArr = res.data.data.claList.filter(o => o.isActive == 5)
  241. // console.log(filterArr, "111111111111")
  242. // if (filterArr.length !== 0) {
  243. // _this.setData({
  244. // ewmurl: filterArr[0].codeImg
  245. // })
  246. // }
  247. // }
  248. // })
  249. // },
  250. showEwm() {
  251. var sessionKey = "";
  252. var _this = this;
  253. wx.checkSession({
  254. success: () => {
  255. console.log("我有缓存")
  256. sessionKey = wx.getStorageSync('sessionKey');
  257. // console.log(sessionKey)
  258. _this.ewmClick(sessionKey)
  259. // _this.ewmGet(sessionKey)
  260. },
  261. fail() {
  262. console.log("我没有缓存并去登录请求")
  263. wx.login({
  264. success(res) {
  265. console.log(res);
  266. var code = res.code
  267. wx.request({
  268. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  269. method: "get",
  270. data: {
  271. code
  272. },
  273. success: function (res) {
  274. sessionKey = res.data.sessionKey;
  275. wx.setStorageSync('sessionKey', res.data.sessionKey);
  276. _this.ewmClick(sessionKey)
  277. // _this.ewmGet(sessionKey)
  278. }
  279. })
  280. }
  281. })
  282. }
  283. })
  284. },
  285. onShow() {
  286. var _this = this;
  287. wx.checkSession({
  288. success: () => {
  289. console.log("我有缓存")
  290. var sessionKey = wx.getStorageSync('sessionKey');
  291. console.log(sessionKey, "我有缓存")
  292. if (sessionKey == "") {
  293. wx.login({
  294. success(res) {
  295. console.log(res);
  296. var code = res.code
  297. wx.request({
  298. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  299. method: "get",
  300. data: {
  301. code
  302. },
  303. success: function (res) {
  304. sessionKey = res.data.sessionKey;
  305. wx.setStorageSync('sessionKey', res.data.sessionKey);
  306. _this.checkTaskList(sessionKey)
  307. _this.isClass(sessionKey);
  308. _this.getMycourse(sessionKey);
  309. }
  310. })
  311. }
  312. })
  313. } else {
  314. _this.checkTaskList(sessionKey)
  315. _this.isClass(sessionKey);
  316. _this.getMycourse(sessionKey);
  317. }
  318. },
  319. fail() {
  320. console.log("我没有缓存并去登录请求")
  321. wx.login({
  322. success(res) {
  323. console.log(res);
  324. var code = res.code
  325. wx.request({
  326. url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login',
  327. method: "get",
  328. data: {
  329. code
  330. },
  331. success: function (res) {
  332. wx.setStorageSync('sessionKey', res.data.sessionKey);
  333. var sessionKey = res.data.sessionKey;
  334. _this.checkTaskList(sessionKey)
  335. _this.isClass(sessionKey);
  336. _this.getMycourse(sessionKey);
  337. }
  338. })
  339. }
  340. })
  341. }
  342. })
  343. },
  344. onClose() {
  345. wx.hideLoading()
  346. this.setData({
  347. showewm: false
  348. });
  349. },
  350. onClose1() {
  351. this.setData({
  352. showzs: false
  353. });
  354. },
  355. /**
  356. * 生命周期函数--监听页面初次渲染完成
  357. */
  358. saveImg() {
  359. let _this = this;
  360. console.log(_this.data.ewmurl)
  361. wx.getSetting({
  362. success(res) {
  363. if (!res.authSetting['scope.writePhotosAlbum']) {
  364. wx.authorize({
  365. scope: 'scope.writePhotosAlbum',
  366. success() {
  367. console.log(res, "我点击同意啦")
  368. wx.showLoading({
  369. title: '保存中...'
  370. })
  371. var imgSrc = _this.data.ewmurl;
  372. wx.downloadFile({
  373. url: imgSrc,
  374. success: function (res) {
  375. console.log(res, '我下载完成啦');
  376. //图片保存到本地
  377. wx.saveImageToPhotosAlbum({
  378. filePath: res.tempFilePath,
  379. success: function (data) {
  380. console.log(data, '我保存成功啦')
  381. wx.hideLoading();
  382. wx.showToast({
  383. title: '保存成功',
  384. icon: 'success',
  385. duration: 2000
  386. })
  387. },
  388. fail: function (err) {
  389. console.log(err, '我保存失败啦')
  390. wx.hideLoading();
  391. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  392. console.log("当初用户拒绝,再次发起授权")
  393. wx.openSetting({
  394. success(settingdata) {
  395. console.log(settingdata)
  396. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  397. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  398. } else {
  399. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  400. }
  401. }
  402. })
  403. }
  404. },
  405. complete(res) {
  406. console.log(res);
  407. }
  408. })
  409. }
  410. })
  411. console.log('授权成功')
  412. }
  413. })
  414. } else {
  415. var imgSrc = _this.data.ewmurl
  416. wx.downloadFile({
  417. url: imgSrc,
  418. success: function (res) {
  419. console.log(res, '我下载完成啦');
  420. wx.hideLoading();
  421. //图片保存到本地
  422. wx.saveImageToPhotosAlbum({
  423. filePath: res.tempFilePath,
  424. success: function (data) {
  425. console.log(data, '我保存成功啦')
  426. wx.hideLoading();
  427. wx.showToast({
  428. title: '保存成功',
  429. icon: 'success',
  430. duration: 2000
  431. })
  432. },
  433. fail: function (err) {
  434. console.log(err, '我保存失败啦')
  435. wx.hideLoading();
  436. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  437. console.log("当初用户拒绝,再次发起授权")
  438. wx.openSetting({
  439. success(settingdata) {
  440. console.log(settingdata)
  441. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  442. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  443. } else {
  444. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  445. }
  446. }
  447. })
  448. }
  449. },
  450. complete(res) {
  451. console.log(res);
  452. }
  453. })
  454. }
  455. })
  456. }
  457. }
  458. })
  459. },
  460. onReady: function () {
  461. },
  462. /**
  463. * 生命周期函数--监听页面显示
  464. */
  465. // onShow: function () {
  466. // },
  467. /**
  468. * 生命周期函数--监听页面隐藏
  469. */
  470. onHide: function () {
  471. },
  472. /**
  473. * 生命周期函数--监听页面卸载
  474. */
  475. onUnload: function () {
  476. },
  477. /**
  478. * 页面相关事件处理函数--监听用户下拉动作
  479. */
  480. onPullDownRefresh: function () {
  481. },
  482. /**
  483. * 页面上拉触底事件的处理函数
  484. */
  485. onReachBottom: function () {
  486. },
  487. /**
  488. * 用户点击右上角分享
  489. */
  490. onShareAppMessage: function () {
  491. }
  492. })