liveDetail.nvue 8.1 KB

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