myMission.js 13 KB

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