liveBox.vue 11 KB

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