living.vue 237 KB

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