liveDetail.nvue 9.0 KB

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