living.vue 195 KB

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