// pages/growUp/growUp.js const app = getApp() const util = require("../../utils/util") const urlDef = require("../../utils/urls") Page({ /** * 页面的初始数据 */ data: { studentId: null, orgId: null, curVideo: '', videoFlag: 0, videoContext: '', curAudio: '', curAudioIndex: -1, audioPause: 0, list: [ ], loading: '上拉加载', flag: 0, pageNum: 0, hasNextPage: true, }, bindfullscreenchange: function () { if (this.data.videoFlag == 0) { this.setData({ videoFlag: 1 }) } else { this.setData({ videoFlag: 0, curVideo: "" }) } }, videoShow: function (e) { this.setData({ curVideo: e.currentTarget.dataset.url }) this.videoContext.requestFullScreen({ // 设置全屏时视频的方向,不指定则根据宽高比自动判断。 direction: 90 // 屏幕逆时针90度 }); }, showImg: function (e) { let id = e.currentTarget.dataset.id var images = []; this.data.list.map(it => { if (it.id == id) { let imgs = it.images imgs.map(i => { images.push(i.url) }) } }) wx.previewImage({ urls: images }) }, audioShow: function (e) { if (this.data.audioPause == 0 && this.data.curAudioIndex != e.currentTarget.dataset.index) {//播放语音,切换 this.setData({ curAudio: "" }) this.setData({ curAudioIndex: e.currentTarget.dataset.index, curAudio: e.currentTarget.dataset.url, }) this.audioContext.play() this.setData({ audioPause: 0 }) } else if (this.data.audioPause == 1 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停后恢复播放 this.audioContext.play() this.setData({ audioPause: 0 }) } else if (this.data.audioPause == 0 && this.data.curAudioIndex == e.currentTarget.dataset.index) {//暂停播放 this.audioContext.pause() this.setData({ audioPause: 1 }) } }, bindended: function () { this.setData({ audioPause: 0, curAudioIndex: -1, curAudio: '' }) }, bindpause: function () { this.setData({ audioPause: 1 }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let sid = options.studentId let oid = options.orgId if (sid == null || oid == null) { let stu = wx.getStorageSync('student') sid = stu.studentId oid = stu.orgId } this.audioContext = wx.createAudioContext('audio-play') this.videoContext = wx.createVideoContext('play-video');// 创建 video 上下文 VideoContext 对象。 this.setData({ studentId: sid, orgId: oid }) this.queryList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (this.data.hasNextPage) { let pn = this.data.pageNum this.setData({ loading: '加载中', 'pageNum': ++pn }) this.queryList() } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { title: '成长足迹', path: '/pages/growUp/growUp?studentId=' + this.data.studentId + '&orgId=' + this.data.orgId, } }, queryList: function () { const urls = urlDef.urls; let params = { 'q.studentId': this.data.studentId, 'q.orgId': this.data.orgId } params.pageNum = this.data.pageNum util.apiPost(urls.query_student_evaluate, params).then(rs => { let list = rs.list list.map(it => { if (it.beginTime) { it.beginTime = it.beginTime.replace('T', ' ').substring(0, 16) } if (it.type === '1') { util.apiPost(urls.query_student_star + '&q.orgId=' + this.data.orgId + '&q.studentId=' + this.data.studentId + '&q.headId=' + it.id).then((st) => { it.star = st; }, e => { console.log(e); }); let attachs; try { if (it.evaluateAttach) { attachs = JSON.parse(it.evaluateAttach); } else { attachs = {}; } } catch (e) { console.error(JSON.stringify(e)); } if (attachs) { it.images = attachs.images ? attachs.images : []; it.videos = attachs.videos ? attachs.videos : []; it.records = attachs.records ? attachs.records : []; it.images.forEach(rs => { rs.url = urls.oss_file + 'image/' + rs.url }); it.records.forEach(rs => { rs.url = urls.oss_file + 'file/' + rs.url }); // 加载视频封面 it.videos.forEach(r => { util.apiPost(urls.video_loadInfo + r.url).then((rs) => { r.imgUrl = rs.img; r.playUrl = rs.url; this.reloadVideos(it) }); }); } } else if (it.type === '4') { util.apiPost(urls.video_loadInfo + it.evaluateAttach).then((rs) => { it.imgUrl = rs.img; it.playUrl = rs.url; this.reloadVideos(it) }); } }) this.setData({ 'hasNextPage': rs.hasNextPage, 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据', 'list': this.data.list.concat(list) }) }) }, reloadVideos: function (t) { let list = this.data.list; list.map(it => { if (it.id == t.id) { it = t; } }) this.setData({ list: list }) } })