lives.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <div class="box">
  3. <u-navbar class="navbar">
  4. <view class="slot-wrap">
  5. <u-search placeholder="搜索直播间" @custom="searchLive" @clear="clear" @search="searchLive" v-model="keyword"></u-search>
  6. </view>
  7. </u-navbar>
  8. <!-- 轮播图 -->
  9. <u-swiper @click="clickSwiper" class="swiper" :effect3d="true" :list="swiperImg">
  10. </u-swiper>
  11. <u-tabs :is-scroll="false" @change="changeTabs" :current="current" :active-color="activeColor" inactive-color="#606266" ref="tabs" :list="tabs"></u-tabs>
  12. <div class="wrapper">
  13. <!-- 直播中 全部 直播回放 -->
  14. <div class="live-item" :class="{'invalid':item.status == 'END'}" v-for="(item,index) in liveList" :key="index" @click="handleLivePlayer(item)">
  15. <div class="live-cover-img">
  16. <div class="tips">
  17. <div class="live-box">
  18. <image class="live-gif" src="./static/live.gif"></image>
  19. </div>
  20. <span>{{item.status == 'END' ? '已结束' : item.status =='NEW' ? '未开始' : '直播中'}}</span>
  21. </div>
  22. <div class="bg"></div>
  23. <u-image width="326" height="354" :src="item.shareImg" />
  24. </div>
  25. <div class="live-goods">
  26. <div class="live-goods-name">
  27. {{item.name}}
  28. </div>
  29. <div class="live-store">
  30. <span class="wes">lilishop</span>
  31. </div>
  32. <div class="live-goods-list">
  33. <div class="live-goods-item">
  34. <u-image border-radius="20" :src="item.roomGoodsList ? item.roomGoodsList[0] : ''" height="140"></u-image>
  35. </div>
  36. <div class="live-goods-item">
  37. <u-image border-radius="20" :src="item.roomGoodsList ? item.roomGoodsList[1] : ''" height="140"></u-image>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <u-loadmore v-if="liveList.length > 10" bg-color="#f8f8f8" :status="status" />
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import { getLiveList } from "@/api/promotions.js";
  48. export default {
  49. data() {
  50. return {
  51. status: "loadmore",
  52. activeColor: this.$lightColor,
  53. current: 0, // 当前tabs索引
  54. keyword: "", //搜索直播间
  55. // 标签栏
  56. tabs: [
  57. {
  58. name: "直播中",
  59. },
  60. {
  61. name: "全部",
  62. },
  63. ],
  64. // 导航栏的配置
  65. background: {
  66. background: "#ff9f28",
  67. },
  68. // 直播间params
  69. params: [
  70. {
  71. pageNumber: 1,
  72. pageSize: 10,
  73. status: "START",
  74. },
  75. {
  76. pageNumber: 1,
  77. pageSize: 4,
  78. },
  79. ],
  80. // 推荐直播间Params
  81. recommendParams: {
  82. pageNumber: 1,
  83. pageSize: 3,
  84. recommend: 0,
  85. },
  86. // 直播间列表
  87. liveList: [],
  88. // 推荐直播间列表
  89. recommendLiveList: [],
  90. //轮播图滚动的图片
  91. swiperImg: [
  92. {
  93. image:
  94. "https://lilishop-oss.oss-cn-beijing.aliyuncs.com/48d789cb9c864b7b87c1c0f70996c3e8.jpeg",
  95. },
  96. ],
  97. };
  98. },
  99. onShow() {
  100. this.params[this.current].pageNumber = 1;
  101. this.liveList = [];
  102. this.getLives();
  103. this.getRecommendLives();
  104. },
  105. onReachBottom() {
  106. this.params[this.current].pageNumber++;
  107. this.getLives();
  108. },
  109. methods: {
  110. /**
  111. * 点击标签栏切换
  112. */
  113. changeTabs(index) {
  114. this.current = index;
  115. this.init();
  116. },
  117. /**
  118. * 初始化直播间
  119. */
  120. init() {
  121. this.liveList = [];
  122. this.status = "loadmore";
  123. this.getLives();
  124. },
  125. /**
  126. * 清除搜索内容
  127. */
  128. clear() {
  129. delete this.params[this.current].name;
  130. this.init();
  131. },
  132. /**
  133. * 点击顶部推荐直播间
  134. */
  135. clickSwiper(val) {
  136. console.log(this.swiperImg[val]);
  137. this.handleLivePlayer(this.swiperImg[val]);
  138. },
  139. /**
  140. * 搜索直播间
  141. */
  142. searchLive(val) {
  143. this.params[this.current].pageNumber = 1;
  144. this.params[this.current].name = val;
  145. this.init();
  146. },
  147. /**
  148. * 获取推荐直播间
  149. */
  150. async getRecommendLives() {
  151. this.status = "loading";
  152. let recommendLives = await getLiveList(this.recommendParams);
  153. if (recommendLives.data.success) {
  154. // 推荐直播间
  155. if (recommendLives.data.result.records.length != 0) {
  156. this.status = "loadmore";
  157. this.recommendLives = recommendLives.data.result.records;
  158. } else {
  159. this.status = "noMore";
  160. }
  161. /**
  162. * 如果推荐直播间没有的情况下
  163. * 1.获取直播间第一个图片
  164. * 2.如果没有直播间设置一个默认图片
  165. */
  166. if (this.recommendLives.length == 0) {
  167. if (this.liveList[0].shareImg) {
  168. this.$set(this, "swiperImg", [
  169. {
  170. image: this.liveList[0].shareImg,
  171. roomId: this.liveList[0].roomId,
  172. },
  173. ]);
  174. }
  175. } else {
  176. this.recommendLives.forEach((item) => {
  177. this.$set(this, "swiperImg", [
  178. { image: item.shareImg, roomId: item.roomId },
  179. ]);
  180. });
  181. }
  182. }
  183. },
  184. /**
  185. * 获取直播间
  186. */
  187. async getLives() {
  188. this.status = "loading";
  189. let res = await getLiveList(this.params[this.current]);
  190. // 直播间
  191. if (res.data.success) {
  192. if (res.data.result.records.length != 0) {
  193. this.status = "loadmore";
  194. this.liveList.push(...res.data.result.records);
  195. } else {
  196. this.status = "noMore";
  197. }
  198. res.data.result.total >
  199. this.params[this.current].pageNumber *
  200. this.params[this.current].pageSize
  201. ? (this.status = "loadmore")
  202. : (this.status = "noMore");
  203. console.log(this.status);
  204. this.liveList.forEach((item) => {
  205. if (item.roomGoodsList) {
  206. item.roomGoodsList = JSON.parse(item.roomGoodsList);
  207. }
  208. });
  209. }
  210. },
  211. /**
  212. * 进入直播间
  213. */
  214. handleLivePlayer(val) {
  215. let roomId = val.roomId; // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  216. let customParams = encodeURIComponent(
  217. JSON.stringify({ path: "pages/index/index", pid: 1 })
  218. ); // 开发者在直播间页面路径上携带自定义参数,后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  219. uni.navigateTo({
  220. url:
  221. "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" +
  222. roomId +
  223. "&custom_params=" +
  224. customParams,
  225. });
  226. },
  227. },
  228. };
  229. </script>
  230. <style lang="scss" scoped>
  231. .slot-wrap {
  232. display: flex;
  233. align-items: center;
  234. /* 如果您想让slot内容占满整个导航栏的宽度 */
  235. flex: 1;
  236. /* 如果您想让slot内容与导航栏左右有空隙 */
  237. /* padding: 0 30rpx; */
  238. }
  239. .invalid {
  240. filter: grayscale(1);
  241. }
  242. .wrapper {
  243. padding: 0 24rpx;
  244. }
  245. .live-item {
  246. display: flex;
  247. overflow: hidden;
  248. border-radius: 20rpx;
  249. flex-wrap: wrap;
  250. background: #fff;
  251. margin: 20rpx 0;
  252. }
  253. .live-cover-img {
  254. position: relative;
  255. }
  256. .swiper {
  257. margin: 20rpx 0;
  258. }
  259. .live-goods {
  260. position: relative;
  261. flex: 1;
  262. padding: 16rpx 24rpx 24rpx;
  263. }
  264. .live-goods-name {
  265. height: 84rpx;
  266. font-weight: bold;
  267. font-size: 30rpx;
  268. display: -webkit-box;
  269. -webkit-box-orient: vertical;
  270. -webkit-line-clamp: 2;
  271. overflow: hidden;
  272. }
  273. .live-store {
  274. display: flex;
  275. align-items: center;
  276. margin: 20rpx 0;
  277. overflow: hidden;
  278. width: calc(100% - 50rpx);
  279. }
  280. .live-gif {
  281. width: 20rpx;
  282. height: 20rpx;
  283. }
  284. .live-box {
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. border-radius: 50%;
  289. width: 40rpx;
  290. margin-right: 10rpx;
  291. height: 40rpx;
  292. background: linear-gradient(90deg, #ff6b35, #ff9f28, #ffcc03);
  293. }
  294. .live-goods-list {
  295. display: flex;
  296. align-items: center;
  297. justify-content: space-between;
  298. > .live-goods-item {
  299. flex: 1;
  300. }
  301. > .live-goods-item:nth-of-type(1) {
  302. padding-right: 38rpx;
  303. }
  304. }
  305. .live-icon,
  306. .zan {
  307. position: absolute;
  308. width: 80rpx;
  309. height: 80rpx;
  310. z-index: 9;
  311. }
  312. .tips {
  313. display: flex;
  314. position: absolute;
  315. z-index: 9;
  316. align-items: center;
  317. top: 20rpx;
  318. right: 0;
  319. padding: 4rpx 12rpx 4rpx 0;
  320. font-size: 24rpx;
  321. border-radius: 100px;
  322. color: #fff;
  323. background: rgba(0, 0, 0, 0.46);
  324. }
  325. .live-icon {
  326. right: 0;
  327. top: 104rpx;
  328. }
  329. .zan {
  330. bottom: 0;
  331. right: 0;
  332. width: 100rpx;
  333. height: 100rpx;
  334. }
  335. .bg {
  336. position: absolute;
  337. bottom: 4rpx;
  338. width: 100%;
  339. height: 100rpx;
  340. z-index: 8;
  341. background-image: -webkit-gradient(
  342. linear,
  343. left bottom,
  344. left top,
  345. from(rgba(0, 0, 0, 0.25)),
  346. color-stop(82%, transparent)
  347. );
  348. background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.25), transparent 82%);
  349. border-bottom-left-radius: 20rpx;
  350. }
  351. </style>