living.vue 60 KB

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