living-old.vue 217 KB

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