liveDetail.nvue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="container" :style="'height: '+windowHeight+'px;'">
  3. <jhlive
  4. v-if="videoType == 1"
  5. ref="jhlive" class="jhlive"
  6. :sdkAppID="sdkAppID" :secretKey="secretKey" :userId="userId" :roomId="roomId"
  7. :isAuthor="isAuthor" :linkMic="linkMic"
  8. :avatar="avatar" :subtitle="subtitle" :title="title"
  9. :showFav="showFav" :isFav="isLiveFav" @onLiveFav="onLiveFav"
  10. :btns="btns" @onBtnClick="onBtnClick"
  11. :showIm="true" :imStatus="imStatus" :imMsgs="imMsgs" @onImSend="onImSend"
  12. @onRemoteUser="num=$event.length" />
  13. <video v-if="videoType == 2" id="myVideo" class="jhlive" :src="videoUrl" @error="videoErrorCallback" controls>
  14. <cover-view class="popup-open" @click="$refs.popup.open()">
  15. <!-- #ifdef APP-PLUS -->
  16. <text class="nvue-iconfont iconzhibo-shangpin" :style="{fontFamily:'nvueIconfont'}">&#xe63f;</text>
  17. <!-- #endif -->
  18. <!-- #ifdef MP-WEIXIN -->
  19. <text class="iconfont iconzhibo-shangpin"></text>
  20. <!-- #endif -->
  21. </cover-view>
  22. </video>
  23. <view v-if="(videoType == 1) && (num<=0)" class="tips-box" :style="'top: '+windowHeight/3+'px;'">
  24. <text class="tips-box-text">提示</text>
  25. <text class="tips-box-text" style="margin-top: 10px;">讲解员未进入</text>
  26. </view>
  27. <uni-popup ref="popup" animation type="bottom">
  28. <view class="popup-box">
  29. <view class="popup-close">
  30. <text class="popup-close-text" @click="$refs.popup.close()">收起</text>
  31. </view>
  32. <scroll-view scroll-y="true" class="good-box">
  33. <view class="goods-row" v-for="(item, index) in goodsList" :key="index" @click="goToGoodDetails(item)">
  34. <view class="goods-img-box">
  35. <image class="goods-img" :src="item.imgPath" mode="aspectFill"></image>
  36. </view>
  37. <view class="goods-info">
  38. <view>
  39. <text class="goods-name">{{item.productName}}</text>
  40. </view>
  41. <text class="goods-sales">{{item.sellCount}}人付款</text>
  42. <text class="price">原价:{{item.originalPrice}}</text>
  43. <view class="goods-number-bottom">
  44. <view class="goods-number">
  45. <!-- <text class="goods-number-left">惊爆价:</text> -->
  46. <text class="goods-icon">¥</text>
  47. <text class="goods-spec">{{item.bizPrice}}</text>
  48. </view>
  49. <view class="more-button">
  50. <!-- #ifdef APP-PLUS -->
  51. <text class="nvue-iconfont more-button-iconfont" :style="{fontFamily:'nvueIconfont'}">&#xe623;</text>
  52. <!-- #endif -->
  53. <!-- #ifdef MP-WEIXIN -->
  54. <text class="iconfont more-button-iconfont icongengduo"></text>
  55. <!-- #endif -->
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </scroll-view>
  61. </view>
  62. </uni-popup>
  63. <!-- <u-modal v-if="(videoType == 1) && (num<=0)" :value="true" content="讲解员未进入" :show-confirm-button="false" :async-close="true"></u-modal> -->
  64. </view>
  65. </template>
  66. <script>
  67. import jhlive from "@/jhlive/jhlive";
  68. import Jhim from "@/jhim/jhim.js";
  69. const NET = require('@/utils/request');
  70. const API = require('@/config/api');
  71. export default {
  72. components: {
  73. jhlive
  74. },
  75. data() {
  76. return {
  77. windowWidth: 0,
  78. windowHeight: 0,
  79. liveId: '',
  80. userData: {},
  81. videoUrl: '',
  82. goodsList: [],
  83. goodsIds: [],
  84. btns: [{picture:"../static/images/live-good.png",title:''}],
  85. isAuthor: false,
  86. linkMic: false,
  87. sdkAppID: API.sdkAppID,
  88. secretKey: API.secretKey,
  89. userId: '',
  90. userName: '',
  91. roomId: '',
  92. avatar: "../static/images/loginLogo.png",
  93. title: "加载中",
  94. subtitle: "0人在观看",
  95. isLiveFav: false,
  96. imStatus: '',
  97. imMsgs: [],
  98. videoType: null,
  99. videoId: '',
  100. num: 0, // 开麦人数
  101. // #ifdef MP-WEIXIN
  102. showFav: true, // 是否展示收藏,app中不展示,小程序中 展示
  103. // #endif
  104. // #ifdef APP-PLUS
  105. showFav: false,
  106. // #endif
  107. }
  108. },
  109. onLoad(options) {
  110. this.videoType = options.videoType
  111. if (this.videoType == 1) {
  112. this.roomId = options.roomId;
  113. this.liveId = options.liveId;
  114. this.userData = uni.getStorageSync("userData");
  115. this.userId = this.userData.userId;
  116. this.userName = this.userData.userName;
  117. uni.setNavigationBarTitle({
  118. title: '产品讲解'
  119. })
  120. } else {
  121. this.videoType = options.videoType
  122. this.videoId = options.videoId
  123. uni.setNavigationBarTitle({
  124. title: '正在播放短视频'
  125. })
  126. this.videoUrl = uni.getStorageSync("videoUrl").replace("http://","https://")
  127. }
  128. let info = uni.getSystemInfoSync();
  129. this.windowWidth = info.windowWidth;
  130. this.windowHeight = info.windowHeight;
  131. console.log('宽高',this.windowWidth,this.windowHeight)
  132. },
  133. onReady() {
  134. // this.isAuthor = false;
  135. // this.linkMic = true;
  136. // this.userId = "22";
  137. // this.userName = "ss";
  138. // this.title = 'test';
  139. // this.roomId = '11';
  140. // this.$nextTick(() => this.enterRoom());
  141. // return;
  142. this.init();
  143. },
  144. // #ifdef APP-PLUS
  145. beforeCreate() {
  146. let domModule = weex.requireModule('dom');
  147. domModule.addRule('fontFace',{
  148. 'fontFamily': "nvueIconfont",
  149. 'src': "url('https://at.alicdn.com/t/font_2119167_43jbldmjpr3.ttf')"
  150. })
  151. },
  152. // #endif
  153. onUnload() {
  154. if (this.videoType == 1) {
  155. this.exitRoom();
  156. }
  157. },
  158. methods: {
  159. init() {
  160. if (this.videoType == 1) {
  161. NET.request(API.getLiveGoodsDetail + this.liveId, {}, 'GET').then(res => {
  162. this.goodsList = res.data
  163. }).catch(res => {
  164. uni.showToast({
  165. title: '获取商品列表失败',
  166. type: 'warning',
  167. })
  168. })
  169. this.avatar = uni.getStorageSync("liveImgUrl");
  170. this.title = uni.getStorageSync("liveName");
  171. this.$nextTick(() => this.enterRoom());
  172. // 查询是否关注
  173. NET.request(API.isSubscribed + this.liveId, {}, 'GET').then(res => {
  174. if(res.data==false){
  175. this.isLiveFav=false
  176. }else{
  177. this.isLiveFav=true
  178. }
  179. }).catch(res => {
  180. console.log(res)
  181. })
  182. } else {
  183. NET.request(API.getShortGoodsDetail + this.videoId, {}, 'GET').then(res => {
  184. this.goodsList = res.data
  185. }).catch(res => {
  186. uni.showToast({
  187. title: '获取商品列表失败',
  188. type: 'warning',
  189. })
  190. })
  191. }
  192. },
  193. enterRoom() {
  194. this.jhim = Jhim.getInstance(this.userId, this.sdkAppID, this.secretKey);
  195. this.jhim.login(this.userName, this.avatar).then(()=>{
  196. this.jhimgroup = this.jhim.createGroup(this.roomId);
  197. this.jhimgroup
  198. .on(this.onImText, this.jhim.TYPES.MSG_TEXT)
  199. .on(this.onImCustomMessage, this.jhim.TYPES.MSG_CUSTOM)
  200. .on(this.onImGroupTip, this.jhim.TYPES.MSG_GRP_TIP)
  201. .onReady(this.onImGroupReady)
  202. .join(this.isAuthor)
  203. })
  204. this.$refs.jhlive && this.$refs.jhlive.enterRoom();
  205. },
  206. onImText(e) {
  207. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  208. type: 'text',
  209. name: v.nick,
  210. text: v.payload.text
  211. }))];
  212. },
  213. onImCustomMessage() {
  214. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  215. type: v.payload.description,
  216. text: v.payload.data
  217. }))];
  218. },
  219. onImGroupTip(e) {
  220. this.jhimgroup.getProfile().then(v=>{
  221. this.subtitle = v.memberCount + '人在观看';
  222. });
  223. },
  224. onImGroupReady(e) {
  225. this.imStatus = e?'':'登录中...';
  226. },
  227. onImSend(text) {
  228. this.jhimgroup.sendText(text).then(msg => {
  229. this.imMsgs.push({
  230. type: 'text',
  231. name: msg.nick,
  232. text: msg.payload.text
  233. });
  234. this.$refs.jhlive && this.$refs.jhlive.cleanImInput();
  235. });
  236. },
  237. onLiveFav() {
  238. let data = {liveId: this.liveId}
  239. data.isDelete = this.isLiveFav ? 1 : 0
  240. NET.request(API.subscribeLive, data, 'POST').then(res => {
  241. this.isLiveFav = !this.isLiveFav
  242. }).catch(res => {
  243. console.log(res)
  244. })
  245. },
  246. exitRoom() {
  247. this.jhimgroup.off(this.onImText);
  248. this.jhimgroup.off(this.onImCustomMessage);
  249. this.jhimgroup.off(this.onImGroupTip);
  250. this.jhimgroup.offReady(this.onImGroupReady);
  251. this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout().then(()=>this.jhim.destroy()));
  252. this.$refs.jhlive && this.$refs.jhlive.exitRoom();
  253. },
  254. onBtnClick(index, item) {
  255. if(index === 0) {
  256. this.$refs.popup.open()
  257. }
  258. },
  259. goToGoodDetails(item) {
  260. uni.navigateTo({
  261. url: '/pagesGood/goodDetails?goodId=' + item.productId
  262. });
  263. },
  264. // 短视频报错
  265. videoErrorCallback(e) {
  266. console.log('短视频报错:' + e)
  267. }
  268. }
  269. }
  270. </script>
  271. <style lang="less" scoped>
  272. .container {
  273. position: relative;
  274. display: flex;
  275. flex-direction: column;
  276. align-items: stretch;
  277. width: 750rpx;
  278. }
  279. .jhlive {
  280. width: 750rpx;
  281. flex: 1;
  282. }
  283. .jhimlive {
  284. width: 400rpx;
  285. position: absolute;
  286. bottom: 10px;
  287. left: 10px;
  288. }
  289. .popup-open {
  290. width: 50px;
  291. height: 50px;
  292. position: fixed;
  293. bottom: 15px;
  294. right: 15px;
  295. background-color: #52A63A;
  296. border-radius: 50%;
  297. text-align: center;
  298. line-height: 50px;
  299. }
  300. .iconzhibo-shangpin {
  301. color: #FFFFFF;
  302. font-size: 34px;
  303. text-align: center;
  304. line-height: 50px;
  305. }
  306. .popup-box {
  307. background-color: #FFFFFF;
  308. width: 750rpx;
  309. height: 750rpx;
  310. border-top-left-radius: 10px;
  311. border-top-right-radius: 10px;
  312. }
  313. .popup-close {
  314. padding: 10px;
  315. line-height: 16px;
  316. }
  317. .popup-close-text {
  318. color: #52A63A;
  319. font-size: 15px;
  320. font-family: PingFang SC;
  321. text-align: left;
  322. }
  323. .good-box {
  324. width: 750rpx;
  325. height: 750rpx;
  326. padding: 0 0 10px 0;
  327. overflow: visible;
  328. }
  329. .goods-row:first-child {
  330. margin-top: 12px;
  331. }
  332. .goods-row {
  333. width: 700rpx;
  334. height: 114px;
  335. display: flex;
  336. flex-direction: row;
  337. flex-wrap: nowrap;
  338. background-color: #FFFFFF;
  339. box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  340. border-radius: 5px;
  341. margin: 0 15px 10px 15px;
  342. }
  343. .goods-img-box {
  344. margin-right: 15px;
  345. }
  346. .goods-img {
  347. width: 114px;
  348. height: 114px;
  349. object-fit: cover;
  350. }
  351. .goods-info {
  352. flex: 1;
  353. padding-top: 10px;
  354. }
  355. .goods-name {
  356. line-height: 15px;
  357. overflow: hidden;
  358. display: -webkit-box;
  359. -webkit-line-clamp: 2;
  360. -webkit-box-orient: vertical;
  361. word-wrap: break-word;
  362. text-overflow: ellipsis;
  363. font-size: 15px;
  364. font-family: PingFang SC;
  365. color: #333333;
  366. }
  367. .goods-sales {
  368. font-size: 12px;
  369. font-family: PingFang SC;
  370. color: #666666;
  371. line-height: 15px;
  372. margin: 8px 0 8px 0;
  373. }
  374. .price {
  375. font-size: 12px;
  376. text-decoration: line-through;
  377. color: #A67954;
  378. }
  379. .goods-number-bottom {
  380. display: flex;
  381. flex-direction: row;
  382. }
  383. .goods-number {
  384. display: flex;
  385. flex-direction: row;
  386. white-space: nowrap;
  387. line-height: 24px;
  388. }
  389. .goods-number-left {
  390. font-size: 12px;
  391. color: #666666;
  392. }
  393. .goods-icon {
  394. font-size: 14px;
  395. font-family: PingFang SC;
  396. color: #52A63A;
  397. }
  398. .goods-spec {
  399. font-size: 24px;
  400. font-family: PingFang SC;
  401. color: #52A63A;
  402. }
  403. .more-button {
  404. width: 24px;
  405. height: 24px;
  406. position: absolute;
  407. right: 16px;
  408. }
  409. .more-button-iconfont {
  410. font-size: 36px;
  411. color: #999999;
  412. text-align: center;
  413. }
  414. .tips-box {
  415. padding: 10px;
  416. width: 400rpx;
  417. border-radius: 6px;
  418. position: absolute;
  419. left: 175rpx;
  420. background-color: #ffffff;
  421. }
  422. .tips-box-text {
  423. text-align: center;
  424. color: #808080;
  425. font-size: 14px;
  426. }
  427. </style>