living.vue 170 KB

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