living.vue 73 KB

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