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.audioList[index]
  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. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh: function () {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom: function () {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {
  163. },
  164. loadHomework: function () {
  165. const urls = urlDef.urls;
  166. let stu = wx.getStorageSync('student');
  167. if (stu) {
  168. const body = { 'q.homeworkId': this.data.homeworkId, 'q.studentId': stu.studentId }
  169. // 接收作业(第一次查看有效)
  170. util.apiPost(urls.homework_receive, body).then((rs) => {
  171. console.log('接收作业')
  172. })
  173. util.apiPost(urls.my_homework, body).then((rs) => {
  174. let o = rs[0];
  175. // 解析内容
  176. let workContents;
  177. try {
  178. workContents = JSON.parse(o.homeworkContent);
  179. } catch (e) {
  180. workContents = {
  181. content: o.homeworkContent,
  182. images: [],
  183. records: [],
  184. videos: []
  185. };
  186. console.error(e);
  187. }
  188. o.homeworkContent = workContents.content;
  189. if (o.receiveDate) {
  190. o.receiveDate = o.receiveDate.substring(0, 16).replace('T', ' ')
  191. }
  192. o.images = workContents.images == null ? [] : workContents.images;
  193. o.images.forEach(rs => {
  194. rs.url = urls.oss_file + 'image/' + rs.url
  195. });
  196. o.records = workContents.records == null ? [] : workContents.records;
  197. o.records.forEach(rs => {
  198. rs.url = urls.oss_file + 'file/' + rs.url
  199. });
  200. o.videos = workContents.videos == null ? [] : workContents.videos;
  201. o.videos.forEach(v => {
  202. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  203. v.imgUrl = rs.img
  204. v.playUrl = rs.url
  205. this.reloadVideo(v)
  206. });
  207. });
  208. // 完成情况
  209. let doneContents;
  210. try {
  211. doneContents = o.content ? JSON.parse(o.content) : {};
  212. } catch (e) {
  213. doneContents = {
  214. images: [],
  215. records: [],
  216. videos: [],
  217. content: ''
  218. };
  219. console.error(e);
  220. }
  221. o.done = doneContents;
  222. o.done.images = doneContents.images == null ? [] : doneContents.images;
  223. o.done.images.forEach(rs => {
  224. rs.url = urls.oss_file + 'image/' + rs.url
  225. });
  226. o.done.records = doneContents.records == null ? [] : doneContents.records;
  227. o.done.records.forEach(rs => {
  228. rs.url = urls.oss_file + 'file/' + rs.url
  229. });
  230. o.done.videos = doneContents.videos == null ? [] : doneContents.videos;
  231. o.done.videos.forEach(v => {
  232. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  233. v.imgUrl = rs.img
  234. v.playUrl = rs.url
  235. this.reloadDoneVideo(v)
  236. });
  237. });
  238. // 批阅情况
  239. let markContents;
  240. try {
  241. markContents = o.markResult ? JSON.parse(o.markResult) : {};
  242. } catch (e) {
  243. markContents = {
  244. images: [],
  245. records: [],
  246. videos: [],
  247. content: ''
  248. };
  249. console.error(e);
  250. }
  251. o.mark = markContents;
  252. o.mark.score = o.markScore ? o.markScore : 0
  253. o.mark.images = markContents.images == null ? [] : markContents.images;
  254. o.mark.images.forEach(rs => {
  255. rs.url = urls.oss_file + 'image/' + rs.url
  256. });
  257. o.mark.records = markContents.records == null ? [] : markContents.records;
  258. o.mark.records.forEach(rs => {
  259. rs.url = urls.oss_file + 'file/' + rs.url
  260. });
  261. o.mark.videos = markContents.videos == null ? [] : markContents.videos;
  262. o.mark.videos.forEach(v => {
  263. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  264. v.imgUrl = rs.img
  265. v.playUrl = rs.url
  266. this.reloadMarkVideo(v)
  267. });
  268. });
  269. this.setData({ entity: o })
  270. util.apiPost(urls.get_user_head + '&q.personId=' + rs[0].teacherId).then((fs) => {
  271. if (fs && fs.length > 0) {
  272. this.setData({ teacherFace: urls.oss_file + 'image/' + fs[0] })
  273. }
  274. });
  275. })
  276. }
  277. },
  278. reloadVideo: function (t) {
  279. let o = this.data.entity
  280. let vs = o.videos
  281. vs.map(v => {
  282. if (t.url == v.url) {
  283. v.imgUrl = t.imgUrl
  284. v.playUrl = t.playUrl
  285. }
  286. })
  287. this.setData({ entity: o })
  288. },
  289. reloadDoneVideo: function (t) {
  290. let o = this.data.entity
  291. let vs = o.done.videos
  292. vs.map(v => {
  293. if (t.url == v.url) {
  294. v.imgUrl = t.imgUrl
  295. v.playUrl = t.playUrl
  296. }
  297. })
  298. this.setData({ entity: o })
  299. },
  300. reloadMarkVideo: function (t) {
  301. let o = this.data.entity
  302. let vs = o.mark.videos
  303. vs.map(v => {
  304. if (t.url == v.url) {
  305. v.imgUrl = t.imgUrl
  306. v.playUrl = t.playUrl
  307. }
  308. })
  309. this.setData({ entity: o })
  310. },
  311. toTask: function(e) {
  312. wx.navigateTo({
  313. url: '/pages/doTask/doTask?homeworkId='+ this.data.homeworkId
  314. })
  315. }
  316. })