living.vue 204 KB

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