living3.vue 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603
  1. <template>
  2. <view class="swiper-wrapper">
  3. <swiper class="swiper-container" :current="currentSwiperIndex" :circular="false" vertical
  4. @change="onSwiperChange" :style="{height: '100vh'}" :duration="swiperDuration" :lazy-load="true"
  5. :display-multiple-items="1">
  6. <swiper-item v-for="(liveItem, index) in list" :key="liveItem.liveId">
  7. <view class="container" :class="{active: currentSwiperIndex === index}">
  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" class="w60 h64 mr26" src="/static/images/live/return.png">
  14. </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 ml10 mr6">
  19. <view>{{liveItem.liveName?truncateString(liveItem.liveName,8):"未命名"}}</view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="u-flex-end align-center" @click="toggleViewerList" style="margin-top: 100rpx;">
  24. <image v-if="Array.isArray(filteredViewers)" class="w52 h52 mr4"
  25. v-for="(item,viewerIndex) in filteredViewers" :key="viewerIndex"
  26. style="border-radius: 26rpx;" :src="item.avatar||$img.logo">
  27. </image>
  28. <view class="sum">{{liveUserTotal||0}}</view>
  29. </view>
  30. </view>
  31. <!-- 右边的 -->
  32. <view :class=" liveItem.showType==1 ? 'siderow-group' : 'side-group'">
  33. <view class="side-item">
  34. <image class="image" @click="onLike(liveItem)" src="/static/images/like.png">
  35. </image>
  36. <view>{{liveItem.liveViewData?.like||0}}</view>
  37. </view>
  38. <!-- <view class="side-item">
  39. <image @click="goStore(liveItem)" src="/static/images/live/shop.png"></image>
  40. <view>店铺</view>
  41. </view> -->
  42. <view class="side-item">
  43. <button open-type="share" class="button">
  44. <image class="image" src="/static/images/share.png" mode="widthFix"></image>
  45. </button>
  46. <view>分享</view>
  47. </view>
  48. </view>
  49. <!-- 红包内容 -->
  50. <view class="activity-box">
  51. <!-- v-if="liveItem.redInfo?.redStatus==1&&isShowRed" -->
  52. <view class="item-box">
  53. <view class="u-flex-y-center">
  54. <view class="tip">领红包</view>
  55. <view class="item">
  56. <image class="w70" @click="onRed(liveItem)" src="/static/images/redbag.png"
  57. mode="widthFix">
  58. </image>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- v-if="liveItem.redInfo?.lotteryStatus==1&&isShowLottery" -->
  63. <view class="item-box">
  64. <view class="u-flex-y-center">
  65. <view class="tip">抽奖</view>
  66. <view class="item">
  67. <image class="w60" @click="onLottery(liveItem)" src="/static/images/lottery.png"
  68. mode="widthFix">
  69. </image>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="shop-prompt f30 u-flex-y-center" v-if="showPurchasePrompt&&orderUser?.count">
  75. <image class="w32 h32 mr8" src="/static/images/live/shopping.png"></image>
  76. <text> {{orderUser.userName ? maskString(orderUser.userName) : ''}} 等
  77. {{orderUser.count || 0}}
  78. 人正在去购买</text>
  79. </view>
  80. <view class="videolist" style="margin: auto 0">
  81. <view class="video" style="height:100vh">
  82. <!-- 视频组件 -->
  83. <live-player v-if="currentSwiperIndex === index && liveItem.liveType === 1"
  84. :id="'myLivePlayer_' + liveItem.liveId"
  85. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.livingUrl"
  86. autoplay mode="live" object-fit="contain" :waiting="false" :muted="false"
  87. :orientation="liveItem.showType == 1 ? 'horizontal' : 'vertical'"
  88. @statechange="onLiveStateChange($event, liveItem)"
  89. @error="onLiveError($event, liveItem)" class="live-player"></live-player>
  90. <!-- <video v-if="currentSwiperIndex === index && liveItem.livingUrl"
  91. :id="'myVideo_' + liveItem.liveId"
  92. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.livingUrl"
  93. :controls='false' object-fit='contain' :custom-cache="false"
  94. :enable-progress-gesture="false" vslide-gesture-in-fullscreen='true'
  95. :show-center-play-btn="false" :http-cache="false" @error="videoError">
  96. </video> -->
  97. <video v-if="currentSwiperIndex === index && liveItem.liveType === 2"
  98. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.videoUrl"
  99. :autoplay="currentSwiperIndex === index" :controls='false' object-fit='contain'
  100. :custom-cache="false" :enable-progress-gesture="false"
  101. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"
  102. :http-cache="false" loop @error="videoError">
  103. </video>
  104. <view v-if="liveItem.videoUrl" class="time">{{liveItem.totalTime}}</view>
  105. </view>
  106. </view>
  107. <!-- 底部聊天区域 -->
  108. <view class="pb40 mt90" style="position: fixed;bottom: 120rpx;width: 100%;">
  109. <view class="w100 h300 mt20">
  110. <scroll-view enable-flex scroll-y="true" class="talk p20 scrolly flex-1 column"
  111. style="width: calc(100% - 40rpx);height: calc(100% - 40rpx);"
  112. :scroll-into-view="liveItem.scrollIntoView">
  113. <view>
  114. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  115. :key="talkIndex" v-show="item.cmd=='announcement'">
  116. <view class="talk-list ml16 justify-start">
  117. <view class="fs30">
  118. <text class='colorf'>
  119. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  120. </view>
  121. </view>
  122. </view>
  123. </view>
  124. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  125. :key="talkIndex" :id="`list_${talkIndex}`"
  126. v-show="item.cmd!='red'&&item.cmd!='out'&&item.cmd!='entry'">
  127. <view class="talk-list ml16 justify-start">
  128. <view class="fs30">
  129. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  130. <text class='colorf'>{{item.msg}}</text>
  131. </view>
  132. </view>
  133. </view>
  134. <view v-if="liveItem.showWelcomeMessage" class="welcome-message">
  135. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  136. :key="talkIndex" v-show="item.cmd=='entry'||item.cmd=='out'">
  137. <view class="talk-list ml16 justify-start">
  138. <view class="fs30">
  139. <text style="color: #ff89d6;">{{item.nickName}} </text>
  140. <text class='colorf'>
  141. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  142. </view>
  143. </view>
  144. </view>
  145. </view>
  146. </scroll-view>
  147. </view>
  148. <!-- 底部输入框和操作按钮 -->
  149. <view class="justify-between p24 input-box">
  150. <view class="u-flex-y-center w580"
  151. style="background:rgba(57, 57, 57, 1);padding:10rpx 14rpx 10rpx 32rpx;box-sizing:border-box;border-radius:36rpx;">
  152. <u-input :placeholder="liveItem.placeholderText" border="none"
  153. customStyle='font-size:24rpx;' v-model="liveItem.value" shape='circle'
  154. color='#fff' placeholderStyle='color:#e7e7e7' class="ml20">
  155. </u-input>
  156. <view class="send" @click="sendMsg(liveItem)">发送</view>
  157. </view>
  158. <view class="justify-between mr15 align-center">
  159. <view class="icon-bg ml20" @click="openCart(liveItem)">
  160. <image src="/static/images/shopping.png" class="w58 h58"></image>
  161. </view>
  162. </view>
  163. </view>
  164. </view>
  165. </view>
  166. <u-popup :show="liveItem.goodsCard?.isShow" @close="!liveItem.goodsCard?.isShow" round='20rpx'
  167. mode="center" bgColor='#ffffff'>
  168. <view class="goods">
  169. <view class="top">
  170. <view class="left">
  171. <image class="w30 h30 mr8" src="/static/images/signal.png"></image>讲解中
  172. </view>
  173. <image class="w30 h30" src="/static/images/close.png"
  174. @click="liveItem.goodsCard.isShow=false"></image>
  175. </view>
  176. <image class="photo" :src="liveItem.goodsCard?.imgUrl"></image>
  177. <view class="item">
  178. <view class="price"><text class="red">¥{{liveItem.goodsCard?.price}} </text><text
  179. class="del">¥{{liveItem.goodsCard?.otPrice}}</text></view>
  180. <view class="title oneline-hide">{{liveItem.goodsCard?.productName}}</view>
  181. <view class="button"
  182. @click="goShop(liveItem.goodsCard?.productId,liveItem.goodsCard?.goodsId)">立即抢购
  183. </view>
  184. </view>
  185. </view>
  186. </u-popup>
  187. <!-- 抽奖 -->
  188. <u-popup :show="isShowLotteryPop" @close="!isShowLotteryPop" round='40rpx'>
  189. <view class="prize-box" style="border-radius: 40rpx;height: fit-content;">
  190. <image class="nav-img " src="/static/images/red_head.png" mode="widthFix"></image>
  191. <image class="bg-img " src="/static/images/red_bg.png"></image>
  192. <view class="prize-content">
  193. <view class="u-flex-row-reverse u-flex mr20">
  194. <u-icon name="close" color="#fff" size="20"
  195. @click="isShowLotteryPop=false"></u-icon>
  196. </view>
  197. <view class="column align-center ">
  198. <image class="w446 h80" src="/static/images/red_title.png"></image>
  199. <view class="fs24 colorf u-flex-y-center mt30 mb30">
  200. 52人已参与,开奖倒计时
  201. <view class="white-item">14</view>:
  202. <view class="white-item">344</view>:
  203. <view class="white-item">44</view>
  204. </view>
  205. <!-- <view class="item-group">
  206. <view class="item" v-for="(item,index) in lotteryProducts" :key="index">
  207. <image class="w280 h280" :src="item.imgUrl"></image>
  208. <view v-show="true" class="title">{{item.prizeLevel}}等奖</view>
  209. <view v-show="true" class="txt">{{item.productName}}</view>
  210. </view>
  211. <view class="item center">
  212. <image class="w280 h280" src="/static/images/img.png"></image>
  213. <view v-show="true" class="title">二等奖</view>
  214. <view v-show="true" class="txt">新用户免费领礼品弹窗</view>
  215. </view>
  216. <view class="item">
  217. <image class="w280 h280" src="/static/images/img.png"></image>
  218. <view v-show="false" class="title">二等奖</view>
  219. <view v-show="false" class="txt">新用户免费领礼品弹窗</view>
  220. </view>
  221. </view>
  222. <view class="point-group" v-for="(item,index) in lotteryProducts" :key="index">
  223. <view class="item" v-if="item.length" :class="{ selected: activePointIndex === 0 }"
  224. @click="activePointIndex = 0"></view>
  225. <view class="item" :class="{ selected: activePointIndex === 1 }"
  226. @click="() => { activePointIndex = 1; scrollToCenterItem() }"></view>
  227. <view class="item" :class="{ selected: activePointIndex === 2 }"
  228. @click="activePointIndex = 2"></view>
  229. </view> -->
  230. <swiper class="prize-swiper" :current="activePointIndex"
  231. @change="onPrizeSwiperChange" :circular="false" :duration="300"
  232. indicator-dots="false">
  233. <swiper-item v-for="(product, idx) in lotteryProducts" :key="idx">
  234. <view class="item" :class="{center: idx === 1}">
  235. <image class="w280 h280" :src="product.imgUrl"></image>
  236. <view class="title">{{product.prizeLevel}}等奖</view>
  237. <view class="txt">{{product.productName}}</view>
  238. </view>
  239. </swiper-item>
  240. </swiper>
  241. <view class="point-group" v-if="lotteryProducts.length > 0">
  242. <view class="item" v-for="(_, idx) in lotteryProducts" :key="idx"
  243. :class="{ selected: activePointIndex === idx }"
  244. @click="activePointIndex = idx"></view>
  245. </view>
  246. <view class="colorf fs28">
  247. 观看直播参与抽奖
  248. </view>
  249. <view class="button" @click="">参与抽奖</view>
  250. </view>
  251. </view>
  252. </view>
  253. </u-popup>
  254. <u-popup :show="liveItem.integral?.status" @close="!liveItem.integral?.status" round='20rpx'
  255. mode="center" bgColor='#ffffff'>
  256. <view class="integral-box">
  257. <view class="top">
  258. <view class="title">观看视频领芳华币</view>
  259. <image class="photo" src="/static/images/integral.png" mode="widthFix"></image>
  260. </view>
  261. <view class="item">
  262. <view class="title ">{{liveItem.integral?.msg}}</view>
  263. <view class="button" @click="liveItem.integral.status=flase">确认</view>
  264. </view>
  265. </view>
  266. </u-popup>
  267. <!-- 观众列表弹窗 -->
  268. <u-popup :show="showadd" @close="close" @open="openViews" round='20rpx' bgColor='#ffffff'>
  269. <view class="view-box">
  270. <view class="t-c fs30">在线观众</view>
  271. <scroll-view scroll-y class="scroll-content" :style="{height: scrollHeight + 'px'}"
  272. @scrolltolower="handleScrollToLower">
  273. <view class="fs24 u-flex-y-center mb20" v-for="(item,index) in liveViewers"
  274. :key="index">
  275. <view
  276. :style="{color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',fontWeight: index < 3 ? 'bold' : 'normal',width: '50rpx'}"
  277. class="mr10">{{index+1}}</view>
  278. <u-avatar :src="item.avatar||$img.logo" size="32"></u-avatar>
  279. <text class="ml16">{{item.nickName||"未命名"}}</text>
  280. </view>
  281. <view class="no-more" v-if="viewNoMoreData && liveViewers.length > 0">
  282. <text>没有更多了</text>
  283. </view>
  284. </scroll-view>
  285. </view>
  286. </u-popup>
  287. <!-- 商品弹窗 -->
  288. <u-popup :show="liveItem.shopping" @close="closeShop" @open="openShop" round='20rpx'
  289. bgColor='f3f5f9'>
  290. <view class="shoppop">
  291. <view class="shoppop-top">
  292. <u-avatar :src="store.logoUrl" size="36" class="ml16"></u-avatar>
  293. <view class="search-input u-flex-y-center">
  294. <image class="w24 mr16" src="/static/images/search.png" mode="widthFix">
  295. </image>
  296. <input placeholder="请搜索商品" v-model="liveItem.inputInfo"
  297. @input="handleSearchInput" />
  298. </view>
  299. <view class="t-c search-top" @click="goOrderList(liveItem)">
  300. <image class="w48 h48" src="/static/images/order.png"></image>
  301. <view>订单</view>
  302. </view>
  303. </view>
  304. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  305. <view class="list-item" v-for="(item,index) in products" :key="index">
  306. <view class="goods-img">
  307. <image :src="item.imgUrl" mode="widthFix"></image>
  308. <view class="goods-label">{{index+1}}</view>
  309. </view>
  310. <view class="goods-right">
  311. <view class="goods-title">{{item.productName}}</view>
  312. <view class="goods-people">{{item.sales}} 人已购</view>
  313. <view class="goods-shop">
  314. <text class="nummber"><text
  315. style="font-size: 20rpx;font-weight: 600;">¥</text><text
  316. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}/日</text>
  317. <view class="btn-group u-flex-y-center">
  318. <view class="collect-btn">
  319. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  320. class="w36 h36" src="/static/images/collect_select.png">
  321. </image>
  322. <image v-else @click="onGoodsCollect(item)" class="w36 h36"
  323. src="/static/images/collect.png">
  324. </image>
  325. </view>
  326. <view v-if="item.status==1" class="shop-btn"
  327. @click="goShop(item.productId,item.goodsId)">去购买 </view>
  328. <view v-else-if="item.status==0" class="shop-btn">
  329. 已下架</view>
  330. </view>
  331. </view>
  332. </view>
  333. </view>
  334. </scroll-view>
  335. </view>
  336. </u-popup>
  337. </view>
  338. </swiper-item>
  339. </swiper>
  340. </view>
  341. </template>
  342. <script>
  343. import Hls from 'hls.js';
  344. import CryptoJS from 'crypto-js'
  345. import {
  346. liveList
  347. } from '@/api/list'
  348. import {
  349. liveLottery, // 抽奖查询
  350. liveRed, // 点击领红包
  351. liveDataLike, // 点赞
  352. collectStore, // 店铺收藏/取消收藏
  353. collectGoods, // 商品收藏/取消收藏
  354. // store, // 查询店铺
  355. // showGoods, //弹出商品卡片
  356. // follow, // 关注/取消关注
  357. watchUserList, //获取直播间用户(展示在线用户)
  358. liveMsg, //获取最近聊天记录
  359. // 小黄车
  360. liveStore, //店铺展示,
  361. // liveGoodsDetail, //商品详情,
  362. liveOrderUser, //正在购买
  363. getLiveInfo, //获取直播间信息接口
  364. getLiveViewData, //直播间点赞、关注、在线人数数据
  365. currentActivities //红包 卡片 抽奖
  366. } from '@/api/live'
  367. import {
  368. liveOrderList, // 订单列表
  369. } from '@/api/order'
  370. import parse from '/uni_modules/uview-plus/libs/config/props/parse';
  371. import {
  372. LiveWS
  373. } from '@/utils/liveWS.js'
  374. import {
  375. getlive,
  376. // gettextlist,
  377. getAnswerlist,
  378. submitAnswer
  379. } from '@/api/home'
  380. // var wsUrl = "wss://live.test.ylrztop.com/ws/live-api/app/webSocket"; //余红奇
  381. var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
  382. // var wsUrl = "ws://192.168.10.125:7114/app/webSocket"; //涂小龙
  383. // var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket"; //余红奇
  384. // var wsUrl = "ws://nd383294.natappfree.cc/app/webSocket"; //余红奇
  385. // var wsUrl = "ws://v56c9b8e.natappfree.cc/app/webSocket"; //余红奇
  386. // var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; //陈果
  387. // var wsUrl = "ws://live.ylrzcloud.com/socket/app/webSocket";
  388. var pingpangTimes = null;
  389. var initTimes = null;
  390. var isSocketOpen = false;
  391. var socket = null;
  392. export default {
  393. data() {
  394. return {
  395. lotteryProducts: [],
  396. activePointIndex: 0,
  397. lotteryTimer: null,
  398. redTimer: null,
  399. isShowLotteryPop: false,
  400. isShowLottery: false,
  401. isShowRed: false,
  402. // 新增:滑动节流相关变量
  403. lastSwiperChangeTime: 0, // 上次切换时间戳
  404. swiperChangeThrottle: 300, // 切换节流阈值(毫秒)
  405. lastClickTime: 0,
  406. clickDelay: 300, // 300ms内只响应一次点击
  407. connectingLiveId: null, // 记录正在连接的直播间ID
  408. swiperDuration: 0, // 初始化为0,首次加载无动画
  409. videoRetryCounts: {}, // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  410. socketInstances: {}, // 改为对象存储多个socket实例
  411. currentSwiperIndex: 0, // 当前swiper索引
  412. list: [], // 直播间列表
  413. // preloading: false, // 预加载状态
  414. liveUserTotal: null,
  415. viewPageSize: 10, // 每页数量
  416. viewPageNum: 1, // 当前页码
  417. viewLoading: false, // 是否正在加载
  418. viewNoMoreData: false, // 是否没有更多数据
  419. scrollHeight: 0,
  420. scrollTimer: null, // 滚动防抖定时器
  421. socketInstance: null, // 统一管理 socket 实例
  422. reconnectCount: 0,
  423. maxReconnectAttempts: 3,
  424. isManualClose: false, // 标记是否手动关闭
  425. showRed: true,
  426. searchTimer: null,
  427. reconnectTimer: null,
  428. isCollect: false,
  429. showPurchasePrompt: false,
  430. purchasePromptTimer: null,
  431. prevOrderCount: 0, // 用于记录上一次的购买人数
  432. videoUrl: null,
  433. showType: 1, //横屏1 竖屏2
  434. boxHeight: 300, //小黄车高度
  435. liveViewers: [], //观众
  436. likeName: 0,
  437. hlsPlayer: null, // HLS播放器实例,
  438. livingUrl: "",
  439. products: {},
  440. store: {},
  441. orderUser: {}, //正在购买
  442. userType: 0,
  443. timestamp: '',
  444. liveId: null,
  445. userinfo: '', //用户信息
  446. // path: 'http://192.168.10.166/dev-api', //余红奇
  447. // path: 'http://v56c9b8e.natappfree.cc', //余红奇
  448. // path: 'live.test.ylrztop.com/prod-api', //余红奇
  449. // value: '',
  450. talkdisabled: false, //输入框是否禁用
  451. autoplay: false, //视频自动播放
  452. showadd: false,
  453. scrollIntoView: '',
  454. videoContext: '',
  455. livedata: {}, //直播间点赞、关注、在线人数数据
  456. };
  457. },
  458. onLoad(options) {
  459. this.initTime();
  460. if (options.liveId) {
  461. this.liveId = options.liveId; // 仅当 liveId 变化时更新
  462. }
  463. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  464. // 初始化直播间列表
  465. this.initLiveList(options);
  466. // this.getliveUser(false); // 调用获取在线用户接口
  467. const platform = uni.getWindowInfo().platform;
  468. // 初始化直播间列表
  469. if (['mp-weixin', 'mp-alipay', 'mp-baidu', 'mp-toutiao'].includes(platform)) {
  470. // 确保 API 存在再调用
  471. if (uni.showShareMenu) {
  472. uni.showShareMenu({
  473. withShareTicket: true, // 可选参数,根据需求配置
  474. success: () => {
  475. console.log('分享菜单显示成功');
  476. },
  477. fail: (err) => {
  478. console.error('分享菜单显示失败:', err);
  479. }
  480. });
  481. } else {
  482. console.warn('当前平台不支持 uni.showShareMenu');
  483. }
  484. }
  485. this.getCurrentActivities(options.liveId);
  486. },
  487. onReady() {
  488. // 页面渲染完成后,默认让中间item居中
  489. this.$nextTick(() => {
  490. if (this.activePointIndex === 1) { // 默认选中第二个point
  491. this.scrollToCenterItem();
  492. }
  493. });
  494. },
  495. onShareAppMessage() {
  496. return {
  497. title: this.livedata.liveName,
  498. path: '/pages/home/living',
  499. imageUrl: this.products.image,
  500. success(res) {
  501. console.log("分享成功", res);
  502. },
  503. fail(err) {
  504. console.error("分享失败", err);
  505. }
  506. };
  507. },
  508. computed: {
  509. filteredViewers() {
  510. // 若 liveViewers 是 null/undefined/非数组,返回空数组
  511. if (!Array.isArray(this.liveViewers)) {
  512. return [];
  513. }
  514. return this.liveViewers.slice(0, 3);
  515. }
  516. },
  517. onHide() {
  518. const currentLive = this.list[this.currentSwiperIndex];
  519. if (currentLive) {
  520. this.pauseVideo(currentLive);
  521. this.clearTimeTimer(currentLive); // 隐藏时清除当前直播间定时器
  522. } // 隐藏时关闭所有连接
  523. this.closeAllWebSockets();
  524. },
  525. onUnload() {
  526. // 清除所有直播间的时间定时器
  527. this.list.forEach(liveItem => {
  528. this.clearTimeTimer(liveItem);
  529. });
  530. // 关闭所有WebSocket连接
  531. this.closeAllWebSockets();
  532. this.socketInstances = {}; // 强制清空实例对象
  533. // 移除所有全局事件监听
  534. this.removeAllEventListeners();
  535. // 清理定时器
  536. this.clearAllTimers();
  537. // 销毁HLS播放器(如果使用了hls.js)
  538. if (this.hlsPlayer) {
  539. this.hlsPlayer.destroy();
  540. this.hlsPlayer = null;
  541. }
  542. this.list.forEach(liveItem => {
  543. const videoId = `myVideo_${liveItem.liveId}`;
  544. const videoContext = uni.createVideoContext(videoId, this);
  545. if (videoContext) {
  546. videoContext.pause(); // 仅暂停视频即可
  547. }
  548. });
  549. // Object.values(this.tempState.redTimer).forEach(timer => clearInterval(timer));
  550. // Object.values(this.tempState.lotteryTimer).forEach(timer => clearInterval(timer));
  551. // Object.values(this.tempState.searchTimer).forEach(timer => clearTimeout(timer));
  552. // clearTimeout(this.tempState.scrollTimer);
  553. // 2. 关闭所有 WebSocket 连接
  554. this.closeAllWebSockets();
  555. // 3. 销毁视频上下文
  556. this.list.forEach(liveItem => {
  557. const videoCtx = uni.createVideoContext(`myVideo_${liveItem.liveId}`, this);
  558. if (videoCtx) videoCtx.destroy(); // 销毁视频上下文
  559. });
  560. // 4. 清空响应式数据
  561. this.list = [];
  562. this.socketInstances = {};
  563. },
  564. watch: {
  565. // 监听orderUser.count的变化
  566. 'orderUser.count': {
  567. handler(newVal, oldVal) {
  568. if (newVal !== this.prevOrderCount) {
  569. this.prevOrderCount = newVal;
  570. this.showPurchaseMessage();
  571. }
  572. },
  573. immediate: true
  574. }
  575. },
  576. methods: {
  577. onPrizeSwiperChange(e) {
  578. // 同步指示点与轮播当前索引
  579. this.activePointIndex = e.detail.current;
  580. },
  581. scrollToCenterItem() {
  582. this.$nextTick(() => { // 确保DOM渲染完成后再获取位置
  583. // 1. 获取父容器(item-group)的DOM信息
  584. const groupQuery = uni.createSelectorQuery().in(this);
  585. groupQuery.select('.item-group')
  586. .boundingClientRect(groupRect => {
  587. if (!groupRect) return; // 防止DOM未找到
  588. // 2. 获取中间item(索引为1的item)的DOM信息
  589. const itemQuery = uni.createSelectorQuery().in(this);
  590. itemQuery.selectAll('.item-group .item')
  591. .boundingClientRect(itemsRect => {
  592. if (!itemsRect || itemsRect.length < 3) return; // 确保有3个item
  593. const centerItemRect = itemsRect[1]; // 中间的item(索引1)
  594. const groupWidth = groupRect.width; // 父容器宽度
  595. const itemWidth = centerItemRect.width; // 单个item宽度
  596. const itemGap = 20; // item之间的间距(对应CSS中的gap:20rpx)
  597. // 3. 计算滚动距离:让中间item的中心点与父容器中心点对齐
  598. // 公式:滚动距离 = 中间item左侧距离 - (父容器宽度 - 中间item宽度)/2
  599. const scrollLeft = centerItemRect.left - (groupWidth - itemWidth - 2 *
  600. itemGap) / 2;
  601. // 4. 让父容器滚动到指定位置(平滑滚动)
  602. uni.createSelectorQuery().in(this)
  603. .select('.item-group')
  604. .node(node => {
  605. if (node) {
  606. node.scrollLeft = scrollLeft; // 直接设置滚动距离(如需平滑可加过渡)
  607. }
  608. })
  609. .exec();
  610. })
  611. .exec();
  612. })
  613. .exec();
  614. });
  615. },
  616. onLiveStateChange(e, liveItem) {
  617. // console.log('直播状态变化:', e.detail.code, e.detail);
  618. // 可以根据状态码处理不同的直播状态
  619. const stateCode = e.detail.code;
  620. // 2001: 已经连接服务器
  621. // 2002: 已经连接服务器,开始拉流
  622. // 2003: 网络接收到首个视频数据包(IDR)
  623. // 2004: 视频播放开始
  624. // 2005: 视频播放进度
  625. // 2006: 视频播放结束
  626. // 2007: 视频播放Loading
  627. // 2008: 解码器启动
  628. // -2301: 网络断连,且经多次重连抢救无效,更多重试请自行重启播放
  629. // -2302: 获取加速拉流地址失败
  630. }, // 直播错误事件
  631. onLiveError(e, liveItem) {
  632. this.videoError(e, liveItem);
  633. },
  634. // 红包 卡片 抽奖
  635. getCurrentActivities(liveItem) {
  636. if (!liveItem.liveId) return;
  637. // const res = currentActivities(liveId);
  638. currentActivities(liveItem.liveId).then(res => {
  639. if (res.code == 200) {
  640. // 商品卡片
  641. this.$set(liveItem, 'goodsCard', res.goods);
  642. // 红包
  643. this.$set(liveItem, 'redInfo', res.red[0]);
  644. this.isShowRed = true
  645. // 抽奖
  646. this.$set(liveItem, 'lotteryInfo', res.lottery[0]);
  647. } else {
  648. uni.showToast({
  649. title: res.msg,
  650. icon: 'none'
  651. });
  652. }
  653. },
  654. rej => {}
  655. );
  656. },
  657. // 计算当前时间与 liveItem.startTime 的差值,并更新 totalTime
  658. calculateTimeDiff(liveItem) {
  659. if (!liveItem.startTime) {
  660. liveItem.totalTime = '00小时00分钟00秒';
  661. return;
  662. }
  663. const iosCompatibleTime = liveItem.startTime
  664. .replace(/-/g, '/')
  665. .replace(' ', ' ');
  666. const startTime = new Date(liveItem.startTime);
  667. const now = new Date();
  668. if (isNaN(startTime.getTime())) {
  669. console.warn(`iOS 时间解析失败,原始时间:${liveItem.startTime},转换后:${iosCompatibleTime}`);
  670. liveItem.totalTime = '00小时00分钟00秒';
  671. return;
  672. }
  673. const diffMs = Math.max(0, now - startTime);
  674. const totalSeconds = Math.floor(diffMs / 1000);
  675. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  676. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  677. const seconds = this.padZero(totalSeconds % 60);
  678. this.$set(liveItem, 'totalTime', `${hours}:${minutes}:${seconds}`);
  679. },
  680. padZero(num) {
  681. return num < 10 ? `0${num}` : num;
  682. },
  683. // 启动当前直播间的时间差值定时器
  684. startTimeTimer(liveItem) {
  685. // 先清除当前直播间的旧定时器(避免重复)
  686. if (liveItem.timeTimer) {
  687. clearInterval(liveItem.timeTimer);
  688. }
  689. // 立即计算一次(避免等待1秒才显示)
  690. this.calculateTimeDiff(liveItem);
  691. // 每秒更新一次(实时刷新)
  692. liveItem.timeTimer = setInterval(() => {
  693. this.calculateTimeDiff(liveItem);
  694. }, 1000);
  695. },
  696. // 清除指定直播间的时间定时器
  697. clearTimeTimer(liveItem) {
  698. if (liveItem.timeTimer) {
  699. clearInterval(liveItem.timeTimer);
  700. liveItem.timeTimer = null; // 清空定时器标识
  701. }
  702. },
  703. toggleViewerList() {
  704. const now = Date.now()
  705. if (now - this.lastClickTime > this.clickDelay) {
  706. this.showadd = !this.showadd
  707. this.lastClickTime = now
  708. }
  709. },
  710. // 重置在线用户列表的分页参数
  711. resetUserListParams() {
  712. this.viewPageNum = 1; // 重置页码为第一页
  713. this.viewNoMoreData = false; // 重置“没有更多数据”状态
  714. this.liveViewers = []; // 清空现有列表
  715. },
  716. closeAllWebSockets() {
  717. this.isManualClose = true;
  718. // 关闭所有连接
  719. Object.keys(this.socketInstances).forEach(liveId => {
  720. try {
  721. if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
  722. this.socketInstances[liveId].instance.close({
  723. code: 1000,
  724. reason: '页面关闭'
  725. });
  726. console.log(`直播间 ${liveId} WebSocket 已关闭`);
  727. }
  728. } catch (e) {
  729. console.error(`关闭直播间 ${liveId} WebSocket 时出错:`, e);
  730. }
  731. });
  732. this.socketInstances = {};
  733. isSocketOpen = false;
  734. }, // 移除所有全局事件监听器
  735. removeAllEventListeners() {
  736. uni.$off('initSocket');
  737. uni.$off('sendMsg');
  738. uni.$off('closeWebSocket');
  739. uni.$off('refreshOrder');
  740. // 可以根据实际情况添加其他需要移除的事件
  741. }, // 清理所有定时器
  742. clearAllTimers() {
  743. if (this.intervalId) {
  744. clearInterval(this.intervalId);
  745. this.intervalId = null;
  746. }
  747. if (this.pingpangTimes) {
  748. clearInterval(this.pingpangTimes);
  749. this.pingpangTimes = null;
  750. }
  751. if (this.reconnectTimer) {
  752. clearInterval(this.reconnectTimer);
  753. this.reconnectTimer = null;
  754. }
  755. if (this.scrollTimer) {
  756. clearTimeout(this.scrollTimer);
  757. this.scrollTimer = null;
  758. }
  759. if (this.searchTimer) {
  760. clearTimeout(this.searchTimer);
  761. this.searchTimer = null;
  762. }
  763. if (this.purchasePromptTimer) {
  764. clearTimeout(this.purchasePromptTimer);
  765. this.purchasePromptTimer = null;
  766. }
  767. },
  768. // 初始化当前直播间数据
  769. async initCurrentLiveData() {
  770. const currentLive = this.list[this.currentSwiperIndex];
  771. if (!currentLive || !currentLive.liveId) {
  772. return;
  773. }
  774. // 设置加载状态
  775. currentLive.loading = true;
  776. try {
  777. // 先初始化WebSocket连接
  778. await this.initSocket(currentLive);
  779. // 然后并行加载其他数据
  780. await Promise.allSettled([
  781. this.getLiveMsg(currentLive),
  782. this.getCurrentActivities(currentLive),
  783. this.getliveViewData(currentLive),
  784. // this.getShowGoods(currentLive),
  785. this.getliving(currentLive)
  786. ]);
  787. currentLive.loaded = true;
  788. // 初始化完成后,启动当前直播间的时间差值定时器
  789. this.startTimeTimer(currentLive);
  790. } catch (error) {
  791. console.error("初始化直播间数据失败:", error);
  792. } finally {
  793. currentLive.loading = false;
  794. }
  795. },
  796. // 初始化直播间列表
  797. async initLiveList(options) {
  798. try {
  799. await this.getList(); // 先加载直播间列表
  800. if (this.list.length === 0) {
  801. console.error("直播间列表为空,无法初始化");
  802. return;
  803. }
  804. // 设置初始直播间索引(原逻辑保留)
  805. if (options.liveId) {
  806. const index = this.list.findIndex(item => item.liveId == options.liveId);
  807. this.currentSwiperIndex = index !== -1 ? index : 0;
  808. } else {
  809. this.currentSwiperIndex = 0;
  810. }
  811. // 延迟设置动画时间(原逻辑保留)
  812. setTimeout(() => {
  813. this.swiperDuration = 300;
  814. }, 100);
  815. // 获取当前直播间的liveItem
  816. const currentLive = this.list[this.currentSwiperIndex];
  817. if (currentLive) {
  818. this.liveId = currentLive.liveId;
  819. // 重置用户列表参数
  820. this.resetUserListParams();
  821. // 预加载相邻直播间(不初始化WebSocket)
  822. this.preloadNearbyLives(false);
  823. // 初始化当前直播间数据(包含WebSocket连接)
  824. await this.initCurrentLiveData();
  825. // // 获取在线用户
  826. // this.getliveUser(false);
  827. // 延迟播放视频
  828. setTimeout(() => {
  829. this.playVideo(currentLive);
  830. }, 500);
  831. }
  832. } catch (error) {
  833. console.error("初始化失败:", error);
  834. }
  835. },
  836. // Swiper切换事件
  837. async onSwiperChange(e) {
  838. const now = Date.now();
  839. const newIndex = e.detail.current;
  840. const oldIndex = this.currentSwiperIndex;
  841. // 相同索引或节流期间,不处理
  842. if (newIndex === oldIndex) return;
  843. if (now - this.lastSwiperChangeTime < this.swiperChangeThrottle) {
  844. console.log('Swiper切换过快,已节流');
  845. return;
  846. }
  847. // 更新最后切换时间
  848. this.lastSwiperChangeTime = now;
  849. // 1. 立即关闭旧直播间的WebSocket(同步操作)
  850. const oldLive = this.list[oldIndex];
  851. if (oldLive) {
  852. // 关闭旧Socket
  853. this.closeWebSocket(oldLive.liveId);
  854. // 清除旧心跳定时器
  855. clearInterval(this.pingpangTimes);
  856. this.pingpangTimes = null;
  857. }
  858. if (this.redTimer) {
  859. clearInterval(this.redTimer);
  860. this.redTimer = null;
  861. }
  862. if (this.lotteryTimer) {
  863. clearInterval(this.lotteryTimer);
  864. this.lotteryTimer = null;
  865. }
  866. this.closeShop()
  867. if (oldLive) {
  868. this.pauseVideo(oldLive);
  869. this.clearTimeTimer(oldLive); // 清除旧直播间的时间定时器
  870. // 强制关闭并删除实例,确保连接被释放
  871. if (this.socketInstances[oldLive.liveId]) {
  872. try {
  873. this.socketInstances[oldLive.liveId].instance.close({
  874. code: 1000,
  875. reason: '切换直播间'
  876. });
  877. console.log(`关闭旧直播间 ${oldLive.liveId} WebSocket`);
  878. } catch (e) {
  879. console.error('关闭旧连接失败:', e);
  880. }
  881. delete this.socketInstances[oldLive.liveId]; // 彻底删除实例
  882. }
  883. }
  884. // 2. 处理新直播间(后续逻辑不变)
  885. this.currentSwiperIndex = newIndex;
  886. const newLive = this.list[newIndex];
  887. if (!newLive) return;
  888. this.liveId = newLive.liveId;
  889. this.resetUserListParams();
  890. await this.initCurrentLiveData(); // 内部会启动新直播间的定时器
  891. // this.getliveUser(false);
  892. setTimeout(() => {
  893. this.playVideo(newLive);
  894. }, 100);
  895. },
  896. // 获取直播间列表
  897. async getList() {
  898. const data = {
  899. page: 1,
  900. page_size: 20
  901. };
  902. try {
  903. const res = await liveList(data);
  904. if (res.code === 200) {
  905. this.list = res.rows.map(item => ({
  906. ...item,
  907. talklist: [],
  908. loading: false,
  909. loaded: false,
  910. shopping: false,
  911. inputInfo: '',
  912. showWelcomeMessage: false,
  913. redInfo: {},
  914. goodsCard: {},
  915. totalTime: '00小时00分钟00秒', // 初始化差值为0
  916. timeTimer: null, // 存储当前直播间的定时器,用于后续清理
  917. // 预处理:统一将 startTime 转换为 iOS 兼容格式(避免重复转换)
  918. startTime: item.startTime ? item.startTime.replace(/-/g, '/') : ''
  919. }));
  920. console.log("直播间列表加载成功,数量:", this.list.length); // 确认数量是否 > 0
  921. } else {
  922. uni.showToast({
  923. title: res.msg,
  924. icon: "none"
  925. });
  926. this.list = []; // 接口失败时清空列表,避免后续错误
  927. }
  928. } catch (error) {
  929. console.error("获取直播间列表失败:", error);
  930. this.list = []; // 异常时清空列表
  931. }
  932. },
  933. // 播放视频
  934. playVideo(liveItem) {
  935. if (!liveItem) return;
  936. try {
  937. // 直播流使用live-player
  938. if (liveItem.liveType === 1 && liveItem.livingUrl) {
  939. const livePlayerId = `myLivePlayer_${liveItem.liveId}`;
  940. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  941. if (livePlayerContext) {
  942. livePlayerContext.play();
  943. }
  944. }
  945. // 回放视频使用video
  946. else if (liveItem.liveType === 2 && liveItem.videoUrl) {
  947. const videoId = `myVideo_${liveItem.liveId}`;
  948. const videoContext = uni.createVideoContext(videoId, this);
  949. if (videoContext) {
  950. videoContext.pause(() => {
  951. videoContext.play();
  952. });
  953. }
  954. }
  955. } catch (error) {
  956. console.error("播放视频失败:", error);
  957. }
  958. },
  959. pauseVideo(liveItem) {
  960. if (!liveItem) return;
  961. try {
  962. // 直播流使用live-player
  963. if (liveItem.liveType === 1) {
  964. const livePlayerId = `myLivePlayer_${liveItem.liveId}`;
  965. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  966. if (livePlayerContext) {
  967. livePlayerContext.pause();
  968. }
  969. }
  970. // 回放视频使用video
  971. else if (liveItem.liveType === 2) {
  972. const videoId = `myVideo_${liveItem.liveId}`;
  973. const videoContext = uni.createVideoContext(videoId, this);
  974. if (videoContext) {
  975. videoContext.pause();
  976. }
  977. }
  978. } catch (error) {
  979. console.error("暂停视频失败:", error);
  980. }
  981. },
  982. // 预加载相邻直播间
  983. async preloadNearbyLives(includeWebSocket = false) {
  984. // this.preloading = true;
  985. const currentIndex = this.currentSwiperIndex;
  986. const preloadIndexes = [];
  987. // 只预加载数据,不初始化WebSocket(强制关闭WebSocket预加载)
  988. if (currentIndex > 0) preloadIndexes.push(currentIndex - 1);
  989. if (currentIndex < this.list.length - 1) preloadIndexes.push(currentIndex + 1);
  990. for (const index of preloadIndexes) {
  991. const liveItem = this.list[index];
  992. if (!liveItem || liveItem.loaded || liveItem.loading) continue;
  993. liveItem.loading = true;
  994. try {
  995. // 只加载基础数据,不初始化WebSocket
  996. await Promise.all([
  997. this.getliving(liveItem),
  998. this.getLiveMsg(liveItem),
  999. this.getCurrentActivities(liveItem),
  1000. this.getliveViewData(liveItem),
  1001. // this.getShowGoods(liveItem)
  1002. ]);
  1003. liveItem.loaded = true;
  1004. } catch (error) {
  1005. liveItem.loaded = false;
  1006. } finally {
  1007. liveItem.loading = false;
  1008. }
  1009. }
  1010. // this.preloading = false;
  1011. },
  1012. openViews() {
  1013. // 计算scroll-view高度
  1014. this.$nextTick(() => {
  1015. const query = uni.createSelectorQuery().in(this);
  1016. query.select('.view-box').boundingClientRect(data => {
  1017. if (data) {
  1018. // 减去标题和底部固定区域的高度
  1019. this.scrollHeight = data.height - 80 - 120; // 80是标题高度,120是底部高度
  1020. }
  1021. }).exec();
  1022. });
  1023. },
  1024. // 重置直播间数据
  1025. resetLiveData() {
  1026. // 保留不需要重置的数据(如用户信息等)
  1027. const keepData = {
  1028. userinfo: this.userinfo,
  1029. list: this.list,
  1030. currentSwiperIndex: this.currentSwiperIndex
  1031. };
  1032. // 重置其他直播间特定数据
  1033. this.liveUserTotal = null;
  1034. // this.liveViewData = {};
  1035. this.liveViewers = [];
  1036. this.livingUrl = "";
  1037. this.videoUrl = null;
  1038. this.products = {};
  1039. this.store = {};
  1040. this.orderUser = {};
  1041. this.talklist = [];
  1042. this.livedata = {};
  1043. // this.isFollow = false;
  1044. this.shopping = false;
  1045. this.inputInfo = ''
  1046. // 恢复需要保留的数据
  1047. Object.assign(this, keepData);
  1048. },
  1049. // 获取直播间用户
  1050. async getliveUser(isLoadMore = false) {
  1051. // 强制使用当前 liveId,避免使用旧值
  1052. const currentLiveId = this.liveId;
  1053. if (!currentLiveId) return;
  1054. // if (this.viewLoading || this.viewNoMoreData) return;
  1055. this.viewLoading = true;
  1056. try {
  1057. const res = await watchUserList(currentLiveId, this.viewPageSize, this.viewPageNum, false);
  1058. if (res.code === 200) {
  1059. // 若请求期间已切换直播间,忽略旧数据
  1060. if (this.liveId !== currentLiveId) return;
  1061. this.liveUserTotal = res.total;
  1062. if (res.rows.length === 0) {
  1063. this.viewNoMoreData = true;
  1064. return;
  1065. }
  1066. this.liveViewers = isLoadMore ? [...this.liveViewers, ...res.rows] : res
  1067. .rows; // 首次加载/切换直播间时重置数据
  1068. this.viewPageNum++;
  1069. // console.log("在线观众", this.liveViewers)
  1070. }
  1071. } catch (error) {
  1072. console.error('获取观众列表失败:', error);
  1073. } finally {
  1074. this.viewLoading = false;
  1075. }
  1076. },
  1077. // 滚动到底部触发
  1078. handleScrollToLower() {
  1079. clearTimeout(this.tempState.scrollTimer);
  1080. this.tempState.scrollTimer = setTimeout(() => {
  1081. if (!this.viewLoading && !this.viewNoMoreData) {
  1082. this.getliveUser(true);
  1083. }
  1084. }, 300);
  1085. },
  1086. async getLiveMsg(liveItem) {
  1087. // 强化校验:确保 liveItem 存在且包含 liveId
  1088. if (!liveItem || !liveItem.liveId) {
  1089. return; // 直接返回,不执行后续逻辑
  1090. }
  1091. try {
  1092. const res = await liveMsg(liveItem.liveId, 30, 1);
  1093. if (res.code == 200) {
  1094. const rows = Array.isArray(res.rows) ? res.rows : [];
  1095. const reversedTalkList = [...rows].reverse();
  1096. this.$set(liveItem, 'talklist', reversedTalkList);
  1097. this.$nextTick(() => {
  1098. // 滚动到最新消息(反转后最新消息在数组最后一位,索引为 reversedTalkList.length - 1)
  1099. this.$set(liveItem, 'scrollIntoView', `list_${reversedTalkList.length - 1}`);
  1100. });
  1101. }
  1102. } catch (error) {
  1103. console.error("获取聊天记录失败:", error);
  1104. }
  1105. },
  1106. // 点击抽奖
  1107. onLottery(item) {
  1108. if (!item.lotteryInfo) return;
  1109. let data = {
  1110. lotteryId: item.lotteryInfo.lotteryId
  1111. }
  1112. console.log("dian", data)
  1113. // 抽奖查询
  1114. liveLottery(data).then(res => {
  1115. // this.isShowLottery=false
  1116. this.isShowLotteryPop = true
  1117. if (res.code == 200) {
  1118. this.lotteryProducts = res.data.products
  1119. } else {
  1120. uni.showToast({
  1121. title: res.msg,
  1122. icon: 'none'
  1123. });
  1124. }
  1125. },
  1126. rej => {}
  1127. );
  1128. },
  1129. // 点击红包
  1130. onRed(item) {
  1131. // console.log("点了this.liveId", item)
  1132. if (!item.liveId) return;
  1133. if (!item.redInfo?.redId) return;
  1134. let data = {
  1135. liveId: item.liveId,
  1136. userId: this.userinfo.userId,
  1137. redId: item.redInfo.redId,
  1138. }
  1139. liveRed(data).then(res => {
  1140. this.isShowRed = false
  1141. if (res.code == 200) {
  1142. console.log(this.isShowRed)
  1143. console.log("点了this.liveId", liveItem.redInfo)
  1144. uni.showToast({
  1145. title: res.msg,
  1146. icon: 'none'
  1147. });
  1148. } else {
  1149. uni.showToast({
  1150. title: res.msg,
  1151. icon: 'none'
  1152. });
  1153. }
  1154. },
  1155. rej => {}
  1156. );
  1157. },
  1158. handleSearchInput(liveItem) {
  1159. clearTimeout(this.tempState.searchTimer[liveItem.liveId]); // 清除旧定时器
  1160. this.tempState.searchTimer[liveItem.liveId] = setTimeout(() => {
  1161. this.queryCollect(liveItem);
  1162. }, 500);
  1163. },
  1164. // 显示购买提示信息
  1165. showPurchaseMessage() {
  1166. // 清除之前的定时器
  1167. if (this.purchasePromptTimer) {
  1168. clearTimeout(this.purchasePromptTimer);
  1169. }
  1170. // 显示提示
  1171. this.showPurchasePrompt = true;
  1172. // 2秒后自动隐藏
  1173. this.purchasePromptTimer = setTimeout(() => {
  1174. this.showPurchasePrompt = false;
  1175. }, 2000);
  1176. },
  1177. truncateString(str, maxLength) {
  1178. return str.length > maxLength ? str.slice(0, maxLength) + '...' : str;
  1179. },
  1180. goStore(item) {
  1181. console.log("带过去storeId", item)
  1182. if (!item.storeId) {
  1183. uni.showToast({
  1184. title: "当前直播间暂未开通店铺",
  1185. icon: 'none'
  1186. });
  1187. return;
  1188. }
  1189. uni.navigateTo({
  1190. url: '/pages_shop/store?liveId=' + item.liveId + "&storeId=" + item.storeId
  1191. })
  1192. },
  1193. // 去订单列表
  1194. goOrderList() {
  1195. uni.navigateTo({
  1196. url: "/pages_shop/order"
  1197. })
  1198. },
  1199. // 初始化HLS播放器
  1200. initHlsPlayer() {
  1201. if (Hls.isSupported() && this.livingUrl) {
  1202. const video = document.getElementById('myVideo');
  1203. if (video) {
  1204. this.hlsPlayer = new Hls();
  1205. this.hlsPlayer.loadSource(this.livingUrl);
  1206. this.hlsPlayer.attachMedia(video);
  1207. this.hlsPlayer.on(Hls.Events.MANIFEST_PARSED, () => {
  1208. video.play();
  1209. });
  1210. }
  1211. }
  1212. },
  1213. // 视频错误处理
  1214. videoError(e, liveItem) {
  1215. const maxRetry = 3;
  1216. const retryDelay = 3000; // 3秒后重试
  1217. if (!this.tempState.videoRetry[liveItem.liveId]) {
  1218. this.tempState.videoRetry[liveItem.liveId] = 0;
  1219. }
  1220. if (this.tempState.videoRetry[liveItem.liveId] >= maxRetry) {
  1221. uni.showToast({
  1222. title: "视频加载失败,请检查网络"
  1223. });
  1224. return;
  1225. }
  1226. this.tempState.videoRetry[liveItem.liveId]++;
  1227. setTimeout(() => {
  1228. if (liveItem.liveId === this.liveId) {
  1229. this.playVideo(liveItem);
  1230. }
  1231. }, retryDelay);
  1232. },
  1233. // 修改获取直播信息方法
  1234. async getliving(liveItem) {
  1235. if (!liveItem || !liveItem.liveId) return;
  1236. // console.log("获取直播信息:", liveItem.liveId);
  1237. const param = {
  1238. id: liveItem.liveId
  1239. };
  1240. try {
  1241. const res = await getlive({
  1242. id: liveItem.liveId
  1243. });
  1244. if (res.code !== 200) {
  1245. uni.showToast({
  1246. title: res.msg,
  1247. icon: 'none'
  1248. });
  1249. return;
  1250. }
  1251. // 强制更新视频源(覆盖旧值)
  1252. if (res.data.liveType === 2) {
  1253. // 回放视频
  1254. this.$set(liveItem, 'videoUrl', res.data.videoUrl);
  1255. this.$set(liveItem, 'livingUrl', ''); // 清空直播流
  1256. this.$set(liveItem, 'placeholderText', "说点什么...");
  1257. } else if (res.data.liveType === 1) {
  1258. // 直播流
  1259. this.$set(liveItem, 'livingUrl', res.data.flvHlsUrl);
  1260. this.$set(liveItem, 'videoUrl', ''); // 清空回放视频
  1261. this.$set(liveItem, 'placeholderText', "说点什么...");
  1262. } else {
  1263. // 未开播
  1264. this.$set(liveItem, 'livingUrl', '');
  1265. this.$set(liveItem, 'videoUrl', '');
  1266. }
  1267. // 更新其他直播信息
  1268. // 仅当是当前激活的直播间时,才允许自动播放
  1269. const isCurrentLive = this.currentSwiperIndex === this.list.findIndex(item => item.liveId ===
  1270. liveItem.liveId);
  1271. this.$set(liveItem, 'autoplay', isCurrentLive && res.data.liveType !== 0);
  1272. this.$set(liveItem, 'showType', res.data.showType);
  1273. this.$set(liveItem, 'storeId', res.storeId);
  1274. this.queryCollect();
  1275. } catch (err) {
  1276. console.error("获取直播信息失败:", err);
  1277. uni.showToast({
  1278. title: "获取直播信息失败",
  1279. icon: 'none'
  1280. });
  1281. }
  1282. }, // 设置视频播放
  1283. setupVideoPlayback(liveItem, liveData) {
  1284. if (!liveItem.livingUrl) return;
  1285. // H5 平台:使用 HLS.js 处理 .m3u8 流
  1286. // #ifdef H5
  1287. if (liveItem.livingUrl.includes('.m3u8')) {
  1288. this.initHlsPlayer(liveItem);
  1289. return;
  1290. }
  1291. // #endif
  1292. // 小程序/App 平台:直接使用 video 组件
  1293. const videoId = `myVideo_${liveItem.liveId}`;
  1294. const videoContext = uni.createVideoContext(videoId, this);
  1295. if (liveData.liveType === 1) {
  1296. // 回放:跳转到指定位置
  1297. videoContext.seek(liveData.nowDuration || 0);
  1298. } else {
  1299. // 直播:直接播放
  1300. videoContext.play();
  1301. }
  1302. },
  1303. maskString(str, maskChar = '*') {
  1304. // 如果str是undefined或null,直接返回空字符串
  1305. if (!str) return '';
  1306. // 确保str是字符串(如果是数字等类型,先转为字符串)
  1307. const strVal = String(str);
  1308. return strVal.split('').map((char, index) => (index === 0 ? char : maskChar)).join('');
  1309. },
  1310. getPureDecimal(num, precision = 6) {
  1311. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  1312. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  1313. },
  1314. // 返回上一个页面并关闭WebSocket
  1315. goBack() {
  1316. // 暂停当前视频
  1317. const currentLive = this.list[this.currentSwiperIndex];
  1318. if (currentLive) {
  1319. this.pauseVideo(currentLive);
  1320. }
  1321. // 关闭所有WebSocket连接
  1322. this.closeWebSocket();
  1323. // 导航返回
  1324. const pages = getCurrentPages();
  1325. if (pages.length > 1) {
  1326. uni.navigateBack();
  1327. } else {
  1328. uni.reLaunch({
  1329. url: '/pages/list/index'
  1330. });
  1331. }
  1332. },
  1333. //正在购买
  1334. async getliveOrder() {
  1335. const currentLiveId = this.liveId;
  1336. if (!currentLiveId) return;
  1337. try {
  1338. const res = await liveOrderUser(currentLiveId);
  1339. if (res.code === 200) {
  1340. // 绑定到当前 liveItem
  1341. const currentLive = this.list[this.currentSwiperIndex];
  1342. if (currentLive) {
  1343. this.$set(currentLive, 'orderUser', res);
  1344. this.orderUser = res; // 同步全局变量
  1345. }
  1346. }
  1347. } catch (error) {
  1348. console.error('获取正在购买用户失败:', error);
  1349. }
  1350. },
  1351. // 获取直播间信息接口
  1352. getLiveinformation() {
  1353. if (!this.liveId) return;
  1354. getLiveInfo(this.liveId).then(res => {
  1355. if (res.code == 200) {
  1356. console.log("获取直播间信息接口>>>>", res)
  1357. this.livingUrl = res.livingUrl
  1358. } else {
  1359. uni.showToast({
  1360. title: res.msg,
  1361. icon: 'none'
  1362. });
  1363. }
  1364. },
  1365. rej => {}
  1366. );
  1367. },
  1368. // 点赞
  1369. async onLike(liveItem) {
  1370. if (!liveItem || !liveItem.liveId) return;
  1371. try {
  1372. const res = await liveDataLike(liveItem.liveId);
  1373. if (res?.like) {
  1374. liveItem.liveViewData.like++; // 只更新当前直播间的点赞数
  1375. } else {
  1376. uni.showToast({
  1377. title: res.msg,
  1378. icon: 'none'
  1379. });
  1380. }
  1381. } catch (error) {
  1382. console.error('点赞失败:', error);
  1383. }
  1384. },
  1385. //直播间点赞、关注、在线人数数据
  1386. async getliveViewData(liveItem) {
  1387. if (!liveItem || !liveItem.liveId) return;
  1388. try {
  1389. const res = await getLiveViewData(liveItem.liveId);
  1390. if (res.code == 200) {
  1391. // 强制响应式更新,确保数据实时显示
  1392. this.$set(liveItem, 'liveViewData', res);
  1393. }
  1394. } catch (error) {
  1395. console.error("获取直播间数据失败:", error);
  1396. // 失败时兜底,避免显示异常
  1397. this.$set(liveItem, 'liveViewData', {
  1398. like: 0,
  1399. watchCount: 0
  1400. });
  1401. }
  1402. },
  1403. //弹出商品卡片
  1404. // async getShowGoods(liveItem) {
  1405. // if (!liveItem || !liveItem.liveId) return;
  1406. // try {
  1407. // const res = await showGoods(liveItem.liveId);
  1408. // if (res.code == 200) {
  1409. // this.$set(liveItem, 'goodsCard', res);
  1410. // }
  1411. // } catch (error) {
  1412. // console.error("暂无商品卡片", error);
  1413. // }
  1414. // },
  1415. // 去购买,跳商品详情
  1416. goShop(productId, goodsId) {
  1417. const currentLive = this.list[this.currentSwiperIndex];
  1418. if (!currentLive || !currentLive.liveId) return;
  1419. uni.navigateTo({
  1420. url: '/pages_shop/goods?productId=' + productId + '&liveId=' + currentLive.liveId +
  1421. '&goodsId=' + goodsId + '&storeId=' + currentLive.storeId
  1422. })
  1423. },
  1424. // 查询店铺
  1425. async queryCollect() {
  1426. const currentLive = this.list[this.currentSwiperIndex];
  1427. if (!currentLive || !currentLive.liveId) return;
  1428. const {
  1429. storeId
  1430. } = currentLive;
  1431. if (!storeId) return;
  1432. try {
  1433. const res = await liveStore(currentLive.liveId, currentLive.inputInfo);
  1434. if (res.code === 200) {
  1435. // 数据绑定到当前 liveItem,避免全局污染
  1436. this.$set(currentLive, 'products', res.data);
  1437. // this.$set(currentLive, 'store', res.data);
  1438. // 同步更新全局变量(供弹窗使用)
  1439. this.products = res.data;
  1440. // this.store = res.data;
  1441. }
  1442. } catch (error) {
  1443. console.error('获取小黄车商品失败:', error);
  1444. }
  1445. },
  1446. // 店铺收藏
  1447. onStoreCollect(liveItem) {
  1448. console.log("店铺收藏", liveItem)
  1449. if (!liveItem.storeId) return;
  1450. collectStore(liveItem.storeId).then(res => {
  1451. if (res.code == 200) {
  1452. uni.showToast({
  1453. title: res.msg,
  1454. icon: 'none'
  1455. });
  1456. liveItem.store.isFavorite = !liveItem.store.isFavorite
  1457. } else {
  1458. uni.showToast({
  1459. title: res.msg,
  1460. icon: 'none'
  1461. });
  1462. }
  1463. },
  1464. rej => {}
  1465. );
  1466. },
  1467. // 商品收藏
  1468. onGoodsCollect(item) {
  1469. console.log("商品收藏", item)
  1470. if (!item || item.length === 0 || !item.goodsId) {
  1471. return;
  1472. }
  1473. collectGoods(item.goodsId).then(res => {
  1474. if (res.code == 200) {
  1475. uni.showToast({
  1476. title: res.msg,
  1477. icon: 'none'
  1478. });
  1479. item.isFavorite = !item.isFavorite
  1480. } else {
  1481. uni.showToast({
  1482. title: res.msg,
  1483. icon: 'none'
  1484. });
  1485. }
  1486. },
  1487. rej => {}
  1488. );
  1489. },
  1490. // 关注
  1491. // async onFollow(liveItem) {
  1492. // if (!liveItem || !liveItem.liveId) return;
  1493. // try {
  1494. // const res = await follow(liveItem.liveId);
  1495. // liveItem.isFollow = !liveItem.isFollow;
  1496. // uni.showToast({
  1497. // title: res.msg,
  1498. // icon: 'none'
  1499. // });
  1500. // } catch (error) {
  1501. // console.error("关注操作失败:", error);
  1502. // }
  1503. // },
  1504. // 时间戳
  1505. initTime() {
  1506. const now = new Date();
  1507. this.timestamp = now.getTime(); // 例如:'2023-04-01 12:00:00'
  1508. },
  1509. openShop() {
  1510. },
  1511. openViews() {
  1512. this.$nextTick(() => {
  1513. const query = uni.createSelectorQuery().in(this);
  1514. query.select('.view-box').boundingClientRect(data => {
  1515. if (data) {
  1516. this.scrollHeight = data.height - 80 - 120;
  1517. }
  1518. }).exec();
  1519. });
  1520. },
  1521. openCart(liveItem) {
  1522. if (!liveItem.storeId) {
  1523. uni.showToast({
  1524. title: "当前直播间暂未开通店铺",
  1525. icon: 'none'
  1526. });
  1527. return;
  1528. }
  1529. liveItem.shopping = true
  1530. },
  1531. close() {
  1532. this.showadd = false;
  1533. const scrollView = uni.createSelectorQuery().in(this).select('.scroll-content');
  1534. scrollView.offScroll(); // 移除滚动监听
  1535. },
  1536. // 关闭小黄车
  1537. closeShop() {
  1538. // 通过当前swiper索引获取当前直播间实例
  1539. const currentLive = this.list[this.currentSwiperIndex];
  1540. if (currentLive) {
  1541. this.$set(currentLive, 'shopping', false);
  1542. }
  1543. },
  1544. getEWechatSdk() {
  1545. // 只在H5平台执行
  1546. // #ifdef H5
  1547. let eWechatSdk = '';
  1548. if (/(Android)/i.test(navigator.userAgent)) {
  1549. eWechatSdk = 'jWeixin';
  1550. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  1551. eWechatSdk = 'wx';
  1552. } else {
  1553. eWechatSdk = 'jWeixin';
  1554. }
  1555. uni.setStorageSync("wxSdk", eWechatSdk);
  1556. // #endif
  1557. },
  1558. // 修改关闭WebSocket方法
  1559. closeWebSocket(liveId = null) {
  1560. this.isManualClose = true;
  1561. clearInterval(this.pingpangTimes);
  1562. clearInterval(this.reconnectTimer);
  1563. if (liveId) {
  1564. // 添加空值检查
  1565. if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
  1566. try {
  1567. this.socketInstances[liveId].instance.close();
  1568. } catch (e) {}
  1569. }
  1570. delete this.socketInstances[liveId];
  1571. } else {
  1572. Object.keys(this.socketInstances).forEach(id => {
  1573. // 添加空值检查
  1574. if (this.socketInstances[id] && this.socketInstances[id].instance) {
  1575. try {
  1576. this.socketInstances[id].instance.close();
  1577. } catch (e) {}
  1578. }
  1579. });
  1580. this.socketInstances = {};
  1581. }
  1582. isSocketOpen = false;
  1583. },
  1584. startHeartbeat(liveId) {
  1585. clearInterval(this.pingpangTimes);
  1586. this.pingpangTimes = setInterval(() => {
  1587. const inst = this.socketInstances[liveId];
  1588. if (!inst || !inst.isOpen || !inst.instance) return;
  1589. const pingData = {
  1590. cmd: 'ping',
  1591. timestamp: Date.now()
  1592. };
  1593. try {
  1594. inst.instance.send({
  1595. data: JSON.stringify(pingData)
  1596. });
  1597. } catch (err) {
  1598. this.scheduleReconnect(liveId);
  1599. }
  1600. }, 30000);
  1601. },
  1602. async initSocket(liveItem) {
  1603. if (this.currentSwiperIndex !== this.list.findIndex(item => item.liveId === liveItem.liveId)) {
  1604. return; // 只连接当前直播间
  1605. }
  1606. const currentLive = this.list[this.currentSwiperIndex];
  1607. if (!currentLive || currentLive.liveId !== liveItem.liveId) {
  1608. return;
  1609. }
  1610. if (!liveItem || !liveItem.liveId) return;
  1611. const liveId = liveItem.liveId;
  1612. // 检查是否已经是当前连接或正在连接
  1613. if (this.connectingLiveId === liveId ||
  1614. (this.socketInstances[liveId] && this.socketInstances[liveId].isOpen)) {
  1615. return;
  1616. }
  1617. // 检查是否是当前活跃的直播间
  1618. if (this.currentSwiperIndex !== this.list.findIndex(item => item.liveId === liveId)) {
  1619. return;
  1620. }
  1621. this.socketInstances[liveId] = {
  1622. instance: null,
  1623. isOpen: false
  1624. };
  1625. // 关闭之前的连接(如果存在)
  1626. this.closeWebSocket(liveId);
  1627. // 设置正在连接的直播间ID
  1628. this.connectingLiveId = liveId;
  1629. // 防止重复创建
  1630. if (this.reconnectCount >= this.maxReconnectAttempts) {
  1631. this.connectingLiveId = null;
  1632. return;
  1633. }
  1634. this.isManualClose = false;
  1635. const connectTimeout = setTimeout(() => {
  1636. if (!this.socketInstances[liveId]?.isOpen) {
  1637. console.error(`WebSocket连接超时: ${liveId}`);
  1638. this.scheduleReconnect(liveId);
  1639. }
  1640. }, 10000); // 10秒超时
  1641. // 生成签名
  1642. const signature = CryptoJS.HmacSHA256(
  1643. `${liveId}${this.userinfo.userId}${this.userType}${this.timestamp}`,
  1644. this.timestamp.toString()
  1645. ).toString(CryptoJS.enc.Hex);
  1646. // 初始化实例状态
  1647. this.socketInstances[liveId] = {
  1648. instance: null,
  1649. isOpen: false
  1650. };
  1651. try {
  1652. const socketTask = uni.connectSocket({
  1653. url: `${wsUrl}?userId=${this.userinfo.userId}&liveId=${liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`,
  1654. success: () => {},
  1655. fail: (err) => {
  1656. this.connectingLiveId = null;
  1657. this.scheduleReconnect(liveId);
  1658. }
  1659. });
  1660. socketTask.onOpen((res) => {
  1661. console.log('WebSocket 连接已成功建立', res);
  1662. this.socketInstances[liveId].instance = socketTask;
  1663. this.socketInstances[liveId].isOpen = true;
  1664. clearTimeout(connectTimeout);
  1665. isSocketOpen = true;
  1666. this.connectingLiveId = null;
  1667. this.reconnectCount = 0;
  1668. this.startHeartbeat(liveId); // 修改 startHeartbeat 以接受 liveId 并使用 socketTask.send
  1669. });
  1670. socketTask.onMessage((res) => {
  1671. // 找到对应的直播间并更新数据
  1672. const targetLive = this.list.find(item => item.liveId === liveId);
  1673. if (targetLive) {
  1674. this.handleSocketMessage(res, targetLive);
  1675. }
  1676. });
  1677. socketTask.onError((err) => {
  1678. clearTimeout(connectTimeout);
  1679. this.connectingLiveId = null;
  1680. this.scheduleReconnect(liveId);
  1681. });
  1682. socketTask.onClose(() => {
  1683. console.log(`WebSocket 连接已关闭: ${liveId}`);
  1684. this.connectingLiveId = null;
  1685. });
  1686. } catch (e) {
  1687. console.error('创建 WebSocket 异常:', e);
  1688. this.connectingLiveId = null;
  1689. this.scheduleReconnect(liveId);
  1690. }
  1691. },
  1692. // 处理Socket消息
  1693. handleSocketMessage(message, liveItem) {
  1694. let data = JSON.parse(message.data)
  1695. const socketMessage = data.data // 服务端返回的消息体
  1696. if (data.code == 200) {
  1697. const messageData = {
  1698. ...socketMessage,
  1699. cmd: socketMessage.cmd || '', // 确保cmd字段存在
  1700. ts: Date.now() // 新增时间戳,用于排序(可选)
  1701. };
  1702. // 处理服务端返回的sendMsg消息,加入本地列表
  1703. if (socketMessage.cmd == 'sendMsg') {
  1704. // 1. 将消息追加到当前直播间的talklist中(响应式更新)
  1705. this.$set(liveItem, 'talklist', [...(liveItem.talklist || []), messageData]);
  1706. // 2. 延迟下一帧滚动到最新消息(确保DOM已更新)
  1707. this.$nextTick(() => {
  1708. const lastIndex = liveItem.talklist.length - 1;
  1709. this.$set(liveItem, 'scrollIntoView', `list_${lastIndex}`);
  1710. });
  1711. } else if (socketMessage.cmd == 'red') {
  1712. this.$set(liveItem, 'redInfo', JSON.parse(socketMessage.data));
  1713. this.isShowRed = true
  1714. this.redTimer = setInterval(() => {
  1715. this.isShowRed = true
  1716. }, liveItem.redInfo.duration * 1000)
  1717. } else if (socketMessage.cmd == 'lottery') {
  1718. this.$set(liveItem, 'lotteryInfo', JSON.parse(socketMessage.data));
  1719. this.isShowlottery = true
  1720. this.lotteryTimer = setInterval(() => {
  1721. this.isShowlottery = true
  1722. }, liveItem.lotteryInfo.duration * 1000)
  1723. } else if (socketMessage.cmd == 'entry' || socketMessage.cmd == 'out') {
  1724. this.$set(liveItem, 'talklist', [...liveItem.talklist, messageData]);
  1725. this.$set(liveItem, 'showWelcomeMessage', false);
  1726. this.$set(liveItem, 'showWelcomeMessage', true);
  1727. this.getliveUser(false);
  1728. if (liveItem.welcomeTimer) clearTimeout(liveItem.welcomeTimer);
  1729. liveItem.welcomeTimer = setTimeout(() => {
  1730. this.$set(liveItem, 'showWelcomeMessage', false);
  1731. }, 1000);
  1732. } else if (socketMessage.cmd == 'Integral') {
  1733. let integral = {
  1734. msg: socketMessage.msg,
  1735. status: true
  1736. }
  1737. this.$set(liveItem, 'integral', integral);
  1738. } else if (socketMessage.cmd == 'blockUser') {
  1739. uni.removeStorage({
  1740. key: 'AppToken',
  1741. success: () => {
  1742. uni.reLaunch({
  1743. url: '/pages/auth/login'
  1744. });
  1745. }
  1746. });
  1747. } else if (socketMessage.cmd == 'goods') {
  1748. this.$set(liveItem, 'goodsCard', JSON.parse(socketMessage.data));
  1749. }
  1750. } else {
  1751. uni.showToast({
  1752. title: data.msg,
  1753. icon: 'none'
  1754. });
  1755. }
  1756. },
  1757. scheduleReconnect(liveId) {
  1758. if (this.isManualClose || this.reconnectCount >= this.maxReconnectAttempts) return;
  1759. this.reconnectCount++;
  1760. const delay = Math.min(3000 * this.reconnectCount, 30000);
  1761. clearInterval(this.reconnectTimer);
  1762. this.reconnectTimer = setTimeout(() => {
  1763. // 使用传入的liveId
  1764. const liveItem = this.list.find(item => item.liveId === liveId) || {
  1765. liveId
  1766. };
  1767. this.initSocket(liveItem);
  1768. }, delay);
  1769. },
  1770. sendMsg(liveItem) {
  1771. if (!liveItem || !liveItem.liveId) return;
  1772. // 防止连续点击发送两次(短时锁定)
  1773. if (liveItem.isSending) return;
  1774. liveItem.isSending = true;
  1775. setTimeout(() => {
  1776. liveItem.isSending = false;
  1777. }, 800); // 800ms 内禁止再次发送
  1778. const text = (liveItem.value || '').trim();
  1779. if (!text) {
  1780. uni.showToast({
  1781. title: "不能发送空消息",
  1782. icon: 'none'
  1783. });
  1784. return;
  1785. }
  1786. const liveId = liveItem.liveId;
  1787. const socketItem = this.socketInstances[liveId];
  1788. this.$set(liveItem, 'value', ''); // 立即清空输入框,提升体验
  1789. // 检查socket连接状态
  1790. if (!socketItem || !socketItem.instance || !socketItem.isOpen) {
  1791. this.initSocket(liveItem); // 尝试重连
  1792. uni.showToast({
  1793. title: "连接未建立,正在重连",
  1794. icon: 'none'
  1795. });
  1796. return;
  1797. }
  1798. // 构造发送给服务端的消息数据
  1799. const data = {
  1800. liveId,
  1801. userId: this.userinfo.userId,
  1802. userType: 0,
  1803. cmd: "sendMsg", // 指令标识,服务端会根据此返回sendMsg消息
  1804. msg: text,
  1805. nickName: this.userinfo.nickName,
  1806. avatar: this.userinfo.avatar
  1807. };
  1808. // 发送socket消息
  1809. try {
  1810. socketItem.instance.send({
  1811. data: JSON.stringify(data),
  1812. success: () => {
  1813. // 发送成功无需额外操作,等待服务端返回消息后再更新列表
  1814. },
  1815. fail: (err) => {
  1816. uni.showToast({
  1817. title: err,
  1818. icon: 'none'
  1819. });
  1820. // 发送失败时可恢复输入框内容
  1821. this.$set(liveItem, 'value', text);
  1822. }
  1823. });
  1824. } catch (err) {}
  1825. }
  1826. }
  1827. };
  1828. </script>
  1829. <style scoped lang="scss">
  1830. .live-player {
  1831. width: 100%;
  1832. height: 100%;
  1833. }
  1834. .swiper-wrapper {
  1835. position: relative;
  1836. width: 100%;
  1837. height: 100vh;
  1838. overflow: hidden;
  1839. background-color: #000000;
  1840. }
  1841. .swiper-container {
  1842. width: 100%;
  1843. height: 100vh;
  1844. }
  1845. .container {
  1846. width: 100%;
  1847. height: 100%;
  1848. position: relative;
  1849. transition: opacity 0.3s ease;
  1850. transform: translateZ(0); // 开启GPU加速
  1851. will-change: opacity; // 告诉浏览器提前优化该属性
  1852. }
  1853. .loading-tip {
  1854. position: absolute;
  1855. top: 50%;
  1856. left: 50%;
  1857. transform: translate(-50%, -50%);
  1858. display: flex;
  1859. flex-direction: column;
  1860. align-items: center;
  1861. justify-content: center;
  1862. z-index: 10;
  1863. .loading-text {
  1864. color: #ffffff;
  1865. font-size: 28rpx;
  1866. margin-top: 20rpx;
  1867. }
  1868. }
  1869. .loading-more,
  1870. .no-more {
  1871. display: flex;
  1872. justify-content: center;
  1873. align-items: center;
  1874. padding: 20rpx 0;
  1875. color: #999;
  1876. font-size: 24rpx;
  1877. }
  1878. .loading-more {
  1879. flex-direction: column;
  1880. }
  1881. .preload-indicator {
  1882. position: absolute;
  1883. top: 50%;
  1884. right: 30rpx;
  1885. transform: translateY(-50%);
  1886. z-index: 100;
  1887. background: rgba(0, 0, 0, 0.5);
  1888. border-radius: 50%;
  1889. padding: 16rpx;
  1890. }
  1891. /* button自带样式清除 */
  1892. .student-orther-icon button::after {
  1893. border: none !important;
  1894. padding: 0 !important;
  1895. margin: 0 !important;
  1896. }
  1897. .student-orther-icon button {
  1898. background-color: transparent !important;
  1899. padding: 0 !important;
  1900. line-height: inherit !important;
  1901. margin: 0 !important;
  1902. width: auto !important;
  1903. font-weight: 500 !important;
  1904. border-radius: none !important;
  1905. }
  1906. .welcome-message {
  1907. position: fixed;
  1908. width: 100%;
  1909. bottom: 460rpx;
  1910. left: 50%;
  1911. transform: translateX(-50%);
  1912. color: white;
  1913. padding: 10px 20px;
  1914. border-radius: 20px;
  1915. // animation: fadeOut 1s ease 1s forwards;
  1916. z-index: 1000;
  1917. transition: opacity 0.3s ease;
  1918. }
  1919. @keyframes fadeOut {
  1920. from {
  1921. opacity: 1;
  1922. }
  1923. to {
  1924. opacity: 0;
  1925. }
  1926. }
  1927. .send {
  1928. background-color: #fafafa;
  1929. border-radius: 28rpx;
  1930. padding: 14rpx 16rpx;
  1931. color: #181818;
  1932. font-weight: 500;
  1933. }
  1934. // .container {
  1935. // position: relative;
  1936. // width: 100%;
  1937. // height: 100vh;
  1938. // overflow: hidden;
  1939. // }
  1940. // .talktext {
  1941. // border-radius: 8rpx;
  1942. // background-color: rgba(255, 255, 255, 0.1);
  1943. // view {
  1944. // width: 100%;
  1945. // }
  1946. // }
  1947. .talk-list {
  1948. border-radius: 30rpx;
  1949. background-color: rgba(33, 33, 33, 0.5);
  1950. padding: 10rpx 30rpx;
  1951. }
  1952. // .zoom-button-active {
  1953. // transform: scale(1.5);
  1954. // }
  1955. // .background-image {
  1956. // position: absolute;
  1957. // top: 0;
  1958. // left: -40rpx;
  1959. // width: 110%;
  1960. // height: 110%;
  1961. // object-fit: cover;
  1962. // filter: blur(20px);
  1963. // z-index: 0;
  1964. // }
  1965. // .background-images {
  1966. // position: absolute;
  1967. // top: 0;
  1968. // left: -40rpx;
  1969. // width: 110%;
  1970. // height: 110%;
  1971. // object-fit: cover;
  1972. // filter: blur(20px);
  1973. // z-index: 6;
  1974. // }
  1975. // .blackbg {
  1976. // position: absolute;
  1977. // top: 0;
  1978. // left: 0;
  1979. // width: 100%;
  1980. // height: 100%;
  1981. // background: rgba(0, 0, 0, 0.7);
  1982. // object-fit: cover;
  1983. // filter: blur(10px);
  1984. // z-index: 1;
  1985. // }
  1986. .content {
  1987. position: relative;
  1988. z-index: 2;
  1989. height: 100%;
  1990. width: 100%;
  1991. top: 0;
  1992. left: 0;
  1993. display: flex;
  1994. flex-direction: column;
  1995. justify-content: space-between;
  1996. .activity-box {
  1997. position: fixed;
  1998. top: 220rpx;
  1999. left: 30rpx;
  2000. z-index: 5;
  2001. display: flex;
  2002. align-items: center;
  2003. .item-box {
  2004. border-radius: 16rpx;
  2005. background-color: rgba(77, 77, 77, 0.5);
  2006. width: 80rpx;
  2007. height: 90rpx;
  2008. margin-right: 20rpx;
  2009. position: relative;
  2010. .tip {
  2011. position: absolute;
  2012. width: 100%;
  2013. bottom: 0;
  2014. color: #fafcff;
  2015. font-size: 20rpx;
  2016. background-color: rgba(15, 15, 15, 0.8);
  2017. border-radius: 16rpx;
  2018. text-align: center;
  2019. }
  2020. .item {
  2021. margin: 0 auto;
  2022. padding: 10rpx 0;
  2023. image {
  2024. height: 100%;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. .siderow-group {
  2030. position: absolute;
  2031. top: 65%;
  2032. right: 30rpx;
  2033. z-index: 9;
  2034. display: flex;
  2035. flex-direction: column;
  2036. align-items: center;
  2037. .side-item {
  2038. font-weight: 500;
  2039. font-size: 24rpx;
  2040. color: #FFFFFF;
  2041. margin-bottom: 32rpx;
  2042. text-align: center;
  2043. .button {
  2044. background-color: transparent;
  2045. margin: 0;
  2046. line-height: 1;
  2047. padding: 0;
  2048. }
  2049. .image {
  2050. width: 72rpx;
  2051. height: 72rpx;
  2052. }
  2053. }
  2054. }
  2055. .side-group {
  2056. position: absolute;
  2057. // top: 30%;
  2058. top: 65%;
  2059. right: 30rpx;
  2060. z-index: 9;
  2061. display: flex;
  2062. flex-direction: column;
  2063. align-items: center;
  2064. .side-item {
  2065. font-weight: 500;
  2066. font-size: 24rpx;
  2067. color: #FFFFFF;
  2068. margin-bottom: 32rpx;
  2069. text-align: center;
  2070. .button {
  2071. background-color: transparent;
  2072. margin: 0;
  2073. line-height: 1;
  2074. padding: 0;
  2075. }
  2076. .image {
  2077. width: 72rpx;
  2078. height: 72rpx;
  2079. }
  2080. }
  2081. }
  2082. .goods {
  2083. position: fixed;
  2084. // bottom: 160rpx;
  2085. // right: 10rpx;
  2086. top: 50%;
  2087. left: 50%;
  2088. transform: translate(-50%, -50%);
  2089. z-index: 5;
  2090. background-color: #fff;
  2091. border-radius: 20rpx;
  2092. overflow: hidden;
  2093. width: 300rpx;
  2094. // width: 220rpx;
  2095. padding: 4rpx;
  2096. .top {
  2097. position: absolute;
  2098. top: 4rpx;
  2099. display: flex;
  2100. justify-content: space-between;
  2101. align-items: center;
  2102. color: #fff;
  2103. width: 100%;
  2104. padding-right: 10rpx;
  2105. box-sizing: border-box;
  2106. .left {
  2107. background-color: rgba(0, 0, 0, 0.8);
  2108. padding: 10rpx;
  2109. font-size: 20rpx;
  2110. display: flex;
  2111. justify-content: space-between;
  2112. align-items: center;
  2113. border-radius: 10rpx;
  2114. }
  2115. }
  2116. .photo {
  2117. width: 100%;
  2118. height: 250rpx;
  2119. border-radius: 16rpx 16rpx 0 0;
  2120. overflow: hidden;
  2121. }
  2122. .item {
  2123. padding: 4rpx;
  2124. .price {
  2125. .red {
  2126. color: #FF5701;
  2127. font-weight: 600;
  2128. margin-right: 10rpx;
  2129. }
  2130. .del {
  2131. color: #828282;
  2132. font-weight: 500;
  2133. font-size: 24rpx;
  2134. text-decoration: line-through
  2135. }
  2136. }
  2137. .title {
  2138. font-weight: 500;
  2139. font-size: 26rpx;
  2140. margin: 10rpx 0 12rpx;
  2141. }
  2142. .button {
  2143. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  2144. color: #fff;
  2145. text-align: center;
  2146. padding: 16rpx 0;
  2147. border-radius: 10rpx;
  2148. font-weight: 500;
  2149. }
  2150. }
  2151. }
  2152. // 抽奖
  2153. .prize-box {
  2154. position: relative;
  2155. .nav-img {
  2156. width: 311rpx;
  2157. position: absolute;
  2158. top: -122rpx;
  2159. left: 50%;
  2160. transform: translateX(-50%);
  2161. }
  2162. .bg-img {
  2163. position: absolute;
  2164. top: 0;
  2165. left: 0;
  2166. width: 100%;
  2167. height: 100%;
  2168. z-index: 1;
  2169. }
  2170. .prize-content {
  2171. position: relative;
  2172. z-index: 2;
  2173. padding: 24rpx 0 68rpx;
  2174. .white-item {
  2175. width: 40rpx;
  2176. height: 40rpx;
  2177. text-align: center;
  2178. overflow: hidden;
  2179. background: #FFFFFF;
  2180. box-shadow: inset 0rpx 2rpx 8rpx 0rpx #FFEBB2;
  2181. border-radius: 8rpx;
  2182. margin: 4rpx;
  2183. font-weight: 600;
  2184. font-size: 24rpx;
  2185. color: #F85D22;
  2186. line-height: 40rpx;
  2187. }
  2188. .prize-swiper {
  2189. width: 100%;
  2190. height: 400rpx;
  2191. margin: 20rpx 0;
  2192. overflow: visible;
  2193. /* 轮播项基础样式 */
  2194. .item {
  2195. flex-shrink: 0;
  2196. width: 348rpx;
  2197. height: 348rpx;
  2198. background: #FFFFFF;
  2199. box-shadow: 0rpx 12rpx 19rpx 2rpx rgba(219, 73, 22, 0.6);
  2200. border-radius: 24rpx;
  2201. border: 4rpx solid #FFCA96;
  2202. display: flex;
  2203. flex-direction: column;
  2204. align-items: center;
  2205. box-sizing: border-box;
  2206. padding: 20rpx 0;
  2207. margin: 0 auto;
  2208. transition: all 0.3s ease;
  2209. &:not(.center) {
  2210. transform: scale(0.85);
  2211. z-index: 1;
  2212. opacity: 0.8;
  2213. }
  2214. &.center {
  2215. width: 440rpx;
  2216. height: 450rpx;
  2217. transform: scale(1);
  2218. z-index: 2;
  2219. opacity: 1;
  2220. box-shadow: 0rpx 16rpx 24rpx 4rpx rgba(219, 73, 22, 0.8);
  2221. border-color: #FFEB66;
  2222. }
  2223. .title {
  2224. font-weight: 500;
  2225. font-size: 32rpx;
  2226. color: #222222;
  2227. margin: 20rpx 0 10rpx;
  2228. }
  2229. .txt {
  2230. font-size: 24rpx;
  2231. color: #757575;
  2232. text-align: center;
  2233. padding: 0 10rpx;
  2234. }
  2235. image {
  2236. width: 220rpx;
  2237. height: 220rpx;
  2238. object-fit: cover;
  2239. border-radius: 16rpx;
  2240. }
  2241. }
  2242. }
  2243. /* 5. 指示点样式优化 */
  2244. .point-group {
  2245. margin: 30rpx 0 50rpx;
  2246. display: flex;
  2247. gap: 12rpx;
  2248. justify-content: center;
  2249. .item {
  2250. width: 24rpx;
  2251. height: 8rpx;
  2252. background: rgba(255, 255, 255, 0.5);
  2253. border-radius: 4rpx;
  2254. transition: all 0.3s ease;
  2255. &.selected {
  2256. background: #FFEB66;
  2257. }
  2258. }
  2259. }
  2260. .item-group {
  2261. position: absolute;
  2262. top: 250rpx;
  2263. left: 0;
  2264. width: 100%;
  2265. display: flex;
  2266. align-items: center;
  2267. overflow: hidden;
  2268. overflow-x: auto; // 仅横向滚动
  2269. overflow-y: hidden;
  2270. gap: 20rpx;
  2271. padding: 0 20rpx; // 左右留间隙,避免item贴边
  2272. scroll-behavior: smooth; // 平滑滚动(关键)
  2273. scrollbar-width: none; // 隐藏滚动条(可选,美化)
  2274. -ms-overflow-style: none; // IE隐藏滚动条
  2275. .item {
  2276. flex-shrink: 0;
  2277. width: 348rpx;
  2278. height: 348rpx;
  2279. background: #FFFFFF;
  2280. box-shadow: 0rpx 12rpx 19rpx 2rpx rgba(219, 73, 22, 0.6);
  2281. border-radius: 24rpx 24rpx 24rpx 24rpx;
  2282. border: 4rpx solid #FFCA96;
  2283. display: flex;
  2284. flex-direction: column;
  2285. align-items: center;
  2286. box-sizing: border-box;
  2287. padding: 20rpx 0;
  2288. .title {
  2289. font-weight: 500;
  2290. font-size: 32rpx;
  2291. color: #222222;
  2292. margin: 20rpx 0 20rpx;
  2293. }
  2294. .txt {
  2295. font-size: 24rpx;
  2296. color: #757575;
  2297. }
  2298. }
  2299. .center {
  2300. width: 440rpx;
  2301. height: 450rpx;
  2302. }
  2303. }
  2304. // .point-group {
  2305. // margin: 480rpx 0 50rpx;
  2306. // display: flex;
  2307. // gap: 6rpx;
  2308. // .item {
  2309. // width: 20rpx;
  2310. // height: 8rpx;
  2311. // background: rgba(255, 255, 255, 0.5);
  2312. // border-radius: 4rpx 4rpx 4rpx 4rpx;
  2313. // }
  2314. // .selected {
  2315. // background: #FFEB66;
  2316. // }
  2317. // }
  2318. .button {
  2319. margin-top: 30rpx;
  2320. width: 520rpx;
  2321. height: 88rpx;
  2322. line-height: 88rpx;
  2323. background: linear-gradient(180deg, #FFF4D6 0%, #FFEB66 100%);
  2324. box-shadow: 0rpx 10rpx 8rpx 4rpx rgba(246, 82, 25, 0.5);
  2325. border-radius: 44rpx;
  2326. font-weight: 500;
  2327. font-size: 36rpx;
  2328. color: #F4410B;
  2329. text-align: center;
  2330. }
  2331. }
  2332. }
  2333. .shoppop {
  2334. padding: 22rpx 16rpx;
  2335. .shoppop-top {
  2336. display: flex;
  2337. justify-content: space-between;
  2338. align-items: center;
  2339. padding: 0 16rpx 22rpx;
  2340. .search-input {
  2341. width: 414rpx;
  2342. height: 76rpx;
  2343. background: #FFFFFF;
  2344. border-radius: 36rpx;
  2345. margin-left: 20rpx;
  2346. padding: 0 32rpx;
  2347. box-sizing: border-box;
  2348. font-size: 24rpx;
  2349. margin-right: 24rpx;
  2350. }
  2351. .search-top {
  2352. font-size: 20rpx;
  2353. color: #222222;
  2354. }
  2355. }
  2356. }
  2357. }
  2358. </style>