myClass.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. Page({
  4. data: {
  5. showMore: false, //更多
  6. showzs: false, //证书显示
  7. show: false, //协议显示
  8. notice: "暂无未读通知",
  9. classInfo: {}, //班级信息
  10. kcArr: [], //课程列表
  11. sfmArr: [], //换算时分秒数组
  12. studentName: "", //学生明字
  13. status: '', //状态
  14. myCanvasId: 0, //画布id
  15. byzsbj: "../../images/zsbj.jpg", //结业证背景 用于合成图片
  16. IngCourseArr: [], //如果有正在进行的课就存一下
  17. istask: false, //判断班级群是否添加
  18. istask1: false, //学员登记表是否完成
  19. istask2: false, //课程是否完成
  20. istask3: false, //期末考试是否完成
  21. istask4: false, //综合反馈是否完成
  22. },
  23. // 查询我是否认证
  24. isRz(sessionKey) {
  25. wx.request({
  26. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  27. method: "post",
  28. data: {
  29. sessionKey: sessionKey
  30. },
  31. success: (res) => {
  32. if (res.data.code == 0) {
  33. if (res.data.data !== null || res.data.data !== "") {
  34. this.isClass(sessionKey)
  35. } else {
  36. wx.showModal({
  37. content: "您还没有进行身份认证哦",
  38. showCancel: false,
  39. success(res) {
  40. if (res.confirm) {
  41. wx.redirectTo({
  42. url: '../Identity/Identity'
  43. })
  44. }
  45. }
  46. })
  47. }
  48. } else {
  49. wx.showModal({
  50. content: "您还没有进行身份认证哦",
  51. showCancel: false,
  52. success(res) {
  53. if (res.confirm) {
  54. wx.redirectTo({
  55. url: '../Identity/Identity'
  56. })
  57. }
  58. }
  59. })
  60. }
  61. }
  62. })
  63. },
  64. // 查询我是否有班&&班级名字
  65. isClass(sessionKey) {
  66. wx.request({
  67. url: app.globalData.publicUrl + '/wx/student/selMyClas',
  68. method: "post",
  69. data: {
  70. sessionKey: sessionKey
  71. },
  72. success: (res) => {
  73. if (res.data.code == 0) {
  74. this.setData({
  75. classInfo: res.data.data
  76. })
  77. this.checkTaskList4(sessionKey, res.data.data.id);
  78. this.checkTaskList(sessionKey);
  79. this.checkTaskList3(sessionKey, res.data.data.id);
  80. this.isAgree(sessionKey);
  81. } else {
  82. wx.showModal({
  83. content: "您当前还没有正在开放的班级!",
  84. showCancel: false,
  85. success(res) {
  86. if (res.confirm) {
  87. wx.switchTab({
  88. url: '../index/index'
  89. })
  90. }
  91. }
  92. })
  93. return false;
  94. }
  95. }
  96. })
  97. },
  98. // 协议是否已同意
  99. isAgree(sessionKey) {
  100. // let _this = this;
  101. wx.request({
  102. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  103. method: "post",
  104. data: {
  105. sessionKey: sessionKey
  106. },
  107. success: (res) => {
  108. if (res.data.code == 0 && res.data.data) {
  109. if (res.data.data.agreement == 0) {
  110. this.setData({
  111. studentName: res.data.data.studentName,
  112. show: false
  113. });
  114. } else {
  115. this.setData({
  116. studentName: res.data.data.studentName,
  117. show: true
  118. });
  119. }
  120. }
  121. }
  122. })
  123. },
  124. // 点击同意协议 并且记一下
  125. hidePopup() {
  126. this.setData({
  127. show: false
  128. });
  129. let sessionKey = "";
  130. wx.checkSession({
  131. success: () => {
  132. sessionKey = wx.getStorageSync('sessionKey');
  133. wx.request({
  134. url: app.globalData.publicUrl + '/wx/student/verification',
  135. method: "post",
  136. data: {
  137. sessionKey: sessionKey
  138. },
  139. success: function (res) {
  140. console.log(res, "我成功了")
  141. }
  142. })
  143. },
  144. fail() {
  145. wx.login({
  146. success(res) {
  147. let code = res.code
  148. wx.request({
  149. url: app.globalData.publicUrl + '/wx/user/wx7e7a46e129d6cd0f/login',
  150. method: "get",
  151. data: {
  152. code
  153. },
  154. success: function (res) {
  155. sessionKey = res.data.sessionKey;
  156. wx.setStorageSync('sessionKey', res.data.sessionKey);
  157. wx.request({
  158. url: app.globalData.publicUrl + '/wx/student/verification',
  159. method: "post",
  160. data: {
  161. sessionKey: sessionKey
  162. },
  163. success: function (res) {
  164. console.log(res, "我成功了")
  165. }
  166. })
  167. }
  168. })
  169. }
  170. })
  171. }
  172. })
  173. },
  174. // 检查班级群是否加了
  175. checkTaskList(sessionKey) {
  176. wx.request({
  177. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  178. method: "post",
  179. data: {
  180. sessionKey: sessionKey
  181. },
  182. success: (res) => {
  183. if (res.data.code == 0) {
  184. if (res.data.data.joinClas == 0) {
  185. this.setData({
  186. istask: true
  187. })
  188. }
  189. this.setData({
  190. studentName: res.data.data.studentName,
  191. })
  192. }
  193. }
  194. })
  195. },
  196. // 学员登记任务check
  197. checkTaskList1(sessionKey) {
  198. wx.request({
  199. url: app.globalData.publicUrl + '/wx/student/selStudentSessionKey',
  200. method: "post",
  201. data: {
  202. sessionKey: sessionKey
  203. },
  204. success: (res) => {
  205. if (res.data.code == 0 && res.data.data.register == 0) {
  206. this.setData({
  207. istask1: true
  208. })
  209. }
  210. }
  211. })
  212. },
  213. // 期末考试任务检查
  214. checkTaskList3(sessionKey, id) {
  215. wx.request({
  216. url: app.globalData.publicUrl + '/wx/exam/clasExamstatus',
  217. method: "post",
  218. data: {
  219. sessionKey: sessionKey,
  220. clasId: id
  221. },
  222. success: (res) => {
  223. if (res.data.code == 0 && res.data.status == 1) {
  224. this.setData({
  225. istask3: true
  226. })
  227. }
  228. }
  229. })
  230. },
  231. // 综合反馈任务check
  232. checkTaskList4(sessionKey, id) {
  233. wx.request({
  234. url: app.globalData.publicUrl + '/wx/exam/status',
  235. method: "post",
  236. data: {
  237. sessionKey: sessionKey,
  238. clasId: id
  239. },
  240. success: (res) => {
  241. if (res.data.code == 0 && res.data.status == 1) {
  242. this.setData({
  243. istask4: true
  244. })
  245. }
  246. }
  247. })
  248. },
  249. // 页面上显示的我的未读通知
  250. getMynotice(sessionKey) {
  251. // let _this = this;
  252. wx.request({
  253. url: app.globalData.publicUrl + '/wx/eduNoticeSee/list',
  254. method: "post",
  255. data: {
  256. sessionKey: sessionKey,
  257. isSee: 1,
  258. isNotice: 0
  259. },
  260. success: (res) => {
  261. if (res.data.code == 0) {
  262. if (res.data.list && res.data.list.length !== 0)
  263. this.setData({
  264. notice: res.data.list[0].noticeContent
  265. });
  266. }
  267. }
  268. })
  269. },
  270. // 跳转通知页
  271. gomyNotice() {
  272. // if (this.data.notice !== "暂无未读通知") {
  273. wx.navigateTo({
  274. url: '../myNotice/myNotice'
  275. })
  276. // }
  277. },
  278. // 学员登记表
  279. goWrite() {
  280. if (!this.data.istask) {
  281. wx.showModal({
  282. showCancel: false,
  283. content: "请先去扫描二维码加入班级群吧",
  284. success(res) {
  285. if (res.confirm) {
  286. wx.switchTab({
  287. url: '../myMission/myMission'
  288. })
  289. }
  290. }
  291. })
  292. return false
  293. }
  294. wx.navigateTo({
  295. url: '../studentRegistration/studentRegistration'
  296. })
  297. },
  298. // 我的课程
  299. getMycourse(sessionKey) {
  300. // let _this = this;
  301. wx.request({
  302. url: app.globalData.publicUrl + '/wx/course/selectBySessionKey',
  303. method: "post",
  304. data: {
  305. sessionKey: sessionKey
  306. },
  307. success: (res) => {
  308. this.setData({
  309. kcArr: res.data.list,
  310. istask2: res.data.allDone
  311. });
  312. for (let i = 0; i < res.data.list.length; i++) {
  313. if (res.data.list[i].isStudyDone == 0) {
  314. this.setData({
  315. IngCourseArr: res.data.list[i]
  316. })
  317. }
  318. }
  319. let result = [];
  320. if (res.data.list)
  321. for (let i = 0; i < res.data.list.length; i++) {
  322. result.push({
  323. courseTime: res.data.list[i].courseTime
  324. });
  325. }
  326. const timesArr = result.map((item) => {
  327. return item.courseTime;
  328. });
  329. let sfmArr = [];
  330. for (let i = 0; i < timesArr.length; i++) {
  331. let value = timesArr[i];
  332. const resultValue = this.handler(value);
  333. sfmArr.push({
  334. courseTime: resultValue
  335. })
  336. this.setData({
  337. sfmArr: sfmArr
  338. })
  339. }
  340. }
  341. })
  342. },
  343. // 时间换算
  344. handler(value) {
  345. //换算为秒 进制1000
  346. const second = Math.floor(value / 1000); //判断是否够1秒
  347. if (second < 1) {
  348. return "0秒";
  349. }
  350. const secondValue = second % 60; // 秒
  351. const minutes = Math.floor(second / 60); //判断是否够1分钟
  352. if (minutes < 1) {
  353. return `${secondValue}秒`;
  354. }
  355. const minutesValue = minutes % 60; //分
  356. const hours = Math.floor(minutes / 60); //判断是否够1小时
  357. if (hours < 1) {
  358. return `${minutesValue}分${secondValue}秒`;
  359. }
  360. const hoursValue = hours % 60; //小时
  361. return `${hoursValue}时${minutesValue}分${secondValue}秒`;
  362. },
  363. // 查看更多列表展开
  364. listToggle: function () {
  365. this.setData({
  366. showMore: !this.data.showMore
  367. })
  368. },
  369. // 去学习
  370. goStudy(e) {
  371. if (!this.data.istask) {
  372. wx.showModal({
  373. showCancel: false,
  374. content: "请先去扫描二维码加入班级群吧",
  375. success(res) {
  376. if (res.confirm) {
  377. wx.switchTab({
  378. url: '../myMission/myMission'
  379. })
  380. }
  381. }
  382. })
  383. return false
  384. }
  385. if (!this.data.istask1) {
  386. wx.showModal({
  387. showCancel: false,
  388. content: "请先填写学员登记表再来学习哦!"
  389. })
  390. return false
  391. }
  392. let id = e.currentTarget.dataset.item.id //此课程的id
  393. if (this.data.IngCourseArr.length == 0) {
  394. if (e.currentTarget.dataset.item.isLive == 1) {
  395. if (e.currentTarget.dataset.item.isActive == 1) {
  396. wx.navigateTo({
  397. url: '../zbDetails/zbDetails?id=' + id
  398. })
  399. } else {
  400. wx.showModal({
  401. showCancel: false,
  402. content: "直播还未开始哦"
  403. })
  404. return false;
  405. }
  406. } else {
  407. wx.navigateTo({
  408. url: '../dbDetails/dbDetails?id=' + id
  409. })
  410. }
  411. } else {
  412. if (e.currentTarget.dataset.item.isLive == 1) {
  413. if (e.currentTarget.dataset.item.isActive == 1) {
  414. wx.navigateTo({
  415. url: '../zbDetails/zbDetails?id=' + id
  416. })
  417. } else {
  418. wx.showModal({
  419. showCancel: false,
  420. content: "直播还未开始哦"
  421. })
  422. return false;
  423. }
  424. } else {
  425. if (id == this.data.IngCourseArr.id) {
  426. wx.navigateTo({
  427. url: '../dbDetails/dbDetails?id=' + id
  428. })
  429. } else {
  430. wx.showModal({
  431. showCancel: false,
  432. content: "您的" + this.data.IngCourseArr.courseName + "课还未学完,快去学习吧"
  433. })
  434. }
  435. }
  436. }
  437. },
  438. // 去考试
  439. gokhAnswer(e) {
  440. if (!this.data.istask) {
  441. wx.showModal({
  442. showCancel: false,
  443. content: "请先去扫描二维码加入班级群吧",
  444. success(res) {
  445. if (res.confirm) {
  446. wx.switchTab({
  447. url: '../myMission/myMission'
  448. })
  449. }
  450. }
  451. })
  452. return false
  453. }
  454. if (!this.data.istask1) {
  455. wx.showModal({
  456. showCancel: false,
  457. content: "请先填写学员登记表再来学习哦!"
  458. })
  459. return false
  460. }
  461. let isStudyDone = e.currentTarget.dataset.item.isStudyDone
  462. if (isStudyDone != 1) {
  463. wx.showModal({
  464. showCancel: false,
  465. content: "您的学习课程还未完成哦,请先完成再来考试吧!"
  466. })
  467. return false
  468. } else {
  469. wx.request({
  470. url: app.globalData.publicUrl + '/wx/exam/examList',
  471. method: "post",
  472. data: {
  473. sessionKey: this.data.sessionKey,
  474. courseId: e.currentTarget.dataset.item.id,
  475. clasId: this.data.classInfo.id
  476. },
  477. success: (res) => {
  478. if (res.data.code == 0) {
  479. if (res.data.list.length == 0) {
  480. wx.showModal({
  481. showCancel: false,
  482. content: '老师还未出考试题哦'
  483. })
  484. } else {
  485. if (res.data.list[0]) {
  486. if (res.data.list[0].answersId) {
  487. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
  488. } else {
  489. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
  490. }
  491. }
  492. }
  493. }
  494. }
  495. })
  496. }
  497. },
  498. //去评价
  499. gopjClass(e) {
  500. if (!this.data.istask) {
  501. wx.showModal({
  502. showCancel: false,
  503. content: "请先去扫描二维码加入班级群吧",
  504. success(res) {
  505. if (res.confirm) {
  506. wx.switchTab({
  507. url: '../myMission/myMission'
  508. })
  509. }
  510. }
  511. })
  512. return false
  513. }
  514. if (!this.data.istask1) {
  515. wx.showModal({
  516. showCancel: false,
  517. content: "请先填写学员登记表再来学习哦!"
  518. })
  519. return false
  520. }
  521. let isStudyDone = e.currentTarget.dataset.item.isStudyDone
  522. if (isStudyDone != 1) {
  523. wx.showModal({
  524. showCancel: false,
  525. content: "您的学习课程还未完成哦,请先完成再来评价吧!"
  526. })
  527. return false
  528. } else {
  529. wx.request({
  530. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  531. method: "post",
  532. data: {
  533. sessionKey: this.data.sessionKey,
  534. // questSub: '3',
  535. courseId: e.currentTarget.dataset.item.id,
  536. clasId: this.data.classInfo.id
  537. },
  538. success: (res) => {
  539. if (res.data.code == 0) {
  540. if (res.data.list.length == 0) {
  541. wx.showModal({
  542. showCancel: false,
  543. content: '老师还未出评价模板哦'
  544. })
  545. } else {
  546. if (res.data.list[0]) {
  547. if (res.data.list[0].answersId) {
  548. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'evaluationCourse');
  549. } else {
  550. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'evaluationCourse');
  551. }
  552. }
  553. }
  554. }
  555. }
  556. })
  557. }
  558. },
  559. // 查看详情成绩
  560. gockcj(e) {
  561. if (e.currentTarget.dataset.item.isExamId) {
  562. wx.request({
  563. url: app.globalData.publicUrl + '/wx/answer/detail',
  564. method: "post",
  565. data: {
  566. answersId: e.currentTarget.dataset.item.isExamId
  567. },
  568. success: (res) => {
  569. console.log(res.data.list[0].answerScore)
  570. if (res.data.list[0].answerScore < 0 && (res.data.list[0].answerScore == null || res.data.list[0].answerScore == "")) {
  571. wx.showModal({
  572. showCancel: false,
  573. content: '当前老师批阅中,请耐心等待'
  574. })
  575. } else {
  576. wx.navigateTo({
  577. url: '/pages/grade/grade?answersId=' + e.currentTarget.dataset.item.isExamId,
  578. })
  579. }
  580. }
  581. })
  582. }
  583. },
  584. // 查看详情评价
  585. gockpj(e) {
  586. wx.navigateTo({
  587. url: '/pages/evaluationCourseDetail/evaluationCourseDetail?answersId=' + e.currentTarget.dataset.item.isFeedbackId,
  588. })
  589. },
  590. // 期末考试
  591. goQmks() {
  592. if (!this.data.istask) {
  593. wx.showModal({
  594. showCancel: false,
  595. content: "请先去扫描二维码加入班级群吧",
  596. success(res) {
  597. if (res.confirm) {
  598. wx.switchTab({
  599. url: '../myMission/myMission'
  600. })
  601. }
  602. }
  603. })
  604. return false
  605. }
  606. if (!this.data.istask2) {
  607. wx.showModal({
  608. showCancel: false,
  609. content: "您的课程任务还未全部完成哦!请先去完成再来期末考试吧!"
  610. })
  611. return false
  612. }
  613. wx.request({
  614. url: app.globalData.publicUrl + '/wx/exam/examList',
  615. method: "post",
  616. data: {
  617. sessionKey: this.data.sessionKey,
  618. clasId: this.data.classInfo.id
  619. },
  620. success: (res) => {
  621. if (res.data.code == 0) {
  622. if (res.data.list.length == 0) {
  623. wx.showModal({
  624. showCancel: false,
  625. content: '期末考试还未开始哦!'
  626. })
  627. } else {
  628. if (res.data.list[0].answersId) {
  629. if (res.data.list[0].status == '1') {
  630. wx.request({
  631. url: app.globalData.publicUrl + '/wx/answer/detail',
  632. method: "post",
  633. data: {
  634. answersId: res.data.list[0].answersId
  635. },
  636. success: (res1) => {
  637. if (res1.data.list[0].answerScore) {
  638. wx.navigateTo({
  639. url: '/pages/grade/grade?answersId=' + res.data.list[0].answersId,
  640. })
  641. } else {
  642. wx.showModal({
  643. showCancel: false,
  644. content: '当前老师批阅中,请耐心等待'
  645. })
  646. }
  647. }
  648. })
  649. } else {
  650. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'answerAfterclass');
  651. }
  652. } else {
  653. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'answerAfterclass');
  654. }
  655. }
  656. }
  657. }
  658. })
  659. },
  660. // 综合反馈表
  661. goWrite2() {
  662. if (this.data.istask4) {
  663. wx.request({
  664. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  665. method: "post",
  666. data: {
  667. sessionKey: this.data.sessionKey,
  668. questSub: '1',
  669. clasId: this.data.classInfo.id
  670. },
  671. success: (res) => {
  672. if (res.data.code == 0) {
  673. if (res.data.list[0]) {
  674. if (res.data.list[0].answersId) {
  675. wx.navigateTo({
  676. url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId,
  677. })
  678. } else {
  679. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack');
  680. }
  681. }
  682. }
  683. }
  684. })
  685. } else {
  686. wx.request({
  687. url: app.globalData.publicUrl + '/wx/exam/quesExamList',
  688. method: "post",
  689. data: {
  690. sessionKey: this.data.sessionKey,
  691. questSub: '1',
  692. clasId: this.data.classInfo.id
  693. },
  694. success: (res) => {
  695. if (res.data.code == 0) {
  696. if (res.data.list.length == 0) {
  697. wx.showModal({
  698. showCancel: false,
  699. content: '当前综合反馈还不可以填写哦!'
  700. })
  701. } else {
  702. if (res.data.list[0].answersId) {
  703. if (res.data.list[0].status == '1') {
  704. wx.navigateTo({
  705. url: '/pages/feedBackDetail/feedBackDetail?answersId=' + res.data.list[0].answersId,
  706. })
  707. } else {
  708. this.toPath(res.data.list[0].id, res.data.list[0].paperId, res.data.list[0].answersId, 'feedBack');
  709. }
  710. } else {
  711. this.beginKao(res.data.list[0].id, res.data.list[0].paperId, this.data.sessionKey, 'feedBack');
  712. }
  713. }
  714. }
  715. }
  716. })
  717. }
  718. },
  719. // 我的积分
  720. goMyPoints() {
  721. wx.navigateTo({
  722. url: '../myPoints/myPoints'
  723. })
  724. },
  725. // 领取结业证
  726. lq() {
  727. if (!this.data.istask) {
  728. wx.showModal({
  729. showCancel: false,
  730. content: "请先去扫描二维码加入班级群吧",
  731. success(res) {
  732. if (res.confirm) {
  733. wx.switchTab({
  734. url: '../myMission/myMission'
  735. })
  736. }
  737. }
  738. })
  739. return false
  740. }
  741. if (!this.data.istask3) {
  742. wx.showModal({
  743. showCancel: false,
  744. content: "您的期末考试还未完成哦!"
  745. })
  746. return false
  747. }
  748. wx.showLoading({
  749. mask: true,
  750. title: '加载中',
  751. })
  752. this.setData({
  753. myCanvasId: this.data.myCanvasId + 1
  754. })
  755. let str = this.data.studentName + "同志于" + this.data.classInfo.beginDate + " 至 " + this.data.classInfo.endDate + "参加学习完成规定培训内容,准予结业,特发此证。"
  756. let strArr = [];
  757. let a = str.slice(0, 16);
  758. let b = str.slice(16, 36);
  759. let c = str.slice(36, 56);
  760. strArr.push(a, b, c);
  761. const ctx = wx.createCanvasContext(this.data.myCanvasId);
  762. ctx.drawImage(this.data.byzsbj, 0, 0, 300, 415); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
  763. ctx.setFillStyle("#000");
  764. ctx.setFontSize(16); //字大小
  765. ctx.setTextAlign('left'); //是否居中显示,参考点画布中线
  766. let leftPositionAarr = [60, 30, 30, 30]
  767. for (let i = 0; i < strArr.length; i++) {
  768. ctx.fillText(strArr[i], leftPositionAarr[i], 160 + i * 30);
  769. }
  770. // ctx.fillText(str, 150, 160); //150:canvas画布宽300,取1/2,中间,280:纵向位置
  771. ctx.draw();
  772. wx.hideLoading();
  773. this.setData({
  774. showzs: true
  775. });
  776. wx.request({
  777. url: app.globalData.publicUrl + '/wx/student/wxGraduation',
  778. method: "post",
  779. data: {
  780. sessionKey: this.data.sessionKey
  781. },
  782. success: (res) => {
  783. console.log(res.data, "领取结业证提交")
  784. }
  785. })
  786. },
  787. // 存储结业证
  788. saveZs() {
  789. wx.canvasToTempFilePath({ //把当前画布指定区域的内容导出生成指定大小的图片
  790. canvasId: this.data.myCanvasId,
  791. success(res) {
  792. wx.authorize({ //向用户发起授权请求
  793. scope: 'scope.writePhotosAlbum', //保存相册授权
  794. success: () => {
  795. wx.saveImageToPhotosAlbum({ //保存图片到系统相册
  796. filePath: res.tempFilePath,
  797. success: () => {
  798. wx.showToast({
  799. title: '图片保存成功'
  800. })
  801. }
  802. })
  803. }
  804. })
  805. }
  806. })
  807. },
  808. // 证书隐藏
  809. onClose1() {
  810. this.setData({
  811. showzs: false
  812. });
  813. },
  814. toPath(id, paperId, answersId, address, status) {
  815. wx.navigateTo({
  816. url: '/pages/' + address + '/' + address + '?id=' + id + '&paperId=' + paperId + '&answersId=' + answersId + '&status=' + status,
  817. })
  818. },
  819. beginKao(id, paperId, sessionKey, address) {
  820. wx.request({
  821. url: app.globalData.publicUrl + '/wx/exam/begin',
  822. method: "post",
  823. data: {
  824. sessionKey: sessionKey,
  825. id: id,
  826. paperId: paperId
  827. },
  828. success: (res) => {
  829. if (res.data.code == 0) {
  830. this.setData({
  831. status: res.data.status
  832. })
  833. this.toPath(id, paperId, res.data.answersId, address);
  834. }
  835. }
  836. })
  837. },
  838. async onShow() {
  839. const sessionKey = await tools.checkSessionAndLogin();
  840. this.setData({
  841. sessionKey
  842. });
  843. this.isRz(sessionKey)
  844. this.getMycourse(sessionKey);
  845. this.getMynotice(sessionKey);
  846. this.checkTaskList1(sessionKey);
  847. }
  848. })