living.vue 59 KB

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