live.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view>
  3. <!--pages/live/live.wxml-->
  4. <view class="list" v-if="pageList.length > 0">
  5. <block v-for="(item, index) in pageList" :key="index">
  6. <view class="li" @tap="intoLive" :data-id="item.roomid" :data-index="index">
  7. <image :src="item.share_img" mode="scaleToFill" class="zbimg"></image>
  8. <view class="title">{{item.name}}</view>
  9. <view class="dflex">
  10. <view class="sta dflex flex" v-if="item.live_status == 101">
  11. <image src="/static/pages/images/zbico.png"></image>直播中
  12. </view>
  13. <view class="sta dflex flex" v-else-if="item.live_status == 102">
  14. <image src="/static/pages/images/zbico.png"></image>{{item.time}}开播
  15. </view>
  16. <view class="sta end dflex flex" v-else>
  17. <image src="/static/pages/images/zbico1.png"></image>已结束
  18. </view>
  19. <!-- <view class="ren dflex flex"><image src="/pages/images/ren.png"></image>6247</view> -->
  20. <view class="into" v-if="item.live_status == 103">查看回放</view>
  21. <view class="into" v-else>进入直播</view>
  22. <!-- <view class="into" wx:if="{{item.live_status == 102}}">开播提醒</view> -->
  23. </view>
  24. </view>
  25. </block>
  26. <footer-copyright></footer-copyright>
  27. </view>
  28. <view class="nodata" v-if="ishow">
  29. <image :src="picUrlss+'empty_zb.png'"></image>
  30. <text>暂无直播</text>
  31. </view>
  32. <foot channel="live" :isUpdate="isUpdate" v-if="query.isSwitchTab"></foot>
  33. </view>
  34. </template>
  35. <script>
  36. // pages/live/live.js
  37. const app = getApp();
  38. const req = require("../../utils/request.js");
  39. const util = require("../../utils/util.js");
  40. import foot from "../../components/nav-bar/index";
  41. import footerCopyright from "../../components/footer-copyright/footer-copyright";
  42. export default {
  43. data() {
  44. return {
  45. picUrlss: req.public.picUrls,
  46. query: {},
  47. bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
  48. page: 1,
  49. pageList: [],
  50. isLoad: true,
  51. isUpdate: false // 是否更新消息
  52. ,
  53. hasmore: false,
  54. ishow: false
  55. };
  56. },
  57. components: {
  58. foot,
  59. footerCopyright
  60. },
  61. props: {},
  62. onLoad(options) { // this.getList()
  63. if(options.isSwitchTab) options.isSwitchTab = true;
  64. this.query = options;
  65. },
  66. onShow() {
  67. this.getList();
  68. this.setData({
  69. isUpdate: !this.isUpdate
  70. });
  71. },
  72. onReachBottom() {
  73. this.page++;
  74. this.getList();
  75. },
  76. methods: {
  77. getList() {
  78. let that = this;
  79. let isShowLoading = false;
  80. // console.log(that.isLoad);
  81. if (!that.isLoad) return false;
  82. that.isLoad = false;
  83. let form = {
  84. page: that.page,
  85. limit: 10
  86. };
  87. if (form.page == 1 && !isShowLoading) {
  88. req.loadIng('加载中');
  89. isShowLoading = true;
  90. }
  91. req.getRequest('/api/live/list', form, data => {
  92. // if (!data) return req.msg('还没有直播');
  93. if (data && data.length == 10) that.isLoad = true;
  94. if (that.page > 1) data = that.pageList.concat(data);
  95. if (!data || data.length < 10) {
  96. that.setData({
  97. hasmore: true
  98. });
  99. }
  100. if (data) {
  101. data.map(item => {
  102. if (item.start_time) {
  103. item.time = util.transTime(item.start_time);
  104. }
  105. return item;
  106. });
  107. }
  108. // console.log(data);
  109. that.setData({
  110. pageList: data
  111. });
  112. if (!this.pageList) {
  113. that.setData({
  114. ishow: true
  115. });
  116. } else {
  117. that.setData({
  118. ishow: false
  119. });
  120. }
  121. if (isShowLoading) {
  122. uni.hideLoading();
  123. isShowLoading = false;
  124. }
  125. });
  126. },
  127. getLive(id) {
  128. return new Promise((resolve, reject) => {
  129. req.getRequest('/api/live/playBack', {
  130. page: 1,
  131. limit: 10,
  132. room_id: id
  133. }, data => {
  134. this.videoList = data;
  135. resolve();
  136. });
  137. });
  138. },
  139. intoLive(event) {
  140. let roomId = event.currentTarget.dataset.id;
  141. let index = event.currentTarget.dataset.index;
  142. // console.log(roomId)
  143. // let date=this.data.pageList.filter(res=>res.roomid==roomId)
  144. // // console.log(JSON.stringify(JSON.stringify(date[0])))
  145. // // console.log(typeof(JSON.stringify(date[0])))
  146. // res=JSON.stringify(date[0])
  147. let redirect = '/service/liveMiddle/liveMiddle?id=' + roomId
  148. req.isLogin().then(success => {
  149. if (success) {
  150. uni.navigateTo({
  151. url: redirect // url:`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}`
  152. });
  153. }
  154. });
  155. },
  156. async playBack(event) {
  157. let roomId = event.currentTarget.dataset.id;
  158. await this.getLive(roomId);
  159. let videoList = JSON.stringify(this.videoList);
  160. if (videoList.length < 1) return req.msg('回放生成中');
  161. uni.navigateTo({
  162. url: '/service/video/video?videoList=' + videoList
  163. });
  164. }
  165. }
  166. };
  167. </script>
  168. <style>
  169. @import "./live.css";
  170. </style>