living.vue 198 KB

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