living.vue 219 KB

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