pickVideo.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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.liveProducResVO[0].imgPath,
  92. title:res.data.liveProducResVO[0].productName
  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. this.timestamp = []; // 初始化事件订阅
  169. this.trtcComponent.on(TRTC_EVENT.LOCAL_JOIN, event => {
  170. if(this.trtcComponent.getRemoteUserList().length>0){
  171. var userId=this.trtcComponent.getRemoteUserList()[0].userID;
  172. /* NET.request(API.getMerchantsMainInfo + userId, {}, 'GET').then(res => {
  173. this.setData({
  174. head_img:res.data.merchantImg,
  175. title:res.data.merchantNickname
  176. })
  177. }).catch(error => {
  178. this.$refs.uTips.show({
  179. title: '获取个人信息失败',
  180. type: 'warning',
  181. })
  182. }) */
  183. }
  184. console.log('* room LOCAL_JOIN', event); // 进房成功,触发该事件后可以对本地视频和音频进行设置
  185. if (this.options.localVideo === true || this.options.template === '1v1') {
  186. //this.trtcComponent.publishLocalVideo();
  187. }
  188. if (this.options.localAudio === true || this.options.template === '1v1') {
  189. this.trtcComponent.publishLocalAudio();
  190. }
  191. });
  192. this.trtcComponent.on(TRTC_EVENT.LOCAL_LEAVE, event => {
  193. console.log('* room LOCAL_LEAVE', event);
  194. });
  195. this.trtcComponent.on(TRTC_EVENT.ERROR, event => {
  196. console.log('* room ERROR', event);
  197. }); // 远端用户进房
  198. this.trtcComponent.on(TRTC_EVENT.REMOTE_USER_JOIN, event => {
  199. var userId=this.trtcComponent.getRemoteUserList()[0].userID;
  200. /* NET.request(API.getMerchantsMainInfo + userId, {}, 'GET').then(res => {
  201. this.setData({
  202. head_img:res.data.merchantImg,
  203. title:res.data.merchantNickname
  204. })
  205. }).catch(error => {
  206. this.$refs.uTips.show({
  207. title: '获取个人信息失败',
  208. type: 'warning',
  209. })
  210. }) */
  211. console.log('* room REMOTE_USER_JOIN --- room.vue', event, this.trtcComponent.getRemoteUserList(), this.template);
  212. this.timestamp.push(new Date()); // 1v1视频通话时限制人数为两人的简易逻辑,建议通过后端实现房间人数管理
  213. // 2人以上同时进行通话请选择网格布局
  214. if (this.template === '1v1' && this.timestamp.length > 1) {
  215. const interval = this.timestamp[1] - this.timestamp[0];
  216. if (interval < 1000) {
  217. // 房间里已经有两个人
  218. this.setData({
  219. showTipToast: true
  220. }, () => {
  221. setTimeout(() => {
  222. this.setData({
  223. showTipToast: false
  224. });
  225. wx.navigateBack({
  226. delta: 1
  227. });
  228. }, 4000);
  229. });
  230. }
  231. }
  232. }); // 远端用户退出
  233. this.trtcComponent.on(TRTC_EVENT.REMOTE_USER_LEAVE, event => {
  234. // this.setData({
  235. // head_img:"../static/images/loginLogo.png",
  236. // title:''
  237. // })
  238. console.log('* room REMOTE_USER_LEAVE', event, this.trtcComponent.getRemoteUserList());
  239. if (this.template === '1v1') {
  240. this.timestamp = [];
  241. }
  242. if (this.template === '1v1' && this.remoteUser === event.data.userID) {
  243. this.remoteUser = null;
  244. }
  245. }); // 远端用户推送视频
  246. this.trtcComponent.on(TRTC_EVENT.REMOTE_VIDEO_ADD, event => {
  247. console.log('* room REMOTE_VIDEO_ADD', event, this.trtcComponent.getRemoteUserList()); // 订阅视频
  248. const userList = this.trtcComponent.getRemoteUserList();
  249. const data = event.data;
  250. if (this.template === '1v1' && (!this.remoteUser || this.remoteUser === data.userID)) {
  251. // 1v1 只订阅第一个远端流
  252. this.remoteUser = data.userID;
  253. this.trtcComponent.subscribeRemoteVideo({
  254. userID: data.userID,
  255. streamType: data.streamType
  256. });
  257. } else if (this.template === 'grid') {
  258. this.trtcComponent.subscribeRemoteVideo({
  259. userID: data.userID,
  260. streamType: data.streamType
  261. });
  262. }
  263. if (this.template === 'custom' && data.userID && data.streamType) {
  264. let index = userList.findIndex(item => {
  265. return item.userID === data.userID;
  266. });
  267. index++;
  268. const y = 320 * index + 160; // 设置远端视图坐标和尺寸
  269. this.trtcComponent.setViewRect({
  270. userID: data.userID,
  271. streamType: data.streamType,
  272. xAxis: '480rpx',
  273. yAxis: y + 'rpx',
  274. width: '240rpx',
  275. height: '320rpx'
  276. });
  277. }
  278. }); // 远端用户取消推送视频
  279. this.trtcComponent.on(TRTC_EVENT.REMOTE_VIDEO_REMOVE, event => {
  280. console.log('* room REMOTE_VIDEO_REMOVE', event, this.trtcComponent.getRemoteUserList());
  281. }); // 远端用户推送音频
  282. this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_ADD, event => {
  283. console.log('* room REMOTE_AUDIO_ADD', event, this.trtcComponent.getRemoteUserList()); // 订阅音频
  284. const data = event.data;
  285. if (this.template === '1v1' && (!this.remoteUser || this.remoteUser === data.userID)) {
  286. this.remoteUser = data.userID;
  287. this.trtcComponent.subscribeRemoteAudio({
  288. userID: data.userID
  289. });
  290. } else if (this.template === 'grid' || this.template === 'custom') {
  291. this.trtcComponent.subscribeRemoteAudio({
  292. userID: data.userID
  293. });
  294. } // 如果不订阅就不会自动播放音频
  295. // this.trtcComponent.subscribeRemoteAudio({ userID: data.userID })
  296. }); // 远端用户取消推送音频
  297. this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_REMOVE, event => {
  298. console.log('* room REMOTE_AUDIO_REMOVE', event, this.trtcComponent.getRemoteUserList());
  299. });
  300. }
  301. }
  302. }
  303. </script>
  304. <style lang="less" scoped>
  305. page {
  306. width: 100%;
  307. height: 100%;
  308. }
  309. .container {
  310. width: 100%;
  311. height: 100%;
  312. float: left;
  313. position: relative;
  314. .tip-toast {
  315. position: absolute;
  316. top: 40vh;
  317. width: 70vw;
  318. left: 15vw;
  319. border-radius: 12rpx;
  320. height: 20vh;
  321. background: rgba(0, 0, 0, 0.8);
  322. color: white;
  323. display: flex;
  324. flex-direction: column;
  325. align-items: center;
  326. justify-content: center;
  327. }
  328. .tip-toast view {
  329. padding: 20rpx 0;
  330. font-size: 32rpx;
  331. }
  332. .top_box{
  333. //width: 304rpx;
  334. height: 86rpx;
  335. position: absolute;
  336. z-index: 100;
  337. background:rgba(0, 0, 0, 0.4);
  338. border-radius: 100px;
  339. top: 182rpx;
  340. left: 30rpx;
  341. }
  342. .top_box_img{
  343. width: 86rpx;
  344. height: 86rpx;
  345. border-radius: 100rpx;
  346. float: left;
  347. }
  348. .top_box_text{
  349. float: left;
  350. color: #fff;
  351. margin-left: 30rpx;
  352. //width: 180rpx;
  353. padding-right: 30rpx;
  354. padding-top: 2rpx;
  355. }
  356. .text_box_top{
  357. font-size: 34rpx;
  358. width: 100%;
  359. display: block;
  360. height: 30rpx;
  361. float: left;
  362. margin-top: 19rpx;
  363. }
  364. .text_box_bottom{
  365. font-size: 22rpx;
  366. float: left;
  367. margin-top: 10rpx;
  368. }
  369. .popup-open {
  370. width: 50px;
  371. height: 50px;
  372. position: fixed;
  373. bottom: 15px;
  374. right: 15px;
  375. background: #52A63A;
  376. border-radius: 50%;
  377. text-align: center;
  378. line-height: 50px;
  379. z-index: 20000;
  380. .iconzhibo-shangpin {
  381. color: #FFFFFF;
  382. font-size: 34px;
  383. }
  384. }
  385. .popup-box {
  386. width: 100%;
  387. height: 265px;
  388. float: left;
  389. background-color: #FFFFFF;
  390. border-radius: 15px 15px 0px 0px;
  391. box-sizing: border-box;
  392. padding: 16px 0 0 0;
  393. position: relative;
  394. .popup-close {
  395. width: 100%;
  396. height: 26px;
  397. float: left;
  398. box-sizing: border-box;
  399. padding: 10px 15px 0 15px;
  400. font-size: 15px;
  401. font-family: PingFang SC;
  402. color: #52A63A;
  403. line-height: 16px;
  404. }
  405. .good-box {
  406. width: 100%;
  407. height: calc(100% - 26px);
  408. box-sizing: border-box;
  409. padding: 0 0 10px 0;
  410. overflow: auto;
  411. position: relative;
  412. .goods-row:first-child {
  413. margin-top: 12px;
  414. }
  415. .goods-row {
  416. width: calc(100% - 30px);
  417. height: 104px;
  418. float: left;
  419. background: #FFFFFF;
  420. box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  421. border-radius: 5px;
  422. margin: 0 15px 10px 15px;
  423. position: relative;
  424. .goods-img {
  425. width: 104px;
  426. height: 104px;
  427. object-fit: cover;
  428. float: left;
  429. margin-right: 15px;
  430. }
  431. .goods-info {
  432. width: calc(100% - 120px);
  433. float: left;
  434. padding-top: 10px;
  435. .goods-name {
  436. width: 100%;
  437. height: 30px;
  438. float: left;
  439. font-size: 15px;
  440. font-family: PingFang SC;
  441. color: #333333;
  442. line-height: 15px;
  443. overflow: hidden;
  444. text-overflow: ellipsis;
  445. display: -webkit-box;
  446. -webkit-line-clamp: 2;
  447. -webkit-box-orient: vertical;
  448. word-wrap: break-word;
  449. }
  450. .goods-sales {
  451. width: 100%;
  452. float: left;
  453. font-size: 12px;
  454. font-family: PingFang SC;
  455. color: #666666;
  456. line-height: 15px;
  457. margin: 4px 0 8px 0;
  458. }
  459. .goods-number {
  460. width: 100%;
  461. height: 24px;
  462. float: left;
  463. white-space: nowrap;
  464. font-family: PingFang SC;
  465. color: #52A63A;
  466. line-height: 24px;
  467. .goods-icon {
  468. font-size: 14px;
  469. }
  470. .goods-spec {
  471. font-size: 24px;
  472. }
  473. .price {
  474. font-size: 12px;
  475. text-decoration: line-through;
  476. color: #A67954;
  477. margin-left: 6px;
  478. }
  479. }
  480. }
  481. .more-button {
  482. width: 24px;
  483. height: 24px;
  484. position: absolute;
  485. right: 16px;
  486. bottom: 16px;
  487. .iconfont {
  488. font-size: 36px;
  489. color: #999999;
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. </style>