living.vue 171 KB

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