growUp.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // pages/growUp/growUp.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. studentId: null,
  11. orgId: null,
  12. curVideo: '',
  13. videoFlag: 0,
  14. videoContext: '',
  15. curAudio: '',
  16. curAudioIndex: -1,
  17. audioPause: 0,
  18. list: [
  19. ],
  20. loading: '上拉加载',
  21. flag: 0,
  22. pageNum: 0,
  23. hasNextPage: true,
  24. },
  25. bindfullscreenchange: function () {
  26. if (this.data.videoFlag == 0) {
  27. this.setData({
  28. videoFlag: 1
  29. })
  30. } else {
  31. this.setData({
  32. videoFlag: 0,
  33. curVideo: ""
  34. })
  35. }
  36. },
  37. videoShow: function (e) {
  38. this.setData({
  39. curVideo: e.currentTarget.dataset.url
  40. })
  41. this.videoContext.requestFullScreen({ // 设置全屏时视频的方向,不指定则根据宽高比自动判断。
  42. direction: 90 // 屏幕逆时针90度
  43. });
  44. },
  45. showImg: function (e) {
  46. let id = e.currentTarget.dataset.id
  47. var images = [];
  48. this.data.list.map(it => {
  49. if (it.id == id) {
  50. let imgs = it.images
  51. imgs.map(i => {
  52. images.push(i.url)
  53. })
  54. }
  55. })
  56. wx.previewImage({
  57. urls: images
  58. })
  59. },
  60. audioShow: function (e) {
  61. if (this.data.audioPause == 0 && this.data.curAudioIndex != e.currentTarget.dataset.index) {//播放语音,切换
  62. this.setData({
  63. curAudio: ""
  64. })
  65. this.setData({
  66. curAudioIndex: e.currentTarget.dataset.index,
  67. curAudio: e.currentTarget.dataset.url,
  68. })
  69. this.audioContext.play()
  70. this.setData({
  71. audioPause: 0
  72. })
  73. } else if (this.data.audioPause == 1 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停后恢复播放
  74. this.audioContext.play()
  75. this.setData({
  76. audioPause: 0
  77. })
  78. } else if (this.data.audioPause == 0 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停播放
  79. this.audioContext.pause()
  80. this.setData({
  81. audioPause: 1
  82. })
  83. }
  84. },
  85. bindended: function () {
  86. this.setData({
  87. audioPause: 0,
  88. curAudioIndex: -1,
  89. curAudio: ''
  90. })
  91. },
  92. bindpause: function () {
  93. this.setData({
  94. audioPause: 1
  95. })
  96. },
  97. /**
  98. * 生命周期函数--监听页面加载
  99. */
  100. onLoad: function (options) {
  101. let sid = options.studentId
  102. let oid = options.orgId
  103. if (sid == null || oid == null) {
  104. let stu = wx.getStorageSync('student')
  105. sid = stu.studentId
  106. oid = stu.orgId
  107. }
  108. this.audioContext = wx.createAudioContext('audio-play')
  109. this.videoContext = wx.createVideoContext('play-video');// 创建 video 上下文 VideoContext 对象。
  110. this.setData({ studentId: sid, orgId: oid })
  111. this.queryList()
  112. },
  113. /**
  114. * 生命周期函数--监听页面初次渲染完成
  115. */
  116. onReady: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面显示
  120. */
  121. onShow: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面隐藏
  125. */
  126. onHide: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面卸载
  130. */
  131. onUnload: function () {
  132. },
  133. /**
  134. * 页面相关事件处理函数--监听用户下拉动作
  135. */
  136. onPullDownRefresh: function () {
  137. },
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom: function () {
  142. if (this.data.hasNextPage) {
  143. let pn = this.data.pageNum
  144. this.setData({ loading: '加载中', 'pageNum': ++pn })
  145. this.queryList()
  146. }
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. return {
  153. title: '成长足迹',
  154. path: '/pages/growUp/growUp?studentId=' + this.data.studentId + '&orgId=' + this.data.orgId,
  155. }
  156. },
  157. queryList: function () {
  158. const urls = urlDef.urls;
  159. let params = { 'q.studentId': this.data.studentId, 'q.orgId': this.data.orgId }
  160. params.pageNum = this.data.pageNum
  161. util.apiPost(urls.query_student_evaluate, params).then(rs => {
  162. let list = rs.list
  163. list.map(it => {
  164. if (it.beginTime) {
  165. it.beginTime = it.beginTime.replace('T', ' ').substring(0, 16)
  166. }
  167. if (it.type === '1') {
  168. util.apiPost(urls.query_student_star + '&q.orgId=' + this.data.orgId + '&q.studentId='
  169. + this.data.studentId + '&q.headId=' + it.id).then((st) => {
  170. it.star = st;
  171. }, e => {
  172. console.log(e);
  173. });
  174. let attachs;
  175. try {
  176. if (it.evaluateAttach) {
  177. attachs = JSON.parse(it.evaluateAttach);
  178. } else {
  179. attachs = {};
  180. }
  181. } catch (e) {
  182. console.error(JSON.stringify(e));
  183. }
  184. if (attachs) {
  185. it.images = attachs.images ? attachs.images : [];
  186. it.videos = attachs.videos ? attachs.videos : [];
  187. it.records = attachs.records ? attachs.records : [];
  188. it.images.forEach(rs => {
  189. rs.url = urls.oss_file + 'image/' + rs.url
  190. });
  191. it.records.forEach(rs => {
  192. rs.url = urls.oss_file + 'file/' + rs.url
  193. });
  194. // 加载视频封面
  195. it.videos.forEach(r => {
  196. util.apiPost(urls.video_loadInfo + r.url).then((rs) => {
  197. r.imgUrl = rs.img;
  198. r.playUrl = rs.url;
  199. this.reloadVideos(it)
  200. });
  201. });
  202. }
  203. } else if (it.type === '4') {
  204. util.apiPost(urls.video_loadInfo + it.evaluateAttach).then((rs) => {
  205. it.imgUrl = rs.img;
  206. it.playUrl = rs.url;
  207. this.reloadVideos(it)
  208. });
  209. }
  210. })
  211. this.setData({
  212. 'hasNextPage': rs.hasNextPage,
  213. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  214. 'list': this.data.list.concat(list)
  215. })
  216. })
  217. },
  218. reloadVideos: function (t) {
  219. let list = this.data.list;
  220. list.map(it => {
  221. if (it.id == t.id) {
  222. it = t;
  223. }
  224. })
  225. this.setData({ list: list })
  226. }
  227. })