living.vue 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686
  1. <template>
  2. <view class="swiper-wrapper">
  3. <swiper class="swiper-container" :current="currentSwiperIndex" :circular="false" vertical
  4. @change="onSwiperChange" :style="{height: '100vh'}" :duration="swiperDuration">
  5. <swiper-item v-for="(liveItem, index) in list" :key="liveItem.liveId">
  6. <view class="container" :class="{active: currentSwiperIndex === index}">
  7. <view class="blackbg"></view>
  8. <view class="content">
  9. <!-- 页面内容 -->
  10. <view style="position: fixed;top: 0;z-index: 5;" class="content-top">
  11. <view class="u-flex-y-center">
  12. <image @click="goBack" style="width: 60rpx;height: 64rpx;margin-right: 26rpx;"
  13. src="/static/images/live/return.png"></image>
  14. <view class="align-center"
  15. style="padding: 6rpx 4rpx;height: 64rpx;background: rgba(0,0,0,0.5);border-radius: 32rpx;">
  16. <u-avatar :src="liveItem.liveImgUrl||$img.logo" size="32"></u-avatar>
  17. <view class="colorf ml10 mr6">
  18. <view>{{liveItem.liveName?truncateString(liveItem.liveName,8):"未命名"}}</view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="u-flex-end align-center" @click="toggleViewerList" style="margin-top: 100rpx;">
  23. <image class="w52 h52 mr4" v-for="(item,viewerIndex) in filteredViewers"
  24. :key="viewerIndex" style="border-radius: 26rpx;" :src="item.avatar||$img.logo">
  25. </image>
  26. <view class="sum">{{liveUserTotal||0}}</view>
  27. </view>
  28. </view>
  29. <!-- 右边的 -->
  30. <view :class=" liveItem.showType==1 ? 'siderow-group' : 'side-group'">
  31. <view class="side-item">
  32. <image class="image" @click="onLike(liveItem)" src="/static/images/live/like.png">
  33. </image>
  34. <view>{{liveItem.liveViewData?.like||0}}</view>
  35. </view>
  36. <!-- <view class="side-item">
  37. <image @click="goStore(liveItem)" src="/static/images/live/shop.png"></image>
  38. <view>店铺</view>
  39. </view> -->
  40. <view class="side-item">
  41. <button open-type="share" class="button">
  42. <image class="image" src="/static/images/live/share.png" mode="widthFix"></image>
  43. </button>
  44. <view>分享</view>
  45. </view>
  46. </view>
  47. <!-- 红包内容 -->
  48. <view class="hongbao-box" v-if="liveItem.redInfo?.redStatus==1">
  49. <view class="u-flex-y-center">
  50. <view class="tip">领红包</view>
  51. <view class="item">
  52. <image @click="onRed(liveItem)" src="/static/images/redbag.png" mode="widthFix">
  53. </image>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="shop-prompt u-flex-y-center" v-if="showPurchasePrompt&&orderUser?.count">
  58. <image class="w32 h32 mr8" src="/static/images/live/shopping.png"></image>
  59. <text> {{orderUser.userName ? maskString(orderUser.userName) : ''}} 等
  60. {{orderUser.count || 0}}
  61. 人正在去购买</text>
  62. </view>
  63. <view class="videolist" style="margin: auto 0">
  64. <view class="video" style="height:100vh">
  65. <!-- 视频组件 -->
  66. <video v-if="currentSwiperIndex === index && liveItem.livingUrl"
  67. :id="'myVideo_' + liveItem.liveId"
  68. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.livingUrl"
  69. :autoplay="currentSwiperIndex === index" :controls='false' object-fit='contain'
  70. :custom-cache="false" :enable-progress-gesture="false"
  71. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"
  72. :http-cache="false" @error="videoError">
  73. </video>
  74. <video v-if="currentSwiperIndex === index && liveItem.videoUrl"
  75. :class="liveItem.showType == 1 ? 'video_row' : 'videotop'" :src="liveItem.videoUrl"
  76. :autoplay="currentSwiperIndex === index" :controls='false' object-fit='contain'
  77. :custom-cache="false" :enable-progress-gesture="false"
  78. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false"
  79. :http-cache="false" loop @error="videoError">
  80. </video>
  81. <view v-if="liveItem.videoUrl" class="time">{{liveItem.totalTime}}</view>
  82. </view>
  83. </view>
  84. <!-- 底部聊天区域 -->
  85. <view class="pb40 mt90" style="position: fixed;bottom: 0;width: 100%;">
  86. <view class="w100 h300 mt20">
  87. <scroll-view enable-flex scroll-y="true" class="talk p20 scrolly flex-1 column"
  88. style="width: calc(100% - 40rpx);height: calc(100% - 40rpx);"
  89. :scroll-into-view="liveItem.scrollIntoView">
  90. <view>
  91. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  92. :key="talkIndex" v-show="item.cmd=='announcement'">
  93. <view class="talk-list ml16 justify-start">
  94. <view class="fs24">
  95. <text class='fs24 colorf'>
  96. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  102. :key="talkIndex" :id="`list_${talkIndex}`"
  103. v-show="item.cmd!='red'&&item.cmd!='out'&&item.cmd!='entry'">
  104. <view class="talk-list ml16 justify-start">
  105. <view class="fs24">
  106. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  107. <text class='fs24 colorf'>{{item.msg}}</text>
  108. </view>
  109. </view>
  110. </view>
  111. <view v-if="liveItem.showWelcomeMessage" class="welcome-message">
  112. <view class="list justify-start" v-for="(item,talkIndex) in liveItem.talklist"
  113. :key="talkIndex" v-show="item.cmd=='entry'||item.cmd=='out'">
  114. <view class="talk-list ml16 justify-start">
  115. <view class="fs24">
  116. <text style="color: #ff89d6;">{{item.nickName}} </text>
  117. <text class='fs24 colorf'>
  118. {{item.msg}}直播间{{liveItem.messageContent}}</text>
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. </scroll-view>
  124. </view>
  125. <!-- 底部输入框和操作按钮 -->
  126. <view class="justify-between p24">
  127. <view class="u-flex-y-center"
  128. style="background:rgba(57, 57, 57, 0.8);padding:10rpx 14rpx 10rpx 32rpx;width: 580rpx;box-sizing:border-box;border-radius:36rpx;">
  129. <u-input :placeholder="liveItem.placeholderText" border="none"
  130. customStyle='font-size:24rpx;' v-model="liveItem.value" shape='circle'
  131. color='#fff' placeholderStyle='color:#e7e7e7' class="ml20">
  132. </u-input>
  133. <view class="send" @click="sendMsg(liveItem)">发送</view>
  134. </view>
  135. <view class="justify-between mr15 align-center">
  136. <!-- <view class="icon ml20" @click="onLike(liveItem)">
  137. <image src="/static/images/live/like.png" class="w56 h56"></image>
  138. <view>{{liveItem.liveViewData?.like||0}}</view>
  139. </view>
  140. <view class="icon ml20">
  141. <button open-type="share" class="button">
  142. <image src="/static/images/live/share.png" class="w56 h56"></image>
  143. </button>
  144. <view>分享</view>
  145. </view> -->
  146. <view class="icon-bg ml20" @click="openCart(liveItem)">
  147. <image src="/static/images/shopping.png" class="w48 h48"></image>
  148. </view>
  149. </view>
  150. </view>
  151. </view>
  152. <!-- 弹出商品 -->
  153. <!-- v-if="liveItem.goodsCard.isShow" -->
  154. <!-- <view class="goods">
  155. <view class="top">
  156. <view class="left">
  157. <image class="w30 h30 mr8" src="/static/images/signal.png"></image>讲解中
  158. </view>
  159. <image class="w30 h30" src="/static/images/close.png"
  160. @click="liveItem.goodsCard.isShow=false"></image>
  161. </view>
  162. <image class="photo" :src="liveItem.goodsCard.imgUrl"></image>
  163. <view class="item">
  164. <view class="price"><text class="red">¥{{liveItem.goodsCard.price}} </text><text
  165. class="del">¥{{liveItem.goodsCard.otPrice}}</text></view>
  166. <view class="title oneline-hide">{{liveItem.goodsCard.productName}}</view>
  167. <view class="button">立即抢购</view>
  168. </view>
  169. </view> -->
  170. </view>
  171. <u-popup :show="liveItem.goodsCard.isShow" @close="!liveItem.goodsCard.isShow" round='20rpx'
  172. mode="center" bgColor='#ffffff'>
  173. <view class="goods">
  174. <view class="top">
  175. <view class="left">
  176. <image class="w30 h30 mr8" src="/static/images/signal.png"></image>讲解中
  177. </view>
  178. <image class="w30 h30" src="/static/images/close.png"
  179. @click="liveItem.goodsCard.isShow=false"></image>
  180. </view>
  181. <image class="photo" :src="liveItem.goodsCard.imgUrl"></image>
  182. <view class="item">
  183. <view class="price"><text class="red">¥{{liveItem.goodsCard.price}} </text><text
  184. class="del">¥{{liveItem.goodsCard.otPrice}}</text></view>
  185. <view class="title oneline-hide">{{liveItem.goodsCard.productName}}</view>
  186. <view class="button"
  187. @click="goShop(liveItem.goodsCard.productId,liveItem.goodsCard.goodsId)">立即抢购</view>
  188. </view>
  189. </view>
  190. </u-popup>
  191. <!-- 抽奖 -->
  192. <!-- <u-popup :show="true" @close="" round='40rpx' bgColor='#fff'>
  193. <view class=" p20 bgf" style="border-radius: 40rpx;height: fit-content;">
  194. <view class="u-flex-row-reverse u-flex">
  195. <u-icon name="close" size="18" @click=""></u-icon>
  196. </view>
  197. <view class="column align-center h400">
  198. <view class="fs36 " style="color: #000000;font-weight: bold;">答题获取红包/积分奖励</view>
  199. <view class="answerpop" @click="noredanswer">
  200. <view class="color6 w350 fs24">
  201. 观看直播参与抽奖
  202. </view>
  203. <view class="answera">参与抽奖</view>
  204. </view>
  205. </view>
  206. </view>
  207. </u-popup> -->
  208. <u-popup :show="liveItem.integral?.status" @close="!liveItem.integral?.status" round='20rpx'
  209. mode="center" bgColor='#ffffff'>
  210. <view class="integral-box">
  211. <view class="top">
  212. <view class="title">观看视频领芳华币</view>
  213. <image class="photo" src="/static/images/integral.png" mode="widthFix"></image>
  214. </view>
  215. <view class="item">
  216. <view class="title ">{{liveItem.integral?.msg}}</view>
  217. <view class="button" @click="liveItem.integral.status=flase">确认</view>
  218. </view>
  219. </view>
  220. </u-popup>
  221. <!-- 观众列表弹窗 -->
  222. <u-popup :show="showadd" @close="close" @open="openViews" round='20rpx' bgColor='#ffffff'>
  223. <view class="view-box">
  224. <view class="t-c fs30">在线观众</view>
  225. <scroll-view scroll-y class="scroll-content" :style="{height: scrollHeight + 'px'}"
  226. @scrolltolower="handleScrollToLower">
  227. <view class="fs24 u-flex-y-center mb20" v-for="(item,index) in liveViewers"
  228. :key="index">
  229. <view
  230. :style="{color: index === 0 ? '#FF3B30' : index === 1 ? '#FF9500' : index === 2 ? '#FFCC00' : '#8E8E93',fontWeight: index < 3 ? 'bold' : 'normal',width: '50rpx'}"
  231. class="mr10">{{index+1}}</view>
  232. <u-avatar :src="item.avatar||$img.logo" size="32"></u-avatar>
  233. <text class="ml16">{{item.nickName||"未命名"}}</text>
  234. </view>
  235. <view class="no-more" v-if="viewNoMoreData && liveViewers.length > 0">
  236. <text>没有更多了</text>
  237. </view>
  238. </scroll-view>
  239. </view>
  240. </u-popup>
  241. <!-- 商品弹窗 -->
  242. <u-popup :show="liveItem.shopping" @close="closeShop" @open="openShop" round='20rpx'
  243. bgColor='f3f5f9'>
  244. <view class="shoppop">
  245. <view class="shoppop-top">
  246. <u-avatar :src="store.logoUrl" size="36" class="ml16"></u-avatar>
  247. <view class="search-input u-flex-y-center">
  248. <image style="width: 24rpx;margin-right: 16rpx;" src="/static/images/search.png"
  249. mode="widthFix">
  250. </image>
  251. <input placeholder="请搜索商品" v-model="liveItem.inputInfo"
  252. @input="handleSearchInput" />
  253. </view>
  254. <view class="t-c search-top" style="margin-right: 48rpx;">
  255. <image @click="onStoreCollect(liveItem)" v-if="store.isFavorite"
  256. style="width:40rpx;height: 40rpx;" src="/static/images/collect_select.png">
  257. </image>
  258. <image v-else @click="onStoreCollect(liveItem)" style="width: 32rpx;height: 32rpx;"
  259. src="/static/images/collect.png"></image>
  260. <view>收藏</view>
  261. </view>
  262. <view class="t-c search-top" @click="goOrderList(liveItem)">
  263. <image style="width: 40rpx;height: 40rpx;" src="/static/images/order.png"></image>
  264. <view>订单</view>
  265. </view>
  266. </view>
  267. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  268. <view class="list-item" v-for="(item,index) in products" :key="index">
  269. <view class="goods-img">
  270. <image :src="item.imgUrl" mode="widthFix"></image>
  271. <view class="goods-label">{{index+1}}</view>
  272. </view>
  273. <view class="goods-right">
  274. <view class="goods-title">{{item.productName}}</view>
  275. <view class="goods-people">{{item.sales}} 人已购</view>
  276. <view class="goods-shop">
  277. <text class="nummber"><text
  278. style="font-size: 20rpx;font-weight: 600;">¥</text><text
  279. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}/日</text>
  280. <view class="btn-group u-flex-y-center">
  281. <view class="collect-btn">
  282. <image v-if="item.isFavorite" @click="onGoodsCollect(item)"
  283. style="width: 32rpx;height: 32rpx;"
  284. src="/static/images/collect_select.png">
  285. </image>
  286. <image v-else @click="onGoodsCollect(item)"
  287. style="width: 32rpx;height: 32rpx;"
  288. src="/static/images/collect.png">
  289. </image>
  290. </view>
  291. <view v-if="item.status==1" class="shop-btn"
  292. @click="goShop(item.productId,item.goodsId)">去购买 </view>
  293. <view v-else-if="item.status==0" class="shop-btn">
  294. 已下架</view>
  295. </view>
  296. </view>
  297. </view>
  298. </view>
  299. </scroll-view>
  300. </view>
  301. </u-popup>
  302. </view>
  303. </swiper-item>
  304. </swiper>
  305. </view>
  306. </template>
  307. <script>
  308. import Hls from 'hls.js';
  309. import CryptoJS from 'crypto-js'
  310. import {
  311. liveList
  312. } from '@/api/list'
  313. import {
  314. liveRed, // 点击领红包
  315. liveDataLike, // 点赞
  316. collectStore, // 店铺收藏/取消收藏
  317. collectGoods, // 商品收藏/取消收藏
  318. store, // 查询店铺
  319. showGoods, //弹出商品卡片
  320. // follow, // 关注/取消关注
  321. watchUserList, //获取直播间用户(展示在线用户)
  322. liveMsg, //获取最近聊天记录
  323. // 小黄车
  324. liveStore, //店铺展示,
  325. // liveGoodsDetail, //商品详情,
  326. liveOrderUser, //正在购买
  327. getLiveInfo, //获取直播间信息接口
  328. getLiveViewData //直播间点赞、关注、在线人数数据
  329. } from '@/api/live'
  330. import {
  331. liveOrderList, // 订单列表
  332. } from '@/api/order'
  333. import parse from '/uni_modules/uview-plus/libs/config/props/parse';
  334. import {
  335. LiveWS
  336. } from '@/utils/liveWS.js'
  337. import {
  338. getlive,
  339. // gettextlist,
  340. getAnswerlist,
  341. submitAnswer
  342. } from '@/api/home'
  343. var wsUrl = "wss://live.test.ylrztop.com/ws/live-api/app/webSocket"; //余红奇
  344. // var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
  345. // var wsUrl = "ws://192.168.10.125:7114/app/webSocket"; //涂小龙
  346. // var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket"; //余红奇
  347. // var wsUrl = "ws://nd383294.natappfree.cc/app/webSocket"; //余红奇
  348. // var wsUrl = "ws://v56c9b8e.natappfree.cc/app/webSocket"; //余红奇
  349. // var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; //陈果
  350. // var wsUrl = "ws://live.ylrzcloud.com/socket/app/webSocket";
  351. var pingpangTimes = null;
  352. var initTimes = null;
  353. var isSocketOpen = false;
  354. var socket = null;
  355. export default {
  356. data() {
  357. return {
  358. // 新增:滑动节流相关变量
  359. lastSwiperChangeTime: 0, // 上次切换时间戳
  360. swiperChangeThrottle: 300, // 切换节流阈值(毫秒)
  361. lastClickTime: 0,
  362. clickDelay: 300, // 300ms内只响应一次点击
  363. connectingLiveId: null, // 记录正在连接的直播间ID
  364. swiperDuration: 0, // 初始化为0,首次加载无动画
  365. videoRetryCounts: {}, // 记录每个直播间的视频重试次数,格式: { liveId: 次数 }
  366. socketInstances: {}, // 改为对象存储多个socket实例
  367. currentSwiperIndex: 0, // 当前swiper索引
  368. list: [], // 直播间列表
  369. preloading: false, // 预加载状态
  370. liveUserTotal: null,
  371. viewPageSize: 10, // 每页数量
  372. viewPageNum: 1, // 当前页码
  373. viewLoading: false, // 是否正在加载
  374. viewNoMoreData: false, // 是否没有更多数据
  375. scrollHeight: 0,
  376. scrollTimer: null, // 滚动防抖定时器
  377. socketInstance: null, // 统一管理 socket 实例
  378. reconnectCount: 0,
  379. maxReconnectAttempts: 3,
  380. isManualClose: false, // 标记是否手动关闭
  381. showRed: true,
  382. // redInfo: {},
  383. // inputInfo: '',
  384. searchTimer: null,
  385. // storeId: null,
  386. reconnectTimer: null,
  387. isCollect: false,
  388. showPurchasePrompt: false,
  389. purchasePromptTimer: null,
  390. prevOrderCount: 0, // 用于记录上一次的购买人数
  391. videoUrl: null,
  392. showType: 1, //横屏1 竖屏2
  393. boxHeight: 300, //小黄车高度
  394. // isFollow: false,
  395. // liveViewData: {},
  396. liveViewers: [], //观众
  397. likeName: 0,
  398. hlsPlayer: null, // HLS播放器实例,
  399. livingUrl: "",
  400. products: {},
  401. store: {},
  402. orderUser: {}, //正在购买
  403. userType: 0,
  404. timestamp: '',
  405. liveId: null,
  406. // userId: uni.getStorageSync("userInfo.userId"),
  407. // isZoom: false, //点赞按钮控制是否放大
  408. userinfo: '', //用户信息
  409. // path: 'http://192.168.10.166/dev-api', //余红奇
  410. // path: 'http://v56c9b8e.natappfree.cc', //余红奇
  411. // path: 'live.test.ylrztop.com/prod-api', //余红奇
  412. // path: 'http://192.168.10.170/dev-api', //陈果
  413. // value: '',
  414. talkdisabled: false, //输入框是否禁用
  415. autoplay: false, //视频自动播放
  416. showadd: false,
  417. // talklist: [],
  418. scrollIntoView: '',
  419. videoContext: '',
  420. // thistime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
  421. // showWelcomeMessage: false,
  422. // isSubmit: false,
  423. // messageContent: "",
  424. // showziliao: false,
  425. // isScreen: true,
  426. // shopping: false, //小黄车弹窗
  427. // scrollTop: 0, //弹幕
  428. // old: {
  429. // scrollTop: 0
  430. // },
  431. livedata: {}, //直播间点赞、关注、在线人数数据
  432. };
  433. },
  434. onLoad(options) {
  435. this.initTime();
  436. if (options.liveId) {
  437. this.liveId = options.liveId; // 仅当 liveId 变化时更新
  438. }
  439. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  440. // 初始化直播间列表
  441. this.initLiveList(options);
  442. this.getliveUser(false); // 调用获取在线用户接口
  443. const platform = uni.getWindowInfo().platform;
  444. // 初始化直播间列表
  445. if (['mp-weixin', 'mp-alipay', 'mp-baidu', 'mp-toutiao'].includes(platform)) {
  446. // 确保 API 存在再调用
  447. if (uni.showShareMenu) {
  448. uni.showShareMenu({
  449. withShareTicket: true, // 可选参数,根据需求配置
  450. success: () => {
  451. console.log('分享菜单显示成功');
  452. },
  453. fail: (err) => {
  454. console.error('分享菜单显示失败:', err);
  455. }
  456. });
  457. } else {
  458. console.warn('当前平台不支持 uni.showShareMenu');
  459. }
  460. } else {
  461. // console.log('当前平台无需显示分享菜单');
  462. }
  463. },
  464. onReady() {},
  465. onShareAppMessage() {
  466. return {
  467. // title: this.product.title,
  468. title: this.livedata.liveName,
  469. path: '/pages/home/living',
  470. imageUrl: this.products.image,
  471. success(res) {
  472. console.log("分享成功", res);
  473. },
  474. fail(err) {
  475. console.error("分享失败", err);
  476. }
  477. };
  478. },
  479. computed: {
  480. filteredViewers() {
  481. if (!this.liveViewers) {
  482. return
  483. } else {
  484. return this.liveViewers.slice(0, 3);
  485. }
  486. }
  487. },
  488. onHide() {
  489. const currentLive = this.list[this.currentSwiperIndex];
  490. if (currentLive) {
  491. this.pauseVideo(currentLive);
  492. this.clearTimeTimer(currentLive); // 隐藏时清除当前直播间定时器
  493. } // 隐藏时关闭所有连接
  494. this.closeAllWebSockets();
  495. },
  496. onUnload() {
  497. // 清除所有直播间的时间定时器
  498. this.list.forEach(liveItem => {
  499. this.clearTimeTimer(liveItem);
  500. });
  501. // 关闭所有WebSocket连接
  502. this.closeAllWebSockets();
  503. this.socketInstances = {}; // 强制清空实例对象
  504. // 移除所有全局事件监听
  505. this.removeAllEventListeners();
  506. // 清理定时器
  507. this.clearAllTimers();
  508. // 销毁HLS播放器(如果使用了hls.js)
  509. if (this.hlsPlayer) {
  510. this.hlsPlayer.destroy();
  511. this.hlsPlayer = null;
  512. }
  513. this.list.forEach(liveItem => {
  514. const videoId = `myVideo_${liveItem.liveId}`;
  515. const videoContext = uni.createVideoContext(videoId, this);
  516. if (videoContext) {
  517. videoContext.pause(); // 仅暂停视频即可
  518. }
  519. });
  520. },
  521. watch: {
  522. // 监听orderUser.count的变化
  523. 'orderUser.count': {
  524. handler(newVal, oldVal) {
  525. if (newVal !== this.prevOrderCount) {
  526. this.prevOrderCount = newVal;
  527. this.showPurchaseMessage();
  528. }
  529. },
  530. immediate: true
  531. }
  532. },
  533. methods: { // 计算当前时间与 liveItem.startTime 的差值,并更新 totalTime
  534. calculateTimeDiff(liveItem) {
  535. // 1. 校验 startTime 格式(防止无效时间)
  536. if (!liveItem.startTime) {
  537. liveItem.totalTime = '00小时00分钟00秒';
  538. return;
  539. }
  540. const iosCompatibleTime = liveItem.startTime
  541. .replace(/-/g, '/') // 把所有 "-" 替换为 "/"
  542. .replace(' ', ' '); // 保留空格(也可替换为 "T",即 "yyyy-MM-ddTHH:mm:ss")
  543. // 2. 转换时间格式(字符串转 Date 对象)
  544. const startTime = new Date(liveItem.startTime);
  545. const now = new Date();
  546. // 4. 容错处理:防止时间解析失败(极端情况)
  547. if (isNaN(startTime.getTime())) {
  548. console.warn(`iOS 时间解析失败,原始时间:${liveItem.startTime},转换后:${iosCompatibleTime}`);
  549. liveItem.totalTime = '00小时00分钟00秒';
  550. return;
  551. }
  552. // 3. 计算毫秒级差值(确保差值非负,避免未来时间出现负数)
  553. const diffMs = Math.max(0, now - startTime);
  554. // 4. 转换为 小时:分钟:秒(补零确保两位数)
  555. const totalSeconds = Math.floor(diffMs / 1000);
  556. const hours = this.padZero(Math.floor(totalSeconds / 3600));
  557. const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60));
  558. const seconds = this.padZero(totalSeconds % 60);
  559. // 5. 更新当前直播间的 totalTime(响应式更新)
  560. this.$set(liveItem, 'totalTime', `${hours}:${minutes}:${seconds}`);
  561. },
  562. // 辅助方法:数字补零(如 9 → 09)
  563. padZero(num) {
  564. return num < 10 ? `0${num}` : num;
  565. },
  566. // 启动当前直播间的时间差值定时器
  567. startTimeTimer(liveItem) {
  568. // 先清除当前直播间的旧定时器(避免重复)
  569. if (liveItem.timeTimer) {
  570. clearInterval(liveItem.timeTimer);
  571. }
  572. // 1. 立即计算一次(避免等待1秒才显示)
  573. this.calculateTimeDiff(liveItem);
  574. // 2. 每秒更新一次(实时刷新)
  575. liveItem.timeTimer = setInterval(() => {
  576. this.calculateTimeDiff(liveItem);
  577. }, 1000);
  578. },
  579. // 清除指定直播间的时间定时器
  580. clearTimeTimer(liveItem) {
  581. if (liveItem.timeTimer) {
  582. clearInterval(liveItem.timeTimer);
  583. liveItem.timeTimer = null; // 清空定时器标识
  584. }
  585. },
  586. toggleViewerList() {
  587. const now = Date.now()
  588. if (now - this.lastClickTime > this.clickDelay) {
  589. this.showadd = !this.showadd
  590. this.lastClickTime = now
  591. }
  592. },
  593. // 重置在线用户列表的分页参数
  594. resetUserListParams() {
  595. this.viewPageNum = 1; // 重置页码为第一页
  596. this.viewNoMoreData = false; // 重置“没有更多数据”状态
  597. this.liveViewers = []; // 清空现有列表
  598. },
  599. closeAllWebSockets() {
  600. this.isManualClose = true;
  601. // 关闭所有连接
  602. Object.keys(this.socketInstances).forEach(liveId => {
  603. try {
  604. if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
  605. this.socketInstances[liveId].instance.close({
  606. code: 1000,
  607. reason: '页面关闭'
  608. });
  609. console.log(`直播间 ${liveId} WebSocket 已关闭`);
  610. }
  611. } catch (e) {
  612. console.error(`关闭直播间 ${liveId} WebSocket 时出错:`, e);
  613. }
  614. });
  615. this.socketInstances = {};
  616. isSocketOpen = false;
  617. }, // 移除所有全局事件监听器
  618. removeAllEventListeners() {
  619. uni.$off('initSocket');
  620. uni.$off('sendMsg');
  621. uni.$off('closeWebSocket');
  622. uni.$off('refreshOrder');
  623. // 可以根据实际情况添加其他需要移除的事件
  624. }, // 清理所有定时器
  625. clearAllTimers() {
  626. if (this.intervalId) {
  627. clearInterval(this.intervalId);
  628. this.intervalId = null;
  629. }
  630. if (this.pingpangTimes) {
  631. clearInterval(this.pingpangTimes);
  632. this.pingpangTimes = null;
  633. }
  634. if (this.reconnectTimer) {
  635. clearInterval(this.reconnectTimer);
  636. this.reconnectTimer = null;
  637. }
  638. if (this.scrollTimer) {
  639. clearTimeout(this.scrollTimer);
  640. this.scrollTimer = null;
  641. }
  642. if (this.searchTimer) {
  643. clearTimeout(this.searchTimer);
  644. this.searchTimer = null;
  645. }
  646. if (this.purchasePromptTimer) {
  647. clearTimeout(this.purchasePromptTimer);
  648. this.purchasePromptTimer = null;
  649. }
  650. },
  651. // 初始化当前直播间数据
  652. async initCurrentLiveData() {
  653. const currentLive = this.list[this.currentSwiperIndex];
  654. if (!currentLive) return;
  655. // 设置加载状态
  656. currentLive.loading = true;
  657. try {
  658. // 先初始化WebSocket连接
  659. await this.initSocket(currentLive);
  660. // 然后并行加载其他数据
  661. await Promise.allSettled([
  662. this.getLiveMsg(currentLive),
  663. this.getliveViewData(currentLive),
  664. this.getShowGoods(currentLive),
  665. this.getliving(currentLive)
  666. ]);
  667. currentLive.loaded = true;
  668. // 初始化完成后,启动当前直播间的时间差值定时器
  669. this.startTimeTimer(currentLive);
  670. } catch (error) {
  671. console.error("初始化直播间数据失败:", error);
  672. } finally {
  673. currentLive.loading = false;
  674. }
  675. },
  676. // 初始化直播间列表
  677. async initLiveList(options) {
  678. try {
  679. await this.getList(); // 先加载直播间列表
  680. if (this.list.length === 0) {
  681. console.error("直播间列表为空,无法初始化");
  682. return;
  683. }
  684. // 设置初始直播间索引(原逻辑保留)
  685. if (options.liveId) {
  686. const index = this.list.findIndex(item => item.liveId == options.liveId);
  687. this.currentSwiperIndex = index !== -1 ? index : 0;
  688. } else {
  689. this.currentSwiperIndex = 0;
  690. }
  691. // 延迟设置动画时间(原逻辑保留)
  692. setTimeout(() => {
  693. this.swiperDuration = 300;
  694. }, 100);
  695. // 获取当前直播间的liveItem
  696. const currentLive = this.list[this.currentSwiperIndex];
  697. if (currentLive) {
  698. this.liveId = currentLive.liveId;
  699. // 重置用户列表参数
  700. this.resetUserListParams();
  701. // 预加载相邻直播间(不初始化WebSocket)
  702. this.preloadNearbyLives(false);
  703. // 初始化当前直播间数据(包含WebSocket连接)
  704. await this.initCurrentLiveData();
  705. // 获取在线用户
  706. this.getliveUser(false);
  707. // 延迟播放视频
  708. setTimeout(() => {
  709. this.playVideo(currentLive);
  710. }, 500);
  711. }
  712. } catch (error) {
  713. console.error("初始化失败:", error);
  714. }
  715. },
  716. // Swiper切换事件
  717. async onSwiperChange(e) {
  718. const now = Date.now();
  719. const newIndex = e.detail.current;
  720. const oldIndex = this.currentSwiperIndex;
  721. // 相同索引或节流期间,不处理
  722. if (newIndex === oldIndex) return;
  723. if (now - this.lastSwiperChangeTime < this.swiperChangeThrottle) {
  724. console.log('Swiper切换过快,已节流');
  725. return;
  726. }
  727. // 更新最后切换时间
  728. this.lastSwiperChangeTime = now;
  729. // 1. 立即关闭旧直播间的WebSocket(同步操作)
  730. const oldLive = this.list[oldIndex];
  731. this.closeShop()
  732. if (oldLive) {
  733. this.pauseVideo(oldLive);
  734. this.clearTimeTimer(oldLive); // 清除旧直播间的时间定时器
  735. console.log("oldLive", oldLive)
  736. // 强制关闭并删除实例,确保连接被释放
  737. if (this.socketInstances[oldLive.liveId]) {
  738. try {
  739. this.socketInstances[oldLive.liveId].instance.close({
  740. code: 1000,
  741. reason: '切换直播间'
  742. });
  743. console.log(`关闭旧直播间 ${oldLive.liveId} WebSocket`);
  744. } catch (e) {
  745. console.error('关闭旧连接失败:', e);
  746. }
  747. delete this.socketInstances[oldLive.liveId]; // 彻底删除实例
  748. }
  749. }
  750. // 2. 处理新直播间(后续逻辑不变)
  751. this.currentSwiperIndex = newIndex;
  752. const newLive = this.list[newIndex];
  753. if (!newLive) return;
  754. this.liveId = newLive.liveId;
  755. this.resetUserListParams();
  756. await this.initCurrentLiveData(); // 内部会启动新直播间的定时器
  757. this.getliveUser(false);
  758. setTimeout(() => {
  759. this.playVideo(newLive);
  760. }, 100);
  761. },
  762. // 获取直播间列表
  763. async getList() {
  764. const data = {
  765. page: 1,
  766. page_size: 20
  767. };
  768. try {
  769. const res = await liveList(data);
  770. if (res.code === 200) {
  771. this.list = res.rows.map(item => ({
  772. ...item,
  773. talklist: [],
  774. loading: false,
  775. loaded: false,
  776. shopping: false,
  777. inputInfo: '',
  778. showWelcomeMessage: false,
  779. redInfo: {},
  780. goodsCard: {},
  781. totalTime: '00小时00分钟00秒', // 初始化差值为0
  782. timeTimer: null, // 存储当前直播间的定时器,用于后续清理
  783. // 预处理:统一将 startTime 转换为 iOS 兼容格式(避免重复转换)
  784. startTime: item.startTime ? item.startTime.replace(/-/g, '/') : ''
  785. // 其他初始化字段...
  786. }));
  787. console.log("直播间列表加载成功,数量:", this.list.length); // 确认数量是否 > 0
  788. } else {
  789. uni.showToast({
  790. title: res.msg,
  791. icon: "none"
  792. });
  793. this.list = []; // 接口失败时清空列表,避免后续错误
  794. }
  795. } catch (error) {
  796. console.error("获取直播间列表失败:", error);
  797. this.list = []; // 异常时清空列表
  798. }
  799. },
  800. // 播放视频
  801. playVideo(liveItem) {
  802. if (!liveItem) return;
  803. try {
  804. const videoId = `myVideo_${liveItem.liveId}`;
  805. const videoContext = uni.createVideoContext(videoId, this);
  806. if (videoContext) {
  807. videoContext.pause(() => {
  808. // 暂停完成后再播放
  809. videoContext.play();
  810. });
  811. }
  812. } catch (error) {
  813. console.error("播放视频失败:", error);
  814. }
  815. },
  816. pauseVideo(liveItem) {
  817. if (!liveItem) return;
  818. try {
  819. const videoId = `myVideo_${liveItem.liveId}`;
  820. const videoContext = uni.createVideoContext(videoId, this);
  821. if (videoContext) {
  822. videoContext.pause();
  823. }
  824. } catch (error) {
  825. console.error("暂停视频失败:", error);
  826. }
  827. },
  828. // 预加载相邻直播间
  829. async preloadNearbyLives(includeWebSocket = false) {
  830. this.preloading = true;
  831. const currentIndex = this.currentSwiperIndex;
  832. const preloadIndexes = [];
  833. // 只预加载数据,不初始化WebSocket(强制关闭WebSocket预加载)
  834. includeWebSocket = false; // 关键:强制不预加载WebSocket
  835. if (currentIndex > 0) preloadIndexes.push(currentIndex - 1);
  836. if (currentIndex < this.list.length - 1) preloadIndexes.push(currentIndex + 1);
  837. for (const index of preloadIndexes) {
  838. const liveItem = this.list[index];
  839. if (!liveItem || liveItem.loaded || liveItem.loading) continue;
  840. liveItem.loading = true;
  841. try {
  842. // 只加载基础数据,不初始化WebSocket
  843. await Promise.all([
  844. this.getliving(liveItem),
  845. this.getLiveMsg(liveItem),
  846. this.getliveViewData(liveItem),
  847. this.getShowGoods(liveItem)
  848. ]);
  849. liveItem.loaded = true;
  850. } catch (error) {
  851. console.error(`预加载直播间 ${index} 失败:`, error);
  852. liveItem.loaded = false;
  853. } finally {
  854. liveItem.loading = false;
  855. }
  856. }
  857. this.preloading = false;
  858. },
  859. openViews() {
  860. // 计算scroll-view高度
  861. this.$nextTick(() => {
  862. const query = uni.createSelectorQuery().in(this);
  863. query.select('.view-box').boundingClientRect(data => {
  864. if (data) {
  865. // 减去标题和底部固定区域的高度
  866. this.scrollHeight = data.height - 80 - 120; // 80是标题高度,120是底部高度
  867. }
  868. }).exec();
  869. });
  870. },
  871. // 重置直播间数据
  872. resetLiveData() {
  873. // 保留不需要重置的数据(如用户信息等)
  874. const keepData = {
  875. userinfo: this.userinfo,
  876. list: this.list,
  877. currentSwiperIndex: this.currentSwiperIndex
  878. };
  879. // 重置其他直播间特定数据
  880. this.liveUserTotal = null;
  881. // this.liveViewData = {};
  882. this.liveViewers = [];
  883. this.livingUrl = "";
  884. this.videoUrl = null;
  885. this.products = {};
  886. this.store = {};
  887. this.orderUser = {};
  888. this.talklist = [];
  889. this.livedata = {};
  890. // this.isFollow = false;
  891. this.shopping = false;
  892. this.inputInfo = ''
  893. // 恢复需要保留的数据
  894. Object.assign(this, keepData);
  895. },
  896. // 获取直播间用户
  897. async getliveUser(isLoadMore = false) {
  898. // 强制使用当前 liveId,避免使用旧值
  899. const currentLiveId = this.liveId;
  900. if (!currentLiveId) return;
  901. // if (this.viewLoading || this.viewNoMoreData) return;
  902. this.viewLoading = true;
  903. try {
  904. const res = await watchUserList(currentLiveId, this.viewPageSize, this.viewPageNum, false);
  905. if (res.code === 200) {
  906. // 若请求期间已切换直播间,忽略旧数据
  907. if (this.liveId !== currentLiveId) return;
  908. this.liveUserTotal = res.total;
  909. if (res.rows.length === 0) {
  910. this.viewNoMoreData = true;
  911. return;
  912. }
  913. this.liveViewers = isLoadMore ? [...this.liveViewers, ...res.rows] : res
  914. .rows; // 首次加载/切换直播间时重置数据
  915. this.viewPageNum++;
  916. // console.log("在线观众", this.liveViewers)
  917. }
  918. } catch (error) {
  919. console.error('获取观众列表失败:', error);
  920. } finally {
  921. this.viewLoading = false;
  922. }
  923. },
  924. // 滚动到底部触发
  925. handleScrollToLower() {
  926. // 清除上一次未执行的定时器,避免重复请求
  927. if (this.scrollTimer) {
  928. clearTimeout(this.scrollTimer);
  929. }
  930. // 延迟0.5秒(500毫秒)执行接口请求
  931. this.scrollTimer = setTimeout(() => {
  932. this.getliveUser(true); // 加载更多数据
  933. }, 1000); // 延迟时间:500毫秒
  934. },
  935. async getLiveMsg(liveItem) {
  936. // 强化校验:确保 liveItem 存在且包含 liveId
  937. if (!liveItem || !liveItem.liveId) {
  938. console.error('getLiveMsg 错误:无效的 liveItem', {
  939. liveItem: liveItem,
  940. currentIndex: this.currentSwiperIndex,
  941. listLength: this.list.length
  942. });
  943. return; // 直接返回,不执行后续逻辑
  944. }
  945. try {
  946. const res = await liveMsg(liveItem.liveId, 30, 1);
  947. if (res.code == 200) {
  948. // 确保使用响应式更新
  949. const reversedTalkList = [...res.rows].reverse();
  950. // 确保使用响应式更新(赋值反转后的数组)
  951. this.$set(liveItem, 'talklist', reversedTalkList);
  952. this.$nextTick(() => {
  953. // 滚动到最新消息(反转后最新消息在数组最后一位,索引为 reversedTalkList.length - 1)
  954. this.$set(liveItem, 'scrollIntoView', `list_${reversedTalkList.length - 1}`);
  955. });
  956. }
  957. } catch (error) {
  958. console.error("获取聊天记录失败:", error);
  959. }
  960. },
  961. // 点击红包
  962. onRed(item) {
  963. // console.log("点了this.liveId", item)
  964. if (!item.liveId) return;
  965. // console.log("点了this.liveId", this.liveId)
  966. if (!item.redInfo?.redId) return;
  967. // console.log("点了this.redInfo?.redId", this.redInfo.redId)
  968. // console.log("点了this.userinfo.userId", this.userinfo.userId)
  969. let data = {
  970. liveId: item.liveId,
  971. userId: this.userinfo.userId,
  972. redId: item.redInfo.redId,
  973. }
  974. console.log("点了this.liveId", data)
  975. liveRed(data).then(res => {
  976. if (res.code == 200) {
  977. uni.showToast({
  978. title: res.msg,
  979. icon: 'none'
  980. });
  981. } else {
  982. uni.showToast({
  983. title: res.msg,
  984. icon: 'none'
  985. });
  986. }
  987. },
  988. rej => {}
  989. );
  990. },
  991. handleSearchInput() {
  992. // 使用防抖优化性能,避免频繁请求
  993. clearTimeout(this.searchTimer);
  994. this.searchTimer = setTimeout(() => {
  995. this.queryCollect();
  996. }, 500); // 500毫秒延迟
  997. },
  998. // 显示购买提示信息
  999. showPurchaseMessage() {
  1000. // 清除之前的定时器
  1001. if (this.purchasePromptTimer) {
  1002. clearTimeout(this.purchasePromptTimer);
  1003. }
  1004. // 显示提示
  1005. this.showPurchasePrompt = true;
  1006. // 2秒后自动隐藏
  1007. this.purchasePromptTimer = setTimeout(() => {
  1008. this.showPurchasePrompt = false;
  1009. }, 2000);
  1010. },
  1011. truncateString(str, maxLength) {
  1012. return str.length > maxLength ? str.slice(0, maxLength) + '...' : str;
  1013. },
  1014. goStore(item) {
  1015. console.log("带过去storeId", item)
  1016. if (!item.storeId) {
  1017. uni.showToast({
  1018. title: "当前直播间暂未开通店铺",
  1019. icon: 'none'
  1020. });
  1021. return;
  1022. }
  1023. uni.navigateTo({
  1024. url: '/pages_shop/store?liveId=' + item.liveId + "&storeId=" + item.storeId
  1025. })
  1026. },
  1027. // 去订单列表
  1028. goOrderList() {
  1029. uni.navigateTo({
  1030. url: "/pages_shop/order"
  1031. })
  1032. },
  1033. // 初始化HLS播放器
  1034. initHlsPlayer() {
  1035. if (Hls.isSupported() && this.livingUrl) {
  1036. const video = document.getElementById('myVideo');
  1037. if (video) {
  1038. this.hlsPlayer = new Hls();
  1039. this.hlsPlayer.loadSource(this.livingUrl);
  1040. this.hlsPlayer.attachMedia(video);
  1041. this.hlsPlayer.on(Hls.Events.MANIFEST_PARSED, () => {
  1042. video.play();
  1043. });
  1044. }
  1045. }
  1046. },
  1047. // 视频错误处理
  1048. videoError(e, liveItem) {
  1049. if (!liveItem || liveItem.liveId !== this.liveId) return;
  1050. // 初始化重试计数
  1051. if (this.videoRetryCounts[liveItem.liveId] === undefined) {
  1052. this.videoRetryCounts[liveItem.liveId] = 0;
  1053. }
  1054. // 限制重试次数
  1055. if (this.videoRetryCounts[liveItem.liveId] >= 3) {
  1056. console.error(`直播间 ${liveItem.liveId} 视频加载失败,停止重试`);
  1057. // 显示错误提示
  1058. uni.showToast({
  1059. title: "视频加载失败,请检查网络",
  1060. icon: 'none',
  1061. duration: 2000
  1062. });
  1063. return;
  1064. }
  1065. this.videoRetryCounts[liveItem.liveId]++;
  1066. // 延迟重试
  1067. setTimeout(() => {
  1068. if (liveItem.liveId === this.liveId) {
  1069. console.log(`第${this.videoRetryCounts[liveItem.liveId]}次重试播放视频`);
  1070. this.playVideo(liveItem);
  1071. }
  1072. }, 2000);
  1073. },
  1074. // 修改获取直播信息方法
  1075. async getliving(liveItem) {
  1076. if (!liveItem || !liveItem.liveId) return;
  1077. // console.log("获取直播信息:", liveItem.liveId);
  1078. const param = {
  1079. id: liveItem.liveId
  1080. };
  1081. try {
  1082. const res = await getlive({
  1083. id: liveItem.liveId
  1084. });
  1085. if (res.code !== 200) {
  1086. uni.showToast({
  1087. title: res.msg,
  1088. icon: 'none'
  1089. });
  1090. return;
  1091. }
  1092. // 强制更新视频源(覆盖旧值)
  1093. if (res.data.liveType === 2) {
  1094. // 回放视频
  1095. this.$set(liveItem, 'videoUrl', res.data.videoUrl);
  1096. this.$set(liveItem, 'livingUrl', ''); // 清空直播流
  1097. this.$set(liveItem, 'placeholderText', "说点什么...");
  1098. } else if (res.data.liveType === 1) {
  1099. // 直播流
  1100. this.$set(liveItem, 'livingUrl', res.data.flvHlsUrl);
  1101. this.$set(liveItem, 'videoUrl', ''); // 清空回放视频
  1102. this.$set(liveItem, 'placeholderText', "说点什么...");
  1103. } else {
  1104. // 未开播
  1105. this.$set(liveItem, 'livingUrl', '');
  1106. this.$set(liveItem, 'videoUrl', '');
  1107. }
  1108. // 更新其他直播信息
  1109. // 仅当是当前激活的直播间时,才允许自动播放
  1110. const isCurrentLive = this.currentSwiperIndex === this.list.findIndex(item => item.liveId ===
  1111. liveItem.liveId);
  1112. this.$set(liveItem, 'autoplay', isCurrentLive && res.data.liveType !== 0);
  1113. this.$set(liveItem, 'showType', res.data.showType);
  1114. this.$set(liveItem, 'storeId', res.storeId);
  1115. this.queryCollect();
  1116. } catch (err) {
  1117. console.error("获取直播信息失败:", err);
  1118. uni.showToast({
  1119. title: "获取直播信息失败",
  1120. icon: 'none'
  1121. });
  1122. }
  1123. }, // 设置视频播放
  1124. setupVideoPlayback(liveItem, liveData) {
  1125. if (!liveItem.livingUrl) return;
  1126. // H5 平台:使用 HLS.js 处理 .m3u8 流
  1127. // #ifdef H5
  1128. if (liveItem.livingUrl.includes('.m3u8')) {
  1129. this.initHlsPlayer(liveItem);
  1130. return;
  1131. }
  1132. // #endif
  1133. // 小程序/App 平台:直接使用 video 组件
  1134. const videoId = `myVideo_${liveItem.liveId}`;
  1135. const videoContext = uni.createVideoContext(videoId, this);
  1136. if (liveData.liveType === 1) {
  1137. // 回放:跳转到指定位置
  1138. videoContext.seek(liveData.nowDuration || 0);
  1139. } else {
  1140. // 直播:直接播放
  1141. videoContext.play();
  1142. }
  1143. },
  1144. maskString(str, maskChar = '*') {
  1145. // 如果str是undefined或null,直接返回空字符串
  1146. if (!str) return '';
  1147. // 确保str是字符串(如果是数字等类型,先转为字符串)
  1148. const strVal = String(str);
  1149. return strVal.split('').map((char, index) => (index === 0 ? char : maskChar)).join('');
  1150. },
  1151. getPureDecimal(num, precision = 6) {
  1152. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  1153. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  1154. },
  1155. // 返回上一个页面并关闭WebSocket
  1156. goBack() {
  1157. // 暂停当前视频
  1158. const currentLive = this.list[this.currentSwiperIndex];
  1159. if (currentLive) {
  1160. this.pauseVideo(currentLive);
  1161. }
  1162. // 关闭所有WebSocket连接
  1163. this.closeWebSocket();
  1164. // 导航返回
  1165. const pages = getCurrentPages();
  1166. if (pages.length > 1) {
  1167. uni.navigateBack();
  1168. } else {
  1169. uni.reLaunch({
  1170. url: '/pages/list/index'
  1171. });
  1172. }
  1173. },
  1174. //正在购买
  1175. async getliveOrder() {
  1176. const currentLiveId = this.liveId;
  1177. if (!currentLiveId) return;
  1178. try {
  1179. const res = await liveOrderUser(currentLiveId);
  1180. if (res.code === 200) {
  1181. // 绑定到当前 liveItem
  1182. const currentLive = this.list[this.currentSwiperIndex];
  1183. if (currentLive) {
  1184. this.$set(currentLive, 'orderUser', res);
  1185. this.orderUser = res; // 同步全局变量
  1186. }
  1187. }
  1188. } catch (error) {
  1189. console.error('获取正在购买用户失败:', error);
  1190. }
  1191. },
  1192. // 获取直播间信息接口
  1193. getLiveinformation() {
  1194. if (!this.liveId) return;
  1195. getLiveInfo(this.liveId).then(res => {
  1196. if (res.code == 200) {
  1197. console.log("获取直播间信息接口>>>>", res)
  1198. this.livingUrl = res.livingUrl
  1199. } else {
  1200. uni.showToast({
  1201. title: res.msg,
  1202. icon: 'none'
  1203. });
  1204. }
  1205. },
  1206. rej => {}
  1207. );
  1208. },
  1209. // 点赞
  1210. async onLike(liveItem) {
  1211. if (!liveItem || !liveItem.liveId) return;
  1212. try {
  1213. const res = await liveDataLike(liveItem.liveId);
  1214. if (res?.like) {
  1215. liveItem.liveViewData.like++; // 只更新当前直播间的点赞数
  1216. } else {
  1217. uni.showToast({
  1218. title: res.msg,
  1219. icon: 'none'
  1220. });
  1221. }
  1222. } catch (error) {
  1223. console.error('点赞失败:', error);
  1224. }
  1225. },
  1226. // 点赞
  1227. // async onLike(liveItem) {
  1228. // // 基础校验
  1229. // if (!liveItem || !liveItem.liveId) return;
  1230. // // 确保liveViewData存在(初始化默认值)
  1231. // if (!liveItem.liveViewData) {
  1232. // await this.getliveViewData(liveItem);
  1233. // if (!liveItem.liveViewData) {
  1234. // uni.showToast({
  1235. // title: "数据加载中,请稍后再试",
  1236. // icon: 'none'
  1237. // });
  1238. // return;
  1239. // }
  1240. // // 初始化点赞数(防止undefined)
  1241. // liveItem.liveViewData.like = liveItem.liveViewData.like || 0;
  1242. // }
  1243. // // 限制最多10次点赞
  1244. // const maxLikeCount = 10;
  1245. // if (liveItem.liveViewData.like >= maxLikeCount) {
  1246. // uni.showToast({
  1247. // title: "最多可点赞10次哦~",
  1248. // icon: 'none'
  1249. // });
  1250. // return;
  1251. // }
  1252. // try {
  1253. // const res = await liveDataLike(liveItem.liveId);
  1254. // if (res.code === 200) {
  1255. // // 无论后端是否返回res.like,前端按规则累加(最多到10次)
  1256. // const newLikeCount = Math.min(liveItem.liveViewData.like + 1, maxLikeCount);
  1257. // liveItem.liveViewData.like = newLikeCount;
  1258. // } else {
  1259. // uni.showToast({
  1260. // title: res.msg || "点赞失败",
  1261. // icon: 'none'
  1262. // });
  1263. // }
  1264. // } catch (error) {
  1265. // console.error('点赞失败:', error);
  1266. // uni.showToast({
  1267. // title: "网络异常,点赞失败",
  1268. // icon: 'none'
  1269. // });
  1270. // }
  1271. // },
  1272. //直播间点赞、关注、在线人数数据
  1273. async getliveViewData(liveItem) {
  1274. if (!liveItem || !liveItem.liveId) return;
  1275. try {
  1276. const res = await getLiveViewData(liveItem.liveId);
  1277. if (res.code == 200) {
  1278. // 强制响应式更新,确保数据实时显示
  1279. this.$set(liveItem, 'liveViewData', res);
  1280. }
  1281. } catch (error) {
  1282. console.error("获取直播间数据失败:", error);
  1283. // 失败时兜底,避免显示异常
  1284. this.$set(liveItem, 'liveViewData', {
  1285. like: 0,
  1286. watchCount: 0
  1287. });
  1288. }
  1289. },
  1290. //弹出商品卡片
  1291. async getShowGoods(liveItem) {
  1292. if (!liveItem || !liveItem.liveId) return;
  1293. try {
  1294. const res = await showGoods(liveItem.liveId);
  1295. if (res.code == 200) {
  1296. this.$set(liveItem, 'goodsCard', res);
  1297. }
  1298. } catch (error) {
  1299. console.error("暂无商品卡片", error);
  1300. }
  1301. },
  1302. // 去购买,跳商品详情
  1303. goShop(productId, goodsId) {
  1304. const currentLive = this.list[this.currentSwiperIndex];
  1305. if (!currentLive || !currentLive.liveId) return;
  1306. uni.navigateTo({
  1307. url: '/pages_shop/goods?productId=' + productId + '&liveId=' + currentLive.liveId +
  1308. '&goodsId=' + goodsId + '&storeId=' + currentLive.storeId
  1309. })
  1310. },
  1311. // 查询店铺
  1312. async queryCollect() {
  1313. const currentLive = this.list[this.currentSwiperIndex];
  1314. if (!currentLive || !currentLive.liveId) return;
  1315. const {
  1316. storeId
  1317. } = currentLive;
  1318. // console.log("小黄车数据>>>", currentLive)
  1319. if (!storeId) return;
  1320. try {
  1321. const res = await store(currentLive.storeId, currentLive.inputInfo, currentLive.liveId);
  1322. if (res.code === 200) {
  1323. // 数据绑定到当前 liveItem,避免全局污染
  1324. this.$set(currentLive, 'products', res.data.goodsList);
  1325. this.$set(currentLive, 'store', res.data);
  1326. // 同步更新全局变量(供弹窗使用)
  1327. this.products = res.data.goodsList;
  1328. this.store = res.data;
  1329. }
  1330. } catch (error) {
  1331. console.error('获取小黄车商品失败:', error);
  1332. }
  1333. },
  1334. // 店铺收藏
  1335. onStoreCollect(liveItem) {
  1336. console.log("店铺收藏", liveItem)
  1337. if (!liveItem.storeId) return;
  1338. collectStore(liveItem.storeId).then(res => {
  1339. if (res.code == 200) {
  1340. uni.showToast({
  1341. title: res.msg,
  1342. icon: 'none'
  1343. });
  1344. liveItem.store.isFavorite = !liveItem.store.isFavorite
  1345. } else {
  1346. uni.showToast({
  1347. title: res.msg,
  1348. icon: 'none'
  1349. });
  1350. }
  1351. },
  1352. rej => {}
  1353. );
  1354. },
  1355. // 商品收藏
  1356. onGoodsCollect(item) {
  1357. console.log("商品收藏", item)
  1358. if (!item || item.length === 0 || !item.goodsId) {
  1359. return;
  1360. }
  1361. collectGoods(item.goodsId).then(res => {
  1362. if (res.code == 200) {
  1363. uni.showToast({
  1364. title: res.msg,
  1365. icon: 'none'
  1366. });
  1367. item.isFavorite = !item.isFavorite
  1368. } else {
  1369. uni.showToast({
  1370. title: res.msg,
  1371. icon: 'none'
  1372. });
  1373. }
  1374. },
  1375. rej => {}
  1376. );
  1377. },
  1378. // 关注
  1379. // async onFollow(liveItem) {
  1380. // if (!liveItem || !liveItem.liveId) return;
  1381. // try {
  1382. // const res = await follow(liveItem.liveId);
  1383. // liveItem.isFollow = !liveItem.isFollow;
  1384. // uni.showToast({
  1385. // title: res.msg,
  1386. // icon: 'none'
  1387. // });
  1388. // } catch (error) {
  1389. // console.error("关注操作失败:", error);
  1390. // }
  1391. // },
  1392. // 时间戳
  1393. initTime() {
  1394. const now = new Date();
  1395. this.timestamp = now.getTime(); // 例如:'2023-04-01 12:00:00'
  1396. },
  1397. openShop() {
  1398. },
  1399. openViews() {
  1400. this.$nextTick(() => {
  1401. const query = uni.createSelectorQuery().in(this);
  1402. query.select('.view-box').boundingClientRect(data => {
  1403. if (data) {
  1404. this.scrollHeight = data.height - 80 - 120;
  1405. }
  1406. }).exec();
  1407. });
  1408. },
  1409. openCart(liveItem) {
  1410. if (!liveItem.storeId) {
  1411. uni.showToast({
  1412. title: "当前直播间暂未开通店铺",
  1413. icon: 'none'
  1414. });
  1415. return;
  1416. }
  1417. liveItem.shopping = true
  1418. },
  1419. close() {
  1420. this.showadd = false
  1421. },
  1422. // 关闭小黄车
  1423. closeShop() {
  1424. // 通过当前swiper索引获取当前直播间实例
  1425. const currentLive = this.list[this.currentSwiperIndex];
  1426. if (currentLive) {
  1427. this.$set(currentLive, 'shopping', false);
  1428. }
  1429. },
  1430. // 关闭红包
  1431. closeRed() {
  1432. this.showRed = !this.showRed
  1433. },
  1434. getEWechatSdk() {
  1435. // 只在H5平台执行
  1436. // #ifdef H5
  1437. let eWechatSdk = '';
  1438. if (/(Android)/i.test(navigator.userAgent)) {
  1439. eWechatSdk = 'jWeixin';
  1440. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  1441. eWechatSdk = 'wx';
  1442. } else {
  1443. eWechatSdk = 'jWeixin';
  1444. }
  1445. uni.setStorageSync("wxSdk", eWechatSdk);
  1446. // #endif
  1447. },
  1448. // 修改关闭WebSocket方法
  1449. closeWebSocket(liveId = null) {
  1450. this.isManualClose = true;
  1451. clearInterval(this.pingpangTimes);
  1452. clearInterval(this.reconnectTimer);
  1453. if (liveId) {
  1454. // 添加空值检查
  1455. if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
  1456. try {
  1457. this.socketInstances[liveId].instance.close();
  1458. console.log(`直播间 ${liveId} WebSocket 已安全关闭`);
  1459. } catch (e) {
  1460. console.error(`关闭直播间 ${liveId} WebSocket 时出错:`, e);
  1461. }
  1462. }
  1463. delete this.socketInstances[liveId];
  1464. } else {
  1465. Object.keys(this.socketInstances).forEach(id => {
  1466. // 添加空值检查
  1467. if (this.socketInstances[id] && this.socketInstances[id].instance) {
  1468. try {
  1469. this.socketInstances[id].instance.close();
  1470. console.log(`直播间 ${id} WebSocket 已安全关闭`);
  1471. } catch (e) {
  1472. console.error(`关闭直播间 ${id} WebSocket 时出错:`, e);
  1473. }
  1474. }
  1475. });
  1476. this.socketInstances = {};
  1477. }
  1478. isSocketOpen = false;
  1479. },
  1480. reConnect() {
  1481. var that = this;
  1482. try {
  1483. uni.closeSocket();
  1484. } catch (e) {
  1485. }
  1486. setTimeout(function() {
  1487. that.initSocket();
  1488. }, 10000);
  1489. },
  1490. startHeartbeat(liveId) {
  1491. clearInterval(this.pingpangTimes);
  1492. this.pingpangTimes = setInterval(() => {
  1493. const inst = this.socketInstances[liveId];
  1494. if (!inst || !inst.isOpen || !inst.instance) return;
  1495. const pingData = {
  1496. cmd: 'ping',
  1497. timestamp: Date.now()
  1498. };
  1499. try {
  1500. inst.instance.send({
  1501. data: JSON.stringify(pingData)
  1502. });
  1503. } catch (err) {
  1504. console.error('心跳发送失败:', err);
  1505. this.scheduleReconnect(liveId);
  1506. }
  1507. }, 30000);
  1508. },
  1509. async initSocket(liveItem) {
  1510. const currentLive = this.list[this.currentSwiperIndex];
  1511. if (!currentLive || currentLive.liveId !== liveItem.liveId) {
  1512. console.log(`拒绝为非活跃直播间 ${liveItem.liveId} 建立WebSocket`);
  1513. return;
  1514. }
  1515. if (!liveItem || !liveItem.liveId) return;
  1516. const liveId = liveItem.liveId;
  1517. // 检查是否已经是当前连接或正在连接
  1518. if (this.connectingLiveId === liveId ||
  1519. (this.socketInstances[liveId] && this.socketInstances[liveId].isOpen)) {
  1520. console.log(`直播间 ${liveId} 的WebSocket已经连接或正在连接,跳过初始化`);
  1521. return;
  1522. }
  1523. // 检查是否是当前活跃的直播间
  1524. if (this.currentSwiperIndex !== this.list.findIndex(item => item.liveId === liveId)) {
  1525. console.log(`不初始化非当前直播间 ${liveId} 的WebSocket`);
  1526. return;
  1527. }
  1528. // 关闭之前的连接(如果存在)
  1529. if (this.socketInstances[liveId]) {
  1530. this.closeWebSocket(liveId);
  1531. }
  1532. // 设置正在连接的直播间ID
  1533. this.connectingLiveId = liveId;
  1534. // 防止重复创建
  1535. if (this.reconnectCount >= this.maxReconnectAttempts) {
  1536. this.connectingLiveId = null;
  1537. return;
  1538. }
  1539. this.isManualClose = false;
  1540. const connectTimeout = setTimeout(() => {
  1541. if (!this.socketInstances[liveId]?.isOpen) {
  1542. console.error(`WebSocket连接超时: ${liveId}`);
  1543. this.scheduleReconnect(liveId);
  1544. }
  1545. }, 10000); // 10秒超时
  1546. // 生成签名
  1547. const signature = CryptoJS.HmacSHA256(
  1548. `${liveId}${this.userinfo.userId}${this.userType}${this.timestamp}`,
  1549. this.timestamp.toString()
  1550. ).toString(CryptoJS.enc.Hex);
  1551. // 初始化实例状态
  1552. this.socketInstances[liveId] = {
  1553. instance: null,
  1554. isOpen: false
  1555. };
  1556. try {
  1557. const socketTask = uni.connectSocket({
  1558. url: `${wsUrl}?userId=${this.userinfo.userId}&liveId=${liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`,
  1559. success: () => {
  1560. console.log('WebSocket API 调用成功,正在建立连接...');
  1561. },
  1562. fail: (err) => {
  1563. console.error('WebSocket 连接失败:', err);
  1564. this.connectingLiveId = null;
  1565. this.scheduleReconnect(liveId);
  1566. }
  1567. });
  1568. socketTask.onOpen((res) => {
  1569. console.log('WebSocket 连接已成功建立', res);
  1570. this.socketInstances[liveId].instance = socketTask;
  1571. this.socketInstances[liveId].isOpen = true;
  1572. clearTimeout(connectTimeout);
  1573. isSocketOpen = true;
  1574. this.connectingLiveId = null;
  1575. this.reconnectCount = 0;
  1576. // 改用 socketTask 的 send 作为心跳
  1577. this.startHeartbeat(liveId); // 修改 startHeartbeat 以接受 liveId 并使用 socketTask.send
  1578. });
  1579. socketTask.onMessage((res) => {
  1580. // 找到对应的直播间并更新数据
  1581. const targetLive = this.list.find(item => item.liveId === liveId);
  1582. if (targetLive) {
  1583. this.handleSocketMessage(res, targetLive);
  1584. }
  1585. });
  1586. socketTask.onError((err) => {
  1587. clearTimeout(connectTimeout);
  1588. console.error('WebSocket 连接错误:', err);
  1589. this.connectingLiveId = null;
  1590. this.scheduleReconnect(liveId);
  1591. });
  1592. socketTask.onClose(() => {
  1593. console.log(`WebSocket 连接已关闭: ${liveId}`);
  1594. this.connectingLiveId = null;
  1595. });
  1596. } catch (e) {
  1597. console.error('创建 WebSocket 异常:', e);
  1598. this.connectingLiveId = null;
  1599. this.scheduleReconnect(liveId);
  1600. }
  1601. },
  1602. // 处理Socket消息
  1603. handleSocketMessage(message, liveItem) {
  1604. let data = JSON.parse(message.data)
  1605. const socketMessage = data.data
  1606. // console.log("处理",data)
  1607. if (data.code == 200) {
  1608. const messageData = {
  1609. ...socketMessage, // 原数据(可能包含部分字段)
  1610. cmd: socketMessage.cmd || '' // 强制添加cmd,确保存在(默认空字符串)
  1611. };
  1612. // console.log("messageData是",messageData)
  1613. if (socketMessage.cmd == 'sendMsg') {
  1614. // this.$set(liveItem, 'talklist', [...liveItem.talklist, messageData]);
  1615. this.$nextTick(() => {
  1616. this.$set(liveItem, 'scrollIntoView', `list_${liveItem.talklist.length-1}`);
  1617. });
  1618. } else if (socketMessage.cmd == 'red') {
  1619. // 领红包
  1620. this.$set(liveItem, 'redInfo', JSON.parse(socketMessage.data));
  1621. console.log("红包是liveItem.redInfo", liveItem)
  1622. // liveItem.redInfo = JSON.parse(message.data.data);
  1623. } else if (socketMessage.cmd == 'sendRedPacketQuestion') {
  1624. const list = JSON.parse(message.data.data);
  1625. // 处理红包答题逻辑
  1626. } else if (socketMessage.cmd == 'entry' || socketMessage.cmd == 'out') {
  1627. this.$set(liveItem, 'talklist', [...liveItem.talklist, messageData]);
  1628. // 先重置为 false(避免残留状态)
  1629. this.$set(liveItem, 'showWelcomeMessage', false);
  1630. // 立即设为 true(触发 DOM 更新)
  1631. this.$set(liveItem, 'showWelcomeMessage', true);
  1632. this.getliveUser(false); // 调用获取在线用户接口
  1633. // console.log("开启欢迎消息:", liveItem.showWelcomeMessage);
  1634. if (liveItem.welcomeTimer) {
  1635. clearTimeout(liveItem.welcomeTimer);
  1636. }
  1637. // 存储定时器到 liveItem 中(避免引用丢失)
  1638. liveItem.welcomeTimer = setTimeout(() => {
  1639. this.$set(liveItem, 'showWelcomeMessage', false);
  1640. // console.log("关闭欢迎消息:", liveItem.showWelcomeMessage);
  1641. }, 1000); // 1秒后隐藏
  1642. } else if (socketMessage.cmd == 'Integral') {
  1643. let integral = {
  1644. msg: socketMessage.msg,
  1645. status: true
  1646. }
  1647. // 观看奖励事件 弹出框2s 显示msg
  1648. this.$set(liveItem, 'integral', integral);
  1649. // uni.showToast({
  1650. // title: socketMessage.msg,
  1651. // icon: 'none',
  1652. // duration: 2000
  1653. // });
  1654. } else if (socketMessage.cmd == 'blockUser') {
  1655. //拉黑事件 主动删除用户token,强制跳转到登录页面
  1656. uni.removeStorage({
  1657. key: 'AppToken', // 存储 Token 时的 key
  1658. success: () => {
  1659. uni.reLaunch({
  1660. url: '/pages/auth/login' // 登录页路径,需根据项目实际路径调整
  1661. });
  1662. console.log('Token 删除成功');
  1663. },
  1664. fail: (err) => {
  1665. console.error('Token 删除失败:', err);
  1666. }
  1667. });
  1668. } else if (socketMessage.cmd == 'goods') {
  1669. this.$set(liveItem, 'goodsCard', JSON.parse(socketMessage.data));
  1670. } else if (socketMessage.cmd == 'out') {
  1671. // console.log("进入:", liveItem);
  1672. console.log("有人退出了:");
  1673. } else if (socketMessage.cmd == 'live_start') {
  1674. // 直播开始
  1675. } else if (socketMessage.cmd == 'live_end') {
  1676. // 直播结束
  1677. } else if (socketMessage.data.cmd == 'deleteId') {
  1678. uni.$emit('deleteId');
  1679. } else if (socketMessage.data.cmd == 'sendRedPacketQuestion') {
  1680. // const list = JSON.parse(socketMessage)
  1681. // liveItem.redanswerAll = [...liveItem.redanswerAll, ...list]
  1682. // if (liveItem.redanswerAll[1].randomAmount !== null) {
  1683. // liveItem.redanswertips = JSON.parse(liveItem.redanswerAll[0]
  1684. // .randomAmount)
  1685. // }
  1686. }
  1687. } else {
  1688. uni.showToast({
  1689. title: data.msg,
  1690. icon: 'none'
  1691. });
  1692. }
  1693. },
  1694. scheduleReconnect(liveId) {
  1695. if (this.isManualClose || this.reconnectCount >= this.maxReconnectAttempts) return;
  1696. this.reconnectCount++;
  1697. const delay = Math.min(3000 * this.reconnectCount, 30000);
  1698. clearInterval(this.reconnectTimer);
  1699. this.reconnectTimer = setTimeout(() => {
  1700. // 使用传入的liveId
  1701. const liveItem = this.list.find(item => item.liveId === liveId) || {
  1702. liveId
  1703. };
  1704. this.initSocket(liveItem);
  1705. }, delay);
  1706. },
  1707. sendMsg(liveItem) {
  1708. if (!liveItem || !liveItem.liveId) return;
  1709. // 防止连续点击发送两次(短时锁定)
  1710. if (liveItem.isSending) return;
  1711. liveItem.isSending = true;
  1712. setTimeout(() => {
  1713. liveItem.isSending = false;
  1714. }, 800); // 800ms 内禁止再次发送
  1715. const text = (liveItem.value || '').trim();
  1716. if (!text) {
  1717. uni.showToast({
  1718. title: "不能发送空消息",
  1719. icon: 'none'
  1720. });
  1721. return;
  1722. }
  1723. const liveId = liveItem.liveId;
  1724. const socketItem = this.socketInstances[liveId];
  1725. // 乐观更新:立即把消息加入到本地聊天列表并清空输入(更好的体验)
  1726. const localMsg = {
  1727. cmd: 'sendMsg',
  1728. msg: text,
  1729. nickName: this.userinfo.nickName,
  1730. avatar: this.userinfo.avatar,
  1731. userId: this.userinfo.userId,
  1732. local: true, // 标记为本地消息(可用于样式或后续差异处理)
  1733. ts: Date.now()
  1734. };
  1735. this.$set(liveItem, 'talklist', [...(liveItem.talklist || []), localMsg]);
  1736. this.$set(liveItem, 'value', ''); // 立即清空输入
  1737. if (!socketItem || !socketItem.instance || !socketItem.isOpen) {
  1738. // 如果 socket 未连接,尝试建立连接(但不要阻塞用户)
  1739. this.initSocket(liveItem);
  1740. uni.showToast({
  1741. title: "连接未建立,正在重连",
  1742. icon: 'none'
  1743. });
  1744. return;
  1745. }
  1746. const data = {
  1747. liveId,
  1748. userId: this.userinfo.userId,
  1749. userType: 0,
  1750. cmd: "sendMsg",
  1751. msg: text,
  1752. nickName: this.userinfo.nickName,
  1753. avatar: this.userinfo.avatar
  1754. };
  1755. try {
  1756. socketItem.instance.send({
  1757. data: JSON.stringify(data),
  1758. success: () => {
  1759. // 比如找到最后一条 local 消息并标记为 sent
  1760. },
  1761. fail: (err) => {
  1762. console.error("发送失败:", err);
  1763. uni.showToast({
  1764. title: "发送失败,请重试",
  1765. icon: 'none'
  1766. });
  1767. // 可选择回滚本地显示(此处简单提示即可)
  1768. }
  1769. });
  1770. } catch (err) {
  1771. console.error('socket send 异常', err);
  1772. }
  1773. }
  1774. }
  1775. };
  1776. </script>
  1777. <style scoped lang="scss">
  1778. .swiper-wrapper {
  1779. position: relative;
  1780. width: 100%;
  1781. height: 100vh;
  1782. overflow: hidden;
  1783. background-color: #000000;
  1784. }
  1785. .swiper-container {
  1786. width: 100%;
  1787. height: 100vh;
  1788. }
  1789. .container {
  1790. width: 100%;
  1791. height: 100%;
  1792. position: relative;
  1793. // 添加渐变过渡效果
  1794. transition: opacity 0.3s ease;
  1795. &.active {
  1796. opacity: 1;
  1797. }
  1798. // 非活动项半透明显示
  1799. // &:not(.active) {
  1800. // opacity: 0.7;
  1801. // }
  1802. }
  1803. .loading-tip {
  1804. position: absolute;
  1805. top: 50%;
  1806. left: 50%;
  1807. transform: translate(-50%, -50%);
  1808. display: flex;
  1809. flex-direction: column;
  1810. align-items: center;
  1811. justify-content: center;
  1812. z-index: 10;
  1813. .loading-text {
  1814. color: #ffffff;
  1815. font-size: 28rpx;
  1816. margin-top: 20rpx;
  1817. }
  1818. }
  1819. .loading-more,
  1820. .no-more {
  1821. display: flex;
  1822. justify-content: center;
  1823. align-items: center;
  1824. padding: 20rpx 0;
  1825. color: #999;
  1826. font-size: 24rpx;
  1827. }
  1828. .loading-more {
  1829. flex-direction: column;
  1830. }
  1831. .preload-indicator {
  1832. position: absolute;
  1833. top: 50%;
  1834. right: 30rpx;
  1835. transform: translateY(-50%);
  1836. z-index: 100;
  1837. background: rgba(0, 0, 0, 0.5);
  1838. border-radius: 50%;
  1839. padding: 16rpx;
  1840. }
  1841. /* button自带样式清除 */
  1842. .student-orther-icon button::after {
  1843. border: none !important;
  1844. padding: 0 !important;
  1845. margin: 0 !important;
  1846. }
  1847. .student-orther-icon button {
  1848. background-color: transparent !important;
  1849. padding: 0 !important;
  1850. line-height: inherit !important;
  1851. margin: 0 !important;
  1852. width: auto !important;
  1853. font-weight: 500 !important;
  1854. border-radius: none !important;
  1855. }
  1856. .welcome-message {
  1857. position: fixed;
  1858. width: 100%;
  1859. bottom: 460rpx;
  1860. left: 50%;
  1861. transform: translateX(-50%);
  1862. color: white;
  1863. padding: 10px 20px;
  1864. border-radius: 20px;
  1865. // animation: fadeOut 1s ease 1s forwards;
  1866. z-index: 1000;
  1867. transition: opacity 0.3s ease;
  1868. }
  1869. @keyframes fadeOut {
  1870. from {
  1871. opacity: 1;
  1872. }
  1873. to {
  1874. opacity: 0;
  1875. }
  1876. }
  1877. .send {
  1878. background-color: #fafafa;
  1879. border-radius: 28rpx;
  1880. padding: 14rpx 16rpx;
  1881. color: #181818;
  1882. font-weight: 500;
  1883. }
  1884. // .container {
  1885. // position: relative;
  1886. // width: 100%;
  1887. // height: 100vh;
  1888. // overflow: hidden;
  1889. // }
  1890. // .talktext {
  1891. // border-radius: 8rpx;
  1892. // background-color: rgba(255, 255, 255, 0.1);
  1893. // view {
  1894. // width: 100%;
  1895. // }
  1896. // }
  1897. .talk-list {
  1898. border-radius: 30rpx;
  1899. background-color: rgba(33, 33, 33, 0.5);
  1900. padding: 10rpx 30rpx;
  1901. }
  1902. // .zoom-button-active {
  1903. // transform: scale(1.5);
  1904. // }
  1905. // .background-image {
  1906. // position: absolute;
  1907. // top: 0;
  1908. // left: -40rpx;
  1909. // width: 110%;
  1910. // height: 110%;
  1911. // object-fit: cover;
  1912. // filter: blur(20px);
  1913. // z-index: 0;
  1914. // }
  1915. // .background-images {
  1916. // position: absolute;
  1917. // top: 0;
  1918. // left: -40rpx;
  1919. // width: 110%;
  1920. // height: 110%;
  1921. // object-fit: cover;
  1922. // filter: blur(20px);
  1923. // z-index: 6;
  1924. // }
  1925. // .blackbg {
  1926. // position: absolute;
  1927. // top: 0;
  1928. // left: 0;
  1929. // width: 100%;
  1930. // height: 100%;
  1931. // background: rgba(0, 0, 0, 0.7);
  1932. // object-fit: cover;
  1933. // filter: blur(10px);
  1934. // z-index: 1;
  1935. // }
  1936. .content {
  1937. position: relative;
  1938. z-index: 2;
  1939. height: 100%;
  1940. width: 100%;
  1941. top: 0;
  1942. left: 0;
  1943. display: flex;
  1944. flex-direction: column;
  1945. justify-content: space-between;
  1946. .hongbao-box {
  1947. position: fixed;
  1948. top: 200rpx;
  1949. left: 30rpx;
  1950. z-index: 5;
  1951. border-radius: 16rpx;
  1952. background-color: rgba(77, 77, 77, 0.5);
  1953. .tip {
  1954. position: absolute;
  1955. width: 100%;
  1956. bottom: 0;
  1957. color: #fafcff;
  1958. font-size: 20rpx;
  1959. background-color: rgba(15, 15, 15, 0.8);
  1960. border-radius: 16rpx;
  1961. text-align: center;
  1962. padding: 4rpx 0;
  1963. }
  1964. .item {
  1965. padding: 10rpx 4rpx;
  1966. image {
  1967. width: 80rpx;
  1968. margin: 6rpx 0;
  1969. }
  1970. }
  1971. }
  1972. .siderow-group {
  1973. position: absolute;
  1974. top: 65%;
  1975. right: 30rpx;
  1976. z-index: 9;
  1977. display: flex;
  1978. flex-direction: column;
  1979. align-items: center;
  1980. .side-item {
  1981. font-weight: 500;
  1982. font-size: 24rpx;
  1983. color: #FFFFFF;
  1984. margin-bottom: 32rpx;
  1985. text-align: center;
  1986. .button {
  1987. background-color: transparent;
  1988. margin: 0;
  1989. line-height: 1;
  1990. padding: 0;
  1991. }
  1992. .image {
  1993. width: 72rpx;
  1994. height: 72rpx;
  1995. }
  1996. }
  1997. }
  1998. .side-group {
  1999. position: absolute;
  2000. // top: 30%;
  2001. top: 65%;
  2002. right: 30rpx;
  2003. z-index: 9;
  2004. display: flex;
  2005. flex-direction: column;
  2006. align-items: center;
  2007. .side-item {
  2008. font-weight: 500;
  2009. font-size: 24rpx;
  2010. color: #FFFFFF;
  2011. margin-bottom: 32rpx;
  2012. text-align: center;
  2013. .button {
  2014. background-color: transparent;
  2015. margin: 0;
  2016. line-height: 1;
  2017. padding: 0;
  2018. }
  2019. .image {
  2020. width: 72rpx;
  2021. height: 72rpx;
  2022. }
  2023. }
  2024. }
  2025. .content-top {
  2026. width: 100%;
  2027. margin-top: 68rpx;
  2028. display: flex;
  2029. justify-content: space-between;
  2030. padding: 0 24rpx;
  2031. box-sizing: border-box;
  2032. .sum {
  2033. width: 80rpx;
  2034. height: 52rpx;
  2035. background: rgba(0, 0, 0, 0.5);
  2036. border-radius: 26rpx 26rpx 26rpx 26rpx;
  2037. font-size: 24rpx;
  2038. color: #FFFFFF;
  2039. text-align: center;
  2040. line-height: 52rpx;
  2041. }
  2042. }
  2043. .follow-btn {
  2044. padding: 8rpx 16rpx;
  2045. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  2046. border-radius: 26rpx;
  2047. font-weight: 500;
  2048. font-size: 26rpx;
  2049. color: #FFFFFF;
  2050. }
  2051. }
  2052. .videolist {
  2053. position: relative;
  2054. .video {
  2055. height: 100vh;
  2056. /* 占屏幕高度的80% */
  2057. width: 100%;
  2058. background-color: rgba(57, 57, 57, 0.4);
  2059. .time {
  2060. color: #ffffff;
  2061. font-size: 20rpx;
  2062. margin-left: 10rpx;
  2063. }
  2064. .videotop {
  2065. width: 100%;
  2066. height: 100%;
  2067. }
  2068. .video_row {
  2069. width: 100%;
  2070. max-height: 500rpx;
  2071. overflow: hidden;
  2072. margin-top: 360rpx;
  2073. }
  2074. }
  2075. }
  2076. .integral-box {
  2077. width: 300rpx;
  2078. display: flex;
  2079. flex-direction: column;
  2080. align-items: center;
  2081. border-radius: 20rpx;
  2082. overflow: hidden;
  2083. .top {
  2084. width: 100%;
  2085. position: relative;
  2086. .title {
  2087. width: 100%;
  2088. font-weight: 600;
  2089. font-size: 30rpx;
  2090. color: #FFFFFF;
  2091. text-shadow: 0px 4px 8px rgba(255, 89, 2, 0.8);
  2092. position: absolute;
  2093. top: 30rpx;
  2094. text-align: center;
  2095. }
  2096. .photo {
  2097. width: 100%;
  2098. }
  2099. }
  2100. .item {
  2101. padding: 20rpx;
  2102. .title {
  2103. font-weight: 500;
  2104. font-size: 30rpx;
  2105. text-align: center;
  2106. }
  2107. .button {
  2108. margin-top: 20rpx;
  2109. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  2110. color: #fff;
  2111. text-align: center;
  2112. padding: 16rpx 30rpx;
  2113. border-radius: 10rpx;
  2114. font-weight: 500;
  2115. }
  2116. }
  2117. }
  2118. .goods {
  2119. position: fixed;
  2120. // bottom: 160rpx;
  2121. // right: 10rpx;
  2122. top: 50%;
  2123. left: 50%;
  2124. transform: translate(-50%, -50%);
  2125. z-index: 5;
  2126. background-color: #fff;
  2127. border-radius: 20rpx;
  2128. overflow: hidden;
  2129. width: 300rpx;
  2130. // width: 220rpx;
  2131. padding: 4rpx;
  2132. .top {
  2133. position: absolute;
  2134. top: 4rpx;
  2135. display: flex;
  2136. justify-content: space-between;
  2137. align-items: center;
  2138. color: #fff;
  2139. width: 100%;
  2140. padding-right: 10rpx;
  2141. box-sizing: border-box;
  2142. .left {
  2143. background-color: rgba(0, 0, 0, 0.8);
  2144. padding: 10rpx;
  2145. font-size: 20rpx;
  2146. display: flex;
  2147. justify-content: space-between;
  2148. align-items: center;
  2149. border-radius: 10rpx;
  2150. }
  2151. }
  2152. .photo {
  2153. width: 100%;
  2154. height: 250rpx;
  2155. border-radius: 16rpx 16rpx 0 0;
  2156. overflow: hidden;
  2157. }
  2158. .item {
  2159. padding: 4rpx;
  2160. .price {
  2161. .red {
  2162. color: #FF5701;
  2163. font-weight: 600;
  2164. margin-right: 10rpx;
  2165. }
  2166. .del {
  2167. color: #828282;
  2168. font-weight: 500;
  2169. font-size: 24rpx;
  2170. text-decoration: line-through
  2171. }
  2172. }
  2173. .title {
  2174. font-weight: 500;
  2175. font-size: 26rpx;
  2176. margin: 10rpx 0 12rpx;
  2177. }
  2178. .button {
  2179. background: linear-gradient(270deg, #ff4702 0%, #fe6304 100%);
  2180. color: #fff;
  2181. text-align: center;
  2182. padding: 16rpx 0;
  2183. border-radius: 10rpx;
  2184. font-weight: 500;
  2185. }
  2186. }
  2187. }
  2188. .icon {
  2189. font-weight: 500;
  2190. font-size: 24rpx;
  2191. color: #FFFFFF;
  2192. text-align: center;
  2193. margin-bottom: -10rpx;
  2194. .button {
  2195. background-color: transparent;
  2196. margin: 0;
  2197. line-height: 1;
  2198. padding: 0;
  2199. }
  2200. }
  2201. .icon-bg {
  2202. background-color: rgba(57, 57, 57, 0.8);
  2203. border-radius: 50%;
  2204. width: 72rpx;
  2205. height: 72rpx;
  2206. display: flex;
  2207. justify-content: center;
  2208. align-items: center;
  2209. transition: transform 0.2s ease;
  2210. .button {
  2211. background-color: transparent;
  2212. margin: 0;
  2213. line-height: 1;
  2214. padding: 0;
  2215. }
  2216. }
  2217. .list {
  2218. width: 80%;
  2219. margin-bottom: 20rpx;
  2220. animation: xxxawdawd .2s;
  2221. }
  2222. @keyframes xxxawdawd {
  2223. from {
  2224. margin-top: 0rpx;
  2225. opacity: 0;
  2226. }
  2227. to {
  2228. margin-top: 20rpx;
  2229. opacity: 1;
  2230. }
  2231. }
  2232. .shop-prompt {
  2233. position: absolute;
  2234. bottom: 600rpx;
  2235. left: 24rpx;
  2236. padding: 6rpx 20rpx;
  2237. background: rgba(230, 154, 34, 0.7);
  2238. border-radius: 24rpx;
  2239. z-index: 9;
  2240. font-weight: 500;
  2241. font-size: 26rpx;
  2242. color: #FFFFFF;
  2243. transition: opacity 0.3s ease;
  2244. }
  2245. .red-box {
  2246. .button {
  2247. margin: 0 auto;
  2248. width: 80%;
  2249. line-height: 88rpx;
  2250. height: 88rpx;
  2251. background: linear-gradient(90deg, #FF5701 0%, #FFB501 100%);
  2252. box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(238, 124, 80, 0.2);
  2253. border-radius: 44rpx 44rpx 44rpx 44rpx;
  2254. font-weight: 600;
  2255. font-size: 32rpx;
  2256. color: #FFFFFF;
  2257. text-align: center;
  2258. }
  2259. }
  2260. .view-box {
  2261. position: relative;
  2262. height: 40vh;
  2263. /* 设置弹出层高度为视窗高度的70% */
  2264. padding: 40rpx 0rpx 120rpx;
  2265. box-sizing: border-box;
  2266. display: flex;
  2267. flex-direction: column;
  2268. .scroll-content {
  2269. flex: 1;
  2270. overflow-y: auto;
  2271. padding: 0 40rpx;
  2272. }
  2273. .bottom {
  2274. padding: 20rpx 40rpx;
  2275. position: absolute;
  2276. bottom: 0;
  2277. width: 100%;
  2278. box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(195, 195, 195, 0.3);
  2279. background: #fff;
  2280. }
  2281. }
  2282. // 抽奖
  2283. .answerpop {
  2284. background: linear-gradient(to right, #fff7f8, #fee1e2);
  2285. margin-top: 30rpx;
  2286. padding: 10rpx 20rpx;
  2287. width: calc(100% - 40rpx);
  2288. border-radius: 20rpx;
  2289. display: flex;
  2290. align-items: center;
  2291. justify-content: space-between;
  2292. box-shadow: 2px 2px 4px 0 rgba(255, 124, 126, 0.1);
  2293. .answera {
  2294. display: flex;
  2295. justify-content: center;
  2296. background-color: #fff;
  2297. padding: 20rpx 0;
  2298. width: 35%;
  2299. border-radius: 40rpx;
  2300. align-items: center;
  2301. margin: 10rpx 0;
  2302. box-shadow: 2px 2px 4px 0 rgba(72, 72, 72, 0.1);
  2303. image {
  2304. width: 40rpx;
  2305. height: 40rpx;
  2306. margin-right: 10rpx;
  2307. }
  2308. }
  2309. }
  2310. .shoppop {
  2311. padding: 22rpx 16rpx;
  2312. .shoppop-top {
  2313. display: flex;
  2314. justify-content: space-between;
  2315. align-items: center;
  2316. padding: 0 16rpx 22rpx;
  2317. .search-input {
  2318. width: 414rpx;
  2319. height: 76rpx;
  2320. background: #FFFFFF;
  2321. border-radius: 36rpx;
  2322. margin-left: 20rpx;
  2323. padding: 0 32rpx;
  2324. box-sizing: border-box;
  2325. font-size: 24rpx;
  2326. margin-right: 24rpx;
  2327. }
  2328. .search-top {
  2329. font-size: 20rpx;
  2330. color: #222222;
  2331. }
  2332. }
  2333. .shop-list {
  2334. overflow: hidden;
  2335. .list-item {
  2336. display: flex;
  2337. align-items: center;
  2338. padding: 20rpx 16rpx;
  2339. background: #FFFFFF;
  2340. border-radius: 16rpx;
  2341. margin-bottom: 16rpx;
  2342. .goods-img {
  2343. width: 200rpx;
  2344. height: 200rpx;
  2345. border-radius: 16rpx;
  2346. overflow: hidden;
  2347. position: relative;
  2348. margin-right: 24rpx;
  2349. image {
  2350. width: 100%;
  2351. height: 100%;
  2352. }
  2353. .goods-label {
  2354. position: absolute;
  2355. top: 0;
  2356. width: 64rpx;
  2357. height: 40rpx;
  2358. background: rgba(0, 0, 0, 0.5);
  2359. border-radius: 16rpx 0rpx 16rpx 0rpx;
  2360. text-align: center;
  2361. font-weight: 500;
  2362. font-size: 28rpx;
  2363. color: #FFFFFF;
  2364. }
  2365. }
  2366. .goods-right {
  2367. flex: 1;
  2368. .goods-title {
  2369. font-weight: 500;
  2370. font-size: 28rpx;
  2371. color: #000000;
  2372. }
  2373. .goods-details {
  2374. font-size: 24rpx;
  2375. color: #999999;
  2376. margin: 10rpx 0 20rpx;
  2377. }
  2378. .goods-people {
  2379. font-size: 22rpx;
  2380. color: #E69A22;
  2381. height: 56rpx;
  2382. }
  2383. .goods-shop {
  2384. display: flex;
  2385. justify-content: space-between;
  2386. .nummber {
  2387. color: #FF5C03;
  2388. font-size: 22rpx;
  2389. font-weight: 500;
  2390. }
  2391. .btn-group {
  2392. text-align: center;
  2393. line-height: 56rpx;
  2394. .collect-btn {
  2395. width: 72rpx;
  2396. background: #F5F7FA;
  2397. border-radius: 8rpx 0rpx 0rpx 8rpx;
  2398. }
  2399. .shop-btn {
  2400. width: 152rpx;
  2401. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  2402. border-radius: 0rpx 8rpx 8rpx 0rpx;
  2403. font-weight: 500;
  2404. font-size: 26rpx;
  2405. color: #FFFFFF;
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. :deep(.u-list-item) {
  2414. width: 100%;
  2415. display: flex;
  2416. align-items: center;
  2417. }
  2418. :deep(.u-safe-area-inset-bottom) {
  2419. padding-bottom: 0
  2420. }
  2421. </style>