living.vue 199 KB

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