pickVideo.vue 14 KB

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