living.vue 197 KB

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