liveDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <template>
  2. <view class="container">
  3. <trtc-room ref="trtc-component" :config="rtcConfig"> </trtc-room>
  4. <view class="top_box" :style="{ top: btn_top, left: btn_left}">
  5. <image class="top_box_img" :src="head_img" mode="aspectFill"></image>
  6. <view class="top_box_text">
  7. <text class="text_box_top">{{title}}</text><text class="text_box_bottom" style="display:none">{{user_name}}</text>
  8. <view class="tx_btn" @click="subTap()"><text class="iconfont tixingn">{{tixing_str}}</text></view>
  9. </view>
  10. </view>
  11. <view class="popup-open" @click="showGoods()">
  12. <view class="iconfont iconzhibo-shangpin"></view>
  13. </view>
  14. <uni-popup ref="popup" type="bottom">
  15. <view class="popup-box">
  16. <view class="popup-close" @click="closeGoods()">收起</view>
  17. <scroll-view scroll-y="true" class="good-box">
  18. <view class="goods-row" v-for="(item, index) in goodsList" :key="index" @click="goToGoodDetails(item)">
  19. <image class="goods-img" :src="item.imgPath" mode="aspectFill"></image>
  20. <view class="goods-info">
  21. <view class="goods-name">{{item.productName}}</view>
  22. <view class="goods-sales">{{item.sellCount}}人付款</view>
  23. <view class="goods-number">
  24. <text class="goods-icon">¥</text>
  25. <text class="goods-spec">{{item.bizPrice}}</text>
  26. <text class="price">原价:{{item.originalPrice}}</text>
  27. </view>
  28. </view>
  29. <view class="more-button">
  30. <view class="iconfont icongengduo"></view>
  31. </view>
  32. </view>
  33. </scroll-view>
  34. </view>
  35. </uni-popup>
  36. <u-top-tips ref="uTips"></u-top-tips>
  37. </view>
  38. </template>
  39. <script>
  40. const NET = require('@/utils/request')
  41. const API = require('@/config/api')
  42. import {
  43. genTestUserSig,
  44. setData
  45. } from "@/pagesGood/debug/GenerateTestUserSig";
  46. import trtcRoom from "@/pagesGood/trtc-room/trtc-room";
  47. export default {
  48. components: {
  49. trtcRoom
  50. },
  51. data() {
  52. return {
  53. videoType: '',
  54. roomID: '',
  55. userID: '',
  56. goodsList: [],
  57. rtcConfig: {
  58. sdkAppID: '',
  59. // 必要参数 开通实时音视频服务创建应用后分配的 sdkAppID
  60. userID: '',
  61. // 必要参数 用户 ID 可以由您的帐号系统指定
  62. userSig: '',
  63. // 必要参数 身份签名,相当于登录密码的作用
  64. template: '' // 必要参数 组件模版,支持的值 1v1 grid custom ,注意:不支持动态修改, iOS 不支持 pusher 动态渲染
  65. },
  66. showTipToast: false,
  67. options: {},
  68. btn_left:0,
  69. btn_top:0,
  70. title:"888",
  71. user_name:'1',
  72. head_img:"../static/images/loginLogo.png",
  73. liveId: '',
  74. tixing_str:'直播提醒'
  75. }
  76. },
  77. onLoad(options) {
  78. this.videoType = options.videoType
  79. this.roomID = options.roomId
  80. this.userID = "1323565280579813376"
  81. this.liveId = options.liveId
  82. NET.request(API.isSubscribed + options.liveId, {}, 'GET').then(res => {
  83. if(res.data==false){
  84. this.tixing_str="直播提醒"
  85. }else{
  86. this.tixing_str="取消提醒"
  87. }
  88. //this.goodsList = res.data
  89. }).catch(res => {
  90. })
  91. },
  92. onReady() {
  93. // NET.request(API.getLiveGoodsDetail + options.liveId, {}, 'GET').then(res => {
  94. // this.goodsList = res.data
  95. // }).catch(res => {
  96. // this.$refs.uTips.show({
  97. // title: '获取商品列表失败',
  98. // type: 'warning',
  99. // })
  100. // })
  101. let menuButtonObject = wx.getMenuButtonBoundingClientRect();
  102. wx.getSystemInfo({
  103. success: res => {
  104. this.setData({
  105. btn_left: res.windowWidth - menuButtonObject.right+'rpx',
  106. btn_top:menuButtonObject.top+menuButtonObject.height+14+'rpx',
  107. head_img:uni.getStorageSync("liveImgUrl"),
  108. title:uni.getStorageSync("liveName"),
  109. })
  110. },
  111. })
  112. wx.setKeepScreenOn({
  113. keepScreenOn: true
  114. }); // 获取 rtcroom 实例
  115. this.trtcComponent = this.$refs['trtc-component']; // 监听TRTC Room 关键事件
  116. this.bindTRTCRoomEvent(); // 将String 类型的 true false 转换成 boolean
  117. this.options.localAudio = false; //开启麦克风
  118. this.options.localVideo = false; //开启视频
  119. this.enterRoom({
  120. roomID: Number(this.roomID),
  121. userID: uni.getStorageSync("userData").userId,
  122. template: "grid",
  123. });
  124. },
  125. methods: {
  126. subTap: function() {
  127. let that = this;
  128. if(that.tixing_str=="取消提醒"){
  129. var post_data={liveId:that.liveId,mid:uni.getStorageSync("userData").userId}
  130. post_data.isDelete=0;
  131. NET.request(API.subscribeLive, post_data, 'POST').then(res => {
  132. if(that.tixing_str=="取消提醒"){
  133. that.tixing_str="直播提醒"
  134. }else{
  135. that.tixing_str="取消提醒"
  136. }
  137. //this.goodsList = res.data
  138. }).catch(res => {
  139. })
  140. }else{
  141. wx.requestSubscribeMessage({
  142. tmplIds: ['y0X1cZfbEMg7HdTGN_bW8v7TKeI3M0CHSVTY1zStIXM'],
  143. success(res) {
  144. if(res.y0X1cZfbEMg7HdTGN_bW8v7TKeI3M0CHSVTY1zStIXM=="accept"){
  145. var post_data={liveId:that.liveId,mid:uni.getStorageSync("userData").userId}
  146. if(that.tixing_str=="直播提醒"){
  147. post_data.isDelete=1;
  148. }else{
  149. post_data.isDelete=0;
  150. }
  151. NET.request(API.subscribeLive, post_data, 'POST').then(res => {
  152. if(that.tixing_str=="取消提醒"){
  153. that.tixing_str="直播提醒"
  154. }else{
  155. that.tixing_str="取消提醒"
  156. }
  157. //this.goodsList = res.data
  158. }).catch(res => {
  159. })
  160. }else{
  161. console.log('444', res);
  162. }
  163. //console.log('1111', res);
  164. },
  165. fail(res) {
  166. console.log('2222', res);
  167. }
  168. })
  169. }
  170. },
  171. // 打开弹窗
  172. showGoods() {
  173. this.$refs.popup.open()
  174. NET.request(API.getLiveGoodsDetail + this.liveId, {}, 'GET').then(res => {
  175. this.goodsList = res.data
  176. }).catch(res => {
  177. this.$refs.uTips.show({
  178. title: '获取商品列表失败',
  179. type: 'warning',
  180. })
  181. })
  182. },
  183. // 关闭弹窗
  184. closeGoods() {
  185. this.$refs.popup.close()
  186. },
  187. goToGoodDetails(item) {
  188. uni.navigateTo({
  189. url: '/pagesGood/goodDetails?goodId=' + item.productId
  190. });
  191. },
  192. setData,
  193. enterRoom: function(params) {
  194. params.template = params.template || '1v1';
  195. params.roomID = params.roomID || 2333;
  196. params.userID = params.userID || new Date().getTime().toString(16);
  197. console.log('* room enterRoom', params);
  198. const Signature = genTestUserSig(params.userID);
  199. params.sdkAppID = Signature.sdkAppID;
  200. params.userSig = Signature.userSig;
  201. this.template = params.template;
  202. this.rtcConfig = {
  203. sdkAppID: params.sdkAppID,
  204. // 您的实时音视频服务创建应用后分配的 sdkAppID
  205. userID: params.userID,
  206. userSig: params.userSig,
  207. template: params.template,
  208. // 1v1 grid custom
  209. debugMode: false,
  210. // 非必要参数,打开组件的调试模式,开发调试时建议设置为 true
  211. // cloudenv: params.cloudenv, // 非必要参数
  212. frontCamera: "front",
  213. enableEarMonitor: false,
  214. enableAutoFocus: true,
  215. localMirror: 'auto',
  216. enableAgc: true,
  217. enableAns: true,
  218. enableMic:false,
  219. encsmall: false ? 1 : 0,
  220. videoWidth: 1280,
  221. videoHeight: 720,
  222. scene: "live",
  223. maxBitrate: 2000,
  224. minBitrate: 1500,
  225. beautyLevel: 9 // 默认开启美颜
  226. };
  227. this.setData({
  228. rtcConfig: this.rtcConfig
  229. }, () => {
  230. // roomID 取值范围 1 ~ 4294967295
  231. this.trtcComponent.enterRoom({
  232. roomID: params.roomID
  233. }).then(() => {
  234. if (this.template === 'custom') {
  235. // 设置推流端视窗的坐标和尺寸
  236. this.trtcComponent.setViewRect({
  237. userID: params.userID,
  238. xAxis: '480rpx',
  239. yAxis: '160rpx',
  240. width: '240rpx',
  241. height: '320rpx'
  242. });
  243. }
  244. }).catch(res => {
  245. console.error('* room joinRoom 进房失败:', res);
  246. });
  247. });
  248. },
  249. bindTRTCRoomEvent: function() {
  250. const TRTC_EVENT = this.trtcComponent.EVENT;
  251. this.timestamp = []; // 初始化事件订阅
  252. this.trtcComponent.on(TRTC_EVENT.LOCAL_JOIN, event => {
  253. let user_list=this.trtcComponent.getRemoteUserList();
  254. this.setData({
  255. user_name:user_list.length
  256. })
  257. console.log('* room LOCAL_JOIN', event); // 进房成功,触发该事件后可以对本地视频和音频进行设置
  258. if (this.options.localVideo === true || this.options.template === '1v1') {
  259. //this.trtcComponent.publishLocalVideo();
  260. }
  261. if (this.options.localAudio === true || this.options.template === '1v1') {
  262. //this.trtcComponent.publishLocalAudio();
  263. }
  264. });
  265. this.trtcComponent.on(TRTC_EVENT.LOCAL_LEAVE, event => {
  266. console.log('* room LOCAL_LEAVE', event);
  267. });
  268. this.trtcComponent.on(TRTC_EVENT.ERROR, event => {
  269. console.log('* room ERROR', event);
  270. }); // 远端用户进房
  271. this.trtcComponent.on(TRTC_EVENT.REMOTE_USER_JOIN, event => {
  272. let user_list=this.trtcComponent.getRemoteUserList();
  273. this.setData({
  274. user_name:user_list.length
  275. })
  276. console.log('* room REMOTE_USER_JOIN --- room.vue', event, this.trtcComponent.getRemoteUserList(), this.template);
  277. this.timestamp.push(new Date()); // 1v1视频通话时限制人数为两人的简易逻辑,建议通过后端实现房间人数管理
  278. // 2人以上同时进行通话请选择网格布局
  279. if (this.template === '1v1' && this.timestamp.length > 1) {
  280. const interval = this.timestamp[1] - this.timestamp[0];
  281. if (interval < 1000) {
  282. // 房间里已经有两个人
  283. this.setData({
  284. showTipToast: true
  285. }, () => {
  286. setTimeout(() => {
  287. this.setData({
  288. showTipToast: false
  289. });
  290. wx.navigateBack({
  291. delta: 1
  292. });
  293. }, 4000);
  294. });
  295. }
  296. }
  297. }); // 远端用户退出
  298. this.trtcComponent.on(TRTC_EVENT.REMOTE_USER_LEAVE, event => {
  299. //if (event.data.userID == this.userID) {
  300. console.log("直播用户退出");
  301. this.$refs.uTips.show({
  302. title: '直播用户退出',
  303. type: 'success',
  304. })
  305. setTimeout(() => {
  306. uni.navigateBack()
  307. }, 3000)
  308. //}
  309. let user_list=this.trtcComponent.getRemoteUserList();
  310. this.setData({
  311. user_name:user_list.length
  312. })
  313. }); // 远端用户推送视频
  314. this.trtcComponent.on(TRTC_EVENT.REMOTE_VIDEO_ADD, event => {
  315. console.log('* room REMOTE_VIDEO_ADD', event, this.trtcComponent.getRemoteUserList()); // 订阅视频
  316. const userList = this.trtcComponent.getRemoteUserList();
  317. const data = event.data;
  318. if (this.template === '1v1' && (!this.remoteUser || this.remoteUser === data.userID)) {
  319. // 1v1 只订阅第一个远端流
  320. this.remoteUser = data.userID;
  321. this.trtcComponent.subscribeRemoteVideo({
  322. userID: data.userID,
  323. streamType: data.streamType
  324. });
  325. } else if (this.template === 'grid') {
  326. this.trtcComponent.subscribeRemoteVideo({
  327. userID: data.userID,
  328. streamType: data.streamType
  329. });
  330. }
  331. if (this.template === 'custom' && data.userID && data.streamType) {
  332. let index = userList.findIndex(item => {
  333. return item.userID === data.userID;
  334. });
  335. index++;
  336. const y = 320 * index + 160; // 设置远端视图坐标和尺寸
  337. this.trtcComponent.setViewRect({
  338. userID: data.userID,
  339. streamType: data.streamType,
  340. xAxis: '480rpx',
  341. yAxis: y + 'rpx',
  342. width: '240rpx',
  343. height: '320rpx'
  344. });
  345. }
  346. }); // 远端用户取消推送视频
  347. this.trtcComponent.on(TRTC_EVENT.REMOTE_VIDEO_REMOVE, event => {
  348. console.log('* room REMOTE_VIDEO_REMOVE', event, this.trtcComponent.getRemoteUserList());
  349. }); // 远端用户推送音频
  350. this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_ADD, event => {
  351. console.log('* room REMOTE_AUDIO_ADD', event, this.trtcComponent.getRemoteUserList()); // 订阅音频
  352. const data = event.data;
  353. if (this.template === '1v1' && (!this.remoteUser || this.remoteUser === data.userID)) {
  354. this.remoteUser = data.userID;
  355. this.trtcComponent.subscribeRemoteAudio({
  356. userID: data.userID
  357. });
  358. } else if (this.template === 'grid' || this.template === 'custom') {
  359. this.trtcComponent.subscribeRemoteAudio({
  360. userID: data.userID
  361. });
  362. } // 如果不订阅就不会自动播放音频
  363. // this.trtcComponent.subscribeRemoteAudio({ userID: data.userID })
  364. }); // 远端用户取消推送音频
  365. this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_REMOVE, event => {
  366. console.log('* room REMOTE_AUDIO_REMOVE', event, this.trtcComponent.getRemoteUserList());
  367. });
  368. }
  369. },
  370. }
  371. </script>
  372. <style lang="less" scoped>
  373. page {
  374. width: 100%;
  375. height: 100%;
  376. }
  377. .container {
  378. width: 100%;
  379. height: 100;
  380. float: left;
  381. position: relative;
  382. .popup-open {
  383. width: 50px;
  384. height: 50px;
  385. position: fixed;
  386. bottom: 15px;
  387. right: 15px;
  388. background: #52A63A;
  389. border-radius: 50%;
  390. text-align: center;
  391. line-height: 50px;
  392. .iconzhibo-shangpin {
  393. color: #FFFFFF;
  394. font-size: 34px;
  395. }
  396. }
  397. .popup-box {
  398. width: 100%;
  399. height: 265px;
  400. float: left;
  401. background-color: #FFFFFF;
  402. border-radius: 15px 15px 0px 0px;
  403. box-sizing: border-box;
  404. padding: 16px 0 0 0;
  405. position: relative;
  406. .popup-close {
  407. width: 100%;
  408. height: 26px;
  409. float: left;
  410. box-sizing: border-box;
  411. padding: 10px 15px 0 15px;
  412. font-size: 15px;
  413. font-family: PingFang SC;
  414. color: #52A63A;
  415. line-height: 16px;
  416. }
  417. .good-box {
  418. width: 100%;
  419. height: calc(100% - 26px);
  420. box-sizing: border-box;
  421. padding: 0 0 10px 0;
  422. overflow: auto;
  423. position: relative;
  424. .goods-row:first-child {
  425. margin-top: 12px;
  426. }
  427. .goods-row {
  428. width: calc(100% - 30px);
  429. height: 104px;
  430. float: left;
  431. background: #FFFFFF;
  432. box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  433. border-radius: 5px;
  434. overflow: hidden;
  435. margin: 0 15px 10px 15px;
  436. position: relative;
  437. .goods-img {
  438. width: 104px;
  439. height: 104px;
  440. object-fit: cover;
  441. float: left;
  442. margin-right: 15px;
  443. }
  444. .goods-info {
  445. width: calc(100% - 120px);
  446. float: left;
  447. padding-top: 10px;
  448. .goods-name {
  449. width: 100%;
  450. height: 30px;
  451. float: left;
  452. font-size: 15px;
  453. font-family: PingFang SC;
  454. color: #333333;
  455. line-height: 15px;
  456. overflow: hidden;
  457. text-overflow: ellipsis;
  458. display: -webkit-box;
  459. -webkit-line-clamp: 2;
  460. -webkit-box-orient: vertical;
  461. word-wrap: break-word;
  462. }
  463. .goods-sales {
  464. width: 100%;
  465. float: left;
  466. font-size: 12px;
  467. font-family: PingFang SC;
  468. color: #666666;
  469. line-height: 15px;
  470. margin: 4px 0 8px 0;
  471. }
  472. .goods-number {
  473. width: 100%;
  474. height: 24px;
  475. float: left;
  476. white-space: nowrap;
  477. font-family: PingFang SC;
  478. color: #52A63A;
  479. line-height: 24px;
  480. .goods-icon {
  481. font-size: 14px;
  482. }
  483. .goods-spec {
  484. font-size: 24px;
  485. }
  486. .price {
  487. font-size: 12px;
  488. text-decoration: line-through;
  489. color: #A67954;
  490. margin-left: 6px;
  491. }
  492. }
  493. }
  494. .more-button {
  495. width: 24px;
  496. height: 24px;
  497. position: absolute;
  498. right: 16px;
  499. bottom: 16px;
  500. .iconfont {
  501. font-size: 36px;
  502. color: #999999;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. .top_box{
  509. width: auto;
  510. height: 86rpx;
  511. position: absolute;
  512. z-index: 100;
  513. background: rgba(0, 0, 0, 0.4);
  514. -webkit-border-radius: 100px;
  515. border-radius: 100px;
  516. top: 182rpx;
  517. left: 30rpx;
  518. padding-right: 10rpx;
  519. }
  520. .top_box_img{
  521. width: 86rpx;
  522. height: 86rpx;
  523. border-radius: 100rpx;
  524. float: left;
  525. }
  526. .top_box_text{
  527. float: left;
  528. color: #fff;
  529. margin-left: 30rpx;
  530. padding-top: 2rpx;
  531. }
  532. .text_box_top{
  533. font-size: 34rpx;
  534. /* width: 100%; */
  535. display: block;
  536. height: 30rpx;
  537. float: left;
  538. margin-top: 19rpx;
  539. display: inline-block;
  540. }
  541. .text_box_bottom{
  542. font-size: 22rpx;
  543. float: left;
  544. margin-top: 10rpx;
  545. }
  546. .tx_btn{
  547. background: #4fa237;
  548. display: inline-block;
  549. height: 70rpx;
  550. margin-top: 5rpx;
  551. border-radius: 60rpx;
  552. line-height: 70rpx;
  553. padding: 0 30rpx;
  554. margin-left: 30rpx;
  555. }
  556. .tx_btn image{
  557. width: 60rpx;
  558. height: 60rpx;
  559. margin-top: 5rpx;
  560. margin-right: 20rpx;
  561. }
  562. .tixingn{
  563. font-size: 34rpx;
  564. display: flex;
  565. }
  566. .tixingn:before {
  567. font-size: 60rpx;
  568. }
  569. }
  570. </style>