living.vue 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556
  1. <template>
  2. <view class="swiper-wrapper">
  3. <view class="container">
  4. <view class="content">
  5. <view style="position: fixed;top: 0;z-index: 5;" class="content-top">
  6. <view class="x-f">
  7. <image v-if="!scene" @click="goBack" class="w60 h64 mr26" src="/static/images/return3.png" />
  8. <view class="align-center"
  9. style="padding: 6rpx 8rpx;height: 64rpx;background: rgba(0,0,0,0.5);border-radius: 32rpx;">
  10. <u-avatar :src="liveItem.liveImgUrl||'/static/images/avatar.png'" :size="32"></u-avatar>
  11. <view class="colorf ml10 mr6">
  12. <view>{{liveItem.liveName?truncateString(liveItem.liveName,8):"未命名"}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view v-if="Array.isArray(filteredViewers)" class=" align-center" @click="toggleViewerList"
  17. style="margin-top: 120rpx;">
  18. <view v-for="(item,viewerIndex) in filteredViewers" :key="viewerIndex">
  19. <image v-if="item.avatar" class="w52 h52 mr4" style="border-radius: 26rpx;"
  20. :src="item.avatar" />
  21. <view v-else class="w52 h52 mr4"
  22. :style="{backgroundColor: getUserRandomColor(item.userId), borderRadius:'50%'}">
  23. <text class="text-white text-xs">{{getNicknameInitial(item.nickName)}}</text>
  24. </view>
  25. </view>
  26. <view class="sum">{{liveUserTotal||0}}</view>
  27. </view>
  28. </view>
  29. <!-- 右边的side -->
  30. <view class="side-group">
  31. <view class="side-item" @click="onLike">
  32. <LikeButton :initialCount="100" :heartsPerClick="5" @like="onLike" />
  33. <view>{{liveViewData && liveViewData.like||0}}</view>
  34. </view>
  35. <view class="side-item">
  36. <button open-type="share" class="button">
  37. <image class="image" src="/static/images/weixin.png" mode="widthFix" />
  38. </button>
  39. <view>分享</view>
  40. </view>
  41. </view>
  42. <view class="activity-box">
  43. <view class="item-box" @click="onRed()" v-if="isShowRed">
  44. <view class="x-f">
  45. <view class="tip">领红包</view>
  46. <view class="item">
  47. <image class="w70 img" src="/static/images/redbag.png" mode="widthFix" />
  48. </view>
  49. </view>
  50. </view>
  51. <view class="item-box" @click="onLottery()" v-if="isShowLottery&&countdown">
  52. <view class="x-f">
  53. <view class="tip">抽奖</view>
  54. <view class="item">
  55. <image class="w60" src="/static/images/lottery.png" mode="widthFix" />
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="shop-prompt f30 x-f"
  61. v-if="showPurchasePrompt&&orderUser&&orderUser.count&&liveItem.status==2">
  62. <image class="w32 h32 mr8" src="/static/images/shopping.png" />
  63. <text>{{ orderUser.count || 0 }}人正在去购买</text>
  64. </view>
  65. <view class="videolist" v-if="liveItem.status==2">
  66. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  67. <!-- 直播 -->
  68. <live-player v-if="liveItem.livingUrl && liveItem.liveType == 1" :id="'myLivePlayer_' + liveId"
  69. :src="liveItem.livingUrl" autoplay mode="live" object-fit="contain" :muted="false"
  70. orientation="vertical" :enable-play-gesture="false" min-cache="1" max-cache="3"
  71. @statechange="onLiveStateChange($event, liveItem)" @error="onLiveError($event, liveItem)"
  72. class="item"></live-player>
  73. <!-- 录播 -->
  74. <video v-if="liveItem.videoUrl&&liveItem.liveType==2" :id="`myVideo_${liveId}`" :autoplay="true"
  75. class="item" :src="liveItem.videoUrl" :controls="false" object-fit="contain"
  76. :custom-cache="false" :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false"
  77. :show-center-play-btn="false" :http-cache="false" loop @error="videoError"
  78. @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause"
  79. @play="onVideoPlay" @waiting="onVideoWaiting" :enable-play-gesture="false"
  80. @dblclick="preventDoubleClick">
  81. </video>
  82. <view v-if="liveItem.videoUrl&&liveItem.liveType==2" class="time">{{liveItem.totalTime}}
  83. </view>
  84. </view>
  85. </view>
  86. <view class="videolist" v-if="liveItem.status==3">
  87. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  88. <view class="end">直播已结束</view>
  89. </view>
  90. </view>
  91. <view class="videolist" v-if="liveItem.status==4">
  92. <view class="video" :class="liveItem.showType == 1 ? 'video_row' : ''">
  93. <!-- 直播回放 -->
  94. <video v-if="liveItem.videoUrl&&liveItem.liveType==3" :id="`myVideo_${liveId}`" class="item"
  95. :src="liveItem.videoUrl" :autoplay="true" :controls="true" object-fit="contain"
  96. :custom-cache="false" :enable-progress-gesture="liveItem.isSpeedAllowed"
  97. vslide-gesture-in-fullscreen="true" :show-center-play-btn="true" :http-cache="false" loop
  98. @error="videoError" @timeupdate="onVideoTimeUpdate" @loadedmetadata="onVideoMetaLoaded"
  99. @pause="onVideoPause" @play="onVideoPlay" :enable-play-gesture="true"
  100. @waiting="onVideoWaiting">
  101. </video>
  102. <view v-if="liveItem.videoUrl&&liveItem.liveType==3" class="lable">直播回放</view>
  103. </view>
  104. </view>
  105. <view class="trailer-box" v-if="liveItem.status==1">
  106. <video v-if="liveItem.previewUrl" :id="`myVideo_${liveId}`" class="item" :src="liveItem.previewUrl"
  107. :autoplay="true" :loop="false" :controls="false" object-fit="contain" :custom-cache="false"
  108. :enable-progress-gesture="false" vslide-gesture-in-fullscreen="false"
  109. :show-center-play-btn="false" :http-cache="false" @error="videoError"
  110. @loadedmetadata="onVideoMetaLoaded" @pause="onVideoPause" @play="onVideoPlay"
  111. :disable-progress="true" :enable-play-gesture="true" @waiting="onVideoWaiting">
  112. </video>
  113. <image v-if="liveItem.status==1&&!liveItem.previewUrl" class="img" src="/static/images/no_live.png">
  114. </image>
  115. <view class="countdown-item mt30 mb30" v-if="liveItem.status==1&&liveCountdown">
  116. 开播倒计时
  117. <view class="x-f">
  118. <view class="white">
  119. {{liveCountdown.hours||"00"}}
  120. </view>
  121. <view class="white">
  122. {{ liveCountdown.minutes||"00"}}
  123. </view>
  124. <view class="white">
  125. {{ liveCountdown.seconds||"00" }}
  126. </view>
  127. </view>
  128. </view>
  129. <view class="name"> {{liveItem.liveName}}</view>
  130. <view class="title" v-if="liveCountdown">暂未开播</view>
  131. <view class="button" v-if="!isAgreement" @click="handleAgreement">预约直播</view>
  132. <view class="button ash" v-if="isAgreement">已预约</view>
  133. <view class="title" v-if="!liveCountdown">主播还在来的路上</view>
  134. </view>
  135. <view class="trailer-box" v-if="!liveItem">
  136. <image class="img" src="/static/images/no_live.png">
  137. </image>
  138. <view class="title">暂无直播</view>
  139. </view>
  140. <!-- 底部聊天区域 -->
  141. <view :style="{position: 'fixed',width: '100%',bottom: chatHeight + 'rpx',zIndex:999}">
  142. <view class="mt20" :style="{ height: chatHeight ? '64rpx' : '30vh' }">
  143. <scroll-view v-if="Array.isArray(talklist)" enable-flex scroll-y="true"
  144. class="pl20 scrolly flex-1 column" style="width: calc(100% - 20rpx); height: 100%;"
  145. :scroll-top="scrollTop" ref="scrollView">
  146. <!-- 聊天消息列表 -->
  147. <view class="list justify-start" v-for="(item,talkIndex) in (talklist||[])" :key="talkIndex"
  148. :id="`list_${talkIndex}`" v-show="item.cmd!='red'&&item.cmd!='out'&&item.cmd!='entry'">
  149. <view class="talk-list justify-start">
  150. <view class="fs30" style="max-width: 100%;">
  151. <text style="color: #FFDA73;">{{item.nickName||"未命名"}}:</text>
  152. <text class='colorf'>{{item.msg}}</text>
  153. </view>
  154. </view>
  155. </view>
  156. <!-- 欢迎消息 -->
  157. <view v-if="showWelcomeMessage" class="welcome-message" style="max-width: 100%;">
  158. <view class="list justify-start" v-show="inAndOut.cmd=='entry'||inAndOut.cmd=='out'">
  159. <view class="talk-list justify-start">
  160. <view class="fs30">
  161. <text style="color: #ff89d6;">{{inAndOut.nickName||"未命名"}} </text>
  162. <text class='colorf'>{{inAndOut.msg}}直播间</text>
  163. </view>
  164. </view>
  165. </view>
  166. </view>
  167. </scroll-view>
  168. </view>
  169. <!-- 底部输入框和操作按钮 -->
  170. <view class="justify-between p24">
  171. <view class="x-f justify-between"
  172. :style="{background:'#393939' ,padding: '10rpx 14rpx 10rpx 32rpx',boxSizing: 'border-box',borderRadius: '36rpx',width: isFocus ? '100%' : '580rpx'}">
  173. <input :placeholder="placeholderText" v-model="value" placeholder-style="color:#e7e7e7;"
  174. placeholder-class="placeholder-style" class="ml20 input-native" @focus="inputFocus"
  175. @blur="inputBlur"
  176. style="border: none; font-size: 32rpx; color: #ffffff; background: transparent; width: 70%;"
  177. cursor-spacing="100" :adjust-position="false" />
  178. <view class="send" @click="sendMsg()">发送</view>
  179. </view>
  180. <view class="justify-between mr15 align-center" v-if="!isFocus">
  181. <view class="icon-bg ml20" @tap="openCart()">
  182. <image src="/static/images/shopping.png" class="w58 h58" />
  183. </view>
  184. </view>
  185. </view>
  186. </view>
  187. </view>
  188. <view class="goods" v-if="isShowGoods">
  189. <view class="top">
  190. <view class="left">
  191. <image class="w30 h30 mr8" src="/static/images/signal.png" />讲解中
  192. </view>
  193. <image @click="isShowGoods=false" class="w40 h40 " src="/static/images/del_black.png" />
  194. </view>
  195. <image class="photo" :src="goodsCard.imgUrl" />
  196. <view class="item">
  197. <view class="price"><text class="red">¥{{goodsCard.price}} </text><text
  198. class="del">¥{{goodsCard.otPrice}}</text></view>
  199. <view class="title oneline-hide">{{goodsCard.productName}}</view>
  200. <view class="button" @click="goShop(goodsCard.productId,goodsCard.goodsId)">
  201. 立即抢购
  202. </view>
  203. </view>
  204. </view>
  205. <u-popup :show="isShowLotteryPop&&countdown" round='40rpx'>
  206. <view class="prize-box" style="border-radius: 40rpx;height: fit-content;">
  207. <image class="nav-img " src="/static/images/red_head.png" mode="widthFix" />
  208. <image class="bg-img " src="/static/images/red_bg.png" />
  209. <view class="prize-content">
  210. <view class=" mr20">
  211. <u-icon class="x-end" name="close" color="#fff" size="20"
  212. @click="isShowLotteryPop=false"></u-icon>
  213. </view>
  214. <view class="column align-center ">
  215. <image class="w446 h80" src="/static/images/red_title.png" />
  216. <view class="fs24 colorf x-f mt30 mb30">
  217. 开奖倒计时
  218. <view class="x-f">
  219. <view class="white-item">
  220. {{countdown.hours||"00"}}
  221. </view>
  222. <view class="white-item">
  223. {{ countdown.minutes||"00" }}
  224. </view>
  225. <view class="white-item">
  226. {{ countdown.seconds||"00" }}
  227. </view>
  228. </view>
  229. </view>
  230. <view class="item-group">
  231. <ThreeItemSwiper :products="lotteryProducts"></ThreeItemSwiper>
  232. </view>
  233. <view class="point-group" v-for="(item,index) in lotteryProducts" :key="index">
  234. </view>
  235. <view class="colorf fs28">
  236. 观看直播参与抽奖
  237. </view>
  238. <view class="button" @click="onClaim">参与抽奖</view>
  239. </view>
  240. </view>
  241. </view>
  242. </u-popup>
  243. <u-popup :show="!!integral.status" round='20rpx' mode="center" bgColor='#ffffff' zIndex='10076'>
  244. <view class="integral-box">
  245. <view class="top">
  246. <view class="title">观看视频领芳华币</view>
  247. <image class="photo" src="/static/images/integral_bg.png" mode="widthFix" />
  248. </view>
  249. <view class="item">
  250. <view class="title ">{{integral.msg}}</view>
  251. <view class="button" @click="integral.status=false">确认</view>
  252. </view>
  253. </view>
  254. </u-popup>
  255. <u-popup :show="isShowRedCard" round='20rpx' mode="center" bgColor='transparent' zIndex='10076'>
  256. <view class="red-card">
  257. <image class="img" src="/static/images/red_card.png" />
  258. <view class="red-content">
  259. <view class="title">{{redCard.msg}}</view>
  260. <view class="txt ">直播惊喜芳华币</view>
  261. <view class="button" @click="isShowRedCard=false">确认</view>
  262. </view>
  263. </view>
  264. </u-popup>
  265. <!-- 中奖和未中奖 -->
  266. <u-popup :show="isShowPrize" round='20rpx' mode="center" bgColor='#fff' zIndex='10076'>
  267. <view class="prize-card" v-if="isCurrentUserWon">
  268. <image class="nav-img " src="/static/images/red_head.png" mode="widthFix" />
  269. <view class="title">{{prizeInfo.length}}位幸运观众</view>
  270. <view class="prize-content" v-for="(item,index) in (prizeInfo||[])" :key="index">
  271. <view>{{item.userName}}</view>
  272. <view>{{item.userId}}</view>
  273. <view class="txt">{{item.prizeLevel}}等奖</view>
  274. </view>
  275. <view class="tip">请截图联系客服领取奖品</view>
  276. <view class="button" @click="isShowPrize=false">确认</view>
  277. </view>
  278. <view class="no-prize-card" v-else>
  279. <image class="img" src="/static/images/no-prize.png" mode="widthFix" />
  280. <view class="tip">很遗憾 您未中奖</view>
  281. <view class="button" @click="isShowPrize=false">确认</view>
  282. </view>
  283. </u-popup>
  284. <!-- 观众列表弹窗 -->
  285. <u-popup :show="showadd" @close="close" @open="openViews" round='20rpx' bgColor='#ffffff' zIndex='10077'>
  286. <view class="view-box">
  287. <view class="fs32" style="text-align: center;">在线观众</view>
  288. <scroll-view v-if="Array.isArray(liveViewers)" scroll-y class="scroll-content"
  289. :style="{height: scrollHeight + 'px'}" @scrolltolower="handleScrollToLower">
  290. <view class="fs28 x-f mb20 mt20" v-for="(item,index) in (liveViewers||[])" :key="index">
  291. <view
  292. :style="{color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',fontWeight: index < 3 ? 'bold' : 'normal',width: '50rpx'}"
  293. class="mr10">{{index+1}}</view>
  294. <u-avatar v-if="item.avatar" :src="item.avatar" :size="36"></u-avatar>
  295. <view v-else class="w72 h72"
  296. :style="{backgroundColor: getUserRandomColor(item.userId), borderRadius:'50%'}">
  297. <text class="text-white text-sm">{{getNicknameInitial(item.nickName)}}</text>
  298. </view>
  299. <text class="ml16 f30">{{item.nickName||"未命名"}}</text>
  300. </view>
  301. </scroll-view>
  302. </view>
  303. </u-popup>
  304. <!-- 更多弹窗 -->
  305. <u-popup :show="isMore" @close="closeMore" round='20rpx' bgColor='#f3f5f9' zIndex='10076'>
  306. <view class="more-block">
  307. <view class="item" @click="isMore=false">
  308. <image class="w48 h48" src="/static/images/order.png" />
  309. <view style="text-align: center;">兑换好礼</view>
  310. </view>
  311. <view class=" item"
  312. @click="navgetTo('/pages_shopping/live/storeOrderRefundList?liveId='+liveId),isMore=false">
  313. <image class="w48 h48" src="/static/images/after_sales.png" />
  314. <view style="text-align: center;">售后订单</view>
  315. </view>
  316. <view class=" item" @click="isMore=false,goMiniProgram">
  317. <image class="w48 h48" src="/static/images/points.png" />
  318. <view style="text-align: center;">芳华币</view>
  319. </view>
  320. <view class=" item" @click="isMore=false">
  321. <image class="w48 h48" src="/static/images/health_sel.png" />
  322. <view style="text-align: center;">中奖记录</view>
  323. </view>
  324. </view>
  325. </u-popup>
  326. <!-- 商品弹窗 -->
  327. <u-popup :show="shopping" @close="closeShop" round='20rpx' bgColor='#f3f5f9' zIndex='10075'>
  328. <view class="shoppop">
  329. <view class="shoppop-top">
  330. <view class="search-input x-f">
  331. <image class="w24 mr16" src="/static/images/search.png" mode="widthFix" />
  332. <input placeholder="请搜索商品" v-model="inputInfo" @input="handleSearchInput" />
  333. </view>
  334. <view class=" search-top" @click="navgetTo('/pages_shopping/live/order')">
  335. <image class="w48 h48" src="/static/images/carts.png" />
  336. <view style="text-align: center;">订单</view>
  337. </view>
  338. <view class="search-top" @click="isMore=true,shopping=false">
  339. <image class="w48 h48" src="/static/images/search2.png" />
  340. <view style="text-align: center;">更多</view>
  341. </view>
  342. </view>
  343. <!-- <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  344. <view class="list-item" v-for="(item,index) in products" :key="index">
  345. <view class="goods-img">
  346. <image class="img" :src="item.imgUrl" mode="widthFix" />
  347. <view class="goods-label">{{index+1}}</view>
  348. </view>
  349. <view class="goods-right">
  350. <view class="goods-title">{{item.productName}}</view>
  351. <view class="goods-people">{{item.sales}} 人已购</view>
  352. <view class="goods-shop">
  353. <text class="nummber"><text style="font-size: 20rpx;font-weight: 600;">¥</text><text
  354. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}</text>
  355. <view class="btn-group x-f">
  356. <view class="collect-btn">
  357. <image v-if="item.isFavorite" @click="onGoodsCollect(item)" class="w36 h36"
  358. style="vertical-align: middle;"
  359. src="/static/images/collect_select.png" />
  360. <image v-else @click="onGoodsCollect(item)" class="w36 h36"
  361. style="vertical-align: middle;" src="/static/images/collect.png" />
  362. </view>
  363. <view v-if="item.status==1" class="shop-btn"
  364. @click="goShop(item.productId,item.goodsId)">去购买 </view>
  365. <view v-else-if="item.status==0" class="shop-btn">
  366. 已下架</view>
  367. </view>
  368. </view>
  369. </view>
  370. </view>
  371. </scroll-view> -->
  372. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  373. <!-- 骨架屏 -->
  374. <view v-if="loadingProducts && products.length === 0" class="skeleton-list">
  375. <view v-for="n in 6" :key="n" class="skeleton-item">
  376. <view class="skeleton-img"></view>
  377. <view class="skeleton-content">
  378. <view class="skeleton-line short"></view>
  379. <view class="skeleton-line medium"></view>
  380. <view class="skeleton-line long"></view>
  381. </view>
  382. </view>
  383. </view>
  384. <!-- 实际商品列表 -->
  385. <template v-else>
  386. <view v-for="(item,index) in products" :key="index" class="list-item">
  387. <view class="goods-img">
  388. <image class="img" :src="item.imgUrl" mode="widthFix" />
  389. <view class="goods-label">{{index+1}}</view>
  390. </view>
  391. <view class="goods-right">
  392. <view class="goods-title">{{item.productName}}</view>
  393. <view class="goods-people">{{item.sales}} 人已购</view>
  394. <view class="goods-shop">
  395. <text class="nummber"><text
  396. style="font-size: 20rpx;font-weight: 600;">¥</text><text
  397. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}</text>
  398. <view class="btn-group x-f">
  399. <view class="collect-btn">
  400. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  401. class="w36 h36" style="vertical-align: middle;"
  402. src="/static/images/collect_select.png" />
  403. <image v-else @click="onGoodsCollect(item)" class="w36 h36"
  404. style="vertical-align: middle;" src="/static/images/collect.png" />
  405. </view>
  406. <view v-if="item.status==1" class="shop-btn"
  407. @click="goShop(item.productId,item.goodsId)">去购买 </view>
  408. <view v-else-if="item.status==0" class="shop-btn">
  409. 已下架</view>
  410. </view>
  411. </view>
  412. </view>
  413. </view>
  414. </template>
  415. </scroll-view>
  416. </view>
  417. </u-popup>
  418. <!-- 优惠券弹窗 -->
  419. <view class="coupon-pop" v-if="isShowCoupon">
  420. <view class="coupon-block">
  421. <image class="bg" src="/static/images/coupon_bg.png" />
  422. <image class="nav" src="/static/images/coupon_top.png" />
  423. <image @click="isShowCoupon=false" class="w40 h40 close" style="z-index: 99;"
  424. src="/static/images/close1.png" />
  425. <view class="item">
  426. <view class="title">{{couponInfo.couponName}}</view>
  427. <view class="price">¥<text class="bold">{{couponInfo.couponPrice}}</text></view>
  428. <view class="txt">满{{couponInfo.useMinPrice}}元可用</view>
  429. <view class="txt" style="margin-top: 26rpx;">指定商品可用</view>
  430. <view class="txt">自领取起{{couponInfo.couponTime}}天内有效</view>
  431. <view class="button" @click="onCoupon()">
  432. 立即领券
  433. </view>
  434. </view>
  435. </view>
  436. </view>
  437. </view>
  438. </view>
  439. </template>
  440. <script>
  441. import LikeButton from '@/pages_course/components/like.vue'
  442. import ThreeItemSwiper from '@/pages_course/components/ThreeItemSwiper.vue'
  443. import CryptoJS from 'crypto-js'
  444. import {
  445. coupon, //领取优惠券
  446. liveLottery, // 抽奖查询
  447. claim, //抽奖
  448. liveRed, // 点击领红包
  449. liveDataLike, // 点赞
  450. collectStore, // 店铺收藏/取消收藏
  451. collectGoods, // 商品收藏/取消收藏
  452. watchUserList, //获取直播间用户(展示在线用户)
  453. liveMsg, //获取最近聊天记录
  454. // 小黄车
  455. liveStore, //店铺展示,
  456. liveOrderUser, //正在购买
  457. getLiveInfo, //获取直播间信息接口
  458. getLiveViewData, //直播间点赞、关注、在线人数数据
  459. currentActivities, //红包 卡片 抽奖
  460. getlive,
  461. subNotifyLive,
  462. internetTraffic, // 流量(缓冲百分比),
  463. liveInternetTraffic // 直播流量(缓冲百分比),
  464. } from '@/api/living.js'
  465. import {
  466. getUserInfo
  467. } from '@/api/user'
  468. import {
  469. generateRandomString
  470. } from "@/utils/common.js"
  471. import dayjs from 'dayjs';
  472. import {
  473. nextTick
  474. } from "vue"
  475. var isSocketOpen = false;
  476. var socket = null;
  477. export default {
  478. components: {
  479. ThreeItemSwiper,
  480. LikeButton
  481. },
  482. data() {
  483. return {
  484. isMore: false,
  485. value: '',
  486. totalTraffic: 0, // 总流量(字节)
  487. bitrate: 1600, // 默认码率 0.16Mbps
  488. trafficTimer: null,
  489. stayTime: 0,
  490. startTime: 0,
  491. scrollTop: 0,
  492. isOnload: false,
  493. isConnecting: false, // 是否正在连接中
  494. previousToken: null,
  495. hasInitialized: false,
  496. liveViewersData: [],
  497. liveUserCalled: false, //调用过watchUserList没
  498. liveViewDataTimer: null,
  499. userRandomColors: {}, // 缓存用户ID -> 随机色的映射
  500. heartBeatRetryCount: 0, // 心跳发送重试次数(避免一次失败就重连)
  501. maxHeartBeatRetries: 2, // 心跳最大重试次数
  502. pingTimeout: 20000, // 心跳超时时间从10s延长到20s(应对网络波动)
  503. shownEntryUsers: new Set(), // 存储已显示过「进入提示」的用户ID
  504. templateId: 'fxYJu817lxHNKXl0hJypb-y-lLm8CNmGbcwpQmasCVg',
  505. isAgreement: false,
  506. socket: null, // WebSocket 实例
  507. isSocketOpen: false, // 连接是否已打开
  508. heartBeatTimer: null, // 心跳定时器
  509. heartBeatInterval: 15000, // 心跳发送间隔(15秒)
  510. reconnectTimer: null, // 重连定时器
  511. reconnectCount: 0, // 当前重连次数
  512. maxReconnectAttempts: 3, // 最大重连次数
  513. isManualClose: false, // 是否手动关闭(用于区分主动关闭和异常断开)
  514. pingTimeoutTimer: null, // 心跳超时定时器
  515. wsNewUrl: 'wss://api.fhhx.runtzh.com/ws/app/webSocket',
  516. // wsNewUrl: 'ws://192.168.10.166:7114/ws/app/webSocket',
  517. qrFrom: null,
  518. scene: '',
  519. liveCountdown: {}, //直播倒计时
  520. countdown: {}, //抽奖倒计时
  521. liveViewData: {},
  522. chatHeight: 0,
  523. keyboardHeight: 0,
  524. videoCurrentTime: 0, // 当前视频播放时间
  525. videoProgressKey: '', // 存储进度的key
  526. inAndOut: {},
  527. isShowPrize: false,
  528. isShowCoupon: false,
  529. prizeInfo: [],
  530. countDownKey: 0,
  531. lotteryProducts: [],
  532. lotteryList: [],
  533. talklist: [],
  534. isShowLotteryPop: false,
  535. liveItem: {},
  536. isSending: false,
  537. welcomeTimer: null,
  538. redTimer: null,
  539. liveStartTimer: null,
  540. lotteryTimer: null,
  541. isShowLottery: false,
  542. isShowRedCard: false,
  543. redCard: null, //点击红包出现弹窗
  544. integral: {},
  545. lotteryInfo: {},
  546. goodsCard: {},
  547. couponInfo: {},
  548. redInfo: {},
  549. storeId: null,
  550. isFocus: false,
  551. shopping: false,
  552. inputInfo: '',
  553. showWelcomeMessage: false,
  554. scrollIntoView: '',
  555. isShowGoods: false,
  556. isShowRed: false,
  557. lastClickTime: 0,
  558. clickDelay: 300, // 300ms内只响应一次点击
  559. videoRetryCounts: {}, // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  560. placeholderText: '说点什么...',
  561. liveUserTotal: 0,
  562. viewPageSize: 10, // 每页数量
  563. viewPageNum: 1, // 当前页码
  564. viewLoading: false, // 是否正在加载
  565. scrollHeight: 0,
  566. scrollTimer: null, // 滚动防抖定时器
  567. searchTimer: null,
  568. showPurchasePrompt: false,
  569. purchasePromptTimer: null,
  570. prevOrderCount: 0, // 用于记录上一次的购买人数
  571. videoUrl: null,
  572. showType: 1, //横屏1 竖屏2
  573. boxHeight: 300, //小黄车高度
  574. liveViewers: [], //观众
  575. livingUrl: "",
  576. products: [],
  577. loadingProducts: false, // 商品加载状态
  578. store: {},
  579. orderUser: {}, //正在购买
  580. userType: 0,
  581. timestamp: '',
  582. liveId: null,
  583. userinfo: '', //用户信息
  584. showadd: false,
  585. userData: {},
  586. //流量
  587. uuId: "",
  588. };
  589. },
  590. onLoad(options) {
  591. if (options.liveId) {
  592. this.liveId = options.liveId;
  593. }
  594. this.getUserInfo()
  595. this.previousToken = ('AppToken')
  596. this.initTime();
  597. this.userinfo = uni.getStorageSync("userInfo")
  598. this.userData = uni.getStorageSync("userData")
  599. console.log("全部参数", options)
  600. //获取键盘高度
  601. uni.onKeyboardHeightChange(res => {
  602. this.keyboardHeight = res.height * 2;
  603. });
  604. // 扫码传来的参数
  605. if (options.scene) {
  606. this.scene = options.scene;
  607. const decodedScene = decodeURIComponent(this.scene);
  608. const params = {};
  609. decodedScene.split('&').forEach(item => {
  610. const [key, value] = item.split('=');
  611. params[key] = value;
  612. this.liveId = params.a;
  613. })
  614. if (params.b && params.c) {
  615. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  616. }
  617. }
  618. if (options.companyId && options.companyUserId) {
  619. this.qrFrom = `&companyId=${options.companyId}&companyUserId=${options.companyUserId}`;
  620. }
  621. // 初始化直播间列表
  622. this.$nextTick(() => {
  623. if (this.liveId) {
  624. this.getliving(this.liveId);
  625. this.isOnload = true
  626. this.getLiveMsg(this.liveItem);
  627. this.getliveViewData(this.liveItem);
  628. } else {
  629. console.error("直播间 ID(liveId)未获取到");
  630. }
  631. })
  632. },
  633. onPullDownRefresh() {
  634. this.getLiveMsg(this.liveId)
  635. this.getliveUser()
  636. setTimeout(() => {
  637. uni.stopPullDownRefresh()
  638. }, 1000)
  639. },
  640. async onShow() {
  641. if (this.liveId&& !this.talklist) {
  642. await this.getLiveMsg(this.liveItem);
  643. }
  644. if (!this.liveViewData) {
  645. this.getliveViewData(this.liveItem);
  646. }
  647. if (!this.userData) {
  648. await this.getUserInfo()
  649. }
  650. this.uuId = generateRandomString(16)
  651. this.previousToken = await uni.getStorageSync('AppToken')
  652. const isLiveLogin = uni.getStorageSync('isLiveLogin')
  653. this.share = uni.getStorageSync('share')
  654. this.scene = uni.getStorageSync('scene')
  655. if (this.share && this.share.length > 0) {
  656. this.liveId = this.share.liveId
  657. this.qrFrom = `&companyId=${this.share.companyId}&companyUserId=${this.share.companyUserId}`;
  658. uni.removeStorageSync('share')
  659. }
  660. if (this.scene) {
  661. const decodedScene = decodeURIComponent(this.scene);
  662. const params = {};
  663. decodedScene.split('&').forEach(item => {
  664. const [key, value] = item.split('=');
  665. params[key] = value;
  666. this.liveId = params.a;
  667. })
  668. if (params.b && params.c) {
  669. this.qrFrom = `&companyId=${params.b}&companyUserId=${params.c}`;
  670. }
  671. uni.removeStorageSync('scene')
  672. }
  673. if (isLiveLogin) {
  674. if (this.liveId) {
  675. await this.getliving(this.liveId)
  676. this.getCurrentActivities()
  677. this.getliveOrder()
  678. this.initSocket()
  679. }
  680. this.hasInitialized = true
  681. uni.removeStorageSync('isLiveLogin');
  682. }
  683. // 恢复播放和连接
  684. await this.resumePageActivity()
  685. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  686. this.isAgreement = uni.getStorageSync('isAgreement')
  687. this.$nextTick(() => {
  688. this.setVideoProgress();
  689. });
  690. if (this.lookTimer) {
  691. clearInterval(this.lookTimer)
  692. this.lookTimer = null;
  693. this.stayTime = 0;
  694. this.startTime = 0;
  695. }
  696. if (this.trafficTimer) {
  697. clearInterval(this.trafficTimer)
  698. this.trafficTimer = null;
  699. this.startTime = 0;
  700. this.totalTraffic = 0;
  701. }
  702. this.startTimer()
  703. },
  704. //分享给好友
  705. onShareAppMessage() {
  706. return {
  707. title: '邀请你来观看直播:' + this.liveItem.liveName,
  708. path: '/pages_course/living?companyId=-2&companyUserId=' + this.userData.userId + '&liveId=' + this.liveId,
  709. imageUrl: '/static/images/logo.png',
  710. success(res) {
  711. console.log("分享成功", res);
  712. },
  713. fail(err) {
  714. console.error("分享失败", err);
  715. }
  716. };
  717. },
  718. computed: {
  719. filteredViewers() {
  720. const safeLiveViewers = Array.isArray(this.liveViewersData) ? this.liveViewersData : [];
  721. // 截取前3项
  722. return safeLiveViewers.slice(0, 3);
  723. },
  724. isCurrentUserWon() {
  725. if (!Array.isArray(this.prizeInfo) || !this.userData?.userId) {
  726. return false;
  727. }
  728. return this.prizeInfo.some(item => {
  729. return String(item.userId) === String(this.userData.userId);
  730. });
  731. }
  732. },
  733. onHide() {
  734. // 清除所有定时器
  735. this.clearAllTimers();
  736. this.stopHeartBeat()
  737. },
  738. onUnload() {
  739. this.stopHeartBeat()
  740. this.saveVideoProgress()
  741. if (this.liveItem) {
  742. this.pauseVideo()
  743. // 清除直播间的时间定时器
  744. if (this.liveItem.timeTimer) {
  745. clearInterval(this.liveItem.timeTimer);
  746. this.liveItem.timeTimer = null; // 清空定时器标识
  747. }
  748. }
  749. this.liveUserCalled = false
  750. this.loadUserColorsFromStorage();
  751. // 先关闭WebSocket
  752. this.closeWebSocket(true);
  753. // 清除所有定时器
  754. this.clearAllTimers();
  755. // 暂停视频
  756. const videoId = `myVideo_${this.liveId}`;
  757. const videoContext = uni.createVideoContext(videoId, this);
  758. if (videoContext) {
  759. videoContext.pause();
  760. }
  761. },
  762. mounted() {
  763. this.getCurrentActivities();
  764. this.getliveOrder()
  765. },
  766. watch: {
  767. // 监听liveItem.status的变化
  768. 'liveItem.status': {
  769. handler(newStatus, oldStatus) {
  770. if (newStatus === undefined || oldStatus === undefined) return;
  771. if (newStatus === oldStatus) return;
  772. if (!this.liveId) {
  773. console.warn("liveId不存在,无法触发getliving请求");
  774. return;
  775. }
  776. // 状态变化时,调用getliving更新直播间数据
  777. console.log(`liveItem.status从${oldStatus}变为${newStatus},触发getliving请求`);
  778. this.getliving(this.liveId);
  779. },
  780. deep: true,
  781. },
  782. // 监听orderUser.count的变化
  783. 'orderUser.count': {
  784. handler(newVal, oldVal) {
  785. if (newVal !== this.prevOrderCount) {
  786. this.prevOrderCount = newVal;
  787. this.showPurchaseMessage();
  788. }
  789. },
  790. immediate: true
  791. }
  792. },
  793. methods: {
  794. goMiniProgram() {
  795. uni.navigateToMiniProgram({
  796. appId: 'wx45cf09091aead547',
  797. path: 'pages/index/index',
  798. // extraData: {
  799. // key1: 'value1',
  800. // key2: 'value2'
  801. // },
  802. success: function(res) {
  803. console.log('跳转成功', res);
  804. },
  805. fail: function(err) {
  806. console.error('跳转失败', err);
  807. }
  808. });
  809. },
  810. // 阻止双击事件
  811. preventDoubleClick(e) {
  812. e.preventDefault();
  813. e.stopPropagation();
  814. return false;
  815. },
  816. // 清理所有定时器
  817. clearAllTimers() {
  818. if (this.liveViewDataTimer) {
  819. clearInterval(this.liveViewDataTimer);
  820. this.liveViewDataTimer = null;
  821. }
  822. // 清除特定定时器
  823. if (this.redTimer) {
  824. clearInterval(this.redTimer);
  825. this.redTimer = null;
  826. }
  827. if (this.liveStartTimer) {
  828. clearInterval(this.liveStartTimer);
  829. this.liveStartTimer = null;
  830. }
  831. if (this.lotteryTimer) {
  832. clearInterval(this.lotteryTimer);
  833. this.lotteryTimer = null;
  834. }
  835. if (this.welcomeTimer) {
  836. clearInterval(this.welcomeTimer);
  837. this.welcomeTimer = null;
  838. }
  839. if (this.trafficInterval != null) {
  840. clearInterval(this.trafficInterval)
  841. }
  842. if (this.lookTimer) {
  843. clearInterval(this.lookTimer)
  844. this.lookTimer = null;
  845. this.stayTime = 0;
  846. this.startTime = 0;
  847. }
  848. if (this.trafficTimer) {
  849. clearInterval(this.trafficTimer)
  850. this.trafficTimer = null;
  851. this.startTime = 0;
  852. this.totalTraffic = 0;
  853. }
  854. if (this.intervalId) {
  855. clearInterval(this.intervalId);
  856. this.intervalId = null;
  857. }
  858. if (this.reconnectTimer) {
  859. clearInterval(this.reconnectTimer);
  860. this.reconnectTimer = null;
  861. }
  862. if (this.scrollTimer) {
  863. clearTimeout(this.scrollTimer);
  864. this.scrollTimer = null;
  865. }
  866. if (this.searchTimer) {
  867. clearTimeout(this.searchTimer);
  868. this.searchTimer = null;
  869. }
  870. if (this.purchasePromptTimer) {
  871. clearTimeout(this.purchasePromptTimer);
  872. this.purchasePromptTimer = null;
  873. }
  874. },
  875. //直播计算流量
  876. startTrafficCalculation() {
  877. this.startTime = Date.now();
  878. var that = this
  879. this.trafficTimer = setInterval(() => {
  880. that.calculateTraffic();
  881. }, 10000); // 每5秒计算一次
  882. },
  883. // 计算流量
  884. calculateTraffic() {
  885. const currentTime = Date.now();
  886. const duration = (currentTime - this.startTime) / 1000; // 持续时间(秒)
  887. // 流量 = 码率 × 时间
  888. // 码率单位: bps, 时间单位: 秒, 流量单位: 比特
  889. const trafficBits = this.bitrate * duration;
  890. // 转换为字节
  891. this.totalTraffic = trafficBits / 8;
  892. this.getLiveInternetTraffic()
  893. },
  894. startTimer() {
  895. this.startTime = Date.now()
  896. this.lookTimer = setInterval(() => {
  897. this.stayTime = Math.floor((Date.now() - this.startTime) / 1000)
  898. }, 1000)
  899. },
  900. //直播缓冲
  901. getLiveInternetTraffic() {
  902. if (!this.liveId) return;
  903. const currentTime = this.stayTime / this.liveItem.duration * 100;
  904. const param = {
  905. userId: this.userData.userId || '',
  906. liveId: this.liveId || '',
  907. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  908. internetTraffic: this.totalTraffic,
  909. }
  910. liveInternetTraffic(param)
  911. },
  912. // 缓冲
  913. getInternetTraffic() {
  914. if (!this.liveId || !this.liveId || !this.userData.userId || !this.uuId) return;
  915. const currentTime = this.stayTime / this.liveItem.duration * 100;
  916. const param = {
  917. videoType: this.liveItem.videoType,
  918. videoId: this.liveItem.videoId,
  919. userId: this.userData.userId,
  920. liveId: this.liveId,
  921. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  922. duration: this.liveItem.duration,
  923. bufferRate: currentTime,
  924. }
  925. if (this.liveItem.status == 1) {
  926. param.videoType = this.liveItem.previewVideoType || ''
  927. param.videoId = this.liveItem.previewVideoId || ''
  928. }
  929. if (this.liveItem.liveType == 1) {
  930. param.bufferRate = this.totalTraffic
  931. }
  932. internetTraffic(param)
  933. },
  934. scrollToBottom() {
  935. this.$nextTick(() => {
  936. setTimeout(() => {
  937. const query = uni.createSelectorQuery().in(this);
  938. // 获取 scroll-view 和内容的高度
  939. query.select('.scrolly').boundingClientRect(scrollRect => {
  940. query.select('.scrolly').scrollOffset(scrollOffset => {
  941. // 计算新的滚动位置
  942. const newScrollTop = scrollOffset.scrollHeight - scrollRect
  943. .height;
  944. this.scrollTop = newScrollTop;
  945. }).exec();
  946. }).exec();
  947. }, 100);
  948. });
  949. },
  950. // 恢复页面活动
  951. async resumePageActivity() {
  952. if (this.liveItem) {
  953. await this.getliving(this.liveId)
  954. this.startTimeTimer(this.liveItem)
  955. }
  956. if (!this.isSocketAvailable()) {
  957. this.initSocket()
  958. }
  959. },
  960. // 获取用户专属随机色(缓存机制:同一用户始终用同一颜色)
  961. getUserRandomColor(userId) {
  962. if (!userId) {
  963. return '#8978e2'; // 默认颜色
  964. }
  965. //如果缓存中已有该用户的颜色,直接返回
  966. if (this.userRandomColors[userId]) {
  967. return this.userRandomColors[userId];
  968. }
  969. //为新用户生成固定颜色(基于用户ID生成,不是完全随机)
  970. const color = this.generateStableColor(userId);
  971. this.userRandomColors[userId] = color;
  972. // 存储到本地缓存,确保页面刷新后颜色不变
  973. this.saveUserColorsToStorage();
  974. return color;
  975. }, // 基于用户ID生成稳定颜色(不是完全随机)
  976. generateStableColor(userId) {
  977. // 将用户ID转换为数字种子
  978. let seed = 0;
  979. for (let i = 0; i < userId.length; i++) {
  980. seed = (seed * 31 + userId.charCodeAt(i)) % 1000000;
  981. }
  982. const colorPool = [
  983. '#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7',
  984. '#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E9',
  985. '#F8C471', '#82E0AA', '#F1948A', '#85C1E9', '#D7BDE2'
  986. ];
  987. return colorPool[seed % colorPool.length];
  988. },
  989. // 保存颜色映射到本地存储
  990. saveUserColorsToStorage() {
  991. try {
  992. uni.setStorageSync('userRandomColors', this.userRandomColors);
  993. } catch (e) {
  994. console.warn('保存用户颜色缓存失败:', e);
  995. }
  996. },
  997. // 从本地存储加载颜色映射
  998. loadUserColorsFromStorage() {
  999. try {
  1000. const cached = uni.getStorageSync('userRandomColors');
  1001. if (cached) {
  1002. this.userRandomColors = cached;
  1003. }
  1004. } catch (e) {
  1005. console.warn('加载用户颜色缓存失败:', e);
  1006. }
  1007. },
  1008. //头像名字
  1009. getNicknameInitial(nickName) {
  1010. if (!nickName || typeof nickName !== 'string') return '未';
  1011. if (/^[\u4e00-\u9fa5]/.test(nickName[0])) {
  1012. return nickName[0];
  1013. }
  1014. return nickName[0].toUpperCase();
  1015. },
  1016. async getUserInfo() {
  1017. await getUserInfo().then(
  1018. res => {
  1019. if (res.code == 200) {
  1020. this.userData = res.user;
  1021. } else {
  1022. uni.showToast({
  1023. icon: 'none',
  1024. title: "请求失败",
  1025. });
  1026. }
  1027. },
  1028. rej => {}
  1029. );
  1030. },
  1031. //订阅消息
  1032. handleAgreement() {
  1033. const templateId = this.templateId;
  1034. uni.requestSubscribeMessage({
  1035. tmplIds: [templateId],
  1036. success: (res) => {
  1037. // console.log("模板订阅状态", res[templateId]);
  1038. if (res[templateId] === "accept") {
  1039. uni.showToast({
  1040. title: '订阅成功,开播将提醒您',
  1041. icon: 'success'
  1042. });
  1043. this.callSendMessageApi()
  1044. } else if (res[templateId] === 'reject') {
  1045. uni.showToast({
  1046. title: '您已拒绝订阅,将无法收到提醒',
  1047. icon: 'none'
  1048. });
  1049. } else if (res[templateId] === 'ban') {
  1050. uni.showToast({
  1051. title: '您已关闭所有订阅权限,请在设置中开启',
  1052. icon: 'none'
  1053. });
  1054. }
  1055. },
  1056. fail: (err) => {
  1057. console.error('订阅消息失败', err);
  1058. uni.showToast({
  1059. title: '订阅失败,请重试',
  1060. icon: 'none'
  1061. });
  1062. }
  1063. });
  1064. },
  1065. async callSendMessageApi() {
  1066. if (!this.userData.userId) return;
  1067. const templateData = {
  1068. taskName: this.liveId,
  1069. userId: this.userData.userId,
  1070. templateId: this.templateId, // 模板ID
  1071. data: {
  1072. thing6: this.liveItem.liveName,
  1073. date7: this.liveItem.startTime,
  1074. }
  1075. };
  1076. subNotifyLive(templateData).then(res => {
  1077. if (res.code == 200) {
  1078. this.isAgreement = true;
  1079. uni.setStorageSync('isAgreement', true);
  1080. } else {
  1081. uni.showToast({
  1082. title: res.msg,
  1083. icon: 'none'
  1084. });
  1085. }
  1086. },
  1087. rej => {}
  1088. );
  1089. },
  1090. sendHeartBeat() {
  1091. if (!this.isSocketAvailable()) return;
  1092. try {
  1093. const heartBeatMsg = JSON.stringify({
  1094. cmd: "heartbeat",
  1095. msg: "ping",
  1096. userId: this.userData.userId || '',
  1097. liveId: this.liveId
  1098. });
  1099. this.socket.send({
  1100. data: heartBeatMsg,
  1101. success: () => {
  1102. this.heartBeatRetryCount = 0; // 成功后重置重试次数
  1103. this.startPingTimeout(); // 启动超时检测
  1104. },
  1105. fail: (err) => {
  1106. console.error("心跳包发送失败:", err);
  1107. this.heartBeatRetryCount++;
  1108. // 心跳失败先重试,重试次数用完再重连
  1109. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  1110. setTimeout(() => this.sendHeartBeat(), 2000); // 2秒后重试
  1111. } else {
  1112. this.heartBeatRetryCount = 0;
  1113. this.handleReconnect(); // 重试用完才重连
  1114. }
  1115. }
  1116. });
  1117. } catch (err) {
  1118. console.error("心跳发送异常:", err);
  1119. this.heartBeatRetryCount++;
  1120. if (this.heartBeatRetryCount < this.maxHeartBeatRetries) {
  1121. setTimeout(() => this.sendHeartBeat(), 2000);
  1122. } else {
  1123. this.heartBeatRetryCount = 0;
  1124. this.handleReconnect();
  1125. }
  1126. }
  1127. },
  1128. // 启动心跳超时检测
  1129. startPingTimeout() {
  1130. // 清除之前的超时定时器
  1131. if (this.pingTimeoutTimer) {
  1132. clearTimeout(this.pingTimeoutTimer);
  1133. this.pingTimeoutTimer = null;
  1134. }
  1135. // 超时后触发重连
  1136. this.pingTimeoutTimer = setTimeout(() => {
  1137. // console.error("心跳响应超时,连接异常");
  1138. this.handleReconnect();
  1139. }, this.pingTimeout);
  1140. },
  1141. stopHeartBeat() {
  1142. if (this.heartBeatTimer) {
  1143. clearInterval(this.heartBeatTimer);
  1144. this.heartBeatTimer = null;
  1145. }
  1146. if (this.pingTimeoutTimer) {
  1147. clearTimeout(this.pingTimeoutTimer);
  1148. this.pingTimeoutTimer = null;
  1149. }
  1150. }, // 封装通用的连接状态校验方法
  1151. isSocketAvailable() {
  1152. // WebSocket readyState:0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED
  1153. return this.socket && this.isSocketOpen && this.socket.readyState === 1;
  1154. },
  1155. // 处理重连逻辑
  1156. handleReconnect() {
  1157. this.resetReconnectState();
  1158. // uni.onNetworkStatusChange(res=>{
  1159. // if (res.networkType === 'wifi') {
  1160. // }
  1161. // })
  1162. this.stopHeartBeat();
  1163. if (this.reconnectCount < this.maxReconnectAttempts) {
  1164. this.reconnectCount++;
  1165. const delay = 1000;
  1166. console.log(`第${this.reconnectCount}次重连,延迟${delay}ms`);
  1167. this.reconnectTimer = setInterval(() => {
  1168. this.initSocket();
  1169. }, delay);
  1170. } else {
  1171. console.log(`停止重连(手动关闭/已达最大次数)`);
  1172. this.closeWebSocket(true);
  1173. }
  1174. },
  1175. // 重置重连状态
  1176. resetReconnectState() {
  1177. this.reconnectCount = 0;
  1178. if (this.reconnectTimer) {
  1179. clearInterval(this.reconnectTimer);
  1180. this.reconnectTimer = null;
  1181. }
  1182. },
  1183. //输入框
  1184. inputFocus() {
  1185. this.chatHeight = this.keyboardHeight;
  1186. this.isFocus = true;
  1187. },
  1188. inputBlur() {
  1189. this.chatHeight = 0;
  1190. this.isFocus = false
  1191. },
  1192. getTimeDifferenceInSeconds(createTimeStr) {
  1193. const createTime = new Date(createTimeStr.replace(/-/g, '/'));
  1194. const now = new Date();
  1195. const timeDiffMs = now - createTime;
  1196. const timeDiffSeconds = Math.floor(timeDiffMs / 1000);
  1197. return Math.max(0, timeDiffSeconds);
  1198. },
  1199. // 录播时间点
  1200. onVideoMetaLoaded(e) {
  1201. this.videoProgressKey = `videoProgress_${this.liveId}`;
  1202. this.setVideoProgress();
  1203. },
  1204. setVideoProgress() {
  1205. // 只有录播和回放需要设置进度
  1206. if (this.liveItem.liveType !== 2 && this.liveItem.liveType !== 3) {
  1207. return;
  1208. }
  1209. let currentTime = 0;
  1210. if (this.liveItem.liveType === 2) {
  1211. // 录播:计算当前时间与开始时间的差值,对视频总时长取模
  1212. const diff = this.getTimeDifferenceInSeconds(this.liveItem.startTime);
  1213. if (diff > this.liveItem.duration) {
  1214. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  1215. currentTime = (storedProgress >= this.liveItem.duration) ? 0 : (storedProgress || 0);
  1216. } else {
  1217. currentTime = diff % this.liveItem.duration;
  1218. }
  1219. // currentTime = diff % this.liveItem.duration;
  1220. } else if (this.liveItem.liveType === 3) {
  1221. // 回放:从存储中获取进度
  1222. const storedProgress = uni.getStorageSync(this.videoProgressKey);
  1223. currentTime = storedProgress || 0;
  1224. }
  1225. const videoId = `myVideo_${this.liveId}`;
  1226. const videoContext = uni.createVideoContext(videoId, this);
  1227. if (videoContext) {
  1228. videoContext.seek(currentTime);
  1229. }
  1230. },
  1231. onVideoWaiting(e) {
  1232. // console.log('视频等待加载', e);
  1233. //流量
  1234. let that = this
  1235. if (this.trafficInterval) {
  1236. clearInterval(this.trafficInterval);
  1237. this.trafficInterval = null;
  1238. }
  1239. this.trafficInterval = setInterval(function() {
  1240. that.getInternetTraffic();
  1241. }, 10000);
  1242. },
  1243. // 视频时间更新
  1244. onVideoTimeUpdate(e) {
  1245. // 获取当前播放时间
  1246. this.videoCurrentTime = e.detail.currentTime;
  1247. // 每隔5秒保存一次进度(避免频繁存储)
  1248. if (Math.floor(this.videoCurrentTime) % 5 === 0) {
  1249. this.saveVideoProgress();
  1250. }
  1251. // this.setVideoProgress();
  1252. },
  1253. // 视频暂停
  1254. onVideoPause(e) {
  1255. if (this.liveItem.liveType === 2) {
  1256. const videoId = `myVideo_${this.liveId}`;
  1257. const videoContext = uni.createVideoContext(videoId, this);
  1258. setTimeout(() => {
  1259. videoContext.play();
  1260. }, 100);
  1261. }
  1262. // 暂停时保存进度
  1263. this.saveVideoProgress();
  1264. },
  1265. // 视频播放
  1266. onVideoPlay(e) {},
  1267. // 设置视频当前时间
  1268. // setVideoCurrentTime(time) {
  1269. // if (!time) return;
  1270. // const videoId = `myVideo_${this.liveId}`;
  1271. // const videoContext = uni.createVideoContext(videoId, this);
  1272. // if (videoContext) {
  1273. // videoContext.seek(time);
  1274. // console.log(`设置视频播放位置: ${time}秒`);
  1275. // }
  1276. // },
  1277. // 保存视频进度
  1278. saveVideoProgress() {
  1279. if (this.videoProgressKey) {
  1280. uni.setStorage({
  1281. key: this.videoProgressKey,
  1282. data: this.videoCurrentTime,
  1283. success: () => {},
  1284. fail: (err) => {
  1285. console.error('保存视频进度失败:', err);
  1286. }
  1287. });
  1288. }
  1289. },
  1290. // 点击红包
  1291. onRed() {
  1292. if (!this.liveId) return;
  1293. if (!this.redInfo?.redId) return;
  1294. if (this.redTimer) {
  1295. clearInterval(this.redTimer);
  1296. this.redTimer = null;
  1297. }
  1298. let data = {
  1299. liveId: this.liveId,
  1300. userId: this.userData.userId,
  1301. redId: this.redInfo.redId,
  1302. }
  1303. liveRed(data).then(res => {
  1304. this.isShowRed = false
  1305. this.redCard = res
  1306. this.isShowRedCard = true
  1307. },
  1308. rej => {}
  1309. );
  1310. },
  1311. //领取优惠券
  1312. onCoupon() {
  1313. if (!this.couponInfo.couponIssueId) return;
  1314. let data = {
  1315. goodsId: this.couponInfo.goodsId,
  1316. couponIssueId: this.couponInfo.couponIssueId,
  1317. liveId: this.liveId
  1318. };
  1319. coupon(data)
  1320. .then(res => {
  1321. this.isShowCoupon = false
  1322. if (res.code == 200) {
  1323. uni.showToast({
  1324. title: res.msg,
  1325. icon: 'none'
  1326. });
  1327. } else {
  1328. uni.showToast({
  1329. title: res.msg,
  1330. icon: 'none'
  1331. });
  1332. }
  1333. })
  1334. .catch(rej => {});
  1335. },
  1336. // 抽奖
  1337. onLottery() {
  1338. if (!this.lotteryInfo) return;
  1339. let data = {
  1340. lotteryId: this.lotteryInfo.lotteryId
  1341. };
  1342. liveLottery(data)
  1343. .then(res => {
  1344. if (res.code == 200) {
  1345. const resData = res.data || {};
  1346. this.lotteryList = Array.isArray(resData) ? resData : [];
  1347. this.lotteryProducts = Array.isArray(resData.products) ? resData.products : [];
  1348. if (resData.duration) {
  1349. this.isShowLotteryPop = true;
  1350. }
  1351. } else {
  1352. uni.showToast({
  1353. title: res.msg,
  1354. icon: 'none'
  1355. });
  1356. this.lotteryList = [];
  1357. this.lotteryProducts = [];
  1358. }
  1359. })
  1360. .catch(rej => {
  1361. uni.showToast({
  1362. title: '获取抽奖信息失败',
  1363. icon: 'none'
  1364. });
  1365. // 失败时强制重置为数组
  1366. this.lotteryList = [];
  1367. this.lotteryProducts = [];
  1368. });
  1369. },
  1370. // 参与抽奖
  1371. onClaim() {
  1372. let data = {
  1373. liveId: this.liveId,
  1374. lotteryId: this.lotteryInfo.lotteryId,
  1375. }
  1376. claim(data).then(res => {
  1377. if (res.code == 200) {
  1378. uni.showToast({
  1379. title: res.msg,
  1380. icon: 'none'
  1381. });
  1382. this.isShowLotteryPop = false
  1383. } else {
  1384. uni.showToast({
  1385. title: res.msg,
  1386. icon: 'none'
  1387. });
  1388. }
  1389. },
  1390. rej => {}
  1391. );
  1392. },
  1393. // 商品收藏
  1394. onGoodsCollect(item) {
  1395. if (!item || item.length === 0 || !item.goodsId) {
  1396. return;
  1397. }
  1398. collectGoods(item.goodsId).then(res => {
  1399. if (res.code == 200) {
  1400. uni.showToast({
  1401. title: res.msg,
  1402. icon: 'none'
  1403. });
  1404. item.isFavorite = !item.isFavorite
  1405. } else {
  1406. uni.showToast({
  1407. title: res.msg,
  1408. icon: 'none'
  1409. });
  1410. }
  1411. },
  1412. rej => {}
  1413. );
  1414. },
  1415. //正在购买
  1416. getliveOrder(item) {
  1417. if (!this.liveId) {
  1418. return;
  1419. }
  1420. liveOrderUser(this.liveId).then(res => {
  1421. if (res.code == 200) {
  1422. this.orderUser = res;
  1423. } else {
  1424. console.log('获取正在购买用户失败');
  1425. }
  1426. },
  1427. rej => {}
  1428. );
  1429. },
  1430. onLiveStateChange(e, liveItem) {
  1431. // 可以根据状态码处理不同的直播状态
  1432. const stateCode = e.detail.code;
  1433. if (e.detail.code == -2301 || e.detail.code == -2302) {
  1434. this.playVideo()
  1435. } else if (e.detail.code == 2004) {
  1436. this.calculateTimeDiff(this.liveItem)
  1437. this.startTrafficCalculation();
  1438. }
  1439. // 2001: 已经连接服务器
  1440. // 2002: 已经连接服务器,开始拉流
  1441. // 2003: 网络接收到首个视频数据包(IDR)
  1442. // 2004: 视频播放开始
  1443. // 2005: 视频播放进度
  1444. // 2006: 视频播放结束
  1445. // 2007: 视频播放Loading
  1446. // 2008: 解码器启动
  1447. // -2301: 网络断连,且经多次重连抢救无效,更多重试请自行重启播放
  1448. // -2302: 获取加速拉流地址失败
  1449. }, // 直播错误事件
  1450. onLiveError(e, liveItem) {
  1451. this.videoError(e, liveItem);
  1452. },
  1453. // 红包 卡片 抽奖
  1454. getCurrentActivities() {
  1455. if (!this.liveId) return;
  1456. currentActivities(this.liveId).then(res => {
  1457. if (res.code === 200) {
  1458. // 提取数据(默认空数组/对象避免报错)
  1459. this.redInfo = (Array.isArray(res.red) ? res.red : [])[0] || {};
  1460. this.lotteryInfo = (Array.isArray(res.lottery) ? res.lottery : [])[0] || {};
  1461. this.goodsCard = res.goods || {};
  1462. this.isShowGoods = this.goodsCard && this.goodsCard.status == 1;
  1463. this.isShowRed = this.redInfo && this.redInfo.redStatus == 1;
  1464. this.isShowLottery = this.lotteryInfo && this.lotteryInfo.lotteryStatus == 1;
  1465. if (this.isShowRed) {
  1466. this.redTimer = setInterval(() => {
  1467. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  1468. .duration)
  1469. if (!redCountdown) {
  1470. this.isShowRed = false
  1471. clearInterval(this.redTimer)
  1472. }
  1473. }, 1000);
  1474. }
  1475. // 处理抽奖定时器
  1476. if (this.isShowLottery) {
  1477. this.lotteryTimer = setInterval(() => {
  1478. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this
  1479. .lotteryInfo
  1480. .duration)
  1481. }, 1000);
  1482. }
  1483. } else {
  1484. uni.showToast({
  1485. title: res.msg,
  1486. icon: 'none'
  1487. });
  1488. }
  1489. }, rej => {});
  1490. },
  1491. // 计算当前时间与 liveItem.startTime 的差值,并更新 totalTime
  1492. calculateTimeDiff(item) {
  1493. if (!item.startTime) return;
  1494. // 提取对应场景的时间字符串(直播用startTime,抽奖用updateTime)
  1495. let timeStr = item.startTime;
  1496. // 转换时间格式(适配iOS,将 "-" 替换为 "/")
  1497. const time = new Date(timeStr.replace(/-/g, "/"));
  1498. if (isNaN(time.getTime())) {
  1499. return;
  1500. }
  1501. const now = new Date();
  1502. let diffMs = Math.max(0, now.getTime() - time.getTime())
  1503. // 转换为 时:分:秒(补零处理)
  1504. const totalSeconds = Math.floor(diffMs / 1000);
  1505. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  1506. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  1507. const seconds = this.padZero(totalSeconds % 60);
  1508. this.$set(this.liveItem, "totalTime", `${hours}:${minutes}:${seconds}`);
  1509. // this.$set(this.liveItem, "diffMs", diffMs);
  1510. this.$set(this.liveItem, "totalSeconds", totalSeconds);
  1511. },
  1512. padZero(num) {
  1513. return num < 10 ? `0${num}` : num;
  1514. },
  1515. // 启动当前直播间的时间差值定时器
  1516. startTimeTimer(item) {
  1517. if (!item) return;
  1518. // 立即计算一次(避免等待1秒才显示)
  1519. const totalTime = this.calculateTimeDiff(item);
  1520. item.timeTimer = setInterval(() => {
  1521. const totalTime = this.calculateTimeDiff(item);
  1522. }, 1000);
  1523. },
  1524. toggleViewerList() {
  1525. const now = Date.now();
  1526. if (now - this.lastClickTime > this.clickDelay) {
  1527. this.showadd = !this.showadd;
  1528. if (this.showadd) {
  1529. this.getliveUser(false); // 加载第一页观众
  1530. }
  1531. this.lastClickTime = now;
  1532. }
  1533. },
  1534. // 播放视频
  1535. playVideo() {
  1536. if (!this.liveItem) {
  1537. console.log('liveItem 为空,无法播放视频');
  1538. return;
  1539. }
  1540. try {
  1541. // 直播流使用live-player
  1542. if (this.liveItem.liveType === 1 && this.liveItem.livingUrl && this.liveItem.status == 2) {
  1543. const livePlayerId = `myLivePlayer_${this.liveId}`;
  1544. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  1545. if (livePlayerContext) {
  1546. livePlayerContext.play();
  1547. }
  1548. } else if (this.liveItem.status == 1 && this.liveItem.previewUrl) {
  1549. const videoId = `myVideo_${this.liveId}`;
  1550. const videoContext = uni.createVideoContext(videoId, this);
  1551. if (videoContext) {
  1552. videoContext.play();
  1553. }
  1554. } else if (this.liveItem.liveType === 2 && this.liveItem.videoUrl && this.liveItem.status == 2) {
  1555. const videoId = `myVideo_${this.liveId}`;
  1556. const videoContext = uni.createVideoContext(videoId, this);
  1557. if (videoContext) {
  1558. videoContext.play();
  1559. }
  1560. } // 回放视频使用video
  1561. else if (this.liveItem.liveType === 3 && this.liveItem.videoUrl && this.liveItem.status == 4) {
  1562. const videoId = `myVideo_${this.liveId}`;
  1563. const videoContext = uni.createVideoContext(videoId, this);
  1564. if (videoContext) {
  1565. videoContext.play();
  1566. }
  1567. }
  1568. } catch (error) {
  1569. console.error("播放视频失败:", error);
  1570. }
  1571. },
  1572. pauseVideo() {
  1573. if (!this.liveItem) return;
  1574. try {
  1575. // 直播流使用live-player
  1576. if (this.liveItem.status == 1) {
  1577. const videoId = `myVideo_${this.liveId}`;
  1578. const videoContext = uni.createVideoContext(videoId, this);
  1579. if (videoContext) {
  1580. videoContext.pause();
  1581. }
  1582. } else if (this.liveItem.status == 2) {
  1583. if (this.liveItem.liveType === 1) {
  1584. const livePlayerId = `myLivePlayer_${this.liveId}`;
  1585. const livePlayerContext = uni.createLivePlayerContext(livePlayerId, this);
  1586. if (livePlayerContext) {
  1587. livePlayerContext.pause();
  1588. }
  1589. } else if (this.liveItem.liveType === 2) {
  1590. const videoId = `myVideo_${this.liveId}`;
  1591. const videoContext = uni.createVideoContext(videoId, this);
  1592. if (videoContext) {
  1593. videoContext.pause();
  1594. }
  1595. }
  1596. }
  1597. } catch (error) {
  1598. console.error("暂停视频失败:", error);
  1599. }
  1600. },
  1601. // 视频错误处理
  1602. videoError(e, liveItem) {
  1603. if (!liveItem || !this.liveId) return;
  1604. // 初始化重试计数
  1605. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  1606. this.videoRetryCounts[liveItem.liveId] = 0;
  1607. }
  1608. // 限制重试次数
  1609. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  1610. console.error(`直播间 ${this.liveId} 视频加载失败,停止重试`);
  1611. // 显示错误提示
  1612. uni.showToast({
  1613. title: "视频加载失败,请检查网络",
  1614. icon: 'none',
  1615. duration: 2000
  1616. });
  1617. return;
  1618. }
  1619. this.videoRetryCounts[this.liveId]++;
  1620. // 延迟重试
  1621. setTimeout(() => {
  1622. if (this.liveId === this.liveId) {
  1623. console.log(`第${this.videoRetryCounts[this.liveId]}次重试播放视频`);
  1624. this.playVideo();
  1625. }
  1626. }, 2000);
  1627. },
  1628. openViews() {
  1629. // 计算scroll-view高度
  1630. this.$nextTick(() => {
  1631. const query = uni.createSelectorQuery().in(this);
  1632. query.select('.view-box').boundingClientRect(data => {
  1633. if (data) {
  1634. this.scrollHeight = data.height - 80 - 120; // 80是标题高度,120是底部高度
  1635. }
  1636. }).exec();
  1637. });
  1638. },
  1639. // 滚动到底部触发
  1640. handleScrollToLower() {
  1641. // 清除上一次未执行的定时器,避免重复请求
  1642. if (this.scrollTimer) {
  1643. clearTimeout(this.scrollTimer);
  1644. }
  1645. // 延迟0.5秒(500毫秒)执行接口请求
  1646. this.scrollTimer = setTimeout(() => {
  1647. this.getliveUser(true);
  1648. }, 1000);
  1649. },
  1650. async getLiveMsg(liveItem) {
  1651. if (!liveItem || !this.liveId) {
  1652. console.error('getLiveMsg 错误:无效的 liveItem');
  1653. return;
  1654. }
  1655. try {
  1656. const res = await liveMsg(this.liveId, 30, 1);
  1657. if (res.code == 200) {
  1658. const rows = Array.isArray(res.rows) ? res.rows : [];
  1659. const reversedTalkList = [...rows].reverse();
  1660. this.talklist = Array.isArray(reversedTalkList) ? reversedTalkList : [];
  1661. // 获取历史消息后也滚动到底部
  1662. this.$nextTick(() => {
  1663. this.scrollToBottom();
  1664. });
  1665. } else {
  1666. this.talklist = [];
  1667. }
  1668. } catch (error) {
  1669. this.talklist = [];
  1670. console.error("获取聊天记录失败:", error);
  1671. }
  1672. },
  1673. generateRandomChineseName() {
  1674. const surnames = ['赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈',
  1675. '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许',
  1676. '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏',
  1677. '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦', '章',
  1678. '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦',
  1679. '风', '雪', '月', '星', '云', '海', '山', '林', '江', '河'
  1680. ];
  1681. const maleNames = ['伟', '强', '勇', '军', '磊', '超', '鹏', '杰', '建', '明',
  1682. '亮', '涛', '斌', '浩', '宇', '鑫', '帅', '博', '阳', '晨'
  1683. ];
  1684. const femaleNames = ['芳', '娜林', '敏', '静', '秀英', '丽若', '艳', '娟', '玲王',
  1685. '霞先', '燕', '颖', '洁高', '莹如', '雪', '梅', '婷', '雯', '欣白'
  1686. ];
  1687. const surname = surnames[Math.floor(Math.random() * surnames.length)];
  1688. const isMale = Math.random() > 0.5;
  1689. const givenName = isMale ?
  1690. maleNames[Math.floor(Math.random() * maleNames.length)] :
  1691. femaleNames[Math.floor(Math.random() * femaleNames.length)];
  1692. return surname + givenName;
  1693. },
  1694. // 获取直播间用户
  1695. async getliveUser(isLoadMore = false) {
  1696. this.viewLoading = true;
  1697. try {
  1698. const res = await watchUserList(this.liveId, this.viewPageSize, this.viewPageNum, false);
  1699. if (res.code === 200) {
  1700. const userRows = Array.isArray(res.rows) ? res.rows : [];
  1701. let array = userRows.map(item => ({
  1702. avatar: item.avatar || '',
  1703. userId: item.userId || '',
  1704. nickName: item.nickName || '未命名'
  1705. }));
  1706. // 虚拟数据
  1707. let virtualData = []
  1708. let virtualTotal = res.total * 2 + 50
  1709. this.liveUserTotal = virtualTotal
  1710. for (let i = 0; i < virtualTotal; i++) {
  1711. let data = {
  1712. avatar: '',
  1713. userId: '8565' + i,
  1714. nickName: this.generateRandomChineseName()
  1715. }
  1716. virtualData.push(data)
  1717. }
  1718. this.liveViewersData = [...array, ...virtualData]
  1719. const newRows = Array.isArray(res.rows) ? res.rows : [];
  1720. const currentViewers = Array.isArray(this.liveViewers) ? this.liveViewers : [];
  1721. let viewlist = isLoadMore ? [...currentViewers, ...newRows] : newRows;
  1722. this.liveViewers = [...viewlist, ...virtualData]
  1723. this.viewPageNum++;
  1724. }
  1725. } catch (error) {
  1726. console.error('获取观众列表失败:', error);
  1727. } finally {
  1728. this.viewLoading = false;
  1729. }
  1730. },
  1731. //小黄车搜索商品
  1732. handleSearchInput() {
  1733. // 使用防抖优化性能,避免频繁请求
  1734. clearTimeout(this.searchTimer);
  1735. this.searchTimer = setTimeout(() => {
  1736. this.queryCollect();
  1737. }, 500); // 500毫秒延迟
  1738. },
  1739. // 显示购买提示信息
  1740. showPurchaseMessage() {
  1741. // 清除之前的定时器
  1742. if (this.purchasePromptTimer) {
  1743. clearTimeout(this.purchasePromptTimer);
  1744. }
  1745. // 显示提示
  1746. this.showPurchasePrompt = true;
  1747. // 2秒后自动隐藏
  1748. this.purchasePromptTimer = setTimeout(() => {
  1749. this.showPurchasePrompt = false;
  1750. }, 2000);
  1751. },
  1752. //名字超过省略
  1753. truncateString(str, maxLength) {
  1754. if (typeof str !== 'string' || str.length <= maxLength) {
  1755. return str;
  1756. }
  1757. return str.slice(0, maxLength) + '...'; // 截断后加省略号
  1758. },
  1759. // 跳转页面
  1760. navgetTo(url) {
  1761. uni.navigateTo({
  1762. url: url
  1763. })
  1764. },
  1765. // 修改获取直播信息方法
  1766. async getliving(liveId) {
  1767. if (!liveId) return;
  1768. const param = {
  1769. id: liveId
  1770. };
  1771. try {
  1772. const res = await getlive(param);
  1773. if (res.code !== 200) {
  1774. uni.showToast({
  1775. title: res.msg,
  1776. icon: 'none'
  1777. });
  1778. return;
  1779. }
  1780. this.liveItem = Object.assign({}, this.liveItem, res.data);
  1781. this.talklist = Array.isArray((res.data || {}).talklist) ? res.data.talklist : [];
  1782. this.startTimeTimer(this.liveItem);
  1783. // 清除旧定时器(如预告倒计时)
  1784. if (this.liveStartTimer) {
  1785. clearInterval(this.liveStartTimer);
  1786. this.liveStartTimer = null;
  1787. }
  1788. if (res.data.status == 1) {
  1789. // 直播预告
  1790. this.liveStartTimer = setInterval(async () => {
  1791. this.liveCountdown = this.handleTime(res.data.startTime, 0);
  1792. if (!this.liveCountdown) {
  1793. uni.removeStorageSync('isAgreement');
  1794. await this.getliving(this.liveId);
  1795. clearInterval(this.liveStartTimer);
  1796. }
  1797. }, 1000);
  1798. this.$set(this.liveItem, 'previewUrl', res.data.previewUrl);
  1799. this.$set(this.liveItem, 'livingUrl', ''); // 清空直播流
  1800. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  1801. } else if (res.data.status == 2) {
  1802. if (res.data.liveType == 1) {
  1803. // 直播流
  1804. let cTime = Math.floor(Math.random() * 10000) + 1;
  1805. let livingUrl = res.data.flvHlsUrl + "&t=" + cTime;
  1806. console.log("地址在", this.liveItem.livingUrl)
  1807. this.$set(this.liveItem, 'livingUrl', livingUrl);
  1808. this.$set(this.liveItem, 'videoUrl', ''); // 清空回放视频
  1809. } else if (res.data.liveType === 2) {
  1810. // 回放视频 2录播 3直播回放
  1811. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  1812. this.$set(this.liveItem, 'livingUrl', '');
  1813. }
  1814. } else if (res.data.status == 4 && res.data.liveType == 3) {
  1815. this.$set(this.liveItem, 'videoUrl', res.data.videoUrl);
  1816. this.$set(this.liveItem, 'livingUrl', '');
  1817. } else {
  1818. // 未开播
  1819. this.$set(this.liveItem, 'livingUrl', '');
  1820. this.$set(this.liveItem, 'videoUrl', '');
  1821. }
  1822. this.$set(this.liveItem, 'autoplay', res.data.liveType !== 0);
  1823. this.$set(this.liveItem, 'showType', res.data.showType);
  1824. this.storeId = res.storeId;
  1825. // 2. 启动“10秒刷新直播间数据”的定时器
  1826. this.startLiveViewDataTimer();
  1827. this.playVideo();
  1828. } catch (err) {
  1829. console.error("获取直播信息失败:", err);
  1830. uni.showToast({
  1831. title: "获取直播信息失败",
  1832. icon: 'none'
  1833. });
  1834. }
  1835. },
  1836. getPureDecimal(num, precision = 6) {
  1837. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  1838. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  1839. },
  1840. goBack() {
  1841. // 暂停当前视频
  1842. if (this.liveItem) {
  1843. this.pauseVideo();
  1844. }
  1845. // 关闭WebSocket连接
  1846. this.closeWebSocket(true);
  1847. // 导航返回
  1848. const pages = getCurrentPages();
  1849. if (pages.length > 1) {
  1850. uni.navigateBack();
  1851. } else {
  1852. uni.reLaunch({
  1853. url: '/pages_course/livingList'
  1854. });
  1855. }
  1856. },
  1857. // 点赞
  1858. async onLike() {
  1859. if (!this.liveId) return;
  1860. try {
  1861. const res = await liveDataLike(this.liveId);
  1862. if (res?.like) {
  1863. this.liveViewData.like++; // 只更新当前直播间的点赞数
  1864. } else {
  1865. uni.showToast({
  1866. title: res.msg,
  1867. icon: 'none'
  1868. });
  1869. }
  1870. } catch (error) {
  1871. console.error('点赞失败:', error);
  1872. }
  1873. },
  1874. //直播间点赞、关注、在线人数数据
  1875. getliveViewData(liveItem) {
  1876. if (!liveItem || !this.liveId) return;
  1877. getLiveViewData(this.liveId).then(res => {
  1878. if (res.code == 200) {
  1879. // 强制响应式更新,确保数据实时显示
  1880. this.liveViewData = res;
  1881. }
  1882. }).catch(error => {
  1883. console.error("获取直播间数据失败:", error);
  1884. // 失败时兜底,避免显示异常
  1885. this.liveViewData = {
  1886. like: 0,
  1887. watchCount: 0
  1888. };
  1889. });
  1890. },
  1891. startLiveViewDataTimer() {
  1892. // 先清除旧定时器(防止重复创建)
  1893. if (this.liveViewDataTimer) {
  1894. clearInterval(this.liveViewDataTimer);
  1895. this.liveViewDataTimer = null;
  1896. }
  1897. // 启动新定时器,每3秒执行一次
  1898. this.liveViewDataTimer = setInterval(() => {
  1899. // 安全校验:确保liveItem和liveId存在(避免无效请求)
  1900. if (this.liveItem && this.liveId) {
  1901. this.getliveViewData(this.liveItem);
  1902. }
  1903. }, 10000);
  1904. },
  1905. // 去购买,跳商品详情
  1906. goShop(productId, goodsId) {
  1907. if (!this.liveId) return;
  1908. uni.navigateTo({
  1909. url: '/pages_shopping/live/goods?productId=' + productId + '&liveId=' + this.liveId +
  1910. '&goodsId=' +
  1911. goodsId + '&storeId=' + this.storeId
  1912. })
  1913. },
  1914. // 查询店铺
  1915. async queryCollect() {
  1916. this.loadingProducts = true;
  1917. if (!this.liveId) return;
  1918. if (this.inputInfo == null) this.inputInfo = ''
  1919. uni.showLoading({
  1920. title: '加载中'
  1921. });
  1922. try {
  1923. const res = await liveStore(this.liveId, this.inputInfo);
  1924. uni.hideLoading()
  1925. this.shopping = true
  1926. if (res.code === 200) {
  1927. // 数据绑定到当前 liveItem,避免全局污染
  1928. this.products = Array.isArray(res.data) ? res.data : [];
  1929. }
  1930. } catch (error) {
  1931. console.error('获取小黄车商品失败:', error);
  1932. } finally {
  1933. this.loadingProducts = false;
  1934. }
  1935. },
  1936. // 时间戳
  1937. initTime() {
  1938. const now = new Date();
  1939. this.timestamp = now.getTime();
  1940. },
  1941. openCart() {
  1942. this.queryCollect()
  1943. },
  1944. close() {
  1945. this.showadd = false
  1946. },
  1947. // 关闭小黄车
  1948. closeShop() {
  1949. this.shopping = false;
  1950. },
  1951. closeMore() {
  1952. this.isMore = false;
  1953. },
  1954. // 关闭WebSocket连接(isManual:是否手动关闭)
  1955. closeWebSocket(isManual = true) {
  1956. if (!this.socket || !this.isSocketOpen) {
  1957. console.warn("WebSocket 任务不存在或未打开,无需关闭");
  1958. return;
  1959. }
  1960. // console.log("websocket 连接关闭");
  1961. this.isManualClose = isManual;
  1962. this.stopHeartBeat();
  1963. this.resetReconnectState();
  1964. try {
  1965. // 先保存引用,避免在关闭过程中被置为null
  1966. const socketToClose = this.socket;
  1967. this.socket = null;
  1968. this.isSocketOpen = false;
  1969. socketToClose.close({
  1970. code: 1000,
  1971. reason: isManual ? "主动关闭" : "异常关闭"
  1972. });
  1973. console.log("WebSocket连接已发起关闭");
  1974. } catch (err) {
  1975. console.error("关闭WebSocket失败:", err);
  1976. // 即使关闭失败,也要重置状态
  1977. this.socket = null;
  1978. this.isSocketOpen = false;
  1979. }
  1980. },
  1981. startHeartBeat() {
  1982. this.stopHeartBeat(); // 先停止现有心跳,防止重复
  1983. this.sendHeartBeat(); // 立即发送一次心跳
  1984. // 按间隔循环发送心跳
  1985. this.heartBeatTimer = setInterval(() => {
  1986. this.sendHeartBeat();
  1987. }, this.heartBeatInterval);
  1988. },
  1989. initSocket() {
  1990. if (this.isConnecting) {
  1991. return;
  1992. }
  1993. // 如果已经存在连接且状态为open,则退出
  1994. if (this.socket && this.socket.readyState === 1) {
  1995. return;
  1996. }
  1997. if (this.socket && (this.socket.readyState === 0 || this.socket.readyState === 1)) {
  1998. console.log('关闭现有WebSocket连接,创建新连接');
  1999. this.closeWebSocket(true);
  2000. }
  2001. // 校验必要参数
  2002. if (!this.liveId) {
  2003. console.error("缺失直播间ID,无法初始化WebSocket");
  2004. return;
  2005. }
  2006. if (!this.userData || !this.userData.userId) {
  2007. console.error("用户信息缺失,无法初始化WebSocket");
  2008. return;
  2009. }
  2010. // 清除之前的重连定时器
  2011. this.resetReconnectState();
  2012. const now = new Date();
  2013. this.timestamp = now.getTime(); // 生成签名
  2014. const signature = CryptoJS.HmacSHA256(
  2015. `${this.liveId}${this.userData.userId}${this.userType}${this.timestamp}`,
  2016. this.timestamp.toString()
  2017. ).toString(CryptoJS.enc.Hex);
  2018. try {
  2019. const baseWsUrl = 'wss://api.fhhx.runtzh.com/ws/app/webSocket';
  2020. // const baseWsUrl = 'ws://192.168.10.166:7114/ws/app/webSocket';
  2021. let wsUrl =
  2022. `${baseWsUrl}?userId=${this.userData.userId}&liveId=${this.liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`;
  2023. if (this.qrFrom) {
  2024. wsUrl += this.qrFrom;
  2025. }
  2026. const socketTask = uni.connectSocket({
  2027. url: wsUrl,
  2028. success: () => {
  2029. // console.log("Socket连接请求发送成功")
  2030. },
  2031. fail: (err) => {
  2032. console.error("Socket连接请求失败:", err);
  2033. this.handleReconnect();
  2034. }
  2035. });
  2036. // 连接打开事件
  2037. socketTask.onOpen((res) => {
  2038. // console.log("WebSocket连接已打开");
  2039. this.socket = socketTask;
  2040. this.isConnecting = false;
  2041. this.isSocketOpen = true;
  2042. this.reconnectCount = 0;
  2043. this.resetReconnectState();
  2044. this.heartBeatRetryCount = 0; // 重置心跳重试次数
  2045. this.shownEntryUsers.clear(); // 重连后重置进入提示记录
  2046. this.startHeartBeat();
  2047. });
  2048. // 消息接收事件
  2049. socketTask.onMessage((res) => {
  2050. try {
  2051. const data = JSON.parse(res.data);
  2052. // 处理服务端心跳响应
  2053. if (data.cmd === "heartBeatAck") {
  2054. this.stopHeartBeat(); // 清除当前超时检测
  2055. this.startHeartBeat(); // 重新启动心跳周期
  2056. return;
  2057. }
  2058. this.handleSocketMessage(res);
  2059. } catch (err) {
  2060. console.error("消息解析异常:", err);
  2061. }
  2062. });
  2063. // 连接错误事件
  2064. socketTask.onError((err) => {
  2065. console.error("WebSocket连接错误:", err);
  2066. this.isSocketOpen = false;
  2067. this.stopHeartBeat();
  2068. this.isConnecting = false;
  2069. this.handleReconnect(); // 错误直接触发重连
  2070. });
  2071. // 连接关闭事件
  2072. socketTask.onClose((res) => {
  2073. console.log("WebSocket连接关闭:", res);
  2074. this.isSocketOpen = false;
  2075. this.isConnecting = false;
  2076. this.stopHeartBeat(); // 清除心跳定时器
  2077. if (!this.isManualClose && this.reconnectCount < this.maxReconnectAttempts) {
  2078. this.handleReconnect();
  2079. } else {}
  2080. });
  2081. } catch (e) {
  2082. console.error("创建WebSocket异常:", e);
  2083. this.handleReconnect();
  2084. }
  2085. },
  2086. handleTime(time, duration) {
  2087. // 将time转换为毫秒级时间戳
  2088. let timeStamp;
  2089. // 如果time是数字且合理(毫秒级时间戳通常为13位左右的正数),视为有效时间戳
  2090. if (typeof time === 'number' && time > 0 && time < 9999999999999) {
  2091. timeStamp = time;
  2092. }
  2093. //如果是字符串,尝试解析为日期后转为时间戳
  2094. else if (typeof time === 'string' && time.trim() !== '') {
  2095. // 处理兼容性:将"2025-09-25 17:30:00"转为ISO格式"2025-09-25T17:30:00"
  2096. const isoTime = time.replace(' ', 'T');
  2097. const date = new Date(isoTime);
  2098. // 校验日期是否有效
  2099. if (!isNaN(date.getTime())) {
  2100. timeStamp = date.getTime();
  2101. } else {
  2102. console.error('无效的日期格式:', time);
  2103. return false; // 格式错误时返回false
  2104. }
  2105. } else {
  2106. console.error('time参数必须是有效的时间戳(数字)或日期字符串');
  2107. return false;
  2108. }
  2109. // 后续逻辑保持不变(基于转换后的timeStamp计算)
  2110. const targetTimestamp = timeStamp + duration * 60 * 1000;
  2111. const currentTimestamp = new Date().getTime();
  2112. const timeDiffMs = targetTimestamp - currentTimestamp;
  2113. if (timeDiffMs <= 0) {
  2114. return false;
  2115. }
  2116. const hours = Math.floor(timeDiffMs / (1000 * 60 * 60));
  2117. const minutes = Math.floor((timeDiffMs % (1000 * 60 * 60)) / (1000 * 60));
  2118. const seconds = Math.floor((timeDiffMs % (1000 * 60)) / 1000);
  2119. const formatNum = (num) => num.toString().padStart(2, "0");
  2120. return {
  2121. hours: formatNum(hours),
  2122. minutes: formatNum(minutes),
  2123. seconds: formatNum(seconds)
  2124. };
  2125. },
  2126. // 处理Socket消息
  2127. async handleSocketMessage(message) {
  2128. let data = JSON.parse(message.data)
  2129. const socketMessage = data.data // 服务端返回的消息体
  2130. if (data.code == 200) {
  2131. const messageData = {
  2132. ...socketMessage,
  2133. cmd: socketMessage.cmd || '', // 确保cmd字段存在
  2134. ts: Date.now() // 时间戳
  2135. };
  2136. // 处理服务端返回的sendMsg消息,加入本地列表
  2137. if (socketMessage.cmd == 'sendMsg') {
  2138. if (!this.isSocketAvailable()) {
  2139. uni.showToast({
  2140. title: '连接已断开,正在重试...',
  2141. icon: 'none'
  2142. });
  2143. this.handleReconnect(); // 主动触发重连
  2144. return;
  2145. }
  2146. const oldList = Array.isArray(this.talklist) ? this.talklist : [];
  2147. const newList = [...oldList, messageData];
  2148. this.talklist = newList;
  2149. // 1. 将消息追加到当前直播间的talklist中(响应式更新)
  2150. this.talklist = newList;
  2151. this.scrollToBottom();
  2152. // 2. 延迟下一帧滚动到最新消息(确保DOM已更新)
  2153. // this.$nextTick(() => {
  2154. // const lastIndex = this.talklist.length - 1;
  2155. // this.scrollIntoView = `list_${lastIndex}`;
  2156. // });
  2157. } else if (socketMessage.cmd == 'red') {
  2158. const redData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2159. this.redInfo = redData || {};
  2160. this.isShowRed = socketMessage.status === 1;
  2161. if (this.isShowRed) {
  2162. this.redTimer = setInterval(() => {
  2163. const redCountdown = this.handleTime(this.redInfo.updateTime, this.redInfo
  2164. .duration)
  2165. if (!redCountdown) {
  2166. this.isShowRed = false
  2167. clearInterval(this.redTimer)
  2168. }
  2169. }, 1000);
  2170. }
  2171. } else if (socketMessage.cmd == 'goods') {
  2172. const goodsData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2173. this.goodsCard = goodsData || {};
  2174. this.isShowGoods = socketMessage.status == 1;
  2175. } else if (socketMessage.cmd == 'coupon') {
  2176. const couponData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2177. this.couponInfo = couponData || {};
  2178. this.isShowCoupon = socketMessage.status === 1;
  2179. if (this.isShowCoupon) {}
  2180. } else if (socketMessage.cmd == 'lottery') {
  2181. const lotteryData = socketMessage.data ? JSON.parse(socketMessage.data) : {};
  2182. this.lotteryInfo = lotteryData || {};
  2183. this.isShowLottery = socketMessage.status === 1;
  2184. if (socketMessage.status != 1) {
  2185. this.isShowLotteryPop = false
  2186. }
  2187. // 清除已有定时器(无论状态是否为1,先清掉旧的)
  2188. clearTimeout(this.lotteryTimer);
  2189. if (this.isShowLottery) {
  2190. this.lotteryTimer = setInterval(() => {
  2191. this.countdown = this.handleTime(this.lotteryInfo.updateTime, this.lotteryInfo
  2192. .duration)
  2193. if (!this.countdown) {
  2194. console.log("倒计时", this.countdown)
  2195. this.isShowLottery = false;
  2196. this.isShowLotteryPop = false;
  2197. clearInterval(this.lotteryTimer)
  2198. }
  2199. }, 1000);
  2200. } else {
  2201. this.isShowLottery = false
  2202. }
  2203. } else if (socketMessage.cmd == 'entry') {
  2204. try {
  2205. if (!this.liveUserCalled) {
  2206. await this.getliveUser(false);
  2207. this.liveUserCalled = true;
  2208. }
  2209. const userIdToEntry = socketMessage.userId;
  2210. const existingIndex = this.liveViewersData.findIndex(item => item.userId ===
  2211. userIdToEntry);
  2212. if (existingIndex === -1) {
  2213. const liveViewers = {
  2214. userId: socketMessage.userId,
  2215. nickName: socketMessage.nickName,
  2216. avatar: socketMessage.avatar
  2217. }
  2218. this.liveViewersData.push(liveViewers);
  2219. this.liveUserTotal++;
  2220. }
  2221. // 解析用户ID(根据实际接口字段调整,此处假设data含userId)
  2222. const userData = JSON.parse(socketMessage.data || '{}');
  2223. const userId = userData.userId || socketMessage.userId; // 兼容不同字段
  2224. if (!userId) return; // 无用户ID不处理
  2225. // 仅新用户(未显示过)才触发提示
  2226. if (!this.shownEntryUsers.has(userId)) {
  2227. this.inAndOut = socketMessage;
  2228. this.showWelcomeMessage = true;
  2229. this.shownEntryUsers.add(userId); // 加入已显示集合
  2230. // 3秒后隐藏提示(可调整时长)
  2231. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  2232. this.welcomeTimer = setTimeout(() => {
  2233. this.showWelcomeMessage = false;
  2234. }, 3000);
  2235. }
  2236. } catch (err) {
  2237. console.error("解析entry用户数据失败:", err);
  2238. }
  2239. } else if (socketMessage.cmd == 'out') {
  2240. if (this.liveUserTotal > 0) {
  2241. const userIdToRemove = socketMessage.userId;
  2242. const index = this.liveViewersData.findIndex(item => item.userId === userIdToRemove);
  2243. if (index !== -1) {
  2244. this.liveViewersData.splice(index, 1);
  2245. this.liveUserTotal--; // 根据userId删除对应的用户数据
  2246. }
  2247. }
  2248. this.inAndOut = socketMessage;
  2249. this.showWelcomeMessage = true;
  2250. // 3秒后隐藏提示
  2251. if (this.welcomeTimer) clearTimeout(this.welcomeTimer);
  2252. this.welcomeTimer = setTimeout(() => {
  2253. this.showWelcomeMessage = false;
  2254. }, 3000);
  2255. } else if (socketMessage.cmd == 'live_start' || socketMessage.cmd ==
  2256. 'live_end') {
  2257. // 开始直播,关闭直播
  2258. if (this.liveStartTimer) {
  2259. clearInterval(this.liveStartTimer);
  2260. this.liveStartTimer = null;
  2261. }
  2262. if (this.redTimer) {
  2263. clearInterval(this.redTimer);
  2264. this.redTimer = null;
  2265. }
  2266. // 请求最新直播间数据
  2267. await this.getliving(this.liveId); // 注意:需用 await 确保数据更新完成
  2268. // 强制触发视图更新(兜底方案,若上述步骤仍不生效)
  2269. // this.$forceUpdate();
  2270. } else if (socketMessage.cmd == 'Integral') {
  2271. this.integral = {
  2272. msg: socketMessage.msg,
  2273. status: true
  2274. }
  2275. } else if (socketMessage.cmd == 'LotteryDetail') {
  2276. try {
  2277. this.prizeInfo = Array.isArray(JSON.parse(socketMessage.data || '[]')) ?
  2278. JSON.parse(socketMessage.data || '[]') : [];
  2279. } catch (err) {
  2280. console.error('解析抽奖结果失败:', err);
  2281. // 4. 异常时兜底为数组
  2282. this.prizeInfo = [];
  2283. }
  2284. this.isShowPrize = true;
  2285. this.isShowLottery = false;
  2286. this.isShowLotteryPop = false;
  2287. } else if (socketMessage.cmd == 'blockUser') {
  2288. uni.removeStorage({
  2289. key: 'AppToken',
  2290. success: () => {
  2291. uni.reLaunch({
  2292. url: '/pages/auth/login'
  2293. });
  2294. }
  2295. });
  2296. }
  2297. } else {
  2298. uni.showToast({
  2299. title: data.msg,
  2300. icon: 'none'
  2301. });
  2302. }
  2303. },
  2304. sendMsg(retries = 1) {
  2305. // 防止连续点击发送两次(短时锁定)
  2306. if (this.isSending) return;
  2307. this.isSending = true;
  2308. setTimeout(() => {
  2309. this.isSending = false;
  2310. }, 800); // 800ms 内禁止再次发送
  2311. const text = (this.value || '').trim();
  2312. if (!text) {
  2313. uni.showToast({
  2314. title: "不能发送空消息",
  2315. icon: 'none'
  2316. });
  2317. return;
  2318. }
  2319. if (!this.isSocketAvailable()) {
  2320. if (retries > 0) {
  2321. uni.showToast({
  2322. title: `连接不稳定,正在重试(${retries}次)...`,
  2323. icon: 'none'
  2324. });
  2325. // 延迟500ms重试,重试次数减1
  2326. setTimeout(() => this.sendMsg(retries - 1), 500);
  2327. } else {
  2328. uni.showToast({
  2329. title: '连接已断开,发送失败',
  2330. icon: 'none'
  2331. });
  2332. this.value = text; // 恢复输入框内容
  2333. }
  2334. return;
  2335. }
  2336. const liveId = this.liveId;
  2337. this.value = ''; // 立即清空输入框
  2338. // 构造发送给服务端的消息数据
  2339. const data = {
  2340. liveId,
  2341. userId: this.userData.userId,
  2342. userType: 0,
  2343. cmd: "sendMsg",
  2344. msg: text,
  2345. nickName: this.userData.nickname || '未命名',
  2346. avatar: this.userData.avatar || '/static/images/avatar.png'
  2347. };
  2348. // 发送socket消息
  2349. try {
  2350. this.socket.send({
  2351. data: JSON.stringify(data),
  2352. success: () => {
  2353. this.value = '';
  2354. },
  2355. fail: (err) => {
  2356. console.error("消息发送失败:", err);
  2357. if (retries > 0) {
  2358. uni.showToast({
  2359. title: `发送失败,正在重试(${retries}次)`,
  2360. icon: 'none'
  2361. });
  2362. setTimeout(() => this.sendMsg(retries - 1), 500);
  2363. } else {
  2364. uni.showToast({
  2365. title: '发送失败,请稍后再试',
  2366. icon: 'none'
  2367. });
  2368. this.value = text; // 恢复输入框内容
  2369. }
  2370. }
  2371. });
  2372. } catch (err) {
  2373. console.error("发送消息异常:", err);
  2374. if (retries > 0) {
  2375. setTimeout(() => this.sendMsg(retries - 1), 500);
  2376. } else {
  2377. uni.showToast({
  2378. title: '发送失败,请稍后再试',
  2379. icon: 'none'
  2380. });
  2381. this.value = text;
  2382. }
  2383. }
  2384. }
  2385. }
  2386. };
  2387. </script>
  2388. <style scoped lang="scss">
  2389. .skeleton-item {
  2390. display: flex;
  2391. padding: 20rpx;
  2392. background: #fff;
  2393. margin-bottom: 16rpx;
  2394. border-radius: 16rpx;
  2395. }
  2396. .skeleton-img {
  2397. width: 200rpx;
  2398. height: 200rpx;
  2399. background: #f0f0f0;
  2400. border-radius: 8rpx;
  2401. margin-right: 24rpx;
  2402. animation: pulse 1.5s ease-in-out infinite;
  2403. }
  2404. .skeleton-content {
  2405. flex: 1;
  2406. }
  2407. .skeleton-line {
  2408. height: 20rpx;
  2409. background: #f0f0f0;
  2410. margin-bottom: 16rpx;
  2411. border-radius: 4rpx;
  2412. animation: pulse 1.5s ease-in-out infinite;
  2413. }
  2414. .skeleton-line.short {
  2415. width: 60%;
  2416. }
  2417. .skeleton-line.medium {
  2418. width: 80%;
  2419. }
  2420. .skeleton-line.long {
  2421. width: 95%;
  2422. }
  2423. @keyframes pulse {
  2424. 0% {
  2425. opacity: 1;
  2426. }
  2427. 50% {
  2428. opacity: 0.5;
  2429. }
  2430. 100% {
  2431. opacity: 1;
  2432. }
  2433. }
  2434. ::v-deep .u-icon--right {
  2435. justify-content: flex-end !important;
  2436. }
  2437. // 无头像用户文字样式
  2438. .text-white {
  2439. color: #ffffff;
  2440. }
  2441. .text-xs {
  2442. font-size: 18rpx;
  2443. }
  2444. .text-sm {
  2445. font-size: 24rpx;
  2446. }
  2447. .w52,
  2448. .w72 {
  2449. display: flex;
  2450. align-items: center;
  2451. justify-content: center;
  2452. }
  2453. .swiper-wrapper {
  2454. position: relative;
  2455. width: 100%;
  2456. height: 100vh;
  2457. overflow: hidden;
  2458. background-color: #000000;
  2459. .container {
  2460. width: 100%;
  2461. height: 100%;
  2462. position: relative;
  2463. transition: opacity 0.3s ease;
  2464. transform: translateZ(0);
  2465. will-change: opacity;
  2466. }
  2467. }
  2468. /* button自带样式清除 */
  2469. button::after {
  2470. border: none !important;
  2471. padding: 0 !important;
  2472. margin: 0 !important;
  2473. }
  2474. button {
  2475. background-color: transparent !important;
  2476. padding: 0 !important;
  2477. line-height: inherit !important;
  2478. margin: 0 !important;
  2479. width: auto !important;
  2480. font-weight: 500 !important;
  2481. border-radius: none !important;
  2482. }
  2483. .welcome-message {
  2484. position: fixed;
  2485. width: 100%;
  2486. bottom: 38vh;
  2487. left: 50%;
  2488. transform: translateX(-50%);
  2489. color: white;
  2490. padding: 10px 20px;
  2491. border-radius: 20px;
  2492. z-index: 10;
  2493. transition: opacity 0.3s ease;
  2494. }
  2495. .send {
  2496. background-color: #fafafa;
  2497. border-radius: 28rpx;
  2498. padding: 14rpx 16rpx;
  2499. color: #181818;
  2500. font-weight: 500;
  2501. }
  2502. .talk-list {
  2503. will-change: transform; // 提示浏览器优化
  2504. contain: layout style paint; // 限制渲染范围
  2505. max-width: 100%;
  2506. border-radius: 30rpx;
  2507. background-color: rgba(33, 33, 33, 0.5);
  2508. padding: 10rpx 30rpx;
  2509. }
  2510. .content {
  2511. position: relative;
  2512. z-index: 2;
  2513. height: 100%;
  2514. width: 100%;
  2515. top: 0;
  2516. left: 0;
  2517. display: flex;
  2518. flex-direction: column;
  2519. justify-content: space-between;
  2520. .activity-box {
  2521. position: fixed;
  2522. top: 188rpx;
  2523. left: 30rpx;
  2524. z-index: 5;
  2525. display: flex;
  2526. align-items: center;
  2527. .item-box {
  2528. border-radius: 16rpx;
  2529. background-color: rgba(77, 77, 77, 0.5);
  2530. width: 90rpx;
  2531. height: 100rpx;
  2532. margin-right: 20rpx;
  2533. position: relative;
  2534. z-index: 999;
  2535. .tip {
  2536. position: absolute;
  2537. width: 100%;
  2538. bottom: 0;
  2539. color: #fafcff;
  2540. font-size: 26rpx;
  2541. background-color: rgba(15, 15, 15, 0.8);
  2542. border-radius: 16rpx;
  2543. text-align: center;
  2544. }
  2545. .item {
  2546. margin: 0 auto;
  2547. padding: 10rpx 0;
  2548. .img {
  2549. height: 100%;
  2550. }
  2551. }
  2552. }
  2553. }
  2554. // 减少重绘
  2555. .side-group,
  2556. .content-top {
  2557. will-change: transform;
  2558. }
  2559. .side-group {
  2560. position: absolute;
  2561. top: 65%;
  2562. right: 30rpx;
  2563. z-index: 1000;
  2564. display: flex;
  2565. flex-direction: column;
  2566. align-items: center;
  2567. .side-item {
  2568. font-weight: 500;
  2569. font-size: 24rpx;
  2570. color: #FFFFFF;
  2571. margin-bottom: 32rpx;
  2572. text-align: center;
  2573. .image {
  2574. width: 72rpx;
  2575. height: 72rpx;
  2576. }
  2577. }
  2578. }
  2579. .content-top {
  2580. width: 100%;
  2581. margin-top: 48rpx;
  2582. display: flex;
  2583. justify-content: space-between;
  2584. padding: 0 24rpx;
  2585. box-sizing: border-box;
  2586. .sum {
  2587. width: 80rpx;
  2588. height: 52rpx;
  2589. background: rgba(0, 0, 0, 0.5);
  2590. border-radius: 26rpx 26rpx 26rpx 26rpx;
  2591. font-size: 24rpx;
  2592. color: #FFFFFF;
  2593. text-align: center;
  2594. line-height: 52rpx;
  2595. }
  2596. }
  2597. .follow-btn {
  2598. padding: 8rpx 16rpx;
  2599. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  2600. border-radius: 26rpx;
  2601. font-weight: 500;
  2602. font-size: 26rpx;
  2603. color: #FFFFFF;
  2604. }
  2605. }
  2606. .trailer-box {
  2607. position: relative;
  2608. top: 15%;
  2609. display: flex;
  2610. flex-direction: column;
  2611. align-items: center;
  2612. color: #ffffff;
  2613. padding: 20rpx;
  2614. .button {
  2615. margin-top: 20rpx;
  2616. background: #6d7bd4;
  2617. color: #fff;
  2618. border-radius: 20rpx;
  2619. padding: 20rpx 30rpx;
  2620. position: relative;
  2621. z-index: 99999;
  2622. }
  2623. .ash {
  2624. background: #636363;
  2625. }
  2626. .countdown-item {
  2627. display: flex;
  2628. flex-direction: column;
  2629. align-items: center;
  2630. .white {
  2631. width: 60rpx;
  2632. height: 60rpx;
  2633. text-align: center;
  2634. overflow: hidden;
  2635. background: #FFFFFF;
  2636. border-radius: 8rpx;
  2637. margin: 30rpx 10rpx 0;
  2638. font-weight: 600;
  2639. font-size: 24rpx;
  2640. color: #000000;
  2641. line-height: 60rpx;
  2642. }
  2643. }
  2644. .item {
  2645. width: 100%;
  2646. height: 400rpx;
  2647. }
  2648. .name {
  2649. font-size: 34rpx;
  2650. }
  2651. .img {
  2652. margin-bottom: 40rpx;
  2653. width: 240rpx;
  2654. height: 240rpx;
  2655. }
  2656. .title {
  2657. margin-top: 30rpx;
  2658. font-size: 42rpx;
  2659. font-weight: 500;
  2660. }
  2661. }
  2662. .videolist {
  2663. position: relative;
  2664. height: 100vh;
  2665. width: 100%;
  2666. .video {
  2667. transform: translateZ(0);
  2668. backface-visibility: hidden;
  2669. perspective: 1000;
  2670. height: 100vh;
  2671. width: 100%;
  2672. // background-color: rgba(57, 57, 57, 0.4);
  2673. .item {
  2674. width: 100%;
  2675. height: 100%;
  2676. }
  2677. .time {
  2678. color: #ffffff;
  2679. font-size: 20rpx;
  2680. margin-left: 10rpx;
  2681. }
  2682. .end {
  2683. position: absolute;
  2684. top: 50%;
  2685. left: 50%;
  2686. transform: translate(-50%, -50%);
  2687. font-size: 36rpx;
  2688. color: #fff;
  2689. }
  2690. .lable {
  2691. position: absolute;
  2692. top: 50rpx;
  2693. right: 16rpx;
  2694. background-color: rgba(57, 57, 57, 0.6);
  2695. padding: 4rpx 10rpx;
  2696. color: #fff;
  2697. border-radius: 15rpx;
  2698. }
  2699. }
  2700. .video_row {
  2701. position: absolute;
  2702. top: 20%;
  2703. max-height: 450rpx;
  2704. z-index: 99;
  2705. }
  2706. }
  2707. .prize-card {
  2708. width: 504rpx;
  2709. padding: 40rpx 40rpx 30rpx;
  2710. box-sizing: border-box;
  2711. display: flex;
  2712. flex-direction: column;
  2713. border-radius: 20rpx;
  2714. align-items: center;
  2715. background: linear-gradient(180deg, #f7823f 0%, #ffd4be 27%, #ffffff 100%);
  2716. position: relative;
  2717. .nav-img {
  2718. width: 311rpx;
  2719. position: absolute;
  2720. top: -122rpx;
  2721. left: 50%;
  2722. transform: translateX(-50%);
  2723. }
  2724. .title {
  2725. color: #C32008;
  2726. font-size: 34rpx;
  2727. font-weight: 600;
  2728. margin: 20rpx 0 40rpx;
  2729. }
  2730. .prize-content {
  2731. width: 100%;
  2732. display: flex;
  2733. justify-content: space-between;
  2734. align-items: center;
  2735. font-size: 28rpx;
  2736. margin: 10rpx 0;
  2737. .txt {
  2738. font-weight: 600;
  2739. }
  2740. }
  2741. .tip {
  2742. font-size: 28rpx;
  2743. color: #414141;
  2744. margin: 40rpx 0;
  2745. }
  2746. .button {
  2747. width: 200rpx;
  2748. height: 70rpx;
  2749. line-height: 70rpx;
  2750. background: linear-gradient(180deg, #ff7c30 0%, #FF3A1E 100%);
  2751. border-radius: 28rpx;
  2752. font-weight: 500;
  2753. font-size: 32rpx;
  2754. color: #ffffff;
  2755. text-align: center;
  2756. }
  2757. }
  2758. .no-prize-card {
  2759. width: 504rpx;
  2760. padding: 40rpx 40rpx 30rpx;
  2761. box-sizing: border-box;
  2762. display: flex;
  2763. flex-direction: column;
  2764. border-radius: 20rpx;
  2765. align-items: center;
  2766. position: relative;
  2767. .img {
  2768. margin-top: 40rpx;
  2769. width: 300rpx;
  2770. height: 300rpx;
  2771. }
  2772. .tip {
  2773. font-size: 36rpx;
  2774. color: #414141;
  2775. margin: 40rpx 0;
  2776. }
  2777. .button {
  2778. width: 220rpx;
  2779. height: 80rpx;
  2780. line-height: 80rpx;
  2781. background: linear-gradient(180deg, #fdfbb8 0%, #b79243 100%);
  2782. border-radius: 28rpx;
  2783. font-weight: 500;
  2784. font-size: 32rpx;
  2785. color: #ffffff;
  2786. text-align: center;
  2787. }
  2788. }
  2789. .red-card {
  2790. width: 550rpx;
  2791. height: 636rpx;
  2792. position: relative;
  2793. .img {
  2794. position: absolute;
  2795. width: 100%;
  2796. height: 100%;
  2797. }
  2798. .red-content {
  2799. position: relative;
  2800. z-index: 5;
  2801. display: flex;
  2802. flex-direction: column;
  2803. align-items: center;
  2804. .title {
  2805. font-size: 36rpx;
  2806. color: #FF3A1E;
  2807. margin: 180rpx 0 90rpx;
  2808. }
  2809. .txt {
  2810. font-size: 28rpx;
  2811. color: #FFECC3;
  2812. margin: 80rpx 0 40rpx;
  2813. }
  2814. .button {
  2815. width: 392rpx;
  2816. height: 96rpx;
  2817. line-height: 96rpx;
  2818. background: linear-gradient(180deg, #FFF4D5 0%, #FFE5B1 100%);
  2819. border-radius: 48rpx 48rpx 48rpx 48rpx;
  2820. font-weight: 600;
  2821. font-size: 36rpx;
  2822. color: #C32008;
  2823. text-align: center;
  2824. }
  2825. }
  2826. }
  2827. .integral-box {
  2828. min-width: 400rpx;
  2829. max-width: 600rpx;
  2830. display: flex;
  2831. flex-direction: column;
  2832. align-items: center;
  2833. border-radius: 20rpx;
  2834. overflow: hidden;
  2835. .top {
  2836. width: 100%;
  2837. position: relative;
  2838. .title {
  2839. width: 100%;
  2840. font-weight: 600;
  2841. font-size: 40rpx;
  2842. color: #FFFFFF;
  2843. text-shadow: 0px 4px 8px rgba(255, 89, 2, 0.8);
  2844. position: absolute;
  2845. top: 50rpx;
  2846. text-align: center;
  2847. }
  2848. .photo {
  2849. width: 100%;
  2850. }
  2851. }
  2852. .item {
  2853. padding: 20rpx;
  2854. .title {
  2855. font-weight: 500;
  2856. font-size: 32rpx;
  2857. text-align: center;
  2858. }
  2859. .button {
  2860. font-size: 32rpx;
  2861. margin-top: 20rpx;
  2862. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  2863. color: #fff;
  2864. text-align: center;
  2865. padding: 18rpx 60rpx;
  2866. border-radius: 10rpx;
  2867. font-weight: 500;
  2868. }
  2869. }
  2870. }
  2871. .goods {
  2872. position: fixed;
  2873. bottom: 140rpx;
  2874. right: 104rpx;
  2875. z-index: 5;
  2876. background-color: #fff;
  2877. border-radius: 20rpx;
  2878. overflow: hidden;
  2879. width: 280rpx;
  2880. padding: 4rpx;
  2881. .top {
  2882. position: absolute;
  2883. top: 4rpx;
  2884. display: flex;
  2885. justify-content: space-between;
  2886. align-items: center;
  2887. color: #fff;
  2888. width: 100%;
  2889. padding-right: 10rpx;
  2890. box-sizing: border-box;
  2891. .left {
  2892. background-color: rgba(0, 0, 0, 0.8);
  2893. padding: 12rpx;
  2894. font-size: 22rpx;
  2895. display: flex;
  2896. justify-content: space-between;
  2897. align-items: center;
  2898. border-radius: 10rpx;
  2899. }
  2900. }
  2901. .photo {
  2902. width: 100%;
  2903. height: 180rpx;
  2904. border-radius: 16rpx 16rpx 0 0;
  2905. overflow: hidden;
  2906. }
  2907. .item {
  2908. padding: 4rpx;
  2909. .price {
  2910. font-size: 30rpx;
  2911. .red {
  2912. color: #FF5701;
  2913. font-weight: 600;
  2914. margin-right: 10rpx;
  2915. }
  2916. .del {
  2917. color: #828282;
  2918. font-weight: 500;
  2919. font-size: 28rpx;
  2920. text-decoration: line-through
  2921. }
  2922. }
  2923. .title {
  2924. font-weight: 500;
  2925. font-size: 30rpx;
  2926. margin: 10rpx 0 12rpx;
  2927. }
  2928. .button {
  2929. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  2930. color: #fff;
  2931. text-align: center;
  2932. padding: 16rpx 0;
  2933. border-radius: 10rpx;
  2934. font-weight: 500;
  2935. font-size: 30rpx;
  2936. }
  2937. }
  2938. }
  2939. .coupon-pop {
  2940. position: fixed;
  2941. bottom: 140rpx;
  2942. right: 100rpx;
  2943. z-index: 5;
  2944. border-radius: 20rpx;
  2945. width: 320rpx;
  2946. .coupon-block {
  2947. width: 100%;
  2948. position: relative;
  2949. .item {
  2950. width: 100%;
  2951. position: absolute;
  2952. top: 20rpx;
  2953. display: flex;
  2954. flex-direction: column;
  2955. align-items: center;
  2956. color: #fff;
  2957. .title {
  2958. font-weight: 500;
  2959. font-size: 30rpx;
  2960. margin: 16rpx 0 12rpx;
  2961. }
  2962. .price {
  2963. font-size: 40rpx;
  2964. .bold {
  2965. font-size: 56rpx;
  2966. font-weight: 600;
  2967. }
  2968. }
  2969. .txt {
  2970. font-weight: 500;
  2971. font-size: 30rpx;
  2972. margin: 5rpx 0;
  2973. }
  2974. .button {
  2975. background: linear-gradient(270deg, #fffce1 0%, #ffeaaf 100%);
  2976. color: #ff0004;
  2977. text-align: center;
  2978. padding: 16rpx 0;
  2979. border-radius: 40rpx;
  2980. font-weight: 500;
  2981. font-size: 30rpx;
  2982. width: 70%;
  2983. margin-top: 26rpx;
  2984. }
  2985. }
  2986. .bg {
  2987. height: 432rpx;
  2988. width: 100%;
  2989. }
  2990. .nav {
  2991. position: absolute;
  2992. height: 120rpx;
  2993. top: -120rpx;
  2994. left: 0;
  2995. width: 100%;
  2996. z-index: 6;
  2997. }
  2998. .close {
  2999. position: absolute;
  3000. right: 10rpx;
  3001. top: 10rpx;
  3002. }
  3003. }
  3004. }
  3005. .icon-bg {
  3006. background-color: rgba(57, 57, 57, 0.8);
  3007. border-radius: 50%;
  3008. width: 88rpx;
  3009. height: 88rpx;
  3010. display: flex;
  3011. justify-content: center;
  3012. align-items: center;
  3013. transition: transform 0.2s ease;
  3014. }
  3015. .list {
  3016. width: 80%;
  3017. margin-bottom: 20rpx;
  3018. animation: xxxawdawd .2s;
  3019. }
  3020. @keyframes xxxawdawd {
  3021. from {
  3022. margin-top: 0rpx;
  3023. opacity: 0;
  3024. }
  3025. to {
  3026. // margin-top: 20rpx;
  3027. opacity: 1;
  3028. }
  3029. }
  3030. .shop-prompt {
  3031. position: absolute;
  3032. bottom: 750rpx;
  3033. left: 24rpx;
  3034. padding: 6rpx 20rpx;
  3035. background: rgba(230, 154, 34, 0.7);
  3036. border-radius: 24rpx;
  3037. z-index: 9;
  3038. font-weight: 500;
  3039. color: #FFFFFF;
  3040. transition: opacity 0.3s ease;
  3041. }
  3042. .view-box {
  3043. position: relative;
  3044. height: 40vh;
  3045. /* 设置弹出层高度为视窗高度的70% */
  3046. padding: 40rpx 0rpx 120rpx;
  3047. box-sizing: border-box;
  3048. display: flex;
  3049. flex-direction: column;
  3050. .scroll-content {
  3051. flex: 1;
  3052. margin-top: 50rpx;
  3053. overflow-y: auto;
  3054. padding: 0 40rpx;
  3055. }
  3056. .bottom {
  3057. padding: 20rpx 40rpx;
  3058. position: absolute;
  3059. bottom: 0;
  3060. width: 100%;
  3061. box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(195, 195, 195, 0.3);
  3062. background: #fff;
  3063. }
  3064. }
  3065. // 抽奖
  3066. .prize-box {
  3067. position: relative;
  3068. .nav-img {
  3069. width: 311rpx;
  3070. position: absolute;
  3071. top: -122rpx;
  3072. left: 50%;
  3073. transform: translateX(-50%);
  3074. }
  3075. .bg-img {
  3076. position: absolute;
  3077. top: 0;
  3078. left: 0;
  3079. width: 100%;
  3080. height: 100%;
  3081. z-index: 1;
  3082. }
  3083. .prize-content {
  3084. position: relative;
  3085. z-index: 2;
  3086. padding: 24rpx 0 68rpx;
  3087. .white-item {
  3088. width: 40rpx;
  3089. height: 40rpx;
  3090. text-align: center;
  3091. overflow: hidden;
  3092. background: #FFFFFF;
  3093. box-shadow: inset 0rpx 2rpx 8rpx 0rpx #FFEBB2;
  3094. border-radius: 8rpx;
  3095. margin: 4rpx;
  3096. font-weight: 600;
  3097. font-size: 24rpx;
  3098. color: #F85D22;
  3099. line-height: 40rpx;
  3100. }
  3101. .item-group {
  3102. width: 100%;
  3103. }
  3104. .point-group {
  3105. margin: 20rpx 0 50rpx;
  3106. display: flex;
  3107. gap: 6rpx;
  3108. .item {
  3109. width: 20rpx;
  3110. height: 8rpx;
  3111. background: rgba(255, 255, 255, 0.5);
  3112. border-radius: 4rpx 4rpx 4rpx 4rpx;
  3113. }
  3114. .selected {
  3115. background: #FFEB66;
  3116. }
  3117. }
  3118. .button {
  3119. margin-top: 30rpx;
  3120. width: 520rpx;
  3121. height: 88rpx;
  3122. line-height: 88rpx;
  3123. background: linear-gradient(180deg, #FFF4D6 0%, #FFEB66 100%);
  3124. box-shadow: 0rpx 10rpx 8rpx 4rpx rgba(246, 82, 25, 0.5);
  3125. border-radius: 44rpx;
  3126. font-weight: 500;
  3127. font-size: 36rpx;
  3128. color: #F4410B;
  3129. text-align: center;
  3130. }
  3131. }
  3132. }
  3133. .more-block {
  3134. border-radius: 20rpx 0 0 20rpx;
  3135. padding: 70rpx 30rpx;
  3136. display: flex;
  3137. justify-content: space-between;
  3138. .item {
  3139. text-align: center;
  3140. }
  3141. }
  3142. .shoppop {
  3143. padding: 22rpx 16rpx;
  3144. .shoppop-top {
  3145. display: flex;
  3146. justify-content: space-between;
  3147. align-items: center;
  3148. padding: 0 16rpx 22rpx;
  3149. .search-input {
  3150. width: 414rpx;
  3151. height: 76rpx;
  3152. background: #FFFFFF;
  3153. border-radius: 36rpx;
  3154. margin-left: 20rpx;
  3155. padding: 0 32rpx;
  3156. box-sizing: border-box;
  3157. font-size: 24rpx;
  3158. margin-right: 24rpx;
  3159. }
  3160. .search-top {
  3161. font-size: 20rpx;
  3162. color: #222222;
  3163. }
  3164. }
  3165. .shop-list {
  3166. overflow: hidden;
  3167. .list-item {
  3168. display: flex;
  3169. align-items: center;
  3170. padding: 20rpx 16rpx;
  3171. background: #FFFFFF;
  3172. border-radius: 16rpx;
  3173. margin-bottom: 16rpx;
  3174. .goods-img {
  3175. width: 200rpx;
  3176. height: 200rpx;
  3177. border-radius: 16rpx;
  3178. overflow: hidden;
  3179. position: relative;
  3180. margin-right: 24rpx;
  3181. .img {
  3182. width: 100%;
  3183. height: 100%;
  3184. }
  3185. .goods-label {
  3186. position: absolute;
  3187. top: 0;
  3188. width: 64rpx;
  3189. height: 40rpx;
  3190. background: rgba(0, 0, 0, 0.5);
  3191. border-radius: 16rpx 0rpx 16rpx 0rpx;
  3192. text-align: center;
  3193. font-weight: 500;
  3194. font-size: 28rpx;
  3195. color: #FFFFFF;
  3196. }
  3197. }
  3198. .goods-right {
  3199. flex: 1;
  3200. .goods-title {
  3201. font-weight: 500;
  3202. font-size: 30rpx;
  3203. color: #000000;
  3204. margin-bottom: 10rpx;
  3205. }
  3206. .goods-details {
  3207. font-size: 24rpx;
  3208. color: #999999;
  3209. margin: 10rpx 0 20rpx;
  3210. }
  3211. .goods-people {
  3212. font-size: 22rpx;
  3213. color: #E69A22;
  3214. height: 56rpx;
  3215. }
  3216. .goods-shop {
  3217. display: flex;
  3218. justify-content: space-between;
  3219. .nummber {
  3220. color: #FF5C03;
  3221. font-size: 22rpx;
  3222. font-weight: 500;
  3223. }
  3224. .btn-group {
  3225. text-align: center;
  3226. line-height: 56rpx;
  3227. .collect-btn {
  3228. width: 72rpx;
  3229. height: 100%;
  3230. background: #F5F7FA;
  3231. border-radius: 8rpx 0rpx 0rpx 8rpx;
  3232. }
  3233. .shop-btn {
  3234. width: 152rpx;
  3235. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  3236. border-radius: 0rpx 8rpx 8rpx 0rpx;
  3237. font-weight: 500;
  3238. font-size: 30rpx;
  3239. color: #FFFFFF;
  3240. }
  3241. }
  3242. }
  3243. }
  3244. }
  3245. }
  3246. }
  3247. </style>