index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div
  3. ref="topRef"
  4. class="area-wrap"
  5. :style="{ height: height + 'px' }"
  6. >
  7. <div
  8. v-if="0"
  9. class="tag-wrap"
  10. >
  11. <span
  12. v-for="(item, index) in appStore.areaList.find(
  13. (v) => v.id === Number(route.params.id)
  14. )?.children"
  15. :key="index"
  16. class="tag"
  17. >
  18. {{ item.name }}
  19. </span>
  20. </div>
  21. <LongList
  22. v-if="height > 0"
  23. ref="longListRef"
  24. class="list"
  25. :rootMargin="{
  26. top: 0,
  27. bottom: 100,
  28. left: 0,
  29. right: 0,
  30. }"
  31. :status="status"
  32. @get-list-data="getListData"
  33. >
  34. <div
  35. v-for="(item, index) in liveRoomList"
  36. :key="index"
  37. class="item"
  38. @click="goRoom(item)"
  39. >
  40. <div
  41. v-lazy:background-image="item?.cover_img || item?.users?.[0]?.avatar"
  42. class="cover"
  43. >
  44. <div
  45. v-if="item?.live"
  46. class="living-ico"
  47. >
  48. 直播中
  49. </div>
  50. <div
  51. v-if="
  52. item?.cdn === SwitchEnum.yes ||
  53. [
  54. LiveRoomTypeEnum.tencent_css,
  55. LiveRoomTypeEnum.tencent_css_pk,
  56. ].includes(item.type!)
  57. "
  58. class="cdn-ico"
  59. >
  60. <div class="txt">CDN</div>
  61. </div>
  62. <div class="txt">{{ item?.users?.[0]?.username }}</div>
  63. </div>
  64. <div class="desc">{{ item?.name }}</div>
  65. </div>
  66. </LongList>
  67. </div>
  68. </template>
  69. <script lang="ts" setup>
  70. import { openToTarget } from 'billd-utils';
  71. import { onMounted, reactive, ref, watch } from 'vue';
  72. import { useRoute } from 'vue-router';
  73. import { fetchLiveRoomList } from '@/api/area';
  74. import LongList from '@/components/LongList/index.vue';
  75. import { SwitchEnum } from '@/interface';
  76. import router, { routerName } from '@/router';
  77. import { useAppStore } from '@/store/app';
  78. import { ILiveRoom, LiveRoomTypeEnum } from '@/types/ILiveRoom';
  79. const liveRoomList = ref<ILiveRoom[]>([]);
  80. const appStore = useAppStore();
  81. const route = useRoute();
  82. const status = ref<'loading' | 'nonedata' | 'allLoaded' | 'normal'>('loading');
  83. const longListRef = ref<InstanceType<typeof LongList>>();
  84. const topRef = ref<HTMLDivElement>();
  85. const height = ref(-1);
  86. const loading = ref(false);
  87. const hasMore = ref(true);
  88. const pageParams = reactive({
  89. nowPage: 0,
  90. pageSize: 50,
  91. });
  92. watch(
  93. () => route.params.id,
  94. (newVal) => {
  95. if (!newVal) return;
  96. liveRoomList.value = [];
  97. pageParams.nowPage = 0;
  98. getData();
  99. }
  100. );
  101. function handleStatus() {
  102. if (loading.value) {
  103. status.value = 'loading';
  104. } else if (hasMore.value) {
  105. status.value = 'normal';
  106. } else {
  107. status.value = 'allLoaded';
  108. }
  109. if (!liveRoomList.value?.length) {
  110. status.value = 'nonedata';
  111. }
  112. }
  113. function goRoom(item: ILiveRoom) {
  114. if (!item.live) {
  115. window.$message.info('该直播间没在直播~');
  116. return;
  117. }
  118. const url = router.resolve({
  119. name: routerName.pull,
  120. params: { roomId: item.id },
  121. });
  122. openToTarget(url.href);
  123. }
  124. onMounted(() => {
  125. if (topRef.value) {
  126. height.value =
  127. document.documentElement.clientHeight -
  128. topRef.value.getBoundingClientRect().top;
  129. }
  130. getData();
  131. });
  132. function getListData() {
  133. if (!hasMore.value) return;
  134. getData();
  135. }
  136. async function getData() {
  137. try {
  138. if (loading.value) return;
  139. loading.value = true;
  140. status.value = 'loading';
  141. pageParams.nowPage += 1;
  142. const res = await fetchLiveRoomList({
  143. id: Number(route.params.id),
  144. live_room_is_show: SwitchEnum.yes,
  145. nowPage: pageParams.nowPage,
  146. pageSize: pageParams.pageSize,
  147. });
  148. if (res.code === 200) {
  149. liveRoomList.value.push(...res.data.rows);
  150. hasMore.value = res.data.hasMore;
  151. }
  152. } catch (error) {
  153. pageParams.nowPage -= 1;
  154. console.log(error);
  155. }
  156. loading.value = false;
  157. status.value = 'normal';
  158. handleStatus();
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .area-wrap {
  163. box-sizing: border-box;
  164. padding-top: $header-height;
  165. width: 100vw;
  166. background-color: #f1f2f3;
  167. .tag-wrap {
  168. .tag {
  169. display: inline-block;
  170. margin-right: 10px;
  171. padding: 2px 10px;
  172. font-size: 12px;
  173. border-radius: 10px;
  174. color: $theme-color-gold;
  175. border: 1px solid rgba($color: #999, $alpha: 0.3);
  176. }
  177. }
  178. .list {
  179. padding-top: 20px;
  180. display: flex;
  181. align-content: flex-start;
  182. flex-wrap: wrap;
  183. justify-content: space-between;
  184. .item {
  185. display: inline-block;
  186. margin-right: 25px;
  187. margin-bottom: 12px;
  188. width: 300px;
  189. cursor: pointer;
  190. .cover {
  191. position: relative;
  192. overflow: hidden;
  193. width: 100%;
  194. height: 150px;
  195. border-radius: 8px;
  196. @extend %containBg;
  197. .living-ico {
  198. position: absolute;
  199. top: 0px;
  200. left: 0px;
  201. z-index: 10;
  202. padding: 0 10px;
  203. height: 20px;
  204. border-radius: 8px 0 10px;
  205. background-color: $theme-color-gold;
  206. color: white;
  207. text-align: center;
  208. font-size: 12px;
  209. line-height: 20px;
  210. }
  211. .cdn-ico {
  212. position: absolute;
  213. top: -10px;
  214. right: -10px;
  215. z-index: 2;
  216. width: 70px;
  217. height: 28px;
  218. background-color: #f87c48;
  219. color: white;
  220. transform: rotate(45deg);
  221. transform-origin: bottom;
  222. .txt {
  223. margin-left: 18px;
  224. background-image: initial !important;
  225. font-size: 13px;
  226. }
  227. }
  228. .txt {
  229. position: absolute;
  230. bottom: 0;
  231. left: 0;
  232. box-sizing: border-box;
  233. padding: 4px 8px;
  234. width: 100%;
  235. border-radius: 0 0 4px 4px;
  236. background-image: linear-gradient(
  237. -180deg,
  238. rgba(0, 0, 0, 0),
  239. rgba(0, 0, 0, 0.6)
  240. );
  241. color: white;
  242. text-align: initial;
  243. font-size: 13px;
  244. @extend %singleEllipsis;
  245. }
  246. }
  247. .desc {
  248. margin-top: 4px;
  249. font-size: 14px;
  250. @extend %singleEllipsis;
  251. }
  252. }
  253. .null {
  254. width: 100%;
  255. text-align: center;
  256. }
  257. }
  258. .paging-wrap {
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. margin-bottom: 20px;
  263. }
  264. }
  265. </style>