living.vue 222 KB

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