living.vue 96 KB

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