playShow.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/playShow/playShow.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. id: null,
  11. item: null,
  12. creator: null,
  13. cHeight: 0,
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.setData({
  20. id: options.vid
  21. })
  22. this.loadInfo()
  23. let wHeight = wx.getSystemInfoSync().windowHeight
  24. let psHeight = 0
  25. wx.createSelectorQuery().select('#playShow').boundingClientRect(rect => {
  26. psHeight = rect.height;
  27. console.log(psHeight)
  28. }).exec();
  29. let tHeight = 0
  30. wx.createSelectorQuery().select('.title').boundingClientRect(rect => {
  31. tHeight = rect.height;
  32. console.log(tHeight)
  33. }).exec();
  34. let evHeight = 0
  35. wx.createSelectorQuery().select('.edit-view').boundingClientRect(rect => {
  36. evHeight = rect.height;
  37. console.log(evHeight)
  38. console.log(wHeight)
  39. const cHeight = wHeight - psHeight - evHeight - tHeight - 40
  40. this.setData({
  41. cHeight
  42. })
  43. }).exec();
  44. },
  45. /**
  46. * 生命周期函数--监听页面初次渲染完成
  47. */
  48. onReady: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面隐藏
  57. */
  58. onHide: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面卸载
  62. */
  63. onUnload: function () {
  64. },
  65. /**
  66. * 页面相关事件处理函数--监听用户下拉动作
  67. */
  68. onPullDownRefresh: function () {
  69. },
  70. /**
  71. * 页面上拉触底事件的处理函数
  72. */
  73. onReachBottom: function () {
  74. },
  75. /**
  76. * 用户点击右上角分享
  77. */
  78. onShareAppMessage: function () {
  79. return {
  80. title: '视频秀',
  81. path: '/pages/playShow/playShow?vid=' + this.data.id,
  82. image: this.data.item.imgUrl
  83. }
  84. },
  85. loadInfo: function () {
  86. const urls = urlDef.urls;
  87. let stu = wx.getStorageSync('student');
  88. this.setData({
  89. curStu: stu
  90. })
  91. util.apiPost(urls.person_video_list + '&q.videoId=' + this.data.id).then((rs) => {
  92. if (rs && rs.length > 0) {
  93. let o = rs[0]
  94. o.viewsCount = this.formatCount(o.viewsCount)
  95. this.setData({
  96. item: o
  97. })
  98. util.apiPost(urls.video_loadInfo + this.data.id).then((rs) => {
  99. o.imgUrl = rs.img
  100. o.playUrl = rs.url
  101. this.setData({
  102. item: o
  103. })
  104. })
  105. let goodEntity = {
  106. videoId: this.data.id,
  107. personId: stu.studentId,
  108. personType: 1
  109. };
  110. util.apiPost(urls.person_video_view_save, goodEntity, 'application/json').then(rs => {}).catch(e => {});
  111. }
  112. })
  113. util.apiPost(urls.query_video_creator + '&q.id=' + this.data.id).then((rs) => {
  114. let u = rs
  115. if (rs) {
  116. u.imageUrl = '/images/head.png'
  117. } else {
  118. u = {}
  119. u.imageUrl = urls.oss_file + 'image/' + u.imageUrl
  120. }
  121. this.setData({
  122. creator: u
  123. })
  124. })
  125. },
  126. doThumbsUp: function () {
  127. let o = this.data.item
  128. const urls = urlDef.urls;
  129. let pid = this.data.curStu.studentId;
  130. let pt = o.personType;
  131. let vid = o.videoId;
  132. let entity = {
  133. videoId: vid,
  134. personId: pid,
  135. personType: pt,
  136. actionType: 1
  137. };
  138. util.apiPost(urls.person_video_view_save, entity, 'application/json').then(rs => {
  139. o.goodCount += 1
  140. this.setData({
  141. 'item': o
  142. })
  143. }).catch(e => {
  144. console.log(e);
  145. })
  146. },
  147. formatCount(n) {
  148. if (n >= 100000000) {
  149. return (n / 100000000).toFixed(2) + '亿';
  150. } else if (n >= 10000) {
  151. return (n / 10000).toFixed(2) + '万';
  152. } else if (n >= 1000) {
  153. return (n / 1000).toFixed(2) + '千';
  154. }
  155. return n;
  156. }
  157. })