index.vue 7.6 KB

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