living.vue 93 KB

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