livingyes.vue 76 KB

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