living.vue 182 KB

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