123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- // pages/growUp/growUp.js
- const app = getApp()
- const util = require("../../utils/util")
- const urlDef = require("../../utils/urls")
- const audioContext = wx.createInnerAudioContext() //音频播放对象
- 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,
- current: e.currentTarget.dataset.url
- })
- },
- showAudio: function (e) {
- const url = e.currentTarget.dataset.url
- if (this.data.curAudioIndex != url) {
- this.setData({
- curAudioIndex: url,
- })
- audioContext.src = url
- audioContext.play()
- audioContext.onEnded((res) => {
- this.setData({
- curAudioIndex: '-1',
- })
- })
- } else {
- if (this.data.audioPause) {
- audioContext.play()
- this.setData({
- audioPause: false
- })
- } else {
- audioContext.pause()
- this.setData({
- audioPause: true
- })
- }
- }
- },
- 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.videoContext = wx.createVideoContext('play-video');// 创建 video 上下文 VideoContext 对象。
- this.setData({ studentId: sid, orgId: oid })
- this.queryList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- audioContext.stop()
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- 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.stars = st;
- this.reloadItems(it)
- }, 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.reloadItems(it)
- });
- });
- }
- } else if (it.type === '4') {
- util.apiPost(urls.video_loadInfo + it.evaluateAttach).then((rs) => {
- it.imgUrl = rs.img;
- it.playUrl = rs.url;
- this.reloadItems(it)
- });
- }
- })
- this.setData({
- 'hasNextPage': rs.hasNextPage,
- 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
- 'list': this.data.list.concat(list)
- })
- })
- },
- reloadItems: function (t) {
- let list = this.data.list;
- list.map(it => {
- if (it.id == t.id) {
- it = t;
- }
- })
- this.setData({ list: list })
- }
- })
|