living.vue 166 KB

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