index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="h5-wrap">
  3. <div
  4. class="swiper"
  5. :style="{ backgroundImage: `url(${currentSwiper.bgi})` }"
  6. >
  7. <!-- {{ currentSwiper.txt }} -->
  8. </div>
  9. <div class="type-list">
  10. <div
  11. v-for="(item, index) in liveRoomList"
  12. :key="index"
  13. class="item"
  14. >
  15. <div
  16. class="title"
  17. @click.stop
  18. >
  19. <div class="left">{{ item.name }}</div>
  20. <div
  21. class="right"
  22. @click="showAll(item)"
  23. >
  24. 查看全部
  25. </div>
  26. </div>
  27. <div class="live-room-list">
  28. <div
  29. v-for="(iten, indey) in item.area_live_rooms"
  30. :key="indey"
  31. class="live-room"
  32. @click="goRoom(iten)"
  33. >
  34. <div
  35. class="cover"
  36. :style="{
  37. backgroundImage: `url('${
  38. iten.live_room?.cover_img || iten.live_room?.users?.[0].avatar
  39. }')`,
  40. }"
  41. >
  42. <PullAuthTip
  43. v-if="
  44. iten?.live_room?.pull_is_should_auth ===
  45. LiveRoomPullIsShouldAuthEnum.yes
  46. "
  47. ></PullAuthTip>
  48. <div
  49. v-if="iten?.live_room?.live"
  50. class="living-ico"
  51. >
  52. 直播中
  53. </div>
  54. <div
  55. v-if="iten.live_room?.cdn === LiveRoomUseCDNEnum.yes"
  56. class="cdn-ico"
  57. >
  58. <div class="txt">CDN</div>
  59. </div>
  60. <div class="txt">{{ iten.live_room?.users?.[0].username }}</div>
  61. </div>
  62. <div class="desc">{{ iten.live_room?.name }}</div>
  63. </div>
  64. <div
  65. v-if="!item.area_live_rooms?.length"
  66. class="null"
  67. >
  68. 暂无数据
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </template>
  75. <script lang="ts" setup>
  76. import { onMounted, onUnmounted, ref } from 'vue';
  77. import { fetchAreaLiveRoomList } from '@/api/area';
  78. import { IArea, IAreaLiveRoom } from '@/interface';
  79. import router, { mobileRouterName, routerName } from '@/router';
  80. import { useAppStore } from '@/store/app';
  81. import {
  82. LiveRoomIsShowEnum,
  83. LiveRoomPullIsShouldAuthEnum,
  84. LiveRoomUseCDNEnum,
  85. } from '@/types/ILiveRoom';
  86. const appStore = useAppStore();
  87. const liveRoomList = ref<IArea[]>([]);
  88. const swiperList = ref([
  89. {
  90. id: 1,
  91. txt: '广告位1',
  92. bgi: 'https://resource.hsslive.cn/billd-live/image/ecdece08eb3eda2f37433cb7c748766f.webp',
  93. url: '',
  94. },
  95. {
  96. id: 2,
  97. txt: '广告位2',
  98. bgi: 'https://resource.hsslive.cn/billd-live/image/b2e3459e7d4a70463cd201ee468491a1.webp',
  99. url: '',
  100. },
  101. {
  102. id: 3,
  103. txt: '广告位3',
  104. bgi: 'https://resource.hsslive.cn/billd-live/image/71d01ff0bd34c57586500e425e21938f.webp',
  105. url: '',
  106. },
  107. ]);
  108. const swiperTimer = ref();
  109. const currentSwiper = ref(swiperList.value[0]);
  110. async function getLiveRoomList() {
  111. try {
  112. const res = await fetchAreaLiveRoomList({
  113. live_room_is_show: LiveRoomIsShowEnum.yes,
  114. orderName: 'created_at',
  115. orderBy: 'desc',
  116. });
  117. if (res.code === 200) {
  118. liveRoomList.value = res.data.rows;
  119. }
  120. } catch (error) {
  121. console.log(error);
  122. }
  123. }
  124. function showAll(item: IArea) {
  125. router.push({
  126. name: mobileRouterName.h5Area,
  127. params: { id: item.id },
  128. });
  129. }
  130. function goRoom(item: IAreaLiveRoom) {
  131. if (!item.live_room?.live) {
  132. window.$message.info('该直播间没在直播~');
  133. return;
  134. }
  135. router.push({
  136. name: routerName.h5Room,
  137. params: { roomId: item.live_room_id },
  138. });
  139. }
  140. onMounted(() => {
  141. getLiveRoomList();
  142. let num = 0;
  143. swiperTimer.value = setInterval(() => {
  144. num += 1;
  145. if (num > swiperList.value.length - 1) {
  146. num = 0;
  147. }
  148. currentSwiper.value = swiperList.value[num];
  149. }, 3000);
  150. });
  151. onUnmounted(() => {
  152. clearInterval(swiperTimer.value);
  153. appStore.showLoginModal = false;
  154. });
  155. </script>
  156. <style lang="scss" scoped>
  157. .h5-wrap {
  158. background-color: #f4f4f4;
  159. .logo-bar {
  160. display: flex;
  161. align-items: center;
  162. box-sizing: border-box;
  163. padding: 0 20px;
  164. height: 40px;
  165. border-bottom: 1px solid #e7e7e7;
  166. background-color: white;
  167. .logo {
  168. width: 90px;
  169. height: 36px;
  170. @include setBackground('@/assets/img/logo-txt.png');
  171. }
  172. }
  173. .nav-list {
  174. display: flex;
  175. align-items: center;
  176. height: 40px;
  177. background-color: white;
  178. line-height: 40px;
  179. .item {
  180. position: relative;
  181. margin: 0 20px;
  182. &.active {
  183. &::after {
  184. position: absolute;
  185. right: 0;
  186. bottom: 0;
  187. width: 100%;
  188. height: 4px;
  189. background-color: $theme-color-gold;
  190. content: '';
  191. }
  192. }
  193. }
  194. }
  195. .swiper {
  196. width: 100%;
  197. height: 180px;
  198. background-size: cover;
  199. background-repeat: no-repeat;
  200. background-position: center center;
  201. }
  202. .type-list {
  203. .item {
  204. margin: 15px 0;
  205. padding: 15px;
  206. background-color: white;
  207. .title {
  208. display: flex;
  209. align-items: center;
  210. justify-content: space-between;
  211. margin-bottom: 10px;
  212. .left {
  213. }
  214. .right {
  215. color: #999;
  216. font-size: 14px;
  217. }
  218. }
  219. .live-room-list {
  220. display: flex;
  221. align-items: center;
  222. flex-wrap: wrap;
  223. justify-content: space-between;
  224. .live-room {
  225. display: inline-block;
  226. margin-bottom: 10px;
  227. width: 48%;
  228. height: 130px;
  229. .cover {
  230. position: relative;
  231. overflow: hidden;
  232. width: 100%;
  233. height: 100px;
  234. border-radius: 8px;
  235. background-position: center center;
  236. background-size: cover;
  237. .living-ico {
  238. position: absolute;
  239. top: 0px;
  240. left: 0px;
  241. z-index: 10;
  242. padding: 0 10px;
  243. height: 20px;
  244. border-radius: 8px 0 10px;
  245. background-color: $theme-color-gold;
  246. color: white;
  247. text-align: center;
  248. font-size: 12px;
  249. line-height: 20px;
  250. }
  251. .cdn-ico {
  252. position: absolute;
  253. top: -12px;
  254. right: -12px;
  255. z-index: 2;
  256. width: 70px;
  257. height: 22px;
  258. background-color: #f87c48;
  259. transform: rotate(45deg);
  260. transform-origin: bottom;
  261. .txt {
  262. margin-left: 18px;
  263. background-image: initial !important;
  264. color: white;
  265. font-size: 10px;
  266. transform: scale(0.83333) translate(2px, 3px);
  267. }
  268. }
  269. .txt {
  270. position: absolute;
  271. bottom: 0;
  272. left: 0;
  273. box-sizing: border-box;
  274. padding: 4px 8px;
  275. width: 100%;
  276. border-radius: 0 0 4px 4px;
  277. background-image: linear-gradient(
  278. -180deg,
  279. rgba(0, 0, 0, 0),
  280. rgba(0, 0, 0, 0.6)
  281. );
  282. color: white;
  283. text-align: initial;
  284. font-size: 13px;
  285. @extend %singleEllipsis;
  286. }
  287. }
  288. .desc {
  289. font-size: 14px;
  290. margin-top: 4px;
  291. @extend %singleEllipsis;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. }
  298. </style>