living.vue 192 KB

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