s-live-block.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view>
  3. <view
  4. v-if="mode === 2 && state.liveList.length"
  5. class="goods-md-wrap ss-flex ss-flex-wrap ss-col-top"
  6. :style="[{ margin: '-' + data.space + 'rpx' }]"
  7. >
  8. <view
  9. :style="[
  10. {
  11. padding: data.space + 'rpx',
  12. },
  13. ]"
  14. class="goods-list-box"
  15. v-for="item in state.liveList"
  16. :key="item.id"
  17. >
  18. <s-live-card
  19. class="goods-md-box"
  20. size="md"
  21. :goodsFields="goodsFields"
  22. :data="item"
  23. :titleColor="goodsFields.name?.color"
  24. :subTitleColor="goodsFields.anchor_name?.color"
  25. :topRadius="data.borderRadiusTop"
  26. :bottomRadius="data.borderRadiusBottom"
  27. @click="goRoom(item.roomid)"
  28. >
  29. </s-live-card>
  30. </view>
  31. </view>
  32. <view v-if="mode === 1 && state.liveList.length" class="goods-lg-box">
  33. <view
  34. class="goods-box"
  35. :style="[{ marginBottom: data.space + 'px' }]"
  36. v-for="item in state.liveList"
  37. :key="item.id"
  38. >
  39. <s-live-card
  40. class="goods-card"
  41. size="sl"
  42. :goodsFields="goodsFields"
  43. :data="item"
  44. :titleColor="goodsFields.name?.color"
  45. :subTitleColor="goodsFields.anchor_name.color"
  46. :topRadius="data.borderRadiusTop"
  47. :bottomRadius="data.borderRadiusBottom"
  48. @tap="goRoom(item.roomid)"
  49. >
  50. </s-live-card>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script setup>
  56. import { reactive, onMounted } from 'vue';
  57. import sheep from '@/sheep';
  58. const state = reactive({
  59. liveList: [],
  60. mpLink: '',
  61. });
  62. const props = defineProps({
  63. data: {
  64. type: Object,
  65. default() {},
  66. },
  67. styles: {
  68. type: Object,
  69. default() {},
  70. },
  71. });
  72. const { mode, goodsFields, mpliveIds } = props.data ?? {};
  73. const { marginLeft, marginRight } = props.styles ?? {};
  74. async function getLiveListByIds(ids) {
  75. const { data } = await sheep.$api.app.mplive.getRoomList(ids);
  76. return data;
  77. }
  78. function goRoom(id) {
  79. // #ifdef MP-WEIXIN
  80. uni.navigateTo({
  81. url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${id}`,
  82. });
  83. // #endif
  84. // #ifndef MP-WEIXIN
  85. uni.showModal({
  86. title: '提示',
  87. confirmText: '允许',
  88. content: '将打开小程序访问',
  89. success: async function (res) {
  90. if (res.confirm) {
  91. getMpLink();
  92. }
  93. },
  94. });
  95. // #endif
  96. }
  97. function goMpLink() {
  98. // #ifdef H5
  99. window.location = state.mpLink;
  100. // #endif
  101. // #ifdef APP-PLUS
  102. plus.runtime.openURL(state.mpLink);
  103. // #endif
  104. }
  105. async function getMpLink() {
  106. // #ifndef MP-WEIXIN
  107. if (state.mpLink === '') {
  108. const { error, data } = await sheep.$api.app.mplive.getMpLink();
  109. if (error === 0) {
  110. state.mpLink = data;
  111. }
  112. }
  113. goMpLink();
  114. // #endif
  115. }
  116. onMounted(async () => {
  117. state.liveList = await getLiveListByIds(mpliveIds);
  118. });
  119. </script>
  120. <style lang="scss" scoped>
  121. .goods-list-box {
  122. width: 50%;
  123. flex-shrink: 0;
  124. box-sizing: border-box;
  125. overflow: hidden;
  126. }
  127. .goods-box {
  128. &:nth-last-of-type(1) {
  129. margin-bottom: 0 !important;
  130. }
  131. }
  132. .goods-md-box,
  133. .goods-sl-box {
  134. position: relative;
  135. }
  136. </style>