living.vue 236 KB

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