living.vue 195 KB

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