living.vue 237 KB

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