living.vue 63 KB

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