living.vue 189 KB

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