living.vue 171 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966
  1. <template>
  2. <view class="swiper-wrapper" :class="liveItem.showType == 1 ? 'horizontal' : ''">
  3. <view class="container">
  4. <!-- 预告直播状态 -->
  5. <view class="trailer-box" v-if="liveItem.status == 1">
  6. <video v-if="liveItem.previewUrl" :id="`myVideo_${liveId}`" class="trailer-video"
  7. :src="liveItem.previewUrl" :autoplay="true" :loop="false" object-fit="contain" :custom-cache="false"
  8. :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false" :show-center-play-btn="false"
  9. :http-cache="false" @error="videoError" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  10. @play="onVideoPlay" :disable-progress="true" :enable-play-gesture="true" @waiting="onVideoWaiting"
  11. preload="auto" type="application/x-mpegURL" :controls="false"></video>
  12. <image v-if="liveItem.status == 1 && !liveItem.previewUrl" class="trailer-placeholder"
  13. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/no_live.png">
  14. </image>
  15. <view class="countdown-container" v-if="liveItem.status == 1 && liveCountdown">
  16. <view class="live-name">{{ liveItem.liveName }}</view>
  17. <view class="countdown-display">
  18. <text class="countdown-label">距离开播还有</text>
  19. <view class="countdown-unit">
  20. {{ liveCountdown.hours || '00' }}
  21. </view>
  22. <view class="countdown-separator">:</view>
  23. <view class="countdown-unit">
  24. {{ liveCountdown.minutes || '00' }}
  25. </view>
  26. <view class="countdown-separator">:</view>
  27. <view class="countdown-unit">
  28. {{ liveCountdown.seconds || '00' }}
  29. </view>
  30. </view>
  31. </view>
  32. <view class="trailer-actions">
  33. <button open-type="share" class="button-reset share-button">
  34. <view class="action-button mr18" @click="handleAgreement">
  35. <text>分享给好友</text>
  36. </view>
  37. </button>
  38. <view class="action-button reserve-button" @click="handleAgreement">
  39. <image class="button-icon mr8" src="/static/images/trailer.png"></image>
  40. <text>预约直播</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 无直播状态 -->
  45. <view class="trailer-box" v-if="!liveItem">
  46. <image class="trailer-placeholder"
  47. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/no_live.png">
  48. </image>
  49. <view class="no-live-title">暂无直播</view>
  50. </view>
  51. <!-- 主要内容区域 -->
  52. <view class="content" :class="{ 'horizontal-content': isFocus==1, 'trailer-content': liveItem.status==1 }">
  53. <!-- 顶部信息栏 -->
  54. <view class="top-info-bar" :class="liveItem.showType == 1 ? 'horizontal-top' : ''">
  55. <view class="user-info-section">
  56. <image v-if="!scene" @click="goBack" class="back-icon mr4"
  57. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/return3.png" />
  58. <view class="user-avatar-container">
  59. <u-avatar
  60. :src="liveItem.liveImgUrl || 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/avatar.png'"
  61. :size="32"></u-avatar>
  62. <view class="user-name ml10 mr6">
  63. <view>{{ liveItem.liveName ? truncateString(liveItem.liveName, 8) : '未命名' }}</view>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 观众头像列表 -->
  68. <!-- @click="toggleViewerList" -->
  69. <view v-if="Array.isArray(filteredViewers)" class="viewers-section">
  70. <view v-for="(item, index) in (filteredViewers ||[])" :key="index">
  71. <image v-if="item" class="viewer-avatar mr4" :src="item" />
  72. <!-- <view v-else class="viewer-avatar-placeholder mr4"
  73. :style="{ backgroundColor: getUserRandomColor(item.userId) }">
  74. <text class="avatar-initial">{{ getNicknameInitial(item.nickName) }}</text>
  75. </view> -->
  76. </view>
  77. <view class="viewer-count ">{{virtualHuman || 0 }}</view>
  78. </view>
  79. </view>
  80. <!-- 购买提示 -->
  81. <!-- <view class="purchase-prompt"
  82. v-if="showPurchasePrompt && orderUser && orderUser.count && liveItem.status == 2">
  83. <image class="prompt-icon mr8"
  84. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/shopping.png" />
  85. <text>{{ orderUser.count || 0 }}人正在去购买</text>
  86. </view> -->
  87. <!-- 视频区域 -->
  88. <view class="videolist" v-if="liveItem.status == 2">
  89. <view class="video-container" :class="liveItem.showType == 1 ? 'horizontal-layout' : ''">
  90. <!-- <video v-if="liveItem.videoUrl && liveItem.liveType == 2&&!generating" :id="`myVideo_${liveId}`"
  91. :autoplay="true" class="video-player" :src="liveItem.videoUrl" object-fit="contain"
  92. :custom-cache="false" :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false"
  93. :show-center-play-btn="false" :http-cache="false" loop @error="videoError"
  94. @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  95. @play="onVideoPlay" @waiting="onVideoWaiting" :enable-play-gesture="false"
  96. :play-strategy="1" @dblclick="preventDoubleClick" preload="auto"
  97. :enable-stash-buffer="false" :stash-initial-size="0" :stash-max-size="0" :stash-time="0"
  98. type="application/x-mpegURL" :controls="isPlayback"></video> -->
  99. <video v-if="liveItem.videoUrl && liveItem.liveType == 2 && !generating"
  100. :id="`myVideo_${liveId}`" :autoplay="true" class="video-player" :src="liveItem.videoUrl"
  101. object-fit="contain" :custom-cache="false" :enable-progress-gesture="false"
  102. vslide-gesture-in-fullscreen="true" :show-center-play-btn="false" :http-cache="false" loop
  103. @error="videoError" @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded"
  104. @pause="onVideoPause" @play="onVideoPlay" @waiting="onVideoWaiting"
  105. :enable-play-gesture="false" :play-strategy="1" @dblclick="preventDoubleClick"
  106. preload="auto" :enable-stash-buffer="false" :stash-initial-size="0" :stash-max-size="0"
  107. :stash-time="0" type="application/x-mpegURL" :controls="false" show-fullscreen-btn
  108. show-play-btn show-mute-btn enable-play-gesture="true"></video>
  109. <view v-else class="txt">回放生成中...</view>
  110. <view v-if="isPlayback" class="replay-label">回放</view>
  111. </view>
  112. </view>
  113. <!-- 直播结束状态 -->
  114. <!-- v-if="liveItem.status == 3" -->
  115. <view class="videolist" v-if="liveItem.status == 3">
  116. <view class="video-container" :class="liveItem.showType == 1 ? 'horizontal-layout' : ''">
  117. <view class="live-end-message">直播已结束</view>
  118. </view>
  119. </view>
  120. <!-- 直播回放 -->
  121. <view class="videolist" v-if="liveItem.status == 4">
  122. <view class="video-container" :class="liveItem.showType == 1 ? 'horizontal-layout' : ''">
  123. <video v-if="liveItem.videoUrl && liveItem.liveType == 3" :id="`myVideo_${liveId}`"
  124. class="video-player" :src="liveItem.videoUrl" :autoplay="true" :controls="true"
  125. object-fit="contain" :custom-cache="false"
  126. :enable-progress-gesture="liveItem.isSpeedAllowed" vslide-gesture-in-fullscreen="true"
  127. :show-center-play-btn="true" :http-cache="false" loop @error="videoError"
  128. @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  129. @play="onVideoPlay" :enable-play-gesture="true" preload="auto" @waiting="onVideoWaiting"
  130. type="application/x-mpegURL"></video>
  131. <view v-if="liveItem.videoUrl && liveItem.liveType == 3" class="replay-label">直播回放</view>
  132. </view>
  133. </view>
  134. <!-- 底部聊天区域 -->
  135. <view class="chat-area-container" :class="{
  136. 'chat-area-container2': liveItem.showType == 1,
  137. 'chat-area-container3': liveItem.status == 1,
  138. 'chat-area-focused': isFocus
  139. }" :style="{ '--keyboard-height': keyboardHeight + 'rpx' }">
  140. <view class="tabs_bg" v-if="liveItem.showType == 1">
  141. <u-tabs :list="listTabs" @click="clickTabs" lineColor="#02B176"
  142. :activeStyle="{color: '#02B176',fontWeight: 'bold',transform: 'scale(1.05)'}">
  143. </u-tabs>
  144. </view>
  145. <view class="chat-content-wrapper" :class="{ 'chat-content-focused': isFocus }">
  146. <view class="notice-message" v-if="!isFocus&&isShowNotice"
  147. :class="liveItem.showType == 1 ? 'horizontal-notice' : ''">
  148. 公告消息: {{notice.msg}}
  149. </view>
  150. <scroll-view id="msgScroll" v-if="Array.isArray(talklist)" enable-flex scroll-y="true"
  151. :enhanced="true" :bounces="false" :show-scrollbar="false" :fast-deceleration="false"
  152. :enable-back-to-top="false" class="message-scroll-view" :scroll-top="scrollTop"
  153. :scroll-into-view="scrollIntoView" @scroll="onScroll" ref="scrollView">
  154. <view class="message-list" v-for="(item, talkIndex) in (talklist || [])"
  155. :key="item.uniqueId " :id="`list_${item.uniqueId }`" v-show="item.cmd != 'red' ">
  156. <view class="message-item">
  157. <view class="message-content">
  158. <text class="user-nickname">{{ item.nickName || '未命名' }}
  159. <text v-if="item.cmd != 'entry'">:</text>
  160. </text>
  161. <text class="message-text ml8">{{ item.msg }}</text>
  162. </view>
  163. </view>
  164. </view>
  165. </scroll-view>
  166. </view>
  167. <!-- 底部输入和操作区域 -->
  168. <view class="input-actions-container" :class="{ 'input-actions-focused': isFocus }">
  169. <view v-if="liveItem.status!=3&&!isPlayback" class="input-container" :class="{
  170. 'input-container-focused': isFocus,
  171. 'input-container-normal': !isFocus
  172. }">
  173. <input v-if="isIOS" type="text" :placeholder="placeholderText" v-model="value"
  174. :placeholder-style="liveItem.showType == 1 ? 'color:#999999;' : 'color:#e7e7e7;'"
  175. placeholder-class="placeholder-style" class="chat-input"
  176. :class="{ 'input-focused': isFocus }" @focus="inputFocus" @blur="inputBlur"
  177. cursor-spacing="100" :adjust-position="false" :disabled="isEnd" @confirm="sendMsg" />
  178. <input v-else :placeholder="placeholderText" v-model="value"
  179. :placeholder-style="liveItem.showType == 1 ? 'color:#999999;' : 'color:#e7e7e7;'"
  180. placeholder-class="placeholder-style" class="chat-input"
  181. :class="{ 'input-focused': isFocus }" @focus="inputFocus" @blur="inputBlur"
  182. cursor-spacing="100" :adjust-position="false" :disabled="isEnd" />
  183. <!-- v-if="isFocus&&!isIOS" -->
  184. <view class="send-button" :class="liveItem.showType == 1 ? 'send2' : ''" @click="sendMsg()">
  185. 发送</view>
  186. </view>
  187. <!-- :class="{ 'action-buttons-hidden': isFocus }" -->
  188. <view class="action-buttons" v-if="!isFocus">
  189. <view class="action-button-group" v-if="!isFocus">
  190. <view
  191. :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-button','ml20']"
  192. @click="isMore=true,shopping=false">
  193. <!-- <image
  194. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/more-icon.png"
  195. class="action-icon" /> -->
  196. <image :src="liveItem.showType == 1
  197. ? '/static/images/more2.png'
  198. :'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/more-icon.png'"
  199. class="action-icon" />
  200. </view>
  201. </view>
  202. <view class="action-button-group" v-if="!isFocus">
  203. <view
  204. :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-button','ml20']">
  205. <button open-type="share" class="action-icon button-reset">
  206. <image class="action-icon"
  207. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/weixin.png"
  208. mode="widthFix" />
  209. </button>
  210. </view>
  211. </view>
  212. <view class="icon-button " @tap="openCart()">
  213. <image
  214. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/shopping.png"
  215. class="cart-icon" />
  216. </view>
  217. <view class="action-button-group" v-if="!isFocus">
  218. <view
  219. :class="[liveItem.showType === 1 ? 'horizontal' : 'vertical','icon-button','ml20','like-container']"
  220. @click="onLike">
  221. <LikeButton :initialCount="100" :heartsPerClick="5" @like="onLike" />
  222. <view class="like-count">{{formattedLikeCount||0 }}</view>
  223. </view>
  224. </view>
  225. </view>
  226. </view>
  227. </view>
  228. </view>
  229. <!-- 商品卡片 -->
  230. <view class="goods-card" v-if="isShowGoods" @click.stop="goShop(goodsCard.productId, goodsCard.goodsId)">
  231. <view class="goods-card-header">
  232. <view class="goods-status">
  233. <image class="status-icon mr8"
  234. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/signal.png" />
  235. 主播讲解中
  236. </view>
  237. <image @click.stop="isShowGoods = false" class="close-icon" src="/static/images/close_w.png" />
  238. </view>
  239. <image class="goods-image" :src="goodsCard.imgUrl" />
  240. <view class="goods-info">
  241. <view class="goods-title oneline-hide">{{ goodsCard.productName }}</view>
  242. <view class="goods-action">
  243. <view class="goods-price">
  244. <text class="price-symbol">¥<text class="price-integer">{{ goodsCard.price }}</text> <text
  245. class="price-decimal"></text></text>
  246. </view>
  247. <image class="shop-icon" src="/static/images/shop.png"></image>
  248. </view>
  249. </view>
  250. </view>
  251. <!-- :show="userlogo" -->
  252. <u-popup :show="userlogo" mode="bottom" round='12'>
  253. <view class="userlogo column">
  254. <!-- <view class="mtb30 justify-start align-center ml20">
  255. <u-avatar :src="imgPath+'/app/image/logo.png'" size="50"></u-avatar>
  256. <view class="bold mlr20">{{imgname}}</view>
  257. <view>申请</view>
  258. </view> -->
  259. <view class="bold fs36 ml20">授权你的昵称信息</view>
  260. <view class="mtb20 justify-between align-center plr20">
  261. <view class="button-container">
  262. <input type="nickname" class="hidden-input" @blur="onNickNameInput" placeholder="请点击授权微信昵称"
  263. @input="onNickNameInput" />
  264. <!-- <button class="custom-button"
  265. :class="nameuser==''?'subname':'subavt'">{{nameuser?"已授权":'允许授权'}}</button> -->
  266. </view>
  267. </view>
  268. <view class="submitname" @click="confimrname">确定</view>
  269. </view>
  270. </u-popup>
  271. <!-- 抽奖弹窗 -->
  272. <u-popup :show="isShowLotteryPop && countdown" round="40rpx">
  273. <view class="lottery-popup">
  274. <image class="lottery-header-image"
  275. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_head.png"
  276. mode="widthFix" />
  277. <image class="lottery-background-image"
  278. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_bg.png" />
  279. <view class="lottery-content">
  280. <view class="lottery-close-section">
  281. <view class="close-button-wrapper">
  282. <view class="close-button" @click="isShowLotteryPop = false">
  283. <u-icon class="close-icon" name="close" color="#fff" size="20"></u-icon>
  284. </view>
  285. </view>
  286. </view>
  287. <view class="lottery-main-content">
  288. <image class="lottery-title-image"
  289. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_title.png" />
  290. <view class="lottery-countdown-section">
  291. <view class="countdown-label">开奖倒计时</view>
  292. <view class="countdown-timer">
  293. <view class="countdown-number">
  294. {{ countdown.hours || '00' }}
  295. </view>
  296. <view class="countdown-number">
  297. {{ countdown.minutes || '00' }}
  298. </view>
  299. <view class="countdown-number">
  300. {{ countdown.seconds || '00' }}
  301. </view>
  302. </view>
  303. </view>
  304. <view class="lottery-products-section">
  305. <ThreeItemSwiper :products="lotteryProducts"></ThreeItemSwiper>
  306. </view>
  307. <view class="lottery-indicators">
  308. <view class="indicator-point" v-for="(item, index) in (lotteryProducts || [])"
  309. :key="index"></view>
  310. </view>
  311. <view class="lottery-tip">观看直播参与抽奖</view>
  312. <view class="lottery-action-button" @click="onClaim">参与抽奖</view>
  313. </view>
  314. </view>
  315. </view>
  316. </u-popup>
  317. <!-- 积分弹窗 -->
  318. <u-popup :show="!!integral.status" round="20rpx" mode="center" bgColor="#ffffff" zIndex="10076">
  319. <view class="integral-popup color9">
  320. <view class="integral-header">
  321. <view class="integral-title">观看视频领积分</view>
  322. <image class="integral-background-image"
  323. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/integral_bg.png"
  324. mode="widthFix" />
  325. </view>
  326. <view class="integral-content">
  327. <view class="integral-message">{{ integral.msg }}</view>
  328. <view class="integral-confirm-button" @click="integral.status = false">确认</view>
  329. </view>
  330. </view>
  331. </u-popup>
  332. <!-- 红包弹窗 -->
  333. <u-popup :show="isShowRed" round="20rpx" mode="center" zIndex="10076" bgColor="transparent">
  334. <view class="red-envelope-popup" @click="onRed()">
  335. <image class="red-envelope-close-button"
  336. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/close_white.png"
  337. @click.stop="isShowRed=false"></image>
  338. <image class="red-envelope-background"
  339. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/pop1.png"></image>
  340. <view class="red-envelope-content">
  341. <view class="red-envelope-header">
  342. <image class="header-decoration-left"
  343. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_left.png"
  344. mode="widthFix" />
  345. <view class="header-title">恭喜您可以</view>
  346. <image class="header-decoration-right"
  347. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_right.png"
  348. mode="widthFix" />
  349. </view>
  350. <view class="red-envelope-text">领红包</view>
  351. <view class="red-envelope-open-text">开</view>
  352. </view>
  353. </view>
  354. </u-popup>
  355. <!-- 抽奖弹窗2 -->
  356. <u-popup :show="isShowLottery&&countdown" round="20rpx" mode="center" zIndex="10076" bgColor="transparent">
  357. <view class="lottery-popup-v2">
  358. <image class="lottery-close-button-v2"
  359. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/close_white.png"
  360. @click.stop="isShowLottery=false">
  361. </image>
  362. <image class="lottery-top-image"
  363. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/pop_top.png"
  364. mode="widthFix"></image>
  365. <image class="lottery-background-v2"
  366. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/pop2.png"></image>
  367. <view class="lottery-content-v2">
  368. <view class="lottery-header-v2">
  369. <image class="lottery-header-decoration-left"
  370. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_left.png"
  371. mode="widthFix" />
  372. <view class="lottery-header-title">恭喜您可以</view>
  373. <image class="lottery-header-decoration-right"
  374. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/top_right.png"
  375. mode="widthFix" />
  376. </view>
  377. <view class="lottery-text-v2">参与抽奖</view>
  378. <view class="lottery-text-v2">赢好礼</view>
  379. <view class="lottery-action-button-v2" @click="onLottery()">确认</view>
  380. </view>
  381. </view>
  382. </u-popup>
  383. <!-- 红包卡片弹窗 -->
  384. <u-popup :show="isShowRedCard" round="20rpx" mode="center" bgColor="transparent" zIndex="10076">
  385. <view class="red-card-popup">
  386. <image class="red-card-image"
  387. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_card.png" />
  388. <view class="red-card-content">
  389. <view class="red-card-message">{{ redCard.msg }}</view>
  390. <view class="red-card-tip">直播惊喜积分</view>
  391. <view class="red-card-confirm-button" @click="isShowRedCard = false">确认</view>
  392. </view>
  393. </view>
  394. </u-popup>
  395. <!-- 消息弹窗 -->
  396. <u-popup :show="isShowPopMsg" round="20rpx" mode="center" zIndex="10076">
  397. <view class="message-popup">
  398. <image class="message-close-icon"
  399. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/del2.png"
  400. @click="isShowPopMsg = false" />
  401. <view class="message-title">消息通知</view>
  402. <view class="message-content">{{popMsg}}</view>
  403. <view class="message-confirm-button" @click="isShowPopMsg = false">确认</view>
  404. </view>
  405. </u-popup>
  406. <!-- 中奖和未中奖 -->
  407. <u-popup :show="isShowPrize && havePrize" round="20rpx" mode="center" bgColor="#fff" zIndex="10076">
  408. <view class="prize-popup" v-if="isCurrentUserWon">
  409. <image class="prize-header-image"
  410. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_head.png"
  411. mode="widthFix" />
  412. <view class="prize-title">恭喜您 中奖啦!</view>
  413. <view class="prize-info-section" v-for="(item, index) in (prizeInfo || [])" :key="index">
  414. <view class="prize-info-item">{{ item.userName }}</view>
  415. <view class="prize-info-item">{{ item.userId }}</view>
  416. <view class="prize-level item">{{ item.prizeLevel }}等奖</view>
  417. </view>
  418. <view class="prize-tip">请填写收货地址,主播将会将奖品发给您</view>
  419. <view class="prize-action-button"
  420. @click="navgetTo('/pages_shopping/live/confirmCreateOrder?type=win&productId='+getCurrentUserPrizeProductId+'&liveId='+liveId+'&recordId='+getCurrentUserPrizeRecordId),confirm()">
  421. 填写地址</view>
  422. </view>
  423. <view class="no-prize-popup" v-else>
  424. <image class="no-prize-image"
  425. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/no-prize.png"
  426. mode="widthFix" />
  427. <view class="no-prize-tip">很遗憾 您未中奖</view>
  428. <view class="no-prize-confirm-button" @click="confirm">确认</view>
  429. </view>
  430. </u-popup>
  431. <!-- 中奖记录弹窗 -->
  432. <u-popup :show="winning" @close="closeWin" round="20rpx" bgColor="#f3f5f9" zIndex="10076">
  433. <view class="winning-record-popup">
  434. <image class="winning-record-header-bg"
  435. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_head.png"
  436. mode="widthFix"></image>
  437. <image class="winning-record-background"
  438. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/red_bg.png"></image>
  439. <view class="winning-record-content">
  440. <view class="winning-record-title">我的中奖记录</view>
  441. <view class="winning-record-header">
  442. <view class="header-column time-column">时间</view>
  443. <view class="header-column status-column">状态</view>
  444. <view class="header-column prize-column">奖品</view>
  445. </view>
  446. <scroll-view v-if="prizeAll" enable-flex scroll-y class="winning-record-list">
  447. <view class="winning-record-item" v-for="(item, index) in (prizeAll||[])" :key="index">
  448. <view class="record-time">{{ item.createTime }}</view>
  449. <view class="record-status-button" v-if="item.orderStatus=='-9'||!item.orderStatus"
  450. @click="navgetTo('/pages_shopping/live/confirmCreateOrder?type=win&productId='+item.productId+'&liveId='+liveId+'&recordId='+item.id),winning=false">
  451. <text>填地址</text>
  452. </view>
  453. <view class="record-status" v-else>
  454. <text v-if="item.orderStatus=='1'">待支付</text>
  455. <text v-if="item.orderStatus=='2'">待发货</text>
  456. <text v-if="item.orderStatus=='3'">待收货</text>
  457. <text v-if="item.orderStatus=='4'">已完成</text>
  458. <text v-if="item.orderStatus=='-3'">已取消</text>
  459. </view>
  460. <view class="record-prize">
  461. {{ item.productName ? truncateString(item.productName, 6) : '' }}
  462. </view>
  463. </view>
  464. </scroll-view>
  465. <view v-else class="no-winning-records">暂无中奖信息</view>
  466. </view>
  467. </view>
  468. </u-popup>
  469. <!-- 观众列表弹窗 -->
  470. <!-- <u-popup :show="showadd" @close="close" @open="openViews" round="20rpx" bgColor="#ffffff" zIndex="10077">
  471. <view class="view-box">
  472. <view class="fs32" style="text-align: center">在线观众</view>
  473. <scroll-view v-if="Array.isArray(liveViewers)" scroll-y class="scroll-content"
  474. :style="{ height: scrollHeight + 'px' }" @scrolltolower="handleScrollToLower">
  475. <view class="fs28 x-f mb20 mt20" v-for="(item, index) in (liveViewers || [])" :key="index">
  476. <view :style="{
  477. color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',
  478. fontWeight: index < 3 ? 'bold' : 'normal',
  479. width: '50rpx'
  480. }" class="mr10">
  481. {{ index + 1 }}
  482. </view>
  483. <u-avatar v-if="item.avatar" :src="item.avatar" :size="36"></u-avatar>
  484. <view v-else class="w72 h72"
  485. :style="{ backgroundColor: getUserRandomColor(item.userId), borderRadius: '50%' }">
  486. <text class="text-white text-sm">{{ getNicknameInitial(item.nickName) }}</text>
  487. </view>
  488. <text class="ml16 f30">{{ item.nickName || '未命名' }}</text>
  489. </view>
  490. </scroll-view>
  491. </view>
  492. </u-popup> -->
  493. <!-- 更多操作弹窗 -->
  494. <u-popup :show="isMore" @close="closeMore" round="20rpx" bgColor="#f3f5f9" zIndex="10076">
  495. <view class="more-actions-popup">
  496. <view class="more-action-item" @click="navgetTo('/pages_shopping/live/integral'), (isMore = false)">
  497. <image class="action-icon"
  498. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/order.png" />
  499. <view class="action-label">积分</view>
  500. </view>
  501. <view class="more-action-item"
  502. @click="navgetTo('/pages_shopping/live/storeOrderRefundList?liveId=' + liveId), (isMore = false)">
  503. <image class="action-icon"
  504. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/after_sales.png" />
  505. <view class="action-label">售后订单</view>
  506. </view>
  507. <view class="more-action-item" @click="goMiniProgram(), (isMore = false)">
  508. <image class="action-icon"
  509. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/points.png" />
  510. <view class="action-label">兑换好礼</view>
  511. </view>
  512. <view class="more-action-item" @click="getMyLottery(), (isMore = false), (winning = true)">
  513. <image class="action-icon"
  514. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/health_sel.png" />
  515. <view class="action-label">中奖记录</view>
  516. </view>
  517. </view>
  518. </u-popup>
  519. <!-- 商品弹窗 -->
  520. <u-popup :show="shopping" @close="closeShop" round="20rpx" bgColor="#f3f5f9" zIndex="10075">
  521. <view class="shopping-popup">
  522. <view class="shopping-header">
  523. <view class="search-input-container">
  524. <image class="search-icon"
  525. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/search.png"
  526. mode="widthFix" />
  527. <input placeholder="请搜索商品" v-model="inputInfo" @input="handleSearchInput" />
  528. </view>
  529. <view class="x-f">
  530. <view class="shopping-action-button mr30" @click="navgetTo('/pages_shopping/live/order')">
  531. <image class="action-button-icon"
  532. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/carts.png" />
  533. <view class="action-button-label">订单</view>
  534. </view>
  535. <view class="shopping-action-button" @click="(isMore = true), (shopping = false)">
  536. <image class="action-button-icon"
  537. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/search2.png" />
  538. <view class="action-button-label">更多</view>
  539. </view>
  540. </view>
  541. </view>
  542. <scroll-view enable-flex scroll-y class="products-list">
  543. <view v-for="(item, index) in products" :key="index" class="product-item">
  544. <view class="product-image-container">
  545. <image class="product-image" :src="item.imgUrl" mode="widthFix" />
  546. <view class="product-index-label">{{ index + 1 }}</view>
  547. </view>
  548. <view class="product-info">
  549. <view class="product-name">{{ item.productName }}</view>
  550. <view class="product-sales">{{ item.sales }} 人已购</view>
  551. <view class="product-action-section">
  552. <text class="product-price">
  553. <text class="price-symbol">¥</text>
  554. <text class="price-integer">{{ Math.trunc(item.price) }}</text>
  555. .{{ getPureDecimal(item.price) ? getPureDecimal(item.price) : '00' }}
  556. </text>
  557. <view class="product-action-buttons">
  558. <view class="collect-button">
  559. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  560. class="collect-icon"
  561. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/collect_select.png" />
  562. <image v-else @click="onGoodsCollect(item)" class="collect-icon"
  563. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/collect.png" />
  564. </view>
  565. <view v-if="item.status == 1" class="buy-button"
  566. @click="goShop(item.productId, item.goodsId)">去购买</view>
  567. <view v-else-if="item.status == 0" class="buy-button disabled">已下架</view>
  568. </view>
  569. </view>
  570. </view>
  571. </view>
  572. </scroll-view>
  573. </view>
  574. </u-popup>
  575. <!-- 优惠券弹窗 -->
  576. <view class="coupon-popup" v-if="isShowCoupon">
  577. <view class="coupon-container">
  578. <image class="coupon-background"
  579. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/coupon_bg.png" />
  580. <image class="coupon-header"
  581. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/coupon_top.png" />
  582. <image @click="isShowCoupon = false" class="coupon-close-button"
  583. src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/close_white.png" />
  584. <view class="coupon-content">
  585. <view class="coupon-name">{{ couponInfo.couponName }}</view>
  586. <view class="coupon-price">
  587. <text class="coupon-price-integer">{{ couponInfo.couponPrice }}</text>
  588. </view>
  589. <view class="coupon-condition">满{{ couponInfo.useMinPrice }}元可用</view>
  590. <view class="coupon-description">指定商品可用</view>
  591. <view class="coupon-validity">自领取起{{ couponInfo.couponTime }}天内有效</view>
  592. <view class="coupon-get-button" @click="onCoupon()">立即领券</view>
  593. </view>
  594. </view>
  595. </view>
  596. <view v-if="liveItem.status == 1" class="ash_bg"></view>
  597. </view>
  598. </view>
  599. </template>
  600. <script>
  601. import LikeButton from '@/pages_course/components/like.vue';
  602. import ThreeItemSwiper from '@/pages_course/components/ThreeItemSwiper.vue';
  603. import CryptoJS from 'crypto-js';
  604. import {
  605. myLiveMsg,
  606. myLottery, // 我的中奖明细
  607. coupon, //领取优惠券
  608. liveLottery, // 抽奖查询
  609. claim, //抽奖
  610. liveRed, // 点击领红包
  611. liveDataLike, // 点赞
  612. collectStore, // 店铺收藏/取消收藏
  613. collectGoods, // 商品收藏/取消收藏
  614. watchUserList, //获取直播间用户(展示在线用户)
  615. liveMsg, //获取最近聊天记录
  616. // 小黄车
  617. liveStore, //店铺展示,
  618. liveOrderUser, //正在购买
  619. getLiveInfo, //获取直播间信息接口
  620. getLiveViewData, //直播间点赞、关注、在线人数数据
  621. currentActivities, //红包 卡片 抽奖
  622. getlive,
  623. subNotifyLive,
  624. internetTraffic, // 流量(缓冲百分比),
  625. liveInternetTraffic, // 直播流量(缓冲百分比),
  626. loginByMp,
  627. getUserInfo
  628. } from '@/api/living.js';
  629. import {
  630. editUser
  631. } from '@/api/user'
  632. // import {
  633. // generateRandomString
  634. // } from '@/utils/common.js';
  635. import dayjs from 'dayjs';
  636. import {
  637. nextTick
  638. } from 'vue';
  639. import {
  640. mapGetters
  641. } from 'vuex';
  642. import {
  643. TOKEN_KEYAuto,
  644. generateRandomString
  645. } from '@/utils/courseTool.js'
  646. var isSocketOpen = false;
  647. var socket = null;
  648. export default {
  649. components: {
  650. ThreeItemSwiper,
  651. LikeButton
  652. },
  653. data() {
  654. return {
  655. fakeAvatar: Array.from({
  656. length: 11
  657. }, (_, i) =>
  658. `https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/avatar${i + 1}.jpg`),
  659. virtualHuman: null,
  660. userlogo: false,
  661. listTabs: [{
  662. name: '讨论',
  663. }],
  664. generating: false,
  665. hasPlayback: false,
  666. isPlayback: false, //是否是回放
  667. isIOS: false,
  668. myselfFlag: false, // yhq
  669. isEnd: false,
  670. popMsg: null,
  671. // barrageList: ['支持你!', '谢谢你!', '平台真好!', '666', '欢迎回家!'], //一键弹幕列表
  672. uuId: '',
  673. totalTraffic: 0, // 总流量(字节)
  674. bitrate: 800, // 录播默认码率 0.16Mbps
  675. bitrateLive: 1600, // 直播默认码率 0.16Mbps
  676. //定时器
  677. trafficTimer: null,
  678. pingTimeoutTimer: null, // 心跳超时定时器
  679. heartBeatTimer: null, // 心跳定时器
  680. liveViewDataTimer: null,
  681. reconnectTimer: null, // 重连定时器
  682. scrollTimer: null, // 滚动防抖定时器
  683. lastScrollTime: 0, // 上次滚动时间
  684. scrollDebounceDelay: 200, // 滚动防抖延迟(毫秒)
  685. searchTimer: null, //搜索
  686. purchasePromptTimer: null, //购买提示
  687. welcomeTimer: null, //进入离开直播间定时器
  688. redTimer: null,
  689. liveStartTimer: null,
  690. lotteryTimer: null,
  691. memoryMonitorTimer: null, // 内存监控定时器
  692. networkStatusTimer: null, // 网络状态检测定时器
  693. networkRetryTimer: null, // 网络重试定时器
  694. lastHeartBeatTime: 0, // 上次心跳时间
  695. // 性能监控
  696. connectionStartTime: 0, // 连接开始时间
  697. connectionLatency: 0, // 连接延迟
  698. messageCount: 0, // 消息计数
  699. errorCount: 0, // 错误计数
  700. lastPerformanceCheck: 0, // 上次性能检查时间
  701. stayTime: 0,
  702. startTime: 0,
  703. scrollTop: 0,
  704. currentScrollTop: 0, // 当前实际滚动位置
  705. scrollIntoView: '', // scroll-into-view属性
  706. messageIdCounter: 0, // 消息ID计数器,确保每个消息有唯一ID
  707. scrollPending: false, // 滚动操作是否正在等待执行
  708. isOnload: false,
  709. isConnecting: false, // 是否正在连接中
  710. hasInitialized: false,
  711. liveViewersData: [],
  712. liveUserCalled: false, //调用过watchUserList没
  713. userRandomColors: Object.create(null), // 缓存用户ID -> 随机色的映射
  714. heartBeatRetryCount: 0, // 心跳发送重试次数(避免一次失败就重连)
  715. maxHeartBeatRetries: 3, // 心跳最大重试次数(增加到3次)
  716. pingTimeout: 25000, // 心跳超时时间(25秒,适应移动网络)
  717. shownEntryUsers: new Set(), // 存储已显示过「进入提示」的用户ID
  718. socket: null, // WebSocket 实例
  719. isSocketOpen: false, // 连接是否已打开
  720. heartBeatInterval: 15000, // 心跳发送间隔(15秒)
  721. adaptiveHeartBeatInterval: 15000, // 自适应心跳间隔
  722. reconnectCount: 0, // 当前重连次数f
  723. maxReconnectAttempts: 5, // 最大重连次数(增加到5次)
  724. isManualClose: false, // 是否手动关闭(用于区分主动关闭和异常断开)
  725. networkType: 'unknown', // 当前网络类型
  726. isNetworkAvailable: true, // 网络是否可用
  727. templateId: 'IKffTm6HnbLS91hDCUnKSQpC2r4EABo3fOtThnK1dI8', //百域承品
  728. isAgreement: false,
  729. wsNewUrl: 'wss://api.fhhx.runtzh.com/ws/app/webSocket',
  730. // wsNewUrl: 'ws://192.168.10.166:7114/ws/app/webSocket',
  731. qrFrom: null,
  732. scene: '',
  733. liveCountdown: {}, //直播倒计时
  734. countdown: {}, //抽奖倒计时
  735. liveViewData: {},
  736. keyboardHeight: 0,
  737. videoCurrentTime: 0, // 当前视频播放时间
  738. videoProgressKey: '', // 存储进度的key
  739. inAndOut: {},
  740. winning: false,
  741. isShowPrize: false,
  742. isShowCoupon: false,
  743. prizeInfo: [],
  744. havePrize: uni.getStorageSync('havePrize') || false, //是否参与抽奖
  745. countDownKey: 0,
  746. lotteryProducts: [],
  747. lotteryList: [],
  748. talklist: [],
  749. isShowLotteryPop: false,
  750. liveItem: {},
  751. isSending: false,
  752. isMore: false,
  753. value: '',
  754. placeholderText: '说点什么...',
  755. prizeAll: [],
  756. isShowLottery: false,
  757. isShowRedCard: false,
  758. isShowPopMsg: false,
  759. isShowNotice: false,
  760. notice: [],
  761. redCard: null, //点击红包出现弹窗
  762. integral: {},
  763. lotteryInfo: {},
  764. goodsCard: {},
  765. couponInfo: {},
  766. redInfo: {},
  767. storeId: null,
  768. isFocus: false,
  769. shopping: false,
  770. systemInfo: null, // 缓存系统信息,避免重复调用同步API
  771. inputInfo: '',
  772. showWelcomeMessage: false,
  773. isShowGoods: false,
  774. isShowRed: false,
  775. lastClickTime: 0,
  776. videoRetryCounts: Object.create(null), // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  777. clickDelay: 300, // 300ms内只响应一次点击
  778. liveUserTotal: 0,
  779. viewPageSize: 10, // 每页数量
  780. viewPageNum: 1, // 当前页码
  781. viewLoading: false, // 是否正在加载
  782. scrollHeight: 0,
  783. showPurchasePrompt: false,
  784. prevOrderCount: 0, // 用于记录上一次的购买人数
  785. videoUrl: null,
  786. showType: 1, //横屏1 竖屏2
  787. boxHeight: 300, //小黄车高度
  788. liveViewers: [], //观众
  789. livingUrl: '',
  790. products: [],
  791. loadingProducts: false, // 商品加载状态
  792. orderUser: {}, //正在购买
  793. userType: 0,
  794. timestamp: '',
  795. showadd: false,
  796. liveId: null,
  797. userInfo: {}, //用户信息
  798. userData: {},
  799. diffTotalTime: '',
  800. address: '',
  801. user: {}
  802. };
  803. },
  804. async onLoad(options) {
  805. this.initTime()
  806. this.getLocationByIP();
  807. if (options.liveId) {
  808. this.liveId = options.liveId;
  809. }
  810. // 扫码传来的参数
  811. if (options.scene) {
  812. this.scene = options.scene;
  813. const decodedScene = decodeURIComponent(this.scene);
  814. const params = {};
  815. decodedScene.split('&').forEach((item) => {
  816. const [key, value] = item.split('=');
  817. params[key] = value;
  818. this.liveId = params.a;
  819. });
  820. if (params.b && params.c) {
  821. console.log("扫码参数", params)
  822. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  823. }
  824. }
  825. if (options.companyId && options.companyUserId) {
  826. this.qrFrom = `&companyId=${options.companyId}&companyUserId=${options.companyUserId}`;
  827. }
  828. this.userinfo = uni.getStorageSync('userinfo');
  829. // this.userData = uni.getStorageSync('userData');
  830. console.log('全部参数', options);
  831. try {
  832. const isLogin = await this.utils.checkLiveToken();
  833. if (isLogin) {
  834. this.haveLogin()
  835. }
  836. } catch (error) {
  837. console.error('初始化失败:', error);
  838. }
  839. //获取键盘高度 - 针对iPhone优化(使用缓存的系统信息)
  840. uni.onKeyboardHeightChange((res) => {
  841. console.log('键盘高度变化:', res.height, '平台:', this.systemInfo.platform);
  842. if (this.systemInfo.platform === 'ios') {
  843. // iPhone特殊处理
  844. if (res.height > 0) {
  845. // 键盘弹出
  846. this.isKeyboardShow = true;
  847. // iPhone键盘高度计算优化
  848. let calculatedHeight = res.height * 2;
  849. // 根据iPhone型号进行微调
  850. if (this.systemInfo.model) {
  851. if (this.systemInfo.model.includes('iPhone X') ||
  852. this.systemInfo.model.includes('iPhone 11') ||
  853. this.systemInfo.model.includes('iPhone 12') ||
  854. this.systemInfo.model.includes('iPhone 13') ||
  855. this.systemInfo.model.includes('iPhone 14') ||
  856. this.systemInfo.model.includes('iPhone 15') ||
  857. this.systemInfo.model.includes('iPhone 16') ||
  858. this.systemInfo.model.includes('iPhone 17')) {
  859. // 刘海屏设备需要额外调整
  860. calculatedHeight = calculatedHeight + 20; // 增加20rpx补偿
  861. }
  862. }
  863. // 减去底部安全区域,避免过高
  864. const safeAreaBottom = this.systemInfo.safeAreaInsets ? this.systemInfo.safeAreaInsets
  865. .bottom : 0;
  866. if (safeAreaBottom > 0) {
  867. calculatedHeight = calculatedHeight - (safeAreaBottom * 2.0); // 微调10rpx
  868. }
  869. this.keyboardHeight = Math.max(400, calculatedHeight);
  870. } else {
  871. // 键盘隐藏
  872. this.isKeyboardShow = false;
  873. this.keyboardHeight = 0;
  874. }
  875. } else {
  876. console.log("手机型号是>>>>", this.systemInfo.model)
  877. console.log("手机高度是>>>>", this.systemInfo.model)
  878. // Android处理保持原有逻辑
  879. if (res.height > 0) {
  880. this.isKeyboardShow = true;
  881. const safeAreaBottom = this.systemInfo.safeAreaInsets ? this.systemInfo.safeAreaInsets
  882. .bottom : 0;
  883. // this.keyboardHeight = (res.height * 2)-50;
  884. // this.keyboardHeight = res.height * 2;
  885. if (this.systemInfo.brand == 'vivo') {
  886. this.keyboardHeight = res.height * 2;
  887. } else {
  888. // this.keyboardHeight = (res.height * 1.78) + 20;''
  889. this.keyboardHeight = (res.height * 1.88) + 20;
  890. }
  891. console.log("高度是", this.keyboardHeight)
  892. } else {
  893. this.isKeyboardShow = false;
  894. this.keyboardHeight = 0;
  895. }
  896. }
  897. });
  898. // 初始化网络状态监听
  899. this.initNetworkStatusListener();
  900. },
  901. onPullDownRefresh() {
  902. this.getLiveMsg(this.liveItem);
  903. // this.getliveUser();
  904. setTimeout(() => {
  905. uni.stopPullDownRefresh();
  906. }, 1000);
  907. this.getliving(this.liveId);
  908. },
  909. mounted() {
  910. const systemInfo = uni.getSystemInfoSync();
  911. this.isIOS = systemInfo.platform === 'ios';
  912. },
  913. async onShow() {
  914. try {
  915. const isLogin = await this.utils.checkLiveToken();
  916. if (isLogin) {
  917. this.haveLogin()
  918. } else {
  919. this.goLogin();
  920. }
  921. } catch (error) {
  922. console.error('初始化失败:', error);
  923. }
  924. this.getLocationByIP();
  925. this.uuId = generateRandomString(16);
  926. const isLiveLogin = uni.getStorageSync('isLiveLogin');
  927. this.share = uni.getStorageSync('share');
  928. this.scene = uni.getStorageSync('scene');
  929. if (this.share && this.share.length > 0) {
  930. this.liveId = this.share.liveId;
  931. this.qrFrom = `&companyId=${this.share.companyId}&companyUserId=${this.share.companyUserId}`;
  932. uni.removeStorageSync('share');
  933. }
  934. if (this.scene) {
  935. const decodedScene = decodeURIComponent(this.scene);
  936. const params = {};
  937. decodedScene.split('&').forEach((item) => {
  938. const [key, value] = item.split('=');
  939. params[key] = value;
  940. this.liveId = params.a;
  941. });
  942. if (params.b && params.c) {
  943. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  944. }
  945. uni.removeStorageSync('scene');
  946. }
  947. // if (isLiveLogin) {
  948. // if (this.liveId) {
  949. // await this.getliving(this.liveId);
  950. // this.getCurrentActivities();
  951. // this.getliveOrder();
  952. // this.initSocket();
  953. // }
  954. // this.hasInitialized = true;
  955. // uni.removeStorageSync('isLiveLogin');
  956. // }
  957. // 恢复播放和连接
  958. await this.resumePageActivity();
  959. // this.userinfo = JSON.parse(uni.getStorageSync('userInfo'));
  960. this.userinfo = uni.getStorageSync('userinfo');
  961. this.isAgreement = uni.getStorageSync('isAgreement');
  962. this.$nextTick(() => {
  963. this.setVideoProgress();
  964. });
  965. if (this.lookTimer) {
  966. clearInterval(this.lookTimer);
  967. this.lookTimer = null;
  968. this.stayTime = 0;
  969. this.startTime = 0;
  970. }
  971. // 启动内存监控,定期清理
  972. this.startMemoryMonitor();
  973. if (this.trafficTimer) {
  974. clearInterval(this.trafficTimer);
  975. this.trafficTimer = null;
  976. this.startTime = 0;
  977. this.totalTraffic = 0;
  978. }
  979. this.startTimer();
  980. },
  981. //分享给好友
  982. onShareAppMessage() {
  983. return {
  984. title: '邀请你来观看直播:' + this.liveItem.liveName,
  985. path: '/pages_course/living?companyId=-2&companyUserId=' + this.userInfo.userId + '&liveId=' + this.liveId,
  986. imageUrl: '/static/logo.png',
  987. success(res) {
  988. console.log('分享成功', res);
  989. },
  990. fail(err) {
  991. console.error('分享失败', err);
  992. }
  993. };
  994. }, // 分享到朋友圈
  995. onShareTimeline() {
  996. return {
  997. title: '邀请你来观看直播:' + this.liveItem.liveName,
  998. query: 'companyId=-2&companyUserId=' + this.userInfo.userId + '&liveId=' + this.liveId
  999. };
  1000. },
  1001. computed: {
  1002. ...mapGetters(['coureLogin']),
  1003. appid() {
  1004. return this.$store.state.appid
  1005. },
  1006. // 观看人数
  1007. // formattedWatchCount() {
  1008. // return this.formatNumber(this.liveUserTotal || 0);
  1009. // },
  1010. //点赞人数
  1011. formattedLikeCount() {
  1012. return this.formatNumber(this.liveViewData.like || 0);
  1013. },
  1014. filteredViewers() {
  1015. // 获取3个随机假头像,而不是显示真实观众
  1016. const avatarCount = 3; // 需要显示的假头像数量
  1017. // 如果fakeAvatar数组为空或不存在,返回空数组
  1018. if (!this.fakeAvatar || !Array.isArray(this.fakeAvatar) || this.fakeAvatar.length === 0) {
  1019. return [];
  1020. }
  1021. // 从fakeAvatar中随机选择3个不同的头像
  1022. const randomAvatars = [];
  1023. const availableAvatars = [...this.fakeAvatar]; // 创建副本避免修改原数组
  1024. // 确保有足够的头像可选
  1025. if (availableAvatars.length < avatarCount) {
  1026. // 如果头像数量不足,可以重复使用
  1027. for (let i = 0; i < avatarCount; i++) {
  1028. const randomIndex = Math.floor(Math.random() * availableAvatars.length);
  1029. randomAvatars.push(availableAvatars[randomIndex]);
  1030. }
  1031. } else {
  1032. // 随机选择不重复的头像
  1033. for (let i = 0; i < avatarCount; i++) {
  1034. const randomIndex = Math.floor(Math.random() * availableAvatars.length);
  1035. randomAvatars.push(availableAvatars[randomIndex]);
  1036. availableAvatars.splice(randomIndex, 1); // 移除已选的头像,避免重复
  1037. }
  1038. }
  1039. console.log("随机选择的头像:", randomAvatars);
  1040. return randomAvatars;
  1041. },
  1042. isCurrentUserWon() {
  1043. if (!Array.isArray(this.prizeInfo) || !this.userInfo?.userId) {
  1044. return false;
  1045. }
  1046. return this.prizeInfo.some((item) => {
  1047. return String(item.userId) === String(this.userInfo.userId);
  1048. });
  1049. },
  1050. getCurrentUserPrizeProductId() {
  1051. if (!Array.isArray(this.prizeInfo) || !this.userInfo?.userId) {
  1052. return null;
  1053. }
  1054. // 在 prizeInfo 中查找当前用户的中奖记录
  1055. const userPrize = this.prizeInfo.find(item => {
  1056. return String(item.userId) == String(this.userInfo.userId);
  1057. });
  1058. // 返回商品ID,如果没有找到则返回null
  1059. return userPrize ? userPrize.productId : null;
  1060. },
  1061. getCurrentUserPrizeRecordId() {
  1062. console.log('=== getCurrentUserPrizeRecordId 调试信息 ===');
  1063. console.log('this.prizeInfo:', this.prizeInfo);
  1064. console.log('this.userInfo:', this.userInfo);
  1065. console.log('this.userInfo.userId:', this.userInfo?.userId);
  1066. if (!Array.isArray(this.prizeInfo) || !this.userInfo?.userId) {
  1067. console.log('条件不满足,返回null');
  1068. return null;
  1069. }
  1070. const userPrize = this.prizeInfo.find(item => {
  1071. const match = String(item.userId) == String(this.userInfo.userId);
  1072. console.log('查找匹配:', {
  1073. itemUserId: item.userId,
  1074. currentUserId: this.userInfo.userId,
  1075. match: match,
  1076. itemRecordId: item.recordId
  1077. });
  1078. return match;
  1079. });
  1080. console.log('找到的用户奖品:', userPrize);
  1081. console.log('最终返回的recordId:', userPrize ? userPrize.recordId : null);
  1082. return userPrize ? userPrize.recordId : null;
  1083. },
  1084. nameuser() {
  1085. return this.userInfo.nickname
  1086. },
  1087. },
  1088. onHide() {
  1089. // 清除所有定时器(使用增强清理)
  1090. // this.clearAllTimersEnhanced();
  1091. // this.stopHeartBeat();
  1092. if (this.trafficTimer) {
  1093. clearInterval(this.trafficTimer);
  1094. }
  1095. // 页面隐藏时清理部分数据,减少内存占用
  1096. if (this.talklist && this.talklist.length > 20) {
  1097. // 只保留最新的20条消息
  1098. this.talklist = this.talklist.slice(-20);
  1099. }
  1100. // 触发垃圾回收
  1101. // this.triggerGarbageCollection();
  1102. },
  1103. onUnload() {
  1104. // 保存视频进度
  1105. this.saveVideoProgress();
  1106. // 清理直播相关定时器
  1107. if (this.liveItem) {
  1108. this.pauseVideo();
  1109. // 清除直播间的时间定时器
  1110. if (this.liveItem.timeTimer) {
  1111. clearInterval(this.liveItem.timeTimer);
  1112. this.liveItem.timeTimer = null;
  1113. }
  1114. }
  1115. // 关闭WebSocket连接(会自动清理相关资源)
  1116. this.closeWebSocket(true);
  1117. // 清除所有定时器(使用增强清理)
  1118. this.clearAllTimersEnhanced();
  1119. // 暂停视频
  1120. const videoId = `myVideo_${this.liveId}`;
  1121. const videoContext = uni.createVideoContext(videoId, this);
  1122. if (videoContext) {
  1123. videoContext.pause();
  1124. }
  1125. // 移除网络状态监听
  1126. try {
  1127. uni.offNetworkStatusChange();
  1128. } catch (err) {
  1129. console.warn('移除网络状态监听失败:', err);
  1130. }
  1131. // 清理大数据和状态
  1132. this.clearBigData();
  1133. this.resetAllStates();
  1134. },
  1135. mounted() {
  1136. // 初始化系统信息缓存,避免在键盘监听器中重复调用同步API
  1137. this.systemInfo = uni.getSystemInfoSync();
  1138. console.log('系统信息:', this.systemInfo.platform, this.systemInfo.model);
  1139. this.getCurrentActivities();
  1140. this.getliveOrder();
  1141. },
  1142. watch: {
  1143. coureLogin: {
  1144. immediate: true, // 页面一进入就检查一次
  1145. handler(val) {
  1146. if (val == 2 && this.isLogin) {
  1147. this.isLogin = false
  1148. this.goLogin()
  1149. }
  1150. }
  1151. },
  1152. // 监听liveItem.status的变化
  1153. 'liveItem.status': {
  1154. handler(newStatus, oldStatus) {
  1155. if (newStatus === undefined || oldStatus === undefined) return;
  1156. if (newStatus === oldStatus) return;
  1157. if (!this.liveId) {
  1158. console.warn('liveId不存在,无法触发getliving请求');
  1159. return;
  1160. }
  1161. // 状态变化时,调用getliving更新直播间数据
  1162. // console.log(`liveItem.status从${oldStatus}变为${newStatus},触发getliving请求`);
  1163. this.getliving(this.liveId);
  1164. },
  1165. deep: true
  1166. },
  1167. // 监听orderUser.count的变化
  1168. 'orderUser.count': {
  1169. handler(newVal, oldVal) {
  1170. if (newVal !== this.prevOrderCount) {
  1171. this.prevOrderCount = newVal;
  1172. this.showPurchaseMessage();
  1173. }
  1174. },
  1175. immediate: true
  1176. }
  1177. },
  1178. methods: {
  1179. shouquan() {
  1180. if (this.user.nickname == '') {
  1181. uni.showToast({
  1182. icon: 'none',
  1183. title: "请先授权微信昵称",
  1184. });
  1185. }
  1186. },
  1187. confimrname() {
  1188. if (this.user.nickname == '') {
  1189. uni.showToast({
  1190. icon: 'none',
  1191. title: "请授权微信昵称",
  1192. });
  1193. return
  1194. }
  1195. this.editUser();
  1196. uni.setStorageSync('userInfo', this.userInfo);
  1197. this.userlogo = false;
  1198. },
  1199. editUser() {
  1200. this.user.nickName = this.user.nickname;
  1201. editUser(this.user).then(
  1202. res => {
  1203. if (res.code == 200) {
  1204. uni.showToast({
  1205. icon: 'success',
  1206. title: "修改成功",
  1207. });
  1208. this.getUserInfo()
  1209. // setTimeout(function() {
  1210. // uni.navigateBack({
  1211. // delta: 1, //返回层数,2则上上页
  1212. // })
  1213. // }, 2000);
  1214. } else {
  1215. uni.showToast({
  1216. icon: 'none',
  1217. title: res.msg,
  1218. });
  1219. }
  1220. },
  1221. rej => {}
  1222. );
  1223. },
  1224. onNickNameInput(e) {
  1225. console.log(e)
  1226. this.user.nickname = e.detail.value
  1227. },
  1228. async haveLogin() {
  1229. this.userInfo = uni.getStorageSync('userInfo');
  1230. if (this.userInfo) {
  1231. await this.getUserInfo();
  1232. }
  1233. // this.initTime();
  1234. if (this.liveId) {
  1235. // 先获取直播间信息
  1236. await this.getliving(this.liveId);
  1237. this.isOnload = true;
  1238. await this.getLiveMsg(this.liveItem);
  1239. await this.getliveViewData();
  1240. // await this.getliving(this.liveId);
  1241. this.getCurrentActivities();
  1242. this.getliveOrder();
  1243. this.initSocket();
  1244. }
  1245. },
  1246. // haveShow(){
  1247. // if (this.liveId) {
  1248. // await this.getLiveMsg(this.liveItem);
  1249. // }
  1250. // if (!this.liveViewData) {
  1251. // this.getliveViewData();
  1252. // }
  1253. // if (!this.userData) {
  1254. // await this.getUserInfo();
  1255. // }
  1256. // },
  1257. // 静默登录
  1258. goLogin(data) {
  1259. let provider = 'weixin'
  1260. uni.login({
  1261. provider: provider,
  1262. success: async loginRes => {
  1263. console.log(loginRes)
  1264. uni.getUserInfo({
  1265. provider: provider,
  1266. success: (infoRes) => {
  1267. uni.showToast({
  1268. title: '登录中...',
  1269. icon: 'loading'
  1270. });
  1271. loginByMp({
  1272. code: loginRes.code,
  1273. encryptedData: infoRes.encryptedData,
  1274. iv: infoRes.iv,
  1275. appId: this.appid
  1276. }).then(res => {
  1277. uni.hideLoading();
  1278. if (res.code == 200) {
  1279. uni.setStorageSync('AppToken', res.token);
  1280. uni.setStorageSync('userInfo', JSON.stringify(res
  1281. .user));
  1282. this.userInfo = uni.getStorageSync('userInfo');
  1283. // uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
  1284. // this.user = res.user
  1285. this.$store.commit('setCoureLogin', 1);
  1286. this.isLogin = true
  1287. this.haveLogin()
  1288. this.userlogo = true
  1289. // console.log("TOKEN_KEYAuto",TOKEN_KEYAuto)
  1290. // this.getIsAddKf()
  1291. } else {
  1292. uni.showToast({
  1293. title: res.msg,
  1294. icon: 'none'
  1295. });
  1296. }
  1297. }).catch(err => {
  1298. uni.hideLoading();
  1299. uni.showToast({
  1300. icon: 'none',
  1301. title: "登录失败,请重新登录",
  1302. });
  1303. });
  1304. }
  1305. });
  1306. }
  1307. })
  1308. },
  1309. clickTabs(item) {},
  1310. getLocationByIP() {
  1311. // 高德IP定位API,需要替换成你的key
  1312. const key = '4e13632be0cc278f56825919603c07cf';
  1313. uni.request({
  1314. url: `https://restapi.amap.com/v3/ip?key=${key}`,
  1315. method: 'GET',
  1316. success: (res) => {
  1317. if (res.data && res.data.status === '1') {
  1318. // 返回数据格式:{ province: '广东省', city: '深圳市', ... }
  1319. // ${res.data.city}
  1320. this.location = `${res.data.province} `;
  1321. this.address = this.location
  1322. console.log('用户所在地:', this.location);
  1323. } else {
  1324. console.error('获取位置失败:', res.data);
  1325. }
  1326. },
  1327. fail: (err) => {
  1328. console.error('请求失败:', err);
  1329. }
  1330. });
  1331. },
  1332. formatNumber(num) {
  1333. if (typeof num !== 'number') {
  1334. num = Number(num) || 0;
  1335. }
  1336. if (num < 10000) {
  1337. return num.toString();
  1338. }
  1339. // 处理万以上的数字
  1340. const wan = num / 10000;
  1341. if (wan < 10) {
  1342. // 1万-10万之间,保留2位小数
  1343. const rounded = Math.round(wan * 100) / 100;
  1344. return rounded.toFixed(2).replace(/\.?0+$/, '') + 'w';
  1345. } else if (wan < 10000) {
  1346. // 10万-1亿之间,保留1位小数
  1347. const rounded = Math.round(wan * 10) / 10;
  1348. return rounded.toFixed(1).replace(/\.0$/, '') + 'w';
  1349. } else {
  1350. // 1亿以上,转换为亿单位
  1351. const yi = wan / 10000;
  1352. const rounded = Math.round(yi * 100) / 100;
  1353. return rounded.toFixed(2).replace(/\.?0+$/, '') + '亿';
  1354. }
  1355. },
  1356. // 重置所有状态
  1357. resetAllStates() {
  1358. this.liveUserCalled = false;
  1359. this.talklist = [];
  1360. this.liveViewersData = [];
  1361. this.liveViewers = [];
  1362. this.products = [];
  1363. this.liveItem = [];
  1364. // 重置WebSocket相关状态
  1365. this.isSocketOpen = false;
  1366. this.isConnecting = false;
  1367. this.isManualClose = true;
  1368. this.reconnectCount = 0;
  1369. this.heartBeatRetryCount = 0;
  1370. this.lastHeartBeatTime = 0;
  1371. this.adaptiveHeartBeatInterval = this.heartBeatInterval;
  1372. this.isNetworkAvailable = true;
  1373. this.networkType = 'unknown';
  1374. // 重置性能监控数据
  1375. this.connectionStartTime = 0;
  1376. this.connectionLatency = 0;
  1377. this.messageCount = 0;
  1378. this.errorCount = 0;
  1379. this.lastPerformanceCheck = 0;
  1380. },
  1381. // 获取WebSocket性能统计
  1382. getWebSocketPerformanceStats() {
  1383. const now = Date.now();
  1384. const uptime = this.connectionStartTime > 0 ? now - this.connectionStartTime : 0;
  1385. return {
  1386. connectionLatency: this.connectionLatency,
  1387. uptime: uptime,
  1388. messageCount: this.messageCount,
  1389. errorCount: this.errorCount,
  1390. errorRate: this.messageCount > 0 ? (this.errorCount / this.messageCount * 100).toFixed(2) : 0,
  1391. messagesPerSecond: uptime > 0 ? (this.messageCount / (uptime / 1000)).toFixed(2) : 0,
  1392. networkType: this.networkType,
  1393. isConnected: this.isSocketAvailable(),
  1394. reconnectCount: this.reconnectCount
  1395. };
  1396. },
  1397. // 定期检查性能并输出统计信息
  1398. performanceCheck() {
  1399. const now = Date.now();
  1400. // 每5分钟输出一次性能统计
  1401. if (now - this.lastPerformanceCheck > 300000) { // 5分钟
  1402. const stats = this.getWebSocketPerformanceStats();
  1403. console.log('WebSocket性能统计:', stats);
  1404. this.lastPerformanceCheck = now;
  1405. // 如果错误率过高,记录警告
  1406. if (stats.errorRate > 10) {
  1407. console.warn(`WebSocket错误率过高: ${stats.errorRate}%`);
  1408. }
  1409. // 如果连接延迟过高,记录警告
  1410. if (stats.connectionLatency > 5000) {
  1411. console.warn(`WebSocket连接延迟过高: ${stats.connectionLatency}ms`);
  1412. }
  1413. }
  1414. },
  1415. // 定期清理视频缓存
  1416. startVideoCacheCleanup() {
  1417. if (this.videoCleanupTimer) {
  1418. clearInterval(this.videoCleanupTimer);
  1419. }
  1420. // 每30秒清理一次视频缓存
  1421. this.videoCleanupTimer = setInterval(() => {
  1422. this.cleanupVideoCache();
  1423. }, 30000);
  1424. },
  1425. // 清理视频缓存
  1426. cleanupVideoCache() {
  1427. if (!this.liveItem || !this.liveId) return;
  1428. // 只对录播视频进行清理
  1429. if (this.liveItem.liveType === 2 && this.liveItem.videoUrl) {
  1430. this.reloadVideoPlayer();
  1431. }
  1432. },
  1433. // 重新加载视频播放器
  1434. reloadVideoPlayer() {
  1435. const videoId = `myVideo_${this.liveId}`;
  1436. const videoContext = uni.createVideoContext(videoId, this);
  1437. if (videoContext) {
  1438. const currentTime = this.videoCurrentTime;
  1439. // 暂停视频
  1440. videoContext.pause();
  1441. // 延迟重新加载
  1442. setTimeout(() => {
  1443. // 重新设置视频源,强制清理缓存
  1444. this.$set(this.liveItem, 'videoUrl', this.liveItem.videoUrl + '&t=' + Date.now());
  1445. // 恢复播放位置
  1446. setTimeout(() => {
  1447. if (videoContext.seek) {
  1448. videoContext.seek(currentTime);
  1449. }
  1450. videoContext.play();
  1451. }, 500);
  1452. }, 100);
  1453. }
  1454. },
  1455. // 启动内存监控
  1456. startMemoryMonitoring() {
  1457. if (this.memoryMonitorTimer) {
  1458. clearInterval(this.memoryMonitorTimer);
  1459. }
  1460. this.memoryMonitorTimer = setInterval(() => {
  1461. this.checkMemoryUsage();
  1462. }, 15000); // 每15秒检查一次
  1463. },
  1464. // 检查内存使用情况
  1465. checkMemoryUsage() {
  1466. try {
  1467. // 检查定时器数量
  1468. const timerCount = this.getActiveTimerCount();
  1469. if (timerCount > 10) {
  1470. console.warn(`检测到过多定时器: ${timerCount}个,可能存在内存泄漏`);
  1471. this.cleanupUnusedTimers();
  1472. }
  1473. // 检查消息队列长度
  1474. if (this.messageQueue && this.messageQueue.length > 100) {
  1475. console.warn(`消息队列过长: ${this.messageQueue.length}条,清理旧消息`);
  1476. this.messageQueue = this.messageQueue.slice(-50); // 只保留最新50条
  1477. }
  1478. // 检查用户颜色缓存
  1479. if (this.userRandomColors && Object.keys(this.userRandomColors).length > 500) {
  1480. console.warn('用户颜色缓存过大,清理部分缓存');
  1481. const keys = Object.keys(this.userRandomColors);
  1482. const keysToRemove = keys.slice(0, keys.length - 200); // 只保留最新200个
  1483. keysToRemove.forEach(key => delete this.userRandomColors[key]);
  1484. }
  1485. // 定期触发垃圾回收
  1486. if (Date.now() - this.lastPerformanceCheck > 60000) { // 每分钟一次
  1487. this.triggerGarbageCollection();
  1488. this.lastPerformanceCheck = Date.now();
  1489. }
  1490. } catch (error) {
  1491. console.error('内存检查失败:', error);
  1492. }
  1493. },
  1494. // 强制内存清理
  1495. forceMemoryCleanup() {
  1496. console.log('执行强制内存清理');
  1497. // 1. 清理视频播放器
  1498. this.cleanupVideoPlayer();
  1499. // 2. 清理大数据
  1500. this.clearBigData();
  1501. // 3. 强制垃圾回收(在支持的环境下)
  1502. this.triggerGarbageCollection();
  1503. },
  1504. // 清理视频播放器
  1505. cleanupVideoPlayer() {
  1506. const videoId = `myVideo_${this.liveId}`;
  1507. const videoContext = uni.createVideoContext(videoId, this);
  1508. if (videoContext) {
  1509. // 停止播放
  1510. videoContext.stop();
  1511. // 重置视频源
  1512. setTimeout(() => {
  1513. this.$set(this.liveItem, 'videoUrl', '');
  1514. setTimeout(() => {
  1515. this.$set(this.liveItem, 'videoUrl', this.getFreshVideoUrl());
  1516. this.playVideo();
  1517. }, 500);
  1518. }, 100);
  1519. }
  1520. },
  1521. // 获取带时间戳的新视频URL
  1522. getFreshVideoUrl() {
  1523. if (!this.liveItem.originalVideoUrl) {
  1524. this.liveItem.originalVideoUrl = this.liveItem.videoUrl;
  1525. }
  1526. // 添加时间戳参数,避免缓存
  1527. const separator = this.liveItem.originalVideoUrl.includes('?') ? '&' : '?';
  1528. return this.liveItem.originalVideoUrl + separator + 't=' + Date.now();
  1529. },
  1530. // 清理大数据
  1531. clearBigData() {
  1532. // 清理聊天记录,只保留最近50条
  1533. if (this.talklist.length > 50) {
  1534. this.talklist = this.talklist.slice(-50);
  1535. }
  1536. // 清理观众数据
  1537. // if (this.liveViewersData.length > 100) {
  1538. // this.liveViewersData = this.liveViewersData.slice(-100);
  1539. // }
  1540. // 清理虚拟数据
  1541. if (this.liveViewers.length > 100) {
  1542. this.liveViewers = this.liveViewers.slice(-100);
  1543. }
  1544. // 清理商品数据
  1545. if (this.products.length > 50) {
  1546. this.products = this.products.slice(0, 50);
  1547. }
  1548. // 强制垃圾回收(如果支持)
  1549. if (typeof gc === 'function') {
  1550. gc();
  1551. }
  1552. },
  1553. // 触发垃圾回收(在支持的环境下)
  1554. triggerGarbageCollection() {
  1555. if (wx && wx.triggerGC) {
  1556. wx.triggerGC();
  1557. }
  1558. },
  1559. // 强制滚动到底部(备用方案)
  1560. forceScrollToBottom() {
  1561. console.log('执行强制滚动到底部');
  1562. // 方案1:直接设置一个很大的scrollTop值
  1563. this.scrollTop = 999999;
  1564. // 方案2:使用scroll-into-view滚动到最后一个元素
  1565. this.$nextTick(() => {
  1566. if (this.talklist && this.talklist.length > 0) {
  1567. const lastMessage = this.talklist[this.talklist.length - 1];
  1568. const targetId = `list_${lastMessage.uniqueId || (this.talklist.length - 1)}`;
  1569. console.log(
  1570. `尝试滚动到元素: ${targetId}, 当前消息数量: ${this.talklist.length}, 最后消息ID: ${lastMessage.uniqueId}`
  1571. );
  1572. this.scrollIntoView = targetId;
  1573. // 清除scroll-into-view,避免影响后续滚动
  1574. setTimeout(() => {
  1575. this.scrollIntoView = '';
  1576. }, 200);
  1577. }
  1578. // 方案3:使用更大的延迟再次设置scrollTop
  1579. setTimeout(() => {
  1580. this.scrollTop = 999999;
  1581. console.log('延迟设置scrollTop为999999');
  1582. }, 100);
  1583. // 方案4:300ms后使用原生API作为最终备用方案
  1584. setTimeout(() => {
  1585. this.nativeScrollToBottom();
  1586. }, 300);
  1587. });
  1588. },
  1589. // 可靠的滚动方法(包含多种备用方案)
  1590. // simpleScrollToBottom() {
  1591. // const now = Date.now();
  1592. // // 防抖检查:如果距离上次滚动时间太短,则忽略
  1593. // if (now - this.lastScrollTime < this.scrollDebounceDelay) {
  1594. // console.log('滚动防抖:忽略频繁调用');
  1595. // return;
  1596. // }
  1597. // this.lastScrollTime = now;
  1598. // console.log('执行可靠滚动到底部');
  1599. // // 清理之前的定时器
  1600. // if (this.scrollTimer) {
  1601. // clearTimeout(this.scrollTimer);
  1602. // this.scrollTimer = null;
  1603. // }
  1604. // // 方案1:直接设置scrollTop
  1605. // this.scrollTop = 999999999;
  1606. // console.log('方案1: 设置scrollTop为999999999');
  1607. // // 方案2:使用scroll-into-view(备用方案)
  1608. // if (this.talklist.length > 0) {
  1609. // const lastMessage = this.talklist[this.talklist.length - 1];
  1610. // if (lastMessage && lastMessage.uniqueId) {
  1611. // this.scrollIntoView = `msg-${lastMessage.uniqueId}`;
  1612. // console.log(`方案2: 设置scrollIntoView为msg-${lastMessage.uniqueId}`);
  1613. // }
  1614. // }
  1615. // // 方案3:延迟再次设置scrollTop(最终备用方案)
  1616. // this.scrollTimer = setTimeout(() => {
  1617. // this.scrollTop = 999999999;
  1618. // console.log('方案3: 延迟设置scrollTop为999999999');
  1619. // this.scrollTimer = null;
  1620. // }, 50);
  1621. // },
  1622. // 强制滚动到底部(用于发送消息,绕过防抖限制)
  1623. forceScrollToBottomOnSend() {
  1624. console.log('执行强制滚动到底部(发送消息专用)');
  1625. // 清理之前的定时器
  1626. if (this.scrollTimer) {
  1627. clearTimeout(this.scrollTimer);
  1628. this.scrollTimer = null;
  1629. }
  1630. // 强制更新滚动时间,确保不被防抖阻止
  1631. this.lastScrollTime = Date.now();
  1632. // 清除scroll-into-view,避免冲突
  1633. this.scrollIntoView = '';
  1634. // 方案1:立即使用scroll-into-view滚动到最后一条消息
  1635. if (this.talklist.length > 0) {
  1636. const lastMessage = this.talklist[this.talklist.length - 1];
  1637. if (lastMessage && lastMessage.uniqueId) {
  1638. this.scrollIntoView = `list_${lastMessage.uniqueId}`;
  1639. //console.log(`强制滚动方案1: 设置scrollIntoView为list_${lastMessage.uniqueId}`);
  1640. }
  1641. }
  1642. // 方案2:同时设置scrollTop为一个非常大的值
  1643. const targetScrollTop = Date.now(); // 使用时间戳确保每次都不同
  1644. this.scrollTop = targetScrollTop;
  1645. //console.log('强制滚动方案2: 设置scrollTop为', targetScrollTop);
  1646. // 方案3:立即尝试原生滚动
  1647. this.nativeScrollToBottom();
  1648. // 方案4:使用nextTick确保DOM更新后再次滚动
  1649. this.$nextTick(() => {
  1650. // 清除scroll-into-view后重新设置scrollTop
  1651. this.scrollIntoView = '';
  1652. this.scrollTop = targetScrollTop + 1;
  1653. //console.log('强制滚动方案3: nextTick后重新设置scrollTop');
  1654. // 再次尝试原生滚动
  1655. setTimeout(() => {
  1656. this.nativeScrollToBottom();
  1657. }, 50);
  1658. });
  1659. // 方案5:延迟检查和强制滚动(最终保障)
  1660. this.scrollTimer = setTimeout(() => {
  1661. this.checkAndForceScroll(targetScrollTop);
  1662. this.scrollTimer = null;
  1663. }, 200);
  1664. },
  1665. // 检查并强制滚动
  1666. checkAndForceScroll(targetScrollTop) {
  1667. //console.log(`检查滚动状态: 当前位置=${this.currentScrollTop}, 目标位置=${targetScrollTop}`);
  1668. // 无论当前位置如何,都尝试强制滚动到底部
  1669. // 使用scroll-into-view滚动到最后一条消息
  1670. if (this.talklist.length > 0) {
  1671. const lastMessage = this.talklist[this.talklist.length - 1];
  1672. if (lastMessage && lastMessage.uniqueId) {
  1673. this.scrollIntoView = `list_${lastMessage.uniqueId}`;
  1674. //console.log(`最终检查: 设置scrollIntoView为list_${lastMessage.uniqueId}`);
  1675. }
  1676. }
  1677. // 设置一个新的scrollTop值
  1678. this.scrollTop = Date.now() + Math.random() * 1000;
  1679. //console.log('最终检查: 设置新的scrollTop值');
  1680. // 多次尝试原生滚动
  1681. this.nativeScrollToBottom();
  1682. setTimeout(() => {
  1683. this.nativeScrollToBottom();
  1684. }, 100);
  1685. },
  1686. // 使用原生API强制滚动(最终备用方案)
  1687. nativeScrollToBottom() {
  1688. try {
  1689. // 方案1:使用uni.createSelectorQuery直接操作DOM
  1690. const query = uni.createSelectorQuery().in(this);
  1691. query.select('#msgScroll').node((res) => {
  1692. if (res && res.node) {
  1693. // console.log('找到msgScroll节点,执行原生滚动');
  1694. const scrollHeight = res.node.scrollHeight;
  1695. res.node.scrollTop = scrollHeight;
  1696. // 确保滚动生效,延迟再次设置
  1697. setTimeout(() => {
  1698. res.node.scrollTop = scrollHeight + 100;
  1699. }, 50);
  1700. }
  1701. }).exec();
  1702. // 方案2:同时使用scrollIntoView API
  1703. // query.select('#msgScroll').scrollIntoView({
  1704. // duration: 0,
  1705. // complete: () => {
  1706. // console.log('scrollIntoView完成');
  1707. // }
  1708. // }).exec();
  1709. // 方案3:尝试获取最后一个消息元素并滚动到它
  1710. // if (this.talklist.length > 0) {
  1711. // const lastMessage = this.talklist[this.talklist.length - 1];
  1712. // if (lastMessage && lastMessage.uniqueId) {
  1713. // query.select(`#list_${lastMessage.uniqueId}`).scrollIntoView({
  1714. // duration: 0,
  1715. // complete: () => {
  1716. // console.log('最后消息元素滚动完成');
  1717. // }
  1718. // }).exec();
  1719. // }
  1720. // }
  1721. } catch (error) {
  1722. console.error('原生滚动失败:', error);
  1723. }
  1724. },
  1725. // 监听滚动事件
  1726. onScroll(e) {
  1727. this.currentScrollTop = e.detail.scrollTop;
  1728. // console.log('当前滚动位置:', this.currentScrollTop);
  1729. },
  1730. // 停止内存监控
  1731. stopMemoryMonitor() {
  1732. if (this.memoryMonitorTimer) {
  1733. clearInterval(this.memoryMonitorTimer);
  1734. this.memoryMonitorTimer = null;
  1735. }
  1736. },
  1737. // 获取活跃定时器数量
  1738. getActiveTimerCount() {
  1739. const timers = [
  1740. 'trafficTimer', 'pingTimeoutTimer', 'heartBeatTimer', 'liveViewDataTimer',
  1741. 'reconnectTimer', 'scrollTimer', 'searchTimer', 'purchasePromptTimer',
  1742. 'welcomeTimer', 'redTimer', 'liveStartTimer', 'lotteryTimer',
  1743. 'memoryMonitorTimer', 'networkStatusTimer', 'networkRetryTimer'
  1744. ];
  1745. return timers.filter(timer => this[timer] !== null).length;
  1746. },
  1747. // 清理未使用的定时器
  1748. cleanupUnusedTimers() {
  1749. // 检查并清理可能泄漏的定时器
  1750. const timers = [
  1751. 'trafficTimer', 'pingTimeoutTimer', 'heartBeatTimer', 'liveViewDataTimer',
  1752. 'reconnectTimer', 'scrollTimer', 'searchTimer', 'purchasePromptTimer',
  1753. 'welcomeTimer', 'redTimer', 'liveStartTimer', 'lotteryTimer', 'noticeTimer',
  1754. 'networkStatusTimer', 'networkRetryTimer'
  1755. ];
  1756. timers.forEach(timerName => {
  1757. if (this[timerName] && typeof this[timerName] === 'number') {
  1758. // 检查定时器是否还在运行
  1759. if (timerName.includes('Interval')) {
  1760. clearInterval(this[timerName]);
  1761. } else {
  1762. clearTimeout(this[timerName]);
  1763. }
  1764. this[timerName] = null;
  1765. console.log(`清理了可能泄漏的定时器: ${timerName}`);
  1766. }
  1767. });
  1768. },
  1769. // 增强的定时器清理方法
  1770. clearAllTimersEnhanced() {
  1771. // 先调用原有的清理方法
  1772. this.clearAllTimers();
  1773. // 额外清理新增的定时器
  1774. if (this.networkRetryTimer) {
  1775. clearTimeout(this.networkRetryTimer);
  1776. this.networkRetryTimer = null;
  1777. }
  1778. // 停止内存监控
  1779. this.stopMemoryMonitor();
  1780. // 清理缓存数据
  1781. this.userRandomColors = Object.create(null);
  1782. this.shownEntryUsers.clear();
  1783. // 重置性能监控数据
  1784. this.messageCount = 0;
  1785. this.errorCount = 0;
  1786. this.connectionLatency = 0;
  1787. this.lastPerformanceCheck = 0;
  1788. console.log('增强清理完成:所有定时器和缓存已清理');
  1789. },
  1790. goMiniProgram() {
  1791. // uni.navigateToMiniProgram({
  1792. // appId: 'wx45cf09091aead547',
  1793. // path: '/pages/home/index',
  1794. // success: function(res) {
  1795. // console.log('跳转成功', res);
  1796. // },
  1797. // fail: function(err) {
  1798. // console.error('跳转失败', err);
  1799. // }
  1800. // });
  1801. uni.showToast({
  1802. title: '系统升级中,兑换请联系客服!',
  1803. icon: 'none'
  1804. });
  1805. },
  1806. // 阻止双击事件
  1807. preventDoubleClick(e) {
  1808. e.preventDefault();
  1809. e.stopPropagation();
  1810. return false;
  1811. },
  1812. // 清理所有定时器和内存
  1813. clearAllTimers() {
  1814. // 清理所有定时器
  1815. const timers = [
  1816. 'scrollTimer',
  1817. 'liveViewDataTimer',
  1818. 'redTimer',
  1819. 'liveStartTimer',
  1820. 'lotteryTimer',
  1821. 'noticeTimer',
  1822. 'welcomeTimer',
  1823. 'trafficInterval',
  1824. 'lookTimer',
  1825. 'trafficTimer',
  1826. 'intervalId',
  1827. 'reconnectTimer',
  1828. 'searchTimer',
  1829. 'purchasePromptTimer',
  1830. 'heartBeatTimer',
  1831. 'pingTimeoutTimer'
  1832. ];
  1833. timers.forEach((timer) => {
  1834. if (this[timer]) {
  1835. if (timer.includes('Interval') || timer.includes('Timer')) {
  1836. clearInterval(this[timer]);
  1837. } else {
  1838. clearTimeout(this[timer]);
  1839. }
  1840. this[timer] = null;
  1841. }
  1842. });
  1843. // 重置相关状态
  1844. this.stayTime = 0;
  1845. this.startTime = 0;
  1846. this.totalTraffic = 0;
  1847. this.scrollPending = false;
  1848. this.reconnectCount = 0;
  1849. this.heartBeatRetryCount = 0;
  1850. },
  1851. // startTrafficCalculation(bitrate) {
  1852. // if (this.trafficTimer) {
  1853. // clearInterval(this.trafficTimer);
  1854. // this.trafficTimer = null;
  1855. // }
  1856. // this.startTime = Date.now();
  1857. // var that = this;
  1858. // this.trafficTimer = setInterval(() => {
  1859. // that.calculateTraffic(bitrate);
  1860. // }, 10000); // 每10秒计算一次
  1861. // },
  1862. //直播计算流量
  1863. startTrafficCalculation() {
  1864. if (this.trafficTimer) {
  1865. clearInterval(this.trafficTimer);
  1866. this.trafficTimer = null;
  1867. }
  1868. this.startTime = Date.now();
  1869. var that = this;
  1870. // 计算码率
  1871. let bitrate = this.calculateBitrate();
  1872. this.trafficTimer = setInterval(() => {
  1873. that.calculateTraffic(bitrate);
  1874. }, 10000); // 每10秒计算一次
  1875. },
  1876. // 计算流量
  1877. // calculateTraffic(bitrate) {
  1878. // const currentTime = Date.now();
  1879. // const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  1880. // // 流量 = 码率 × 时间
  1881. // // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  1882. // const trafficBits = bitrate * duration;
  1883. // // 转换为字节
  1884. // this.totalTraffic = trafficBits / 8;
  1885. // this.getLiveInternetTraffic();
  1886. // },
  1887. calculateBitrate() {
  1888. // 如果接口返回了视频文件大小和时长,使用这些数据计算码率
  1889. if (this.liveItem.videoFileSize && this.liveItem.videoDuration) {
  1890. // 码率 = 文件大小(字节) / 时长(秒) × 8 (转换为bps) × 5
  1891. const calculatedBitrate = (this.liveItem.videoFileSize / this.liveItem.videoDuration) * 8 * 5;
  1892. console.log(
  1893. `使用接口数据计算码率: ${calculatedBitrate} bps (文件大小: ${this.liveItem.videoFileSize} 字节, 时长: ${this.liveItem.videoDuration} 秒)`
  1894. );
  1895. return calculatedBitrate;
  1896. } else {
  1897. // 如果任一字段为空,使用默认码率 1500 bps
  1898. console.log('接口数据不完整,使用默认码率: 1500 bps');
  1899. return 1500;
  1900. }
  1901. },
  1902. calculateTraffic(bitrate) {
  1903. const currentTime = Date.now();
  1904. const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  1905. // 流量 = 码率 × 时间
  1906. // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  1907. const trafficBits = bitrate * duration;
  1908. // 转换为字节
  1909. this.totalTraffic = trafficBits / 8;
  1910. // 调用流量上报接口
  1911. this.getLiveInternetTraffic();
  1912. },
  1913. startTimer() {
  1914. this.startTime = Date.now();
  1915. this.lookTimer = setInterval(() => {
  1916. this.stayTime = Math.floor((Date.now() - this.startTime) / 1000);
  1917. }, 1000);
  1918. },
  1919. //直播、录播缓冲
  1920. getLiveInternetTraffic() {
  1921. if (!this.liveId) return;
  1922. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  1923. const param = {
  1924. userId: this.userInfo.userId || '',
  1925. liveId: this.liveId || '',
  1926. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  1927. internetTraffic: this.totalTraffic
  1928. };
  1929. liveInternetTraffic(param);
  1930. },
  1931. // 回放、预告缓冲
  1932. getInternetTraffic() {
  1933. if (!this.liveId || !this.liveId || !this.userInfo.userId || !this.uuId) return;
  1934. const currentTime = (this.stayTime / this.liveItem.duration) * 100;
  1935. const param = {
  1936. videoType: this.liveItem.videoType,
  1937. videoId: this.liveItem.videoId,
  1938. userId: this.userInfo.userId,
  1939. liveId: this.liveId,
  1940. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  1941. duration: this.liveItem.duration,
  1942. bufferRate: currentTime
  1943. };
  1944. if (this.liveItem.status == 1) {
  1945. param.videoType = this.liveItem.previewVideoType || '';
  1946. param.videoId = this.liveItem.previewVideoId || '';
  1947. }
  1948. if (this.liveItem.liveType == 1) {
  1949. param.bufferRate = this.totalTraffic;
  1950. }
  1951. internetTraffic(param);
  1952. },
  1953. scrollToBottom() {
  1954. const now = Date.now();
  1955. // 防抖检查:如果距离上次滚动时间太短,则忽略
  1956. if (now - this.lastScrollTime < this.scrollDebounceDelay) {
  1957. console.log('滚动防抖:忽略频繁调用');
  1958. return;
  1959. }
  1960. this.lastScrollTime = now;
  1961. // 清理之前的定时器
  1962. if (this.scrollTimer) {
  1963. clearTimeout(this.scrollTimer);
  1964. this.scrollTimer = null;
  1965. }
  1966. // 直接设置滚动位置
  1967. this.scrollTop = 999999999;
  1968. },
  1969. // 启动内存监控
  1970. startMemoryMonitor() {
  1971. // 清理之前的监控
  1972. if (this.memoryMonitorTimer) {
  1973. clearInterval(this.memoryMonitorTimer);
  1974. }
  1975. // 每5分钟检查一次内存使用情况
  1976. this.memoryMonitorTimer = setInterval(() => {
  1977. this.checkAndCleanMemory();
  1978. }, 5 * 60 * 1000); // 5分钟
  1979. },
  1980. // 检查并清理内存
  1981. checkAndCleanMemory() {
  1982. try {
  1983. // 清理过多的聊天消息
  1984. if (this.talklist && this.talklist.length > 25) {
  1985. const keepCount = 20;
  1986. this.talklist.splice(0, this.talklist.length - keepCount);
  1987. }
  1988. // 清理用户颜色缓存(保留最近的50个)
  1989. if (this.userRandomColors && Object.keys(this.userRandomColors).length > 50) {
  1990. const entries = Object.entries(this.userRandomColors);
  1991. const keepEntries = entries.slice(-50);
  1992. this.userRandomColors = Object.fromEntries(keepEntries);
  1993. }
  1994. // 清理已显示用户集合(保留最近的100个)
  1995. if (this.shownEntryUsers && this.shownEntryUsers.size > 100) {
  1996. const array = Array.from(this.shownEntryUsers);
  1997. this.shownEntryUsers.clear();
  1998. array.slice(-100).forEach((id) => this.shownEntryUsers.add(id));
  1999. }
  2000. console.log('内存清理完成');
  2001. } catch (error) {
  2002. console.error('内存清理失败:', error);
  2003. }
  2004. },
  2005. // 恢复页面活动
  2006. async resumePageActivity() {
  2007. if (this.liveItem) {
  2008. await this.getliving(this.liveId);
  2009. this.startTimeTimer(this.liveItem);
  2010. }
  2011. if (!this.isSocketAvailable()) {
  2012. this.initSocket();
  2013. }
  2014. },
  2015. // 获取用户专属随机色(缓存机制:同一用户始终用同一颜色)
  2016. getUserRandomColor(userId) {
  2017. if (!userId) {
  2018. return '#8978e2'; // 默认颜色
  2019. }
  2020. //如果缓存中已有该用户的颜色,直接返回
  2021. if (this.userRandomColors[userId]) {
  2022. return this.userRandomColors[userId];
  2023. }
  2024. //为新用户生成固定颜色(基于用户ID生成,不是完全随机)
  2025. const color = this.generateStableColor(userId);
  2026. this.userRandomColors[userId] = color;
  2027. // 存储到本地缓存,确保页面刷新后颜色不变
  2028. this.saveUserColorsToStorage();
  2029. return color;
  2030. }, // 基于用户ID生成稳定颜色(不是完全随机)
  2031. generateStableColor(userId) {
  2032. // 将用户ID转换为数字种子
  2033. let seed = 0;
  2034. for (let i = 0; i < userId.length; i++) {
  2035. seed = (seed * 31 + userId.charCodeAt(i)) % 1000000;
  2036. }
  2037. const colorPool = [
  2038. '#FF6B6B',
  2039. '#4ECDC4',
  2040. '#45B7D1',
  2041. '#96CEB4',
  2042. '#FFEAA7',
  2043. '#DDA0DD',
  2044. '#98D8C8',
  2045. '#F7DC6F',
  2046. '#BB8FCE',
  2047. '#85C1E9',
  2048. '#F8C471',
  2049. '#82E0AA',
  2050. '#F1948A',
  2051. '#85C1E9',
  2052. '#D7BDE2'
  2053. ];
  2054. return colorPool[seed % colorPool.length];
  2055. },
  2056. // 保存颜色映射到本地存储
  2057. saveUserColorsToStorage() {
  2058. try {
  2059. uni.setStorageSync('userRandomColors', this.userRandomColors);
  2060. } catch (e) {
  2061. console.warn('保存用户颜色缓存失败:', e);
  2062. }
  2063. },
  2064. // 从本地存储加载颜色映射
  2065. loadUserColorsFromStorage() {
  2066. try {
  2067. const cached = uni.getStorageSync('userRandomColors');
  2068. if (cached) {
  2069. this.userRandomColors = cached;
  2070. }
  2071. } catch (e) {
  2072. console.warn('加载用户颜色缓存失败:', e);
  2073. }
  2074. },
  2075. //头像名字
  2076. getNicknameInitial(nickName) {
  2077. if (!nickName || typeof nickName !== 'string') return '未';
  2078. if (/^[\u4e00-\u9fa5]/.test(nickName[0])) {
  2079. return nickName[0];
  2080. }
  2081. return nickName[0].toUpperCase();
  2082. },
  2083. async getUserInfo() {
  2084. await getUserInfo().then(
  2085. (res) => {
  2086. if (res.code == 200) {
  2087. this.userInfo = res.user;
  2088. } else {
  2089. uni.showToast({
  2090. icon: 'none',
  2091. title: '请求失败'
  2092. });
  2093. }
  2094. },
  2095. (rej) => {}
  2096. );
  2097. },
  2098. //订阅消息
  2099. handleAgreement() {
  2100. const templateId = this.templateId;
  2101. uni.requestSubscribeMessage({
  2102. tmplIds: [templateId],
  2103. success: (res) => {
  2104. if (res[templateId] === 'accept') {
  2105. uni.showToast({
  2106. title: '订阅成功,开播将提醒您',
  2107. icon: 'success'
  2108. });
  2109. this.callSendMessageApi();
  2110. } else if (res[templateId] === 'reject') {
  2111. uni.showToast({
  2112. title: '您已拒绝订阅,将无法收到提醒',
  2113. icon: 'none'
  2114. });
  2115. } else if (res[templateId] === 'ban') {
  2116. uni.showToast({
  2117. title: '您已关闭所有订阅权限,请在设置中开启',
  2118. icon: 'none'
  2119. });
  2120. }
  2121. },
  2122. fail: (err) => {
  2123. console.error('订阅消息失败', err);
  2124. uni.showToast({
  2125. title: '订阅失败,请重试',
  2126. icon: 'none'
  2127. });
  2128. }
  2129. });
  2130. },
  2131. async callSendMessageApi() {
  2132. if (!this.userInfo.userId) return;
  2133. const templateData = {
  2134. liveId: this.liveId,
  2135. userId: this.userInfo.userId,
  2136. templateId: this.templateId, // 模板ID
  2137. maOpenId: this.userInfo.maOpenId,
  2138. appId: this.appid,
  2139. data: {
  2140. thing6: this.liveItem.liveName,
  2141. date7: this.liveItem.startTime
  2142. }
  2143. };
  2144. subNotifyLive(templateData).then(
  2145. (res) => {
  2146. if (res.code == 200) {
  2147. this.isAgreement = true;
  2148. uni.setStorageSync('isAgreement', true);
  2149. } else {
  2150. uni.showToast({
  2151. title: res.msg,
  2152. icon: 'none'
  2153. });
  2154. }
  2155. },
  2156. (rej) => {}
  2157. );
  2158. },
  2159. //发送心跳
  2160. sendHeartBeat() {
  2161. if (!this.isSocketAvailable() || !this.isNetworkAvailable) {
  2162. console.warn('网络不可用或Socket连接异常,跳过心跳发送');
  2163. return;
  2164. }
  2165. this.lastHeartBeatTime = Date.now();
  2166. try {
  2167. const heartBeatMsg = JSON.stringify({
  2168. cmd: 'heartbeat',
  2169. msg: 'ping',
  2170. userId: this.userInfo.userId || '',
  2171. liveId: this.liveId,
  2172. timestamp: this.lastHeartBeatTime,
  2173. networkType: this.networkType
  2174. });
  2175. this.socket.send({
  2176. data: heartBeatMsg,
  2177. success: () => {
  2178. this.heartBeatRetryCount = 0; // 成功后重置重试次数
  2179. this.adjustHeartBeatInterval(true); // 网络良好,可适当延长间隔
  2180. this.startPingTimeout(); // 启动超时检测
  2181. },
  2182. fail: (err) => {
  2183. console.error('心跳包发送失败:', err);
  2184. this.heartBeatRetryCount++;
  2185. this.adjustHeartBeatInterval(false); // 网络不稳定,缩短间隔
  2186. // 根据网络类型调整重试策略
  2187. const retryDelay = this.getRetryDelay();
  2188. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  2189. setTimeout(() => this.sendHeartBeat(), retryDelay);
  2190. } else {
  2191. this.heartBeatRetryCount = 0;
  2192. this.handleReconnect(); // 重试用完才重连
  2193. }
  2194. }
  2195. });
  2196. } catch (err) {
  2197. console.error('心跳发送异常:', err);
  2198. this.heartBeatRetryCount++;
  2199. const retryDelay = this.getRetryDelay();
  2200. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  2201. setTimeout(() => this.sendHeartBeat(), retryDelay);
  2202. } else {
  2203. this.heartBeatRetryCount = 0;
  2204. this.handleReconnect();
  2205. }
  2206. }
  2207. },
  2208. // 根据网络状态获取重试延迟
  2209. getRetryDelay() {
  2210. const baseDelay = 2000;
  2211. const retryMultiplier = Math.pow(1.5, this.heartBeatRetryCount); // 指数退避
  2212. // 根据网络类型调整延迟
  2213. let networkMultiplier = 1;
  2214. switch (this.networkType) {
  2215. case '2g':
  2216. networkMultiplier = 3;
  2217. break;
  2218. case '3g':
  2219. networkMultiplier = 2;
  2220. break;
  2221. case '4g':
  2222. case '5g':
  2223. networkMultiplier = 1;
  2224. break;
  2225. case 'wifi':
  2226. networkMultiplier = 0.8;
  2227. break;
  2228. default:
  2229. networkMultiplier = 1.5;
  2230. }
  2231. return Math.min(baseDelay * retryMultiplier * networkMultiplier, 10000); // 最大10秒
  2232. },
  2233. // 自适应调整心跳间隔
  2234. adjustHeartBeatInterval(isSuccess) {
  2235. if (isSuccess) {
  2236. // 连接稳定,可适当延长间隔(最大30秒)
  2237. this.adaptiveHeartBeatInterval = Math.min(this.adaptiveHeartBeatInterval * 1.1, 30000);
  2238. } else {
  2239. // 连接不稳定,缩短间隔(最小10秒)
  2240. this.adaptiveHeartBeatInterval = Math.max(this.adaptiveHeartBeatInterval * 0.9, 10000);
  2241. }
  2242. },
  2243. // 启动心跳超时检测
  2244. startPingTimeout() {
  2245. // 清除现有的ping超时定时器
  2246. if (this.pingTimeoutTimer) {
  2247. clearTimeout(this.pingTimeoutTimer);
  2248. this.pingTimeoutTimer = null;
  2249. }
  2250. // 启动新的ping超时定时器
  2251. this.pingTimeoutTimer = setTimeout(() => {
  2252. console.warn('心跳超时,触发重连');
  2253. // 清理当前定时器引用
  2254. this.pingTimeoutTimer = null;
  2255. // 增加心跳重试次数
  2256. this.heartBeatRetryCount++;
  2257. // 如果重试次数未达到上限,先尝试重发心跳
  2258. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  2259. console.log(`心跳超时,尝试重发 (${this.heartBeatRetryCount}/${this.maxHeartBeatRetries})`);
  2260. setTimeout(() => this.sendHeartBeat(), 1000);
  2261. } else {
  2262. console.log('心跳重试次数用尽,触发重连');
  2263. this.heartBeatRetryCount = 0;
  2264. this.handleReconnect();
  2265. }
  2266. }, this.pingTimeout);
  2267. },
  2268. stopHeartBeat() {
  2269. if (this.heartBeatTimer) {
  2270. clearInterval(this.heartBeatTimer);
  2271. this.heartBeatTimer = null;
  2272. }
  2273. if (this.pingTimeoutTimer) {
  2274. clearTimeout(this.pingTimeoutTimer);
  2275. this.pingTimeoutTimer = null;
  2276. }
  2277. }, // 封装通用的连接状态校验方法
  2278. isSocketAvailable() {
  2279. // WebSocket readyState:0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
  2280. return this.socket && this.isSocketOpen && this.socket.readyState === 1;
  2281. },
  2282. // 处理重连逻辑
  2283. handleReconnect() {
  2284. if (this.isManualClose) {
  2285. console.log('手动关闭连接,不进行重连');
  2286. return;
  2287. }
  2288. // 防止重复重连
  2289. if (this.reconnectTimer) {
  2290. console.log('重连已在进行中,跳过重复重连');
  2291. return;
  2292. }
  2293. this.stopHeartBeat();
  2294. // 检查网络状态
  2295. if (!this.isNetworkAvailable) {
  2296. console.warn('网络不可用,延迟重连');
  2297. this.reconnectTimer = setTimeout(() => {
  2298. this.reconnectTimer = null;
  2299. this.handleReconnect();
  2300. }, 5000);
  2301. return;
  2302. }
  2303. if (this.reconnectCount < this.maxReconnectAttempts) {
  2304. this.reconnectCount++;
  2305. // 指数退避算法:基础延迟 * 2^(重连次数-1) + 随机抖动
  2306. const baseDelay = 1000;
  2307. const exponentialDelay = baseDelay * Math.pow(2, this.reconnectCount - 1);
  2308. const jitter = Math.random() * 1000; // 随机抖动,避免同时重连
  2309. const totalDelay = Math.min(exponentialDelay + jitter, 30000); // 最大30秒
  2310. console.log(`第${this.reconnectCount}次重连,延迟${Math.round(totalDelay)}ms,网络类型:${this.networkType}`);
  2311. this.reconnectTimer = setTimeout(() => {
  2312. this.reconnectTimer = null; // 清理定时器引用
  2313. // 重连前再次检查网络状态和连接状态
  2314. if (this.isNetworkAvailable && !this.isManualClose && !this.isSocketAvailable()) {
  2315. console.log('开始执行重连...');
  2316. this.initSocket();
  2317. } else if (this.isSocketAvailable()) {
  2318. console.log('连接已恢复,取消重连');
  2319. this.reconnectCount = 0; // 重置重连计数
  2320. } else {
  2321. console.warn('重连时网络不可用或已手动关闭');
  2322. this.handleReconnect(); // 递归重试
  2323. }
  2324. }, totalDelay);
  2325. } else {
  2326. console.log(`已达最大重连次数(${this.maxReconnectAttempts}),停止重连`);
  2327. this.showReconnectFailedMessage();
  2328. }
  2329. },
  2330. // 显示重连失败提示
  2331. showReconnectFailedMessage() {
  2332. uni.showToast({
  2333. title: '网络连接异常,请检查网络后重新进入',
  2334. icon: 'none',
  2335. duration: 3000
  2336. });
  2337. },
  2338. // 统一处理连接错误
  2339. handleConnectionError(errorType, error) {
  2340. console.error(`WebSocket ${errorType}:`, error);
  2341. // 根据错误类型进行不同处理
  2342. if (errorType === '连接请求失败') {
  2343. // 连接请求失败,可能是网络问题或服务器问题
  2344. if (!this.isNetworkAvailable) {
  2345. console.warn('网络不可用,等待网络恢复后重连');
  2346. return;
  2347. }
  2348. }
  2349. // 触发重连
  2350. this.handleReconnect();
  2351. },
  2352. // 重置重连状态
  2353. resetReconnectState() {
  2354. this.reconnectCount = 0;
  2355. this.heartBeatRetryCount = 0;
  2356. // 清理重连定时器
  2357. if (this.reconnectTimer) {
  2358. clearTimeout(this.reconnectTimer);
  2359. this.reconnectTimer = null;
  2360. }
  2361. // 重置自适应心跳间隔
  2362. this.adaptiveHeartBeatInterval = this.heartBeatInterval;
  2363. },
  2364. // 初始化网络状态监听
  2365. initNetworkStatusListener() {
  2366. // 获取当前网络状态
  2367. uni.getNetworkType({
  2368. success: (res) => {
  2369. this.networkType = res.networkType;
  2370. this.isNetworkAvailable = res.networkType !== 'none';
  2371. console.log('当前网络类型:', res.networkType);
  2372. }
  2373. });
  2374. // 监听网络状态变化
  2375. uni.onNetworkStatusChange((res) => {
  2376. const oldNetworkType = this.networkType;
  2377. const oldNetworkAvailable = this.isNetworkAvailable;
  2378. this.networkType = res.networkType;
  2379. this.isNetworkAvailable = res.isConnected;
  2380. console.log(`网络状态变化: ${oldNetworkType} -> ${res.networkType}, 连接状态: ${res.isConnected}`);
  2381. // 网络从不可用变为可用时,尝试重连
  2382. if (!oldNetworkAvailable && res.isConnected) {
  2383. console.log('网络恢复,尝试重连WebSocket');
  2384. this.resetReconnectState();
  2385. setTimeout(() => {
  2386. if (!this.isSocketAvailable()) {
  2387. this.initSocket();
  2388. }
  2389. }, 1000);
  2390. }
  2391. // 网络类型变化时,调整心跳策略
  2392. if (oldNetworkType !== res.networkType && res.isConnected) {
  2393. this.adjustHeartBeatForNetworkType(res.networkType);
  2394. }
  2395. // 网络断开时停止心跳
  2396. if (!res.isConnected) {
  2397. console.warn('网络断开,停止心跳');
  2398. this.stopHeartBeat();
  2399. }
  2400. });
  2401. },
  2402. // 根据网络类型调整心跳策略
  2403. adjustHeartBeatForNetworkType(networkType) {
  2404. let newInterval = this.heartBeatInterval;
  2405. switch (networkType) {
  2406. case '2g':
  2407. newInterval = 30000; // 2G网络,30秒间隔
  2408. break;
  2409. case '3g':
  2410. newInterval = 20000; // 3G网络,20秒间隔
  2411. break;
  2412. case '4g':
  2413. case '5g':
  2414. newInterval = 15000; // 4G/5G网络,15秒间隔
  2415. break;
  2416. case 'wifi':
  2417. newInterval = 10000; // WiFi网络,10秒间隔
  2418. break;
  2419. default:
  2420. newInterval = 15000; // 默认15秒
  2421. }
  2422. if (newInterval !== this.adaptiveHeartBeatInterval) {
  2423. this.adaptiveHeartBeatInterval = newInterval;
  2424. console.log(`根据网络类型(${networkType})调整心跳间隔为${newInterval}ms`);
  2425. // 如果当前有心跳在运行,重启心跳以应用新间隔
  2426. if (this.heartBeatTimer && this.isSocketAvailable()) {
  2427. this.startHeartBeat();
  2428. }
  2429. }
  2430. },
  2431. //输入框
  2432. inputFocus() {
  2433. // 立即更新状态,确保UI零延迟响应
  2434. this.isFocus = true;
  2435. this.isKeyboardShow = true;
  2436. },
  2437. inputBlur() {
  2438. this.isFocus = false;
  2439. },
  2440. getTimeDifferenceInSeconds(createTimeStr) {
  2441. if (!createTimeStr) return;
  2442. const createTime = new Date(createTimeStr.replace(/-/g, '/'));
  2443. const now = new Date();
  2444. const timeDiffMs = now - createTime;
  2445. const timeDiffSeconds = Math.floor(timeDiffMs / 1000);
  2446. return Math.max(0, timeDiffSeconds);
  2447. },
  2448. // 录播时间点
  2449. onVideoMetaLoaded(e) {
  2450. console.log("录播时间点", e)
  2451. this.videoProgressKey = `videoProgress_${this.liveId}`;
  2452. this.setVideoProgress();
  2453. },
  2454. setVideoProgress() {
  2455. // 只有录播和回放需要设置进度
  2456. if (this.liveItem.liveType !== 2 && this.liveItem.liveType !== 3) {
  2457. return;
  2458. }
  2459. let currentTime = 0;
  2460. if (this.liveItem.liveType === 2) {
  2461. // 录播:计算当前时间与开始时间的差值,对视频总时长取模
  2462. const diff = this.getTimeDifferenceInSeconds(this.liveItem.startTime);
  2463. if (diff > this.liveItem.duration) {
  2464. const storedProgress = uni.getStorageSync(this.videoProgressKey) || 0;
  2465. currentTime = storedProgress >= this.liveItem.duration ? 0 : storedProgress || 0;
  2466. this.isPlayback = true;
  2467. this.hasPlayback = true;
  2468. } else {
  2469. currentTime = diff % this.liveItem.duration;
  2470. }
  2471. } else if (this.liveItem.liveType === 3) {
  2472. // 回放:从存储中获取进度
  2473. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  2474. currentTime = storedProgress || 0;
  2475. }
  2476. const videoId = `myVideo_${this.liveId}`;
  2477. const videoContext = uni.createVideoContext(videoId, this);
  2478. if (videoContext) {
  2479. videoContext.seek(currentTime);
  2480. }
  2481. },
  2482. // onVideoWaiting(e) {
  2483. // // console.log('视频等待加载', e);
  2484. // if (this.liveItem.liveType == 2) {
  2485. // this.startTrafficCalculation(this.bitrate);
  2486. // } else {
  2487. // let that = this;
  2488. // if (this.trafficInterval) {
  2489. // clearInterval(this.trafficInterval);
  2490. // this.trafficInterval = null;
  2491. // }
  2492. // this.trafficInterval = setInterval(function() {
  2493. // that.getInternetTraffic();
  2494. // }, 10000);
  2495. // }
  2496. // },
  2497. onVideoWaiting(e) {
  2498. // console.log('视频等待加载', e);
  2499. if (this.liveItem.liveType == 2) {
  2500. // 修改这里:不再传入固定码率,而是在方法内部计算
  2501. this.startTrafficCalculation();
  2502. } else {
  2503. let that = this;
  2504. if (this.trafficInterval) {
  2505. clearInterval(this.trafficInterval);
  2506. this.trafficInterval = null;
  2507. }
  2508. this.trafficInterval = setInterval(function() {
  2509. that.getInternetTraffic();
  2510. }, 10000);
  2511. }
  2512. },
  2513. // 视频时间更新
  2514. onVideoTimeUpdate(e) {
  2515. // 获取当前播放时间
  2516. this.videoCurrentTime = e.detail.currentTime;
  2517. // 每隔10秒保存一次进度(避免频繁存储)
  2518. if (Math.floor(this.videoCurrentTime) % 10 === 0) {
  2519. this.saveVideoProgress();
  2520. }
  2521. const diff = this.getTimeDifferenceInSeconds(this.liveItem.startTime)
  2522. if (diff >= this.liveItem.duration) {
  2523. if (!this.hasPlayback) {
  2524. this.generating = true;
  2525. this.pauseVideo();
  2526. setTimeout(() => {
  2527. this.playVideo();
  2528. this.generating = false;
  2529. this.hasPlayback = true;
  2530. }, 180000);
  2531. this.closeWebSocket(true);
  2532. this.isEnd = true;
  2533. }
  2534. }
  2535. },
  2536. // 视频暂停
  2537. onVideoPause(e) {
  2538. if (this.liveItem.liveType === 2) {
  2539. const videoId = `myVideo_${this.liveId}`;
  2540. const videoContext = uni.createVideoContext(videoId, this);
  2541. setTimeout(() => {
  2542. videoContext.play();
  2543. }, 100);
  2544. }
  2545. // 暂停时保存进度
  2546. this.saveVideoProgress();
  2547. },
  2548. // 视频播放
  2549. onVideoPlay(e) {},
  2550. // 设置视频当前时间
  2551. // setVideoCurrentTime(time) {
  2552. // if (!time) return;
  2553. // const videoId = `myVideo_${this.liveId}`;
  2554. // const videoContext = uni.createVideoContext(videoId, this);
  2555. // if (videoContext) {
  2556. // videoContext.seek(time);
  2557. // console.log(`设置视频播放位置: ${time}秒`);
  2558. // }
  2559. // },
  2560. // 保存视频进度
  2561. saveVideoProgress() {
  2562. if (this.videoProgressKey) {
  2563. uni.setStorage({
  2564. key: this.videoProgressKey,
  2565. data: this.videoCurrentTime,
  2566. success: () => {},
  2567. fail: (err) => {
  2568. console.error('保存视频进度失败:', err);
  2569. }
  2570. });
  2571. }
  2572. },
  2573. // 点击红包
  2574. onRed() {
  2575. if (!this.liveId) return;
  2576. if (!this.redInfo?.redId) return;
  2577. if (this.redTimer) {
  2578. clearInterval(this.redTimer);
  2579. this.redTimer = null;
  2580. }
  2581. let data = {
  2582. liveId: this.liveId,
  2583. userId: this.userInfo.userId,
  2584. redId: this.redInfo.redId
  2585. };
  2586. liveRed(data).then((res) => {
  2587. this.isShowRed = false;
  2588. this.redCard = res;
  2589. this.isShowRedCard = true;
  2590. },
  2591. (rej) => {}
  2592. );
  2593. },
  2594. //领取优惠券
  2595. onCoupon() {
  2596. if (!this.couponInfo.couponIssueId) return;
  2597. let data = {
  2598. goodsId: this.couponInfo.goodsId,
  2599. couponIssueId: this.couponInfo.couponIssueId,
  2600. liveId: this.liveId
  2601. };
  2602. coupon(data).then((res) => {
  2603. this.isShowCoupon = false;
  2604. if (res.code == 200) {
  2605. uni.showToast({
  2606. title: res.msg,
  2607. icon: 'none'
  2608. });
  2609. } else {
  2610. uni.showToast({
  2611. title: res.msg,
  2612. icon: 'none'
  2613. });
  2614. }
  2615. })
  2616. .catch((rej) => {});
  2617. },
  2618. // 我的中奖名单
  2619. getMyLottery() {
  2620. this.winning = true;
  2621. myLottery()
  2622. .then((res) => {
  2623. if (res.code == 200) {
  2624. // console.log("我的中奖名单", res)
  2625. this.prizeAll = res.data.list || {};
  2626. } else {}
  2627. })
  2628. .catch((rej) => {});
  2629. },
  2630. // 抽奖
  2631. onLottery() {
  2632. if (!this.lotteryInfo) return;
  2633. this.isShowLottery = false
  2634. let data = {
  2635. lotteryId: this.lotteryInfo.lotteryId
  2636. };
  2637. liveLottery(data)
  2638. .then((res) => {
  2639. if (res.code == 200) {
  2640. const resData = res.data || {};
  2641. this.lotteryList = Array.isArray(resData) ? resData : [];
  2642. this.lotteryProducts = Array.isArray(resData.products) ? resData.products : [];
  2643. if (resData.duration) {
  2644. this.isShowLotteryPop = true;
  2645. }
  2646. } else {
  2647. uni.showToast({
  2648. title: res.msg,
  2649. icon: 'none'
  2650. });
  2651. this.lotteryList = [];
  2652. this.lotteryProducts = [];
  2653. }
  2654. })
  2655. .catch((rej) => {
  2656. uni.showToast({
  2657. title: '获取抽奖信息失败',
  2658. icon: 'none'
  2659. });
  2660. // 失败时强制重置为数组
  2661. this.lotteryList = [];
  2662. this.lotteryProducts = [];
  2663. });
  2664. },
  2665. // 参与抽奖
  2666. onClaim() {
  2667. let data = {
  2668. liveId: this.liveId,
  2669. lotteryId: this.lotteryInfo.lotteryId
  2670. };
  2671. claim(data).then(
  2672. (res) => {
  2673. if (res.code == 200) {
  2674. uni.showToast({
  2675. title: res.msg,
  2676. icon: 'none'
  2677. });
  2678. this.isShowLotteryPop = false;
  2679. this.havePrize = true;
  2680. uni.setStorageSync('havePrize', this.havePrize);
  2681. } else {
  2682. uni.showToast({
  2683. title: res.msg,
  2684. icon: 'none'
  2685. });
  2686. }
  2687. },
  2688. (rej) => {}
  2689. );
  2690. },
  2691. confirm() {
  2692. this.isShowPrize = false;
  2693. this.havePrize = false;
  2694. uni.setStorageSync('havePrize', this.havePrize);
  2695. },
  2696. // 商品收藏
  2697. onGoodsCollect(item) {
  2698. if (!item || item.length === 0 || !item.goodsId) {
  2699. return;
  2700. }
  2701. collectGoods(item.goodsId).then(
  2702. (res) => {
  2703. if (res.code == 200) {
  2704. uni.showToast({
  2705. title: res.msg,
  2706. icon: 'none'
  2707. });
  2708. item.isFavorite = !item.isFavorite;
  2709. } else {
  2710. uni.showToast({
  2711. title: res.msg,
  2712. icon: 'none'
  2713. });
  2714. }
  2715. },
  2716. (rej) => {}
  2717. );
  2718. },
  2719. //正在购买
  2720. getliveOrder(item) {
  2721. if (!this.liveId) {
  2722. return;
  2723. }
  2724. liveOrderUser(this.liveId).then(
  2725. (res) => {
  2726. if (res.code == 200) {
  2727. this.orderUser = res;
  2728. } else {
  2729. console.log('获取正在购买用户失败');
  2730. }
  2731. },
  2732. (rej) => {}
  2733. );
  2734. },
  2735. onLiveStateChange(e, liveItem) {
  2736. // 可以根据状态码处理不同的直播状态
  2737. const stateCode = e.detail.code;
  2738. if (e.detail.code == -2301 || e.detail.code == -2302) {
  2739. this.playVideo();
  2740. } else if (e.detail.code == 2004) {
  2741. this.calculateTimeDiff(this.liveItem);
  2742. // this.startTrafficCalculation(this.bitrateLive);
  2743. this.startTrafficCalculation();
  2744. }
  2745. // 2001: 已经连接服务器
  2746. // 2002: 已经连接服务器,开始拉流
  2747. // 2003: 网络接收到首个视频数据包(IDR)
  2748. // 2004: 视频播放开始
  2749. // 2005: 视频播放进度
  2750. // 2006: 视频播放结束
  2751. // 2007: 视频播放Loading
  2752. // 2008: 解码器启动
  2753. // -2301: 网络断连,且经多次重连抢救无效,更多重试请自行重启播放
  2754. // -2302: 获取加速拉流地址失败
  2755. }, // 直播错误事件
  2756. onLiveError(e, liveItem) {
  2757. this.videoError(e, liveItem);
  2758. console.log('错误');
  2759. },
  2760. // 红包 卡片 抽奖
  2761. getCurrentActivities() {
  2762. if (!this.liveId) return;
  2763. currentActivities(this.liveId).then(
  2764. (res) => {
  2765. if (res.code === 200) {
  2766. // 提取数据(默认空数组/对象避免报错)
  2767. this.redInfo = (Array.isArray(res.red) ? res.red : [])[0] || {};
  2768. this.lotteryInfo = (Array.isArray(res.lottery) ? res.lottery : [])[0] || {};
  2769. this.goodsCard = res.goods || {};
  2770. this.notice = res.topMsg || {};
  2771. this.isShowGoods = this.goodsCard && this.goodsCard.status == 1;
  2772. this.isShowRed = this.redInfo && this.redInfo.redStatus == 1;
  2773. this.isShowLottery = this.lotteryInfo && this.lotteryInfo.lotteryStatus == 1;
  2774. if (this.notice.msg) {
  2775. console.log("有》》》》")
  2776. this.noticeTimer = setInterval(() => {
  2777. const noticeCountdown = this.handleTime(this.notice.endTime, 0);
  2778. console.log("出现1>>>", noticeCountdown)
  2779. if (!noticeCountdown) {
  2780. this.isShowNotice = false;
  2781. clearInterval(this.noticeTimer);
  2782. } else {
  2783. this.isShowNotice = true
  2784. }
  2785. }, 1000);
  2786. }
  2787. // if(this.notice.msg&&this.notice){
  2788. // this.isShowNotice = true
  2789. // }else{
  2790. // this.isShowNotice = false
  2791. // }
  2792. if (this.isShowRed) {
  2793. this.redTimer = setInterval(() => {
  2794. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  2795. .duration);
  2796. if (!redCountdown) {
  2797. this.isShowRed = false;
  2798. clearInterval(this.redTimer);
  2799. }
  2800. }, 1000);
  2801. }
  2802. // 处理抽奖定时器
  2803. if (this.isShowLottery) {
  2804. this.lotteryTimer = setInterval(() => {
  2805. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this
  2806. .lotteryInfo.duration);
  2807. }, 1000);
  2808. }
  2809. } else {
  2810. uni.showToast({
  2811. title: res.msg,
  2812. icon: 'none'
  2813. });
  2814. }
  2815. },
  2816. (rej) => {}
  2817. );
  2818. },
  2819. // 计算当前时间与 liveItem.startTime 的差值,并更新 totalTime
  2820. calculateTimeDiff(item) {
  2821. if (!item.startTime) return;
  2822. // 提取对应场景的时间字符串(直播用startTime,抽奖用updateTime)
  2823. let timeStr = item.startTime;
  2824. // 转换时间格式(适配iOS,将 "-" 替换为 "/")
  2825. const time = new Date(timeStr.replace(/-/g, '/'));
  2826. if (isNaN(time.getTime())) {
  2827. return;
  2828. }
  2829. const now = new Date();
  2830. let diffMs = Math.max(0, now.getTime() - time.getTime());
  2831. // 转换为 时:分:秒(补零处理)
  2832. const totalSeconds = Math.floor(diffMs / 1000);
  2833. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  2834. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  2835. const seconds = this.padZero(totalSeconds % 60);
  2836. this.diffTotalTime = `${hours}:${minutes}:${seconds}`;
  2837. },
  2838. padZero(num) {
  2839. return num < 10 ? `0${num}` : num;
  2840. },
  2841. // 启动当前直播间的时间差值定时器
  2842. startTimeTimer(item) {
  2843. if (!item) return;
  2844. // 立即计算一次(避免等待1秒才显示)
  2845. const totalTime = this.calculateTimeDiff(item);
  2846. item.timeTimer = setInterval(() => {
  2847. const totalTime = this.calculateTimeDiff(item);
  2848. }, 1000);
  2849. },
  2850. // toggleViewerList() {
  2851. // const now = Date.now();
  2852. // if (now - this.lastClickTime > this.clickDelay) {
  2853. // this.showadd = !this.showadd;
  2854. // if (this.showadd) {
  2855. // this.getliveUser(false); // 加载第一页观众
  2856. // }
  2857. // this.lastClickTime = now;
  2858. // }
  2859. // },
  2860. // 播放视频
  2861. playVideo() {
  2862. if (!this.liveItem) {
  2863. console.log('liveItem 为空,无法播放视频');
  2864. return;
  2865. }
  2866. try {
  2867. if (this.liveItem.liveType === 1 && this.liveItem.livingUrl && this.liveItem.status == 2) {
  2868. } else if (this.liveItem.status == 1 && this.liveItem.previewUrl) {
  2869. const videoId = `myVideo_${this.liveId}`;
  2870. const videoContext = uni.createVideoContext(videoId, this);
  2871. if (videoContext) {
  2872. videoContext.play();
  2873. }
  2874. } else if (this.liveItem.liveType === 2 && this.liveItem.videoUrl && this.liveItem.status == 2) {
  2875. const videoId = `myVideo_${this.liveId}`;
  2876. const videoContext = uni.createVideoContext(videoId, this);
  2877. // console.log("录播")
  2878. if (videoContext) {
  2879. videoContext.play();
  2880. }
  2881. } // 回放视频使用video
  2882. else if (this.liveItem.liveType === 3 && this.liveItem.videoUrl && this.liveItem.status == 4) {
  2883. const videoId = `myVideo_${this.liveId}`;
  2884. const videoContext = uni.createVideoContext(videoId, this);
  2885. // console.log("回放")
  2886. if (videoContext) {
  2887. videoContext.play();
  2888. }
  2889. }
  2890. } catch (error) {
  2891. console.error('播放视频失败:', error);
  2892. }
  2893. },
  2894. pauseVideo() {
  2895. console.log("暂停了")
  2896. if (!this.liveItem) return;
  2897. try {
  2898. if (this.liveItem.status == 1) {
  2899. const videoId = `myVideo_${this.liveId}`;
  2900. const videoContext = uni.createVideoContext(videoId, this);
  2901. if (videoContext) {
  2902. videoContext.pause();
  2903. }
  2904. } else if (this.liveItem.status == 2) {
  2905. if (this.liveItem.liveType === 1) {
  2906. const livePlayerId = `myLivePlayer_${this.liveId}`;
  2907. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  2908. if (livePlayerContext) {
  2909. livePlayerContext.pause();
  2910. }
  2911. } else if (this.liveItem.liveType === 2) {
  2912. const videoId = `myVideo_${this.liveId}`;
  2913. const videoContext = uni.createVideoContext(videoId, this);
  2914. if (videoContext) {
  2915. videoContext.pause();
  2916. }
  2917. }
  2918. }
  2919. } catch (error) {
  2920. console.error('暂停视频失败:', error);
  2921. }
  2922. },
  2923. // 视频错误处理
  2924. videoError(e, liveItem) {
  2925. if (!liveItem || !this.liveId) return;
  2926. // 初始化重试计数
  2927. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  2928. this.videoRetryCounts[liveItem.liveId] = 0;
  2929. }
  2930. // 限制重试次数
  2931. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  2932. console.error(`直播间 ${this.liveId} 视频加载失败,停止重试`);
  2933. // 显示错误提示
  2934. uni.showToast({
  2935. title: '视频加载失败,请检查网络',
  2936. icon: 'none',
  2937. duration: 2000
  2938. });
  2939. return;
  2940. }
  2941. this.videoRetryCounts[this.liveId]++;
  2942. // 延迟重试
  2943. setTimeout(() => {
  2944. if (this.liveId === this.liveId) {
  2945. console.log(`第${this.videoRetryCounts[this.liveId]}次重试播放视频`);
  2946. this.playVideo();
  2947. }
  2948. }, 2000);
  2949. },
  2950. openViews() {
  2951. // 计算scroll-view高度
  2952. this.$nextTick(() => {
  2953. const query = uni.createSelectorQuery().in(this);
  2954. query
  2955. .select('.view-box')
  2956. .boundingClientRect((data) => {
  2957. if (data) {
  2958. this.scrollHeight = data.height - 80; // 80是标题高度,120是底部高度
  2959. }
  2960. })
  2961. .exec();
  2962. });
  2963. },
  2964. // 滚动到底部触发
  2965. handleScrollToLower() {
  2966. // 清除上一次未执行的定时器,避免重复请求
  2967. if (this.scrollTimer) {
  2968. clearTimeout(this.scrollTimer);
  2969. }
  2970. // 延迟1秒执行接口请求
  2971. this.scrollTimer = setTimeout(() => {
  2972. this.getliveUser(true);
  2973. }, 1000);
  2974. },
  2975. async getMyLiveMsg(liveItem) {
  2976. console.log("不可见了")
  2977. if (!liveItem || !this.liveId) {
  2978. console.error('getLiveMsg 错误:无效的 liveItem');
  2979. return;
  2980. }
  2981. try {
  2982. const res = await myLiveMsg(this.liveId, 30, 1);
  2983. if (res.code == 200) {
  2984. const rows = Array.isArray(res.rows) ? res.rows : [];
  2985. const reversedTalkList = [...rows].reverse();
  2986. this.talklist = Array.isArray(reversedTalkList) ? reversedTalkList : [];
  2987. // 获取历史消息后也滚动到底部
  2988. this.$nextTick(() => {
  2989. this.scrollToBottom();
  2990. });
  2991. } else {
  2992. this.talklist = [];
  2993. }
  2994. } catch (error) {
  2995. this.talklist = [];
  2996. console.error('获取聊天记录失败:', error);
  2997. }
  2998. },
  2999. async getLiveMsg(liveItem) {
  3000. if (!liveItem || !this.liveId) {
  3001. console.error('getLiveMsg 错误:无效的 liveItem');
  3002. return;
  3003. }
  3004. try {
  3005. const res = await liveMsg(this.liveId, 30, 1);
  3006. if (res.code == 200) {
  3007. const rows = Array.isArray(res.rows) ? res.rows : [];
  3008. const reversedTalkList = [...rows].reverse();
  3009. this.talklist = Array.isArray(reversedTalkList) ? reversedTalkList : [];
  3010. // 获取历史消息后也滚动到底部
  3011. this.$nextTick(() => {
  3012. this.scrollToBottom();
  3013. });
  3014. } else {
  3015. this.talklist = [];
  3016. }
  3017. } catch (error) {
  3018. this.talklist = [];
  3019. console.error('获取聊天记录失败:', error);
  3020. }
  3021. },
  3022. // 获取直播间用户
  3023. // async getliveUser(isLoadMore = false) {
  3024. // this.viewLoading = true;
  3025. // try {
  3026. // const res = await watchUserList(this.liveId, this.viewPageSize, this.viewPageNum, false);
  3027. // console.log("getliveUser", res);
  3028. // if (res.code === 200) {
  3029. // const userRows = Array.isArray(res.rows) ? res.rows : [];
  3030. // let array = userRows.map((item) => ({
  3031. // avatar: item.avatar || '',
  3032. // userId: item.userId || '',
  3033. // nickName: item.nickName || '未命名'
  3034. // }));
  3035. // // 虚拟数据
  3036. // let virtualData = [];
  3037. // let virtualTotal = res.total * 10;
  3038. // this.liveUserTotal = virtualTotal;
  3039. // for (let i = 0; i < virtualTotal; i++) {
  3040. // let data = {
  3041. // avatar: '',
  3042. // userId: '8565' + i,
  3043. // nickName: '微信用户'
  3044. // };
  3045. // virtualData.push(data);
  3046. // }
  3047. // this.liveViewersData = [...array, ...virtualData];
  3048. // const newRows = Array.isArray(res.rows) ? res.rows : [];
  3049. // const currentViewers = Array.isArray(this.liveViewers) ? this.liveViewers : [];
  3050. // let viewlist = isLoadMore ? [...currentViewers, ...newRows] : newRows;
  3051. // this.liveViewers = [...viewlist, ...virtualData];
  3052. // this.viewPageNum++;
  3053. // }
  3054. // } catch (error) {
  3055. // console.error('获取观众列表失败:', error);
  3056. // } finally {
  3057. // this.viewLoading = false;
  3058. // }
  3059. // },
  3060. //小黄车搜索商品
  3061. handleSearchInput() {
  3062. // 使用防抖优化性能,避免频繁请求
  3063. clearTimeout(this.searchTimer);
  3064. this.searchTimer = setTimeout(() => {
  3065. this.queryCollect();
  3066. }, 500); // 500毫秒延迟
  3067. },
  3068. // 显示购买提示信息
  3069. showPurchaseMessage() {
  3070. // 清除之前的定时器
  3071. if (this.purchasePromptTimer) {
  3072. clearTimeout(this.purchasePromptTimer);
  3073. }
  3074. // 显示提示
  3075. this.showPurchasePrompt = true;
  3076. // 2秒后自动隐藏
  3077. this.purchasePromptTimer = setTimeout(() => {
  3078. this.showPurchasePrompt = false;
  3079. }, 2000);
  3080. },
  3081. //名字超过省略
  3082. truncateString(str, maxLength) {
  3083. if (typeof str !== 'string' || str.length <= maxLength) {
  3084. return str;
  3085. }
  3086. return str.slice(0, maxLength) + '...'; // 截断后加省略号
  3087. },
  3088. // 跳转页面
  3089. navgetTo(url) {
  3090. uni.navigateTo({
  3091. url: url
  3092. });
  3093. },
  3094. // 修改获取直播信息方法
  3095. async getliving(liveId) {
  3096. if (!liveId) return;
  3097. const param = {
  3098. id: liveId
  3099. };
  3100. try {
  3101. const res = await getlive(param);
  3102. if (res.code !== 200) {
  3103. uni.showToast({
  3104. title: res.msg,
  3105. icon: 'none'
  3106. });
  3107. return;
  3108. }
  3109. this.liveItem = Object.assign({}, this.liveItem, res.data);
  3110. if (res.data.globalVisible || res.data.singleVisible) {
  3111. this.myselfFlag = true;
  3112. }
  3113. // this.talklist = Array.isArray((res.data || {}).talklist) ? res.data.talklist : [];
  3114. this.startTimeTimer(this.liveItem);
  3115. // 清除旧定时器(如预告倒计时)
  3116. if (this.liveStartTimer) {
  3117. clearInterval(this.liveStartTimer);
  3118. this.liveStartTimer = null;
  3119. }
  3120. if (res.data.status == 1) {
  3121. // 直播预告
  3122. this.liveStartTimer = setInterval(async () => {
  3123. this.liveCountdown = this.handleTime(res.data.startTime, 0);
  3124. if (!this.liveCountdown) {
  3125. uni.removeStorageSync('isAgreement');
  3126. await this.getliving(this.liveId);
  3127. clearInterval(this.liveStartTimer);
  3128. }
  3129. }, 1000);
  3130. this.$set(this.liveItem, 'previewUrl', res.data.previewUrl);
  3131. this.$set(this.liveItem, 'livingUrl', ''); // 清空直播流
  3132. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  3133. } else if (res.data.status == 2) {
  3134. if (res.data.liveType == 1) {
  3135. // 直播流
  3136. let cTime = Math.floor(Math.random() * 10000) + 1;
  3137. let livingUrl = res.data.flvHlsUrl + '&t=' + cTime;
  3138. console.log('地址在', this.liveItem.livingUrl);
  3139. this.$set(this.liveItem, 'livingUrl', livingUrl);
  3140. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  3141. } else if (res.data.liveType === 2) {
  3142. // 回放视频 2录播 3直播回放
  3143. // let urlStr = 'https://fs-1319721001.cos.ap-chongqing.myqcloud.com/10%E6%9C%8820%E6%97%A5%20%281%29.m3u8'
  3144. // this.$set(this.liveItem, 'videoUrl', urlStr);
  3145. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  3146. this.$set(this.liveItem, 'livingUrl', '');
  3147. }
  3148. } else if (res.data.status == 4 && res.data.liveType == 3) {
  3149. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  3150. this.$set(this.liveItem, 'livingUrl', '');
  3151. } else {
  3152. // 未开播
  3153. this.$set(this.liveItem, 'livingUrl', '');
  3154. this.$set(this.liveItem, 'videoUrl', '');
  3155. }
  3156. this.$set(this.liveItem, 'autoplay', res.data.liveType !== 0);
  3157. this.$set(this.liveItem, 'showType', res.data.showType);
  3158. this.storeId = res.storeId;
  3159. this.startLiveViewDataTimer();
  3160. this.playVideo();
  3161. } catch (err) {
  3162. console.error('获取直播信息失败:', err);
  3163. uni.showToast({
  3164. title: '获取直播信息失败',
  3165. icon: 'none'
  3166. });
  3167. }
  3168. },
  3169. getPureDecimal(num, precision = 6) {
  3170. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  3171. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  3172. },
  3173. goBack() {
  3174. // 暂停当前视频
  3175. if (this.liveItem) {
  3176. this.pauseVideo();
  3177. }
  3178. // 关闭WebSocket连接
  3179. this.closeWebSocket(true);
  3180. // 导航返回
  3181. // const pages = getCurrentPages();
  3182. // if (pages.length > 1) {
  3183. // uni.navigateBack();
  3184. // } else {
  3185. // uni.reLaunch({
  3186. // url: '/pages_course/livingList'
  3187. // });
  3188. // }
  3189. const pages = getCurrentPages();
  3190. uni.reLaunch({
  3191. url: '/pages/home/index'
  3192. });
  3193. },
  3194. // 点赞
  3195. async onLike() {
  3196. if (!this.liveId) return;
  3197. try {
  3198. const res = await liveDataLike(this.liveId);
  3199. if (res?.like) {
  3200. this.liveViewData.like++; //只更新当前直播间的点赞数
  3201. } else {
  3202. uni.showToast({
  3203. title: res.msg,
  3204. icon: 'none'
  3205. });
  3206. }
  3207. } catch (error) {
  3208. console.error('点赞失败:', error);
  3209. }
  3210. },
  3211. //直播间点赞、关注、在线人数数据
  3212. getliveViewData() {
  3213. if (!this.liveId) return;
  3214. getLiveViewData(this.liveId).then((res) => {
  3215. if (res.code == 200) {
  3216. // 强制响应式更新,确保数据实时显示
  3217. this.liveViewData = res;
  3218. }
  3219. }).catch((error) => {
  3220. console.error('获取直播间数据失败:', error);
  3221. // 失败时兜底,避免显示异常
  3222. this.liveViewData = {
  3223. like: 0,
  3224. watchCount: 0
  3225. };
  3226. });
  3227. },
  3228. // 30秒刷新一下直播间点赞数
  3229. startLiveViewDataTimer() {
  3230. // 先清除旧定时器(防止重复创建)
  3231. if (this.liveViewDataTimer) {
  3232. clearInterval(this.liveViewDataTimer);
  3233. this.liveViewDataTimer = null;
  3234. }
  3235. this.getliveViewData();
  3236. this.liveViewDataTimer = setInterval(() => {
  3237. // 安全校验:确保liveItem和liveId存在(避免无效请求)
  3238. if (this.liveId) {
  3239. this.getliveViewData();
  3240. }
  3241. }, 20000);
  3242. },
  3243. // 去购买,跳商品详情
  3244. goShop(productId, goodsId) {
  3245. if (!this.liveId) return;
  3246. uni.navigateTo({
  3247. url: '/pages_shopping/live/goods?productId=' + productId + '&liveId=' + this.liveId +
  3248. '&goodsId=' + goodsId + '&storeId=' + this.storeId
  3249. });
  3250. },
  3251. // 查询店铺
  3252. async queryCollect() {
  3253. this.loadingProducts = true;
  3254. if (!this.liveId) return;
  3255. if (this.inputInfo == null) this.inputInfo = '';
  3256. uni.showLoading({
  3257. title: '加载中'
  3258. });
  3259. try {
  3260. const res = await liveStore(this.liveId, this.inputInfo);
  3261. uni.hideLoading();
  3262. this.shopping = true;
  3263. if (res.code === 200) {
  3264. // 数据绑定到当前 liveItem,避免全局污染
  3265. this.products = Array.isArray(res.data) ? res.data : [];
  3266. }
  3267. } catch (error) {
  3268. console.error('获取小黄车商品失败:', error);
  3269. } finally {
  3270. this.loadingProducts = false;
  3271. }
  3272. },
  3273. // 时间戳
  3274. initTime() {
  3275. const now = new Date();
  3276. this.timestamp = now.getTime();
  3277. },
  3278. openCart() {
  3279. this.queryCollect();
  3280. },
  3281. close() {
  3282. this.showadd = false;
  3283. },
  3284. // 关闭小黄车
  3285. closeShop() {
  3286. this.shopping = false;
  3287. },
  3288. closeMore() {
  3289. this.isMore = false;
  3290. },
  3291. closeWin() {
  3292. this.winning = false;
  3293. },
  3294. // 关闭WebSocket连接(isManual:是否手动关闭)
  3295. closeWebSocket(isManual = true) {
  3296. if (!this.socket || !this.isSocketOpen) {
  3297. // console.warn('WebSocket 任务不存在或未打开,无需关闭');
  3298. return;
  3299. }
  3300. console.log(`WebSocket连接关闭 - ${isManual ? '手动' : '自动'}`);
  3301. this.isManualClose = isManual;
  3302. // 清理所有定时器和状态
  3303. this.cleanupAllResources();
  3304. try {
  3305. // 先保存引用,避免在关闭过程中被置为null
  3306. const socketToClose = this.socket;
  3307. this.socket = null;
  3308. this.isSocketOpen = false;
  3309. this.isConnecting = false;
  3310. socketToClose.close({
  3311. code: 1000,
  3312. reason: isManual ? '主动关闭' : '异常关闭'
  3313. });
  3314. console.log('WebSocket连接已发起关闭');
  3315. } catch (err) {
  3316. console.error('关闭WebSocket失败:', err);
  3317. // 即使关闭失败,也要重置状态
  3318. this.socket = null;
  3319. this.isSocketOpen = false;
  3320. this.isConnecting = false;
  3321. }
  3322. },
  3323. // 清理所有资源
  3324. cleanupAllResources() {
  3325. // 停止心跳相关
  3326. this.stopHeartBeat();
  3327. // 清理ping超时定时器
  3328. if (this.pingTimeoutTimer) {
  3329. clearTimeout(this.pingTimeoutTimer);
  3330. this.pingTimeoutTimer = null;
  3331. }
  3332. // 清理网络状态定时器
  3333. if (this.networkStatusTimer) {
  3334. clearTimeout(this.networkStatusTimer);
  3335. this.networkStatusTimer = null;
  3336. }
  3337. // 重置重连状态
  3338. this.resetReconnectState();
  3339. // 重置心跳相关状态
  3340. this.heartBeatRetryCount = 0;
  3341. this.lastHeartBeatTime = 0;
  3342. this.adaptiveHeartBeatInterval = this.heartBeatInterval;
  3343. },
  3344. startHeartBeat() {
  3345. this.stopHeartBeat(); // 先停止现有心跳,防止重复
  3346. // 使用自适应间隔循环发送心跳
  3347. this.heartBeatTimer = setInterval(() => {
  3348. this.sendHeartBeat();
  3349. }, this.adaptiveHeartBeatInterval);
  3350. },
  3351. initSocket() {
  3352. // 检查是否正在连接中
  3353. if (this.isConnecting) {
  3354. console.log('WebSocket正在连接中,跳过重复连接');
  3355. return;
  3356. }
  3357. // 检查网络状态
  3358. if (!this.isNetworkAvailable) {
  3359. console.warn('网络不可用,延迟WebSocket连接');
  3360. // 使用定时器而不是递归调用,避免内存泄漏
  3361. if (!this.networkRetryTimer) {
  3362. this.networkRetryTimer = setTimeout(() => {
  3363. this.networkRetryTimer = null;
  3364. this.initSocket();
  3365. }, 3000);
  3366. }
  3367. return;
  3368. }
  3369. // 如果已经存在连接且状态为open,则退出
  3370. if (this.socket && this.socket.readyState === 1) {
  3371. console.log('WebSocket连接已存在且正常,无需重新连接');
  3372. // 重置重连计数
  3373. this.reconnectCount = 0;
  3374. return;
  3375. }
  3376. // 关闭现有连接
  3377. if (this.socket && (this.socket.readyState === 0 || this.socket.readyState === 1)) {
  3378. console.log('关闭现有WebSocket连接,创建新连接');
  3379. this.closeWebSocket(false); // 非手动关闭
  3380. // 等待一小段时间确保连接完全关闭
  3381. setTimeout(() => {
  3382. this.createWebSocketConnection();
  3383. }, 100);
  3384. return;
  3385. }
  3386. this.createWebSocketConnection();
  3387. },
  3388. createWebSocketConnection() {
  3389. // 校验必要参数
  3390. if (!this.liveId) {
  3391. console.error('缺失直播间ID,无法初始化WebSocket');
  3392. return;
  3393. }
  3394. if (!this.userInfo || !this.userInfo.userId) {
  3395. console.error('用户信息缺失,无法初始化WebSocket');
  3396. return;
  3397. }
  3398. // 设置连接状态
  3399. this.isConnecting = true;
  3400. this.isSocketOpen = false;
  3401. // 记录连接开始时间(性能监控)
  3402. this.connectionStartTime = Date.now();
  3403. // 清除之前的重连定时器
  3404. this.resetReconnectState();
  3405. // setTimeout(() => {
  3406. // this.getliveUser(false);
  3407. // }, 1000);
  3408. const now = new Date();
  3409. this.timestamp = now.getTime(); // 生成签名
  3410. const signature = CryptoJS.HmacSHA256(
  3411. `${this.liveId}${this.userInfo.userId}${this.userType}${this.timestamp}`, this.timestamp.toString()
  3412. ).toString(CryptoJS.enc.Hex);
  3413. try {
  3414. const baseWsUrl = 'wss://ws.klbycp.com/ws/app/webSocket';
  3415. // const baseWsUrl = 'wss://api.fhhx.runtzh.com/ws/app/webSocket';
  3416. // const baseWsUrl = 'ws://d6998672.natappfree.cc/ws/app/webSocket';
  3417. // const baseWsUrl = 'ws://nd967d83.natappfree.cc/ws/app/webSocket';
  3418. let wsUrl =
  3419. `${baseWsUrl}?userId=${this.userInfo.userId}&liveId=${this.liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`;
  3420. // let wsUrl =
  3421. // 'ws://q96d9752.natappfree.cc/ws/app/webSocket?liveId=128&userId=9769&userType=1&timestamp=1762501143712&signature=0498c66c3fca64ab009586200c04d51312ce44e36d5639e99b22e34f3bac8d13';
  3422. if (this.qrFrom) {
  3423. wsUrl += this.qrFrom;
  3424. }
  3425. // if(this.address){
  3426. console.log("this.address是什么>>>", this.address)
  3427. wsUrl += `&location=${this.address}`;
  3428. // wsUrl += `&location=${encodeURIComponent(liveWatchUser)}`;
  3429. // }
  3430. console.log("qxj wsUrl", wsUrl);
  3431. console.log(`尝试连接WebSocket: ${wsUrl.replace(/signature=[^&]+/, 'signature=***')}`);
  3432. const socketTask = uni.connectSocket({
  3433. url: wsUrl,
  3434. success: () => {
  3435. console.log("WebSocket连接请求发送成功");
  3436. },
  3437. fail: (err) => {
  3438. console.error('WebSocket连接请求失败:', err);
  3439. this.isConnecting = false;
  3440. this.handleConnectionError('连接请求失败', err);
  3441. }
  3442. });
  3443. // 连接打开事件
  3444. socketTask.onOpen((res) => {
  3445. console.log("WebSocket连接已打开");
  3446. this.socket = socketTask;
  3447. this.isConnecting = false;
  3448. this.isSocketOpen = true;
  3449. // 计算连接延迟(性能监控)
  3450. if (this.connectionStartTime > 0) {
  3451. this.connectionLatency = Date.now() - this.connectionStartTime;
  3452. console.log(`WebSocket连接延迟: ${this.connectionLatency}ms`);
  3453. }
  3454. this.reconnectCount = 0;
  3455. this.resetReconnectState();
  3456. this.heartBeatRetryCount = 0; // 重置心跳重试次数
  3457. this.shownEntryUsers.clear(); // 重连后重置进入提示记录
  3458. // 连接成功后显示提示(仅首次连接)
  3459. if (this.reconnectCount === 0) {
  3460. console.log('WebSocket连接建立成功');
  3461. } else {
  3462. console.log(`WebSocket重连成功(第${this.reconnectCount}次尝试)`);
  3463. }
  3464. this.startHeartBeat();
  3465. });
  3466. // 消息接收事件
  3467. socketTask.onMessage((res) => {
  3468. // 消息计数(性能监控)
  3469. this.messageCount++;
  3470. try {
  3471. //console.log("qxj onMessage handleSocketMessage",res);
  3472. const data = JSON.parse(res.data);
  3473. // 处理服务端心跳响应 - 修复:后端返回的是heartBeat而不是heartBeatAck
  3474. if (!!data.data && data.data.cmd === 'heartbeat') {
  3475. // console.log('收到心跳响应:', data.data);
  3476. // 清除ping超时定时器
  3477. if (this.pingTimeoutTimer) {
  3478. clearTimeout(this.pingTimeoutTimer);
  3479. this.pingTimeoutTimer = null;
  3480. }
  3481. // 重置心跳重试次数
  3482. this.heartBeatRetryCount = 0;
  3483. // 更新网络状态为良好
  3484. this.adjustHeartBeatInterval(true);
  3485. return;
  3486. }
  3487. this.handleSocketMessage(res);
  3488. } catch (err) {
  3489. console.error('消息解析异常:', err);
  3490. this.errorCount++; // 错误计数
  3491. }
  3492. });
  3493. // 连接错误事件
  3494. socketTask.onError((err) => {
  3495. console.error('WebSocket连接错误:', err);
  3496. this.errorCount++; // 错误计数
  3497. this.isSocketOpen = false;
  3498. this.isConnecting = false;
  3499. this.stopHeartBeat();
  3500. this.handleConnectionError('连接错误', err);
  3501. });
  3502. // 连接关闭事件
  3503. socketTask.onClose((res) => {
  3504. console.log('WebSocket连接关闭:', res);
  3505. this.isSocketOpen = false;
  3506. this.isConnecting = false;
  3507. this.stopHeartBeat(); // 清除心跳定时器
  3508. // 根据关闭原因决定是否重连
  3509. if (!this.isManualClose) {
  3510. if (res.code === 1000) {
  3511. console.log('WebSocket正常关闭,不进行重连');
  3512. } else {
  3513. console.warn(`WebSocket异常关闭 (code: ${res.code}, reason: ${res.reason})`);
  3514. this.handleReconnect();
  3515. }
  3516. } else {
  3517. console.log('WebSocket手动关闭,不进行重连');
  3518. }
  3519. });
  3520. } catch (e) {
  3521. console.error('创建WebSocket异常:', e);
  3522. this.handleReconnect();
  3523. }
  3524. },
  3525. handleTime(time, duration) {
  3526. let timeStamp;
  3527. if (typeof time === 'number' && time > 0 && time < 9999999999999) {
  3528. timeStamp = time;
  3529. } else if (typeof time === 'string' && time.trim() !== '') {
  3530. // 手动解析 CST 时间字符串
  3531. const match = time.match(/^(\w{3}) (\w{3}) (\d{1,2}) (\d{1,2}):(\d{2}):(\d{2}) CST (\d{4})$/);
  3532. if (match) {
  3533. const [, day, month, date, hours, minutes, seconds, year] = match;
  3534. // 月份映射
  3535. const monthMap = {
  3536. 'Jan': 0,
  3537. 'Feb': 1,
  3538. 'Mar': 2,
  3539. 'Apr': 3,
  3540. 'May': 4,
  3541. 'Jun': 5,
  3542. 'Jul': 6,
  3543. 'Aug': 7,
  3544. 'Sep': 8,
  3545. 'Oct': 9,
  3546. 'Nov': 10,
  3547. 'Dec': 11
  3548. };
  3549. // 创建日期对象(CST 是 UTC+8,与中国时区一致)
  3550. const jsDate = new Date(
  3551. parseInt(year),
  3552. monthMap[month],
  3553. parseInt(date),
  3554. parseInt(hours),
  3555. parseInt(minutes),
  3556. parseInt(seconds)
  3557. );
  3558. timeStamp = jsDate.getTime();
  3559. } else {
  3560. // 如果不是预期格式,回退到普通解析
  3561. const date = new Date(time);
  3562. if (!isNaN(date.getTime())) {
  3563. timeStamp = date.getTime();
  3564. } else {
  3565. console.error('无效的日期格式:', time);
  3566. return false;
  3567. }
  3568. }
  3569. } else {
  3570. console.error('time参数必须是有效的时间戳(数字)或日期字符串');
  3571. return false;
  3572. }
  3573. const targetTimestamp = timeStamp + duration * 60 * 1000;
  3574. const currentTimestamp = Date.now();
  3575. const timeDiffMs = targetTimestamp - currentTimestamp;
  3576. if (timeDiffMs <= 0) {
  3577. return false;
  3578. }
  3579. const hours = Math.floor(timeDiffMs / (1000 * 60 * 60));
  3580. const minutes = Math.floor((timeDiffMs % (1000 * 60 * 60)) / (1000 * 60));
  3581. const seconds = Math.floor((timeDiffMs % (1000 * 60)) / 1000);
  3582. const formatNum = (num) => num.toString().padStart(2, '0');
  3583. return {
  3584. hours: formatNum(hours),
  3585. minutes: formatNum(minutes),
  3586. seconds: formatNum(seconds)
  3587. };
  3588. },
  3589. // 限制聊天消息数量,防止内存泄漏
  3590. addToTalkList(message) {
  3591. // console.log("修改后的message>>", message)
  3592. // 减少最大消息数量,提升iPhone性能
  3593. const MAX_TALK_ITEMS = 30;
  3594. // 直接操作数组,避免创建新数组
  3595. if (!Array.isArray(this.talklist)) {
  3596. this.talklist = [];
  3597. }
  3598. const wasAtLimit = this.talklist.length >= MAX_TALK_ITEMS;
  3599. //console.log(`添加消息前: 当前消息数量=${this.talklist.length}, 是否达到限制=${wasAtLimit}`);
  3600. // 检查是否是自己发送的消息
  3601. const isMyMessage = message.userId === this.userInfo.userId;
  3602. //console.log(`消息来源: ${isMyMessage ? '自己' : '他人'}, userId=${message.userId}`);
  3603. // 给消息添加唯一ID
  3604. message.uniqueId = ++this.messageIdCounter;
  3605. let msgdata = JSON.parse(message.data);
  3606. message.msgId = msgdata.msgId;
  3607. this.talklist.push(message);
  3608. // 当消息超过限制时,批量删除旧消息
  3609. if (this.talklist.length > MAX_TALK_ITEMS) {
  3610. const removeCount = this.talklist.length - MAX_TALK_ITEMS;
  3611. //console.log(`消息超过限制,删除前${removeCount}条旧消息`);
  3612. this.talklist.splice(0, removeCount);
  3613. }
  3614. //console.log(`添加消息后: 当前消息数量=${this.talklist.length}`);
  3615. // 强制触发视图更新
  3616. this.$forceUpdate();
  3617. // 使用单次nextTick确保DOM更新后再滚动
  3618. this.$nextTick(() => {
  3619. this.forceScrollToBottomOnSend();
  3620. // if (isMyMessage) {
  3621. // // 如果是自己发送的消息,强制滚动到底部
  3622. // console.log('自己的消息,执行强制滚动');
  3623. // this.forceScrollToBottomOnSend();
  3624. // } else {
  3625. // // 如果是他人的消息,使用普通滚动(有防抖)
  3626. // console.log('他人的消息,执行普通滚动');
  3627. // this.simpleScrollToBottom();
  3628. // }
  3629. });
  3630. },
  3631. // 处理Socket消息
  3632. async handleSocketMessage(message) {
  3633. try {
  3634. let data = JSON.parse(message.data);
  3635. const socketMessage = data.data; // 服务端返回的消息体
  3636. //console.log("qxj handleSocketMessage socketMessage",socketMessage);
  3637. if (data.code == 200) {
  3638. const messageData = {
  3639. ...socketMessage,
  3640. cmd: socketMessage.cmd || '', // 确保cmd字段存在
  3641. ts: Date.now() // 时间戳
  3642. };
  3643. // 处理服务端返回的sendMsg消息,加入本地列表
  3644. if (socketMessage.cmd == 'sendMsg') {
  3645. if (!this.isSocketAvailable()) {
  3646. uni.showToast({
  3647. title: '连接已断开,正在重试...',
  3648. icon: 'none'
  3649. });
  3650. this.handleReconnect();
  3651. return;
  3652. }
  3653. this.addToTalkList(messageData);
  3654. } else if (socketMessage.cmd == 'red') {
  3655. const redData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  3656. this.redInfo = redData || {};
  3657. this.isShowRed = socketMessage.status === 1;
  3658. if (this.isShowRed) {
  3659. this.redTimer = setInterval(() => {
  3660. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  3661. .duration);
  3662. if (!redCountdown) {
  3663. this.isShowRed = false;
  3664. clearInterval(this.redTimer);
  3665. }
  3666. }, 1000);
  3667. }
  3668. } else if (socketMessage.cmd == 'goods') {
  3669. const goodsData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  3670. this.goodsCard = goodsData || {};
  3671. this.isShowGoods = socketMessage.status == 1;
  3672. } else if (socketMessage.cmd == 'coupon') {
  3673. const couponData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  3674. this.couponInfo = couponData || {};
  3675. this.isShowCoupon = socketMessage.status === 1;
  3676. if (this.isShowCoupon) {}
  3677. } else if (socketMessage.cmd == 'likeDetail') {
  3678. this.liveViewData.like = socketMessage.data;
  3679. } else if (socketMessage.cmd == 'lottery') {
  3680. const lotteryData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  3681. this.lotteryInfo = lotteryData || {};
  3682. this.isShowLottery = socketMessage.status === 1;
  3683. if (socketMessage.status != 1) {
  3684. this.isShowLotteryPop = false;
  3685. }
  3686. // 清除已有定时器(无论状态是否为1,先清掉旧的)
  3687. clearInterval(this.lotteryTimer);
  3688. if (this.isShowLottery) {
  3689. this.lotteryTimer = setInterval(() => {
  3690. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this
  3691. .lotteryInfo.duration);
  3692. if (!this.countdown) {
  3693. console.log('倒计时', this.countdown);
  3694. this.isShowLottery = false;
  3695. this.isShowLotteryPop = false;
  3696. clearInterval(this.lotteryTimer);
  3697. }
  3698. }, 1000);
  3699. } else {
  3700. this.isShowLottery = false;
  3701. }
  3702. } else if (socketMessage.cmd == 'globalVisible' || socketMessage.cmd == 'singleVisible') {
  3703. // status = 1的时候,用户消息自可见,其他消息丢失}
  3704. console.log("可见性>>>>>", socketMessage)
  3705. if (socketMessage.status == 1) {
  3706. console.log("不可见性")
  3707. this.myselfFlag = true;
  3708. } else {
  3709. this.myselfFlag = false;
  3710. }
  3711. } else if (socketMessage.cmd == 'sendPopMsg') {
  3712. console.log("弹窗消息>>>>", socketMessage)
  3713. this.popMsg = socketMessage.msg
  3714. this.isShowPopMsg = true
  3715. } else if (socketMessage.cmd == 'sendTopMsg') {
  3716. clearInterval(this.noticeTimer);
  3717. console.log("公告消息>>>>", socketMessage)
  3718. const noticeData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  3719. this.notice = noticeData || {};
  3720. this.isShowNotice = true
  3721. if (this.isShowNotice) {
  3722. this.noticeTimer = setInterval(() => {
  3723. const noticeCountdown = this.handleTime(this.notice.endTime, 0);
  3724. if (!noticeCountdown) {
  3725. this.isShowNotice = false;
  3726. clearInterval(this.noticeTimer);
  3727. }
  3728. }, 1000);
  3729. }
  3730. } else if (socketMessage.cmd == 'entry') {
  3731. try {
  3732. if (!this.liveUserCalled) {
  3733. // await this.getliveUser(false);
  3734. this.liveUserCalled = true;
  3735. }
  3736. const userIdToEntry = socketMessage.userId;
  3737. const existingIndex = this.liveViewersData.findIndex((item) => item.userId ===
  3738. userIdToEntry);
  3739. if (existingIndex === -1) {
  3740. const liveViewers = {
  3741. userId: socketMessage.userId,
  3742. nickName: socketMessage.nickName,
  3743. avatar: socketMessage.avatar
  3744. };
  3745. this.liveViewersData.push(liveViewers);
  3746. this.liveUserTotal++;
  3747. }
  3748. // 解析用户ID(根据实际接口字段调整,此处假设data含userId)
  3749. const userInfo = JSON.parse(socketMessage.data || '{}');
  3750. const userId = userInfo.userId || socketMessage.userId; // 兼容不同字段
  3751. if (!userId) return; // 无用户ID不处理
  3752. // 仅新用户(未显示过)才触发提示
  3753. if (!this.shownEntryUsers.has(userId)) {
  3754. this.inAndOut = socketMessage;
  3755. this.showWelcomeMessage = true;
  3756. this.shownEntryUsers.add(userId); // 加入已显示集合
  3757. messageData.msg = '来了'
  3758. this.addToTalkList(messageData);
  3759. // 3秒后隐藏提示(可调整时长)
  3760. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  3761. this.welcomeTimer = setTimeout(() => {
  3762. this.showWelcomeMessage = false;
  3763. }, 3000);
  3764. }
  3765. } catch (err) {
  3766. console.error('解析entry用户数据失败:', err);
  3767. }
  3768. } else if (socketMessage.cmd == 'out') {
  3769. if (this.liveUserTotal > 0) {
  3770. const userIdToRemove = socketMessage.userId;
  3771. const index = this.liveViewersData.findIndex((item) => item.userId === userIdToRemove);
  3772. if (index !== -1) {
  3773. this.liveViewersData.splice(index, 1);
  3774. this.liveUserTotal--; // 根据userId删除对应的用户数据
  3775. }
  3776. }
  3777. this.inAndOut = socketMessage;
  3778. this.showWelcomeMessage = true;
  3779. // 3秒后隐藏提示
  3780. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  3781. this.welcomeTimer = setTimeout(() => {
  3782. this.showWelcomeMessage = false;
  3783. }, 3000);
  3784. } else if (socketMessage.cmd == 'live_start' || socketMessage.cmd == 'live_end') {
  3785. // 开始直播,关闭直播
  3786. if (this.liveStartTimer) {
  3787. clearInterval(this.liveStartTimer);
  3788. this.liveStartTimer = null;
  3789. }
  3790. if (this.redTimer) {
  3791. clearInterval(this.redTimer);
  3792. this.redTimer = null;
  3793. }
  3794. // 请求最新直播间数据
  3795. this.$nextTick(() => {
  3796. this.getliving(this.liveId);
  3797. });
  3798. } else if (socketMessage.cmd == 'Integral') {
  3799. this.integral = {
  3800. msg: socketMessage.msg,
  3801. status: true
  3802. };
  3803. } else if (socketMessage.cmd == 'userCount') {
  3804. // 广播在线人数
  3805. this.virtualHuman = socketMessage.data * 10
  3806. } else if (socketMessage.cmd == 'deleteMsg') {
  3807. const index = this.talklist.findIndex(item => item.msgId == socketMessage.msg);
  3808. if (index !== -1) {
  3809. this.talklist.splice(index, 1);
  3810. }
  3811. } else if (socketMessage.cmd == 'LotteryDetail') {
  3812. try {
  3813. this.prizeInfo = Array.isArray(JSON.parse(socketMessage.data || '[]')) ? JSON.parse(
  3814. socketMessage.data || '[]') : [];
  3815. } catch (err) {
  3816. console.error('解析抽奖结果失败:', err);
  3817. this.prizeInfo = [];
  3818. }
  3819. this.isShowPrize = true;
  3820. this.isShowLottery = false;
  3821. this.isShowLotteryPop = false;
  3822. } else if (socketMessage.cmd == 'blockUser') {
  3823. uni.removeStorage({
  3824. key: 'AppToken',
  3825. success: () => {
  3826. uni.reLaunch({
  3827. url: '/pages/auth/login'
  3828. });
  3829. }
  3830. });
  3831. }
  3832. } else {
  3833. uni.showToast({
  3834. title: data.msg,
  3835. icon: 'none'
  3836. });
  3837. }
  3838. } catch (error) {
  3839. console.error('Socket消息处理失败:', error);
  3840. }
  3841. },
  3842. sendMsg(retries = 1) {
  3843. // 防止连续点击发送两次(800ms短时锁定)
  3844. if (this.isSending) return;
  3845. this.isSending = true;
  3846. setTimeout(() => {
  3847. this.isSending = false;
  3848. }, 800);
  3849. const text = (this.value || '').trim();
  3850. if (!text) {
  3851. uni.showToast({
  3852. title: '不能发送空消息',
  3853. icon: 'none'
  3854. });
  3855. return;
  3856. }
  3857. if (!this.isSocketAvailable()) {
  3858. if (retries > 0) {
  3859. uni.showToast({
  3860. title: `连接不稳定,正在重试(${retries}次)...`,
  3861. icon: 'none'
  3862. });
  3863. // 延迟500ms重试,重试次数减1
  3864. setTimeout(() => this.sendMsg(retries - 1), 500);
  3865. } else {
  3866. uni.showToast({
  3867. title: '连接已断开,发送失败',
  3868. icon: 'none'
  3869. });
  3870. this.value = text; // 恢复输入框内容
  3871. }
  3872. return;
  3873. }
  3874. const liveId = this.liveId;
  3875. this.value = ''; // 立即清空输入框
  3876. // 构造发送给服务端的消息数据
  3877. const data = {
  3878. liveId,
  3879. userId: this.userInfo.userId,
  3880. userType: 0,
  3881. cmd: 'sendMsg',
  3882. msg: text,
  3883. nickName: this.userInfo.nickname || '未命名',
  3884. avatar: this.userInfo.avatar ||
  3885. 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/avatar.png'
  3886. };
  3887. // 发送socket消息
  3888. try {
  3889. if (this.myselfFlag) {
  3890. this.addToTalkList(data);
  3891. } else {
  3892. this.socket.send({
  3893. data: JSON.stringify(data),
  3894. success: () => {
  3895. this.value = '';
  3896. // 发送成功后强制滚动到底部,无论当前滚动位置如何
  3897. this.forceScrollToBottomOnSend();
  3898. },
  3899. fail: (err) => {
  3900. console.error('消息发送失败:', err);
  3901. if (retries > 0) {
  3902. uni.showToast({
  3903. title: `发送失败,正在重试(${retries}次)`,
  3904. icon: 'none'
  3905. });
  3906. setTimeout(() => this.sendMsg(retries - 1), 500);
  3907. } else {
  3908. uni.showToast({
  3909. title: '发送失败,请稍后再试',
  3910. icon: 'none'
  3911. });
  3912. this.value = text; // 恢复输入框内容
  3913. }
  3914. }
  3915. });
  3916. }
  3917. } catch (err) {
  3918. console.error('发送消息异常:', err);
  3919. if (retries > 0) {
  3920. setTimeout(() => this.sendMsg(retries - 1), 500);
  3921. } else {
  3922. uni.showToast({
  3923. title: '发送失败,请稍后再试',
  3924. icon: 'none'
  3925. });
  3926. this.value = text;
  3927. }
  3928. }
  3929. },
  3930. formatUserNum() {
  3931. let userTotal = 0;
  3932. if (!this.liveUserTotal) {
  3933. this.liveUserTotal = 0;
  3934. }
  3935. if (this.liveUserTotal > 0) {
  3936. userTotal = this.liveUserTotal = 0;
  3937. }
  3938. if (this.liveUserTotal > 10000) {
  3939. userTotal = (this.liveUserTotal / 10000.0).toFixed(1);
  3940. userTotal = userTotal + "万";
  3941. }
  3942. console.log("qxj userTotal", userTotal);
  3943. return userTotal;
  3944. }
  3945. },
  3946. };
  3947. </script>
  3948. <style scoped lang="scss">
  3949. // 重置按钮样式
  3950. .button-reset {
  3951. background-color: transparent !important;
  3952. padding: 0 !important;
  3953. line-height: 1 !important;
  3954. margin: 0 !important;
  3955. width: auto !important;
  3956. font-weight: 500 !important;
  3957. border-radius: none !important;
  3958. &::after {
  3959. border: none !important;
  3960. padding: 0 !important;
  3961. margin: 0 !important;
  3962. }
  3963. }
  3964. // :deep(.u-tabs__wrapper__nav) {
  3965. // background-color: #fff !important;
  3966. // }
  3967. .swiper-wrapper {
  3968. /* 深色主题变量 */
  3969. --bottom-color: transparent;
  3970. --bg-color: #242424;
  3971. --text-color: #ffffff;
  3972. --name-color: #8CE7FF;
  3973. --normal-bg: rgba(0, 0, 0, 0.3);
  3974. --input-bg: rgba(0, 0, 0, 0.3);
  3975. --chat-bg: transparent;
  3976. --video-height: 100vh;
  3977. --chat-height: 30vh;
  3978. --pop-bg: #333333;
  3979. --notice-bg: rgba(9, 9, 9, 0.4);
  3980. }
  3981. .swiper-wrapper.horizontal {
  3982. --notice-bg: #fefae8;
  3983. --pop-bg: #ECF5F4;
  3984. /* 默认变量(浅色主题) */
  3985. --bottom-color: #fff;
  3986. --name-color: #666666;
  3987. --bg-color: #ffffff;
  3988. --text-color: #333333;
  3989. --normal-bg: #fff;
  3990. --input-bg: #F5F7FA;
  3991. --chat-bg: #ECF5F4; //对话聊天
  3992. --video-height: 500rpx;
  3993. --chat-height: clac(100% - 650rpx);
  3994. }
  3995. // 主容器
  3996. .swiper-wrapper {
  3997. position: relative;
  3998. width: 100%;
  3999. height: 100vh;
  4000. overflow: hidden;
  4001. /* 应用变量 */
  4002. background: var(--bg-color);
  4003. color: var(--text-color);
  4004. .container {
  4005. width: 100%;
  4006. height: 100%;
  4007. position: relative;
  4008. transition: opacity 0.3s ease;
  4009. transform: translateZ(0);
  4010. will-change: opacity;
  4011. // 预告直播盒子
  4012. .trailer-box {
  4013. width: calc(100% - 80rpx);
  4014. background: var(--pop-bg);
  4015. border-radius: 24rpx;
  4016. position: absolute;
  4017. top: 15%;
  4018. left: 50%;
  4019. transform: translateX(-50%);
  4020. display: flex;
  4021. flex-direction: column;
  4022. align-items: center;
  4023. color: var(--text-color);
  4024. padding: 20rpx;
  4025. z-index: 999;
  4026. box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.12);
  4027. transition: box-shadow 0.3s ease;
  4028. .trailer-video {
  4029. width: 100%;
  4030. height: 400rpx;
  4031. }
  4032. .trailer-placeholder {
  4033. margin-bottom: 40rpx;
  4034. width: 240rpx;
  4035. height: 240rpx;
  4036. }
  4037. .countdown-container {
  4038. margin: 20rpx 0;
  4039. display: flex;
  4040. flex-direction: column;
  4041. align-items: center;
  4042. .live-name {
  4043. font-weight: 600;
  4044. font-size: 36rpx;
  4045. }
  4046. .countdown-display {
  4047. display: flex;
  4048. align-items: center;
  4049. margin: 30rpx 0;
  4050. .countdown-label {
  4051. font-size: 24rpx;
  4052. color: #999999;
  4053. }
  4054. .countdown-separator {
  4055. font-size: 24rpx;
  4056. color: #999999;
  4057. }
  4058. .countdown-unit {
  4059. width: 40rpx;
  4060. height: 40rpx;
  4061. background: #4D4D4D;
  4062. border-radius: 8rpx;
  4063. text-align: center;
  4064. overflow: hidden;
  4065. margin: 0 8rpx;
  4066. font-weight: 500;
  4067. font-size: 28rpx;
  4068. color: #FFFFFF;
  4069. line-height: 40rpx;
  4070. }
  4071. }
  4072. }
  4073. .trailer-actions {
  4074. display: flex;
  4075. justify-content: center;
  4076. align-items: center;
  4077. .action-button {
  4078. width: 280rpx;
  4079. height: 72rpx;
  4080. border-radius: 36rpx;
  4081. line-height: 72rpx;
  4082. text-align: center;
  4083. color: #fff;
  4084. &.reserve-button {
  4085. background: linear-gradient(136deg, #38D97D 0%, #02B176 100%);
  4086. }
  4087. &:not(.reserve-button) {
  4088. background: #F4A007;
  4089. }
  4090. .button-icon {
  4091. width: 32rpx;
  4092. height: 32rpx;
  4093. }
  4094. }
  4095. }
  4096. .no-live-title {
  4097. margin-top: 30rpx;
  4098. font-size: 42rpx;
  4099. font-weight: 500;
  4100. }
  4101. }
  4102. // 主要内容区域
  4103. .content {
  4104. position: relative;
  4105. z-index: 2;
  4106. height: 100%;
  4107. width: 100%;
  4108. top: 0;
  4109. left: 0;
  4110. display: flex;
  4111. flex-direction: column;
  4112. &.horizontal-content {
  4113. z-index: 999;
  4114. }
  4115. &.trailer-content {
  4116. justify-content: space-between;
  4117. }
  4118. // 顶部信息栏
  4119. .top-info-bar {
  4120. position: fixed;
  4121. top: 0;
  4122. z-index: 5;
  4123. width: 100%;
  4124. padding: 0 24rpx;
  4125. box-sizing: border-box;
  4126. margin-top: 48rpx;
  4127. display: flex;
  4128. justify-content: space-between;
  4129. &.horizontal-top {
  4130. position: static;
  4131. margin-bottom: 50rpx;
  4132. }
  4133. .user-info-section {
  4134. display: flex;
  4135. align-items: center;
  4136. .back-icon {
  4137. width: 60rpx;
  4138. height: 64rpx;
  4139. }
  4140. .user-avatar-container {
  4141. padding: 6rpx 8rpx;
  4142. height: 64rpx;
  4143. background: var(--normal-bg);
  4144. border-radius: 32rpx;
  4145. display: flex;
  4146. align-items: center;
  4147. .user-name {
  4148. color: var(--text-color);
  4149. }
  4150. }
  4151. }
  4152. .viewers-section {
  4153. display: flex;
  4154. align-items: center;
  4155. margin-top: 120rpx;
  4156. .viewer-avatar {
  4157. width: 52rpx;
  4158. height: 52rpx;
  4159. border-radius: 26rpx;
  4160. }
  4161. .viewer-avatar-placeholder {
  4162. width: 52rpx;
  4163. height: 52rpx;
  4164. border-radius: 50%;
  4165. display: flex;
  4166. align-items: center;
  4167. justify-content: center;
  4168. .avatar-initial {
  4169. color: var(--text-color);
  4170. font-size: 18rpx;
  4171. }
  4172. }
  4173. .viewer-count {
  4174. width: 80rpx;
  4175. height: 52rpx;
  4176. background: var(--normal-bg);
  4177. border-radius: 26rpx;
  4178. font-size: 30rpx;
  4179. color: var(--text-color);
  4180. text-align: center;
  4181. line-height: 52rpx;
  4182. }
  4183. }
  4184. }
  4185. // 购买提示
  4186. .purchase-prompt {
  4187. position: absolute;
  4188. bottom: 750rpx;
  4189. left: 24rpx;
  4190. padding: 6rpx 20rpx;
  4191. background: rgba(230, 154, 34, 0.7);
  4192. border-radius: 24rpx;
  4193. z-index: 9;
  4194. font-weight: 500;
  4195. color: #ffffff;
  4196. transition: opacity 0.3s ease;
  4197. font-size: 30rpx;
  4198. display: flex;
  4199. align-items: center;
  4200. .prompt-icon {
  4201. width: 32rpx;
  4202. height: 32rpx;
  4203. }
  4204. }
  4205. // 视频区域
  4206. .videolist {
  4207. position: relative;
  4208. height: var(--video-height);
  4209. width: 100%;
  4210. .video-container {
  4211. height: var(--video-height);
  4212. width: 100%;
  4213. transform: translateZ(0);
  4214. backface-visibility: hidden;
  4215. perspective: 1000;
  4216. &.horizontal-layout {
  4217. // position: absolute;
  4218. // top: 20%;
  4219. // max-height: 450rpx;
  4220. // z-index: 99;
  4221. }
  4222. .txt {
  4223. text-align: center;
  4224. font-weight: 500;
  4225. font-size: 40rpx;
  4226. line-height: var(--video-height);
  4227. }
  4228. .video-player {
  4229. width: 100%;
  4230. height: 100%;
  4231. }
  4232. .live-end-message {
  4233. position: absolute;
  4234. top: 50%;
  4235. left: 50%;
  4236. transform: translate(-50%, -50%);
  4237. font-size: 36rpx;
  4238. color: var(--text-color);
  4239. }
  4240. .replay-label {
  4241. position: absolute;
  4242. top: 15%;
  4243. right: 24rpx;
  4244. background-color: rgba(57, 57, 57, 0.6);
  4245. padding: 6rpx 16rpx;
  4246. color: #fff;
  4247. border-radius: 15rpx;
  4248. }
  4249. }
  4250. }
  4251. }
  4252. // 聊天区域
  4253. .chat-area-container {
  4254. background: var(--chat-bg);
  4255. position: fixed;
  4256. width: 100%;
  4257. bottom: 0;
  4258. z-index: 999;
  4259. transform: translateZ(0);
  4260. will-change: transform;
  4261. backface-visibility: hidden;
  4262. &.chat-area-container2 {
  4263. flex: 1;
  4264. min-height: 0; // 重要:允许收缩到0
  4265. position: relative;
  4266. transform: none; // 移除之前的变换
  4267. will-change: auto;
  4268. display: flex;
  4269. flex-direction: column;
  4270. }
  4271. &.chat-area-container3 {
  4272. max-height: 40%;
  4273. flex: 1;
  4274. min-height: 0; // 重要:允许收缩到0
  4275. // position: relative;
  4276. transform: none; // 移除之前的变换
  4277. will-change: auto;
  4278. display: flex;
  4279. flex-direction: column;
  4280. position: absolute;
  4281. }
  4282. &.chat-area-focused {
  4283. transform: translateY(calc(-1 * var(--keyboard-height, 0rpx))) translateZ(0);
  4284. z-index: 1000;
  4285. }
  4286. .tabs_bg {
  4287. background-color: #fff;
  4288. padding: 20rpx 40rpx 0;
  4289. }
  4290. .chat-content-wrapper {
  4291. flex: 1;
  4292. height: 368rpx;
  4293. padding: 20rpx 0;
  4294. transform: translateZ(0);
  4295. will-change: height;
  4296. position: relative;
  4297. &.chat-content-focused {
  4298. height: 64rpx;
  4299. }
  4300. .notice-message {
  4301. position: absolute;
  4302. bottom: 388rpx;
  4303. max-width: 80%;
  4304. padding: 24rpx;
  4305. background-color: var(--notice-bg);
  4306. margin: 0 0 20rpx 20rpx;
  4307. border-radius: 20rpx;
  4308. color: #ffda73;
  4309. overflow: hidden;
  4310. &.horizontal-notice {
  4311. top: 12rpx;
  4312. height: fit-content;
  4313. z-index: 2;
  4314. }
  4315. }
  4316. .message-scroll-view {
  4317. width: calc(100% - 20rpx);
  4318. height: 100%;
  4319. padding-left: 20rpx;
  4320. display: flex;
  4321. flex: 1;
  4322. flex-direction: column;
  4323. -webkit-overflow-scrolling: touch;
  4324. }
  4325. .message-list {
  4326. width: 80%;
  4327. margin-bottom: 4rpx;
  4328. animation: simpleFade 0.2s;
  4329. .message-item {
  4330. display: flex;
  4331. justify-content: flex-start;
  4332. .message-content {
  4333. font-size: 30rpx;
  4334. max-width: 100%;
  4335. border-radius: 30rpx;
  4336. background: var(--normal-bg);
  4337. padding: 10rpx 30rpx;
  4338. line-height: 1.4;
  4339. word-break: break-all;
  4340. word-wrap: break-word;
  4341. overflow-wrap: break-word;
  4342. .user-nickname {
  4343. color: var(--name-color);
  4344. }
  4345. .message-text {
  4346. color: var(--text-color);
  4347. }
  4348. }
  4349. }
  4350. }
  4351. }
  4352. // 输入和操作区域
  4353. .input-actions-container {
  4354. position: relative;
  4355. z-index: 999999;
  4356. background-color: var(--bottom-color);
  4357. display: flex;
  4358. justify-content: space-between;
  4359. align-items: center;
  4360. padding: 24rpx;
  4361. &.input-actions-focused {
  4362. justify-content: flex-start !important;
  4363. align-items: stretch !important;
  4364. width: 100% !important;
  4365. display: flex !important;
  4366. }
  4367. .input-container {
  4368. background: var(--input-bg);
  4369. box-sizing: border-box;
  4370. border-radius: 36rpx;
  4371. display: flex;
  4372. align-items: center;
  4373. transform: translateZ(0);
  4374. will-change: transform;
  4375. backface-visibility: hidden;
  4376. perspective: 1000px;
  4377. &.input-container-normal {
  4378. padding: 18rpx 20rpx;
  4379. width: auto;
  4380. max-width: auto;
  4381. margin-right: 0;
  4382. justify-content: space-between;
  4383. }
  4384. &.input-container-focused {
  4385. padding: 10rpx 10rpx 10rpx 20rpx;
  4386. width: 100%;
  4387. max-width: calc(100% - 20rpx);
  4388. margin-right: 20rpx;
  4389. // flex: 1;
  4390. justify-content: flex-start;
  4391. }
  4392. .chat-input {
  4393. border: none !important;
  4394. font-size: 32rpx !important;
  4395. color: var(--text-color) !important;
  4396. background: transparent !important;
  4397. width: 70% !important;
  4398. transform: translateZ(0);
  4399. will-change: contents, width;
  4400. backface-visibility: hidden;
  4401. margin-left: 20rpx;
  4402. &.input-focused {
  4403. width: 100% !important;
  4404. flex: 1 !important;
  4405. min-width: 0 !important;
  4406. margin-left: 10rpx !important;
  4407. max-width: none !important;
  4408. }
  4409. }
  4410. .send-button {
  4411. background-color: #ffffff;
  4412. border-radius: 28rpx;
  4413. padding: 14rpx 16rpx;
  4414. color: #181818;
  4415. font-weight: 500;
  4416. min-width: 80rpx;
  4417. text-align: center;
  4418. flex-shrink: 0;
  4419. &.send2 {
  4420. background-color: #2fa9f1;
  4421. color: #ffffff;
  4422. }
  4423. }
  4424. }
  4425. .action-buttons {
  4426. display: flex;
  4427. justify-content: space-between;
  4428. align-items: center;
  4429. flex: auto;
  4430. // margin-right: 15rpx;
  4431. transform: translateZ(0);
  4432. justify-content: flex-end;
  4433. &.action-buttons-hidden {
  4434. opacity: 0;
  4435. visibility: hidden;
  4436. }
  4437. .action-button-group {
  4438. display: flex;
  4439. justify-content: space-between;
  4440. align-items: center;
  4441. }
  4442. .icon-button {
  4443. background: var(--normal-bg);
  4444. border-radius: 50%;
  4445. width: 88rpx;
  4446. height: 88rpx;
  4447. display: flex;
  4448. justify-content: center;
  4449. align-items: center;
  4450. transition: transform 0.2s ease;
  4451. margin-left: 10rpx;
  4452. &.like-container {
  4453. display: flex;
  4454. flex-direction: column;
  4455. justify-content: center;
  4456. align-items: center;
  4457. .like-count {
  4458. position: absolute;
  4459. bottom: -10rpx;
  4460. font-size: 14rpx;
  4461. color: #FA341E;
  4462. padding: 4rpx 6rpx;
  4463. background: #FFFFFF;
  4464. border-radius: 10rpx;
  4465. }
  4466. }
  4467. .action-icon {
  4468. width: 48rpx;
  4469. height: 48rpx;
  4470. }
  4471. .cart-icon {
  4472. width: 58rpx;
  4473. height: 58rpx;
  4474. }
  4475. }
  4476. }
  4477. }
  4478. }
  4479. // 商品卡片
  4480. .goods-card {
  4481. position: fixed;
  4482. bottom: 140rpx;
  4483. right: 24rpx;
  4484. z-index: 5;
  4485. background-color: #fff;
  4486. border-radius: 20rpx;
  4487. overflow: hidden;
  4488. width: 224rpx;
  4489. padding: 4rpx;
  4490. .goods-card-header {
  4491. position: absolute;
  4492. top: 4rpx;
  4493. display: flex;
  4494. justify-content: space-between;
  4495. align-items: center;
  4496. color: #fff;
  4497. width: 100%;
  4498. padding-right: 10rpx;
  4499. box-sizing: border-box;
  4500. .goods-status {
  4501. background: rgba(0, 0, 0, 0.4);
  4502. padding: 12rpx;
  4503. font-size: 22rpx;
  4504. display: flex;
  4505. justify-content: space-between;
  4506. align-items: center;
  4507. border-radius: 10rpx;
  4508. .status-icon {
  4509. width: 30rpx;
  4510. height: 30rpx;
  4511. }
  4512. }
  4513. .close-icon {
  4514. width: 24rpx;
  4515. height: 24rpx;
  4516. }
  4517. }
  4518. .goods-image {
  4519. width: 100%;
  4520. height: 224rpx;
  4521. border-radius: 16rpx 16rpx 0 0;
  4522. overflow: hidden;
  4523. }
  4524. .goods-info {
  4525. padding: 4rpx;
  4526. .goods-title {
  4527. font-weight: 500;
  4528. font-size: 24rpx;
  4529. margin: 10rpx 0 12rpx;
  4530. color: #111111;
  4531. }
  4532. .goods-action {
  4533. color: #fff;
  4534. text-align: center;
  4535. font-weight: 500;
  4536. font-size: 30rpx;
  4537. position: relative;
  4538. .goods-price {
  4539. left: 10rpx;
  4540. position: absolute;
  4541. top: 40%;
  4542. transform: translateY(-50%);
  4543. font-size: 30rpx;
  4544. z-index: 999;
  4545. .price-symbol {
  4546. font-weight: 600;
  4547. font-size: 20rpx;
  4548. color: #FFFFFF;
  4549. }
  4550. .price-integer {
  4551. font-size: 36rpx;
  4552. margin-right: 10rpx;
  4553. }
  4554. }
  4555. .shop-icon {
  4556. width: 204rpx;
  4557. height: 52rpx;
  4558. }
  4559. }
  4560. }
  4561. }
  4562. // 动画
  4563. @keyframes simpleFade {
  4564. from {
  4565. opacity: 0;
  4566. }
  4567. to {
  4568. opacity: 1;
  4569. }
  4570. }
  4571. .userlogo {
  4572. padding: 40rpx 20rpx;
  4573. color: #181818;
  4574. .boxweixin {
  4575. width: 44rpx;
  4576. height: 44rpx;
  4577. border-radius: 50%;
  4578. text-align: center;
  4579. line-height: 34rpx;
  4580. color: #0a0;
  4581. }
  4582. .button-container {
  4583. position: relative;
  4584. // width: 240rpx;
  4585. .subname {
  4586. background-color: #00aa00;
  4587. color: #fff;
  4588. }
  4589. .subavt {
  4590. background-color: #fff;
  4591. border: 2rpx #0a0 solid;
  4592. color: #00aa00;
  4593. }
  4594. }
  4595. .submitname {
  4596. background-color: #00aa00;
  4597. color: #fff;
  4598. width: 90%;
  4599. margin: 0 auto;
  4600. text-align: center;
  4601. padding: 30rpx;
  4602. margin-top: 40rpx;
  4603. }
  4604. }
  4605. // 抽奖弹窗1
  4606. .lottery-popup {
  4607. position: relative;
  4608. border-radius: 40rpx;
  4609. height: fit-content;
  4610. .lottery-header-image {
  4611. width: 311rpx;
  4612. position: absolute;
  4613. top: -122rpx;
  4614. left: 50%;
  4615. transform: translateX(-50%);
  4616. }
  4617. .lottery-background-image {
  4618. position: absolute;
  4619. top: 0;
  4620. left: 0;
  4621. width: 100%;
  4622. height: 100%;
  4623. z-index: 1;
  4624. }
  4625. .lottery-content {
  4626. position: relative;
  4627. z-index: 2;
  4628. padding: 24rpx 0 68rpx;
  4629. .lottery-close-section {
  4630. display: flex;
  4631. justify-content: flex-end;
  4632. margin-right: 20rpx;
  4633. .close-button-wrapper {
  4634. .close-button {
  4635. width: 80rpx;
  4636. height: 80rpx;
  4637. display: flex;
  4638. justify-content: center;
  4639. align-items: center;
  4640. }
  4641. }
  4642. }
  4643. .lottery-main-content {
  4644. display: flex;
  4645. flex-direction: column;
  4646. align-items: center;
  4647. .lottery-title-image {
  4648. width: 446rpx;
  4649. height: 80rpx;
  4650. }
  4651. .lottery-countdown-section {
  4652. font-size: 24rpx;
  4653. color: #fff;
  4654. display: flex;
  4655. align-items: center;
  4656. margin: 30rpx 0;
  4657. .countdown-label {
  4658. margin-right: 10rpx;
  4659. }
  4660. .countdown-timer {
  4661. display: flex;
  4662. align-items: center;
  4663. .countdown-number {
  4664. width: 40rpx;
  4665. height: 40rpx;
  4666. text-align: center;
  4667. overflow: hidden;
  4668. background: #ffffff;
  4669. box-shadow: inset 0rpx 2rpx 8rpx 0rpx #ffebb2;
  4670. border-radius: 8rpx;
  4671. margin: 4rpx;
  4672. font-weight: 600;
  4673. font-size: 24rpx;
  4674. color: #f85d22;
  4675. line-height: 40rpx;
  4676. }
  4677. }
  4678. }
  4679. .lottery-products-section {
  4680. width: 100%;
  4681. }
  4682. .lottery-indicators {
  4683. margin: 20rpx 0 50rpx;
  4684. display: flex;
  4685. gap: 6rpx;
  4686. .indicator-point {
  4687. width: 20rpx;
  4688. height: 8rpx;
  4689. background: rgba(255, 255, 255, 0.5);
  4690. border-radius: 4rpx;
  4691. &.selected {
  4692. background: #ffeb66;
  4693. }
  4694. }
  4695. }
  4696. .lottery-tip {
  4697. color: #fff;
  4698. font-size: 28rpx;
  4699. }
  4700. .lottery-action-button {
  4701. margin-top: 30rpx;
  4702. width: 520rpx;
  4703. height: 88rpx;
  4704. line-height: 88rpx;
  4705. background: linear-gradient(180deg, #fff4d6 0%, #ffeb66 100%);
  4706. box-shadow: 0rpx 10rpx 8rpx 4rpx rgba(246, 82, 25, 0.5);
  4707. border-radius: 44rpx;
  4708. font-weight: 500;
  4709. font-size: 36rpx;
  4710. color: #f4410b;
  4711. text-align: center;
  4712. }
  4713. }
  4714. }
  4715. }
  4716. // 积分弹窗
  4717. .integral-popup {
  4718. min-width: 400rpx;
  4719. max-width: 600rpx;
  4720. display: flex;
  4721. flex-direction: column;
  4722. align-items: center;
  4723. border-radius: 20rpx;
  4724. overflow: hidden;
  4725. .integral-header {
  4726. width: 100%;
  4727. position: relative;
  4728. .integral-title {
  4729. width: 100%;
  4730. font-weight: 600;
  4731. font-size: 40rpx;
  4732. color: #ffffff;
  4733. text-shadow: 0px 4rpx 8rpx rgba(255, 89, 2, 0.8);
  4734. position: absolute;
  4735. top: 50rpx;
  4736. text-align: center;
  4737. }
  4738. .integral-background-image {
  4739. width: 100%;
  4740. }
  4741. }
  4742. .integral-content {
  4743. padding: 20rpx;
  4744. .integral-message {
  4745. font-weight: 500;
  4746. font-size: 32rpx;
  4747. text-align: center;
  4748. }
  4749. .integral-confirm-button {
  4750. font-size: 32rpx;
  4751. margin-top: 20rpx;
  4752. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  4753. color: #fff;
  4754. text-align: center;
  4755. padding: 18rpx 60rpx;
  4756. border-radius: 10rpx;
  4757. font-weight: 500;
  4758. }
  4759. }
  4760. }
  4761. // 红包弹窗
  4762. .red-envelope-popup {
  4763. width: 504rpx;
  4764. position: relative;
  4765. text-align: center;
  4766. height: 610rpx;
  4767. display: flex;
  4768. align-items: center;
  4769. .red-envelope-close-button {
  4770. position: absolute;
  4771. right: 0;
  4772. top: -180rpx;
  4773. width: 64rpx;
  4774. height: 64rpx;
  4775. }
  4776. .red-envelope-background {
  4777. width: 100%;
  4778. height: 100%;
  4779. }
  4780. .red-envelope-content {
  4781. position: absolute;
  4782. top: 0;
  4783. left: 50%;
  4784. transform: translateX(-50%);
  4785. display: flex;
  4786. flex-direction: column;
  4787. align-items: center;
  4788. height: auto;
  4789. .red-envelope-header {
  4790. margin-top: 68rpx;
  4791. display: flex;
  4792. align-items: center;
  4793. .header-decoration-left,
  4794. .header-decoration-right {
  4795. width: 44rpx;
  4796. height: 20rpx;
  4797. }
  4798. .header-title {
  4799. margin: 0 12rpx;
  4800. font-size: 28rpx;
  4801. color: #FFF1BC;
  4802. }
  4803. }
  4804. .red-envelope-text {
  4805. font-weight: 600;
  4806. font-size: 80rpx;
  4807. color: #FFF1BC;
  4808. margin-top: 42rpx;
  4809. }
  4810. .red-envelope-open-text {
  4811. font-weight: 800;
  4812. font-size: 110rpx;
  4813. color: #F41420;
  4814. margin-top: 70rpx;
  4815. }
  4816. }
  4817. }
  4818. // 抽奖弹窗2
  4819. .lottery-popup-v2 {
  4820. width: 504rpx;
  4821. position: relative;
  4822. text-align: center;
  4823. height: 556rpx;
  4824. display: flex;
  4825. align-items: center;
  4826. .lottery-close-button-v2 {
  4827. position: absolute;
  4828. right: 0;
  4829. top: -180rpx;
  4830. width: 64rpx;
  4831. height: 64rpx;
  4832. z-index: 9;
  4833. }
  4834. .lottery-top-image {
  4835. position: absolute;
  4836. top: -214rpx;
  4837. width: 100%;
  4838. }
  4839. .lottery-background-v2 {
  4840. width: 100%;
  4841. height: 100%;
  4842. }
  4843. .lottery-content-v2 {
  4844. position: absolute;
  4845. top: 0;
  4846. left: 50%;
  4847. transform: translateX(-50%);
  4848. display: flex;
  4849. flex-direction: column;
  4850. align-items: center;
  4851. height: auto;
  4852. .lottery-header-v2 {
  4853. margin-top: 68rpx;
  4854. display: flex;
  4855. align-items: center;
  4856. .lottery-header-decoration-left,
  4857. .lottery-header-decoration-right {
  4858. width: 44rpx;
  4859. height: 20rpx;
  4860. }
  4861. .lottery-header-title {
  4862. margin: 0 12rpx;
  4863. font-size: 28rpx;
  4864. color: #FFF1BC;
  4865. margin-top: 22rpx;
  4866. }
  4867. }
  4868. .lottery-text-v2 {
  4869. font-weight: 600;
  4870. font-size: 80rpx;
  4871. color: #FFF1BC;
  4872. &:last-of-type {
  4873. margin-bottom: 56rpx;
  4874. }
  4875. }
  4876. .lottery-action-button-v2 {
  4877. width: 424rpx;
  4878. height: 96rpx;
  4879. line-height: 96rpx;
  4880. background: linear-gradient(180deg, #FBF1CA 0%, #FFD684 100%);
  4881. border-radius: 48rpx;
  4882. font-weight: 600;
  4883. font-size: 36rpx;
  4884. color: #F12E2C;
  4885. margin-bottom: 52rpx;
  4886. }
  4887. }
  4888. }
  4889. // 红包卡片弹窗
  4890. .red-card-popup {
  4891. width: 550rpx;
  4892. height: 636rpx;
  4893. position: relative;
  4894. .red-card-image {
  4895. position: absolute;
  4896. width: 100%;
  4897. height: 100%;
  4898. }
  4899. .red-card-content {
  4900. position: relative;
  4901. z-index: 5;
  4902. display: flex;
  4903. flex-direction: column;
  4904. align-items: center;
  4905. .red-card-message {
  4906. font-size: 36rpx;
  4907. color: #ff3a1e;
  4908. margin: 180rpx 0 90rpx;
  4909. }
  4910. .red-card-tip {
  4911. font-size: 28rpx;
  4912. color: #ffecc3;
  4913. margin: 80rpx 0 40rpx;
  4914. }
  4915. .red-card-confirm-button {
  4916. width: 392rpx;
  4917. height: 96rpx;
  4918. line-height: 96rpx;
  4919. background: linear-gradient(180deg, #fff4d5 0%, #ffe5b1 100%);
  4920. border-radius: 48rpx;
  4921. font-weight: 600;
  4922. font-size: 36rpx;
  4923. color: #c32008;
  4924. text-align: center;
  4925. }
  4926. }
  4927. }
  4928. // 消息弹窗
  4929. .message-popup {
  4930. display: flex;
  4931. flex-direction: column;
  4932. position: relative;
  4933. align-items: center;
  4934. padding: 40rpx 20rpx 0 20rpx;
  4935. width: 420rpx;
  4936. box-sizing: border-box;
  4937. .message-close-icon {
  4938. position: absolute;
  4939. z-index: 9;
  4940. top: 14rpx;
  4941. right: 14rpx;
  4942. width: 50rpx;
  4943. height: 50rpx;
  4944. }
  4945. .message-title {
  4946. font-weight: 500;
  4947. font-size: 42rpx;
  4948. margin: 40rpx 0;
  4949. }
  4950. .message-content {
  4951. margin-bottom: 60rpx;
  4952. }
  4953. .message-confirm-button {
  4954. width: 55%;
  4955. border-radius: 50rpx;
  4956. height: 100rpx;
  4957. line-height: 100rpx;
  4958. font-weight: 600;
  4959. font-size: 32rpx;
  4960. text-align: center;
  4961. background-color: #dfdfdf;
  4962. }
  4963. }
  4964. // 中奖弹窗
  4965. .prize-popup {
  4966. width: 504rpx;
  4967. padding: 40rpx 40rpx 30rpx;
  4968. box-sizing: border-box;
  4969. display: flex;
  4970. flex-direction: column;
  4971. border-radius: 20rpx;
  4972. align-items: center;
  4973. background: linear-gradient(180deg, #f7823f 0%, #ffd4be 27%, #ffffff 100%);
  4974. position: relative;
  4975. .prize-header-image {
  4976. width: 311rpx;
  4977. position: absolute;
  4978. top: -122rpx;
  4979. left: 50%;
  4980. transform: translateX(-50%);
  4981. }
  4982. .prize-title {
  4983. color: #c32008;
  4984. font-size: 34rpx;
  4985. font-weight: 600;
  4986. margin: 20rpx 0 40rpx;
  4987. }
  4988. .prize-info-section {
  4989. width: 100%;
  4990. display: flex;
  4991. justify-content: space-between;
  4992. align-items: center;
  4993. font-size: 28rpx;
  4994. margin: 10rpx 0;
  4995. .prize-level {
  4996. font-weight: 600;
  4997. }
  4998. }
  4999. .prize-tip {
  5000. font-size: 28rpx;
  5001. color: #414141;
  5002. margin: 40rpx 0;
  5003. }
  5004. .prize-action-button {
  5005. width: 200rpx;
  5006. height: 70rpx;
  5007. line-height: 70rpx;
  5008. background: linear-gradient(180deg, #ff7c30 0%, #ff3a1e 100%);
  5009. border-radius: 28rpx;
  5010. font-weight: 500;
  5011. font-size: 32rpx;
  5012. color: #ffffff;
  5013. text-align: center;
  5014. }
  5015. }
  5016. // 未中奖弹窗
  5017. .no-prize-popup {
  5018. width: 504rpx;
  5019. padding: 40rpx 40rpx 30rpx;
  5020. box-sizing: border-box;
  5021. display: flex;
  5022. flex-direction: column;
  5023. border-radius: 20rpx;
  5024. align-items: center;
  5025. position: relative;
  5026. .no-prize-image {
  5027. margin-top: 40rpx;
  5028. width: 300rpx;
  5029. height: 300rpx;
  5030. }
  5031. .no-prize-tip {
  5032. font-size: 36rpx;
  5033. color: #414141;
  5034. margin: 40rpx 0;
  5035. }
  5036. .no-prize-confirm-button {
  5037. width: 220rpx;
  5038. height: 80rpx;
  5039. line-height: 80rpx;
  5040. background: linear-gradient(180deg, #fdfbb8 0%, #b79243 100%);
  5041. border-radius: 28rpx;
  5042. font-weight: 500;
  5043. font-size: 32rpx;
  5044. color: #ffffff;
  5045. text-align: center;
  5046. }
  5047. }
  5048. // 中奖记录弹窗
  5049. .winning-record-popup {
  5050. position: relative;
  5051. height: 800rpx;
  5052. .winning-record-header-bg {
  5053. position: absolute;
  5054. top: -125rpx;
  5055. left: 50%;
  5056. width: 311rpx;
  5057. transform: translateX(-50%);
  5058. }
  5059. .winning-record-background {
  5060. width: 100%;
  5061. height: 100%;
  5062. }
  5063. .winning-record-content {
  5064. position: absolute;
  5065. top: 50rpx;
  5066. color: #fff;
  5067. width: 100%;
  5068. padding: 0 36rpx;
  5069. box-sizing: border-box;
  5070. .winning-record-title {
  5071. text-align: center;
  5072. font-size: 40rpx;
  5073. font-weight: 500;
  5074. margin-bottom: 40rpx;
  5075. }
  5076. .winning-record-header {
  5077. display: flex;
  5078. justify-content: space-between;
  5079. text-align: center;
  5080. font-size: 34rpx;
  5081. margin-bottom: 40rpx;
  5082. .header-column {
  5083. &.time-column {
  5084. width: 45%;
  5085. }
  5086. &.status-column {
  5087. width: 20%;
  5088. }
  5089. &.prize-column {
  5090. width: 35%;
  5091. }
  5092. }
  5093. }
  5094. .winning-record-list {
  5095. height: 500rpx;
  5096. .winning-record-item {
  5097. display: flex;
  5098. justify-content: space-between;
  5099. text-align: center;
  5100. font-size: 34rpx;
  5101. margin-bottom: 20rpx;
  5102. .record-time {
  5103. width: 45%;
  5104. font-size: 30rpx;
  5105. }
  5106. .record-status-button {
  5107. width: 20%;
  5108. background-color: #fff;
  5109. border-radius: 20rpx;
  5110. color: #f4410b;
  5111. }
  5112. .record-status {
  5113. width: 20%;
  5114. }
  5115. .record-prize {
  5116. width: 35%;
  5117. }
  5118. }
  5119. }
  5120. .no-winning-records {
  5121. font-size: 36rpx;
  5122. margin-top: 150rpx;
  5123. text-align: center;
  5124. }
  5125. }
  5126. }
  5127. // 观众列表弹窗
  5128. .viewers-list-popup {
  5129. position: relative;
  5130. height: 40vh;
  5131. padding: 40rpx 0rpx;
  5132. box-sizing: border-box;
  5133. display: flex;
  5134. flex-direction: column;
  5135. .viewers-list-title {
  5136. font-size: 32rpx;
  5137. text-align: center;
  5138. }
  5139. .viewers-scroll-list {
  5140. flex: 1;
  5141. margin-top: 50rpx;
  5142. overflow-y: auto;
  5143. padding: 0 40rpx;
  5144. .viewer-list-item {
  5145. display: flex;
  5146. align-items: center;
  5147. font-size: 28rpx;
  5148. margin: 20rpx 0;
  5149. .rank-number {
  5150. width: 50rpx;
  5151. margin-right: 10rpx;
  5152. font-weight: normal;
  5153. &.rank-1 {
  5154. color: #FF3B30;
  5155. font-weight: bold;
  5156. }
  5157. &.rank-2 {
  5158. color: #FF9500;
  5159. font-weight: bold;
  5160. }
  5161. &.rank-3 {
  5162. color: #FFCC00;
  5163. font-weight: bold;
  5164. }
  5165. &:not(.rank-1):not(.rank-2):not(.rank-3) {
  5166. color: #8E8E93;
  5167. }
  5168. }
  5169. .viewer-avatar-placeholder {
  5170. width: 72rpx;
  5171. height: 72rpx;
  5172. border-radius: 50%;
  5173. display: flex;
  5174. align-items: center;
  5175. justify-content: center;
  5176. background-color: #8978e2;
  5177. .avatar-initial {
  5178. color: #ffffff;
  5179. font-size: 24rpx;
  5180. }
  5181. }
  5182. .viewer-name {
  5183. margin-left: 16rpx;
  5184. font-size: 30rpx;
  5185. }
  5186. }
  5187. }
  5188. }
  5189. // 更多操作弹窗
  5190. .more-actions-popup {
  5191. border-radius: 20rpx 0 0 20rpx;
  5192. padding: 70rpx 30rpx;
  5193. display: flex;
  5194. justify-content: space-between;
  5195. .more-action-item {
  5196. display: flex;
  5197. flex-direction: column;
  5198. align-items: center;
  5199. .action-icon {
  5200. width: 48rpx;
  5201. height: 48rpx;
  5202. }
  5203. .action-label {
  5204. color: #1e1e1e;
  5205. text-align: center;
  5206. margin-top: 10rpx;
  5207. }
  5208. }
  5209. }
  5210. // 商品弹窗
  5211. .shopping-popup {
  5212. padding: 22rpx 16rpx;
  5213. .shopping-header {
  5214. display: flex;
  5215. justify-content: space-between;
  5216. align-items: center;
  5217. padding: 0 16rpx 22rpx;
  5218. .search-input-container {
  5219. width: 414rpx;
  5220. height: 76rpx;
  5221. background: #ffffff;
  5222. border-radius: 36rpx;
  5223. margin-left: 20rpx;
  5224. padding: 0 32rpx;
  5225. box-sizing: border-box;
  5226. font-size: 24rpx;
  5227. margin-right: 24rpx;
  5228. display: flex;
  5229. align-items: center;
  5230. .search-icon {
  5231. width: 24rpx;
  5232. margin-right: 16rpx;
  5233. }
  5234. }
  5235. .shopping-action-button {
  5236. display: flex;
  5237. flex-direction: column;
  5238. align-items: center;
  5239. font-size: 20rpx;
  5240. color: #222222;
  5241. .action-button-icon {
  5242. width: 48rpx;
  5243. height: 48rpx;
  5244. }
  5245. .action-button-label {
  5246. text-align: center;
  5247. }
  5248. }
  5249. }
  5250. .products-list {
  5251. height: 30vh;
  5252. overflow: hidden;
  5253. .product-item {
  5254. display: flex;
  5255. align-items: center;
  5256. padding: 20rpx 16rpx;
  5257. background: #ffffff;
  5258. border-radius: 16rpx;
  5259. margin-bottom: 16rpx;
  5260. .product-image-container {
  5261. width: 200rpx;
  5262. height: 200rpx;
  5263. border-radius: 16rpx;
  5264. overflow: hidden;
  5265. position: relative;
  5266. margin-right: 24rpx;
  5267. .product-image {
  5268. width: 100%;
  5269. height: 100%;
  5270. }
  5271. .product-index-label {
  5272. position: absolute;
  5273. top: 0;
  5274. width: 64rpx;
  5275. height: 40rpx;
  5276. background: var(--normal-bg);
  5277. border-radius: 16rpx 0rpx 16rpx 0rpx;
  5278. text-align: center;
  5279. font-weight: 500;
  5280. font-size: 28rpx;
  5281. color: var(--text-color);
  5282. }
  5283. }
  5284. .product-info {
  5285. flex: 1;
  5286. .product-name {
  5287. font-weight: 500;
  5288. font-size: 30rpx;
  5289. color: #000000;
  5290. margin-bottom: 10rpx;
  5291. }
  5292. .product-sales {
  5293. font-size: 22rpx;
  5294. color: #e69a22;
  5295. height: 56rpx;
  5296. }
  5297. .product-action-section {
  5298. display: flex;
  5299. justify-content: space-between;
  5300. align-items: center;
  5301. .product-price {
  5302. color: #ff5c03;
  5303. font-size: 22rpx;
  5304. font-weight: 500;
  5305. .price-symbol {
  5306. font-size: 20rpx;
  5307. font-weight: 600;
  5308. }
  5309. .price-integer {
  5310. font-size: 36rpx;
  5311. font-weight: bold;
  5312. }
  5313. }
  5314. .product-action-buttons {
  5315. display: flex;
  5316. align-items: center;
  5317. text-align: center;
  5318. line-height: 56rpx;
  5319. .collect-button {
  5320. width: 72rpx;
  5321. height: 100%;
  5322. background: #f5f7fa;
  5323. border-radius: 8rpx 0rpx 0rpx 8rpx;
  5324. .collect-icon {
  5325. width: 36rpx;
  5326. height: 36rpx;
  5327. vertical-align: middle;
  5328. }
  5329. }
  5330. .buy-button {
  5331. width: 152rpx;
  5332. background: linear-gradient(270deg, #ff5c03 0%, #ffac64 100%);
  5333. border-radius: 0rpx 8rpx 8rpx 0rpx;
  5334. font-weight: 500;
  5335. font-size: 30rpx;
  5336. color: #ffffff;
  5337. &.disabled {
  5338. background: #cccccc;
  5339. }
  5340. }
  5341. }
  5342. }
  5343. }
  5344. }
  5345. }
  5346. }
  5347. // 优惠券弹窗
  5348. .coupon-popup {
  5349. position: fixed;
  5350. bottom: 140rpx;
  5351. right: 100rpx;
  5352. z-index: 5;
  5353. border-radius: 20rpx;
  5354. width: 320rpx;
  5355. .coupon-container {
  5356. width: 100%;
  5357. position: relative;
  5358. .coupon-background {
  5359. height: 452rpx;
  5360. width: 100%;
  5361. }
  5362. .coupon-header {
  5363. position: absolute;
  5364. height: 120rpx;
  5365. top: -120rpx;
  5366. left: 0;
  5367. width: 100%;
  5368. z-index: 6;
  5369. }
  5370. .coupon-close-button {
  5371. position: absolute;
  5372. right: 10rpx;
  5373. top: 10rpx;
  5374. width: 40rpx;
  5375. height: 40rpx;
  5376. z-index: 99;
  5377. }
  5378. .coupon-content {
  5379. width: 100%;
  5380. position: absolute;
  5381. top: 20rpx;
  5382. display: flex;
  5383. flex-direction: column;
  5384. align-items: center;
  5385. color: #fff;
  5386. .coupon-name {
  5387. font-weight: 500;
  5388. font-size: 30rpx;
  5389. margin: 16rpx 0 12rpx;
  5390. }
  5391. .coupon-price {
  5392. font-size: 40rpx;
  5393. .coupon-price-integer {
  5394. font-size: 56rpx;
  5395. font-weight: 600;
  5396. }
  5397. }
  5398. .coupon-condition,
  5399. .coupon-description,
  5400. .coupon-validity {
  5401. font-weight: 500;
  5402. font-size: 30rpx;
  5403. margin: 5rpx 0;
  5404. }
  5405. .coupon-description {
  5406. margin-top: 26rpx;
  5407. }
  5408. .coupon-get-button {
  5409. background: linear-gradient(270deg, #fffce1 0%, #ffeaaf 100%);
  5410. color: #ff0004;
  5411. text-align: center;
  5412. padding: 16rpx 0;
  5413. border-radius: 40rpx;
  5414. font-weight: 500;
  5415. font-size: 30rpx;
  5416. width: 70%;
  5417. margin-top: 26rpx;
  5418. }
  5419. }
  5420. }
  5421. }
  5422. }
  5423. }
  5424. </style>