// pages/playShow/playShow.js const app = getApp() const util = require("../../utils/util") const urlDef = require("../../utils/urls") Page({ /** * 页面的初始数据 */ data: { id: null, item: null, creator: null, cHeight: 0, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ id: options.vid }) this.loadInfo() let wHeight = wx.getSystemInfoSync().windowHeight let psHeight = 0 wx.createSelectorQuery().select('#playShow').boundingClientRect(rect => { psHeight = rect.height; console.log(psHeight) }).exec(); let tHeight = 0 wx.createSelectorQuery().select('.title').boundingClientRect(rect => { tHeight = rect.height; console.log(tHeight) }).exec(); let evHeight = 0 wx.createSelectorQuery().select('.edit-view').boundingClientRect(rect => { evHeight = rect.height; console.log(evHeight) console.log(wHeight) const cHeight = wHeight - psHeight - evHeight - tHeight - 40 this.setData({ cHeight }) }).exec(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { title: '视频秀', path: '/pages/playShow/playShow?vid=' + this.data.id, image: this.data.item.imgUrl } }, loadInfo: function () { const urls = urlDef.urls; let stu = wx.getStorageSync('student'); this.setData({ curStu: stu }) util.apiPost(urls.person_video_list + '&q.videoId=' + this.data.id).then((rs) => { if (rs && rs.length > 0) { let o = rs[0] o.viewsCount = this.formatCount(o.viewsCount) this.setData({ item: o }) util.apiPost(urls.video_loadInfo + this.data.id).then((rs) => { o.imgUrl = rs.img o.playUrl = rs.url this.setData({ item: o }) }) let goodEntity = { videoId: this.data.id, personId: stu.studentId, personType: 1 }; util.apiPost(urls.person_video_view_save, goodEntity, 'application/json').then(rs => {}).catch(e => {}); } }) util.apiPost(urls.query_video_creator + '&q.id=' + this.data.id).then((rs) => { let u = rs if (rs) { u.imageUrl = '/images/head.png' } else { u = {} u.imageUrl = urls.oss_file + 'image/' + u.imageUrl } this.setData({ creator: u }) }) }, doThumbsUp: function () { let o = this.data.item const urls = urlDef.urls; let pid = this.data.curStu.studentId; let pt = o.personType; let vid = o.videoId; let entity = { videoId: vid, personId: pid, personType: pt, actionType: 1 }; util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => { o.goodCount += 1 this.setData({ 'item': o }) }).catch(e => { console.log(e); }) }, formatCount(n) { if (n >= 100000000) { return (n / 100000000).toFixed(2) + '亿'; } else if (n >= 10000) { return (n / 10000).toFixed(2) + '万'; } else if (n >= 1000) { return (n / 1000).toFixed(2) + '千'; } return n; } })