living.vue 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069
  1. <template>
  2. <view class="swiper-wrapper">
  3. <swiper class="swiper-container" :current="currentSwiperIndex" :circular="false" vertical
  4. @change="onSwiperChange" :style="{height: '100vh'}" :duration="300">
  5. <swiper-item v-for="(liveItem, index) in list" :key="liveItem.liveId">
  6. <view class="container" :class="{active: currentSwiperIndex === index}">
  7. <!-- 原有直播间内容结构保持不变 -->
  8. <view class="blackbg"></view>
  9. <view class="content">
  10. <!-- 页面内容 -->
  11. <view style=" position: fixed;top: 0;z-index: 5;" class="content-top">
  12. <view class="u-flex-y-center">
  13. <image @click="goBack" style="width: 60rpx;height: 64rpx;margin-right: 26rpx;"
  14. src="@/static/images/live/return.png"></image>
  15. <view class=" align-center"
  16. style="padding: 6rpx 4rpx;height: 64rpx;background: rgba(0,0,0,0.5);border-radius: 32rpx;">
  17. <u-avatar :src="liveItem.liveImgUrl||$img.logo" size="32"></u-avatar>
  18. <view class="colorf" style="margin-left: 8rpx;">
  19. <view>{{liveItem.liveName?truncateString(liveItem.liveName,5):"未命名"}}</view>
  20. <view style="font-size: 16rpx;">
  21. {{ liveItem.liveViewData?.follow || liveItem.liveViewData?.follow === 0 ? liveItem.liveViewData.follow : 0 }}位粉丝
  22. </view>
  23. </view>
  24. <view v-if="liveItem.isFollow" @click="onFollow(liveItem)" class="follow-btn ml20">
  25. 关注</view>
  26. <view v-else @click="onFollow(liveItem)" class="follow-btn ml20">已关注</view>
  27. </view>
  28. </view>
  29. <view class="u-flex-end align-center" @click="showadd=!showadd">
  30. <image class="w52 h52 mr4" v-for="(item,viewerIndex) in liveItem.filteredViewers"
  31. :key="viewerIndex" style="border-radius: 26rpx;" :src="item.avatar||$img.logo">
  32. </image>
  33. <view class="sum">{{liveItem.liveUserTotal||0}}</view>
  34. </view>
  35. </view>
  36. <!-- 页面内容 -->
  37. <view style=" position: fixed;top:100rpx;left: 0rpx; z-index: 5;" class="content-top">
  38. <view class="u-flex-y-center">
  39. <image @click="onRed(liveItem)" v-if="liveItem.redInfo?.redStatus==1"
  40. style="width: 70rpx;height: 70rpx;" src="@/static/images/hongbao.png"></image>
  41. </view>
  42. </view>
  43. <!-- 右边的 -->
  44. <view :class=" liveItem.showType==1 ? 'siderow-group' : 'side-group'">
  45. <view class="side-item">
  46. <image @click="onLike(liveItem)" src="/static/images/live/like.png"></image>
  47. <view>{{liveItem.liveViewData?.like||0}}</view>
  48. </view>
  49. <view class="side-item">
  50. <image @click="goStore(liveItem)" src="/static/images/live/shop.png"></image>
  51. <view>店铺</view>
  52. </view>
  53. <view class="side-item">
  54. <button open-type="share">
  55. <image src="/static/images/live/share.png" mode="widthFix"></image>
  56. </button>
  57. <view>分享</view>
  58. </view>
  59. </view>
  60. <view class="shop-prompt u-flex-y-center"
  61. v-if="liveItem.showPurchasePrompt&&liveItem.orderUser?.count">
  62. <image class="w32 h32 mr8" src="/static/images/live/shopping.png"></image>
  63. <text> {{liveItem.orderUser.userName ? maskString(liveItem.orderUser.userName) : ''}} 等
  64. {{liveItem.orderUser.count || 0}}
  65. 人正在去购买</text>
  66. </view>
  67. <!-- object-fit:fill; -->
  68. <view class="videolist " style="margin: auto 0">
  69. <view class="video" style="height:100vh">
  70. <!-- 修改video组件以支持HLS -->
  71. <!-- showType 1 横屏 2 竖屏 -->
  72. <video v-if="liveItem.livingUrl" :id="'myVideo_' + liveItem.liveId"
  73. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.livingUrl"
  74. :autoplay="currentSwiperIndex === index" :controls='false' object-fit='contain'
  75. :custom-cache="false" :enable-progress-gesture="false"
  76. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"
  77. :http-cache="false" @error="videoError">
  78. </video>
  79. <video v-if="liveItem.videoUrl"
  80. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.videoUrl"
  81. :autoplay="currentSwiperIndex === index" :controls='false' object-fit='contain'
  82. :custom-cache="false" :enable-progress-gesture="false"
  83. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"
  84. :http-cache="false" loop @error="videoError">
  85. </video>
  86. <!-- 加载提示 -->
  87. <view v-if="liveItem.loading" class="loading-tip">
  88. <u-loading mode="circle" color="#ffffff" size="36"></u-loading>
  89. <text class="loading-text">加载中...</text>
  90. </view>
  91. </view>
  92. </view>
  93. <view class="pb40 mt90" style="position: fixed;bottom: 0;">
  94. <view class="w100 h300 mt20">
  95. <scroll-view enable-flex scroll-y="true" class="talk p20 scrolly flex-1 column"
  96. style="width: calc(100% - 40rpx);height: calc(100% - 40rpx);"
  97. :scroll-into-view="liveItem.scrollIntoView">
  98. <view>
  99. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  100. :key="talkIndex" v-show="item.cmd=='announcement'">
  101. <view class="talk-list ml16 justify-start">
  102. <view class="fs24">
  103. <text class='fs24 colorf'>
  104. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  110. :key="talkIndex" :id="`list_${talkIndex}`"
  111. v-show="item.cmd!='red'&&item.cmd!='out'&&item.cmd!='entry'">
  112. <view class="talk-list ml16 justify-start">
  113. <view class="fs24">
  114. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  115. <text class='fs24 colorf'>{{item.msg}}</text>
  116. </view>
  117. </view>
  118. </view>
  119. <view v-if="liveItem.showWelcomeMessage" class="welcome-message">
  120. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  121. :key="talkIndex" v-show="item.cmd=='entry'||item.cmd=='out'">
  122. <view class="talk-list ml16 justify-start">
  123. <view class="fs24">
  124. <text style="color: #ff89d6;">{{item.nickName}} </text>
  125. <text class='fs24 colorf'>
  126. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </scroll-view>
  132. </view>
  133. <view class="justify-between p24">
  134. <view class="u-flex-y-center"
  135. style="background:rgba(157, 157, 157, 0.8);padding:18rpx 14rpx 18rpx 32rpx;width: 526rpx;box-sizing:border-box;border-radius:36rpx;">
  136. <u-input :placeholder="liveItem.placeholderText" border="none"
  137. customStyle='font-size:24rpx;' v-model="liveItem.value" shape='circle'
  138. color='#fff' placeholderStyle='color:#e7e7e7' class="ml20"
  139. @keydown.enter="sendMsg(liveItem)">
  140. </u-input>
  141. </view>
  142. <view class="justify-between mr30 align-center">
  143. <view class="icon-bg ml20" @click="liveItem.shopping=!liveItem.shopping">
  144. <image src="/static/images/shopping.png" class="w48 h48"></image>
  145. </view>
  146. <view class="icon-bg ml20" @click="liveItem.showziliao=!liveItem.showziliao">
  147. <image src="/static/images/more-icon.png" class="w48 h48"></image>
  148. </view>
  149. </view>
  150. </view>
  151. </view>
  152. </view>
  153. <!-- 弹窗组件保持不变 -->
  154. <u-popup :show="showadd" @close="close" @open="openViews" round='20rpx' bgColor='#ffffff'>
  155. <view class="view-box">
  156. <view class="t-c fs30">在线观众</view>
  157. <scroll-view scroll-y class="scroll-content" :style="{height: scrollHeight + 'px'}"
  158. @scrolltolower="handleScrollToLower">
  159. <view class="fs24 u-flex-y-center mb20" v-for="(item,index) in liveViewers"
  160. :key="index">
  161. <view
  162. :style="{color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',fontWeight: index < 3 ? 'bold' : 'normal',width: '50rpx'}"
  163. class="mr10">{{index+1}}</view>
  164. <u-avatar :src="item.avatar||$img.logo" size="32"></u-avatar>
  165. <text class="ml16">{{item.nickName||"未命名"}}</text>
  166. </view>
  167. <view class="no-more" v-if="viewNoMoreData && liveViewers.length > 0">
  168. <text>没有更多了</text>
  169. </view>
  170. </scroll-view>
  171. <view class="fs24 u-flex-y-center bottom">
  172. <view class="mr10" style="width:50rpx">我</view>
  173. <u-avatar :src="livedata.liveImgUrl||$img.logo" size="32"></u-avatar>
  174. <text class="ml16">{{livedata.liveName||"未命名"}}</text>
  175. </view>
  176. </view>
  177. </u-popup>
  178. <u-popup :show="shopping" @close="closeShop" @open="openShop" round='20rpx' bgColor='f3f5f9'>
  179. <view class="shoppop">
  180. <view class="shoppop-top">
  181. <u-avatar :src="store.logoUrl" size="36" class="ml16"></u-avatar>
  182. <view class="search-input u-flex-y-center">
  183. <image style="width: 24rpx;height: 24rpx;margin-right: 16rpx;"
  184. src="@/static/images/search.png">
  185. </image>
  186. <input placeholder="请搜索商品" v-model="inputInfo" @input="handleSearchInput" />
  187. </view>
  188. <view class="t-c search-top" style="margin-right: 48rpx;">
  189. <image @click="onStoreCollect" v-if="store.isFavorite"
  190. style="width: 32rpx;height: 32rpx;" src="@/static/images/collect_select.png">
  191. </image>
  192. <image v-else @click="onStoreCollect" style="width: 32rpx;height: 32rpx;"
  193. src="@/static/images/collect.png"></image>
  194. <view>收藏</view>
  195. </view>
  196. <view class="t-c search-top" @click="goOrderList">
  197. <image style="width: 32rpx;height: 32rpx;" src="@/static/images/order.png"></image>
  198. <view>订单</view>
  199. </view>
  200. </view>
  201. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  202. <view class="list-item " v-for="(item,index) in products" :key="index">
  203. <view class="goods-img">
  204. <image :src="item.imgUrl" mode="widthFix"></image>
  205. <view class="goods-label">{{index+1}}</view>
  206. </view>
  207. <view class="goods-right">
  208. <view class="goods-title">{{item.productName}}</view>
  209. <view class="goods-people">{{item.sales}} 人已购</view>
  210. <view class="goods-shop">
  211. <text class="nummber"><text
  212. style="font-size: 20rpx;font-weight: 600;">¥</text><text
  213. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}/日</text>
  214. <view class="btn-group u-flex-y-center">
  215. <view class="collect-btn">
  216. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  217. style="width: 32rpx;height: 32rpx;"
  218. src="/static/images/collect_select.png">
  219. </image>
  220. <image v-else @click="onGoodsCollect(item)"
  221. style="width: 32rpx;height: 32rpx;"
  222. src="/static/images/collect.png">
  223. </image>
  224. </view>
  225. <view v-if="item.status==1" class="shop-btn"
  226. @click="goShop(item.productId,item.goodsId)">去购买
  227. </view>
  228. <view v-else-if="item.status==0" @click="goShop(item.productId)"
  229. class="shop-btn">
  230. 已下架</view>
  231. </view>
  232. </view>
  233. </view>
  234. </view>
  235. </scroll-view>
  236. </view>
  237. </u-popup>
  238. </view>
  239. </swiper-item>
  240. </swiper>
  241. </view>
  242. </template>
  243. <script>
  244. import Hls from 'hls.js';
  245. import CryptoJS from 'crypto-js'
  246. import {
  247. liveList
  248. } from '@/api/list'
  249. import {
  250. liveRed, // 点击领红包
  251. liveDataLike, // 点赞
  252. collectStore, // 店铺收藏/取消收藏
  253. collectGoods, // 商品收藏/取消收藏
  254. store, // 查询店铺
  255. follow, // 关注/取消关注
  256. watchUserList, //获取直播间用户(展示在线用户)
  257. liveMsg, //获取最近聊天记录
  258. // 小黄车
  259. liveStore, //店铺展示,
  260. // liveGoodsDetail, //商品详情,
  261. liveOrderUser, //正在购买
  262. getLiveInfo, //获取直播间信息接口
  263. getLiveViewData //直播间点赞、关注、在线人数数据
  264. } from '@/api/live'
  265. import {
  266. liveOrderList, // 订单列表
  267. } from '@/api/order'
  268. import parse from '../../uni_modules/uview-plus/libs/config/props/parse';
  269. import {
  270. LiveWS
  271. } from '@/utils/liveWS.js'
  272. import {
  273. getlive,
  274. // gettextlist,
  275. getAnswerlist,
  276. submitAnswer
  277. } from '@/api/home'
  278. // var wsUrl = "ws://192.168.10.166:7114/app/webSocket";
  279. // var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
  280. // var wsUrl = "ws://192.168.10.125:7114/app/webSocket"; //涂小龙
  281. var wsUrl = "wss://live.test.ylrztop.com/ws/live-api/app/webSocket"; //余红奇
  282. // var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
  283. // var wsUrl = "ws://192.168.10.125:7114/app/webSocket"; //涂小龙
  284. // var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket"; //余红奇
  285. // var wsUrl = "ws://nd383294.natappfree.cc/app/webSocket"; //余红奇
  286. // var wsUrl = "ws://v56c9b8e.natappfree.cc/app/webSocket"; //余红奇
  287. // var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; //陈果
  288. // var wsUrl = "ws://live.ylrzcloud.com/socket/app/webSocket";
  289. var pingpangTimes = null;
  290. var initTimes = null;
  291. var isSocketOpen = false;
  292. var socket = null;
  293. export default {
  294. data() {
  295. return {
  296. socketInstances: {}, // 改为对象存储多个socket实例
  297. currentSwiperIndex: 0, // 当前swiper索引
  298. preloadCount: 5, // 预加载直播间数量
  299. list: [], // 直播间列表
  300. preloading: false, // 预加载状态
  301. liveUserTotal: null,
  302. viewPageSize: 10, // 每页数量
  303. viewPageNum: 1, // 当前页码
  304. viewLoading: false, // 是否正在加载
  305. viewNoMoreData: false, // 是否没有更多数据
  306. scrollHeight: 0,
  307. scrollTimer: null, // 滚动防抖定时器
  308. socketInstance: null, // 统一管理 socket 实例
  309. reconnectCount: 0,
  310. maxReconnectAttempts: 3,
  311. isManualClose: false, // 标记是否手动关闭
  312. showRed: true,
  313. redInfo: {},
  314. inputInfo: '',
  315. searchTimer: null,
  316. storeId: null,
  317. reconnectTimer: null,
  318. isCollect: false,
  319. showPurchasePrompt: false,
  320. purchasePromptTimer: null,
  321. prevOrderCount: 0, // 用于记录上一次的购买人数
  322. videoUrl: null,
  323. showType: 1, //横屏1 竖屏2
  324. boxHeight: 300, //小黄车高度
  325. isFollow: true,
  326. liveViewData: {},
  327. liveViewers: [], //观众
  328. likeName: 0,
  329. hlsPlayer: null, // HLS播放器实例,
  330. livingUrl: "",
  331. products: {},
  332. store: {},
  333. orderUser: {}, //正在购买
  334. userType: 0,
  335. timestamp: '',
  336. liveId: null,
  337. // userId: uni.getStorageSync("userInfo.userId"),
  338. placeholderText: '说点什么...',
  339. isZoom: false, //点赞按钮控制是否放大
  340. userinfo: '', //用户信息
  341. // path: 'http://192.168.10.166/dev-api', //余红奇
  342. // path: 'http://v56c9b8e.natappfree.cc', //余红奇
  343. // path: 'live.test.ylrztop.com/prod-api', //余红奇
  344. // path: 'http://192.168.10.170/dev-api', //陈果
  345. value: '',
  346. talkdisabled: false, //输入框是否禁用
  347. autoplay: false, //视频自动播放
  348. showadd: false,
  349. talklist: [],
  350. scrollIntoView: '',
  351. videoContext: '',
  352. thistime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
  353. showWelcomeMessage: false,
  354. isSubmit: false,
  355. messageContent: "",
  356. showziliao: false,
  357. isScreen: true,
  358. shopping: false, //小黄车弹窗
  359. scrollTop: 0, //弹幕
  360. old: {
  361. scrollTop: 0
  362. },
  363. livedata: {}, //直播间点赞、关注、在线人数数据
  364. };
  365. },
  366. onLoad(options) {
  367. this.initTime();
  368. if (options.liveId) {
  369. this.liveId = options.liveId; // 仅当 liveId 变化时更新
  370. }
  371. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  372. // 初始化直播间列表
  373. this.initLiveList(options);
  374. const platform = uni.getSystemInfoSync().platform;
  375. if (['mp-weixin', 'mp-alipay', 'mp-baidu', 'mp-toutiao'].includes(platform)) {
  376. // 确保 API 存在再调用
  377. if (uni.showShareMenu) {
  378. uni.showShareMenu({
  379. withShareTicket: true, // 可选参数,根据需求配置
  380. success: () => {
  381. console.log('分享菜单显示成功');
  382. },
  383. fail: (err) => {
  384. console.error('分享菜单显示失败:', err);
  385. }
  386. });
  387. } else {
  388. console.warn('当前平台不支持 uni.showShareMenu');
  389. }
  390. } else {
  391. console.log('当前平台无需显示分享菜单');
  392. }
  393. },
  394. onReady(){
  395. },
  396. onShareAppMessage() {
  397. return {
  398. // title: this.product.title,
  399. title: this.livedata.liveName,
  400. path: '/pages/home/index',
  401. imageUrl: this.products.image,
  402. success(res) {
  403. console.log("分享成功", res);
  404. },
  405. fail(err) {
  406. console.error("分享失败", err);
  407. }
  408. };
  409. },
  410. computed: {
  411. filteredViewers() {
  412. if (!this.liveViewers) {
  413. return
  414. } else {
  415. return this.liveViewers.slice(0, 3);
  416. }
  417. }
  418. },
  419. onHide() {
  420. clearInterval(this.intervalId); // 页面隐藏时清理
  421. },
  422. onUnload() {
  423. // 关闭所有WebSocket连接
  424. this.closeAllWebSockets();
  425. // 移除所有全局事件监听
  426. this.removeAllEventListeners();
  427. // 清理定时器
  428. this.clearAllTimers();
  429. // 销毁HLS播放器
  430. if (this.hlsPlayer) {
  431. this.hlsPlayer.destroy();
  432. this.hlsPlayer = null;
  433. }
  434. },
  435. watch: {
  436. // 监听orderUser.count的变化
  437. 'orderUser.count': {
  438. handler(newVal, oldVal) {
  439. if (newVal !== this.prevOrderCount) {
  440. this.prevOrderCount = newVal;
  441. this.showPurchaseMessage();
  442. }
  443. },
  444. immediate: true
  445. }
  446. },
  447. methods: {
  448. closeAllWebSockets() {
  449. this.isManualClose = true;
  450. // 关闭所有连接
  451. Object.keys(this.socketInstances).forEach(liveId => {
  452. try {
  453. if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
  454. this.socketInstances[liveId].instance.close({
  455. code: 1000,
  456. reason: '页面关闭'
  457. });
  458. console.log(`直播间 ${liveId} WebSocket 已关闭`);
  459. }
  460. } catch (e) {
  461. console.error(`关闭直播间 ${liveId} WebSocket 时出错:`, e);
  462. }
  463. });
  464. this.socketInstances = {};
  465. isSocketOpen = false;
  466. }, // 新增:移除所有全局事件监听器
  467. removeAllEventListeners() {
  468. uni.$off('initSocket');
  469. uni.$off('sendMsg');
  470. uni.$off('closeWebSocket');
  471. uni.$off('refreshOrder');
  472. // 可以根据实际情况添加其他需要移除的事件
  473. }, // 新增:清理所有定时器
  474. clearAllTimers() {
  475. if (this.intervalId) {
  476. clearInterval(this.intervalId);
  477. this.intervalId = null;
  478. }
  479. if (this.pingpangTimes) {
  480. clearInterval(this.pingpangTimes);
  481. this.pingpangTimes = null;
  482. }
  483. if (this.reconnectTimer) {
  484. clearInterval(this.reconnectTimer);
  485. this.reconnectTimer = null;
  486. }
  487. if (this.scrollTimer) {
  488. clearTimeout(this.scrollTimer);
  489. this.scrollTimer = null;
  490. }
  491. if (this.searchTimer) {
  492. clearTimeout(this.searchTimer);
  493. this.searchTimer = null;
  494. }
  495. if (this.purchasePromptTimer) {
  496. clearTimeout(this.purchasePromptTimer);
  497. this.purchasePromptTimer = null;
  498. }
  499. },
  500. // 初始化当前直播间数据
  501. async initCurrentLiveData() {
  502. const currentLive = this.list[this.currentSwiperIndex];
  503. if (!currentLive) return;
  504. console.log("initCurrentLiveData:" + currentLive)
  505. try {
  506. // 并行加载,但允许单个失败不阻塞整体
  507. await Promise.allSettled([
  508. this.getLiveMsg(currentLive),
  509. this.getliveViewData(currentLive),
  510. this.getliving(currentLive),
  511. this.initSocket(currentLive)
  512. ]);
  513. currentLive.loaded = true;
  514. } catch (error) {
  515. console.error("初始化直播间数据失败:", error);
  516. } finally {
  517. currentLive.loading = false;
  518. }
  519. },
  520. // 初始化直播间列表
  521. async initLiveList(options) {
  522. try {
  523. await this.getList(); // 先加载直播间列表
  524. if (this.list.length === 0) {
  525. console.error("直播间列表为空,无法初始化");
  526. return;
  527. }
  528. // 设置初始直播间索引
  529. if (options.liveId) {
  530. const index = this.list.findIndex(item => item.liveId == options.liveId);
  531. this.currentSwiperIndex = index !== -1 ? index : 0;
  532. } else {
  533. this.currentSwiperIndex = 0;
  534. }
  535. console.log(this.currentSwiperIndex)
  536. // 获取当前直播间的liveItem
  537. const currentLive = this.list[this.currentSwiperIndex];
  538. console.log(currentLive)
  539. if (currentLive) {
  540. this.liveId = currentLive.liveId;
  541. // 只初始化当前直播间的WebSocket
  542. // await this.getLiveMsg(currentLive);
  543. // await this.initCurrentLiveData();
  544. this.preloadNearbyLives();
  545. }
  546. } catch (error) {
  547. console.error("初始化失败:", error);
  548. }
  549. },
  550. // 预加载相邻直播间
  551. async preloadNearbyLives() {
  552. if (this.list.length === 0) {
  553. console.warn("list 为空,跳过预加载");
  554. return;
  555. }
  556. this.preloading = true;
  557. const preloadIndexes = [];
  558. const currentIndex = this.currentSwiperIndex;
  559. // 预加载前后各一个直播间
  560. if (currentIndex > 0) preloadIndexes.push(currentIndex - 1);
  561. if (currentIndex < this.list.length - 1) preloadIndexes.push(currentIndex + 1);
  562. // 异步预加载
  563. for (const index of preloadIndexes) {
  564. const liveItem = this.list[index];
  565. if (!liveItem) continue;
  566. if (!liveItem.loaded && !liveItem.loading) {
  567. try {
  568. await this.getLiveMsg(liveItem);
  569. await this.getliveViewData(liveItem);
  570. // 新增:预加载视频地址(关键)
  571. await this.getliving(liveItem);
  572. liveItem.loaded = true;
  573. } catch (error) {
  574. console.error(`预加载直播间 ${index} 失败:`, error);
  575. }
  576. }
  577. }
  578. this.preloading = false;
  579. },
  580. // Swiper切换事件
  581. async onSwiperChange(e) {
  582. const newIndex = e.detail.current;
  583. const oldIndex = this.currentSwiperIndex;
  584. // 1. 关闭旧直播间连接,暂停视频
  585. const oldLive = this.list[oldIndex];
  586. console.log("onSwiperChange")
  587. if (oldLive) {
  588. this.closeWebSocket(oldLive.liveId);
  589. this.pauseVideo(oldLive);
  590. }
  591. // 2. 更新当前直播间索引和 liveId
  592. this.currentSwiperIndex = newIndex;
  593. const newLive = this.list[newIndex];
  594. if (!newLive) return;
  595. this.liveId = newLive.liveId;
  596. // 3. 重置全局数据(避免旧数据影响新直播间)
  597. this.liveViewers = []; // 重置观众列表
  598. this.products = []; // 重置商品列表
  599. this.store = {}; // 重置店铺信息
  600. this.orderUser = {}; // 重置正在购买用户
  601. this.viewPageNum = 1; // 重置观众分页
  602. this.viewNoMoreData = false;
  603. // 4. 加载新直播间数据
  604. try {
  605. // 并行加载关键数据(视频、观众、商品等)
  606. await Promise.all([
  607. this.initSocket(),
  608. this.getliving(newLive), // 视频源
  609. this.getLiveMsg(newLive), // 聊天记录
  610. this.getliveViewData(newLive), // 点赞/关注数据
  611. this.getliveUser(), // 观众列表(当前直播间)
  612. this.getliveOrder() // 正在购买用户(当前直播间)
  613. ]);
  614. // 播放新视频
  615. this.$nextTick(() => this.playVideo(newLive));
  616. } catch (error) {
  617. console.error('切换直播间加载数据失败:', error);
  618. }
  619. },
  620. // 获取直播间列表
  621. async getList() {
  622. const data = {
  623. page: 1,
  624. page_size: 20
  625. };
  626. try {
  627. const res = await liveList(data);
  628. if (res.code === 200) {
  629. this.list = res.rows.map(item => ({
  630. ...item,
  631. talklist: [],
  632. loading: false,
  633. loaded: false,
  634. // 其他初始化字段...
  635. }));
  636. console.log("直播间列表加载成功,数量:", this.list.length); // 确认数量是否 > 0
  637. } else {
  638. uni.showToast({
  639. title: res.msg,
  640. icon: "none"
  641. });
  642. this.list = []; // 接口失败时清空列表,避免后续错误
  643. }
  644. } catch (error) {
  645. console.error("获取直播间列表失败:", error);
  646. this.list = []; // 异常时清空列表
  647. }
  648. },
  649. // 播放视频
  650. playVideo(liveItem) {
  651. if (!liveItem) {
  652. console.error('播放失败:直播间数据不存在');
  653. return;
  654. }
  655. // 检查视频源是否存在
  656. if (!liveItem.livingUrl && !liveItem.videoUrl) {
  657. console.error('播放失败:无视频源', liveItem);
  658. // 尝试重新加载视频源
  659. liveItem.loading = true;
  660. this.getliving(liveItem).then(() => {
  661. liveItem.loading = false;
  662. this.$nextTick(() => this.playVideo(liveItem)); // 重新尝试播放
  663. });
  664. return;
  665. }
  666. this.$nextTick(() => {
  667. try {
  668. const videoId = `myVideo_${liveItem.liveId}`;
  669. const videoContext = uni.createVideoContext(videoId, this);
  670. if (videoContext) {
  671. videoContext.play();
  672. } else {
  673. console.error('未找到视频组件', videoId);
  674. }
  675. } catch (error) {
  676. console.error("播放视频失败:", error);
  677. }
  678. });
  679. },
  680. // 重置直播间数据
  681. resetLiveData() {
  682. // 保留不需要重置的数据(如用户信息等)
  683. const keepData = {
  684. userinfo: this.userinfo,
  685. list: this.list,
  686. currentSwiperIndex: this.currentSwiperIndex
  687. };
  688. // 重置其他直播间特定数据
  689. this.liveUserTotal = null;
  690. this.liveViewData = {};
  691. this.liveViewers = [];
  692. this.livingUrl = "";
  693. this.videoUrl = null;
  694. this.products = {};
  695. this.store = {};
  696. this.orderUser = {};
  697. this.talklist = [];
  698. this.livedata = {};
  699. this.isFollow = true;
  700. // 恢复需要保留的数据
  701. Object.assign(this, keepData);
  702. },
  703. // 获取直播间用户
  704. async getliveUser(isLoadMore = false) {
  705. // 强制使用当前 liveId,避免使用旧值
  706. const currentLiveId = this.liveId;
  707. if (!currentLiveId) return;
  708. if (this.viewLoading || this.viewNoMoreData) return;
  709. this.viewLoading = true;
  710. try {
  711. const res = await watchUserList(currentLiveId, this.viewPageSize, this.viewPageNum, false);
  712. if (res.code === 200) {
  713. // 若请求期间已切换直播间,忽略旧数据
  714. if (this.liveId !== currentLiveId) return;
  715. this.liveUserTotal = res.total;
  716. if (res.rows.length === 0) {
  717. this.viewNoMoreData = true;
  718. return;
  719. }
  720. this.liveViewers = isLoadMore ? [...this.liveViewers, ...res.rows] :
  721. res.rows; // 首次加载/切换直播间时重置数据
  722. this.viewPageNum++;
  723. }
  724. } catch (error) {
  725. console.error('获取观众列表失败:', error);
  726. } finally {
  727. this.viewLoading = false;
  728. }
  729. },
  730. // 滚动到底部触发
  731. handleScrollToLower() {
  732. // 清除上一次未执行的定时器,避免重复请求
  733. if (this.scrollTimer) {
  734. clearTimeout(this.scrollTimer);
  735. }
  736. // 延迟0.5秒(500毫秒)执行接口请求
  737. this.scrollTimer = setTimeout(() => {
  738. this.getliveUser(true); // 加载更多数据
  739. }, 1000); // 延迟时间:500毫秒
  740. },
  741. // gettalklist() {
  742. // if (!this.liveId) return;
  743. // const param = {
  744. // id: this.liveId
  745. // }
  746. // gettextlist(param).then(res => {
  747. // if (res.code == 200) {
  748. // this.talklist = res.data
  749. // // console.log(res.data);
  750. // this.$nextTick(() => {
  751. // this.scrollIntoView = `list_${this.talklist.length-1}`
  752. // })
  753. // }
  754. // })
  755. // },
  756. // 修改其他方法,增加liveItem参数
  757. async getLiveMsg(liveItem) {
  758. // 强化校验:确保 liveItem 存在且包含 liveId
  759. if (!liveItem || !liveItem.liveId) {
  760. console.error('getLiveMsg 错误:无效的 liveItem', {
  761. liveItem: liveItem,
  762. currentIndex: this.currentSwiperIndex,
  763. listLength: this.list.length
  764. });
  765. return; // 直接返回,不执行后续逻辑
  766. }
  767. try {
  768. const res = await liveMsg(liveItem.liveId, 30, 1);
  769. if (res.code == 200) {
  770. // 确保使用响应式更新
  771. this.$set(liveItem, 'talklist', [...res.rows]);
  772. this.$nextTick(() => {
  773. this.$set(liveItem, 'scrollIntoView', `list_${liveItem.talklist.length-1}`);
  774. });
  775. }
  776. } catch (error) {
  777. console.error("获取聊天记录失败:", error);
  778. }
  779. },
  780. // 暂停视频
  781. pauseVideo(liveItem) {
  782. if (!liveItem.livingUrl && !liveItem.videoUrl) return;
  783. try {
  784. const videoId = `myVideo_${liveItem.liveId}`;
  785. const videoContext = uni.createVideoContext(videoId, this);
  786. if (videoContext) {
  787. videoContext.pause();
  788. }
  789. } catch (error) {
  790. console.error("暂停视频失败:", error);
  791. }
  792. },
  793. // 点击红包
  794. onRed() {
  795. console.log("点了")
  796. if (!this.liveId) return;
  797. console.log("点了this.liveId", this.liveId)
  798. if (!this.redInfo?.redId) return;
  799. console.log("点了this.redInfo?.redId", this.redInfo.redId)
  800. console.log("点了this.userinfo.userId", this.userinfo.userId)
  801. let data = {
  802. liveId: this.liveId,
  803. userId: this.userinfo.userId,
  804. redId: this.redInfo.redId,
  805. }
  806. liveRed(data).then(res => {
  807. if (res.code == 200) {} else {
  808. uni.showToast({
  809. title: res.msg,
  810. icon: 'none'
  811. });
  812. }
  813. },
  814. rej => {}
  815. );
  816. },
  817. handleSearchInput() {
  818. // 使用防抖优化性能,避免频繁请求
  819. clearTimeout(this.searchTimer);
  820. this.searchTimer = setTimeout(() => {
  821. this.queryCollect();
  822. }, 500); // 500毫秒延迟
  823. },
  824. // 显示购买提示信息
  825. showPurchaseMessage() {
  826. // 清除之前的定时器
  827. if (this.purchasePromptTimer) {
  828. clearTimeout(this.purchasePromptTimer);
  829. }
  830. // 显示提示
  831. this.showPurchasePrompt = true;
  832. // 2秒后自动隐藏
  833. this.purchasePromptTimer = setTimeout(() => {
  834. this.showPurchasePrompt = false;
  835. }, 2000);
  836. },
  837. truncateString(str, maxLength) {
  838. return str.length > maxLength ? str.slice(0, maxLength) + '...' : str;
  839. },
  840. goStore() {
  841. console.log("带过去storeId", this.storeId)
  842. uni.navigateTo({
  843. url: '/pages_shop/store?liveId=' + this.liveId + "&storeId=" + this.storeId
  844. })
  845. },
  846. // 去订单列表
  847. goOrderList() {
  848. uni.navigateTo({
  849. url: "/pages_shop/order"
  850. })
  851. },
  852. // 初始化HLS播放器
  853. initHlsPlayer() {
  854. if (Hls.isSupported() && this.livingUrl) {
  855. const video = document.getElementById('myVideo');
  856. if (video) {
  857. this.hlsPlayer = new Hls();
  858. this.hlsPlayer.loadSource(this.livingUrl);
  859. this.hlsPlayer.attachMedia(video);
  860. this.hlsPlayer.on(Hls.Events.MANIFEST_PARSED, () => {
  861. video.play();
  862. });
  863. }
  864. }
  865. },
  866. // 视频错误处理
  867. videoError(e) {
  868. console.error('视频播放错误:', e.detail.errMsg);
  869. // 尝试重新加载或切换到备用流
  870. if (this.livingUrl) {
  871. setTimeout(() => {
  872. this.videoContext.play();
  873. }, 2000);
  874. }
  875. },
  876. // 修改获取直播信息方法
  877. async getliving(liveItem) {
  878. if (!liveItem || !liveItem.liveId) return;
  879. console.log("获取直播信息:", liveItem.liveId);
  880. const param = {
  881. id: liveItem.liveId
  882. };
  883. try {
  884. const res = await getlive(param);
  885. if (res.code !== 200) {
  886. uni.showToast({
  887. title: res.msg,
  888. icon: 'none'
  889. });
  890. return;
  891. }
  892. // 强制更新视频源(覆盖旧值)
  893. if (res.data.liveType === 2) {
  894. // 回放视频
  895. this.$set(liveItem, 'videoUrl', res.data.videoUrl);
  896. this.$set(liveItem, 'livingUrl', ''); // 清空直播流
  897. } else if (res.data.liveType === 1) {
  898. // 直播流
  899. this.$set(liveItem, 'livingUrl', res.data.flvHlsUrl);
  900. this.$set(liveItem, 'videoUrl', ''); // 清空回放视频
  901. } else {
  902. // 未开播
  903. this.$set(liveItem, 'livingUrl', '');
  904. this.$set(liveItem, 'videoUrl', '');
  905. }
  906. // 更新其他直播信息
  907. this.$set(liveItem, 'showType', res.data.showType);
  908. this.$set(liveItem, 'storeId', res.storeId);
  909. this.$set(liveItem, 'autoplay', res.data.liveType !== 0); // 未开播不自动播放
  910. } catch (err) {
  911. console.error("获取直播信息失败:", err);
  912. uni.showToast({
  913. title: "获取直播信息失败",
  914. icon: 'none'
  915. });
  916. }
  917. }, // 设置视频播放
  918. setupVideoPlayback(liveItem, liveData) {
  919. if (!liveItem.livingUrl) return;
  920. // H5 平台:使用 HLS.js 处理 .m3u8 流
  921. // #ifdef H5
  922. if (liveItem.livingUrl.includes('.m3u8')) {
  923. this.initHlsPlayer(liveItem);
  924. return;
  925. }
  926. // #endif
  927. // 小程序/App 平台:直接使用 video 组件
  928. const videoId = `myVideo_${liveItem.liveId}`;
  929. const videoContext = uni.createVideoContext(videoId, this);
  930. if (liveData.liveType === 1) {
  931. // 回放:跳转到指定位置
  932. videoContext.seek(liveData.nowDuration || 0);
  933. } else {
  934. // 直播:直接播放
  935. videoContext.play();
  936. }
  937. },
  938. maskString(str, maskChar = '*') {
  939. // 新增:如果str是undefined或null,直接返回空字符串
  940. if (!str) return '';
  941. // 确保str是字符串(如果是数字等类型,先转为字符串)
  942. const strVal = String(str);
  943. return strVal.split('').map((char, index) => (index === 0 ? char : maskChar)).join('');
  944. },
  945. getPureDecimal(num, precision = 6) {
  946. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  947. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  948. },
  949. // 返回上一个页面并关闭WebSocket
  950. goBack() {
  951. // 暂停当前视频
  952. const currentLive = this.list[this.currentSwiperIndex];
  953. if (currentLive) {
  954. this.pauseVideo(currentLive);
  955. }
  956. // 关闭所有WebSocket连接
  957. this.closeWebSocket();
  958. // 导航返回
  959. const pages = getCurrentPages();
  960. if (pages.length > 1) {
  961. uni.navigateBack();
  962. } else {
  963. uni.switchTab({
  964. url: '/pages/list/index'
  965. });
  966. }
  967. },
  968. // 修改其他需要liveItem参数的方法
  969. async getliveViewData(liveItem) {
  970. if (!liveItem || !liveItem.liveId) return;
  971. try {
  972. const res = await getLiveViewData(liveItem.liveId);
  973. if (res.code == 200) {
  974. liveItem.liveViewData = res;
  975. }
  976. } catch (error) {
  977. console.error("获取直播间数据失败:", error);
  978. }
  979. },
  980. //正在购买
  981. async getliveOrder() {
  982. const currentLiveId = this.liveId;
  983. if (!currentLiveId) return;
  984. try {
  985. const res = await liveOrderUser(currentLiveId);
  986. if (res.code === 200) {
  987. // 绑定到当前 liveItem
  988. const currentLive = this.list[this.currentSwiperIndex];
  989. if (currentLive) {
  990. this.$set(currentLive, 'orderUser', res);
  991. this.orderUser = res; // 同步全局变量
  992. }
  993. }
  994. } catch (error) {
  995. console.error('获取正在购买用户失败:', error);
  996. }
  997. },
  998. // 获取直播间信息接口
  999. getLiveinformation() {
  1000. if (!this.liveId) return;
  1001. getLiveInfo(this.liveId).then(res => {
  1002. if (res.code == 200) {
  1003. console.log("获取直播间信息接口>>>>", res)
  1004. this.livingUrl = res.livingUrl
  1005. } else {
  1006. uni.showToast({
  1007. title: res.msg,
  1008. icon: 'none'
  1009. });
  1010. }
  1011. },
  1012. rej => {}
  1013. );
  1014. },
  1015. // 修改点赞方法
  1016. async onLike(liveItem) {
  1017. if (!liveItem || !liveItem.liveId) return;
  1018. try {
  1019. const res = await liveDataLike(liveItem.liveId);
  1020. if (res.code === 200 && liveItem.liveViewData) {
  1021. liveItem.liveViewData.like++; // 只更新当前直播间的点赞数
  1022. }
  1023. } catch (error) {
  1024. console.error('点赞失败:', error);
  1025. }
  1026. },
  1027. // 去购买,跳商品详情
  1028. goShop(productId, goodsId) {
  1029. uni.navigateTo({
  1030. url: '/pages_shop/goods?productId=' + productId + '&liveId=' + this.liveId + '&goodsId=' +
  1031. goodsId + '&storeId=' + this.storeId
  1032. })
  1033. },
  1034. // 查询店铺
  1035. async queryCollect() {
  1036. const currentLive = this.list[this.currentSwiperIndex];
  1037. if (!currentLive || !currentLive.liveId) return;
  1038. const {
  1039. storeId
  1040. } = currentLive;
  1041. if (!storeId) return;
  1042. try {
  1043. const res = await store(currentLive.storeId, currentLive.inputInfo);
  1044. if (res.code === 200) {
  1045. // 数据绑定到当前 liveItem,避免全局污染
  1046. this.$set(currentLive, 'products', res.data.goodsList);
  1047. this.$set(currentLive, 'store', res.data);
  1048. // 同步更新全局变量(供弹窗使用)
  1049. this.products = res.data.goodsList;
  1050. this.store = res.data;
  1051. }
  1052. } catch (error) {
  1053. console.error('获取小黄车商品失败:', error);
  1054. }
  1055. },
  1056. // 店铺收藏
  1057. onStoreCollect() {
  1058. if (!this.storeId) return;
  1059. collectStore(this.storeId).then(res => {
  1060. if (res.code == 200) {
  1061. uni.showToast({
  1062. title: res.msg,
  1063. icon: 'none'
  1064. });
  1065. this.store.isFavorite = !this.store.isFavorite
  1066. } else {
  1067. uni.showToast({
  1068. title: res.msg,
  1069. icon: 'none'
  1070. });
  1071. }
  1072. },
  1073. rej => {}
  1074. );
  1075. },
  1076. // 商品收藏
  1077. onGoodsCollect(item) {
  1078. if (!item || item.length === 0 || !item.goodsId) {
  1079. return;
  1080. }
  1081. collectGoods(item.goodsId).then(res => {
  1082. if (res.code == 200) {
  1083. uni.showToast({
  1084. title: res.msg,
  1085. icon: 'none'
  1086. });
  1087. item.isFavorite = !item.isFavorite
  1088. } else {
  1089. uni.showToast({
  1090. title: res.msg,
  1091. icon: 'none'
  1092. });
  1093. }
  1094. },
  1095. rej => {}
  1096. );
  1097. },
  1098. // 关注
  1099. async onFollow(liveItem) {
  1100. if (!liveItem || !liveItem.liveId) return;
  1101. try {
  1102. const res = await follow(liveItem.liveId);
  1103. liveItem.isFollow = !liveItem.isFollow;
  1104. uni.showToast({
  1105. title: res.msg,
  1106. icon: 'none'
  1107. });
  1108. } catch (error) {
  1109. console.error("关注操作失败:", error);
  1110. }
  1111. },
  1112. // 时间戳
  1113. initTime() {
  1114. const now = new Date();
  1115. this.timestamp = now.getTime(); // 例如:'2023-04-01 12:00:00'
  1116. },
  1117. // initWebSocket() {
  1118. // const liveWS = new LiveWS('ws://your-server.com', 123, 456);
  1119. // // 从 URL 中解析 timestamp
  1120. // const urlParams = new URL(liveWS.url).searchParams;
  1121. // this.timestamp = urlParams.get('timestamp');
  1122. // // console.log('Timestamp:', timestamp);
  1123. // },
  1124. // 弹幕滚动
  1125. lowerChat: function(e) {
  1126. console.log(e)
  1127. },
  1128. scroll: function(e) {
  1129. console.log(e)
  1130. this.old.scrollTop = e.detail.scrollTop
  1131. },
  1132. loadmore() {
  1133. // for (let i = 0; i < 30; i++) {
  1134. // this.indexList.push({
  1135. // url: this.shopList[uni.$u.random(0, this.shopList.length - 1)],
  1136. // });
  1137. // }
  1138. },
  1139. openShop() {
  1140. },
  1141. openViews() {
  1142. this.$nextTick(() => {
  1143. const query = uni.createSelectorQuery().in(this);
  1144. query.select('.view-box').boundingClientRect(data => {
  1145. if (data) {
  1146. this.scrollHeight = data.height - 80 - 120;
  1147. }
  1148. }).exec();
  1149. });
  1150. },
  1151. close() {
  1152. this.showadd = !this.showadd
  1153. },
  1154. closes() {
  1155. this.showziliao = !this.showziliao
  1156. },
  1157. closest() {
  1158. this.showAnswer = !this.showAnswer
  1159. },
  1160. closestred() {
  1161. this.showAnswerred = !this.showAnswerred
  1162. },
  1163. closeanswer() {
  1164. this.answerbtn = !this.answerbtn
  1165. },
  1166. // 关闭小黄车
  1167. closeShop() {
  1168. this.shopping = !this.shopping
  1169. },
  1170. // 关闭红包
  1171. closeRed() {
  1172. this.showRed = !this.showRed
  1173. },
  1174. // 触摸结束
  1175. handleTouchEnd() {
  1176. this.isZoom = false; // 恢复原状
  1177. },
  1178. getEWechatSdk() {
  1179. // 只在H5平台执行
  1180. // #ifdef H5
  1181. let eWechatSdk = '';
  1182. if (/(Android)/i.test(navigator.userAgent)) {
  1183. eWechatSdk = 'jWeixin';
  1184. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  1185. eWechatSdk = 'wx';
  1186. } else {
  1187. eWechatSdk = 'jWeixin';
  1188. }
  1189. uni.setStorageSync("wxSdk", eWechatSdk);
  1190. // #endif
  1191. },
  1192. // 修改关闭WebSocket方法
  1193. closeWebSocket(liveId = null) {
  1194. this.isManualClose = true;
  1195. // 清除所有定时器
  1196. clearInterval(this.pingpangTimes);
  1197. clearInterval(this.reconnectTimer);
  1198. // 关闭指定或所有WebSocket连接
  1199. if (liveId) {
  1200. // 关闭指定直播间的连接
  1201. if (this.socketInstances[liveId]) {
  1202. try {
  1203. uni.closeSocket({
  1204. instance: this.socketInstances[liveId]
  1205. });
  1206. console.log(`直播间 ${liveId} WebSocket 已安全关闭`);
  1207. } catch (e) {
  1208. console.error('关闭 WebSocket 时出错:', e);
  1209. }
  1210. delete this.socketInstances[liveId];
  1211. }
  1212. } else {
  1213. // 关闭所有连接
  1214. Object.keys(this.socketInstances).forEach(liveId => {
  1215. try {
  1216. uni.closeSocket({
  1217. instance: this.socketInstances[liveId]
  1218. });
  1219. console.log(`直播间 ${liveId} WebSocket 已安全关闭`);
  1220. } catch (e) {
  1221. console.error('关闭 WebSocket 时出错:', e);
  1222. }
  1223. });
  1224. this.socketInstances = {};
  1225. }
  1226. isSocketOpen = false;
  1227. },
  1228. reConnect() {
  1229. var that = this;
  1230. try {
  1231. uni.closeSocket();
  1232. } catch (e) {
  1233. }
  1234. setTimeout(function() {
  1235. that.initSocket();
  1236. }, 10000);
  1237. },
  1238. startHeartbeat() {
  1239. clearInterval(this.pingpangTimes);
  1240. this.pingpangTimes = setInterval(() => {
  1241. if (!isSocketOpen) return;
  1242. const pingData = {
  1243. cmd: 'ping',
  1244. timestamp: Date.now()
  1245. };
  1246. uni.sendSocketMessage({
  1247. data: JSON.stringify(pingData),
  1248. success: () => console.debug('心跳发送成功'),
  1249. fail: (err) => {
  1250. console.error('心跳发送失败:', err);
  1251. this.scheduleReconnect();
  1252. }
  1253. });
  1254. }, 30000); // 30秒心跳间隔
  1255. },
  1256. initSocket() {
  1257. console.log(this.liveId);
  1258. // 如果没有指定直播间,不初始化
  1259. if ( !this.liveId) return;
  1260. const liveId = this.liveId;
  1261. // 检查是否是当前活跃的直播间
  1262. if (this.currentSwiperIndex !== this.list.findIndex(item => item.liveId === liveId)) {
  1263. console.log(`不初始化非当前直播间 ${liveId} 的WebSocket`);
  1264. return;
  1265. }
  1266. // 关闭之前的连接(如果存在)
  1267. if (this.socketInstances[liveId]) {
  1268. this.closeWebSocket(liveId);
  1269. }
  1270. // 防止重复创建
  1271. if (this.socketInstances[liveId]?.isOpen || this.reconnectCount >= this
  1272. .maxReconnectAttempts) {
  1273. return;
  1274. }
  1275. this.isManualClose = false;
  1276. console.log(this.timestamp)
  1277. // 生成签名
  1278. const signature = CryptoJS.HmacSHA256(
  1279. `${liveId}${this.userinfo.userId}${this.userType}${this.timestamp}`,
  1280. this.timestamp.toString()
  1281. ).toString(CryptoJS.enc.Hex);
  1282. // 初始化实例状态
  1283. this.socketInstances[liveId] = {
  1284. instance: null,
  1285. isOpen: false
  1286. };
  1287. try {
  1288. const socketTask = uni.connectSocket({
  1289. url: `${wsUrl}?userId=${this.userinfo.userId}&liveId=${liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`,
  1290. success: () => {
  1291. console.log('WebSocket API 调用成功,正在建立连接...');
  1292. },
  1293. fail: (err) => {
  1294. console.error('WebSocket 连接失败:', err);
  1295. this.scheduleReconnect(liveId);
  1296. }
  1297. });
  1298. socketTask.onOpen((res) => {
  1299. console.log('WebSocket 连接已成功建立', res);
  1300. this.socketInstances[liveId].instance = socketTask;
  1301. this.socketInstances[liveId].isOpen = true;
  1302. })
  1303. socketTask.onMessage((res)=>{
  1304. // 找到对应的直播间并更新数据
  1305. const targetLive = this.list.find(item => item.liveId === liveId);
  1306. this.handleSocketMessage(res, targetLive)
  1307. })
  1308. } catch (e) {
  1309. console.error('创建 WebSocket 异常:', e);
  1310. this.scheduleReconnect(liveId);
  1311. }
  1312. },
  1313. // 处理Socket消息
  1314. handleSocketMessage(message, liveItem) {
  1315. console.log("开始监听处理消息")
  1316. if(message.cmd == 'sendMsg'){
  1317. }
  1318. else if (message.cmd == 'red') {
  1319. // 领红包
  1320. liveItem.redInfo = JSON.parse(message.data);
  1321. } else if (message.cmd == 'sendRedPacketQuestion') {
  1322. const list = JSON.parse(message.data);
  1323. // 处理红包答题逻辑
  1324. } else if (message.cmd == 'entry') {
  1325. liveItem.showWelcomeMessage = true;
  1326. setTimeout(() => {
  1327. liveItem.showWelcomeMessage = false;
  1328. }, 1000);
  1329. } else if (message.cmd == 'live_start') {
  1330. // 直播开始
  1331. } else if (message.cmd == 'live_end') {
  1332. // 直播结束
  1333. } else if (message.cmd == 'deleteId') {
  1334. uni.$emit('deleteId');
  1335. } else if (message.cmd == 'sendRedPacketQuestion') {
  1336. const list = JSON.parse(message.data)
  1337. liveItem.redanswerAll = [...liveItem.redanswerAll, ...list]
  1338. if (liveItem.redanswerAll[1].randomAmount !== null) {
  1339. liveItem.redanswertips = JSON.parse(liveItem.redanswerAll[0]
  1340. .randomAmount)
  1341. }
  1342. }
  1343. },
  1344. scheduleReconnect() {
  1345. if (this.isManualClose || this.reconnectCount >= this.maxReconnectAttempts) return;
  1346. this.reconnectCount++;
  1347. const delay = Math.min(3000 * this.reconnectCount, 30000);
  1348. console.log(`将在 ${delay}ms 后重连 (尝试 ${this.reconnectCount}/${this.maxReconnectAttempts})`);
  1349. this.reconnectTimer = setInterval(() => {
  1350. this.initSocket();
  1351. }, delay);
  1352. },
  1353. sendMsg(liveItem) {
  1354. console.log("sendMsg")
  1355. if (!liveItem || !liveItem.liveId) return;
  1356. const liveId = liveItem.liveId;
  1357. const socketItem = this.socketInstances[liveId];
  1358. // 检查连接是否存在且已打开
  1359. if (!socketItem || !socketItem.instance || !socketItem.isOpen) {
  1360. // 尝试重新连接
  1361. this.initSocket(liveItem);
  1362. // 显示提示并延迟重试
  1363. uni.showToast({
  1364. title: "连接未建立,正在重试...",
  1365. icon: 'none'
  1366. });
  1367. return;
  1368. }
  1369. const data = {
  1370. liveId: liveId,
  1371. userId: this.userinfo.userId,
  1372. userType: 0,
  1373. cmd: "sendMsg",
  1374. msg: liveItem.value,
  1375. nickName: this.userinfo.nickName,
  1376. avatar: this.userinfo.avatar
  1377. };
  1378. if (!liveItem.value.trim()) {
  1379. console.log(!this.value.trim())
  1380. if (!this.value.trim()) { // 优化空消息判断
  1381. uni.showToast({
  1382. title: "不能发送空消息",
  1383. icon: 'none'
  1384. });
  1385. return;
  1386. }}
  1387. socketItem.instance.send({
  1388. data: JSON.stringify(data),
  1389. success: () => {
  1390. console.log("发送成功");
  1391. liveItem.value = ''; // 清空当前直播间的输入框
  1392. },
  1393. fail: (err) => {
  1394. console.error("发送失败:", err);
  1395. uni.showToast({
  1396. title: "发送失败,请重试",
  1397. icon: 'none'
  1398. });
  1399. }
  1400. });
  1401. },
  1402. }
  1403. };
  1404. </script>
  1405. <style scoped lang="scss">
  1406. .swiper-wrapper {
  1407. position: relative;
  1408. width: 100%;
  1409. height: 100vh;
  1410. overflow: hidden;
  1411. background-color: #000000;
  1412. }
  1413. .swiper-container {
  1414. width: 100%;
  1415. height: 100vh;
  1416. }
  1417. .container {
  1418. width: 100%;
  1419. height: 100%;
  1420. position: relative;
  1421. // 添加渐变过渡效果
  1422. transition: opacity 0.3s ease;
  1423. &.active {
  1424. opacity: 1;
  1425. }
  1426. // 非活动项半透明显示
  1427. // &:not(.active) {
  1428. // opacity: 0.7;
  1429. // }
  1430. }
  1431. .loading-tip {
  1432. position: absolute;
  1433. top: 50%;
  1434. left: 50%;
  1435. transform: translate(-50%, -50%);
  1436. display: flex;
  1437. flex-direction: column;
  1438. align-items: center;
  1439. justify-content: center;
  1440. z-index: 10;
  1441. .loading-text {
  1442. color: #ffffff;
  1443. font-size: 28rpx;
  1444. margin-top: 20rpx;
  1445. }
  1446. }
  1447. .loading-more,
  1448. .no-more {
  1449. display: flex;
  1450. justify-content: center;
  1451. align-items: center;
  1452. padding: 20rpx 0;
  1453. color: #999;
  1454. font-size: 24rpx;
  1455. }
  1456. .loading-more {
  1457. flex-direction: column;
  1458. }
  1459. .preload-indicator {
  1460. position: absolute;
  1461. top: 50%;
  1462. right: 30rpx;
  1463. transform: translateY(-50%);
  1464. z-index: 100;
  1465. background: rgba(0, 0, 0, 0.5);
  1466. border-radius: 50%;
  1467. padding: 16rpx;
  1468. }
  1469. /* button自带样式清除 */
  1470. .student-orther-icon button::after {
  1471. border: none !important;
  1472. padding: 0 !important;
  1473. margin: 0 !important;
  1474. }
  1475. .student-orther-icon button {
  1476. background-color: transparent !important;
  1477. padding: 0 !important;
  1478. line-height: inherit !important;
  1479. margin: 0 !important;
  1480. width: auto !important;
  1481. font-weight: 500 !important;
  1482. border-radius: none !important;
  1483. }
  1484. .welcome-message {
  1485. position: fixed;
  1486. width: 100%;
  1487. bottom: 460rpx;
  1488. left: 50%;
  1489. transform: translateX(-50%);
  1490. color: white;
  1491. padding: 10px 20px;
  1492. border-radius: 20px;
  1493. animation: fadeOut 1s ease 1s forwards;
  1494. z-index: 1000;
  1495. }
  1496. @keyframes fadeOut {
  1497. from {
  1498. opacity: 1;
  1499. }
  1500. to {
  1501. opacity: 0;
  1502. }
  1503. }
  1504. // .container {
  1505. // position: relative;
  1506. // width: 100%;
  1507. // height: 100vh;
  1508. // overflow: hidden;
  1509. // }
  1510. // .talktext {
  1511. // border-radius: 8rpx;
  1512. // background-color: rgba(255, 255, 255, 0.1);
  1513. // view {
  1514. // width: 100%;
  1515. // }
  1516. // }
  1517. .talk-list {
  1518. border-radius: 30rpx;
  1519. background-color: rgba(33, 33, 33, 0.5);
  1520. padding: 10rpx 30rpx;
  1521. }
  1522. // .zoom-button-active {
  1523. // transform: scale(1.5);
  1524. // }
  1525. // .background-image {
  1526. // position: absolute;
  1527. // top: 0;
  1528. // left: -40rpx;
  1529. // width: 110%;
  1530. // height: 110%;
  1531. // object-fit: cover;
  1532. // filter: blur(20px);
  1533. // z-index: 0;
  1534. // }
  1535. // .background-images {
  1536. // position: absolute;
  1537. // top: 0;
  1538. // left: -40rpx;
  1539. // width: 110%;
  1540. // height: 110%;
  1541. // object-fit: cover;
  1542. // filter: blur(20px);
  1543. // z-index: 6;
  1544. // }
  1545. // .blackbg {
  1546. // position: absolute;
  1547. // top: 0;
  1548. // left: 0;
  1549. // width: 100%;
  1550. // height: 100%;
  1551. // background: rgba(0, 0, 0, 0.7);
  1552. // object-fit: cover;
  1553. // filter: blur(10px);
  1554. // z-index: 1;
  1555. // }
  1556. .content {
  1557. position: relative;
  1558. z-index: 2;
  1559. height: 100%;
  1560. width: 100%;
  1561. top: 0;
  1562. left: 0;
  1563. display: flex;
  1564. flex-direction: column;
  1565. justify-content: space-between;
  1566. .content-top {
  1567. width: 100%;
  1568. margin-top: 150rpx;
  1569. display: flex;
  1570. align-items: center;
  1571. justify-content: space-between;
  1572. padding: 0 24rpx;
  1573. box-sizing: border-box;
  1574. .sum {
  1575. width: 80rpx;
  1576. height: 52rpx;
  1577. background: rgba(0, 0, 0, 0.5);
  1578. border-radius: 26rpx 26rpx 26rpx 26rpx;
  1579. font-size: 24rpx;
  1580. color: #FFFFFF;
  1581. text-align: center;
  1582. line-height: 52rpx;
  1583. }
  1584. }
  1585. .follow-btn {
  1586. padding: 8rpx 16rpx;
  1587. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1588. border-radius: 26rpx;
  1589. font-weight: 500;
  1590. font-size: 26rpx;
  1591. color: #FFFFFF;
  1592. }
  1593. }
  1594. .videolist {
  1595. position: relative;
  1596. }
  1597. .video {
  1598. height: 100vh;
  1599. /* 占屏幕高度的80% */
  1600. width: 100%;
  1601. background-color: rgba(57, 57, 57, 0.4);
  1602. }
  1603. .videotop {
  1604. width: 100%;
  1605. height: 100%;
  1606. }
  1607. .video_row {
  1608. width: 100%;
  1609. max-height: 500rpx;
  1610. overflow: hidden;
  1611. margin-top: 360rpx;
  1612. }
  1613. .popup-video {
  1614. position: absolute;
  1615. top: 30%;
  1616. height: 500rpx;
  1617. display: flex;
  1618. flex-direction: column;
  1619. align-items: center;
  1620. justify-content: center;
  1621. width: 100%;
  1622. color: #fff;
  1623. z-index: 9;
  1624. .more {
  1625. background-color: #3280fe;
  1626. border-radius: 80rpx;
  1627. width: 280rpx;
  1628. text-align: center;
  1629. height: 60rpx;
  1630. line-height: 60rpx;
  1631. }
  1632. }
  1633. .icon-bg {
  1634. background-color: rgba(157, 157, 157, 0.8);
  1635. border-radius: 50%;
  1636. width: 72rpx;
  1637. height: 72rpx;
  1638. display: flex;
  1639. justify-content: center;
  1640. align-items: center;
  1641. transition: transform 0.2s ease;
  1642. }
  1643. .list {
  1644. width: 80%;
  1645. margin-bottom: 20rpx;
  1646. animation: xxxawdawd .2s;
  1647. }
  1648. @keyframes xxxawdawd {
  1649. from {
  1650. margin-top: 0rpx;
  1651. opacity: 0;
  1652. }
  1653. to {
  1654. margin-top: 20rpx;
  1655. opacity: 1;
  1656. }
  1657. }
  1658. .shop-prompt {
  1659. position: absolute;
  1660. bottom: 600rpx;
  1661. left: 24rpx;
  1662. padding: 6rpx 20rpx;
  1663. background: rgba(230, 154, 34, 0.7);
  1664. border-radius: 24rpx;
  1665. z-index: 9;
  1666. font-weight: 500;
  1667. font-size: 26rpx;
  1668. color: #FFFFFF;
  1669. transition: opacity 0.3s ease;
  1670. }
  1671. .siderow-group {
  1672. position: absolute;
  1673. top: 56%;
  1674. right: 50rpx;
  1675. z-index: 9;
  1676. display: flex;
  1677. flex-direction: column;
  1678. align-items: center;
  1679. .side-item {
  1680. font-weight: 500;
  1681. font-size: 24rpx;
  1682. color: #FFFFFF;
  1683. margin-bottom: 32rpx;
  1684. text-align: center;
  1685. button {
  1686. background-color: transparent;
  1687. margin: 0;
  1688. line-height: 1;
  1689. padding: 0;
  1690. }
  1691. image {
  1692. width: 72rpx;
  1693. height: 72rpx;
  1694. }
  1695. }
  1696. }
  1697. .side-group {
  1698. position: absolute;
  1699. // top: 30%;
  1700. top: 56%;
  1701. right: 50rpx;
  1702. z-index: 9;
  1703. display: flex;
  1704. flex-direction: column;
  1705. align-items: center;
  1706. .side-item {
  1707. font-weight: 500;
  1708. font-size: 24rpx;
  1709. color: #FFFFFF;
  1710. margin-bottom: 32rpx;
  1711. text-align: center;
  1712. button {
  1713. background-color: transparent;
  1714. margin: 0;
  1715. line-height: 1;
  1716. padding: 0;
  1717. }
  1718. image {
  1719. width: 72rpx;
  1720. height: 72rpx;
  1721. }
  1722. }
  1723. }
  1724. .red-box {
  1725. .button {
  1726. margin: 0 auto;
  1727. width: 80%;
  1728. line-height: 88rpx;
  1729. height: 88rpx;
  1730. background: linear-gradient(90deg, #FF5701 0%, #FFB501 100%);
  1731. box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(238, 124, 80, 0.2);
  1732. border-radius: 44rpx 44rpx 44rpx 44rpx;
  1733. font-weight: 600;
  1734. font-size: 32rpx;
  1735. color: #FFFFFF;
  1736. text-align: center;
  1737. }
  1738. }
  1739. .view-box {
  1740. position: relative;
  1741. height: 40vh;
  1742. /* 设置弹出层高度为视窗高度的70% */
  1743. padding: 40rpx 0rpx 120rpx;
  1744. box-sizing: border-box;
  1745. display: flex;
  1746. flex-direction: column;
  1747. .scroll-content {
  1748. flex: 1;
  1749. overflow-y: auto;
  1750. padding: 0 40rpx;
  1751. }
  1752. .bottom {
  1753. padding: 20rpx 40rpx;
  1754. position: absolute;
  1755. bottom: 0;
  1756. width: 100%;
  1757. box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(195, 195, 195, 0.3);
  1758. background: #fff;
  1759. }
  1760. }
  1761. .shoppop {
  1762. padding: 22rpx 16rpx;
  1763. .shoppop-top {
  1764. display: flex;
  1765. justify-content: space-between;
  1766. align-items: center;
  1767. padding: 0 16rpx 22rpx;
  1768. .search-input {
  1769. width: 414rpx;
  1770. height: 76rpx;
  1771. background: #FFFFFF;
  1772. border-radius: 36rpx;
  1773. margin-left: 20rpx;
  1774. padding: 0 32rpx;
  1775. box-sizing: border-box;
  1776. font-size: 24rpx;
  1777. margin-right: 24rpx;
  1778. }
  1779. .search-top {
  1780. font-size: 18rpx;
  1781. color: #222222;
  1782. }
  1783. }
  1784. .shop-list {
  1785. overflow: hidden;
  1786. .list-item {
  1787. display: flex;
  1788. align-items: center;
  1789. padding: 20rpx 16rpx;
  1790. background: #FFFFFF;
  1791. border-radius: 16rpx;
  1792. margin-bottom: 16rpx;
  1793. .goods-img {
  1794. width: 200rpx;
  1795. height: 200rpx;
  1796. border-radius: 16rpx;
  1797. overflow: hidden;
  1798. position: relative;
  1799. margin-right: 24rpx;
  1800. image {
  1801. width: 100%;
  1802. height: 100%;
  1803. }
  1804. .goods-label {
  1805. position: absolute;
  1806. top: 0;
  1807. width: 64rpx;
  1808. height: 40rpx;
  1809. background: rgba(0, 0, 0, 0.5);
  1810. border-radius: 16rpx 0rpx 16rpx 0rpx;
  1811. text-align: center;
  1812. font-weight: 500;
  1813. font-size: 28rpx;
  1814. color: #FFFFFF;
  1815. }
  1816. }
  1817. .goods-right {
  1818. flex: 1;
  1819. .goods-title {
  1820. font-weight: 500;
  1821. font-size: 28rpx;
  1822. color: #000000;
  1823. }
  1824. .goods-details {
  1825. font-size: 24rpx;
  1826. color: #999999;
  1827. margin: 10rpx 0 20rpx;
  1828. }
  1829. .goods-people {
  1830. font-size: 22rpx;
  1831. color: #E69A22;
  1832. height: 56rpx;
  1833. }
  1834. .goods-shop {
  1835. display: flex;
  1836. justify-content: space-between;
  1837. .nummber {
  1838. color: #FF5C03;
  1839. font-size: 22rpx;
  1840. font-weight: 500;
  1841. }
  1842. .btn-group {
  1843. text-align: center;
  1844. line-height: 56rpx;
  1845. .collect-btn {
  1846. width: 72rpx;
  1847. background: #F5F7FA;
  1848. border-radius: 8rpx 0rpx 0rpx 8rpx;
  1849. }
  1850. .shop-btn {
  1851. width: 152rpx;
  1852. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1853. border-radius: 0rpx 8rpx 8rpx 0rpx;
  1854. font-weight: 500;
  1855. font-size: 26rpx;
  1856. color: #FFFFFF;
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. :deep(.u-list-item) {
  1865. width: 100%;
  1866. display: flex;
  1867. align-items: center;
  1868. }
  1869. :deep(.u-safe-area-inset-bottom) {
  1870. padding-bottom: 0
  1871. }
  1872. </style>