living.vue 203 KB

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