living.vue 226 KB

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