item.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <view class="live-box">
  3. <view class="live-ongoing" v-if="liveData.liveStatus === 101">
  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. if (!liveAppid || !this.liveData) { return }
  198. // 跳转直播间携带路由参数
  199. // let customParams = encodeURIComponent(JSON.stringify({ path: 'livePage/index', pid: 1 }))
  200. // #ifdef MP-WEIXIN
  201. wx.navigateTo({
  202. url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}`
  203. // url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}&custom_params=${customParams}`
  204. })
  205. // #endif
  206. },
  207. onSubscribe() {
  208. if (this.subscribeLive === '立即预约') {
  209. const _this = this
  210. // #ifdef MP-WEIXIN
  211. uni.requestSubscribeMessage({
  212. tmplIds: [startLiveTemplate],
  213. success (res) {
  214. if (res[startLiveTemplate] === "accept") {
  215. NET.request(API.SubScribeLive, {id: _this.liveData.id }, 'post')
  216. .then(res => {
  217. if (res.data) {
  218. _this.subscribeLive = '已预约'
  219. } else {
  220. uni.showToast({
  221. title: res.message || '订阅失败,请稍后再试!',
  222. icon: "none"
  223. })
  224. }
  225. })
  226. .catch(err => {
  227. console.log(err)
  228. uni.showToast({
  229. title: res.message || '订阅失败,请稍后再试!',
  230. icon: "none"
  231. })
  232. })
  233. }
  234. }
  235. })
  236. // #endif
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. .live-box{
  244. position: relative;
  245. color: #fff;
  246. width: 100%;
  247. height: 100%;
  248. .cover-img{
  249. width: 100%;
  250. height: 100%;
  251. position: absolute;
  252. z-index: 0;
  253. }
  254. .user{
  255. display: flex;
  256. line-height: 60rpx;
  257. height: 64rpx;
  258. &-pic{
  259. .img{
  260. width: 60rpx;
  261. height: 60rpx;
  262. border: 2px solid rgba(255, 255, 255, 0.5019607843137255);
  263. border-radius: 50%;
  264. overflow: hidden;
  265. }
  266. }
  267. &-name{
  268. font-size: 28rpx;
  269. margin-left: 16rpx;
  270. overflow: hidden;
  271. text-overflow: ellipsis;
  272. white-space: nowrap;
  273. width: 245rpx;
  274. }
  275. }
  276. .live-ongoing{
  277. width: 100%;
  278. height: 100%;
  279. position: relative;
  280. .status{
  281. position: absolute;
  282. top: 22rpx;
  283. left: 22rpx;
  284. //width: 212upx;
  285. height: 48rpx;
  286. // background: rgba(0,0,0,0.3);
  287. // border: 2rpx solid rgba(255,255,255,0.3);
  288. border-radius: 24rpx;
  289. font-size: 20rpx;
  290. line-height: 44rpx;
  291. display: flex;
  292. // padding-right: 8rpx;
  293. &-state{
  294. width: 118rpx;
  295. height: 44rpx;
  296. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  297. opacity: 1;
  298. border-radius: 26rpx;
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. .img{
  303. width: 20rpx;
  304. height: 20rpx;
  305. margin-right: 6rpx;
  306. }
  307. }
  308. &-num{
  309. min-width: 80rpx;
  310. padding: 0 8rpx;
  311. }
  312. }
  313. .user{
  314. position: absolute;
  315. bottom: 62rpx;
  316. left: 20rpx;
  317. }
  318. .products{
  319. position: absolute;
  320. left: 0rpx;
  321. bottom: 20rpx;
  322. width: 100%;
  323. padding:0 20rpx;
  324. .swiper{
  325. height: 34rpx;
  326. line-height: 34rpx;
  327. font-size: 24rpx;
  328. overflow: hidden;
  329. text-overflow:ellipsis;
  330. white-space: nowrap;
  331. }
  332. }
  333. }
  334. .live-other{
  335. position: relative;
  336. height: 100%;
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. .filter-box-warp{
  341. background-color: #000000;
  342. position: absolute;
  343. top: 0;
  344. left: 0;
  345. width: 100%;
  346. height: 100%;
  347. .filter-box{
  348. position: absolute;
  349. top: -30rpx;
  350. left: -30rpx;
  351. width: 348rpx;
  352. height: 464rpx;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. -webkit-filter: blur(20px);
  357. -moz-filter: blur(21px);
  358. -ms-filter: blur(20px);
  359. -o-filter: blur(20px);
  360. padding: 30rpx;
  361. box-sizing: content-box;
  362. }
  363. }
  364. .user{
  365. position: absolute;
  366. top: 20rpx;
  367. left: 20rpx;
  368. }
  369. .count-down{
  370. position: relative;
  371. .text{
  372. font-size: 26rpx;
  373. line-height: 36rpx;
  374. margin-bottom: 16rpx;
  375. opacity: 0.5;
  376. text-align: center;
  377. }
  378. .img{
  379. display: block;
  380. width: 80rpx;
  381. height: 80rpx;
  382. margin: 16rpx auto;
  383. }
  384. .time{
  385. display: flex;
  386. justify-content: space-around;
  387. align-items: center;
  388. &-item{
  389. min-width: 52rpx;
  390. padding: 0 5rpx;
  391. height: 52rpx;
  392. line-height: 52rpx;
  393. background: #FFFFFF;
  394. opacity: 1;
  395. border-radius: 6rpx;
  396. font-size: 26rpx;
  397. color: #C83732;
  398. text-align: center;
  399. .dot{
  400. line-height: 52rpx;
  401. }
  402. }
  403. }
  404. }
  405. .btn-subscribe{
  406. width: 200rpx;
  407. height: 64rpx;
  408. line-height: 64rpx;
  409. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  410. box-shadow: 0rpx 6rpx 12rpx rgba(233, 0, 0, 0.3);
  411. opacity: 1;
  412. border-radius: 6rpx;
  413. color: #fff;
  414. font-size: 24rpx;
  415. text-align: center;
  416. position: absolute;
  417. bottom: 60rpx;
  418. left: 50%;
  419. margin-left: -100rpx;
  420. &.subscribed{
  421. background: #FFFFFF;
  422. color: #999999;
  423. box-shadow: none;
  424. }
  425. }
  426. .endContainer{
  427. position: relative;
  428. .endBox{
  429. width: 40%;
  430. height: 60rpx;
  431. margin: 20rpx auto;
  432. display: flex;
  433. justify-content: space-between;
  434. align-items: flex-end;
  435. view{
  436. width: 0;
  437. border: 2rpx solid #FFF;
  438. }
  439. view:nth-of-type(1){
  440. height: 20%;
  441. }
  442. view:nth-of-type(2){
  443. height: 50%;
  444. }
  445. view:nth-of-type(3){
  446. height: 30%;
  447. }
  448. view:nth-of-type(4){
  449. height: 70%;
  450. }
  451. }
  452. }
  453. }
  454. }
  455. </style>