living.vue 166 KB

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