living.vue 181 KB

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