index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div class="area-wrap">
  3. <div
  4. v-loading="loading"
  5. class="live-room-list"
  6. >
  7. <div
  8. v-for="(iten, indey) in liveRoomList"
  9. :key="indey"
  10. class="live-room"
  11. @click="goRoom(iten)"
  12. >
  13. <div
  14. class="cover"
  15. :style="{
  16. backgroundImage: `url('${
  17. iten?.cover_img || iten?.users?.[0].avatar
  18. }')`,
  19. }"
  20. >
  21. <div
  22. v-if="iten?.cdn === 1"
  23. class="cdn-ico"
  24. >
  25. <div class="txt">CDN</div>
  26. </div>
  27. <div class="txt">{{ iten?.users?.[0].username }}</div>
  28. </div>
  29. <div class="desc">{{ iten?.name }}</div>
  30. </div>
  31. <div
  32. v-if="!liveRoomList.length"
  33. class="null"
  34. >
  35. 暂无数据
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script lang="ts" setup>
  41. import { onMounted, ref, watch } from 'vue';
  42. import { useRoute } from 'vue-router';
  43. import { fetchLiveRoomList } from '@/api/area';
  44. import { ILiveRoom, liveTypeEnum } from '@/interface';
  45. import router, { routerName } from '@/router';
  46. const liveRoomList = ref<ILiveRoom[]>([]);
  47. const route = useRoute();
  48. const loading = ref(false);
  49. watch(
  50. () => route.params.id,
  51. (newVal) => {
  52. if (!newVal) return;
  53. getData();
  54. }
  55. );
  56. function goRoom(item: ILiveRoom) {
  57. if (!item.live) {
  58. window.$message.info('该直播间没在直播~');
  59. return;
  60. }
  61. router.push({
  62. name: routerName.pull,
  63. params: { roomId: item.id },
  64. query: {
  65. liveType: liveTypeEnum.srsFlvPull,
  66. },
  67. });
  68. }
  69. onMounted(() => {
  70. getData();
  71. });
  72. async function getData() {
  73. try {
  74. loading.value = true;
  75. const res = await fetchLiveRoomList({
  76. id: Number(route.params.id),
  77. });
  78. if (res.code === 200) {
  79. liveRoomList.value = res.data.rows;
  80. }
  81. } catch (error) {
  82. console.log(error);
  83. } finally {
  84. loading.value = false;
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .area-wrap {
  90. padding: 15px 20px;
  91. .title {
  92. margin-bottom: 10px;
  93. }
  94. .live-room-list {
  95. display: flex;
  96. align-items: center;
  97. flex-wrap: wrap;
  98. .live-room {
  99. display: inline-block;
  100. margin-right: 25px;
  101. margin-bottom: 12px;
  102. width: 300px;
  103. cursor: pointer;
  104. .cover {
  105. position: relative;
  106. overflow: hidden;
  107. width: 100%;
  108. height: 150px;
  109. border-radius: 8px;
  110. background-position: center center;
  111. background-size: cover;
  112. .cdn-ico {
  113. position: absolute;
  114. right: -10px;
  115. top: -10px;
  116. background-color: #f87c48;
  117. color: white;
  118. z-index: 2;
  119. height: 28px;
  120. width: 70px;
  121. transform-origin: bottom;
  122. transform: rotate(45deg);
  123. .txt {
  124. margin-left: 18px;
  125. font-size: 13px;
  126. background-image: initial !important;
  127. }
  128. }
  129. .txt {
  130. position: absolute;
  131. bottom: 0;
  132. left: 0;
  133. box-sizing: border-box;
  134. padding: 4px 8px;
  135. width: 100%;
  136. border-radius: 0 0 4px 4px;
  137. background-image: linear-gradient(
  138. -180deg,
  139. rgba(0, 0, 0, 0),
  140. rgba(0, 0, 0, 0.6)
  141. );
  142. color: white;
  143. text-align: initial;
  144. font-size: 13px;
  145. @extend %singleEllipsis;
  146. }
  147. }
  148. .desc {
  149. margin-top: 4px;
  150. font-size: 14px;
  151. @extend %singleEllipsis;
  152. }
  153. }
  154. }
  155. }
  156. </style>