index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="h5-wrap">
  3. <div
  4. class="swiper"
  5. :style="{ backgroundColor: currentSwiper.bg }"
  6. >
  7. {{ currentSwiper.txt }}
  8. </div>
  9. <!-- <div v-if="currentNav.id === appStore.mobileNav?.id"> -->
  10. <div class="type-list">
  11. <div
  12. v-for="(item, index) in liveRoomList"
  13. :key="index"
  14. class="item"
  15. >
  16. <div
  17. class="title"
  18. @click.stop
  19. >
  20. <div class="left">{{ item.name }}</div>
  21. <div
  22. class="right"
  23. @click="showAll(item)"
  24. >
  25. 查看全部
  26. </div>
  27. </div>
  28. <div class="live-room-list">
  29. <div
  30. v-for="(iten, indey) in item.area_live_rooms"
  31. :key="indey"
  32. class="live-room"
  33. @click="goRoom(iten)"
  34. >
  35. <div
  36. class="cover"
  37. :style="{
  38. backgroundImage: `url('${
  39. iten.live_room?.cover_img || iten.live_room?.users?.[0].avatar
  40. }')`,
  41. }"
  42. >
  43. <div class="txt">{{ iten.live_room?.users?.[0].username }}</div>
  44. </div>
  45. <div class="desc">{{ iten.live_room?.name }}</div>
  46. </div>
  47. <div
  48. v-if="!item.area_live_rooms?.length"
  49. class="null"
  50. >
  51. 暂无数据
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script lang="ts" setup>
  59. import { onMounted, ref } from 'vue';
  60. import { fetchAreaLiveRoomList } from '@/api/area';
  61. import { IArea, IAreaLiveRoom, liveTypeEnum } from '@/interface';
  62. import router, { mobileRouterName, routerName } from '@/router';
  63. import { useAppStore } from '@/store/app';
  64. const appStore = useAppStore();
  65. const navList = ref([
  66. { id: 1, name: '频道' },
  67. { id: 2, name: '排行' },
  68. { id: 3, name: '我的' },
  69. ]);
  70. const currentNav = ref(navList.value[0]);
  71. const liveRoomList = ref<IArea[]>([]);
  72. const swiperList = ref([
  73. { id: 1, txt: '广告位1', bg: '#FFCC70', url: '' },
  74. { id: 2, txt: '广告位2', bg: '#C850C0', url: '' },
  75. { id: 3, txt: '广告位3', bg: '#4158D0', url: '' },
  76. ]);
  77. const timer = ref();
  78. const currentSwiper = ref({ id: 1, txt: '广告位1', bg: '#FFCC70', url: '' });
  79. async function getLiveRoomList() {
  80. try {
  81. const res = await fetchAreaLiveRoomList({
  82. orderName: 'created_at',
  83. orderBy: 'desc',
  84. });
  85. if (res.code === 200) {
  86. liveRoomList.value = res.data.rows;
  87. }
  88. } catch (error) {
  89. console.log(error);
  90. }
  91. }
  92. function showAll(item: IArea) {
  93. router.push({
  94. name: mobileRouterName.h5Area,
  95. params: { areaId: item.id },
  96. query: { name: item.name },
  97. });
  98. }
  99. function goRoom(item: IAreaLiveRoom) {
  100. router.push({
  101. name: routerName.h5Room,
  102. params: { roomId: item.live_room_id },
  103. query: {
  104. liveType: liveTypeEnum.srsHlsPull,
  105. },
  106. });
  107. }
  108. onMounted(() => {
  109. getLiveRoomList();
  110. let num = 0;
  111. timer.value = setInterval(() => {
  112. num += 1;
  113. if (num > swiperList.value.length - 1) {
  114. num = 0;
  115. }
  116. currentSwiper.value = swiperList.value[num];
  117. }, 3000);
  118. });
  119. </script>
  120. <style lang="scss" scoped>
  121. .h5-wrap {
  122. background-color: #f4f4f4;
  123. .logo-bar {
  124. display: flex;
  125. align-items: center;
  126. box-sizing: border-box;
  127. padding: 0 20px;
  128. height: 40px;
  129. border-bottom: 1px solid #e7e7e7;
  130. background-color: white;
  131. .logo {
  132. width: 90px;
  133. height: 36px;
  134. @include setBackground('@/assets/img/logo-txt.png');
  135. }
  136. }
  137. .nav-list {
  138. display: flex;
  139. align-items: center;
  140. height: 40px;
  141. background-color: white;
  142. line-height: 40px;
  143. .item {
  144. position: relative;
  145. margin: 0 20px;
  146. &.active {
  147. &::after {
  148. position: absolute;
  149. right: 0;
  150. bottom: 0;
  151. width: 100%;
  152. height: 4px;
  153. background-color: $theme-color-gold;
  154. content: '';
  155. }
  156. }
  157. }
  158. }
  159. .swiper {
  160. width: 100%;
  161. height: 130px;
  162. display: flex;
  163. align-items: center;
  164. justify-content: center;
  165. user-select: none;
  166. font-size: 30px;
  167. }
  168. .type-list {
  169. .item {
  170. margin: 15px 0;
  171. padding: 15px;
  172. background-color: white;
  173. .title {
  174. display: flex;
  175. align-items: center;
  176. justify-content: space-between;
  177. margin-bottom: 10px;
  178. .left {
  179. }
  180. .right {
  181. color: #999;
  182. font-size: 14px;
  183. }
  184. }
  185. .live-room-list {
  186. display: flex;
  187. align-items: center;
  188. flex-wrap: wrap;
  189. justify-content: space-between;
  190. .live-room {
  191. display: inline-block;
  192. margin-bottom: 10px;
  193. width: 48%;
  194. .cover {
  195. position: relative;
  196. overflow: hidden;
  197. width: 100%;
  198. height: 100px;
  199. border-radius: 8px;
  200. background-position: center center;
  201. background-size: cover;
  202. .txt {
  203. position: absolute;
  204. bottom: 0;
  205. left: 0;
  206. box-sizing: border-box;
  207. padding: 4px 8px;
  208. width: 100%;
  209. border-radius: 0 0 4px 4px;
  210. background-image: linear-gradient(
  211. -180deg,
  212. rgba(0, 0, 0, 0),
  213. rgba(0, 0, 0, 0.6)
  214. );
  215. color: white;
  216. text-align: initial;
  217. font-size: 13px;
  218. @extend %singleEllipsis;
  219. }
  220. }
  221. .desc {
  222. font-size: 14px;
  223. margin-top: 4px;
  224. @extend %singleEllipsis;
  225. }
  226. }
  227. }
  228. }
  229. }
  230. }
  231. </style>