taskDetail.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. // pages/taskDetail/taskDetail.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. const recordManager = wx.getRecorderManager() //录音对象
  6. const audioContext = wx.createInnerAudioContext() //音频播放对象
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. curStu: null,
  13. homeworkId: null,
  14. curVideo: '',
  15. videoFlag: 0,
  16. videoContext: '',
  17. curAudio: '',
  18. curAudioIndex: -1,
  19. audioPause: false,
  20. doTaskFlag: false,
  21. entity: null,
  22. teacherFace: '/images/head.png',
  23. },
  24. bindfullscreenchange: function () {
  25. if (this.data.videoFlag == 0) {
  26. this.setData({
  27. videoFlag: 1
  28. })
  29. } else {
  30. this.setData({
  31. videoFlag: 0,
  32. curVideo: ""
  33. })
  34. }
  35. },
  36. videoShow: function (e) {
  37. this.setData({
  38. curVideo: e.currentTarget.dataset.url
  39. })
  40. this.videoContext.requestFullScreen({ // 设置全屏时视频的方向,不指定则根据宽高比自动判断。
  41. direction: 90 // 屏幕逆时针90度
  42. });
  43. },
  44. showImg: function (e) {
  45. var list = [];
  46. this.data.entity.images.map(o => {
  47. list.push(o.url);
  48. });
  49. wx.previewImage({
  50. urls: list,
  51. current: e.currentTarget.dataset.url
  52. })
  53. },
  54. showDoneImg: function (e) {
  55. var list = [];
  56. this.data.entity.done.images.map(o => {
  57. list.push(o.url);
  58. });
  59. wx.previewImage({
  60. urls: list,
  61. current: e.currentTarget.dataset.url
  62. })
  63. },
  64. showMarkImg: function (e) {
  65. var list = [];
  66. this.data.entity.mark.images.map(o => {
  67. list.push(o.url);
  68. });
  69. wx.previewImage({
  70. urls: list,
  71. current: e.currentTarget.dataset.url
  72. })
  73. },
  74. showAudio: function (e) {
  75. const index = e.currentTarget.dataset.index
  76. if (this.data.curAudioIndex != index) {
  77. this.setData({
  78. curAudioIndex: index,
  79. })
  80. audioContext.src = this.data.entity.records[index].url
  81. audioContext.play()
  82. audioContext.onEnded((res) => {
  83. this.setData({
  84. curAudioIndex: '-1',
  85. })
  86. })
  87. } else {
  88. if (this.data.audioPause) {
  89. audioContext.play()
  90. this.setData({
  91. audioPause: false
  92. })
  93. } else {
  94. audioContext.pause()
  95. this.setData({
  96. audioPause: true
  97. })
  98. }
  99. }
  100. },
  101. bindended: function () {
  102. this.setData({
  103. audioPause: 0,
  104. curAudioIndex: -1,
  105. curAudio: ''
  106. })
  107. },
  108. bindpause: function () {
  109. this.setData({
  110. audioPause: 1
  111. })
  112. },
  113. /**
  114. * 生命周期函数--监听页面加载
  115. */
  116. onLoad: function (options) {
  117. let id = options.id;
  118. this.setData({ homeworkId: id });
  119. // this.audioContext = wx.createAudioContext('audio-play')
  120. this.videoContext = wx.createVideoContext('play-video');// 创建 video 上下文 VideoContext 对象。
  121. const type = options.type
  122. if (type == 0) {
  123. this.setData({
  124. doTaskFlag: true
  125. })
  126. }
  127. this.loadHomework()
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. audioContext.stop()
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. },
  165. loadHomework: function () {
  166. const urls = urlDef.urls;
  167. let stu = wx.getStorageSync('student');
  168. if (stu) {
  169. const body = { 'q.homeworkId': this.data.homeworkId, 'q.studentId': stu.studentId }
  170. // 接收作业(第一次查看有效)
  171. util.apiPost(urls.homework_receive, body).then((rs) => {
  172. console.log('接收作业')
  173. })
  174. util.apiPost(urls.my_homework, body).then((rs) => {
  175. let o = rs[0];
  176. // 解析内容
  177. let workContents;
  178. try {
  179. workContents = JSON.parse(o.homeworkContent);
  180. } catch (e) {
  181. workContents = {
  182. content: o.homeworkContent,
  183. images: [],
  184. records: [],
  185. videos: []
  186. };
  187. console.error(e);
  188. }
  189. o.homeworkContent = workContents.content;
  190. if (o.receiveDate) {
  191. o.receiveDate = o.receiveDate.substring(0, 16).replace('T', ' ')
  192. }
  193. o.images = workContents.images == null ? [] : workContents.images;
  194. o.images.forEach(rs => {
  195. rs.url = urls.oss_file + 'image/' + rs.url
  196. });
  197. o.records = workContents.records == null ? [] : workContents.records;
  198. o.records.forEach(rs => {
  199. rs.url = urls.oss_file + 'file/' + rs.url
  200. });
  201. o.videos = workContents.videos == null ? [] : workContents.videos;
  202. o.videos.forEach(v => {
  203. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  204. v.imgUrl = rs.img
  205. v.playUrl = rs.url
  206. this.reloadVideo(v)
  207. });
  208. });
  209. // 完成情况
  210. let doneContents;
  211. try {
  212. doneContents = o.content ? JSON.parse(o.content) : {};
  213. } catch (e) {
  214. doneContents = {
  215. images: [],
  216. records: [],
  217. videos: [],
  218. content: ''
  219. };
  220. console.error(e);
  221. }
  222. o.done = doneContents;
  223. o.done.images = doneContents.images == null ? [] : doneContents.images;
  224. o.done.images.forEach(rs => {
  225. rs.url = urls.oss_file + 'image/' + rs.url
  226. });
  227. o.done.records = doneContents.records == null ? [] : doneContents.records;
  228. o.done.records.forEach(rs => {
  229. rs.url = urls.oss_file + 'file/' + rs.url
  230. });
  231. o.done.videos = doneContents.videos == null ? [] : doneContents.videos;
  232. o.done.videos.forEach(v => {
  233. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  234. v.imgUrl = rs.img
  235. v.playUrl = rs.url
  236. this.reloadDoneVideo(v)
  237. });
  238. });
  239. // 批阅情况
  240. let markContents;
  241. try {
  242. markContents = o.markResult ? JSON.parse(o.markResult) : {};
  243. } catch (e) {
  244. markContents = {
  245. images: [],
  246. records: [],
  247. videos: [],
  248. content: ''
  249. };
  250. console.error(e);
  251. }
  252. o.mark = markContents;
  253. o.mark.score = o.markScore ? o.markScore : 0
  254. o.mark.images = markContents.images == null ? [] : markContents.images;
  255. o.mark.images.forEach(rs => {
  256. rs.url = urls.oss_file + 'image/' + rs.url
  257. });
  258. o.mark.records = markContents.records == null ? [] : markContents.records;
  259. o.mark.records.forEach(rs => {
  260. rs.url = urls.oss_file + 'file/' + rs.url
  261. });
  262. o.mark.videos = markContents.videos == null ? [] : markContents.videos;
  263. o.mark.videos.forEach(v => {
  264. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  265. v.imgUrl = rs.img
  266. v.playUrl = rs.url
  267. this.reloadMarkVideo(v)
  268. });
  269. });
  270. this.setData({ entity: o })
  271. util.apiPost(urls.get_user_head + '&q.personId=' + rs[0].teacherId).then((fs) => {
  272. if (fs && fs.length > 0) {
  273. this.setData({ teacherFace: urls.oss_file + 'image/' + fs[0] })
  274. }
  275. });
  276. })
  277. }
  278. },
  279. reloadVideo: function (t) {
  280. let o = this.data.entity
  281. let vs = o.videos
  282. vs.map(v => {
  283. if (t.url == v.url) {
  284. v.imgUrl = t.imgUrl
  285. v.playUrl = t.playUrl
  286. }
  287. })
  288. this.setData({ entity: o })
  289. },
  290. reloadDoneVideo: function (t) {
  291. let o = this.data.entity
  292. let vs = o.done.videos
  293. vs.map(v => {
  294. if (t.url == v.url) {
  295. v.imgUrl = t.imgUrl
  296. v.playUrl = t.playUrl
  297. }
  298. })
  299. this.setData({ entity: o })
  300. },
  301. reloadMarkVideo: function (t) {
  302. let o = this.data.entity
  303. let vs = o.mark.videos
  304. vs.map(v => {
  305. if (t.url == v.url) {
  306. v.imgUrl = t.imgUrl
  307. v.playUrl = t.playUrl
  308. }
  309. })
  310. this.setData({ entity: o })
  311. },
  312. toTask: function(e) {
  313. wx.navigateTo({
  314. url: '/pages/doTask/doTask?homeworkId='+ this.data.homeworkId
  315. })
  316. }
  317. })