living.vue 217 KB

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