living.vue 170 KB

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