living.vue 170 KB

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