app-live.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <view v-if="value.live_list.length > 0" class="app-live" :style="{background: value.background}">
  3. <view class="live-style-1 shadow"
  4. v-if="value.style_type == 1"
  5. v-for="(item, index) in value.live_list"
  6. :key="index"
  7. @click="liveClick(item)">
  8. <view class="item">
  9. <image class="anchor-img" mode="aspectFill" :src="item.anchor_img"></image>
  10. <view class="gradient"></view>
  11. <view class="label-box">
  12. <view class="label-item"
  13. :class="{'label-item-over': item.live_status == 103,
  14. 'label-item-notice': item.live_status == 102}">
  15. <image v-if="item.live_status == 101" class="live-ing"
  16. src="/static/image/icon/liveing.png"></image>
  17. <view v-else class="round"></view>
  18. <span class="label-text">{{item.status_text}}</span>
  19. </view>
  20. <span v-if="item.live_status == 102" class="text-time">{{item.text_time}}</span>
  21. </view>
  22. <view class="user-info">
  23. <image class="avatar" mode="aspectFill" :src="item.anchor_img"></image>
  24. <span class="nickname ellipsis">{{item.anchor_name}}</span>
  25. </view>
  26. <image v-if="item.live_status === 103" class="play-icon"
  27. src="/static/image/video-play.png"></image>
  28. </view>
  29. <span class="title ellipsis">{{item.name}}</span>
  30. <view v-if="value.is_show_goods == true && item.goods.length > 0" class="goods-info">
  31. <image mode="aspectFill" class="goods-cover" :src="item.goods[0].cover_img"></image>
  32. <view class="goods-item">
  33. <span class="goods-name ellipsis">{{item.goods[0].name}}</span>
  34. <span class="goods-price">¥{{item.goods[0].price}}</span>
  35. </view>
  36. </view>
  37. </view>
  38. <view v-if="value.style_type == 2" class="wrap-box">
  39. <view class="wrap-item" v-for="(valueItem, valueIndex) in newValue" :key="valueIndex">
  40. <view class="live-style-2 shadow"
  41. v-for="(item, index) in valueItem.live_list"
  42. :key="index"
  43. @click="liveClick(item)">
  44. <view class="item">
  45. <image mode="aspectFill" class="anchor-img" :src="item.anchor_img"></image>
  46. <view class="gradient"></view>
  47. <view class="label-box">
  48. <view class="label-item"
  49. :class="{'label-item-over': item.live_status == 103,
  50. 'label-item-notice': item.live_status == 102}">
  51. <image v-if="item.live_status == 101" class="live-ing"
  52. src="/static/image/icon/liveing.png"></image>
  53. <view v-else class="round"></view>
  54. <span class="label-text">{{item.status_text}}</span>
  55. </view>
  56. <span v-if="item.live_status == 102" class="text-time">{{item.text_time}}</span>
  57. </view>
  58. <view class="user-info">
  59. <image class="avatar" mode="aspectFill" :src="item.anchor_img"></image>
  60. <span class="nickname ellipsis">{{item.anchor_name}}</span>
  61. </view>
  62. <image v-if="item.live_status === 103" class="play-icon"
  63. src="/static/image/video-play.png"></image>
  64. </view>
  65. <span class="title ellipsis">{{item.name}}</span>
  66. <view v-if="value.is_show_goods == true && item.goods.length > 0" class="goods-info">
  67. <image mode="aspectFill" class="goods-cover" :src="item.goods[0].cover_img"></image>
  68. <view class="goods-item">
  69. <span class="goods-name ellipsis">{{item.goods[0].name}}</span>
  70. <span class="goods-price">¥{{item.goods[0].price}}</span>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="live-style-3 shadow"
  77. v-if="value.style_type == 3"
  78. v-for="(item, index) in value.live_list"
  79. :key="index"
  80. @click="liveClick(item)">
  81. <view class="item">
  82. <image mode="aspectFill" class="anchor-img" :src="item.anchor_img"></image>
  83. <view class="gradient"></view>
  84. <view class="label-box">
  85. <view class="label-item"
  86. :class="{'label-item-over': item.live_status == 103,
  87. 'label-item-notice': item.live_status == 102}">
  88. <image v-if="item.live_status == 101" class="live-ing"
  89. src="/static/image/icon/liveing.png"></image>
  90. <view v-else class="round"></view>
  91. <span class="label-text">{{item.status_text}}</span>
  92. </view>
  93. <span v-if="item.live_status == 102" class="text-time">{{item.text_time}}</span>
  94. </view>
  95. <image v-if="item.live_status === 103" class="play-icon"
  96. src="/static/image/video-play.png"></image>
  97. </view>
  98. <view class="item-2">
  99. <span class="title">{{item.name}}</span>
  100. <view class="user-info">
  101. <image class="avatar" mode="aspectFill" :src="item.anchor_img"></image>
  102. <span class="nickname ellipsis">{{item.anchor_name}}</span>
  103. </view>
  104. <view v-if="value.is_show_goods == true && item.goods.length > 0" class="goods-info">
  105. <view class="goods-cover">
  106. <view class="gradient"></view>
  107. <image mode="aspectFill" :src="item.goods[0].cover_img"></image>
  108. <span class="goods-price">¥{{item.goods[0].price}}</span>
  109. </view>
  110. <view class="goods-cover goods-cover-2" v-if="item.goods.length >= 2">
  111. <view class="shade"></view>
  112. <image mode="aspectFill" :src="item.goods[1].cover_img"></image>
  113. <view class="goods-count">
  114. <span class="number">{{item.goods.length}}</span>
  115. <span>宝贝</span>
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. </template>
  123. <script>
  124. import {mapState} from "vuex";
  125. export default {
  126. name: 'app-live',
  127. components: {},
  128. props: {
  129. value: {
  130. type: Object,
  131. default: function () {
  132. return {
  133. background: '#f7f7f7',
  134. live_list: [],
  135. is_show_goods: true,
  136. number: 5,
  137. style_type: 1
  138. }
  139. }
  140. },
  141. },
  142. data() {
  143. return {}
  144. },
  145. computed: {
  146. newValue() {
  147. let self = this;
  148. let newValue = [
  149. {
  150. background: self.value.background,
  151. is_show_goods: self.value.is_show_goods,
  152. number: self.value.number,
  153. style_type: self.value.style_type,
  154. live_list: [],
  155. }, {
  156. background: self.value.background,
  157. is_show_goods: self.value.is_show_goods,
  158. number: self.value.number,
  159. style_type: self.value.style_type,
  160. live_list: [],
  161. },
  162. ];
  163. let number1 = 0;
  164. let number2 = 0;
  165. self.value.live_list.forEach((item, index) => {
  166. let sign = item.goods.length > 0 ? true : false;
  167. if (number1 == 0 || number1 <= number2) {
  168. number1 = sign ? number1 + 2 : number1 + 1;
  169. newValue[0].live_list.push(item);
  170. } else {
  171. number2 = sign ? number2 + 2 : number2 + 1;
  172. newValue[1].live_list.push(item);
  173. }
  174. });
  175. return newValue;
  176. },
  177. ...mapState({
  178. userInfo: state => state.user.info,
  179. })
  180. },
  181. methods: {
  182. liveClick(liveData) {
  183. let userId = this.userInfo ? this.userInfo.options.user_id : 0;
  184. let customParams = {user_id: userId}; // 开发者在直播间页面路径上携带自定义参数
  185. uni.navigateTo({
  186. url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${liveData.roomid}&custom_params=${encodeURIComponent(JSON.stringify(customParams))}`
  187. })
  188. }
  189. }
  190. }
  191. </script>
  192. <style scoped lang="scss">
  193. .app-live {
  194. padding: 20#{rpx};
  195. .shadow {
  196. box-shadow: 0 0 10#{rpx} 5#{rpx} rgba(0, 0, 0, 0.1);
  197. }
  198. .label-item {
  199. border-top-left-radius:16#{rpx};
  200. border-top-right-radius: 30#{rpx};
  201. border-bottom-right-radius: 30#{rpx};
  202. background: #ff4544;
  203. padding: 12#{rpx} 20#{rpx};
  204. display: flex;
  205. align-items: center;
  206. }
  207. .label-item-over {
  208. background: #777777;
  209. }
  210. .label-item-notice {
  211. background: #22ac38;
  212. }
  213. .round {
  214. width: 12#{rpx};
  215. height: 12#{rpx};
  216. background: #ffffff;
  217. border-radius: 50%;
  218. }
  219. .live-ing {
  220. width: 24#{rpx};
  221. height: 24#{rpx};
  222. }
  223. .label-text {
  224. margin-left: 12#{rpx};
  225. color: #ffffff;
  226. font-size: 26#{rpx};
  227. }
  228. .label-box {
  229. position: absolute;
  230. top: 0;
  231. left: 0;
  232. border-top-left-radius: 16#{rpx};
  233. border-top-right-radius: 30#{rpx};
  234. border-bottom-right-radius: 30#{rpx};
  235. background: rgba(0, 0, 0, 0.5);
  236. display: flex;
  237. align-items: center;
  238. z-index: 20;
  239. }
  240. .ellipsis {
  241. overflow: hidden;
  242. text-overflow: ellipsis;
  243. white-space: nowrap;
  244. }
  245. .play-icon {
  246. width: 100#{rpx};
  247. height: 100#{rpx};
  248. z-index: 20;
  249. }
  250. .user-info {
  251. display: flex;
  252. align-items: center;
  253. z-index: 20;
  254. .avatar {
  255. width: 40#{rpx};
  256. height: 40#{rpx};
  257. border-radius: 50%;
  258. }
  259. .nickname {
  260. color: #ffffff;
  261. font-size: 24#{rpx};
  262. margin-left: 12#{rpx};
  263. width: 578#{rpx};
  264. }
  265. }
  266. .text-time {
  267. color: #ffffff;
  268. font-size: 24#{rpx};
  269. margin: 0 20#{rpx} 0 12#{rpx};
  270. }
  271. .shade {
  272. width: 100%;
  273. height: 100%;
  274. background: rgba(0, 0, 0, 0.3);
  275. position: absolute;
  276. z-index: 10;
  277. }
  278. .gradient {
  279. width: 100%;
  280. height: 100%;
  281. position: absolute;
  282. top: 0;
  283. left: 0;
  284. background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.5));
  285. }
  286. /*样式一*/
  287. .live-style-1 {
  288. width: 100%;
  289. border-radius: 16#{rpx};
  290. background: #ffffff;
  291. padding: 20#{rpx};
  292. margin-bottom: 20#{rpx};
  293. display: flex;
  294. flex-direction: column;
  295. .item {
  296. width: 100%;
  297. height: 360#{rpx};
  298. border-radius: 16#{rpx};
  299. position: relative;
  300. overflow: hidden;
  301. .anchor-img {
  302. position: absolute;
  303. left: 0;
  304. top: 0;
  305. width: 100%;
  306. height: 100%;
  307. }
  308. .user-info {
  309. position: absolute;
  310. bottom: 0;
  311. left: 0;
  312. margin-left: 20#{rpx};
  313. margin-bottom: 20#{rpx};
  314. }
  315. .play-icon {
  316. position: absolute;
  317. top: 130#{rpx};
  318. left: 285#{rpx};
  319. }
  320. }
  321. .title {
  322. font-size: 32#{rpx};
  323. color: #353535;
  324. width: 654#{rpx};
  325. margin: 28#{rpx} 0 20#{rpx};
  326. }
  327. .goods-info {
  328. width: 100%;
  329. border-radius: 8#{rpx};
  330. padding: 10#{rpx};
  331. display: flex;
  332. background: #f7f7f7;
  333. .goods-cover {
  334. width: 80#{rpx};
  335. height: 80#{rpx};
  336. border-radius: 8#{rpx};
  337. }
  338. .goods-item {
  339. display: flex;
  340. flex-direction: column;
  341. margin-left: 16#{rpx};
  342. .goods-name {
  343. font-size: 26#{rpx};
  344. color: #666666;
  345. width: 540#{rpx};
  346. }
  347. .goods-price {
  348. font-size: 26#{rpx};
  349. color: #353535;
  350. margin-top: 16#{rpx};
  351. }
  352. }
  353. }
  354. }
  355. .live-style-1:last-child {
  356. margin-bottom: 0;
  357. }
  358. /*样式二*/
  359. .wrap-box {
  360. width: 100%;
  361. display: flex;
  362. justify-content: space-between;
  363. .wrap-item {
  364. display: flex;
  365. flex-direction: column;
  366. .live-style-2 {
  367. background: #ffffff;
  368. border-radius: 16#{rpx};
  369. overflow: hidden;
  370. margin-bottom: 20#{rpx};
  371. width: 100%;
  372. display: flex;
  373. flex-direction: column;
  374. .item {
  375. width: 346#{rpx};
  376. height: 346#{rpx};
  377. position: relative;
  378. border-radius: 16#{rpx};
  379. .anchor-img {
  380. position: absolute;
  381. width: 100%;
  382. height: 100%;
  383. top: 0;
  384. left: 0;
  385. }
  386. .user-info {
  387. position: absolute;
  388. bottom: 20#{rpx};
  389. left: 20#{rpx};
  390. .nickname {
  391. width: 254#{rpx};
  392. }
  393. }
  394. .play-icon {
  395. position: absolute;
  396. top: 123#{rpx};
  397. left: 123#{rpx};
  398. }
  399. }
  400. .title {
  401. font-size: 28#{rpx};
  402. color: #353535;
  403. width: 290#{rpx};
  404. margin: 28#{rpx};
  405. }
  406. .goods-info {
  407. width: 100%;
  408. display: flex;
  409. margin: 0 28#{rpx} 28#{rpx};
  410. .goods-cover {
  411. width: 80#{rpx};
  412. height: 80#{rpx};
  413. border-radius: 8#{rpx};
  414. }
  415. .goods-item {
  416. display: flex;
  417. flex-direction: column;
  418. margin-left: 16#{rpx};
  419. .goods-name {
  420. font-size: 26#{rpx};
  421. color: #666666;
  422. width: 194#{rpx};
  423. }
  424. .goods-price {
  425. font-size: 26#{rpx};
  426. color: #353535;
  427. margin-top: 16#{rpx};
  428. }
  429. }
  430. }
  431. }
  432. .live-style-2:last-child {
  433. margin-bottom: 0;
  434. }
  435. }
  436. }
  437. /*样式三*/
  438. .live-style-3 {
  439. width: 100%;
  440. background: #ffffff;
  441. border-radius: 16#{rpx};
  442. overflow: hidden;
  443. display: flex;
  444. margin-bottom: 20#{rpx};
  445. .item {
  446. border-radius: 16#{rpx};
  447. width: 360#{rpx};
  448. height: 360#{rpx};
  449. position: relative;
  450. .anchor-img {
  451. width: 100%;
  452. height:100%;
  453. position: absolute;
  454. top: 0;
  455. left: 0;
  456. }
  457. .play-icon {
  458. position: absolute;
  459. top: 123#{rpx};
  460. left: 123#{rpx};
  461. }
  462. }
  463. .item-2 {
  464. display: flex;
  465. flex-direction: column;
  466. padding: 20#{rpx};
  467. .title {
  468. width: 310#{rpx};
  469. height: 88#{rpx};
  470. overflow: hidden;
  471. text-overflow: ellipsis;
  472. display: -webkit-box;
  473. -webkit-box-orient: vertical;
  474. -webkit-line-clamp: 2;
  475. line-clamp: 2;
  476. }
  477. .user-info {
  478. margin: 20#{rpx} 0;
  479. }
  480. .nickname {
  481. width: 258#{rpx};
  482. color: #999999;
  483. }
  484. .goods-info {
  485. display: flex;
  486. justify-content: space-between;
  487. .goods-cover {
  488. width: 148#{rpx};
  489. height: 148#{rpx};
  490. border-radius: 16#{rpx};
  491. overflow: hidden;
  492. display: flex;
  493. align-items: flex-end;
  494. justify-content: center;
  495. position: relative;
  496. image {
  497. width: 148#{rpx};
  498. height: 148#{rpx};
  499. position: absolute;
  500. top: 0;
  501. left: 0;
  502. }
  503. .goods-price {
  504. color: #ffffff;
  505. font-size: 24#{rpx};
  506. z-index: 10;
  507. margin-bottom: 10#{rpx};
  508. }
  509. }
  510. .goods-cover-2 {
  511. align-items: center;
  512. .goods-count {
  513. display: flex;
  514. flex-direction: column;
  515. color: #ffffff;
  516. font-size: 24#{rpx};
  517. z-index: 10;
  518. .number {
  519. text-align: center;
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }
  526. .live-style-3:last-child {
  527. margin-bottom: 0;
  528. }
  529. }
  530. </style>