living.vue 200 KB

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