item.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <view class="live-box">
  3. <view class="live-ongoing" v-if="liveData.liveStatus === 101" @click="toLive">
  4. <image class="cover-img" :src="liveData.feedsImg" />
  5. <view class="status">
  6. <view class="status-state">
  7. <!-- #ifdef MP-WEIXIN -->
  8. <img class="img" src="../../../static/images/live/icon-live-num.png" mode="widthFix"/>
  9. <!-- #endif -->
  10. <!-- #ifdef H5 || APP-PLUS -->
  11. <image class="img" src="../../../static/images/live/icon-live-num.png" mode="widthFix"/>
  12. <!-- #endif -->
  13. 直播中
  14. </view>
  15. <!-- <view class="status-num">1000人</view> -->
  16. </view>
  17. <view class="user">
  18. <view class="user-pic">
  19. <image class="img" :src="liveData.anchorHeadImg" />
  20. </view>
  21. <view class="user-name">{{ liveData.anchorNickName }}</view>
  22. </view>
  23. <view class="products">
  24. <view class="uni-padding-wrap">
  25. <view class="page-section swiper">
  26. <view class="page-section-spacing">
  27. <swiper class="swiper"
  28. :indicator-dots="indicatorDots"
  29. :autoplay="autoplay"
  30. :interval="interval"
  31. :duration="duration"
  32. :vertical="true"
  33. >
  34. <swiper-item
  35. v-for="item in liveData.goods"
  36. :key="item.goods_id"
  37. >
  38. <view class="swiper-item">{{ item.name }}</view>
  39. </swiper-item>
  40. </swiper>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="live-other" v-else @click="toLive">
  47. <image class="cover-img" :src="liveData.feedsImg" />
  48. <div class="filter-box-warp">
  49. <div class="filter-box">
  50. <image class="cover-img" :src="liveData.feedsImg" />
  51. </div>
  52. </div>
  53. <view class="user">
  54. <view class="user-pic"><image class="img" :src="liveData.anchorHeadImg" /></view>
  55. <view class="user-name">{{ liveData.anchorNickName }}</view>
  56. </view>
  57. <view class="count-down" v-if="liveStatus === 102">
  58. <image v-if="isLate" class="img" src="@/static/images/live/live-late.png"/>
  59. <view class="text">{{ liveTimeTitle }}</view>
  60. <view v-if="!isLate" class="time">
  61. <view class="time-item">{{times[0]}}</view>
  62. <view class="dot">:</view>
  63. <view class="time-item">{{times[1]}}</view>
  64. <view class="dot">:</view>
  65. <view class="time-item">{{times[2]}}</view>
  66. </view>
  67. </view>
  68. <!-- #ifdef MP-WEIXIN -->
  69. <view
  70. v-if="liveStatus === 102 && !isLate"
  71. class="btn-subscribe"
  72. :class="{subscribed : subscribeLive === '已预约'}"
  73. @click.stop="onSubscribe"
  74. >{{ subscribeLive }}</view>
  75. <!-- #endif -->
  76. <view class="endContainer" v-if="liveStatus === 103">
  77. <view class="endBox">
  78. <view></view>
  79. <view></view>
  80. <view></view>
  81. <view></view>
  82. </view>
  83. <view>直播已结束</view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. const NET = require('@/utils/request')
  90. const API = require('@/config/api')
  91. import { startLiveTemplate } from '@/config/subscribe.js'
  92. import { liveAppid } from '@/config/live.js'
  93. // #ifdef MP-WEIXIN
  94. const livePlayer = requirePlugin('live-player-plugin')
  95. // #endif
  96. export default {
  97. props: {
  98. liveData: {
  99. type: Object,
  100. default: () => ({
  101. roomId: 0,
  102. anchorNickName: '',
  103. feedsImg: '' // 官方收录封面
  104. })
  105. }
  106. },
  107. data () {
  108. return {
  109. background: ['color1', 'color2', 'color3'],
  110. indicatorDots: false,
  111. autoplay: true,
  112. interval: 2000, // 自动播放间隔时长
  113. duration: 500, // 幻灯片切换时长(ms)
  114. d: 0,
  115. m: 0,
  116. s: 0,
  117. times: [],
  118. liveStatus: 100,
  119. liveTimeTitle: '开播倒计时',
  120. subscribeLive: '立即预约',
  121. timer: null,
  122. isLate: false,
  123. }
  124. },
  125. created() {
  126. this.liveStatus = this.liveData.liveStatus
  127. this.subscribeLive = this.liveData.subscribeStatus === 0 ? '立即预约' : '已预约'
  128. this.getStatus()
  129. this.countTime()
  130. // this.getSubscribeStatus()
  131. },
  132. destroyed() {
  133. clearTimeout(this.timer)
  134. },
  135. methods: {
  136. getStatus() {
  137. if (!this.liveData.roomId) { return }
  138. let _this = this
  139. // #ifdef MP-WEIXIN
  140. livePlayer.getLiveStatus({ room_id: this.liveData.roomId })
  141. .then(res => {
  142. // 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期
  143. // _this.liveData.liveStatus = res.liveStatus
  144. _this.liveStatus = res.liveStatus
  145. })
  146. .catch(err => {
  147. console.log('get live status', err)
  148. })
  149. this.timer = setInterval(() => {
  150. livePlayer.getLiveStatus({ room_id: this.liveData.roomId })
  151. .then(res => {
  152. // 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期
  153. _this.liveStatus = res.liveStatus
  154. this.countTime()
  155. console.log('get live status', res.liveStatus)
  156. })
  157. .catch(err => {
  158. console.log('get live status', err)
  159. })
  160. }, 60000)
  161. // #endif
  162. },
  163. changeIndicatorDots(e) {
  164. this.indicatorDots = !this.indicatorDots
  165. },
  166. changeAutoplay(e) {
  167. this.autoplay = !this.autoplay
  168. },
  169. intervalChange(e) {
  170. this.interval = e.target.value
  171. },
  172. durationChange(e) {
  173. this.duration = e.target.value
  174. },
  175. countTime(){
  176. var nowtime = new Date().getTime() //获取当前时间
  177. const starttime = new Date(this.liveData.startTime).getTime()
  178. if(this.liveStatus === 102){
  179. if(starttime > nowtime){
  180. var lefttime = starttime - nowtime //距离结束时间的毫秒数
  181. var leftd = Math.floor(lefttime/(1000*60*60)), //计算小时数
  182. leftm = Math.floor(lefttime/(1000*60)%60), //计算分钟数
  183. lefts = Math.floor(lefttime/1000%60); //计算秒数
  184. this.times = [leftd < 10?'0'+ leftd:leftd,leftm < 10?'0'+ leftm:leftm,lefts < 10?'0'+ lefts:lefts]
  185. this.liveTimeTitle = '开播倒计时'
  186. setTimeout(() => {
  187. this.countTime()
  188. },1000)
  189. } else {
  190. this.times = ['00', '00', '00']
  191. this.isLate = true
  192. this.liveTimeTitle = '正在赶来的路上...'
  193. }
  194. }
  195. },
  196. toLive() {
  197. console.log(liveAppid,'liveAppid')
  198. console.log(this.liveData.roomId,'this.liveData.roomId')
  199. if (!liveAppid || !this.liveData) { return }
  200. // 跳转直播间携带路由参数
  201. // let customParams = encodeURIComponent(JSON.stringify({ path: 'livePage/index', pid: 1 }))
  202. // #ifdef MP-WEIXIN
  203. wx.navigateTo({
  204. url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}`
  205. // url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}&custom_params=${customParams}`
  206. })
  207. // #endif
  208. },
  209. onSubscribe() {
  210. if (this.subscribeLive === '立即预约') {
  211. const _this = this
  212. // #ifdef MP-WEIXIN
  213. uni.requestSubscribeMessage({
  214. tmplIds: [startLiveTemplate],
  215. success (res) {
  216. if (res[startLiveTemplate] === "accept") {
  217. NET.request(API.SubScribeLive, {id: _this.liveData.id }, 'post')
  218. .then(res => {
  219. if (res.data) {
  220. _this.subscribeLive = '已预约'
  221. } else {
  222. uni.showToast({
  223. title: res.message || '订阅失败,请稍后再试!',
  224. icon: "none"
  225. })
  226. }
  227. })
  228. .catch(err => {
  229. console.log(err)
  230. uni.showToast({
  231. title: res.message || '订阅失败,请稍后再试!',
  232. icon: "none"
  233. })
  234. })
  235. }
  236. }
  237. })
  238. // #endif
  239. }
  240. }
  241. }
  242. }
  243. </script>
  244. <style lang="scss" scoped>
  245. .live-box{
  246. position: relative;
  247. color: #fff;
  248. width: 100%;
  249. height: 100%;
  250. .cover-img{
  251. width: 100%;
  252. height: 100%;
  253. position: absolute;
  254. z-index: 0;
  255. }
  256. .user{
  257. display: flex;
  258. line-height: 60rpx;
  259. height: 64rpx;
  260. &-pic{
  261. .img{
  262. width: 60rpx;
  263. height: 60rpx;
  264. border: 2px solid rgba(255, 255, 255, 0.5019607843137255);
  265. border-radius: 50%;
  266. overflow: hidden;
  267. }
  268. }
  269. &-name{
  270. font-size: 28rpx;
  271. margin-left: 16rpx;
  272. overflow: hidden;
  273. text-overflow: ellipsis;
  274. white-space: nowrap;
  275. width: 245rpx;
  276. }
  277. }
  278. .live-ongoing{
  279. width: 100%;
  280. height: 100%;
  281. position: relative;
  282. .status{
  283. position: absolute;
  284. top: 22rpx;
  285. left: 22rpx;
  286. //width: 212upx;
  287. height: 48rpx;
  288. // background: rgba(0,0,0,0.3);
  289. // border: 2rpx solid rgba(255,255,255,0.3);
  290. border-radius: 24rpx;
  291. font-size: 20rpx;
  292. line-height: 44rpx;
  293. display: flex;
  294. // padding-right: 8rpx;
  295. &-state{
  296. width: 118rpx;
  297. height: 44rpx;
  298. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  299. opacity: 1;
  300. border-radius: 26rpx;
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. .img{
  305. width: 20rpx;
  306. height: 20rpx;
  307. margin-right: 6rpx;
  308. }
  309. }
  310. &-num{
  311. min-width: 80rpx;
  312. padding: 0 8rpx;
  313. }
  314. }
  315. .user{
  316. position: absolute;
  317. bottom: 62rpx;
  318. left: 20rpx;
  319. }
  320. .products{
  321. position: absolute;
  322. left: 0rpx;
  323. bottom: 20rpx;
  324. width: 100%;
  325. padding:0 20rpx;
  326. .swiper{
  327. height: 34rpx;
  328. line-height: 34rpx;
  329. font-size: 24rpx;
  330. overflow: hidden;
  331. text-overflow:ellipsis;
  332. white-space: nowrap;
  333. }
  334. }
  335. }
  336. .live-other{
  337. position: relative;
  338. height: 100%;
  339. display: flex;
  340. align-items: center;
  341. justify-content: center;
  342. .filter-box-warp{
  343. background-color: #000000;
  344. position: absolute;
  345. top: 0;
  346. left: 0;
  347. width: 100%;
  348. height: 100%;
  349. .filter-box{
  350. position: absolute;
  351. top: -30rpx;
  352. left: -30rpx;
  353. width: 348rpx;
  354. height: 464rpx;
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. -webkit-filter: blur(20px);
  359. -moz-filter: blur(21px);
  360. -ms-filter: blur(20px);
  361. -o-filter: blur(20px);
  362. padding: 30rpx;
  363. box-sizing: content-box;
  364. }
  365. }
  366. .user{
  367. position: absolute;
  368. top: 20rpx;
  369. left: 20rpx;
  370. }
  371. .count-down{
  372. position: relative;
  373. .text{
  374. font-size: 26rpx;
  375. line-height: 36rpx;
  376. margin-bottom: 16rpx;
  377. opacity: 0.5;
  378. text-align: center;
  379. }
  380. .img{
  381. display: block;
  382. width: 80rpx;
  383. height: 80rpx;
  384. margin: 16rpx auto;
  385. }
  386. .time{
  387. display: flex;
  388. justify-content: space-around;
  389. align-items: center;
  390. &-item{
  391. min-width: 52rpx;
  392. padding: 0 5rpx;
  393. height: 52rpx;
  394. line-height: 52rpx;
  395. background: #FFFFFF;
  396. opacity: 1;
  397. border-radius: 6rpx;
  398. font-size: 26rpx;
  399. color: #C83732;
  400. text-align: center;
  401. .dot{
  402. line-height: 52rpx;
  403. }
  404. }
  405. }
  406. }
  407. .btn-subscribe{
  408. width: 200rpx;
  409. height: 64rpx;
  410. line-height: 64rpx;
  411. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  412. box-shadow: 0rpx 6rpx 12rpx rgba(233, 0, 0, 0.3);
  413. opacity: 1;
  414. border-radius: 6rpx;
  415. color: #fff;
  416. font-size: 24rpx;
  417. text-align: center;
  418. position: absolute;
  419. bottom: 60rpx;
  420. left: 50%;
  421. margin-left: -100rpx;
  422. &.subscribed{
  423. background: #FFFFFF;
  424. color: #999999;
  425. box-shadow: none;
  426. }
  427. }
  428. .endContainer{
  429. position: relative;
  430. .endBox{
  431. width: 40%;
  432. height: 60rpx;
  433. margin: 20rpx auto;
  434. display: flex;
  435. justify-content: space-between;
  436. align-items: flex-end;
  437. view{
  438. width: 0;
  439. border: 2rpx solid #FFF;
  440. }
  441. view:nth-of-type(1){
  442. height: 20%;
  443. }
  444. view:nth-of-type(2){
  445. height: 50%;
  446. }
  447. view:nth-of-type(3){
  448. height: 30%;
  449. }
  450. view:nth-of-type(4){
  451. height: 70%;
  452. }
  453. }
  454. }
  455. }
  456. }
  457. </style>