living.vue 207 KB

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