growUp.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. current: e.currentTarget.dataset.url
  59. })
  60. },
  61. audioShow: function (e) {
  62. if (this.data.audioPause == 0 && this.data.curAudioIndex != e.currentTarget.dataset.index) {//播放语音,切换
  63. this.setData({
  64. curAudio: ""
  65. })
  66. this.setData({
  67. curAudioIndex: e.currentTarget.dataset.index,
  68. curAudio: e.currentTarget.dataset.url,
  69. })
  70. this.audioContext.play()
  71. this.setData({
  72. audioPause: 0
  73. })
  74. } else if (this.data.audioPause == 1 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停后恢复播放
  75. this.audioContext.play()
  76. this.setData({
  77. audioPause: 0
  78. })
  79. } else if (this.data.audioPause == 0 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停播放
  80. this.audioContext.pause()
  81. this.setData({
  82. audioPause: 1
  83. })
  84. }
  85. },
  86. bindended: function () {
  87. this.setData({
  88. audioPause: 0,
  89. curAudioIndex: -1,
  90. curAudio: ''
  91. })
  92. },
  93. bindpause: function () {
  94. this.setData({
  95. audioPause: 1
  96. })
  97. },
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. onLoad: function (options) {
  102. let sid = options.studentId
  103. let oid = options.orgId
  104. if (sid == null || oid == null) {
  105. let stu = wx.getStorageSync('student')
  106. sid = stu.studentId
  107. oid = stu.orgId
  108. }
  109. this.audioContext = wx.createAudioContext('audio-play')
  110. this.videoContext = wx.createVideoContext('play-video');// 创建 video 上下文 VideoContext 对象。
  111. this.setData({ studentId: sid, orgId: oid })
  112. this.queryList()
  113. },
  114. /**
  115. * 生命周期函数--监听页面初次渲染完成
  116. */
  117. onReady: function () {
  118. },
  119. /**
  120. * 生命周期函数--监听页面显示
  121. */
  122. onShow: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload: function () {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom: function () {
  143. if (this.data.hasNextPage) {
  144. let pn = this.data.pageNum
  145. this.setData({ loading: '加载中', 'pageNum': ++pn })
  146. this.queryList()
  147. }
  148. },
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage: function () {
  153. return {
  154. title: '成长足迹',
  155. path: '/pages/growUp/growUp?studentId=' + this.data.studentId + '&orgId=' + this.data.orgId,
  156. }
  157. },
  158. queryList: function () {
  159. const urls = urlDef.urls;
  160. let params = { 'q.studentId': this.data.studentId, 'q.orgId': this.data.orgId }
  161. params.pageNum = this.data.pageNum
  162. util.apiPost(urls.query_student_evaluate, params).then(rs => {
  163. let list = rs.list
  164. list.map(it => {
  165. if (it.beginTime) {
  166. it.beginTime = it.beginTime.replace('T', ' ').substring(0, 16)
  167. }
  168. if (it.type === '1') {
  169. util.apiPost(urls.query_student_star + '&q.orgId=' + this.data.orgId + '&q.studentId='
  170. + this.data.studentId + '&q.headId=' + it.id).then((st) => {
  171. it.stars = st;
  172. this.reloadItems(it)
  173. }, e => {
  174. console.log(e);
  175. });
  176. let attachs;
  177. try {
  178. if (it.evaluateAttach) {
  179. attachs = JSON.parse(it.evaluateAttach);
  180. } else {
  181. attachs = {};
  182. }
  183. } catch (e) {
  184. console.error(JSON.stringify(e));
  185. }
  186. if (attachs) {
  187. it.images = attachs.images ? attachs.images : [];
  188. it.videos = attachs.videos ? attachs.videos : [];
  189. it.records = attachs.records ? attachs.records : [];
  190. it.images.forEach(rs => {
  191. rs.url = urls.oss_file + 'image/' + rs.url
  192. });
  193. it.records.forEach(rs => {
  194. rs.url = urls.oss_file + 'file/' + rs.url
  195. });
  196. // 加载视频封面
  197. it.videos.forEach(r => {
  198. util.apiPost(urls.video_loadInfo + r.url).then((rs) => {
  199. r.imgUrl = rs.img;
  200. r.playUrl = rs.url;
  201. this.reloadItems(it)
  202. });
  203. });
  204. }
  205. } else if (it.type === '4') {
  206. util.apiPost(urls.video_loadInfo + it.evaluateAttach).then((rs) => {
  207. it.imgUrl = rs.img;
  208. it.playUrl = rs.url;
  209. this.reloadItems(it)
  210. });
  211. }
  212. })
  213. this.setData({
  214. 'hasNextPage': rs.hasNextPage,
  215. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  216. 'list': this.data.list.concat(list)
  217. })
  218. })
  219. },
  220. reloadItems: function (t) {
  221. let list = this.data.list;
  222. list.map(it => {
  223. if (it.id == t.id) {
  224. it = t;
  225. }
  226. })
  227. this.setData({ list: list })
  228. }
  229. })