living.vue 193 KB

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