pickVideo.vue 15 KB

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