liveDetail.nvue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. :showSwitch="true" :showBeauty="true" :btns="btns" @onBtnClick="onBtnClick"
  9. :showIm="true" :imStatus="imStatus" :imMsgs="imMsgs" @onImSend="onImSend" />
  10. <uni-popup ref="popup" animation type="bottom">
  11. <view class="popup-box">
  12. <view class="popup-close">
  13. <text class="popup-close-text" @click="$refs.popup.close()">收起</text>
  14. <text class="popup-close-text">绑定</text>
  15. </view>
  16. <scroll-view v-if="true" scroll-y="true" class="good-box2">
  17. <view class="goods-row2" v-for="(item, index) in goodsList" :key="index">
  18. <view class="good-check">
  19. <view @click="checkGoods(item)">
  20. <!-- #ifdef MP-WEIXIN -->
  21. <text class="iconfont good-check-iconfont" :class="item.check ? 'iconqueding' : 'iconfeigouxuan'" ></text>
  22. <!-- #endif -->
  23. </view>
  24. <!-- #ifdef APP-PLUS -->
  25. <text class="nvue-iconfont good-check-iconfont" :style="{fontFamily:'nvueIconfont'}">{{item.check ? '&#xe626;' : '&#xe646;'}}</text>
  26. <!-- #endif -->
  27. </view>
  28. <view class="good-card2">
  29. <view class="goods-img-box2">
  30. <image class="goods-img2" :src="item.imgPath" mode="aspectFill"></image>
  31. </view>
  32. <view class="goods-info2">
  33. <view>
  34. <text class="goods-name2">{{item.productName}}</text>
  35. </view>
  36. <text class="goods-sales2">销量:{{item.sellCount}}</text>
  37. <text class="price2">原价:{{item.originalPrice}}</text>
  38. <view class="goods-number2">
  39. <text class="goods-icon2">¥</text>
  40. <text class="goods-icon2">{{item.bizPrice}}/{{item.unit}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </uni-popup>
  48. </view>
  49. </template>
  50. <script>
  51. import jhlive from "@/jhlive/jhlive";
  52. import Jhim from "@/jhim/jhim.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: true,
  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.liveId = options.liveId
  86. this.userData = uni.getStorageSync("userData");
  87. this.userId = this.userData.userId;
  88. this.userName = this.userData.userName;
  89. let info = uni.getSystemInfoSync();
  90. this.windowWidth = info.windowWidth;
  91. this.windowHeight = info.windowHeight;
  92. // 假数据
  93. this.goodsList.push({
  94. productId: 1336146105292816384,
  95. tenantCode: null,
  96. imgPath: 'https: //www.qianjiadi.com:443/file/2020/12/2af4eb48-35c4-4aa7-80c9-ab7a7cb49984.jpg',
  97. productName: '测试拍卖商品zxw111',
  98. sellCount: 0,
  99. owner: 1,
  100. productType: 2,
  101. originalPrice: 1.00,
  102. bizPrice: 0.01,
  103. unit: '个'
  104. },{
  105. productId: 1336146105292816386,
  106. tenantCode: null,
  107. imgPath: 'https: //www.qianjiadi.com:443/file/2020/12/2af4eb48-35c4-4aa7-80c9-ab7a7cb49984.jpg',
  108. productName: '测试拍卖商品zxw222',
  109. sellCount: 0,
  110. owner: 1,
  111. productType: 2,
  112. originalPrice: 1.00,
  113. bizPrice: 0.01,
  114. unit: '个'
  115. })
  116. this.goodsIds = this.goodsList.map(site => {
  117. return site.productId
  118. }).join(',')
  119. this.goodsList.forEach(site => {
  120. site.check = this.goodsIds.indexOf(site.productId) != -1
  121. })
  122. },
  123. onReady() {
  124. // this.isAuthor = true;
  125. // this.linkMic = false;
  126. // this.userId = "123";
  127. // this.name = 'test';
  128. // this.roomId = '1';
  129. // this.$nextTick(() => this.enterRoom());
  130. // return;
  131. this.init();
  132. },
  133. onUnload() {
  134. this.exitRoom();
  135. },
  136. methods: {
  137. init() {
  138. NET.request(API.startStream + 2, 'GET').then(res => {
  139. this.avatar = res.data.imgUrl;
  140. this.title = res.data.liveName;
  141. this.roomId = String(res.data.roomId);
  142. this.$nextTick(() => this.enterRoom());
  143. }).catch(res => {
  144. uni.showToast({
  145. title: error.data.msg,
  146. duration: 2000
  147. });
  148. })
  149. },
  150. enterRoom() {
  151. this.jhim = Jhim.getInstance(this.userId, this.sdkAppID, this.secretKey);
  152. this.jhim.login(this.userName, this.avatar).then(()=>{
  153. this.jhimgroup = this.jhim.createGroup(this.roomId);
  154. this.jhimgroup
  155. .on(this.onImText, this.jhim.TYPES.MSG_TEXT)
  156. .on(this.onImCustomMessage, this.jhim.TYPES.MSG_CUSTOM)
  157. .on(this.onImGroupTip, this.jhim.TYPES.MSG_GRP_TIP)
  158. .onReady(this.onImGroupReady)
  159. .join(this.isAuthor)
  160. })
  161. this.$refs.jhlive && this.$refs.jhlive.enterRoom();
  162. },
  163. onImText(e) {
  164. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  165. type: 'text',
  166. name: v.nick,
  167. text: v.payload.text
  168. }))];
  169. },
  170. onImCustomMessage() {
  171. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  172. type: v.payload.description,
  173. text: v.payload.data
  174. }))];
  175. },
  176. onImGroupTip(e) {
  177. this.subtitle = e[0].payload.userIDList.length + '人在观看';
  178. },
  179. onImGroupReady(e) {
  180. this.imStatus = e?'':'登录中...';
  181. },
  182. onImSend(text) {
  183. this.jhimgroup.sendText(text).then(msg => {
  184. this.imMsgs.push({
  185. type: 'text',
  186. name: msg.nick,
  187. text: msg.payload.text
  188. });
  189. this.$refs.jhlive && this.$refs.jhlive.cleanImInput();
  190. });
  191. },
  192. exitRoom() {
  193. this.jhimgroup.off(this.onImText);
  194. this.jhimgroup.off(this.onImCustomMessage);
  195. this.jhimgroup.off(this.onImGroupTip);
  196. this.jhimgroup.offReady(this.onImGroupReady);
  197. this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout());
  198. this.$refs.jhlive && this.$refs.jhlive.exitRoom();
  199. },
  200. onBtnClick(index, item) {
  201. if(index === 0) {
  202. this.$refs.popup.open()
  203. }
  204. },
  205. // 勾选商品
  206. checkGoods(site) {
  207. site.check = !site.check
  208. }
  209. },
  210. }
  211. </script>
  212. <style>
  213. .nvue-iconfont {
  214. font-family: "nvueIconfont";
  215. font-size: 16px;
  216. font-style: normal;
  217. -webkit-font-smoothing: antialiased;
  218. -moz-osx-font-smoothing: grayscale;
  219. }
  220. </style>
  221. <style lang="less" scoped>
  222. .container {
  223. position: relative;
  224. display: flex;
  225. flex-direction: column;
  226. align-items: stretch;
  227. width: 750rpx;
  228. }
  229. .jhlive {
  230. width: 750rpx;
  231. flex: 1;
  232. }
  233. .jhimlive {
  234. width: 400rpx;
  235. position: absolute;
  236. bottom: 10px;
  237. left: 10px;
  238. // background-color: blue;
  239. }
  240. .popup-open {
  241. width: 50px;
  242. height: 50px;
  243. position: fixed;
  244. bottom: 15px;
  245. right: 15px;
  246. background-color: #52A63A;
  247. border-radius: 50%;
  248. text-align: center;
  249. line-height: 50px;
  250. }
  251. .iconzhibo-shangpin {
  252. color: #FFFFFF;
  253. font-size: 34px;
  254. }
  255. .popup-box {
  256. background-color: #FFFFFF;
  257. width: 750rpx;
  258. height: 265px;
  259. // border-radius: 10px 10px 0 0;
  260. border-top-left-radius:10px;
  261. border-top-right-radius: 10px;
  262. }
  263. .popup-close {
  264. padding: 10px;
  265. line-height: 16px;
  266. display: flex;
  267. flex-direction: row;
  268. justify-content: space-between;
  269. }
  270. .popup-close-text{
  271. color: #52A63A;
  272. font-size: 15px;
  273. font-family: PingFang SC;
  274. }
  275. // 商户端直播样式,暂时在用户端里调试
  276. .good-check {
  277. width: 30px;
  278. height: 104px;
  279. line-height: 104px;
  280. margin-right: 10px;
  281. }
  282. .good-check-iconfont {
  283. font-size: 40px;
  284. text-align: center;
  285. color: #51A539;
  286. line-height: 104px;
  287. }
  288. .good-box2 {
  289. width: 750rpx;
  290. height: 230px;
  291. padding: 0 0 10px 0;
  292. overflow: visible;
  293. }
  294. .goods-row2:first-child {
  295. margin-top: 12px;
  296. }
  297. .goods-row2 {
  298. width: 700rpx;
  299. height: 104px;
  300. display: flex;
  301. flex-direction: row;
  302. flex-wrap: nowrap;
  303. background-color: #FFFFFF;
  304. box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  305. border-radius: 5px;
  306. margin: 0 15px 10px 15px;
  307. }
  308. .good-card2 {
  309. display: flex;
  310. flex-direction: row;
  311. flex-wrap: nowrap;
  312. }
  313. .goods-img-box2 {
  314. margin-right: 15px;
  315. }
  316. .goods-img2 {
  317. width: 104px;
  318. height: 104px;
  319. object-fit: cover;
  320. }
  321. .goods-info2 {
  322. width: 180px;
  323. flex: 1;
  324. padding-top: 10px;
  325. }
  326. .goods-name2 {
  327. line-height: 15px;
  328. overflow: hidden;
  329. display: -webkit-box;
  330. -webkit-line-clamp: 2;
  331. -webkit-box-orient: vertical;
  332. word-wrap: break-word;
  333. text-overflow: ellipsis;
  334. font-size: 15px;
  335. font-family: PingFang SC;
  336. color: #333333;
  337. }
  338. .goods-sales2 {
  339. font-size: 12px;
  340. font-family: PingFang SC;
  341. color: #666666;
  342. line-height: 15px;
  343. margin: 8px 0 8px 0;
  344. }
  345. .price2 {
  346. font-size: 12px;
  347. text-decoration: line-through;
  348. color: #A67954;
  349. }
  350. .goods-number-bottom2 {
  351. display: flex;
  352. flex-direction: row;
  353. }
  354. .goods-number2 {
  355. display: flex;
  356. flex-direction: row;
  357. white-space: nowrap;
  358. line-height: 24px;
  359. }
  360. .goods-number-left2 {
  361. font-size: 12px;
  362. color: #666666;
  363. }
  364. .goods-icon2 {
  365. font-size: 14px;
  366. font-family: PingFang SC;
  367. color: #52A63A;
  368. }
  369. .goods-spec2 {
  370. font-size: 24px;
  371. font-family: PingFang SC;
  372. color: #52A63A;
  373. }
  374. </style>