living.vue 56 KB

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