index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="rf-live" v-show="liveShow">
  3. <view class="wrapper">
  4. <text class="iconfont" :class="icon"></text>
  5. <view class="content">直播中</view>
  6. <view class="btn" @tap="navToLive">去围观</view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import { miniProgramLiveIndex } from '@/api/product';
  12. export default {
  13. name: 'rfLive',
  14. props: {
  15. },
  16. data () {
  17. return {
  18. icon: 'iconzhibo11',
  19. index: 1,
  20. liveShow: false,
  21. roomId: '',
  22. timer: ''
  23. };
  24. },
  25. async created() {
  26. await this.getLiveList();
  27. },
  28. // 销毁定时器
  29. beforeDestroy () {
  30. clearInterval(this.timer);
  31. },
  32. methods: {
  33. // 获取直播记录
  34. async getLiveList() {
  35. await this.$http
  36. .get(`${miniProgramLiveIndex}`, {
  37. live_status: 101
  38. })
  39. .then(r => {
  40. if (r.data.length === 0) return;
  41. this.liveShow = true;
  42. this.roomId = r.data[0].room_id;
  43. this.timer = setInterval(() => {
  44. if (this.index > 3) this.index = 1;
  45. this.icon = `iconzhibo${this.index}1`;
  46. this.index += 1;
  47. }, 0.15 * 1000);
  48. });
  49. },
  50. navToLive() {
  51. // #ifdef MP-WEIXIN
  52. if (!this.roomId) return;
  53. this.$mRouter.push({ route: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${[this.roomId]}` });
  54. // #endif
  55. // #ifndef MP-WEIXIN
  56. this.$mHelper.toast('请从微信小程序进入带货直播间');
  57. // #endif
  58. }
  59. }
  60. };
  61. </script>
  62. <style scoped lang="scss">
  63. .rf-live {
  64. width: 100%;
  65. .wrapper {
  66. padding: $spacing-base $spacing-sm $spacing-sm;
  67. background-color: rgba(0 ,0, 0, 0.6);
  68. border-radius: 12upx;
  69. position: fixed;
  70. text-align: center;
  71. right: 40upx;
  72. top: 40%;
  73. z-index: 98;
  74. color: $color-white;
  75. .iconfont {
  76. font-size: $font-lg;
  77. opacity: 1;
  78. z-index: 92;
  79. }
  80. .content {
  81. font-size: $font-sm;
  82. margin: $spacing-sm 0;
  83. }
  84. .btn {
  85. margin-top: $spacing-lg;
  86. font-size: $font-sm;
  87. background-color: $base-color;
  88. opacity: 1;
  89. width: 100upx;
  90. height: 42upx;
  91. line-height: 42upx;
  92. border-radius: 18upx;
  93. }
  94. }
  95. }
  96. </style>