living.vue 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986
  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/avatar.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. <view v-for="(item,viewerIndex) in filteredViewers" :key="viewerIndex">
  19. <image v-if="item.avatar" class="w52 h52 mr4" style="border-radius: 26rpx;"
  20. :src="item.avatar" />
  21. <view v-else class="w52 h52 mr4"
  22. :style="{backgroundColor: getUserRandomColor(item.userId), borderRadius:'50%'}">
  23. <text class="text-white text-xs">{{getNicknameInitial(item.nickName)}}</text>
  24. </view>
  25. </view>
  26. <view class="sum">{{liveUserTotal||0}}</view>
  27. </view>
  28. </view>
  29. <!-- 右边的side -->
  30. <!-- <view class="side-group">
  31. <view class="side-item" @click="onLike">
  32. <LikeButton :initialCount="100" :heartsPerClick="5" @like="onLike" />
  33. <view>{{liveViewData && liveViewData.like||0}}</view>
  34. </view>
  35. <view class="side-item">
  36. <button open-type="share" class="button button-reset">
  37. <image class="image" src="/static/images/weixin.png" mode="widthFix" />
  38. </button>
  39. <view>分享</view>
  40. </view>
  41. </view> -->
  42. <view class="side-group">
  43. <!-- v-if="isShowRed" -->
  44. <view :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','item-box']" @click="onRed()" >
  45. <view class="x-f">
  46. <view class="tip">领红包</view>
  47. <view class="item">
  48. <image class="w70 img" src="/static/images/redbag.png" mode="widthFix" />
  49. </view>
  50. </view>
  51. </view>
  52. <!-- v-if="isShowLottery&&countdown" -->
  53. <view :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','item-box']" @click="onLottery()" >
  54. <view class="x-f">
  55. <view class="tip">抽奖</view>
  56. <view class="item">
  57. <image class="w60" src="/static/images/lottery.png" mode="widthFix" />
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- <view class="activity-box">
  63. <view class="item-box" @click="onRed()" v-if="isShowRed">
  64. <view class="x-f">
  65. <view class="tip">领红包</view>
  66. <view class="item">
  67. <image class="w70 img" src="/static/images/redbag.png" mode="widthFix" />
  68. </view>
  69. </view>
  70. </view>
  71. <view class="item-box" @click="onLottery()" v-if="isShowLottery&&countdown">
  72. <view class="x-f">
  73. <view class="tip">抽奖</view>
  74. <view class="item">
  75. <image class="w60" src="/static/images/lottery.png" mode="widthFix" />
  76. </view>
  77. </view>
  78. </view>
  79. </view> -->
  80. <view class="shop-prompt f30 x-f"
  81. v-if="showPurchasePrompt&&orderUser&&orderUser.count&&liveItem.status==2">
  82. <image class="w32 h32 mr8" src="/static/images/shopping.png" />
  83. <text>{{ orderUser.count || 0 }}人正在去购买</text>
  84. </view>
  85. <view class="videolist" v-if="liveItem.status==2">
  86. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  87. <!-- 直播 -->
  88. <live-player v-if="liveItem.livingUrl && liveItem.liveType == 1" :id="'myLivePlayer_' + liveId"
  89. :src="liveItem.livingUrl" autoplay mode="live" object-fit="contain" :muted="false"
  90. orientation="vertical" :enable-play-gesture="false" min-cache="1" max-cache="3"
  91. @statechange="onLiveStateChange($event, liveItem)" @error="onLiveError($event, liveItem)"
  92. class="item"></live-player>
  93. <!-- 录播 -->
  94. <video v-if="liveItem.videoUrl&&liveItem.liveType==2" :id="`myVideo_${liveId}`" :autoplay="true"
  95. class="item" :src="liveItem.videoUrl" :controls="false" object-fit="contain"
  96. :custom-cache="false" :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false"
  97. :show-center-play-btn="false" :http-cache="false" loop @error="videoError"
  98. @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  99. @play="onVideoPlay" @waiting="onVideoWaiting" :enable-play-gesture="false"
  100. :play-strategy="1" @dblclick="preventDoubleClick" preload="auto"
  101. :enable-stash-buffer="false" :stash-initial-size="0" :stash-max-size="0" :stash-time="0"
  102. type="application/x-mpegURL">
  103. </video>
  104. <view v-if="liveItem.videoUrl&&liveItem.liveType==2" class="time">{{diffTotalTime}}
  105. </view>
  106. </view>
  107. </view>
  108. <view class="videolist" v-if="liveItem.status==3">
  109. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  110. <view class="end">直播已结束</view>
  111. </view>
  112. </view>
  113. <view class="videolist" v-if="liveItem.status==4">
  114. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  115. <!-- 直播回放 -->
  116. <video v-if="liveItem.videoUrl&&liveItem.liveType==3" :id="`myVideo_${liveId}`" class="item"
  117. :src="liveItem.videoUrl" :autoplay="true" :controls="true" object-fit="contain"
  118. :custom-cache="false" :enable-progress-gesture="liveItem.isSpeedAllowed"
  119. vslide-gesture-in-fullscreen="true" :show-center-play-btn="true" :http-cache="false" loop
  120. @error="videoError" @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded"
  121. @pause="onVideoPause" @play="onVideoPlay" :enable-play-gesture="true" preload="auto"
  122. @waiting="onVideoWaiting" type="application/x-mpegURL">
  123. </video>
  124. <view v-if="liveItem.videoUrl&&liveItem.liveType==3" class="lable">直播回放</view>
  125. </view>
  126. </view>
  127. <view class="trailer-box" v-if="liveItem.status==1">
  128. <video v-if="liveItem.previewUrl" :id="`myVideo_${liveId}`" class="item" :src="liveItem.previewUrl"
  129. :autoplay="true" :loop="false" :controls="false" object-fit="contain" :custom-cache="false"
  130. :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false"
  131. :show-center-play-btn="false" :http-cache="false" @error="videoError"
  132. @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause" @play="onVideoPlay"
  133. :disable-progress="true" :enable-play-gesture="true" @waiting="onVideoWaiting" preload="auto"
  134. type="application/x-mpegURL">
  135. </video>
  136. <image v-if="liveItem.status==1&&!liveItem.previewUrl" class="img" src="/static/images/no_live.png">
  137. </image>
  138. <view class="countdown-item mt30 mb30" v-if="liveItem.status==1&&liveCountdown">
  139. 开播倒计时
  140. <view class="x-f">
  141. <view class="white">
  142. {{liveCountdown.hours||"00"}}
  143. </view>
  144. <view class="white">
  145. {{ liveCountdown.minutes||"00"}}
  146. </view>
  147. <view class="white">
  148. {{ liveCountdown.seconds||"00" }}
  149. </view>
  150. </view>
  151. </view>
  152. <view class="name"> {{liveItem.liveName}}</view>
  153. <view class="title" v-if="liveCountdown">暂未开播</view>
  154. <view class="button" v-if="!isAgreement" @click="handleAgreement">预约直播</view>
  155. <view class="button ash" v-if="isAgreement">已预约</view>
  156. <view class="title" v-if="!liveCountdown">主播还在来的路上</view>
  157. </view>
  158. <view class="trailer-box" v-if="!liveItem">
  159. <image class="img" src="/static/images/no_live.png">
  160. </image>
  161. <view class="title">暂无直播</view>
  162. </view>
  163. <!-- 底部聊天区域 -->
  164. <view
  165. :style="{position: 'fixed',width: '100%',bottom:isFocus ? keyboardHeight+'rpx' : '0' ,zIndex:999}">
  166. <view class="mt20" :style="{ height: isFocus ? '64rpx' : '30vh' }">
  167. <scroll-view v-if="Array.isArray(talklist)" enable-flex scroll-y="true"
  168. class="pl20 scrolly flex-1 column" style="width: calc(100% - 20rpx); height: 100%;"
  169. :scroll-top="scrollTop" ref="scrollView">
  170. <view class="list justify-start" v-for="(item,talkIndex) in (talklist||[])" :key="talkIndex"
  171. :id="`list_${talkIndex}`" v-show="item.cmd!='red'&&item.cmd!='out'&&item.cmd!='entry'">
  172. <view
  173. :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','talk-list','justify-start']">
  174. <view class="fs30" style="max-width: 100%;">
  175. <text style="color: #FFDA73;">{{item.nickName||"未命名"}}:</text>
  176. <text class='colorf'>{{item.msg}}</text>
  177. </view>
  178. </view>
  179. </view>
  180. <view v-if="showWelcomeMessage" class="welcome-message" style="max-width: 100%;">
  181. <view class="list justify-start" v-show="inAndOut.cmd=='entry'||inAndOut.cmd=='out'">
  182. <view
  183. :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','talk-list','justify-start']">
  184. <view class="fs30">
  185. <text style="color: #ff89d6;">{{inAndOut.nickName||"未命名"}} </text>
  186. <text class='colorf'>{{inAndOut.msg}}直播间</text>
  187. </view>
  188. </view>
  189. </view>
  190. </view>
  191. </scroll-view>
  192. </view>
  193. <!-- 底部输入框和操作按钮 -->
  194. <view class="justify-between p24 input-bottom">
  195. <view class="x-f justify-between" :class="liveItem.showType==1? 'horizontal':'vertical'"
  196. :style="{padding: '10rpx 14rpx 10rpx 32rpx',boxSizing: 'border-box',borderRadius: '36rpx',width: isFocus ? '100%' : '420rpx'}">
  197. <input :placeholder="placeholderText" v-model="value" placeholder-style="color:#e7e7e7;"
  198. placeholder-class="placeholder-style" class="ml20 input-native" @focus="inputFocus"
  199. @blur="inputBlur"
  200. style="border: none; font-size: 32rpx; color: #ffffff; background: transparent; width: 70%;"
  201. cursor-spacing="100" :adjust-position="false" />
  202. <view class="send" @click="sendMsg()">发送</view>
  203. </view>
  204. <view class="justify-between align-center" v-if="!isFocus">
  205. <view :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-bg','ml20']"
  206. @tap="openCart()">
  207. <image src="/static/images/more-icon.png" class="w48 h48" />
  208. </view>
  209. </view>
  210. <view class="justify-between align-center" v-if="!isFocus">
  211. <view :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-bg','ml20']"
  212. @tap="openCart()">
  213. <image src="/static/images/shopping.png" class="w48 h48" />
  214. </view>
  215. </view>
  216. <view class="justify-between align-center" v-if="!isFocus">
  217. <view :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-bg','ml20']"
  218. style="position: relative;">
  219. <LikeButton style="z-index: 99999;" :initialCount="100" :heartsPerClick="5" @like="onLike" />
  220. <view class="num">{{liveViewData && liveViewData.like||0}}</view>
  221. </view>
  222. </view>
  223. <view class="justify-between align-center" v-if="!isFocus">
  224. <view :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-bg','ml20']">
  225. <button open-type="share" class="w48 h48 button button-reset">
  226. <image class="w48 h48" src="/static/images/weixin.png" mode="widthFix" />
  227. </button>
  228. </view>
  229. </view>
  230. </view>
  231. </view>
  232. </view>
  233. <view class="goods" v-if="isShowGoods">
  234. <view class="top">
  235. <view class="left">
  236. <image class="w30 h30 mr8" src="/static/images/signal.png" />讲解中
  237. </view>
  238. <image @click="isShowGoods=false" class="w40 h40 " src="/static/images/del_black.png" />
  239. </view>
  240. <image class="photo" :src="goodsCard.imgUrl" />
  241. <view class="item">
  242. <view class="price"><text class="red">¥{{goodsCard.price}} </text><text
  243. class="del">¥{{goodsCard.otPrice}}</text></view>
  244. <view class="title oneline-hide">{{goodsCard.productName}}</view>
  245. <view class="button" @click="goShop(goodsCard.productId,goodsCard.goodsId)">
  246. 立即抢购
  247. </view>
  248. </view>
  249. </view>
  250. <u-popup :show="isShowLotteryPop&&countdown" round='40rpx'>
  251. <view class="prize-box" style="border-radius: 40rpx;height: fit-content;">
  252. <image class="nav-img " src="/static/images/red_head.png" mode="widthFix" />
  253. <image class="bg-img " src="/static/images/red_bg.png" />
  254. <view class="prize-content">
  255. <view class=" mr20" style="display: flex;justify-content: flex-end;">
  256. <view
  257. style="width: 80rpx;height: 80rpx;display: flex; justify-content: center;align-items: center;"
  258. @click="isShowLotteryPop=false"><u-icon class="x-end" name="close" color="#fff"
  259. size="20"></u-icon>
  260. </view>
  261. </view>
  262. <view class="column align-center ">
  263. <image class="w446 h80" src="/static/images/red_title.png" />
  264. <view class="fs24 colorf x-f mt30 mb30">
  265. 开奖倒计时
  266. <view class="x-f">
  267. <view class="white-item">
  268. {{countdown.hours||"00"}}
  269. </view>
  270. <view class="white-item">
  271. {{ countdown.minutes||"00" }}
  272. </view>
  273. <view class="white-item">
  274. {{ countdown.seconds||"00" }}
  275. </view>
  276. </view>
  277. </view>
  278. <view class="item-group">
  279. <ThreeItemSwiper :products="lotteryProducts"></ThreeItemSwiper>
  280. </view>
  281. <view class="point-group" v-for="(item,index) in lotteryProducts" :key="index">
  282. </view>
  283. <view class="colorf fs28">
  284. 观看直播参与抽奖
  285. </view>
  286. <view class="button" @click="onClaim">参与抽奖</view>
  287. </view>
  288. </view>
  289. </view>
  290. </u-popup>
  291. <u-popup :show="!!integral.status" round='20rpx' mode="center" bgColor='#ffffff' zIndex='10076'>
  292. <view class="integral-box">
  293. <view class="top">
  294. <view class="title">观看视频领芳华币</view>
  295. <image class="photo" src="/static/images/integral_bg.png" mode="widthFix" />
  296. </view>
  297. <view class="item">
  298. <view class="title ">{{integral.msg}}</view>
  299. <view class="button" @click="integral.status=false">确认</view>
  300. </view>
  301. </view>
  302. </u-popup>
  303. <u-popup :show="isShowRedCard" round='20rpx' mode="center" bgColor='transparent' zIndex='10076'>
  304. <view class="red-card">
  305. <image class="img" src="/static/images/red_card.png" />
  306. <view class="red-content">
  307. <view class="title">{{redCard.msg}}</view>
  308. <view class="txt ">直播惊喜芳华币</view>
  309. <view class="button" @click="isShowRedCard=false">确认</view>
  310. </view>
  311. </view>
  312. </u-popup>
  313. <!-- 中奖和未中奖 -->
  314. <u-popup :show="isShowPrize&&havePrize" round='20rpx' mode="center" bgColor='#fff' zIndex='10076'>
  315. <view class="prize-card" v-if="isCurrentUserWon">
  316. <image class="nav-img " src="/static/images/red_head.png" mode="widthFix" />
  317. <view class="title">恭喜您 中奖啦!</view>
  318. <view class="prize-content" v-for="(item,index) in (prizeInfo||[])" :key="index">
  319. <view class="item">{{item.userName}}</view>
  320. <view class="item">{{item.userId}}</view>
  321. <view class="txt item">{{item.prizeLevel}}等奖</view>
  322. </view>
  323. <view class="tip">请截图联系客服领取奖品</view>
  324. <view class="button" @click="confirm">确认</view>
  325. </view>
  326. <view class="no-prize-card" v-else>
  327. <image class="img" src="/static/images/no-prize.png" mode="widthFix" />
  328. <view class="tip">很遗憾 您未中奖</view>
  329. <view class="button" @click="confirm">确认</view>
  330. </view>
  331. </u-popup>
  332. <!-- 中奖记录 -->
  333. <!-- winning -->
  334. <u-popup :show="winning" @close="closeWin" round='20rpx' bgColor='#f3f5f9' zIndex='10076'>
  335. <view class="winning_record">
  336. <image class="head_bg" src="/static/images/red_head.png" mode="widthFix"></image>
  337. <image class="bg" src="/static/images/red_bg.png"></image>
  338. <view class="winning_content">
  339. <view class="title">我的中奖记录</view>
  340. <view class="row mb40">
  341. <view class="head">时间</view>
  342. <view class="head">奖品</view>
  343. </view>
  344. <scroll-view enable-flex scroll-y v-if="prizeAll" style="height: 500rpx;">
  345. <view class="row fs30 mb20" v-for="(item,index) in prizeAll" :key="index">
  346. <view class="start">{{item.createTime}}</view>
  347. <view class="end">{{item.productName?truncateString(item.productName,8):'' }}</view>
  348. </view>
  349. </scroll-view>
  350. <view v-else class="f36 mt150" style="text-align: center;">
  351. 暂无中奖信息
  352. </view>
  353. </view>
  354. </view>
  355. </u-popup>
  356. <!-- 观众列表弹窗 -->
  357. <u-popup :show="showadd" @close="close" @open="openViews" round='20rpx' bgColor='#ffffff' zIndex='10077'>
  358. <view class="view-box">
  359. <view class="fs32" style="text-align: center;">在线观众</view>
  360. <scroll-view v-if="Array.isArray(liveViewers)" scroll-y class="scroll-content"
  361. :style="{height: scrollHeight + 'px'}" @scrolltolower="handleScrollToLower">
  362. <view class="fs28 x-f mb20 mt20" v-for="(item,index) in (liveViewers||[])" :key="index">
  363. <view
  364. :style="{color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',fontWeight: index < 3 ? 'bold' : 'normal',width: '50rpx'}"
  365. class="mr10">{{index+1}}</view>
  366. <u-avatar v-if="item.avatar" :src="item.avatar" :size="36"></u-avatar>
  367. <view v-else class="w72 h72"
  368. :style="{backgroundColor: getUserRandomColor(item.userId), borderRadius:'50%'}">
  369. <text class="text-white text-sm">{{getNicknameInitial(item.nickName)}}</text>
  370. </view>
  371. <text class="ml16 f30">{{item.nickName||"未命名"}}</text>
  372. </view>
  373. </scroll-view>
  374. </view>
  375. </u-popup>
  376. <!-- 更多弹窗 -->
  377. <u-popup :show="isMore" @close="closeMore" round='20rpx' bgColor='#f3f5f9' zIndex='10076'>
  378. <view class="more-block">
  379. <view class="item" @click="navgetTo('/pages_shopping/live/integral'),isMore=false">
  380. <image class="w48 h48" src="/static/images/order.png" />
  381. <view style="text-align: center;">芳华币</view>
  382. </view>
  383. <view class=" item"
  384. @click="navgetTo('/pages_shopping/live/storeOrderRefundList?liveId='+liveId),isMore=false">
  385. <image class="w48 h48" src="/static/images/after_sales.png" />
  386. <view style="text-align: center;">售后订单</view>
  387. </view>
  388. <view class=" item" @click="goMiniProgram(),isMore=false">
  389. <image class="w48 h48" src="/static/images/points.png" />
  390. <view style="text-align: center;">兑换好礼</view>
  391. </view>
  392. <view class="item" @click="getMyLottery(),isMore=false,winning=true">
  393. <image class="w48 h48" src="/static/images/health_sel.png" />
  394. <view style="text-align: center;">中奖记录</view>
  395. </view>
  396. </view>
  397. </u-popup>
  398. <!-- 商品弹窗 -->
  399. <!-- show="true" -->
  400. <u-popup :show="shopping" @close="closeShop" round='20rpx' bgColor='#f3f5f9' zIndex='10075'>
  401. <view class="shoppop">
  402. <view class="shoppop-top">
  403. <view class="search-input x-f">
  404. <image class="w24 mr16" src="/static/images/search.png" mode="widthFix" />
  405. <input placeholder="请搜索商品" v-model="inputInfo" @input="handleSearchInput" />
  406. </view>
  407. <view class=" search-top" @click="navgetTo('/pages_shopping/live/order')">
  408. <image class="w48 h48" src="/static/images/carts.png" />
  409. <view style="text-align: center;">订单</view>
  410. </view>
  411. <view class="search-top" @click="isMore=true,shopping=false">
  412. <image class="w48 h48" src="/static/images/search2.png" />
  413. <view style="text-align: center;">更多</view>
  414. </view>
  415. </view>
  416. <!-- <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  417. <view class="list-item" v-for="(item,index) in products" :key="index">
  418. <view class="goods-img">
  419. <image class="img" :src="item.imgUrl" mode="widthFix" />
  420. <view class="goods-label">{{index+1}}</view>
  421. </view>
  422. <view class="goods-right">
  423. <view class="goods-title">{{item.productName}}</view>
  424. <view class="goods-people">{{item.sales}} 人已购</view>
  425. <view class="goods-shop">
  426. <text class="nummber"><text style="font-size: 20rpx;font-weight: 600;">¥</text><text
  427. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}</text>
  428. <view class="btn-group x-f">
  429. <view class="collect-btn">
  430. <image v-if="item.isFavorite" @click="onGoodsCollect(item)" class="w36 h36"
  431. style="vertical-align: middle;"
  432. src="/static/images/collect_select.png" />
  433. <image v-else @click="onGoodsCollect(item)" class="w36 h36"
  434. style="vertical-align: middle;" src="/static/images/collect.png" />
  435. </view>
  436. <view v-if="item.status==1" class="shop-btn"
  437. @click="goShop(item.productId,item.goodsId)">去购买 </view>
  438. <view v-else-if="item.status==0" class="shop-btn">
  439. 已下架</view>
  440. </view>
  441. </view>
  442. </view>
  443. </view>
  444. </scroll-view> -->
  445. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  446. <!-- 骨架屏 -->
  447. <view v-if="loadingProducts && products.length === 0" class="skeleton-list">
  448. <view v-for="n in 6" :key="n" class="skeleton-item">
  449. <view class="skeleton-img"></view>
  450. <view class="skeleton-content">
  451. <view class="skeleton-line short"></view>
  452. <view class="skeleton-line medium"></view>
  453. <view class="skeleton-line long"></view>
  454. </view>
  455. </view>
  456. </view>
  457. <!-- 实际商品列表 -->
  458. <template v-else>
  459. <view v-for="(item,index) in products" :key="index" class="list-item">
  460. <view class="goods-img">
  461. <image class="img" :src="item.imgUrl" mode="widthFix" />
  462. <view class="goods-label">{{index+1}}</view>
  463. </view>
  464. <view class="goods-right">
  465. <view class="goods-title">{{item.productName}}</view>
  466. <view class="goods-people">{{item.sales}} 人已购</view>
  467. <view class="goods-shop">
  468. <text class="nummber"><text
  469. style="font-size: 20rpx;font-weight: 600;">¥</text><text
  470. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}</text>
  471. <view class="btn-group x-f">
  472. <view class="collect-btn">
  473. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  474. class="w36 h36" style="vertical-align: middle;"
  475. src="/static/images/collect_select.png" />
  476. <image v-else @click="onGoodsCollect(item)" class="w36 h36"
  477. style="vertical-align: middle;" src="/static/images/collect.png" />
  478. </view>
  479. <view v-if="item.status==1" class="shop-btn"
  480. @click="goShop(item.productId,item.goodsId)">去购买 </view>
  481. <view v-else-if="item.status==0" class="shop-btn">
  482. 已下架</view>
  483. </view>
  484. </view>
  485. </view>
  486. </view>
  487. </template>
  488. </scroll-view>
  489. </view>
  490. </u-popup>
  491. <!-- 优惠券弹窗 -->
  492. <view class="coupon-pop" v-if="isShowCoupon">
  493. <view class="coupon-block">
  494. <image class="bg" src="/static/images/coupon_bg.png" />
  495. <image class="nav" src="/static/images/coupon_top.png" />
  496. <image @click="isShowCoupon=false" class="w40 h40 close" style="z-index: 99;"
  497. src="/static/images/close1.png" />
  498. <view class="item">
  499. <view class="title">{{couponInfo.couponName}}</view>
  500. <view class="price">¥<text class="bold">{{couponInfo.couponPrice}}</text></view>
  501. <view class="txt">满{{couponInfo.useMinPrice}}元可用</view>
  502. <view class="txt" style="margin-top: 26rpx;">指定商品可用</view>
  503. <view class="txt">自领取起{{couponInfo.couponTime}}天内有效</view>
  504. <view class="button" @click="onCoupon()">
  505. 立即领券
  506. </view>
  507. </view>
  508. </view>
  509. </view>
  510. </view>
  511. </view>
  512. </template>
  513. <script>
  514. import LikeButton from '@/pages_course/components/like.vue'
  515. import ThreeItemSwiper from '@/pages_course/components/ThreeItemSwiper.vue'
  516. import CryptoJS from 'crypto-js'
  517. import {
  518. myLottery, // 我的中奖明细
  519. coupon, //领取优惠券
  520. liveLottery, // 抽奖查询
  521. claim, //抽奖
  522. liveRed, // 点击领红包
  523. liveDataLike, // 点赞
  524. collectStore, // 店铺收藏/取消收藏
  525. collectGoods, // 商品收藏/取消收藏
  526. watchUserList, //获取直播间用户(展示在线用户)
  527. liveMsg, //获取最近聊天记录
  528. // 小黄车
  529. liveStore, //店铺展示,
  530. liveOrderUser, //正在购买
  531. getLiveInfo, //获取直播间信息接口
  532. getLiveViewData, //直播间点赞、关注、在线人数数据
  533. currentActivities, //红包 卡片 抽奖
  534. getlive,
  535. subNotifyLive,
  536. internetTraffic, // 流量(缓冲百分比),
  537. liveInternetTraffic // 直播流量(缓冲百分比),
  538. } from '@/api/living.js'
  539. import {
  540. getUserInfo
  541. } from '@/api/user'
  542. import {
  543. generateRandomString
  544. } from "@/utils/common.js"
  545. import dayjs from 'dayjs';
  546. import {
  547. nextTick
  548. } from "vue"
  549. var isSocketOpen = false;
  550. var socket = null;
  551. export default {
  552. components: {
  553. ThreeItemSwiper,
  554. LikeButton
  555. },
  556. data() {
  557. return {
  558. uuId: "",
  559. totalTraffic: 0, // 总流量(字节)
  560. bitrate: 800, // 录播默认码率 0.16Mbps
  561. bitrateLive: 1600, // 直播默认码率 0.16Mbps
  562. //定时器
  563. trafficTimer: null,
  564. pingTimeoutTimer: null, // 心跳超时定时器
  565. heartBeatTimer: null, // 心跳定时器
  566. liveViewDataTimer: null,
  567. reconnectTimer: null, // 重连定时器
  568. scrollTimer: null, // 滚动防抖定时器
  569. searchTimer: null, //搜索
  570. purchasePromptTimer: null, //购买提示
  571. welcomeTimer: null, //进入离开直播间定时器
  572. redTimer: null,
  573. liveStartTimer: null,
  574. lotteryTimer: null,
  575. stayTime: 0,
  576. startTime: 0,
  577. scrollTop: 0,
  578. isOnload: false,
  579. isConnecting: false, // 是否正在连接中
  580. hasInitialized: false,
  581. liveViewersData: [],
  582. liveUserCalled: false, //调用过watchUserList没
  583. userRandomColors: Object.create(null), // 缓存用户ID -> 随机色的映射
  584. heartBeatRetryCount: 0, // 心跳发送重试次数(避免一次失败就重连)
  585. maxHeartBeatRetries: 2, // 心跳最大重试次数
  586. pingTimeout: 20000, // 心跳超时时间从10s延长到20s(应对网络波动)
  587. shownEntryUsers: new Set(), // 存储已显示过「进入提示」的用户ID
  588. socket: null, // WebSocket 实例
  589. isSocketOpen: false, // 连接是否已打开
  590. heartBeatInterval: 15000, // 心跳发送间隔(15秒)
  591. reconnectCount: 0, // 当前重连次数
  592. maxReconnectAttempts: 3, // 最大重连次数
  593. isManualClose: false, // 是否手动关闭(用于区分主动关闭和异常断开)
  594. templateId: 'fxYJu817lxHNKXl0hJypb-y-lLm8CNmGbcwpQmasCVg',
  595. isAgreement: false,
  596. wsNewUrl: 'wss://api.fhhx.runtzh.com/ws/app/webSocket',
  597. // wsNewUrl: 'ws://192.168.10.166:7114/ws/app/webSocket',
  598. qrFrom: null,
  599. scene: '',
  600. liveCountdown: {}, //直播倒计时
  601. countdown: {}, //抽奖倒计时
  602. liveViewData: {},
  603. keyboardHeight: 0,
  604. videoCurrentTime: 0, // 当前视频播放时间
  605. videoProgressKey: '', // 存储进度的key
  606. inAndOut: {},
  607. winning: false,
  608. isShowPrize: false,
  609. isShowCoupon: false,
  610. prizeInfo: [],
  611. havePrize: uni.getStorageSync('havePrize') || false, //是否参与抽奖
  612. countDownKey: 0,
  613. lotteryProducts: [],
  614. lotteryList: [],
  615. talklist: [],
  616. isShowLotteryPop: false,
  617. liveItem: {},
  618. isSending: false,
  619. isMore: false,
  620. value: '',
  621. placeholderText: '说点什么...',
  622. prizeAll: [],
  623. isShowLottery: false,
  624. isShowRedCard: false,
  625. redCard: null, //点击红包出现弹窗
  626. integral: {},
  627. lotteryInfo: {},
  628. goodsCard: {},
  629. couponInfo: {},
  630. redInfo: {},
  631. storeId: null,
  632. isFocus: false,
  633. shopping: false,
  634. inputInfo: '',
  635. showWelcomeMessage: false,
  636. scrollIntoView: '',
  637. isShowGoods: false,
  638. isShowRed: false,
  639. lastClickTime: 0,
  640. videoRetryCounts: Object.create(null), // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  641. clickDelay: 300, // 300ms内只响应一次点击
  642. liveUserTotal: 0,
  643. viewPageSize: 10, // 每页数量
  644. viewPageNum: 1, // 当前页码
  645. viewLoading: false, // 是否正在加载
  646. scrollHeight: 0,
  647. showPurchasePrompt: false,
  648. prevOrderCount: 0, // 用于记录上一次的购买人数
  649. videoUrl: null,
  650. showType: 1, //横屏1 竖屏2
  651. boxHeight: 300, //小黄车高度
  652. liveViewers: [], //观众
  653. livingUrl: "",
  654. products: [],
  655. loadingProducts: false, // 商品加载状态
  656. orderUser: {}, //正在购买
  657. userType: 0,
  658. timestamp: '',
  659. showadd: false,
  660. liveId: null,
  661. userinfo: '', //用户信息
  662. userData: {},
  663. diffTotalTime: ''
  664. };
  665. },
  666. async onLoad(options) {
  667. if (options.liveId) {
  668. this.liveId = options.liveId;
  669. }
  670. // 扫码传来的参数
  671. if (options.scene) {
  672. this.scene = options.scene;
  673. const decodedScene = decodeURIComponent(this.scene);
  674. const params = {};
  675. decodedScene.split('&').forEach(item => {
  676. const [key, value] = item.split('=');
  677. params[key] = value;
  678. this.liveId = params.a;
  679. })
  680. if (params.b && params.c) {
  681. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  682. }
  683. }
  684. if (options.companyId && options.companyUserId) {
  685. this.qrFrom = `&companyId=${options.companyId}&companyUserId=${options.companyUserId}`;
  686. }
  687. this.userinfo = uni.getStorageSync("userInfo")
  688. this.userData = uni.getStorageSync("userData")
  689. console.log("全部参数", options)
  690. try {
  691. const isLogin = await this.utils.isLogin();
  692. if (isLogin) {
  693. await this.getUserInfo();
  694. this.initTime();
  695. if (this.liveId) {
  696. // 先获取直播间信息
  697. await this.getliving(this.liveId);
  698. this.isOnload = true;
  699. // 然后获取聊天记录
  700. await this.getLiveMsg(this.liveId);
  701. await this.getliveViewData(this.liveItem);
  702. }
  703. }
  704. } catch (error) {
  705. console.error("初始化失败:", error);
  706. }
  707. //获取键盘高度
  708. uni.onKeyboardHeightChange(res => {
  709. this.keyboardHeight = res.height * 2;
  710. });
  711. },
  712. onPullDownRefresh() {
  713. this.getLiveMsg(this.liveId)
  714. this.getliveUser()
  715. setTimeout(() => {
  716. uni.stopPullDownRefresh()
  717. }, 1000)
  718. },
  719. async onShow() {
  720. if (this.liveId) {
  721. await this.getLiveMsg(this.liveItem);
  722. }
  723. if (!this.liveViewData) {
  724. this.getliveViewData(this.liveItem);
  725. }
  726. if (!this.userData) {
  727. await this.getUserInfo()
  728. }
  729. this.uuId = generateRandomString(16)
  730. const isLiveLogin = uni.getStorageSync('isLiveLogin')
  731. this.share = uni.getStorageSync('share')
  732. this.scene = uni.getStorageSync('scene')
  733. if (this.share && this.share.length > 0) {
  734. this.liveId = this.share.liveId
  735. this.qrFrom = `&companyId=${this.share.companyId}&companyUserId=${this.share.companyUserId}`;
  736. uni.removeStorageSync('share')
  737. }
  738. if (this.scene) {
  739. const decodedScene = decodeURIComponent(this.scene);
  740. const params = {};
  741. decodedScene.split('&').forEach(item => {
  742. const [key, value] = item.split('=');
  743. params[key] = value;
  744. this.liveId = params.a;
  745. })
  746. if (params.b && params.c) {
  747. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  748. }
  749. uni.removeStorageSync('scene')
  750. }
  751. if (isLiveLogin) {
  752. if (this.liveId) {
  753. await this.getliving(this.liveId)
  754. this.getCurrentActivities()
  755. this.getliveOrder()
  756. this.initSocket()
  757. }
  758. this.hasInitialized = true
  759. uni.removeStorageSync('isLiveLogin');
  760. }
  761. // 恢复播放和连接
  762. await this.resumePageActivity()
  763. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  764. this.isAgreement = uni.getStorageSync('isAgreement')
  765. this.$nextTick(() => {
  766. this.setVideoProgress();
  767. });
  768. if (this.lookTimer) {
  769. clearInterval(this.lookTimer)
  770. this.lookTimer = null;
  771. this.stayTime = 0;
  772. this.startTime = 0;
  773. }
  774. if (this.trafficTimer) {
  775. clearInterval(this.trafficTimer)
  776. this.trafficTimer = null;
  777. this.startTime = 0;
  778. this.totalTraffic = 0;
  779. }
  780. this.startTimer()
  781. },
  782. //分享给好友
  783. onShareAppMessage() {
  784. return {
  785. title: '邀请你来观看直播:' + this.liveItem.liveName,
  786. path: '/pages_course/living?companyId=-2&companyUserId=' + this.userData.userId + '&liveId=' + this.liveId,
  787. imageUrl: '/static/images/logo.png',
  788. success(res) {
  789. console.log("分享成功", res);
  790. },
  791. fail(err) {
  792. console.error("分享失败", err);
  793. }
  794. };
  795. },
  796. computed: {
  797. filteredViewers() {
  798. const safeLiveViewers = Array.isArray(this.liveViewersData) ? this.liveViewersData : [];
  799. // 截取前3项
  800. return safeLiveViewers.slice(0, 3);
  801. },
  802. isCurrentUserWon() {
  803. if (!Array.isArray(this.prizeInfo) || !this.userData?.userId) {
  804. return false;
  805. }
  806. return this.prizeInfo.some(item => {
  807. return String(item.userId) === String(this.userData.userId);
  808. });
  809. }
  810. },
  811. onHide() {
  812. // 清除所有定时器
  813. this.clearAllTimers();
  814. this.stopHeartBeat()
  815. },
  816. onUnload() {
  817. this.stopHeartBeat()
  818. this.saveVideoProgress()
  819. if (this.liveItem) {
  820. this.pauseVideo()
  821. // 清除直播间的时间定时器
  822. if (this.liveItem.timeTimer) {
  823. clearInterval(this.liveItem.timeTimer);
  824. this.liveItem.timeTimer = null; // 清空定时器标识
  825. }
  826. }
  827. this.liveUserCalled = false
  828. this.loadUserColorsFromStorage();
  829. // 先关闭WebSocket
  830. this.closeWebSocket(true);
  831. // 清除所有定时器
  832. this.clearAllTimers();
  833. // 暂停视频
  834. const videoId = `myVideo_${this.liveId}`;
  835. const videoContext = uni.createVideoContext(videoId, this);
  836. if (videoContext) {
  837. videoContext.pause();
  838. }
  839. // 清理大数据
  840. this.talklist = [];
  841. this.liveViewersData = [];
  842. this.liveViewers = [];
  843. this.products = [];
  844. this.liveItem = [];
  845. },
  846. mounted() {
  847. this.getCurrentActivities();
  848. this.getliveOrder()
  849. },
  850. watch: {
  851. // 监听liveItem.status的变化
  852. 'liveItem.status': {
  853. handler(newStatus, oldStatus) {
  854. if (newStatus === undefined || oldStatus === undefined) return;
  855. if (newStatus === oldStatus) return;
  856. if (!this.liveId) {
  857. console.warn("liveId不存在,无法触发getliving请求");
  858. return;
  859. }
  860. // 状态变化时,调用getliving更新直播间数据
  861. // console.log(`liveItem.status从${oldStatus}变为${newStatus},触发getliving请求`);
  862. this.getliving(this.liveId);
  863. },
  864. deep: true,
  865. },
  866. // 监听orderUser.count的变化
  867. 'orderUser.count': {
  868. handler(newVal, oldVal) {
  869. if (newVal !== this.prevOrderCount) {
  870. this.prevOrderCount = newVal;
  871. this.showPurchaseMessage();
  872. }
  873. },
  874. immediate: true
  875. }
  876. },
  877. methods: {
  878. // 定期清理视频缓存
  879. startVideoCacheCleanup() {
  880. if (this.videoCleanupTimer) {
  881. clearInterval(this.videoCleanupTimer);
  882. }
  883. // 每30秒清理一次视频缓存
  884. this.videoCleanupTimer = setInterval(() => {
  885. this.cleanupVideoCache();
  886. }, 30000);
  887. },
  888. // 清理视频缓存
  889. cleanupVideoCache() {
  890. if (!this.liveItem || !this.liveId) return;
  891. // 只对录播视频进行清理
  892. if (this.liveItem.liveType === 2 && this.liveItem.videoUrl) {
  893. this.reloadVideoPlayer();
  894. }
  895. },
  896. // 重新加载视频播放器
  897. reloadVideoPlayer() {
  898. const videoId = `myVideo_${this.liveId}`;
  899. const videoContext = uni.createVideoContext(videoId, this);
  900. if (videoContext) {
  901. const currentTime = this.videoCurrentTime;
  902. // 暂停视频
  903. videoContext.pause();
  904. // 延迟重新加载
  905. setTimeout(() => {
  906. // 重新设置视频源,强制清理缓存
  907. this.$set(this.liveItem, 'videoUrl', this.liveItem.videoUrl + '&t=' + Date.now());
  908. // 恢复播放位置
  909. setTimeout(() => {
  910. if (videoContext.seek) {
  911. videoContext.seek(currentTime);
  912. }
  913. videoContext.play();
  914. }, 500);
  915. }, 100);
  916. }
  917. },
  918. // 启动内存监控
  919. startMemoryMonitoring() {
  920. if (this.memoryMonitorTimer) {
  921. clearInterval(this.memoryMonitorTimer);
  922. }
  923. this.memoryMonitorTimer = setInterval(() => {
  924. this.checkMemoryUsage();
  925. }, 15000); // 每15秒检查一次
  926. },
  927. // 检查内存使用情况
  928. checkMemoryUsage() {
  929. // 在微信小程序中,可以通过性能监控API检查内存
  930. if (wx && wx.getPerformance) {
  931. try {
  932. const performance = wx.getPerformance();
  933. const memory = performance.memory;
  934. if (memory && memory.usedJSHeapSize > 50 * 1024 * 1024) { // 超过50MB
  935. console.warn('内存使用过高,触发清理:', memory.usedJSHeapSize);
  936. this.forceMemoryCleanup();
  937. }
  938. } catch (e) {
  939. console.log('无法获取内存信息');
  940. }
  941. }
  942. },
  943. // 强制内存清理
  944. forceMemoryCleanup() {
  945. console.log('执行强制内存清理');
  946. // 1. 清理视频播放器
  947. this.cleanupVideoPlayer();
  948. // 2. 清理大数据
  949. this.clearBigData();
  950. // 3. 强制垃圾回收(在支持的环境下)
  951. this.triggerGarbageCollection();
  952. },
  953. // 清理视频播放器
  954. cleanupVideoPlayer() {
  955. const videoId = `myVideo_${this.liveId}`;
  956. const videoContext = uni.createVideoContext(videoId, this);
  957. if (videoContext) {
  958. // 停止播放
  959. videoContext.stop();
  960. // 重置视频源
  961. setTimeout(() => {
  962. this.$set(this.liveItem, 'videoUrl', '');
  963. setTimeout(() => {
  964. this.$set(this.liveItem, 'videoUrl', this.getFreshVideoUrl());
  965. this.playVideo();
  966. }, 500);
  967. }, 100);
  968. }
  969. },
  970. // 获取带时间戳的新视频URL
  971. getFreshVideoUrl() {
  972. if (!this.liveItem.originalVideoUrl) {
  973. this.liveItem.originalVideoUrl = this.liveItem.videoUrl;
  974. }
  975. // 添加时间戳参数,避免缓存
  976. const separator = this.liveItem.originalVideoUrl.includes('?') ? '&' : '?';
  977. return this.liveItem.originalVideoUrl + separator + 't=' + Date.now();
  978. },
  979. // 清理大数据
  980. clearBigData() {
  981. // 清理聊天记录,只保留最近50条
  982. if (this.talklist.length > 50) {
  983. this.talklist = this.talklist.slice(-50);
  984. }
  985. // 清理观众数据
  986. if (this.liveViewersData.length > 100) {
  987. this.liveViewersData = this.liveViewersData.slice(-100);
  988. }
  989. // 清理虚拟数据
  990. if (this.liveViewers.length > 100) {
  991. this.liveViewers = this.liveViewers.slice(-100);
  992. }
  993. // 清理商品数据
  994. if (this.products.length > 50) {
  995. this.products = this.products.slice(0, 50);
  996. }
  997. },
  998. // 触发垃圾回收(在支持的环境下)
  999. triggerGarbageCollection() {
  1000. if (wx && wx.triggerGC) {
  1001. wx.triggerGC();
  1002. }
  1003. },
  1004. goMiniProgram() {
  1005. // uni.navigateToMiniProgram({
  1006. // appId: 'wx45cf09091aead547',
  1007. // path: '/pages/home/index',
  1008. // success: function(res) {
  1009. // console.log('跳转成功', res);
  1010. // },
  1011. // fail: function(err) {
  1012. // console.error('跳转失败', err);
  1013. // }
  1014. // });
  1015. uni.showToast({
  1016. title: '系统升级中,兑换请联系伴学助手!',
  1017. icon: 'none'
  1018. });
  1019. },
  1020. // 阻止双击事件
  1021. preventDoubleClick(e) {
  1022. e.preventDefault();
  1023. e.stopPropagation();
  1024. return false;
  1025. },
  1026. // 清理所有定时器
  1027. clearAllTimers() {
  1028. if (this.scrollTimer) {
  1029. clearTimeout(this.scrollTimer);
  1030. this.scrollTimer = null;
  1031. }
  1032. if (this.liveViewDataTimer) {
  1033. clearInterval(this.liveViewDataTimer);
  1034. this.liveViewDataTimer = null;
  1035. }
  1036. if (this.redTimer) {
  1037. clearInterval(this.redTimer);
  1038. this.redTimer = null;
  1039. }
  1040. if (this.liveStartTimer) {
  1041. clearInterval(this.liveStartTimer);
  1042. this.liveStartTimer = null;
  1043. }
  1044. if (this.lotteryTimer) {
  1045. clearInterval(this.lotteryTimer);
  1046. this.lotteryTimer = null;
  1047. }
  1048. if (this.welcomeTimer) {
  1049. clearInterval(this.welcomeTimer);
  1050. this.welcomeTimer = null;
  1051. }
  1052. if (this.trafficInterval != null) {
  1053. clearInterval(this.trafficInterval)
  1054. }
  1055. if (this.lookTimer) {
  1056. clearInterval(this.lookTimer)
  1057. this.lookTimer = null;
  1058. this.stayTime = 0;
  1059. this.startTime = 0;
  1060. }
  1061. if (this.trafficTimer) {
  1062. clearInterval(this.trafficTimer)
  1063. this.trafficTimer = null;
  1064. this.startTime = 0;
  1065. this.totalTraffic = 0;
  1066. }
  1067. if (this.intervalId) {
  1068. clearInterval(this.intervalId);
  1069. this.intervalId = null;
  1070. }
  1071. if (this.reconnectTimer) {
  1072. clearInterval(this.reconnectTimer);
  1073. this.reconnectTimer = null;
  1074. }
  1075. if (this.scrollTimer) {
  1076. clearTimeout(this.scrollTimer);
  1077. this.scrollTimer = null;
  1078. }
  1079. if (this.searchTimer) {
  1080. clearTimeout(this.searchTimer);
  1081. this.searchTimer = null;
  1082. }
  1083. if (this.purchasePromptTimer) {
  1084. clearTimeout(this.purchasePromptTimer);
  1085. this.purchasePromptTimer = null;
  1086. }
  1087. },
  1088. //直播计算流量
  1089. startTrafficCalculation(bitrate) {
  1090. if (this.trafficTimer) {
  1091. clearInterval(this.trafficTimer);
  1092. this.trafficTimer = null;
  1093. }
  1094. this.startTime = Date.now();
  1095. var that = this
  1096. this.trafficTimer = setInterval(() => {
  1097. that.calculateTraffic(bitrate);
  1098. console.log("liveItem在这里>>>", this.liveItem)
  1099. }, 10000); // 每10秒计算一次
  1100. },
  1101. // 计算流量
  1102. calculateTraffic(bitrate) {
  1103. const currentTime = Date.now();
  1104. const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  1105. // 流量 = 码率 × 时间
  1106. // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  1107. const trafficBits = bitrate * duration;
  1108. // 转换为字节
  1109. this.totalTraffic = trafficBits / 8;
  1110. this.getLiveInternetTraffic()
  1111. },
  1112. startTimer() {
  1113. this.startTime = Date.now()
  1114. this.lookTimer = setInterval(() => {
  1115. this.stayTime = Math.floor((Date.now() - this.startTime) / 1000)
  1116. }, 1000)
  1117. },
  1118. //直播、录播缓冲
  1119. getLiveInternetTraffic() {
  1120. if (!this.liveId) return;
  1121. const currentTime = this.stayTime / this.liveItem.duration * 100;
  1122. const param = {
  1123. userId: this.userData.userId || '',
  1124. liveId: this.liveId || '',
  1125. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  1126. internetTraffic: this.totalTraffic,
  1127. }
  1128. liveInternetTraffic(param)
  1129. },
  1130. // 回放、预告缓冲
  1131. getInternetTraffic() {
  1132. if (!this.liveId || !this.liveId || !this.userData.userId || !this.uuId) return;
  1133. const currentTime = this.stayTime / this.liveItem.duration * 100;
  1134. const param = {
  1135. videoType: this.liveItem.videoType,
  1136. videoId: this.liveItem.videoId,
  1137. userId: this.userData.userId,
  1138. liveId: this.liveId,
  1139. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  1140. duration: this.liveItem.duration,
  1141. bufferRate: currentTime,
  1142. }
  1143. if (this.liveItem.status == 1) {
  1144. param.videoType = this.liveItem.previewVideoType || ''
  1145. param.videoId = this.liveItem.previewVideoId || ''
  1146. }
  1147. if (this.liveItem.liveType == 1) {
  1148. param.bufferRate = this.totalTraffic
  1149. }
  1150. internetTraffic(param)
  1151. },
  1152. scrollToBottom() {
  1153. if (this.scrollTimer) {
  1154. clearTimeout(this.scrollTimer);
  1155. }
  1156. this.scrollTimer = setTimeout(() => {
  1157. this.$nextTick(() => {
  1158. const query = uni.createSelectorQuery().in(this);
  1159. query.select('.scrolly').boundingClientRect(scrollRect => {
  1160. if (!scrollRect) return;
  1161. query.select('.scrolly').scrollOffset(scrollOffset => {
  1162. const newScrollTop = scrollOffset.scrollHeight - scrollRect
  1163. .height;
  1164. this.scrollTop = newScrollTop;
  1165. }).exec();
  1166. }).exec();
  1167. });
  1168. }, 0);
  1169. },
  1170. // 恢复页面活动
  1171. async resumePageActivity() {
  1172. if (this.liveItem) {
  1173. await this.getliving(this.liveId)
  1174. this.startTimeTimer(this.liveItem)
  1175. }
  1176. if (!this.isSocketAvailable()) {
  1177. this.initSocket()
  1178. }
  1179. },
  1180. // 获取用户专属随机色(缓存机制:同一用户始终用同一颜色)
  1181. getUserRandomColor(userId) {
  1182. if (!userId) {
  1183. return '#8978e2'; // 默认颜色
  1184. }
  1185. //如果缓存中已有该用户的颜色,直接返回
  1186. if (this.userRandomColors[userId]) {
  1187. return this.userRandomColors[userId];
  1188. }
  1189. //为新用户生成固定颜色(基于用户ID生成,不是完全随机)
  1190. const color = this.generateStableColor(userId);
  1191. this.userRandomColors[userId] = color;
  1192. // 存储到本地缓存,确保页面刷新后颜色不变
  1193. this.saveUserColorsToStorage();
  1194. return color;
  1195. }, // 基于用户ID生成稳定颜色(不是完全随机)
  1196. generateStableColor(userId) {
  1197. // 将用户ID转换为数字种子
  1198. let seed = 0;
  1199. for (let i = 0; i < userId.length; i++) {
  1200. seed = (seed * 31 + userId.charCodeAt(i)) % 1000000;
  1201. }
  1202. const colorPool = [
  1203. '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7',
  1204. '#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E9',
  1205. '#F8C471', '#82E0AA', '#F1948A', '#85C1E9', '#D7BDE2'
  1206. ];
  1207. return colorPool[seed % colorPool.length];
  1208. },
  1209. // 保存颜色映射到本地存储
  1210. saveUserColorsToStorage() {
  1211. try {
  1212. uni.setStorageSync('userRandomColors', this.userRandomColors);
  1213. } catch (e) {
  1214. console.warn('保存用户颜色缓存失败:', e);
  1215. }
  1216. },
  1217. // 从本地存储加载颜色映射
  1218. loadUserColorsFromStorage() {
  1219. try {
  1220. const cached = uni.getStorageSync('userRandomColors');
  1221. if (cached) {
  1222. this.userRandomColors = cached;
  1223. }
  1224. } catch (e) {
  1225. console.warn('加载用户颜色缓存失败:', e);
  1226. }
  1227. },
  1228. //头像名字
  1229. getNicknameInitial(nickName) {
  1230. if (!nickName || typeof nickName !== 'string') return '未';
  1231. if (/^[\u4e00-\u9fa5]/.test(nickName[0])) {
  1232. return nickName[0];
  1233. }
  1234. return nickName[0].toUpperCase();
  1235. },
  1236. async getUserInfo() {
  1237. await getUserInfo().then(
  1238. res => {
  1239. if (res.code == 200) {
  1240. this.userData = res.user;
  1241. } else {
  1242. uni.showToast({
  1243. icon: 'none',
  1244. title: "请求失败",
  1245. });
  1246. }
  1247. },
  1248. rej => {}
  1249. );
  1250. },
  1251. //订阅消息
  1252. handleAgreement() {
  1253. const templateId = this.templateId;
  1254. uni.requestSubscribeMessage({
  1255. tmplIds: [templateId],
  1256. success: (res) => {
  1257. // console.log("模板订阅状态", res[templateId]);
  1258. if (res[templateId] === "accept") {
  1259. uni.showToast({
  1260. title: '订阅成功,开播将提醒您',
  1261. icon: 'success'
  1262. });
  1263. this.callSendMessageApi()
  1264. } else if (res[templateId] === 'reject') {
  1265. uni.showToast({
  1266. title: '您已拒绝订阅,将无法收到提醒',
  1267. icon: 'none'
  1268. });
  1269. } else if (res[templateId] === 'ban') {
  1270. uni.showToast({
  1271. title: '您已关闭所有订阅权限,请在设置中开启',
  1272. icon: 'none'
  1273. });
  1274. }
  1275. },
  1276. fail: (err) => {
  1277. console.error('订阅消息失败', err);
  1278. uni.showToast({
  1279. title: '订阅失败,请重试',
  1280. icon: 'none'
  1281. });
  1282. }
  1283. });
  1284. },
  1285. async callSendMessageApi() {
  1286. if (!this.userData.userId) return;
  1287. const templateData = {
  1288. taskName: this.liveId,
  1289. userId: this.userData.userId,
  1290. templateId: this.templateId, // 模板ID
  1291. data: {
  1292. thing6: this.liveItem.liveName,
  1293. date7: this.liveItem.startTime,
  1294. }
  1295. };
  1296. subNotifyLive(templateData).then(res => {
  1297. if (res.code == 200) {
  1298. this.isAgreement = true;
  1299. uni.setStorageSync('isAgreement', true);
  1300. } else {
  1301. uni.showToast({
  1302. title: res.msg,
  1303. icon: 'none'
  1304. });
  1305. }
  1306. },
  1307. rej => {}
  1308. );
  1309. },
  1310. //发送心跳
  1311. sendHeartBeat() {
  1312. if (!this.isSocketAvailable()) return;
  1313. try {
  1314. const heartBeatMsg = JSON.stringify({
  1315. cmd: "heartbeat",
  1316. msg: "ping",
  1317. userId: this.userData.userId || '',
  1318. liveId: this.liveId
  1319. });
  1320. this.socket.send({
  1321. data: heartBeatMsg,
  1322. success: () => {
  1323. this.heartBeatRetryCount = 0; // 成功后重置重试次数
  1324. this.startPingTimeout(); // 启动超时检测
  1325. },
  1326. fail: (err) => {
  1327. console.error("心跳包发送失败:", err);
  1328. this.heartBeatRetryCount++;
  1329. // 心跳失败先重试,重试次数用完再重连
  1330. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  1331. setTimeout(() => this.sendHeartBeat(), 2000); // 2秒后重试
  1332. } else {
  1333. this.heartBeatRetryCount = 0;
  1334. this.handleReconnect(); // 重试用完才重连
  1335. }
  1336. }
  1337. });
  1338. } catch (err) {
  1339. console.error("心跳发送异常:", err);
  1340. this.heartBeatRetryCount++;
  1341. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  1342. setTimeout(() => this.sendHeartBeat(), 2000);
  1343. } else {
  1344. this.heartBeatRetryCount = 0;
  1345. this.handleReconnect();
  1346. }
  1347. }
  1348. },
  1349. // 启动心跳超时检测
  1350. startPingTimeout() {
  1351. // 清除之前的超时定时器
  1352. if (this.pingTimeoutTimer) {
  1353. clearTimeout(this.pingTimeoutTimer);
  1354. this.pingTimeoutTimer = null;
  1355. }
  1356. // 超时后触发重连
  1357. this.pingTimeoutTimer = setTimeout(() => {
  1358. // console.error("心跳响应超时,连接异常");
  1359. this.handleReconnect();
  1360. }, this.pingTimeout);
  1361. },
  1362. stopHeartBeat() {
  1363. if (this.heartBeatTimer) {
  1364. clearInterval(this.heartBeatTimer);
  1365. this.heartBeatTimer = null;
  1366. }
  1367. if (this.pingTimeoutTimer) {
  1368. clearTimeout(this.pingTimeoutTimer);
  1369. this.pingTimeoutTimer = null;
  1370. }
  1371. }, // 封装通用的连接状态校验方法
  1372. isSocketAvailable() {
  1373. // WebSocket readyState:0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
  1374. return this.socket && this.isSocketOpen && this.socket.readyState === 1;
  1375. },
  1376. // 处理重连逻辑
  1377. handleReconnect() {
  1378. this.resetReconnectState();
  1379. // uni.onNetworkStatusChange(res=>{
  1380. // if (res.networkType === 'wifi') {
  1381. // }
  1382. // })
  1383. this.stopHeartBeat();
  1384. if (this.reconnectCount < this.maxReconnectAttempts) {
  1385. this.reconnectCount++;
  1386. const delay = 1000;
  1387. console.log(`第${this.reconnectCount}次重连,延迟${delay}ms`);
  1388. this.reconnectTimer = setInterval(() => {
  1389. this.initSocket();
  1390. }, delay);
  1391. } else {
  1392. console.log(`停止重连(手动关闭/已达最大次数)`);
  1393. this.closeWebSocket(true);
  1394. }
  1395. },
  1396. // 重置重连状态
  1397. resetReconnectState() {
  1398. this.reconnectCount = 0;
  1399. if (this.reconnectTimer) {
  1400. clearInterval(this.reconnectTimer);
  1401. this.reconnectTimer = null;
  1402. }
  1403. },
  1404. //输入框
  1405. inputFocus() {
  1406. // this.chatHeight = this.keyboardHeight;
  1407. this.isFocus = true;
  1408. },
  1409. inputBlur() {
  1410. // this.chatHeight = 0;
  1411. this.isFocus = false
  1412. },
  1413. getTimeDifferenceInSeconds(createTimeStr) {
  1414. const createTime = new Date(createTimeStr.replace(/-/g, '/'));
  1415. const now = new Date();
  1416. const timeDiffMs = now - createTime;
  1417. const timeDiffSeconds = Math.floor(timeDiffMs / 1000);
  1418. return Math.max(0, timeDiffSeconds);
  1419. },
  1420. // 录播时间点
  1421. onVideoMetaLoaded(e) {
  1422. this.videoProgressKey = `videoProgress_${this.liveId}`;
  1423. this.setVideoProgress();
  1424. },
  1425. setVideoProgress() {
  1426. // 只有录播和回放需要设置进度
  1427. if (this.liveItem.liveType !== 2 && this.liveItem.liveType !== 3) {
  1428. return;
  1429. }
  1430. let currentTime = 0;
  1431. if (this.liveItem.liveType === 2) {
  1432. // 录播:计算当前时间与开始时间的差值,对视频总时长取模
  1433. const diff = this.getTimeDifferenceInSeconds(this.liveItem.startTime);
  1434. if (diff > this.liveItem.duration) {
  1435. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  1436. currentTime = (storedProgress >= this.liveItem.duration) ? 0 : (storedProgress || 0);
  1437. } else {
  1438. currentTime = diff % this.liveItem.duration;
  1439. }
  1440. // currentTime = diff % this.liveItem.duration;
  1441. } else if (this.liveItem.liveType === 3) {
  1442. // 回放:从存储中获取进度
  1443. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  1444. currentTime = storedProgress || 0;
  1445. }
  1446. const videoId = `myVideo_${this.liveId}`;
  1447. const videoContext = uni.createVideoContext(videoId, this);
  1448. if (videoContext) {
  1449. videoContext.seek(currentTime);
  1450. }
  1451. },
  1452. onVideoWaiting(e) {
  1453. // console.log('视频等待加载', e);
  1454. //流量
  1455. if (this.liveItem.liveType == 2) {
  1456. this.startTrafficCalculation(this.bitrate);
  1457. } else {
  1458. let that = this
  1459. if (this.trafficInterval) {
  1460. clearInterval(this.trafficInterval);
  1461. this.trafficInterval = null;
  1462. }
  1463. this.trafficInterval = setInterval(function() {
  1464. that.getInternetTraffic();
  1465. }, 10000);
  1466. }
  1467. },
  1468. // 视频时间更新
  1469. onVideoTimeUpdate(e) {
  1470. // 获取当前播放时间
  1471. this.videoCurrentTime = e.detail.currentTime;
  1472. // 每隔10秒保存一次进度(避免频繁存储)
  1473. if (Math.floor(this.videoCurrentTime) % 10 === 0) {
  1474. this.saveVideoProgress();
  1475. }
  1476. // this.setVideoProgress();
  1477. },
  1478. // 视频暂停
  1479. onVideoPause(e) {
  1480. if (this.liveItem.liveType === 2) {
  1481. const videoId = `myVideo_${this.liveId}`;
  1482. const videoContext = uni.createVideoContext(videoId, this);
  1483. setTimeout(() => {
  1484. videoContext.play();
  1485. }, 100);
  1486. }
  1487. // 暂停时保存进度
  1488. this.saveVideoProgress();
  1489. },
  1490. // 视频播放
  1491. onVideoPlay(e) {},
  1492. // 设置视频当前时间
  1493. // setVideoCurrentTime(time) {
  1494. // if (!time) return;
  1495. // const videoId = `myVideo_${this.liveId}`;
  1496. // const videoContext = uni.createVideoContext(videoId, this);
  1497. // if (videoContext) {
  1498. // videoContext.seek(time);
  1499. // console.log(`设置视频播放位置: ${time}秒`);
  1500. // }
  1501. // },
  1502. // 保存视频进度
  1503. saveVideoProgress() {
  1504. if (this.videoProgressKey) {
  1505. uni.setStorage({
  1506. key: this.videoProgressKey,
  1507. data: this.videoCurrentTime,
  1508. success: () => {},
  1509. fail: (err) => {
  1510. console.error('保存视频进度失败:', err);
  1511. }
  1512. });
  1513. }
  1514. },
  1515. // 点击红包
  1516. onRed() {
  1517. if (!this.liveId) return;
  1518. if (!this.redInfo?.redId) return;
  1519. if (this.redTimer) {
  1520. clearInterval(this.redTimer);
  1521. this.redTimer = null;
  1522. }
  1523. let data = {
  1524. liveId: this.liveId,
  1525. userId: this.userData.userId,
  1526. redId: this.redInfo.redId,
  1527. }
  1528. liveRed(data).then(res => {
  1529. this.isShowRed = false
  1530. this.redCard = res
  1531. this.isShowRedCard = true
  1532. },
  1533. rej => {}
  1534. );
  1535. },
  1536. //领取优惠券
  1537. onCoupon() {
  1538. if (!this.couponInfo.couponIssueId) return;
  1539. let data = {
  1540. goodsId: this.couponInfo.goodsId,
  1541. couponIssueId: this.couponInfo.couponIssueId,
  1542. liveId: this.liveId
  1543. };
  1544. coupon(data)
  1545. .then(res => {
  1546. this.isShowCoupon = false
  1547. if (res.code == 200) {
  1548. uni.showToast({
  1549. title: res.msg,
  1550. icon: 'none'
  1551. });
  1552. } else {
  1553. uni.showToast({
  1554. title: res.msg,
  1555. icon: 'none'
  1556. });
  1557. }
  1558. })
  1559. .catch(rej => {});
  1560. },
  1561. // 我的中奖名单
  1562. getMyLottery() {
  1563. this.winning = true
  1564. myLottery().then(res => {
  1565. if (res.code == 200) {
  1566. // console.log("我的中奖名单", res)
  1567. this.prizeAll = res.data.list || {};
  1568. } else {
  1569. }
  1570. })
  1571. .catch(rej => {});
  1572. },
  1573. // 抽奖
  1574. onLottery() {
  1575. if (!this.lotteryInfo) return;
  1576. let data = {
  1577. lotteryId: this.lotteryInfo.lotteryId
  1578. };
  1579. liveLottery(data)
  1580. .then(res => {
  1581. if (res.code == 200) {
  1582. const resData = res.data || {};
  1583. this.lotteryList = Array.isArray(resData) ? resData : [];
  1584. this.lotteryProducts = Array.isArray(resData.products) ? resData.products : [];
  1585. if (resData.duration) {
  1586. this.isShowLotteryPop = true;
  1587. }
  1588. } else {
  1589. uni.showToast({
  1590. title: res.msg,
  1591. icon: 'none'
  1592. });
  1593. this.lotteryList = [];
  1594. this.lotteryProducts = [];
  1595. }
  1596. })
  1597. .catch(rej => {
  1598. uni.showToast({
  1599. title: '获取抽奖信息失败',
  1600. icon: 'none'
  1601. });
  1602. // 失败时强制重置为数组
  1603. this.lotteryList = [];
  1604. this.lotteryProducts = [];
  1605. });
  1606. },
  1607. // 参与抽奖
  1608. onClaim() {
  1609. let data = {
  1610. liveId: this.liveId,
  1611. lotteryId: this.lotteryInfo.lotteryId,
  1612. }
  1613. claim(data).then(res => {
  1614. if (res.code == 200) {
  1615. uni.showToast({
  1616. title: res.msg,
  1617. icon: 'none'
  1618. });
  1619. this.isShowLotteryPop = false
  1620. this.havePrize = true
  1621. uni.setStorageSync('havePrize', this.havePrize);
  1622. } else {
  1623. uni.showToast({
  1624. title: res.msg,
  1625. icon: 'none'
  1626. });
  1627. }
  1628. },
  1629. rej => {}
  1630. );
  1631. },
  1632. confirm() {
  1633. this.isShowPrize = false;
  1634. this.havePrize = false;
  1635. uni.setStorageSync('havePrize', this.havePrize);
  1636. },
  1637. // 商品收藏
  1638. onGoodsCollect(item) {
  1639. if (!item || item.length === 0 || !item.goodsId) {
  1640. return;
  1641. }
  1642. collectGoods(item.goodsId).then(res => {
  1643. if (res.code == 200) {
  1644. uni.showToast({
  1645. title: res.msg,
  1646. icon: 'none'
  1647. });
  1648. item.isFavorite = !item.isFavorite
  1649. } else {
  1650. uni.showToast({
  1651. title: res.msg,
  1652. icon: 'none'
  1653. });
  1654. }
  1655. },
  1656. rej => {}
  1657. );
  1658. },
  1659. //正在购买
  1660. getliveOrder(item) {
  1661. if (!this.liveId) {
  1662. return;
  1663. }
  1664. liveOrderUser(this.liveId).then(res => {
  1665. if (res.code == 200) {
  1666. this.orderUser = res;
  1667. } else {
  1668. console.log('获取正在购买用户失败');
  1669. }
  1670. },
  1671. rej => {}
  1672. );
  1673. },
  1674. onLiveStateChange(e, liveItem) {
  1675. // 可以根据状态码处理不同的直播状态
  1676. const stateCode = e.detail.code;
  1677. if (e.detail.code == -2301 || e.detail.code == -2302) {
  1678. this.playVideo()
  1679. } else if (e.detail.code == 2004) {
  1680. this.calculateTimeDiff(this.liveItem)
  1681. this.startTrafficCalculation(this.bitrateLive);
  1682. }
  1683. // 2001: 已经连接服务器
  1684. // 2002: 已经连接服务器,开始拉流
  1685. // 2003: 网络接收到首个视频数据包(IDR)
  1686. // 2004: 视频播放开始
  1687. // 2005: 视频播放进度
  1688. // 2006: 视频播放结束
  1689. // 2007: 视频播放Loading
  1690. // 2008: 解码器启动
  1691. // -2301: 网络断连,且经多次重连抢救无效,更多重试请自行重启播放
  1692. // -2302: 获取加速拉流地址失败
  1693. }, // 直播错误事件
  1694. onLiveError(e, liveItem) {
  1695. this.videoError(e, liveItem);
  1696. console.log('错误');
  1697. },
  1698. // 红包 卡片 抽奖
  1699. getCurrentActivities() {
  1700. if (!this.liveId) return;
  1701. currentActivities(this.liveId).then(res => {
  1702. if (res.code === 200) {
  1703. // 提取数据(默认空数组/对象避免报错)
  1704. this.redInfo = (Array.isArray(res.red) ? res.red : [])[0] || {};
  1705. this.lotteryInfo = (Array.isArray(res.lottery) ? res.lottery : [])[0] || {};
  1706. this.goodsCard = res.goods || {};
  1707. this.isShowGoods = this.goodsCard && this.goodsCard.status == 1;
  1708. this.isShowRed = this.redInfo && this.redInfo.redStatus == 1;
  1709. this.isShowLottery = this.lotteryInfo && this.lotteryInfo.lotteryStatus == 1;
  1710. if (this.isShowRed) {
  1711. this.redTimer = setInterval(() => {
  1712. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  1713. .duration)
  1714. if (!redCountdown) {
  1715. this.isShowRed = false
  1716. clearInterval(this.redTimer)
  1717. }
  1718. }, 1000);
  1719. }
  1720. // 处理抽奖定时器
  1721. if (this.isShowLottery) {
  1722. this.lotteryTimer = setInterval(() => {
  1723. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this
  1724. .lotteryInfo
  1725. .duration)
  1726. }, 1000);
  1727. }
  1728. } else {
  1729. uni.showToast({
  1730. title: res.msg,
  1731. icon: 'none'
  1732. });
  1733. }
  1734. }, rej => {});
  1735. },
  1736. // 计算当前时间与 liveItem.startTime 的差值,并更新 totalTime
  1737. calculateTimeDiff(item) {
  1738. if (!item.startTime) return;
  1739. // 提取对应场景的时间字符串(直播用startTime,抽奖用updateTime)
  1740. let timeStr = item.startTime;
  1741. // 转换时间格式(适配iOS,将 "-" 替换为 "/")
  1742. const time = new Date(timeStr.replace(/-/g, "/"));
  1743. if (isNaN(time.getTime())) {
  1744. return;
  1745. }
  1746. const now = new Date();
  1747. let diffMs = Math.max(0, now.getTime() - time.getTime())
  1748. // 转换为 时:分:秒(补零处理)
  1749. const totalSeconds = Math.floor(diffMs / 1000);
  1750. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  1751. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  1752. const seconds = this.padZero(totalSeconds % 60);
  1753. this.diffTotalTime = `${hours}:${minutes}:${seconds}`;
  1754. // this.$set(this.liveItem, "diffMs", diffMs);
  1755. // this.$set(this.liveItem, "totalSeconds", totalSeconds);
  1756. },
  1757. padZero(num) {
  1758. return num < 10 ? `0${num}` : num;
  1759. },
  1760. // 启动当前直播间的时间差值定时器
  1761. startTimeTimer(item) {
  1762. if (!item) return;
  1763. // 立即计算一次(避免等待1秒才显示)
  1764. const totalTime = this.calculateTimeDiff(item);
  1765. item.timeTimer = setInterval(() => {
  1766. const totalTime = this.calculateTimeDiff(item);
  1767. }, 1000);
  1768. },
  1769. toggleViewerList() {
  1770. const now = Date.now();
  1771. if (now - this.lastClickTime > this.clickDelay) {
  1772. this.showadd = !this.showadd;
  1773. if (this.showadd) {
  1774. this.getliveUser(false); // 加载第一页观众
  1775. }
  1776. this.lastClickTime = now;
  1777. }
  1778. },
  1779. // 播放视频
  1780. playVideo() {
  1781. if (!this.liveItem) {
  1782. console.log('liveItem 为空,无法播放视频');
  1783. return;
  1784. }
  1785. try {
  1786. // 直播流使用live-player
  1787. if (this.liveItem.liveType === 1 && this.liveItem.livingUrl && this.liveItem.status == 2) {
  1788. const livePlayerId = `myLivePlayer_${this.liveId}`;
  1789. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  1790. // console.log("直播")
  1791. if (livePlayerContext) {
  1792. livePlayerContext.play();
  1793. }
  1794. } else if (this.liveItem.status == 1 && this.liveItem.previewUrl) {
  1795. const videoId = `myVideo_${this.liveId}`;
  1796. const videoContext = uni.createVideoContext(videoId, this);
  1797. if (videoContext) {
  1798. videoContext.play();
  1799. }
  1800. } else if (this.liveItem.liveType === 2 && this.liveItem.videoUrl && this.liveItem.status == 2) {
  1801. const videoId = `myVideo_${this.liveId}`;
  1802. const videoContext = uni.createVideoContext(videoId, this);
  1803. // console.log("录播")
  1804. if (videoContext) {
  1805. videoContext.play();
  1806. }
  1807. } // 回放视频使用video
  1808. else if (this.liveItem.liveType === 3 && this.liveItem.videoUrl && this.liveItem.status == 4) {
  1809. const videoId = `myVideo_${this.liveId}`;
  1810. const videoContext = uni.createVideoContext(videoId, this);
  1811. // console.log("回放")
  1812. if (videoContext) {
  1813. videoContext.play();
  1814. }
  1815. }
  1816. } catch (error) {
  1817. console.error("播放视频失败:", error);
  1818. }
  1819. },
  1820. pauseVideo() {
  1821. if (!this.liveItem) return;
  1822. try {
  1823. // 直播流使用live-player
  1824. if (this.liveItem.status == 1) {
  1825. const videoId = `myVideo_${this.liveId}`;
  1826. const videoContext = uni.createVideoContext(videoId, this);
  1827. if (videoContext) {
  1828. videoContext.pause();
  1829. }
  1830. } else if (this.liveItem.status == 2) {
  1831. if (this.liveItem.liveType === 1) {
  1832. const livePlayerId = `myLivePlayer_${this.liveId}`;
  1833. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  1834. if (livePlayerContext) {
  1835. livePlayerContext.pause();
  1836. }
  1837. } else if (this.liveItem.liveType === 2) {
  1838. const videoId = `myVideo_${this.liveId}`;
  1839. const videoContext = uni.createVideoContext(videoId, this);
  1840. if (videoContext) {
  1841. videoContext.pause();
  1842. }
  1843. }
  1844. }
  1845. } catch (error) {
  1846. console.error("暂停视频失败:", error);
  1847. }
  1848. },
  1849. // 视频错误处理
  1850. videoError(e, liveItem) {
  1851. if (!liveItem || !this.liveId) return;
  1852. // 初始化重试计数
  1853. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  1854. this.videoRetryCounts[liveItem.liveId] = 0;
  1855. }
  1856. // 限制重试次数
  1857. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  1858. console.error(`直播间 ${this.liveId} 视频加载失败,停止重试`);
  1859. // 显示错误提示
  1860. uni.showToast({
  1861. title: "视频加载失败,请检查网络",
  1862. icon: 'none',
  1863. duration: 2000
  1864. });
  1865. return;
  1866. }
  1867. this.videoRetryCounts[this.liveId]++;
  1868. // 延迟重试
  1869. setTimeout(() => {
  1870. if (this.liveId === this.liveId) {
  1871. console.log(`第${this.videoRetryCounts[this.liveId]}次重试播放视频`);
  1872. this.playVideo();
  1873. }
  1874. }, 2000);
  1875. },
  1876. openViews() {
  1877. // 计算scroll-view高度
  1878. this.$nextTick(() => {
  1879. const query = uni.createSelectorQuery().in(this);
  1880. query.select('.view-box').boundingClientRect(data => {
  1881. if (data) {
  1882. this.scrollHeight = data.height - 80; // 80是标题高度,120是底部高度
  1883. }
  1884. }).exec();
  1885. });
  1886. },
  1887. // 滚动到底部触发
  1888. handleScrollToLower() {
  1889. // 清除上一次未执行的定时器,避免重复请求
  1890. if (this.scrollTimer) {
  1891. clearTimeout(this.scrollTimer);
  1892. }
  1893. // 延迟0.5秒(500毫秒)执行接口请求
  1894. this.scrollTimer = setTimeout(() => {
  1895. this.getliveUser(true);
  1896. }, 1000);
  1897. },
  1898. async getLiveMsg(liveItem) {
  1899. if (!liveItem || !this.liveId) {
  1900. console.error('getLiveMsg 错误:无效的 liveItem');
  1901. return;
  1902. }
  1903. try {
  1904. const res = await liveMsg(this.liveId, 30, 1);
  1905. if (res.code == 200) {
  1906. const rows = Array.isArray(res.rows) ? res.rows : [];
  1907. const reversedTalkList = [...rows].reverse();
  1908. this.talklist = Array.isArray(reversedTalkList) ? reversedTalkList : [];
  1909. // 获取历史消息后也滚动到底部
  1910. this.$nextTick(() => {
  1911. this.scrollToBottom();
  1912. });
  1913. } else {
  1914. this.talklist = [];
  1915. }
  1916. } catch (error) {
  1917. this.talklist = [];
  1918. console.error("获取聊天记录失败:", error);
  1919. }
  1920. },
  1921. generateRandomChineseName() {
  1922. const prefixes = [
  1923. '幸福', '快乐', '安康', '吉祥', '如意', '平安', '健康', '长寿',
  1924. '福气', '美满', '和谐', '团圆', '富贵', '荣华', '宁静', '淡泊',
  1925. '知足', '常乐', '悠然', '自在', '夕阳', '晚霞', '金秋', '银发',
  1926. '老顽童', '开心', '笑口常开', '岁月静好', '云淡风轻', '海阔天空'
  1927. ];
  1928. const suffixes = [
  1929. '老人', '大爷', '大妈', '爷爷', '奶奶', '伯伯', '阿姨', '前辈',
  1930. '先生', '女士', '长者', '翁', '婆', '哥', '姐', '友',
  1931. '客', '迷', '粉丝', '达人', '爱好者', '之家', '之人', '之心',
  1932. '之情', '之乐', '之旅', '之梦', '之歌', '之韵'
  1933. ];
  1934. const specialNames = [
  1935. '老有所乐', '知足常乐', '笑看人生', '云淡风轻', '岁月如歌',
  1936. '夕阳红', '金色年华', '老当益壮', '鹤发童颜', '老骥伏枥',
  1937. '闲云野鹤', '淡泊明志', '宁静致远', '随遇而安', '顺其自然',
  1938. '老来俏', '开心果', '老宝贝', '不老松', '常青树'
  1939. ];
  1940. // 30%概率使用特殊网名,70%使用前缀+后缀组合
  1941. if (Math.random() < 0.3) {
  1942. return specialNames[Math.floor(Math.random() * specialNames.length)];
  1943. } else {
  1944. const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
  1945. const suffix = suffixes[Math.floor(Math.random() * suffixes.length)];
  1946. return prefix + suffix;
  1947. }
  1948. },
  1949. // 获取直播间用户
  1950. async getliveUser(isLoadMore = false) {
  1951. this.viewLoading = true;
  1952. try {
  1953. const res = await watchUserList(this.liveId, this.viewPageSize, this.viewPageNum, false);
  1954. if (res.code === 200) {
  1955. const userRows = Array.isArray(res.rows) ? res.rows : [];
  1956. let array = userRows.map(item => ({
  1957. avatar: item.avatar || '',
  1958. userId: item.userId || '',
  1959. nickName: item.nickName || '未命名'
  1960. }));
  1961. // 虚拟数据
  1962. let virtualData = []
  1963. let virtualTotal = res.total * 2 + 50
  1964. this.liveUserTotal = virtualTotal
  1965. for (let i = 0; i < virtualTotal; i++) {
  1966. let data = {
  1967. avatar: '',
  1968. userId: '8565' + i,
  1969. nickName: this.generateRandomChineseName()
  1970. }
  1971. virtualData.push(data)
  1972. }
  1973. this.liveViewersData = [...array, ...virtualData]
  1974. const newRows = Array.isArray(res.rows) ? res.rows : [];
  1975. const currentViewers = Array.isArray(this.liveViewers) ? this.liveViewers : [];
  1976. let viewlist = isLoadMore ? [...currentViewers, ...newRows] : newRows;
  1977. this.liveViewers = [...viewlist, ...virtualData]
  1978. this.viewPageNum++;
  1979. }
  1980. } catch (error) {
  1981. console.error('获取观众列表失败:', error);
  1982. } finally {
  1983. this.viewLoading = false;
  1984. }
  1985. },
  1986. //小黄车搜索商品
  1987. handleSearchInput() {
  1988. // 使用防抖优化性能,避免频繁请求
  1989. clearTimeout(this.searchTimer);
  1990. this.searchTimer = setTimeout(() => {
  1991. this.queryCollect();
  1992. }, 500); // 500毫秒延迟
  1993. },
  1994. // 显示购买提示信息
  1995. showPurchaseMessage() {
  1996. // 清除之前的定时器
  1997. if (this.purchasePromptTimer) {
  1998. clearTimeout(this.purchasePromptTimer);
  1999. }
  2000. // 显示提示
  2001. this.showPurchasePrompt = true;
  2002. // 2秒后自动隐藏
  2003. this.purchasePromptTimer = setTimeout(() => {
  2004. this.showPurchasePrompt = false;
  2005. }, 2000);
  2006. },
  2007. //名字超过省略
  2008. truncateString(str, maxLength) {
  2009. if (typeof str !== 'string' || str.length <= maxLength) {
  2010. return str;
  2011. }
  2012. return str.slice(0, maxLength) + '...'; // 截断后加省略号
  2013. },
  2014. // 跳转页面
  2015. navgetTo(url) {
  2016. uni.navigateTo({
  2017. url: url
  2018. })
  2019. },
  2020. // 修改获取直播信息方法
  2021. async getliving(liveId) {
  2022. if (!liveId) return;
  2023. const param = {
  2024. id: liveId
  2025. };
  2026. try {
  2027. const res = await getlive(param);
  2028. if (res.code !== 200) {
  2029. uni.showToast({
  2030. title: res.msg,
  2031. icon: 'none'
  2032. });
  2033. return;
  2034. }
  2035. this.liveItem = Object.assign({}, this.liveItem, res.data);
  2036. // this.talklist = Array.isArray((res.data || {}).talklist) ? res.data.talklist : [];
  2037. this.startTimeTimer(this.liveItem);
  2038. // 清除旧定时器(如预告倒计时)
  2039. if (this.liveStartTimer) {
  2040. clearInterval(this.liveStartTimer);
  2041. this.liveStartTimer = null;
  2042. }
  2043. if (res.data.status == 1) {
  2044. // 直播预告
  2045. this.liveStartTimer = setInterval(async () => {
  2046. this.liveCountdown = this.handleTime(res.data.startTime, 0);
  2047. if (!this.liveCountdown) {
  2048. uni.removeStorageSync('isAgreement');
  2049. await this.getliving(this.liveId);
  2050. clearInterval(this.liveStartTimer);
  2051. }
  2052. }, 1000);
  2053. this.$set(this.liveItem, 'previewUrl', res.data.previewUrl);
  2054. this.$set(this.liveItem, 'livingUrl', ''); // 清空直播流
  2055. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  2056. } else if (res.data.status == 2) {
  2057. if (res.data.liveType == 1) {
  2058. // 直播流
  2059. let cTime = Math.floor(Math.random() * 10000) + 1;
  2060. let livingUrl = res.data.flvHlsUrl + "&t=" + cTime;
  2061. console.log("地址在", this.liveItem.livingUrl)
  2062. this.$set(this.liveItem, 'livingUrl', livingUrl);
  2063. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  2064. } else if (res.data.liveType === 2) {
  2065. // 回放视频 2录播 3直播回放
  2066. // let urlStr = 'https://fs-1319721001.cos.ap-chongqing.myqcloud.com/10%E6%9C%8820%E6%97%A5%20%281%29.m3u8'
  2067. // this.$set(this.liveItem, 'videoUrl', urlStr);
  2068. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  2069. this.$set(this.liveItem, 'livingUrl', '');
  2070. }
  2071. } else if (res.data.status == 4 && res.data.liveType == 3) {
  2072. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  2073. this.$set(this.liveItem, 'livingUrl', '');
  2074. } else {
  2075. // 未开播
  2076. this.$set(this.liveItem, 'livingUrl', '');
  2077. this.$set(this.liveItem, 'videoUrl', '');
  2078. }
  2079. this.$set(this.liveItem, 'autoplay', res.data.liveType !== 0);
  2080. this.$set(this.liveItem, 'showType', res.data.showType);
  2081. this.storeId = res.storeId;
  2082. // 启动“30秒刷新直播间数据”的定时器
  2083. this.startLiveViewDataTimer();
  2084. this.playVideo();
  2085. } catch (err) {
  2086. console.error("获取直播信息失败:", err);
  2087. uni.showToast({
  2088. title: "获取直播信息失败",
  2089. icon: 'none'
  2090. });
  2091. }
  2092. },
  2093. getPureDecimal(num, precision = 6) {
  2094. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  2095. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  2096. },
  2097. goBack() {
  2098. // 暂停当前视频
  2099. if (this.liveItem) {
  2100. this.pauseVideo();
  2101. }
  2102. // 关闭WebSocket连接
  2103. this.closeWebSocket(true);
  2104. // 导航返回
  2105. const pages = getCurrentPages();
  2106. if (pages.length > 1) {
  2107. uni.navigateBack();
  2108. } else {
  2109. uni.reLaunch({
  2110. url: '/pages_course/livingList'
  2111. });
  2112. }
  2113. },
  2114. // 点赞
  2115. async onLike() {
  2116. console.log("点到了")
  2117. if (!this.liveId) return;
  2118. try {
  2119. const res = await liveDataLike(this.liveId);
  2120. if (res?.like) {
  2121. this.liveViewData.like++; // 只更新当前直播间的点赞数
  2122. } else {
  2123. uni.showToast({
  2124. title: res.msg,
  2125. icon: 'none'
  2126. });
  2127. }
  2128. } catch (error) {
  2129. console.error('点赞失败:', error);
  2130. }
  2131. },
  2132. //直播间点赞、关注、在线人数数据
  2133. getliveViewData(liveItem) {
  2134. if (!liveItem || !this.liveId) return;
  2135. getLiveViewData(this.liveId).then(res => {
  2136. if (res.code == 200) {
  2137. // 强制响应式更新,确保数据实时显示
  2138. this.liveViewData = res;
  2139. }
  2140. }).catch(error => {
  2141. console.error("获取直播间数据失败:", error);
  2142. // 失败时兜底,避免显示异常
  2143. this.liveViewData = {
  2144. like: 0,
  2145. watchCount: 0
  2146. };
  2147. });
  2148. },
  2149. // 30秒刷新一下直播间点赞数
  2150. startLiveViewDataTimer() {
  2151. // 先清除旧定时器(防止重复创建)
  2152. if (this.liveViewDataTimer) {
  2153. clearInterval(this.liveViewDataTimer);
  2154. this.liveViewDataTimer = null;
  2155. }
  2156. // 启动新定时器,每3秒执行一次
  2157. this.liveViewDataTimer = setInterval(() => {
  2158. // 安全校验:确保liveItem和liveId存在(避免无效请求)
  2159. if (this.liveItem && this.liveId) {
  2160. this.getliveViewData(this.liveItem);
  2161. }
  2162. }, 30000);
  2163. },
  2164. // 去购买,跳商品详情
  2165. goShop(productId, goodsId) {
  2166. if (!this.liveId) return;
  2167. uni.navigateTo({
  2168. url: '/pages_shopping/live/goods?productId=' + productId + '&liveId=' + this.liveId +
  2169. '&goodsId=' +
  2170. goodsId + '&storeId=' + this.storeId
  2171. })
  2172. },
  2173. // 查询店铺
  2174. async queryCollect() {
  2175. this.loadingProducts = true;
  2176. if (!this.liveId) return;
  2177. if (this.inputInfo == null) this.inputInfo = ''
  2178. uni.showLoading({
  2179. title: '加载中'
  2180. });
  2181. try {
  2182. const res = await liveStore(this.liveId, this.inputInfo);
  2183. uni.hideLoading()
  2184. this.shopping = true
  2185. if (res.code === 200) {
  2186. // 数据绑定到当前 liveItem,避免全局污染
  2187. this.products = Array.isArray(res.data) ? res.data : [];
  2188. }
  2189. } catch (error) {
  2190. console.error('获取小黄车商品失败:', error);
  2191. } finally {
  2192. this.loadingProducts = false;
  2193. }
  2194. },
  2195. // 时间戳
  2196. initTime() {
  2197. const now = new Date();
  2198. this.timestamp = now.getTime();
  2199. },
  2200. openCart() {
  2201. this.queryCollect()
  2202. },
  2203. close() {
  2204. this.showadd = false
  2205. },
  2206. // 关闭小黄车
  2207. closeShop() {
  2208. this.shopping = false;
  2209. },
  2210. closeMore() {
  2211. this.isMore = false;
  2212. },
  2213. closeWin() {
  2214. this.winning = false;
  2215. },
  2216. // 关闭WebSocket连接(isManual:是否手动关闭)
  2217. closeWebSocket(isManual = true) {
  2218. if (!this.socket || !this.isSocketOpen) {
  2219. console.warn("WebSocket 任务不存在或未打开,无需关闭");
  2220. return;
  2221. }
  2222. // console.log("websocket 连接关闭");
  2223. this.isManualClose = isManual;
  2224. this.stopHeartBeat();
  2225. this.resetReconnectState();
  2226. try {
  2227. // 先保存引用,避免在关闭过程中被置为null
  2228. const socketToClose = this.socket;
  2229. this.socket = null;
  2230. this.isSocketOpen = false;
  2231. socketToClose.close({
  2232. code: 1000,
  2233. reason: isManual ? "主动关闭" : "异常关闭"
  2234. });
  2235. console.log("WebSocket连接已发起关闭");
  2236. } catch (err) {
  2237. console.error("关闭WebSocket失败:", err);
  2238. // 即使关闭失败,也要重置状态
  2239. this.socket = null;
  2240. this.isSocketOpen = false;
  2241. }
  2242. },
  2243. startHeartBeat() {
  2244. this.stopHeartBeat(); // 先停止现有心跳,防止重复
  2245. this.sendHeartBeat(); // 立即发送一次心跳
  2246. // 按间隔循环发送心跳
  2247. this.heartBeatTimer = setInterval(() => {
  2248. this.sendHeartBeat();
  2249. }, this.heartBeatInterval);
  2250. },
  2251. initSocket() {
  2252. if (this.isConnecting) {
  2253. return;
  2254. }
  2255. // 如果已经存在连接且状态为open,则退出
  2256. if (this.socket && this.socket.readyState === 1) {
  2257. return;
  2258. }
  2259. if (this.socket && (this.socket.readyState === 0 || this.socket.readyState === 1)) {
  2260. console.log('关闭现有WebSocket连接,创建新连接');
  2261. this.closeWebSocket(true);
  2262. }
  2263. // 校验必要参数
  2264. if (!this.liveId) {
  2265. console.error("缺失直播间ID,无法初始化WebSocket");
  2266. return;
  2267. }
  2268. if (!this.userData || !this.userData.userId) {
  2269. console.error("用户信息缺失,无法初始化WebSocket");
  2270. return;
  2271. }
  2272. // 清除之前的重连定时器
  2273. this.resetReconnectState();
  2274. const now = new Date();
  2275. this.timestamp = now.getTime(); // 生成签名
  2276. const signature = CryptoJS.HmacSHA256(
  2277. `${this.liveId}${this.userData.userId}${this.userType}${this.timestamp}`,
  2278. this.timestamp.toString()
  2279. ).toString(CryptoJS.enc.Hex);
  2280. try {
  2281. const baseWsUrl = 'wss://api.fhhx.runtzh.com/ws/app/webSocket';
  2282. // const baseWsUrl = 'ws://192.168.10.166:7114/ws/app/webSocket';
  2283. let wsUrl =
  2284. `${baseWsUrl}?userId=${this.userData.userId}&liveId=${this.liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`;
  2285. if (this.qrFrom) {
  2286. wsUrl += this.qrFrom;
  2287. }
  2288. const socketTask = uni.connectSocket({
  2289. url: wsUrl,
  2290. success: () => {
  2291. // console.log("Socket连接请求发送成功")
  2292. },
  2293. fail: (err) => {
  2294. console.error("Socket连接请求失败:", err);
  2295. this.handleReconnect();
  2296. }
  2297. });
  2298. // 连接打开事件
  2299. socketTask.onOpen((res) => {
  2300. // console.log("WebSocket连接已打开");
  2301. this.socket = socketTask;
  2302. this.isConnecting = false;
  2303. this.isSocketOpen = true;
  2304. this.reconnectCount = 0;
  2305. this.resetReconnectState();
  2306. this.heartBeatRetryCount = 0; // 重置心跳重试次数
  2307. this.shownEntryUsers.clear(); // 重连后重置进入提示记录
  2308. this.startHeartBeat();
  2309. });
  2310. // 消息接收事件
  2311. socketTask.onMessage((res) => {
  2312. try {
  2313. const data = JSON.parse(res.data);
  2314. // 处理服务端心跳响应
  2315. if (data.cmd === "heartBeatAck") {
  2316. this.stopHeartBeat(); // 清除当前超时检测
  2317. this.startHeartBeat(); // 重新启动心跳周期
  2318. return;
  2319. }
  2320. this.handleSocketMessage(res);
  2321. } catch (err) {
  2322. console.error("消息解析异常:", err);
  2323. }
  2324. });
  2325. // 连接错误事件
  2326. socketTask.onError((err) => {
  2327. console.error("WebSocket连接错误:", err);
  2328. this.isSocketOpen = false;
  2329. this.stopHeartBeat();
  2330. this.isConnecting = false;
  2331. this.handleReconnect(); // 错误直接触发重连
  2332. });
  2333. // 连接关闭事件
  2334. socketTask.onClose((res) => {
  2335. console.log("WebSocket连接关闭:", res);
  2336. this.isSocketOpen = false;
  2337. this.isConnecting = false;
  2338. this.stopHeartBeat(); // 清除心跳定时器
  2339. if (!this.isManualClose && this.reconnectCount < this.maxReconnectAttempts) {
  2340. this.handleReconnect();
  2341. } else {}
  2342. });
  2343. } catch (e) {
  2344. console.error("创建WebSocket异常:", e);
  2345. this.handleReconnect();
  2346. }
  2347. },
  2348. handleTime(time, duration) {
  2349. // 将time转换为毫秒级时间戳
  2350. let timeStamp;
  2351. // 如果time是数字且合理(毫秒级时间戳通常为13位左右的正数),视为有效时间戳
  2352. if (typeof time === 'number' && time > 0 && time < 9999999999999) {
  2353. timeStamp = time;
  2354. }
  2355. //如果是字符串,尝试解析为日期后转为时间戳
  2356. else if (typeof time === 'string' && time.trim() !== '') {
  2357. // 处理兼容性:将"2025-09-25 17:30:00"转为ISO格式"2025-09-25T17:30:00"
  2358. const isoTime = time.replace(' ', 'T');
  2359. const date = new Date(isoTime);
  2360. // 校验日期是否有效
  2361. if (!isNaN(date.getTime())) {
  2362. timeStamp = date.getTime();
  2363. } else {
  2364. console.error('无效的日期格式:', time);
  2365. return false; // 格式错误时返回false
  2366. }
  2367. } else {
  2368. console.error('time参数必须是有效的时间戳(数字)或日期字符串');
  2369. return false;
  2370. }
  2371. // 后续逻辑保持不变(基于转换后的timeStamp计算)
  2372. const targetTimestamp = timeStamp + duration * 60 * 1000;
  2373. const currentTimestamp = new Date().getTime();
  2374. const timeDiffMs = targetTimestamp - currentTimestamp;
  2375. if (timeDiffMs <= 0) {
  2376. return false;
  2377. }
  2378. const hours = Math.floor(timeDiffMs / (1000 * 60 * 60));
  2379. const minutes = Math.floor((timeDiffMs % (1000 * 60 * 60)) / (1000 * 60));
  2380. const seconds = Math.floor((timeDiffMs % (1000 * 60)) / 1000);
  2381. const formatNum = (num) => num.toString().padStart(2, "0");
  2382. return {
  2383. hours: formatNum(hours),
  2384. minutes: formatNum(minutes),
  2385. seconds: formatNum(seconds)
  2386. };
  2387. },
  2388. // 限制聊天消息数量,防止内存泄漏
  2389. addToTalkList(message) {
  2390. const MAX_TALK_ITEMS = 30;
  2391. const oldList = Array.isArray(this.talklist) ? this.talklist : [];
  2392. const newList = [...oldList, message];
  2393. if (newList.length > MAX_TALK_ITEMS) {
  2394. newList.splice(0, newList.length - MAX_TALK_ITEMS);
  2395. }
  2396. this.talklist = newList;
  2397. // 使用 setTimeout 替代 requestAnimationFrame
  2398. setTimeout(() => {
  2399. this.scrollToBottom();
  2400. }, 0);
  2401. },
  2402. // 处理Socket消息
  2403. async handleSocketMessage(message) {
  2404. let data = JSON.parse(message.data)
  2405. const socketMessage = data.data // 服务端返回的消息体
  2406. if (data.code == 200) {
  2407. const messageData = {
  2408. ...socketMessage,
  2409. cmd: socketMessage.cmd || '', // 确保cmd字段存在
  2410. ts: Date.now() // 时间戳
  2411. };
  2412. // 处理服务端返回的sendMsg消息,加入本地列表
  2413. if (socketMessage.cmd == 'sendMsg') {
  2414. if (!this.isSocketAvailable()) {
  2415. uni.showToast({
  2416. title: '连接已断开,正在重试...',
  2417. icon: 'none'
  2418. });
  2419. this.handleReconnect();
  2420. return;
  2421. }
  2422. this.addToTalkList(messageData);
  2423. } else if (socketMessage.cmd == 'red') {
  2424. const redData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2425. this.redInfo = redData || {};
  2426. this.isShowRed = socketMessage.status === 1;
  2427. if (this.isShowRed) {
  2428. this.redTimer = setInterval(() => {
  2429. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  2430. .duration)
  2431. if (!redCountdown) {
  2432. this.isShowRed = false
  2433. clearInterval(this.redTimer)
  2434. }
  2435. }, 1000);
  2436. }
  2437. } else if (socketMessage.cmd == 'goods') {
  2438. const goodsData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2439. this.goodsCard = goodsData || {};
  2440. this.isShowGoods = socketMessage.status == 1;
  2441. } else if (socketMessage.cmd == 'coupon') {
  2442. const couponData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2443. this.couponInfo = couponData || {};
  2444. this.isShowCoupon = socketMessage.status === 1;
  2445. if (this.isShowCoupon) {}
  2446. } else if (socketMessage.cmd == 'lottery') {
  2447. const lotteryData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2448. this.lotteryInfo = lotteryData || {};
  2449. this.isShowLottery = socketMessage.status === 1;
  2450. if (socketMessage.status != 1) {
  2451. this.isShowLotteryPop = false
  2452. }
  2453. // 清除已有定时器(无论状态是否为1,先清掉旧的)
  2454. clearTimeout(this.lotteryTimer);
  2455. if (this.isShowLottery) {
  2456. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this.lotteryInfo
  2457. .duration)
  2458. if (this.countdown) {
  2459. this.lotteryTimer = setInterval(() => {
  2460. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this
  2461. .lotteryInfo
  2462. .duration)
  2463. if (!this.countdown) {
  2464. // console.log("倒计时", this.countdown)
  2465. this.isShowLottery = false;
  2466. this.isShowLotteryPop = false;
  2467. clearInterval(this.lotteryTimer)
  2468. }
  2469. }, 1000);
  2470. }
  2471. } else {
  2472. this.isShowLottery = false
  2473. }
  2474. } else if (socketMessage.cmd == 'entry') {
  2475. try {
  2476. if (!this.liveUserCalled) {
  2477. await this.getliveUser(false);
  2478. this.liveUserCalled = true;
  2479. }
  2480. const userIdToEntry = socketMessage.userId;
  2481. const existingIndex = this.liveViewersData.findIndex(item => item.userId ===
  2482. userIdToEntry);
  2483. if (existingIndex === -1) {
  2484. const liveViewers = {
  2485. userId: socketMessage.userId,
  2486. nickName: socketMessage.nickName,
  2487. avatar: socketMessage.avatar
  2488. }
  2489. this.liveViewersData.push(liveViewers);
  2490. this.liveUserTotal++;
  2491. }
  2492. // 解析用户ID(根据实际接口字段调整,此处假设data含userId)
  2493. const userData = JSON.parse(socketMessage.data || '{}');
  2494. const userId = userData.userId || socketMessage.userId; // 兼容不同字段
  2495. if (!userId) return; // 无用户ID不处理
  2496. // 仅新用户(未显示过)才触发提示
  2497. if (!this.shownEntryUsers.has(userId)) {
  2498. this.inAndOut = socketMessage;
  2499. this.showWelcomeMessage = true;
  2500. this.shownEntryUsers.add(userId); // 加入已显示集合
  2501. // 3秒后隐藏提示(可调整时长)
  2502. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  2503. this.welcomeTimer = setTimeout(() => {
  2504. this.showWelcomeMessage = false;
  2505. }, 3000);
  2506. }
  2507. } catch (err) {
  2508. console.error("解析entry用户数据失败:", err);
  2509. }
  2510. } else if (socketMessage.cmd == 'out') {
  2511. if (this.liveUserTotal > 0) {
  2512. const userIdToRemove = socketMessage.userId;
  2513. const index = this.liveViewersData.findIndex(item => item.userId === userIdToRemove);
  2514. if (index !== -1) {
  2515. this.liveViewersData.splice(index, 1);
  2516. this.liveUserTotal--; // 根据userId删除对应的用户数据
  2517. }
  2518. }
  2519. this.inAndOut = socketMessage;
  2520. this.showWelcomeMessage = true;
  2521. // 3秒后隐藏提示
  2522. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  2523. this.welcomeTimer = setTimeout(() => {
  2524. this.showWelcomeMessage = false;
  2525. }, 3000);
  2526. } else if (socketMessage.cmd == 'live_start' || socketMessage.cmd ==
  2527. 'live_end') {
  2528. // 开始直播,关闭直播
  2529. if (this.liveStartTimer) {
  2530. clearInterval(this.liveStartTimer);
  2531. this.liveStartTimer = null;
  2532. }
  2533. if (this.redTimer) {
  2534. clearInterval(this.redTimer);
  2535. this.redTimer = null;
  2536. }
  2537. // 请求最新直播间数据
  2538. await this.getliving(this.liveId);
  2539. } else if (socketMessage.cmd == 'Integral') {
  2540. this.integral = {
  2541. msg: socketMessage.msg,
  2542. status: true
  2543. }
  2544. } else if (socketMessage.cmd == 'LotteryDetail') {
  2545. try {
  2546. this.prizeInfo = Array.isArray(JSON.parse(socketMessage.data || '[]')) ?
  2547. JSON.parse(socketMessage.data || '[]') : [];
  2548. } catch (err) {
  2549. console.error('解析抽奖结果失败:', err);
  2550. this.prizeInfo = [];
  2551. }
  2552. this.isShowPrize = true;
  2553. this.isShowLottery = false;
  2554. this.isShowLotteryPop = false;
  2555. } else if (socketMessage.cmd == 'blockUser') {
  2556. uni.removeStorage({
  2557. key: 'AppToken',
  2558. success: () => {
  2559. uni.reLaunch({
  2560. url: '/pages/auth/login'
  2561. });
  2562. }
  2563. });
  2564. }
  2565. } else {
  2566. uni.showToast({
  2567. title: data.msg,
  2568. icon: 'none'
  2569. });
  2570. }
  2571. },
  2572. sendMsg(retries = 1) {
  2573. // 防止连续点击发送两次(800ms短时锁定)
  2574. if (this.isSending) return;
  2575. this.isSending = true;
  2576. setTimeout(() => {
  2577. this.isSending = false;
  2578. }, 800);
  2579. const text = (this.value || '').trim();
  2580. if (!text) {
  2581. uni.showToast({
  2582. title: "不能发送空消息",
  2583. icon: 'none'
  2584. });
  2585. return;
  2586. }
  2587. if (!this.isSocketAvailable()) {
  2588. if (retries > 0) {
  2589. uni.showToast({
  2590. title: `连接不稳定,正在重试(${retries}次)...`,
  2591. icon: 'none'
  2592. });
  2593. // 延迟500ms重试,重试次数减1
  2594. setTimeout(() => this.sendMsg(retries - 1), 500);
  2595. } else {
  2596. uni.showToast({
  2597. title: '连接已断开,发送失败',
  2598. icon: 'none'
  2599. });
  2600. this.value = text; // 恢复输入框内容
  2601. }
  2602. return;
  2603. }
  2604. const liveId = this.liveId;
  2605. this.value = ''; // 立即清空输入框
  2606. // 构造发送给服务端的消息数据
  2607. const data = {
  2608. liveId,
  2609. userId: this.userData.userId,
  2610. userType: 0,
  2611. cmd: "sendMsg",
  2612. msg: text,
  2613. nickName: this.userData.nickname || '未命名',
  2614. avatar: this.userData.avatar || '/static/images/avatar.png'
  2615. };
  2616. // 发送socket消息
  2617. try {
  2618. this.socket.send({
  2619. data: JSON.stringify(data),
  2620. success: () => {
  2621. this.value = '';
  2622. },
  2623. fail: (err) => {
  2624. console.error("消息发送失败:", err);
  2625. if (retries > 0) {
  2626. uni.showToast({
  2627. title: `发送失败,正在重试(${retries}次)`,
  2628. icon: 'none'
  2629. });
  2630. setTimeout(() => this.sendMsg(retries - 1), 500);
  2631. } else {
  2632. uni.showToast({
  2633. title: '发送失败,请稍后再试',
  2634. icon: 'none'
  2635. });
  2636. this.value = text; // 恢复输入框内容
  2637. }
  2638. }
  2639. });
  2640. } catch (err) {
  2641. console.error("发送消息异常:", err);
  2642. if (retries > 0) {
  2643. setTimeout(() => this.sendMsg(retries - 1), 500);
  2644. } else {
  2645. uni.showToast({
  2646. title: '发送失败,请稍后再试',
  2647. icon: 'none'
  2648. });
  2649. this.value = text;
  2650. }
  2651. }
  2652. }
  2653. }
  2654. };
  2655. </script>
  2656. <style scoped lang="scss">
  2657. .input-bottom {
  2658. .button -reset::after {
  2659. border: none !important;
  2660. padding: 0 !important;
  2661. margin: 0 !important;
  2662. }
  2663. .button-reset {
  2664. background-color: transparent !important;
  2665. padding: 0 !important;
  2666. line-height: inherit !important;
  2667. margin: 0 !important;
  2668. width: auto !important;
  2669. font-weight: 500 !important;
  2670. border-radius: none !important;
  2671. }
  2672. .num {
  2673. width: 36rpx;
  2674. height: 20rpx;
  2675. background: #FFFFFF;
  2676. border-radius: 10rpx 10rpx 10rpx 10rpx;
  2677. text-align: center;
  2678. line-height: 20rpx;
  2679. position: absolute;
  2680. bottom: -10rpx;
  2681. font-weight: 600;
  2682. font-size: 14rpx;
  2683. color: #FA341E;
  2684. }
  2685. }
  2686. .horizontal {
  2687. background-color: rgba(23, 23, 23, 0.8);
  2688. }
  2689. .vertical {
  2690. background: rgba(0, 0, 0, 0.3);
  2691. }
  2692. .skeleton-item {
  2693. display: flex;
  2694. padding: 20rpx;
  2695. background: #fff;
  2696. margin-bottom: 16rpx;
  2697. border-radius: 16rpx;
  2698. }
  2699. .skeleton-img {
  2700. width: 200rpx;
  2701. height: 200rpx;
  2702. background: #f0f0f0;
  2703. border-radius: 8rpx;
  2704. margin-right: 24rpx;
  2705. animation: pulse 1.5s ease-in-out infinite;
  2706. }
  2707. .skeleton-content {
  2708. flex: 1;
  2709. }
  2710. .skeleton-line {
  2711. height: 20rpx;
  2712. background: #f0f0f0;
  2713. margin-bottom: 16rpx;
  2714. border-radius: 4rpx;
  2715. animation: pulse 1.5s ease-in-out infinite;
  2716. }
  2717. .skeleton-line.short {
  2718. width: 60%;
  2719. }
  2720. .skeleton-line.medium {
  2721. width: 80%;
  2722. }
  2723. .skeleton-line.long {
  2724. width: 95%;
  2725. }
  2726. @keyframes pulse {
  2727. 0% {
  2728. opacity: 1;
  2729. }
  2730. 50% {
  2731. opacity: 0.5;
  2732. }
  2733. 100% {
  2734. opacity: 1;
  2735. }
  2736. }
  2737. ::v-deep .u-icon--right {
  2738. justify-content: flex-end !important;
  2739. }
  2740. // 无头像用户文字样式
  2741. .text-white {
  2742. color: #ffffff;
  2743. }
  2744. .text-xs {
  2745. font-size: 18rpx;
  2746. }
  2747. .text-sm {
  2748. font-size: 24rpx;
  2749. }
  2750. .w52,
  2751. .w72 {
  2752. display: flex;
  2753. align-items: center;
  2754. justify-content: center;
  2755. }
  2756. .swiper-wrapper {
  2757. position: relative;
  2758. width: 100%;
  2759. height: 100vh;
  2760. overflow: hidden;
  2761. background-color: #000000;
  2762. .container {
  2763. width: 100%;
  2764. height: 100%;
  2765. position: relative;
  2766. transition: opacity 0.3s ease;
  2767. transform: translateZ(0);
  2768. will-change: opacity;
  2769. }
  2770. }
  2771. .welcome-message {
  2772. position: fixed;
  2773. width: 100%;
  2774. bottom: 38vh;
  2775. left: 50%;
  2776. transform: translateX(-50%);
  2777. color: white;
  2778. padding: 10px 20px;
  2779. border-radius: 20px;
  2780. z-index: 10;
  2781. transition: opacity 0.3s ease;
  2782. }
  2783. .send {
  2784. background-color: #fafafa;
  2785. border-radius: 28rpx;
  2786. // width: 50rpx;
  2787. // height: 80rpx;
  2788. width: 100rpx;
  2789. height: 70rpx;
  2790. line-height: 70rpx;
  2791. text-align: center;
  2792. // padding: 14rpx 16rpx;
  2793. color: #181818;
  2794. font-weight: 500;
  2795. }
  2796. /* 减少重绘和重排 */
  2797. .talk-list,
  2798. .viewer-item,
  2799. .message-item {
  2800. will-change: transform;
  2801. contain: layout style paint;
  2802. backface-visibility: hidden;
  2803. transform: translateZ(0);
  2804. }
  2805. .talk-list {
  2806. will-change: transform; // 提示浏览器优化
  2807. contain: layout style paint; // 限制渲染范围
  2808. max-width: 100%;
  2809. border-radius: 30rpx;
  2810. // background-color: rgba(33, 33, 33, 0.5);
  2811. padding: 10rpx 30rpx;
  2812. }
  2813. .content {
  2814. position: relative;
  2815. z-index: 2;
  2816. height: 100%;
  2817. width: 100%;
  2818. top: 0;
  2819. left: 0;
  2820. display: flex;
  2821. flex-direction: column;
  2822. justify-content: space-between;
  2823. // .activity-box {
  2824. // position: fixed;
  2825. // top: 188rpx;
  2826. // left: 30rpx;
  2827. // z-index: 999999;
  2828. // display: flex;
  2829. // align-items: center;
  2830. // .item-box {
  2831. // -webkit-transform: translateZ(0);
  2832. // /* 硬件加速 */
  2833. // transform: translateZ(0);
  2834. // border-radius: 16rpx;
  2835. // background-color: rgba(77, 77, 77, 0.5);
  2836. // width: 90rpx;
  2837. // height: 100rpx;
  2838. // margin-right: 20rpx;
  2839. // position: relative;
  2840. // z-index: 999;
  2841. // .tip {
  2842. // position: absolute;
  2843. // width: 100%;
  2844. // bottom: 0;
  2845. // color: #fafcff;
  2846. // font-size: 26rpx;
  2847. // background-color: rgba(15, 15, 15, 0.8);
  2848. // border-radius: 16rpx;
  2849. // text-align: center;
  2850. // }
  2851. // .item {
  2852. // margin: 0 auto;
  2853. // padding: 10rpx 0;
  2854. // .img {
  2855. // height: 100%;
  2856. // }
  2857. // }
  2858. // }
  2859. // }
  2860. // 减少重绘
  2861. .side-group,
  2862. .content-top {
  2863. will-change: transform;
  2864. }
  2865. .side-group {
  2866. position: absolute;
  2867. top: 55%;
  2868. right: 30rpx;
  2869. z-index: 1000;
  2870. display: flex;
  2871. flex-direction: column;
  2872. align-items: center;
  2873. // .side-item {
  2874. // font-weight: 500;
  2875. // font-size: 24rpx;
  2876. // color: #FFFFFF;
  2877. // margin-bottom: 32rpx;
  2878. // text-align: center;
  2879. // .button -reset::after {
  2880. // border: none !important;
  2881. // padding: 0 !important;
  2882. // margin: 0 !important;
  2883. // }
  2884. // .button-reset {
  2885. // background-color: transparent !important;
  2886. // padding: 0 !important;
  2887. // line-height: inherit !important;
  2888. // margin: 0 !important;
  2889. // width: auto !important;
  2890. // font-weight: 500 !important;
  2891. // border-radius: none !important;
  2892. // }
  2893. // .image {
  2894. // width: 72rpx;
  2895. // height: 72rpx;
  2896. // }
  2897. // }
  2898. .item-box {
  2899. -webkit-transform: translateZ(0);
  2900. /* 硬件加速 */
  2901. transform: translateZ(0);
  2902. border-radius: 16rpx;
  2903. width: 96rpx;
  2904. height: 96rpx;
  2905. position: relative;
  2906. z-index: 999;
  2907. margin-bottom: 30rpx;
  2908. .tip {
  2909. position: absolute;
  2910. width: 100%;
  2911. bottom: 0;
  2912. color: #fafcff;
  2913. font-size: 26rpx;
  2914. background: rgba(0,0,0,0.5);
  2915. text-align: center;
  2916. }
  2917. .item {
  2918. margin: 0 auto;
  2919. padding: 10rpx 0;
  2920. .img {
  2921. height: 100%;
  2922. }
  2923. }
  2924. }
  2925. }
  2926. .content-top {
  2927. width: 100%;
  2928. margin-top: 48rpx;
  2929. display: flex;
  2930. justify-content: space-between;
  2931. padding: 0 24rpx;
  2932. box-sizing: border-box;
  2933. .sum {
  2934. width: 80rpx;
  2935. height: 52rpx;
  2936. background: rgba(0, 0, 0, 0.5);
  2937. border-radius: 26rpx 26rpx 26rpx 26rpx;
  2938. font-size: 24rpx;
  2939. color: #FFFFFF;
  2940. text-align: center;
  2941. line-height: 52rpx;
  2942. }
  2943. }
  2944. .follow-btn {
  2945. padding: 8rpx 16rpx;
  2946. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  2947. border-radius: 26rpx;
  2948. font-weight: 500;
  2949. font-size: 26rpx;
  2950. color: #FFFFFF;
  2951. }
  2952. }
  2953. .trailer-box {
  2954. position: relative;
  2955. top: 15%;
  2956. display: flex;
  2957. flex-direction: column;
  2958. align-items: center;
  2959. color: #ffffff;
  2960. padding: 20rpx;
  2961. .button {
  2962. margin-top: 20rpx;
  2963. background: #6d7bd4;
  2964. color: #fff;
  2965. border-radius: 20rpx;
  2966. padding: 20rpx 30rpx;
  2967. position: relative;
  2968. z-index: 99999;
  2969. }
  2970. .ash {
  2971. background: #636363;
  2972. }
  2973. .countdown-item {
  2974. display: flex;
  2975. flex-direction: column;
  2976. align-items: center;
  2977. .white {
  2978. width: 60rpx;
  2979. height: 60rpx;
  2980. text-align: center;
  2981. overflow: hidden;
  2982. background: #FFFFFF;
  2983. border-radius: 8rpx;
  2984. margin: 30rpx 10rpx 0;
  2985. font-weight: 600;
  2986. font-size: 24rpx;
  2987. color: #000000;
  2988. line-height: 60rpx;
  2989. }
  2990. }
  2991. .item {
  2992. width: 100%;
  2993. height: 400rpx;
  2994. }
  2995. .name {
  2996. font-size: 34rpx;
  2997. }
  2998. .img {
  2999. margin-bottom: 40rpx;
  3000. width: 240rpx;
  3001. height: 240rpx;
  3002. }
  3003. .title {
  3004. margin-top: 30rpx;
  3005. font-size: 42rpx;
  3006. font-weight: 500;
  3007. }
  3008. }
  3009. .videolist {
  3010. position: relative;
  3011. height: 100vh;
  3012. width: 100%;
  3013. .video {
  3014. transform: translateZ(0);
  3015. backface-visibility: hidden;
  3016. perspective: 1000;
  3017. height: 100vh;
  3018. width: 100%;
  3019. // background-color: rgba(57, 57, 57, 0.4);
  3020. .item {
  3021. width: 100%;
  3022. height: 100%;
  3023. }
  3024. .time {
  3025. color: #ffffff;
  3026. font-size: 20rpx;
  3027. margin-left: 10rpx;
  3028. }
  3029. .end {
  3030. position: absolute;
  3031. top: 50%;
  3032. left: 50%;
  3033. transform: translate(-50%, -50%);
  3034. font-size: 36rpx;
  3035. color: #fff;
  3036. }
  3037. .lable {
  3038. position: absolute;
  3039. top: 50rpx;
  3040. right: 16rpx;
  3041. background-color: rgba(57, 57, 57, 0.6);
  3042. padding: 4rpx 10rpx;
  3043. color: #fff;
  3044. border-radius: 15rpx;
  3045. }
  3046. }
  3047. .video_row {
  3048. position: absolute;
  3049. top: 20%;
  3050. max-height: 450rpx;
  3051. z-index: 99;
  3052. }
  3053. }
  3054. .prize-card {
  3055. width: 504rpx;
  3056. padding: 40rpx 40rpx 30rpx;
  3057. box-sizing: border-box;
  3058. display: flex;
  3059. flex-direction: column;
  3060. border-radius: 20rpx;
  3061. align-items: center;
  3062. background: linear-gradient(180deg, #f7823f 0%, #ffd4be 27%, #ffffff 100%);
  3063. position: relative;
  3064. .nav-img {
  3065. width: 311rpx;
  3066. position: absolute;
  3067. top: -122rpx;
  3068. left: 50%;
  3069. transform: translateX(-50%);
  3070. }
  3071. .title {
  3072. color: #C32008;
  3073. font-size: 34rpx;
  3074. font-weight: 600;
  3075. margin: 20rpx 0 40rpx;
  3076. }
  3077. .prize-content {
  3078. width: 100%;
  3079. display: flex;
  3080. justify-content: space-between;
  3081. align-items: center;
  3082. font-size: 28rpx;
  3083. margin: 10rpx 0;
  3084. .txt {
  3085. font-weight: 600;
  3086. }
  3087. }
  3088. .tip {
  3089. font-size: 28rpx;
  3090. color: #414141;
  3091. margin: 40rpx 0;
  3092. }
  3093. .button {
  3094. width: 200rpx;
  3095. height: 70rpx;
  3096. line-height: 70rpx;
  3097. background: linear-gradient(180deg, #ff7c30 0%, #FF3A1E 100%);
  3098. border-radius: 28rpx;
  3099. font-weight: 500;
  3100. font-size: 32rpx;
  3101. color: #ffffff;
  3102. text-align: center;
  3103. }
  3104. }
  3105. .no-prize-card {
  3106. width: 504rpx;
  3107. padding: 40rpx 40rpx 30rpx;
  3108. box-sizing: border-box;
  3109. display: flex;
  3110. flex-direction: column;
  3111. border-radius: 20rpx;
  3112. align-items: center;
  3113. position: relative;
  3114. .img {
  3115. margin-top: 40rpx;
  3116. width: 300rpx;
  3117. height: 300rpx;
  3118. }
  3119. .tip {
  3120. font-size: 36rpx;
  3121. color: #414141;
  3122. margin: 40rpx 0;
  3123. }
  3124. .button {
  3125. width: 220rpx;
  3126. height: 80rpx;
  3127. line-height: 80rpx;
  3128. background: linear-gradient(180deg, #fdfbb8 0%, #b79243 100%);
  3129. border-radius: 28rpx;
  3130. font-weight: 500;
  3131. font-size: 32rpx;
  3132. color: #ffffff;
  3133. text-align: center;
  3134. }
  3135. }
  3136. .red-card {
  3137. width: 550rpx;
  3138. height: 636rpx;
  3139. position: relative;
  3140. .img {
  3141. position: absolute;
  3142. width: 100%;
  3143. height: 100%;
  3144. }
  3145. .red-content {
  3146. position: relative;
  3147. z-index: 5;
  3148. display: flex;
  3149. flex-direction: column;
  3150. align-items: center;
  3151. .title {
  3152. font-size: 36rpx;
  3153. color: #FF3A1E;
  3154. margin: 180rpx 0 90rpx;
  3155. }
  3156. .txt {
  3157. font-size: 28rpx;
  3158. color: #FFECC3;
  3159. margin: 80rpx 0 40rpx;
  3160. }
  3161. .button {
  3162. width: 392rpx;
  3163. height: 96rpx;
  3164. line-height: 96rpx;
  3165. background: linear-gradient(180deg, #FFF4D5 0%, #FFE5B1 100%);
  3166. border-radius: 48rpx 48rpx 48rpx 48rpx;
  3167. font-weight: 600;
  3168. font-size: 36rpx;
  3169. color: #C32008;
  3170. text-align: center;
  3171. }
  3172. }
  3173. }
  3174. .integral-box {
  3175. min-width: 400rpx;
  3176. max-width: 600rpx;
  3177. display: flex;
  3178. flex-direction: column;
  3179. align-items: center;
  3180. border-radius: 20rpx;
  3181. overflow: hidden;
  3182. .top {
  3183. width: 100%;
  3184. position: relative;
  3185. .title {
  3186. width: 100%;
  3187. font-weight: 600;
  3188. font-size: 40rpx;
  3189. color: #FFFFFF;
  3190. text-shadow: 0px 4px 8px rgba(255, 89, 2, 0.8);
  3191. position: absolute;
  3192. top: 50rpx;
  3193. text-align: center;
  3194. }
  3195. .photo {
  3196. width: 100%;
  3197. }
  3198. }
  3199. .item {
  3200. padding: 20rpx;
  3201. .title {
  3202. font-weight: 500;
  3203. font-size: 32rpx;
  3204. text-align: center;
  3205. }
  3206. .button {
  3207. font-size: 32rpx;
  3208. margin-top: 20rpx;
  3209. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  3210. color: #fff;
  3211. text-align: center;
  3212. padding: 18rpx 60rpx;
  3213. border-radius: 10rpx;
  3214. font-weight: 500;
  3215. }
  3216. }
  3217. }
  3218. .goods {
  3219. position: fixed;
  3220. bottom: 140rpx;
  3221. right: 104rpx;
  3222. z-index: 5;
  3223. background-color: #fff;
  3224. border-radius: 20rpx;
  3225. overflow: hidden;
  3226. width: 280rpx;
  3227. padding: 4rpx;
  3228. .top {
  3229. position: absolute;
  3230. top: 4rpx;
  3231. display: flex;
  3232. justify-content: space-between;
  3233. align-items: center;
  3234. color: #fff;
  3235. width: 100%;
  3236. padding-right: 10rpx;
  3237. box-sizing: border-box;
  3238. .left {
  3239. background-color: rgba(0, 0, 0, 0.8);
  3240. padding: 12rpx;
  3241. font-size: 22rpx;
  3242. display: flex;
  3243. justify-content: space-between;
  3244. align-items: center;
  3245. border-radius: 10rpx;
  3246. }
  3247. }
  3248. .photo {
  3249. width: 100%;
  3250. height: 180rpx;
  3251. border-radius: 16rpx 16rpx 0 0;
  3252. overflow: hidden;
  3253. }
  3254. .item {
  3255. padding: 4rpx;
  3256. .price {
  3257. font-size: 30rpx;
  3258. .red {
  3259. color: #FF5701;
  3260. font-weight: 600;
  3261. margin-right: 10rpx;
  3262. }
  3263. .del {
  3264. color: #828282;
  3265. font-weight: 500;
  3266. font-size: 28rpx;
  3267. text-decoration: line-through
  3268. }
  3269. }
  3270. .title {
  3271. font-weight: 500;
  3272. font-size: 30rpx;
  3273. margin: 10rpx 0 12rpx;
  3274. }
  3275. .button {
  3276. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  3277. color: #fff;
  3278. text-align: center;
  3279. padding: 16rpx 0;
  3280. border-radius: 10rpx;
  3281. font-weight: 500;
  3282. font-size: 30rpx;
  3283. }
  3284. }
  3285. }
  3286. .coupon-pop {
  3287. position: fixed;
  3288. bottom: 140rpx;
  3289. right: 100rpx;
  3290. z-index: 5;
  3291. border-radius: 20rpx;
  3292. width: 320rpx;
  3293. .coupon-block {
  3294. width: 100%;
  3295. position: relative;
  3296. .item {
  3297. width: 100%;
  3298. position: absolute;
  3299. top: 20rpx;
  3300. display: flex;
  3301. flex-direction: column;
  3302. align-items: center;
  3303. color: #fff;
  3304. .title {
  3305. font-weight: 500;
  3306. font-size: 30rpx;
  3307. margin: 16rpx 0 12rpx;
  3308. }
  3309. .price {
  3310. font-size: 40rpx;
  3311. .bold {
  3312. font-size: 56rpx;
  3313. font-weight: 600;
  3314. }
  3315. }
  3316. .txt {
  3317. font-weight: 500;
  3318. font-size: 30rpx;
  3319. margin: 5rpx 0;
  3320. }
  3321. .button {
  3322. background: linear-gradient(270deg, #fffce1 0%, #ffeaaf 100%);
  3323. color: #ff0004;
  3324. text-align: center;
  3325. padding: 16rpx 0;
  3326. border-radius: 40rpx;
  3327. font-weight: 500;
  3328. font-size: 30rpx;
  3329. width: 70%;
  3330. margin-top: 26rpx;
  3331. }
  3332. }
  3333. .bg {
  3334. height: 432rpx;
  3335. width: 100%;
  3336. }
  3337. .nav {
  3338. position: absolute;
  3339. height: 120rpx;
  3340. top: -120rpx;
  3341. left: 0;
  3342. width: 100%;
  3343. z-index: 6;
  3344. }
  3345. .close {
  3346. position: absolute;
  3347. right: 10rpx;
  3348. top: 10rpx;
  3349. }
  3350. }
  3351. }
  3352. .icon-bg {
  3353. border-radius: 50%;
  3354. width: 72rpx;
  3355. height: 72rpx;
  3356. display: flex;
  3357. justify-content: center;
  3358. align-items: center;
  3359. transition: transform 0.2s ease;
  3360. }
  3361. .list {
  3362. width: 80%;
  3363. margin-bottom: 20rpx;
  3364. animation: simpleFade .2s;
  3365. }
  3366. @keyframes simpleFade {
  3367. from {
  3368. opacity: 0;
  3369. }
  3370. to {
  3371. opacity: 1;
  3372. }
  3373. }
  3374. .shop-prompt {
  3375. position: absolute;
  3376. bottom: 750rpx;
  3377. left: 24rpx;
  3378. padding: 6rpx 20rpx;
  3379. background: rgba(230, 154, 34, 0.7);
  3380. border-radius: 24rpx;
  3381. z-index: 9;
  3382. font-weight: 500;
  3383. color: #FFFFFF;
  3384. transition: opacity 0.3s ease;
  3385. }
  3386. .view-box {
  3387. position: relative;
  3388. height: 40vh;
  3389. /* 设置弹出层高度为视窗高度的70% */
  3390. padding: 40rpx 0rpx;
  3391. box-sizing: border-box;
  3392. display: flex;
  3393. flex-direction: column;
  3394. .scroll-content {
  3395. flex: 1;
  3396. margin-top: 50rpx;
  3397. overflow-y: auto;
  3398. padding: 0 40rpx;
  3399. }
  3400. .bottom {
  3401. padding: 20rpx 40rpx;
  3402. position: absolute;
  3403. bottom: 0;
  3404. width: 100%;
  3405. box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(195, 195, 195, 0.3);
  3406. background: #fff;
  3407. }
  3408. }
  3409. // 抽奖
  3410. .prize-box {
  3411. position: relative;
  3412. .nav-img {
  3413. width: 311rpx;
  3414. position: absolute;
  3415. top: -122rpx;
  3416. left: 50%;
  3417. transform: translateX(-50%);
  3418. }
  3419. .bg-img {
  3420. position: absolute;
  3421. top: 0;
  3422. left: 0;
  3423. width: 100%;
  3424. height: 100%;
  3425. z-index: 1;
  3426. }
  3427. .prize-content {
  3428. position: relative;
  3429. z-index: 2;
  3430. padding: 24rpx 0 68rpx;
  3431. .item {
  3432. flex: 1;
  3433. text-align: center;
  3434. }
  3435. .white-item {
  3436. width: 40rpx;
  3437. height: 40rpx;
  3438. text-align: center;
  3439. overflow: hidden;
  3440. background: #FFFFFF;
  3441. box-shadow: inset 0rpx 2rpx 8rpx 0rpx #FFEBB2;
  3442. border-radius: 8rpx;
  3443. margin: 4rpx;
  3444. font-weight: 600;
  3445. font-size: 24rpx;
  3446. color: #F85D22;
  3447. line-height: 40rpx;
  3448. }
  3449. .item-group {
  3450. width: 100%;
  3451. }
  3452. .point-group {
  3453. margin: 20rpx 0 50rpx;
  3454. display: flex;
  3455. gap: 6rpx;
  3456. .item {
  3457. width: 20rpx;
  3458. height: 8rpx;
  3459. background: rgba(255, 255, 255, 0.5);
  3460. border-radius: 4rpx 4rpx 4rpx 4rpx;
  3461. }
  3462. .selected {
  3463. background: #FFEB66;
  3464. }
  3465. }
  3466. .button {
  3467. margin-top: 30rpx;
  3468. width: 520rpx;
  3469. height: 88rpx;
  3470. line-height: 88rpx;
  3471. background: linear-gradient(180deg, #FFF4D6 0%, #FFEB66 100%);
  3472. box-shadow: 0rpx 10rpx 8rpx 4rpx rgba(246, 82, 25, 0.5);
  3473. border-radius: 44rpx;
  3474. font-weight: 500;
  3475. font-size: 36rpx;
  3476. color: #F4410B;
  3477. text-align: center;
  3478. }
  3479. }
  3480. }
  3481. .more-block {
  3482. border-radius: 20rpx 0 0 20rpx;
  3483. padding: 70rpx 30rpx;
  3484. display: flex;
  3485. justify-content: space-between;
  3486. .item {
  3487. text-align: center;
  3488. }
  3489. }
  3490. .winning_record {
  3491. position: relative;
  3492. height: 800rpx;
  3493. .head_bg {
  3494. position: absolute;
  3495. top: -125rpx;
  3496. left: 50%;
  3497. width: 311rpx;
  3498. transform: translateX(-50%);
  3499. }
  3500. .bg {
  3501. width: 100%;
  3502. height: 100%;
  3503. }
  3504. .winning_content {
  3505. position: absolute;
  3506. top: 50rpx;
  3507. color: #fff;
  3508. width: 100%;
  3509. padding: 0 36rpx;
  3510. box-sizing: border-box;
  3511. .title {
  3512. text-align: center;
  3513. font-size: 40rpx;
  3514. font-weight: 500;
  3515. margin-bottom: 40rpx;
  3516. }
  3517. .row {
  3518. display: flex;
  3519. justify-content: space-between;
  3520. .head {
  3521. flex: 1;
  3522. text-align: center;
  3523. }
  3524. .start {
  3525. flex: 1;
  3526. }
  3527. .end {
  3528. flex: 1;
  3529. text-align: end;
  3530. }
  3531. }
  3532. }
  3533. }
  3534. .shoppop {
  3535. padding: 22rpx 16rpx;
  3536. .shoppop-top {
  3537. display: flex;
  3538. justify-content: space-between;
  3539. align-items: center;
  3540. padding: 0 16rpx 22rpx;
  3541. .search-input {
  3542. width: 414rpx;
  3543. height: 76rpx;
  3544. background: #FFFFFF;
  3545. border-radius: 36rpx;
  3546. margin-left: 20rpx;
  3547. padding: 0 32rpx;
  3548. box-sizing: border-box;
  3549. font-size: 24rpx;
  3550. margin-right: 24rpx;
  3551. }
  3552. .search-top {
  3553. font-size: 20rpx;
  3554. color: #222222;
  3555. }
  3556. }
  3557. .shop-list {
  3558. overflow: hidden;
  3559. .list-item {
  3560. display: flex;
  3561. align-items: center;
  3562. padding: 20rpx 16rpx;
  3563. background: #FFFFFF;
  3564. border-radius: 16rpx;
  3565. margin-bottom: 16rpx;
  3566. .goods-img {
  3567. width: 200rpx;
  3568. height: 200rpx;
  3569. border-radius: 16rpx;
  3570. overflow: hidden;
  3571. position: relative;
  3572. margin-right: 24rpx;
  3573. .img {
  3574. width: 100%;
  3575. height: 100%;
  3576. }
  3577. .goods-label {
  3578. position: absolute;
  3579. top: 0;
  3580. width: 64rpx;
  3581. height: 40rpx;
  3582. background: rgba(0, 0, 0, 0.5);
  3583. border-radius: 16rpx 0rpx 16rpx 0rpx;
  3584. text-align: center;
  3585. font-weight: 500;
  3586. font-size: 28rpx;
  3587. color: #FFFFFF;
  3588. }
  3589. }
  3590. .goods-right {
  3591. flex: 1;
  3592. .goods-title {
  3593. font-weight: 500;
  3594. font-size: 30rpx;
  3595. color: #000000;
  3596. margin-bottom: 10rpx;
  3597. }
  3598. .goods-details {
  3599. font-size: 24rpx;
  3600. color: #999999;
  3601. margin: 10rpx 0 20rpx;
  3602. }
  3603. .goods-people {
  3604. font-size: 22rpx;
  3605. color: #E69A22;
  3606. height: 56rpx;
  3607. }
  3608. .goods-shop {
  3609. display: flex;
  3610. justify-content: space-between;
  3611. .nummber {
  3612. color: #FF5C03;
  3613. font-size: 22rpx;
  3614. font-weight: 500;
  3615. }
  3616. .btn-group {
  3617. text-align: center;
  3618. line-height: 56rpx;
  3619. .collect-btn {
  3620. width: 72rpx;
  3621. height: 100%;
  3622. background: #F5F7FA;
  3623. border-radius: 8rpx 0rpx 0rpx 8rpx;
  3624. }
  3625. .shop-btn {
  3626. width: 152rpx;
  3627. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  3628. border-radius: 0rpx 8rpx 8rpx 0rpx;
  3629. font-weight: 500;
  3630. font-size: 30rpx;
  3631. color: #FFFFFF;
  3632. }
  3633. }
  3634. }
  3635. }
  3636. }
  3637. }
  3638. }
  3639. </style>