living.vue 182 KB

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