living.vue 193 KB

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