living.vue 187 KB

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