growUp.js 5.9 KB

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