homework_report.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. // pages/homework_report/homework_report.js
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. baseImgUrl: app.globalData.baseImgUrl,
  9. thumbnail: app.globalData.thumbnail,
  10. yuwen: '../../image/yuwen4.0.png',
  11. math: '../../image/shuxue4.0.png',
  12. English: '../../image/yingyu4.0.png',
  13. physics: '../../image/wuli.png',
  14. chemistry: '../../image/huaxue.png',
  15. labelRed: '../../image/biao_qian_hong.png',
  16. labelGay: '../../image/biao_qian_hui.png',
  17. idx:0,
  18. isMohu:false,
  19. voiceKeyIndex:-1,
  20. imgNum:3,
  21. isPlay:0,
  22. times:0,
  23. isMusic:0,
  24. isEnd:0,
  25. learningState: [{
  26. "name": "积极性",
  27. "type": 1
  28. },
  29. {
  30. "name": "自律性",
  31. "type": 2
  32. },
  33. {
  34. "name": "专注度",
  35. "type": 3
  36. },
  37. {
  38. "name": "作业速度",
  39. "type": 2
  40. }
  41. ],
  42. subjectList: []
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. this.setData({ options })
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. this.getHomeworkReport()
  60. },
  61. /**
  62. * 生命周期函数--监听页面隐藏
  63. */
  64. onHide: function () {
  65. let pages = getCurrentPages();
  66. const {isMusic,voiceKeyList, voiceKeyIndex}=this.data
  67. console.log( '生命周期函数--监听页面隐藏'+isMusic)
  68. if(isMusic){
  69. this.stopPlay()
  70. this.innerAudioContext.stop();
  71. clearInterval(this.setIntervalAudio)
  72. this.pauseAudio(voiceKeyList, voiceKeyIndex)
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. const {isMusic,voiceKeyList, voiceKeyIndex}=this.data
  80. console.log( '生命周期函数--监听页面卸载'+isMusic)
  81. if(isMusic){
  82. this.stopPlay()
  83. this.innerAudioContext.stop();
  84. clearInterval(this.setIntervalAudio)
  85. this.pauseAudio(voiceKeyList, voiceKeyIndex)
  86. }
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {
  92. },
  93. /**
  94. * 页面上拉触底事件的处理函数
  95. */
  96. onReachBottom: function () {
  97. },
  98. /**
  99. * 底部导航跳转
  100. */
  101. redirectCtl: app.redirectCtl,
  102. /**
  103. * 路由跳转
  104. */
  105. navigateCtl: app.navigateCtl,
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. const { vipId, date } = this.data.options
  111. return {
  112. title: `作业反馈报告`,
  113. path: `pages/homework_report/homework_report?type=8&vipId=${vipId}&date=${date}`,
  114. success: res => {
  115. wx.showToast({
  116. title: '转发成功',
  117. icon: 'success'
  118. })
  119. },
  120. fail: res => {
  121. wx.showToast({
  122. title: '转发失败',
  123. icon: 'none'
  124. })
  125. }
  126. }
  127. },
  128. //查看图片
  129. viewImageCtl: app.viewImageCtl,
  130. /**
  131. * 查看评语
  132. */
  133. getWords:function(e){
  134. const {method} = e.currentTarget.dataset;
  135. wx.navigateTo({
  136. url: `../remark/remark?method=${JSON.stringify(method)}`,
  137. success: res => { },
  138. fail: res => {
  139. wx.showToast({
  140. title: '跳转失败',
  141. icon: 'none'
  142. })
  143. }
  144. })
  145. },
  146. // 获取作业报告
  147. getHomeworkReport:function(){
  148. const postData = { fn: this.getHomeworkReport, param: { ...arguments } }
  149. const { idx, options } = this.data
  150. const { vipId, date }=options;
  151. wx.showLoading({
  152. title: '加载中',
  153. })
  154. const fn = res => {
  155. const { abstractSituation = {}, correctList = [], learningState = [], isMainParent} = res.data;
  156. wx.hideLoading();
  157. const {voiceKeyList}=abstractSituation
  158. const voiceListTemp = (res => {
  159. for (let i in res) {
  160. res[i].voiceType = 0
  161. res[i].durationNum = 0;
  162. res[i].progress = 0;
  163. res[i].isHands = false;
  164. }
  165. return res
  166. })(voiceKeyList)
  167. const correctListTemp = (res => {
  168. for (let i in res) {
  169. const { homeworkList, homeworkCommentList } = res[i];
  170. const arr = { homeworkList, homeworkCommentList }
  171. const homeworkListTemp = [], wrongItemListTemp = []
  172. for (let j in homeworkList) {
  173. homeworkListTemp.push({
  174. photoKey: homeworkList[j].homeworkPictureUrl, isVague: homeworkList[j].isVague, status: homeworkList[j].status
  175. })
  176. }
  177. for (let j in homeworkCommentList) {
  178. wrongItemListTemp.push({
  179. photoKey: homeworkCommentList[j].homeworkCommentUrl,
  180. compositionCommentModuleList: homeworkCommentList[j].compositionCommentModuleList,
  181. isComposition: homeworkCommentList[j].isComposition,
  182. })
  183. }
  184. res[i]['homeworkList'] = homeworkListTemp
  185. res[i]['homeworkCommentList'] = wrongItemListTemp
  186. }
  187. return res
  188. })(correctList)
  189. this.setData({ abstractSituation, correctList, learningState, isMainParent,voiceKeyList:voiceListTemp});
  190. // console.log(abstractSituation)
  191. this.clickSubject(idx);
  192. }
  193. app.post('/api/parents/parents/V2/homeworkReport4', { vipId, date}, 0, postData ).then(fn)
  194. },
  195. cutItems:function(e){
  196. const { idx } = e.target.dataset;
  197. this.setData({ idx })
  198. this.clickSubject(idx)
  199. },
  200. // 切换科目
  201. clickSubject:function(idx){
  202. const { correctList}=this.data;
  203. var temp={};
  204. var workImg, mistakeImg = [];
  205. for (var i in correctList){
  206. if (correctList[idx].subject == correctList[i].subject){
  207. for (let j in correctList[i].homeworkList){
  208. if (correctList[i].homeworkList[j].isVague == 0) {
  209. this.setData({ isMohu: true })
  210. }else{
  211. this.setData({ isMohu: false })
  212. }
  213. }
  214. this.setData({ list: correctList[i] })
  215. }
  216. }
  217. },
  218. /**
  219. * 开始计时
  220. */
  221. startSetInter: function () {
  222. let time = 1000;
  223. var that = this;
  224. let { times,isEnd} = this.data;
  225. // console.log(times)
  226. var setTime = this.data.times + 1
  227. console.log(setTime)
  228. that.setData({ times: setTime,imgNum:setTime })
  229. that.data.setInter = setTimeout(this.startSetInter, time);
  230. if (setTime>2) {
  231. that.endSetInter();
  232. if(setTime==3&&!isEnd){
  233. setTimeout(
  234. function () {
  235. that.startSetInter()
  236. }, 1000)
  237. }
  238. }
  239. },
  240. /**
  241. * 结束计时
  242. */
  243. endSetInter:function(){
  244. var that = this;
  245. clearTimeout(that.data.setInter)
  246. that.setData({ times: 0})
  247. },
  248. /**
  249. * 结束计时
  250. */
  251. stopPlay:function(){
  252. var that = this;
  253. that.endSetInter();
  254. that.setData({ imgNum:3})
  255. console.log('结束')
  256. },
  257. /**
  258. * 音频控制按钮
  259. */
  260. audioCtl: function (e) {
  261. const { index } = e.currentTarget.dataset
  262. const { voiceKeyList, voiceKeyIndex} = this.data
  263. const { voiceType } = voiceKeyList[index];
  264. this.setData({isMusic:1})
  265. var that=this
  266. // console.log(index,voiceKeyIndex,voiceType)
  267. if (index == voiceKeyIndex) {
  268. if (voiceType == 1) {
  269. console.log('1---停止')
  270. that.stopPlay()
  271. if (this.innerAudioContext) this.innerAudioContext.stop()
  272. } else if (voiceType == 2) {
  273. console.log('1---播放')
  274. if (this.innerAudioContext) this.innerAudioContext.play()
  275. } else {
  276. this.audioManager()
  277. }
  278. } else {
  279. const temp = {}
  280. temp['voiceKeyIndex'] = index
  281. this.setData(temp)
  282. this.audioManager()
  283. }
  284. },
  285. /**
  286. * 开始播放语音
  287. */
  288. playAudio: function (voiceKeyList, voiceKeyIndex) {
  289. const { voiceKey, voiceType, durationNum, duration, progress } = voiceKeyList[voiceKeyIndex];
  290. console.log('开始播放语音')
  291. this.startSetInter()
  292. const temp = {}
  293. temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 1;
  294. temp[`voiceKeyList[${voiceKeyIndex}].isHands`] = true;
  295. this.setData(temp)
  296. let d = voiceType == 2 ? durationNum - 1 : duration
  297. if (this.setIntervalAudio) {
  298. clearInterval(this.setIntervalAudio)
  299. }
  300. // console.log(d)
  301. this.setIntervalAudio = setInterval(() => {
  302. if (d > 0) {
  303. d--
  304. temp[`voiceKeyList[${voiceKeyIndex}].durationNum`] = d
  305. temp[`voiceKeyList[${voiceKeyIndex}].progress`] = Math.floor((duration - d) / duration * 100)
  306. this.setData(temp)
  307. } else {
  308. clearInterval(this.setIntervalAudio)
  309. }
  310. }, 1000)
  311. },
  312. /**
  313. * 暂停播放语音
  314. */
  315. pauseAudio: function (voiceKeyList, voiceKeyIndex) {
  316. console.log('2---停止')
  317. const {isEnd}=this.data
  318. this.setData({isEnd:!isEnd})
  319. const temp = {}
  320. temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 2
  321. this.setData(temp)
  322. },
  323. /**
  324. * 结束播放语音
  325. */
  326. endAudio: function (voiceKeyList, voiceKeyIndex, listIndex) {
  327. console.log('3---停止')
  328. const {isEnd}=this.data
  329. this.setData({isEnd:!isEnd})
  330. const { voiceKey, voiceType, durationNum, duration, progress } = voiceKeyList[voiceKeyIndex]
  331. this.stopPlay()
  332. const temp = {}
  333. temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 0
  334. temp[`voiceKeyList[${voiceKeyIndex}].duration`] = duration
  335. temp[`voiceKeyList[${voiceKeyIndex}].progress`] = 0
  336. temp[`voiceKeyList[${voiceKeyIndex}].isHands`] = false;
  337. this.setData(temp)
  338. },
  339. /**
  340. * 语音播放管理器
  341. */
  342. audioManager: function () {
  343. const { voiceKeyList, voiceKeyIndex, baseImgUrl } = this.data
  344. if (this.innerAudioContext) {
  345. this.innerAudioContext.destroy()
  346. clearInterval(this.setIntervalAudio)
  347. for (const i in voiceKeyList) {
  348. const temp = {};
  349. temp[`voiceKeyList[${i}].voiceType`] = 0;
  350. this.setData(temp)
  351. }
  352. }
  353. const { voiceKey } = voiceKeyList[voiceKeyIndex]
  354. if (!voiceKey) return
  355. this.innerAudioContext = wx.createInnerAudioContext()
  356. this.innerAudioContext.autoplay = true
  357. this.innerAudioContext.src = baseImgUrl+voiceKey
  358. console.log(baseImgUrl + voiceKey)
  359. this.innerAudioContext.onPlay(() => {
  360. this.playAudio(voiceKeyList, voiceKeyIndex)
  361. })
  362. this.innerAudioContext.onStop(() => {
  363. clearInterval(this.setIntervalAudio)
  364. this.pauseAudio(voiceKeyList, voiceKeyIndex)
  365. })
  366. this.innerAudioContext.onEnded(() => {
  367. this.innerAudioContext.destroy()
  368. clearInterval(this.setIntervalAudio)
  369. this.endAudio(voiceKeyList, voiceKeyIndex)
  370. })
  371. this.innerAudioContext.onError(res => {
  372. console.log(res)
  373. wx.showToast({
  374. title: '播放语音失败',
  375. icon: 'none'
  376. })
  377. })
  378. },
  379. /**
  380. * 结束语音
  381. */
  382. nextAudio: function () {
  383. const { voiceKeyList, voiceKeyIndex} = this.data;
  384. this.stopPlay()
  385. if (voiceKeyIndex != -1 && listIndex != -1) {
  386. const { voiceKey, voiceType, durationNum, duration, progress } = voiceKeyList[voiceKeyIndex]
  387. const temp = {}
  388. temp[`voiceKeyList[${voiceKeyIndex}].voiceType`] = 0
  389. temp[`voiceKeyList[${voiceKeyIndex}].duration`] = duration
  390. temp[`voiceKeyList[${voiceKeyIndex}].progress`] = 0
  391. if (this.innerAudioContext) this.innerAudioContext.pause()
  392. this.setData(temp)
  393. }
  394. },
  395. })