index.vue 4.4 KB

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