liveDetail.nvue 8.4 KB

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