app-live.vue 20 KB

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