living.vue 203 KB

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