item.vue 11 KB

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