liveDetail.nvue 9.2 KB

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