living.vue 185 KB

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