living.vue 223 KB

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