taskDetail.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. })
  52. },
  53. showDoneImg: function (e) {
  54. var list = [];
  55. this.data.entity.done.images.map(o => {
  56. list.push(o.url);
  57. });
  58. wx.previewImage({
  59. urls: list
  60. })
  61. },
  62. showMarkImg: function (e) {
  63. var list = [];
  64. this.data.entity.mark.images.map(o => {
  65. list.push(o.url);
  66. });
  67. wx.previewImage({
  68. urls: list
  69. })
  70. },
  71. showAudio:function(e){
  72. const index = e.currentTarget.dataset.index
  73. if(this.data.curAudioIndex != index){
  74. this.setData({
  75. curAudioIndex: index,
  76. })
  77. audioContext.src = this.data.audioList[index]
  78. audioContext.play()
  79. audioContext.onEnded((res)=>{
  80. this.setData({
  81. curAudioIndex: '-1',
  82. })
  83. })
  84. }else{
  85. if(this.data.audioPause){
  86. audioContext.play()
  87. this.setData({
  88. audioPause: false
  89. })
  90. } else {
  91. audioContext.pause()
  92. this.setData({
  93. audioPause: true
  94. })
  95. }
  96. }
  97. },
  98. bindended: function () {
  99. this.setData({
  100. audioPause: 0,
  101. curAudioIndex: -1,
  102. curAudio: ''
  103. })
  104. },
  105. bindpause: function () {
  106. this.setData({
  107. audioPause: 1
  108. })
  109. },
  110. /**
  111. * 生命周期函数--监听页面加载
  112. */
  113. onLoad: function (options) {
  114. let id = options.id;
  115. this.setData({ homeworkId: id });
  116. // this.audioContext = wx.createAudioContext('audio-play')
  117. this.videoContext = wx.createVideoContext('play-video');// 创建 video 上下文 VideoContext 对象。
  118. const type = options.type
  119. if (type == 0) {
  120. this.setData({
  121. doTaskFlag: true
  122. })
  123. }
  124. this.loadHomework()
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload: function () {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh: function () {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom: function () {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage: function () {
  160. },
  161. loadHomework: function () {
  162. const urls = urlDef.urls;
  163. let stu = wx.getStorageSync('student');
  164. if (stu) {
  165. const body = { 'q.homeworkId': this.data.homeworkId, 'q.studentId': stu.studentId }
  166. // 接收作业(第一次查看有效)
  167. util.apiPost(urls.homework_receive, body).then((rs) => {
  168. console.log('接收作业')
  169. })
  170. util.apiPost(urls.my_homework, body).then((rs) => {
  171. let o = rs[0];
  172. // 解析内容
  173. let workContents;
  174. try {
  175. workContents = JSON.parse(o.homeworkContent);
  176. } catch (e) {
  177. workContents = {
  178. content: o.homeworkContent,
  179. images: [],
  180. records: [],
  181. videos: []
  182. };
  183. console.error(e);
  184. }
  185. o.homeworkContent = workContents.content;
  186. if (o.receiveDate) {
  187. o.receiveDate = o.receiveDate.substring(0, 16).replace('T', ' ')
  188. }
  189. o.images = workContents.images == null ? [] : workContents.images;
  190. o.images.forEach(rs => {
  191. rs.url = urls.oss_file + 'image/' + rs.url
  192. });
  193. o.records = workContents.records == null ? [] : workContents.records;
  194. o.records.forEach(rs => {
  195. rs.url = urls.oss_file + 'file/' + rs.url
  196. });
  197. o.videos = workContents.videos == null ? [] : workContents.videos;
  198. o.videos.forEach(v => {
  199. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  200. v.imgUrl = rs.img
  201. v.playUrl = rs.url
  202. this.reloadVideo(v)
  203. });
  204. });
  205. // 完成情况
  206. let doneContents;
  207. try {
  208. doneContents = o.content ? JSON.parse(o.content) : {};
  209. } catch (e) {
  210. doneContents = {
  211. images: [],
  212. records: [],
  213. videos: [],
  214. content: ''
  215. };
  216. console.error(e);
  217. }
  218. o.done = doneContents;
  219. o.done.images = doneContents.images == null ? [] : doneContents.images;
  220. o.done.images.forEach(rs => {
  221. rs.url = urls.oss_file + 'image/' + rs.url
  222. });
  223. o.done.records = doneContents.records == null ? [] : doneContents.records;
  224. o.done.records.forEach(rs => {
  225. rs.url = urls.oss_file + 'file/' + rs.url
  226. });
  227. o.done.videos = doneContents.videos == null ? [] : doneContents.videos;
  228. o.done.videos.forEach(v => {
  229. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  230. v.imgUrl = rs.img
  231. v.playUrl = rs.url
  232. this.reloadDoneVideo(v)
  233. });
  234. });
  235. // 批阅情况
  236. let markContents;
  237. try {
  238. markContents = o.markResult ? JSON.parse(o.markResult) : {};
  239. } catch (e) {
  240. markContents = {
  241. images: [],
  242. records: [],
  243. videos: [],
  244. content: ''
  245. };
  246. console.error(e);
  247. }
  248. o.mark = markContents;
  249. o.mark.score = o.markScore ? o.markScore : 0
  250. o.mark.images = markContents.images == null ? [] : markContents.images;
  251. o.mark.images.forEach(rs => {
  252. rs.url = urls.oss_file + 'image/' + rs.url
  253. });
  254. o.mark.records = markContents.records == null ? [] : markContents.records;
  255. o.mark.records.forEach(rs => {
  256. rs.url = urls.oss_file + 'file/' + rs.url
  257. });
  258. o.mark.videos = markContents.videos == null ? [] : markContents.videos;
  259. o.mark.videos.forEach(v => {
  260. util.apiPost(urls.video_loadInfo + v.url).then((rs) => {
  261. v.imgUrl = rs.img
  262. v.playUrl = rs.url
  263. this.reloadMarkVideo(v)
  264. });
  265. });
  266. this.setData({ entity: o })
  267. util.apiPost(urls.get_user_head + '&q.personId=' + rs[0].teacherId).then((fs) => {
  268. if (fs && fs.length > 0) {
  269. this.setData({ teacherFace: urls.oss_file + 'image/' + fs[0] })
  270. }
  271. });
  272. })
  273. }
  274. },
  275. reloadVideo: function (t) {
  276. let o = this.data.entity
  277. let vs = o.videos
  278. vs.map(v => {
  279. if (t.url == v.url) {
  280. v.imgUrl = t.imgUrl
  281. v.playUrl = t.playUrl
  282. }
  283. })
  284. this.setData({ entity: o })
  285. },
  286. reloadDoneVideo: function (t) {
  287. let o = this.data.entity
  288. let vs = o.done.videos
  289. vs.map(v => {
  290. if (t.url == v.url) {
  291. v.imgUrl = t.imgUrl
  292. v.playUrl = t.playUrl
  293. }
  294. })
  295. this.setData({ entity: o })
  296. },
  297. reloadMarkVideo: function (t) {
  298. let o = this.data.entity
  299. let vs = o.mark.videos
  300. vs.map(v => {
  301. if (t.url == v.url) {
  302. v.imgUrl = t.imgUrl
  303. v.playUrl = t.playUrl
  304. }
  305. })
  306. this.setData({ entity: o })
  307. }
  308. })