living.vue 217 KB

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