s-live-block.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 { code, data } = await sheep.$api.app.mplive.getRoomList(ids);
  76. if (code === 1) {
  77. return data;
  78. }
  79. }
  80. function goRoom(id) {
  81. // #ifdef MP-WEIXIN
  82. uni.navigateTo({
  83. url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${id}`,
  84. });
  85. // #endif
  86. // #ifndef MP-WEIXIN
  87. uni.showModal({
  88. title: $t('sheep.auth.tips'),
  89. confirmText: $t('sheep.auth.allow'),
  90. content: $t('sheep.auth.tipsContent'),
  91. success: async function (res) {
  92. if (res.confirm) {
  93. getMpLink();
  94. }
  95. },
  96. });
  97. // #endif
  98. }
  99. function goMpLink() {
  100. // #ifdef H5
  101. window.location = state.mpLink;
  102. // #endif
  103. // #ifdef APP-PLUS
  104. plus.runtime.openURL(state.mpLink);
  105. // #endif
  106. }
  107. async function getMpLink() {
  108. // #ifndef MP-WEIXIN
  109. if (state.mpLink === '') {
  110. const { code, data } = await sheep.$api.app.mplive.getMpLink();
  111. if (code === 1) {
  112. state.mpLink = data;
  113. }
  114. }
  115. goMpLink();
  116. // #endif
  117. }
  118. onMounted(async () => {
  119. state.liveList = await getLiveListByIds(mpliveIds);
  120. });
  121. </script>
  122. <style lang="scss" scoped>
  123. .goods-list-box {
  124. width: 50%;
  125. flex-shrink: 0;
  126. box-sizing: border-box;
  127. overflow: hidden;
  128. }
  129. .goods-box {
  130. &:nth-last-of-type(1) {
  131. margin-bottom: 0 !important;
  132. }
  133. }
  134. .goods-md-box,
  135. .goods-sl-box {
  136. position: relative;
  137. }
  138. </style>