living.vue 91 KB

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