detail.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. const _Http = getApp().globalData.http,
  2. MFT = require("../../utils/matchingFeilType");
  3. let sat_coursewareid = null;
  4. Page({
  5. data: {
  6. },
  7. onLoad(options) {
  8. sat_coursewareid = options.id;
  9. this.getDetail()
  10. },
  11. getDetail() {
  12. _Http.basic({
  13. "classname": "saletool.courseware.courseware",
  14. "method": "selectDetail",
  15. "content": {
  16. sat_coursewareid
  17. }
  18. }).then(res => {
  19. console.log("详情", res)
  20. if (res.msg != '成功') return wx.showToast({
  21. title: res.msg,
  22. icon: "none"
  23. });
  24. let videoList = [], //视频附件列表
  25. attinfos = []; //其他附件
  26. if (res.data.attinfos.length) MFT.fileList(res.data.attinfos).filter(v => {
  27. if (v.usetype != 'cover') v.fileType == 'video' ? videoList.push(v) : attinfos.push(v)
  28. });
  29. this.setData({
  30. videoList,
  31. attinfos,
  32. play: videoList[0] || null,
  33. detailData: res.data,
  34. });
  35. })
  36. },
  37. /* 选择播放视频 */
  38. playItem(e) {
  39. const {
  40. item
  41. } = e.currentTarget.dataset;
  42. if (this.data.play.attachmentid == item.attachmentid) return;
  43. this.setData({
  44. play: item
  45. })
  46. },
  47. /* 播放结束更改状态 */
  48. onEnded() {
  49. let play = this.data.play;
  50. if (play.status == '已学习') return;
  51. _Http.basic({
  52. "classname": "saletool.courseware.courseware",
  53. "method": "updateAttInfoLearnLog",
  54. "content": {
  55. sat_coursewareid,
  56. attachmentid: play.attachmentid
  57. }
  58. })
  59. play.status = '已学习';
  60. this.data.videoList.find(v => v.attachmentid == play.attachmentid).status = '已学习';
  61. this.setData({
  62. play,
  63. videoList: this.data.videoList
  64. })
  65. },
  66. /* 打开文档 */
  67. openDoc(e) {
  68. const {
  69. item
  70. } = e.currentTarget.dataset,
  71. that = this;
  72. if (item.fileType == 'image') {
  73. wx.previewImage({
  74. urls: [item.url],
  75. })
  76. } else {
  77. wx.showLoading({
  78. title: '打开中...',
  79. mask: true
  80. })
  81. wx.downloadFile({
  82. // 示例 url,并非真实存在
  83. url: item.url,
  84. success: function (res) {
  85. const filePath = res.tempFilePath
  86. wx.openDocument({
  87. filePath: filePath,
  88. success: function (res) {
  89. console.log('打开文档成功')
  90. wx.hideLoading()
  91. },
  92. fail(err) {
  93. console.log(err)
  94. that.copyUrl(item)
  95. wx.hideLoading()
  96. }
  97. })
  98. },
  99. fail(err) {
  100. console.log(err)
  101. that.copyUrl(item)
  102. wx.hideLoading()
  103. }
  104. })
  105. };
  106. if (item.status == '已学习') return;
  107. _Http.basic({
  108. "classname": "saletool.courseware.courseware",
  109. "method": "updateAttInfoLearnLog",
  110. "content": {
  111. sat_coursewareid,
  112. attachmentid: item.attachmentid
  113. }
  114. });
  115. this.data.attinfos.find(v => v.attachmentid == item.attachmentid).status = '已学习';
  116. this.setData({
  117. attinfos: this.data.attinfos
  118. })
  119. },
  120. copyUrl(item) {
  121. wx.showModal({
  122. title: '提示',
  123. content: `该文件不支持在线预览,是否复制链接到剪切板在浏览器中尝试打开文件`,
  124. confirmText: "复制",
  125. complete: (res) => {
  126. if (res.confirm) wx.setClipboardData({
  127. data: item.url,
  128. success(s) {
  129. wx.showToast({
  130. title: '已将文件地址复制到剪切板',
  131. icon: "none",
  132. mask: true
  133. })
  134. }
  135. })
  136. }
  137. })
  138. },
  139. toExam() {
  140. let that = this;
  141. _Http.basic({
  142. "classname": "saletool.courseware.coursewaretest",
  143. "method": "queryTestList",
  144. "content": {
  145. "pageNumber": 1,
  146. "pageSize": 999,
  147. sat_coursewareid,
  148. "where": {
  149. "status": ""
  150. }
  151. }
  152. }).then(res => {
  153. if (res.msg != '成功') return wx.showToast({
  154. title: res.msg,
  155. icon: "none"
  156. });
  157. if (res.data.length == 0) {
  158. this.createTest();
  159. } else {
  160. let status = res.data[res.data.length - 1].status;
  161. if (status == '已完成') {
  162. wx.showModal({
  163. title: '提示',
  164. content: '当前课程已完成考试,是否进入新的考试?',
  165. confirmText: "进入考试",
  166. complete: ({
  167. confirm
  168. }) => {
  169. if (confirm) that.createTest();
  170. }
  171. });
  172. } else if (status == '未完成') {
  173. wx.showModal({
  174. title: '提示',
  175. content: '上一次考试未完成,是否继续考试?',
  176. confirmText: "继续",
  177. cancelText: "重新考试",
  178. complete: ({
  179. cancel,
  180. confirm
  181. }) => {
  182. if (cancel) that.createTest();
  183. if (confirm) wx.navigateTo({
  184. url: '/pages/exam/detail?id=' + res.data[res.data.length - 1].sat_courseware_testid,
  185. })
  186. }
  187. })
  188. }
  189. }
  190. })
  191. },
  192. createTest() {
  193. _Http.basic({
  194. "classname": "saletool.courseware.coursewaretest",
  195. "method": "createTest",
  196. "content": {
  197. sat_coursewareid
  198. }
  199. }).then(s => {
  200. console.log("开始考试", s)
  201. if (s.msg != '成功') return wx.showToast({
  202. title: s.msg,
  203. icon: "none"
  204. })
  205. wx.navigateTo({
  206. url: '/pages/exam/detail?id=' + s.data.sat_courseware_testid,
  207. })
  208. })
  209. }
  210. })