living.vue 60 KB

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