living.vue 189 KB

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