living.vue 179 KB

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