learn.vue 198 KB

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