living.vue 201 KB

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