living.vue 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. <template>
  2. <view class="container">
  3. <!-- <view class="popup-video " v-if="!autoplay">
  4. <view class="fs36 bold" v-if="livedata.status==1">——直播还未开始——</view>
  5. <view class="fs36 bold" v-if="livedata.status==3">——直播已经结束——</view>
  6. <view class="fs28 mtb20">了解更多,点击下方联系老师</view>
  7. <view class="more" @click="showadd=!showadd">联系老师</view>
  8. </view> -->
  9. <!-- <image :src="livedata.liveImgUrl"
  10. :class="livedata.status!=2?'background-images':'background-image'"></image> -->
  11. <view class="blackbg"></view>
  12. <view class="content">
  13. <!-- 页面内容 -->
  14. <view style=" position: fixed;top: 0;z-index: 5;" class="content-top">
  15. <view class="u-flex-y-center">
  16. <image @click="goBack" style="width: 60rpx;height: 64rpx;margin-right: 26rpx;"
  17. src="@/static/images/live/return.png"></image>
  18. <view class=" align-center"
  19. style="padding: 6rpx 4rpx;height: 64rpx;background: rgba(0,0,0,0.5);border-radius: 32rpx;">
  20. <u-avatar :src="livedata.liveImgUrl" size="32"></u-avatar>
  21. <view class="colorf" style="margin-left: 8rpx;">
  22. <view>{{livedata.liveName?livedata.liveName:"芳华未来"}}</view>
  23. <view style="font-size: 16rpx;">
  24. {{ liveViewData.follow || liveViewData.follow === 0 ? liveViewData.follow : 0 }}位粉丝
  25. </view>
  26. </view>
  27. <view v-if="isFollow" @click="onFollow" class="follow-btn ml20">关注</view>
  28. <view v-else @click="onFollow" class="follow-btn ml20">已关注</view>
  29. </view>
  30. </view>
  31. <view class="u-flex-end align-center">
  32. <image class="w52 h52 mr4" v-for="(item,index) in filteredViewers" :key="index"
  33. style="border-radius: 26rpx;" :src="item.avatar"></image>
  34. <view class="sum">{{liveViewData.online}}</view>
  35. </view>
  36. </view>
  37. <!-- 右边的 -->
  38. <view class="side-group">
  39. <view class="side-item">
  40. <image @click="onLike()" src="/static/images/live/like.png"></image>
  41. <view>{{liveViewData.like}}</view>
  42. <!-- <view>{{liveData likeName}}</view> -->
  43. </view>
  44. <view class="side-item" @click="goStore()">
  45. <image src="/static/images/live/shop.png"></image>
  46. <view>店铺</view>
  47. </view>
  48. <view class="side-item">
  49. <image src="/static/images/live/share.png"></image>
  50. <view>分享</view>
  51. </view>
  52. </view>
  53. <view class="shop-prompt u-flex-y-center">
  54. <image class="w32 h32 mr8" src="/static/images/live/shopping.png"></image>
  55. <text> {{orderUser.userName ? maskString(orderUser.userName) : ''}} 等 {{orderUser.count || 0}}
  56. 人正在去购买</text>
  57. </view>
  58. <!-- object-fit:fill; -->
  59. <view class="videolist " style="margin: auto 0">
  60. <view class="video" :style="{height:isScreen?'100vh':''}">
  61. <!-- 修改video组件以支持HLS -->
  62. <video v-if="livingUrl" id="myVideo" class="videotop" :src="livingUrl" :autoplay="autoplay"
  63. :controls='false' object-fit='contain' :custom-cache="false" :enable-progress-gesture="false"
  64. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false" :http-cache="false"
  65. @error="videoError">
  66. </video>
  67. <video v-if="videoUrl" class="videotop" :src="videoUrl" :autoplay="autoplay" :controls='false'
  68. object-fit='contain' :custom-cache="false" :enable-progress-gesture="false"
  69. vslide-gesture-in-fullscreen='true' :show-center-play-btn="false" :http-cache="false" loop
  70. @error="videoError">
  71. </video>
  72. </view>
  73. </view>
  74. <view class="pb40 mt90" style="position: fixed;bottom: 0;">
  75. <view class="w100 h300 mt20">
  76. <scroll-view enable-flex scroll-y="true" class="talk p20 scrolly flex-1 column"
  77. style="width: calc(100% - 40rpx);height: calc(100% - 40rpx);"
  78. :scroll-into-view="scrollIntoView">
  79. <view>
  80. <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  81. :id="`list_${index}`" v-show="item.cmd=='announcement'">
  82. <view class="talk-list ml16 justify-start">
  83. <view class="fs24">
  84. <text class='fs24 colorf'> {{item.msg}}直播间{{messageContent}}</text>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 弹幕 -->
  90. <!-- <u-list class="chat-list" height="184" @scrolltolower="scrollchat">
  91. <u-list-item class="chat-item" v-for="(item,index) in chatList" :key="index">
  92. <view class="chat-lable u-flex-y-center mr8" v-if="item.lable">
  93. <image class="w24 h24 mr8" src="@/static/images/live/diamond.png"></image>
  94. <text>{{item.lable}}</text>
  95. </view>
  96. <text style="color: #FFDA73;white-space: nowrap;" class=" mr8">{{item.name}}:</text>
  97. <text style="flex: 1;min-width: 0;word-break: break-word;">{{item.txt}}</text>
  98. </u-list-item>
  99. </u-list> -->
  100. <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  101. :id="`list_${index}`" v-show="item.cmd=='sendMsg'">
  102. <view class="talk-list ml16 justify-start">
  103. <view class="fs24">
  104. <!-- <text style="color: #3fc69b;transform: scale(0.8);display: inline-block; "v-if="item.userId==userinfo.userId&&item.cmd=='sendMsg'">我</text> -->
  105. <!-- <text style="color: #c84e1e;transform: scale(0.8);display: inline-block;" v-if="item.userType==1">[ 管理员 ]</text> -->
  106. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  107. <text class='fs24 colorf'>{{item.msg}}</text>
  108. </view>
  109. </view>
  110. </view>
  111. <!-- <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  112. :id="`list_${index}`" v-show="item.cmd=='sendMsg'">
  113. <view class="talk-list ml16 justify-start">
  114. <view class="fs24">
  115. <text style="color: #3fc69b;transform: scale(0.8);display: inline-block; "
  116. v-if="item.userId==userinfo.userId&&item.cmd=='sendMsg'">我</text>
  117. <text style="color: #c84e1e;transform: scale(0.8);display: inline-block;" v-if="item.userType==1">
  118. [ 管理员 ]</text>
  119. <text style="color: #FFDA73;">{{item.nickName}}:</text>
  120. <text class='fs24 colorf'>{{item.msg}}</text>
  121. </view>
  122. </view>
  123. </view> -->
  124. <view v-if="showWelcomeMessage" class="welcome-message">
  125. <view class="list justify-start" v-for="(item,index) in talklist" :key="item.index"
  126. :id="`list_${index}`" v-show="item.cmd=='entry'||item.cmd=='out'">
  127. <view class="talk-list ml16 justify-start">
  128. <view class="fs24">
  129. <text style="color: #ff89d6;">{{item.nickName}} </text>
  130. <text class='fs24 colorf'> {{item.msg}}直播间{{messageContent}}</text>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. </scroll-view>
  136. </view>
  137. <view class="justify-between p24">
  138. <view class="u-flex-y-center"
  139. style="background:rgba(157, 157, 157, 0.8);padding:18rpx 14rpx 18rpx 32rpx;width: 526rpx;box-sizing:border-box;border-radius:36rpx;">
  140. <u-input :placeholder="placeholderText" border="none" customStyle='font-size:24rpx;'
  141. v-model="value" shape='circle' color='#fff' placeholderStyle='color:#e7e7e7' class="ml20"
  142. @keydown.enter="sendMsg" @confirm="sendMsg">
  143. </u-input>
  144. <!-- <image @click="sendMsg" class="w44 h44" src="@/static/images/live/like.png"></image> -->
  145. </view>
  146. <!-- :disabled='talkdisabled' ></u-input> -->
  147. <!-- <view @click="sendMsg" class="colorf center ml10 fs24">发送</view> -->
  148. <view class="justify-between mr30 align-center">
  149. <!-- <view class="icon-bg ml20" @click="answerbtn=!answerbtn">
  150. <image src="/static/images/redbag.png" class="w40 h40"></image>
  151. </view> -->
  152. <view class="icon-bg ml20" @click="shopping=!shopping">
  153. <image src="/static/images/shopping.png" class="w48 h48"></image>
  154. </view>
  155. <view class="icon-bg ml20" @click="showziliao=!showziliao">
  156. <image src="/static/images/more-icon.png" class="w48 h48"></image>
  157. </view>
  158. <!-- <view class="icon-bg ml20" :class="{ 'zoom-button-active': isZoom }"
  159. @touchstart="handleTouchStart" @touchend="handleTouchEnd">
  160. <image src="/static/images/dianzan.png" class="w40 h40"></image>
  161. </view> -->
  162. </view>
  163. </view>
  164. </view>
  165. </view>
  166. <!-- <u-popup :show="showadd" @close="close" @open="open" round='20rpx' bgColor='#fffee1'>
  167. <view class="addchat p20">
  168. <view class="u-flex-row-reverse u-flex">
  169. <u-icon name="close" size="18" @click="showadd=!showadd"></u-icon>
  170. </view>
  171. <view class="column align-center">
  172. <view class="fs36" style="color: #ff5c03;">扫码添加助教老师</view>
  173. <view class="fs28 color6">扫码添加助教老师</view>
  174. <view class="p10 mt40" style="border: #ff5c03 solid 2rpx;">
  175. <image :src="codeimg" class="wh180" @touchstart="longPress" @touchend="cancelLongPress">
  176. </image>
  177. </view>
  178. <view class="color6 mt20">长按识别二维码</view>
  179. </view>
  180. </view>
  181. </u-popup> -->
  182. <u-popup :show="showziliao" @close="closes" round='20' bgColor='#fffee1'>
  183. <view class="addchat p20 bgf" style="border-radius: 20rpx;">
  184. <view class="u-flex-row-reverse u-flex">
  185. <u-icon name="close" size="18" @click="showziliao=!showziliao"></u-icon>
  186. </view>
  187. <view class="column align-center h400">
  188. <view class="fs36 " style="color: #ff5c03;">资料</view>
  189. <view v-html="livedata.liveDesc"></view>
  190. </view>
  191. </view>
  192. </u-popup>
  193. <!-- 抽奖 -->
  194. <!-- <u-popup :show="answerbtn" @close="closeanswer" round='40rpx' bgColor='#fff'>
  195. <view class=" p20 bgf" style="border-radius: 40rpx;height: fit-content;">
  196. <view class="u-flex-row-reverse u-flex">
  197. <u-icon name="close" size="18" @click="answerbtn=!answerbtn"></u-icon>
  198. </view>
  199. <view class="column align-center h400">
  200. <view class="fs36 " style="color: #000000;font-weight: bold;">答题获取红包/积分奖励</view>
  201. <view class="answerpop" @click="noredanswer">
  202. <view class="color6 w350 fs24">
  203. 边玩边学,解锁你的知识巅峰!
  204. </view>
  205. <view class="answera">答题挑战</view>
  206. </view>
  207. <view class="answerpop">
  208. <view class="color6 fs24" v-if='redanswertips&&redanswertips.length>0'>
  209. 🔥 <text style="color: #ff5c03;" class="fs30 bold">{{redanswertips[1].probability}}</text>
  210. %用户首抽得
  211. <text style="color: #ff5c03;" class="fs40 bold">{{redanswertips[1].maxAmount}}</text>元
  212. </view>
  213. <view v-else class="color6 w350 fs24">
  214. 随机奖励
  215. </view>
  216. <view class="answera" @click="redbagAnswer">
  217. <image src="/static/images/baganswer.png"></image>
  218. <view> 获得红包</view>
  219. </view>
  220. </view>
  221. </view>
  222. </view>
  223. </u-popup> -->
  224. <!-- <u-popup :show="showAnswer" @close="closest" round='40' bgColor='#fffee1' mode="center">
  225. <view class="answerbox p20 bgf">
  226. <view class="u-flex-row-reverse u-flex">
  227. <u-icon name="close" size="18" @click="closest"></u-icon>
  228. </view>
  229. <view class="column align-center ">
  230. <view v-if="answerlist.type==1" style="width: 100%;">
  231. <view class="mb40" style="text-align: center;">
  232. <text class="color9 fs24">(单选)</text>{{answerlist.title}}
  233. </view>
  234. <view v-for="(item,index) in answerlist.content" :key="index"
  235. :class=" checkboxValue[0]== item.label?'answeract itemanswer':'itemanswer' "
  236. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  237. </view>
  238. <view v-if="answerlist.type==2" style="width: 100%;">
  239. <view class="mb40 " style="text-align: center;">
  240. <text class="color9 fs24">(多选)</text>{{answerlist.title}}
  241. </view>
  242. <view v-for="(item,index) in answerlist.content" :key="index"
  243. :class=" checkboxValue.includes(item.label)?'answeract itemanswer':'itemanswer' "
  244. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  245. <view class=" submitbtn" @click="submitAnswers">确认</view>
  246. </view>
  247. <view class="fs24 mtb20 " style="color: #717171;">
  248. {{answerfrist+1}}/{{Answerlistall}}
  249. </view>
  250. </view>
  251. </view>
  252. </u-popup> -->
  253. <!-- <u-popup :show="showAnswerred" @close="closestred" round='40' bgColor='#fffee1' mode="center">
  254. <view class="answerbox p20 bgf">
  255. <view class="u-flex-row-reverse u-flex">
  256. <u-icon name="close" size="18" @click="closestred"></u-icon>
  257. </view>
  258. <view class="column align-center ">
  259. <view v-if="answerlist.type==1" style="width: 100%;">
  260. <view class="mb40" style="text-align: center;">
  261. <text class="color9 fs24">(单选)</text>{{answerlist.title}}
  262. </view>
  263. <view v-for="(item,index) in answerlist.content" :key="index"
  264. :class=" checkboxValue[0]== item.label?'answeract itemanswer':'itemanswer' "
  265. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  266. </view>
  267. <view v-if="answerlist.type==2" style="width: 100%;">
  268. <view class="mb40 " style="text-align: center;">
  269. <text class="color9 fs24">(多选)</text>{{answerlist.title}}
  270. </view>
  271. <view v-for="(item,index) in answerlist.content" :key="index"
  272. :class=" checkboxValue.includes(item.label)?'answeract itemanswer':'itemanswer' "
  273. @click="handleCheckboxSelect(item.label)">{{item.label}}. {{item.content}}</view>
  274. <view class=" submitbtn" @click="submitAnswers">确认</view>
  275. </view>
  276. <view class="fs24 mtb20 " style="color: #717171;">
  277. {{answerfrist+1}}/{{Answerlistall}}
  278. </view>
  279. </view>
  280. </view>
  281. </u-popup> -->
  282. <!-- 小黄车弹窗 -->
  283. <u-popup :show="shopping" @close="closeshop" @open="open" round='20rpx' bgColor='#f3f5f9'>
  284. <view class="shoppop">
  285. <view class="shoppop-top">
  286. <u-avatar :src="livedata.liveImgUrl" size="36" class="ml16"></u-avatar>
  287. <view class="search-input u-flex-y-center">
  288. <image style="width: 24rpx;height: 24rpx;margin-right: 16rpx;" src="@/static/images/search.png">
  289. </image>
  290. <input placeholder="搜索商品或序号" />
  291. </view>
  292. <view class="t-c search-top" style="margin-right: 48rpx;" @click="onCollect">
  293. <image style="width: 32rpx;height: 32rpx;" src="@/static/images/collect.png"></image>
  294. <view>收藏</view>
  295. </view>
  296. <view class="t-c search-top" @click="goOrderList">
  297. <image style="width: 32rpx;height: 32rpx;" src="@/static/images/order.png"></image>
  298. <view>订单</view>
  299. </view>
  300. </view>
  301. <scroll-view enable-flex scroll-y class="shop-list" :style="{ height: boxHeight + 'px' }">
  302. <view class="list-item " v-for="(item,index) in products" :key="index">
  303. <view class="goods-img">
  304. <image :src="item.imgUrl" mode="widthFix"></image>
  305. <view class="goods-label">{{index+1}}</view>
  306. </view>
  307. <view class="goods-right">
  308. <view class="goods-title">{{item.productName}}</view>
  309. <view class="goods-details">{{item.productIntroduce}}</view>
  310. <view class="goods-people">{{item.sales}} 人已购</view>
  311. <view class="goods-shop">
  312. <text class="nummber"><text style="font-size: 20rpx;font-weight: 600;">¥</text><text
  313. style="font-size: 36rpx;font-weight: bold;">{{Math.trunc(item.price)}}</text>.{{getPureDecimal(item.price)?getPureDecimal(item.price):'00'}}/日</text>
  314. <view class="btn-group u-flex-y-center">
  315. <view class="collect-btn">
  316. <image @click="onCollect(item)" style="width: 32rpx;height: 32rpx;"
  317. src="/static/images/collect.png">
  318. </image>
  319. </view>
  320. <view v-if="item.status==1" class="shop-btn"
  321. @click="goShop(item.productId,item.goodsId)">去购买
  322. </view>
  323. <view v-else-if="item.status==0" @click="goShop(item.productId)" class="shop-btn">
  324. 已下架</view>
  325. </view>
  326. </view>
  327. </view>
  328. </view>
  329. </scroll-view>
  330. </view>
  331. </u-popup>
  332. </view>
  333. </template>
  334. <script>
  335. import Hls from 'hls.js';
  336. import CryptoJS from 'crypto-js'
  337. import {
  338. liveDataLike, // 点赞
  339. collectStore, // 收藏/取消收藏
  340. follow, // 关注/取消关注
  341. getRecentLiveViewers, //获取直播间用户(展示在线用户)
  342. // 小黄车
  343. liveStore, //店铺展示,
  344. // liveGoodsDetail, //商品详情,
  345. liveOrderUser, //正在购买
  346. getLiveInfo, //获取直播间信息接口
  347. getLiveViewData //直播间点赞、关注、在线人数数据
  348. } from '@/api/live'
  349. import {
  350. liveOrderList, // 订单列表
  351. } from '@/api/order'
  352. import parse from '../../uni_modules/uview-plus/libs/config/props/parse';
  353. import {
  354. LiveWS
  355. } from '@/utils/liveWS.js'
  356. import {
  357. getlive,
  358. gettextlist,
  359. getAnswerlist,
  360. submitAnswer
  361. } from '@/api/home'
  362. // var wsUrl = "ws://192.168.10.166:7114/app/webSocket";
  363. var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
  364. // var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket"; //余红奇
  365. // var wsUrl = "ws://nd383294.natappfree.cc/app/webSocket"; //余红奇
  366. // var wsUrl = "ws://v56c9b8e.natappfree.cc/app/webSocket"; //余红奇
  367. // var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; //陈果
  368. // var wsUrl = "ws://live.ylrzcloud.com/socket/app/webSocket";
  369. var pingpangTimes = null;
  370. var initTimes = null;
  371. var isSocketOpen = false;
  372. var socket = null;
  373. export default {
  374. data() {
  375. return {
  376. videoUrl: null,
  377. showType: 1, //横屏1 竖屏2
  378. boxHeight: 300, //小黄车高度
  379. isFollow: true,
  380. liveViewData: {},
  381. liveViewers: [], //观众
  382. likeName: 0,
  383. hlsPlayer: null, // HLS播放器实例,
  384. livingUrl: "",
  385. products: {},
  386. store: {},
  387. orderUser: {}, //正在购买
  388. userType: 0,
  389. timestamp: '',
  390. liveId: null,
  391. // userId: uni.getStorageSync("userInfo.userId"),
  392. livedata: {},
  393. codeimg: '',
  394. placeholderText: '说点什么...',
  395. isZoom: false, //点赞按钮控制是否放大
  396. userinfo: '', //用户信息
  397. path: 'http://192.168.10.166/dev-api', //余红奇
  398. // path: 'http://v56c9b8e.natappfree.cc', //余红奇
  399. // path: 'live.test.ylrztop.com/prod-api', //余红奇
  400. // path: 'http://192.168.10.170/dev-api', //陈果
  401. value: '',
  402. talkdisabled: false, //输入框是否禁用
  403. autoplay: false, //视频自动播放
  404. showadd: false,
  405. talklist: [],
  406. scrollIntoView: '',
  407. bufferRate: 0, //视频缓冲时间
  408. playDuration: 0, //视频播放时间
  409. videoContext: '',
  410. thistime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
  411. upDown: true, //是否视频显示隐藏
  412. isLongPress: false, // 是否长按
  413. timeout: null, // 计时器
  414. showWelcomeMessage: false,
  415. isSubmit: false,
  416. messageContent: "",
  417. showziliao: false,
  418. isScreen: true,
  419. showAnswer: false, //展示答题
  420. Answerlistall: {}, //所有题目
  421. answerlist: {}, //当前题目
  422. answerfrist: 0, //当前选择
  423. checkboxValue: [], //多选数据
  424. checkboxFormValue: "", //多选数据
  425. allAnswerLists: [], // 新增:存储所有题目列表
  426. showAnswerred: false, //展示红包答题
  427. answerbtn: false, //答题按钮弹窗
  428. redallAnswerLists: [], //储存所有红包答题列表
  429. redanswerAll: [], //红包当前题目
  430. redanswerList: [], //红包答题列表
  431. redanswertips: [], //红包答题提示
  432. shopping: false, //小黄车弹窗
  433. scrollTop: 0, //弹幕
  434. old: {
  435. scrollTop: 0
  436. },
  437. // liveData: {}, //直播间点赞、关注、在线人数数据
  438. };
  439. },
  440. onLoad(options) {
  441. if (options.liveId) {
  442. this.liveId = options.liveId;
  443. // this.liveId = decodeURIComponent(options.liveId);
  444. console.log("接收到的liveId:", this.liveId);
  445. }
  446. },
  447. computed: {
  448. filteredViewers() {
  449. // 只返回前3项(索引0、1、2)
  450. return this.liveViewers.slice(0, 3);
  451. }
  452. },
  453. mounted() {
  454. // this.onLike()
  455. this.getliveViewData() ////直播间点赞、关注、在线人数数据
  456. this.intervalId = setInterval(() => {
  457. this.getliveViewData();
  458. }, 60 * 1000);
  459. // this.getLiveinformation() // 获取直播间信息接口
  460. this.getliveOrder() //正在购买
  461. this.getliveStore() // 获取小黄车 店铺展示
  462. // this.getliveGoods() // 获取小黄车 商品详情
  463. this.getliveUser() // 获取直播间用户
  464. this.initTime()
  465. // this.initWebSocket()
  466. this.initSocket()
  467. var that = this;
  468. uni.$on('initSocket', () => {
  469. that.initSocket()
  470. })
  471. uni.$on('sendMsg', (item) => {
  472. that.sendMsg(item)
  473. })
  474. uni.$on('closeWebSocket', () => {
  475. that.closeWebSocket()
  476. })
  477. this.getEWechatSdk();
  478. this.getliving() //hls
  479. this.gettalklist()
  480. // this.getAnswerlists()
  481. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
  482. },
  483. onReady: function(res) {
  484. this.videoContext = uni.createVideoContext('myVideo')
  485. // console.log(this.videoContext)
  486. },
  487. onUnload() {
  488. this.closeWebSocket(); // 安全关闭
  489. if (this.hlsPlayer) {
  490. this.hlsPlayer.destroy(); // 清理 HLS 播放器
  491. }
  492. if (this.pingpangTimes) {
  493. clearInterval(this.pingpangTimes); // 清除心跳定时器
  494. }
  495. },
  496. methods: {
  497. goStore() {
  498. console.log("带过去storeId",this.products[0].storeId)
  499. uni.navigateTo({
  500. url: '/pages_shop/store?liveId=' + this.liveId + "&storeId=" + this.products[0].storeId
  501. })
  502. },
  503. // 去订单列表
  504. goOrderList() {
  505. uni.navigateTo({
  506. url: "/pages_shop/order"
  507. })
  508. },
  509. // 初始化HLS播放器
  510. initHlsPlayer() {
  511. if (Hls.isSupported() && this.livingUrl) {
  512. const video = document.getElementById('myVideo');
  513. if (video) {
  514. this.hlsPlayer = new Hls();
  515. this.hlsPlayer.loadSource(this.livingUrl);
  516. this.hlsPlayer.attachMedia(video);
  517. this.hlsPlayer.on(Hls.Events.MANIFEST_PARSED, () => {
  518. video.play();
  519. });
  520. }
  521. }
  522. },
  523. // 视频错误处理
  524. videoError(e) {
  525. console.error('视频播放错误:', e.detail.errMsg);
  526. // 尝试重新加载或切换到备用流
  527. if (this.livingUrl) {
  528. setTimeout(() => {
  529. this.videoContext.play();
  530. }, 2000);
  531. }
  532. },
  533. getliving() {
  534. console.log("获取直播信息");
  535. const param = {
  536. id: this.liveId
  537. };
  538. getlive(param).then(res => {
  539. if (res.code !== 200) {
  540. uni.showToast({
  541. title: res.msg,
  542. icon: 'none',
  543. duration: 2000
  544. });
  545. return;
  546. }
  547. this.livedata = res.data;
  548. this.showType = res.showType;
  549. // 1. 根据直播类型设置播放地址
  550. if (res.data.liveType === 1) {
  551. // 回放视频
  552. this.videoUrl = res.data.videoUrl;
  553. this.autoplay = true;
  554. this.placeholderText = "观看回放中";
  555. this.talkdisabled = false;
  556. } else if (res.data.liveType === 2) {
  557. // 直播流
  558. this.livingUrl = res.data.livingUrl;
  559. this.autoplay = true;
  560. this.placeholderText = "说点什么...";
  561. this.talkdisabled = false;
  562. } else {
  563. // 未开播
  564. this.livingUrl = "";
  565. this.autoplay = false;
  566. this.placeholderText = "直播未开始,暂时无法发言";
  567. this.talkdisabled = true;
  568. return;
  569. }
  570. // 2. 根据不同平台处理播放逻辑
  571. this.$nextTick(() => {
  572. if (!this.livingUrl) return;
  573. // H5 平台:使用 HLS.js 处理 .m3u8 流
  574. // #ifdef H5
  575. if (this.livingUrl.includes('.m3u8')) {
  576. this.initHlsPlayer();
  577. return;
  578. }
  579. // #endif
  580. // 小程序/App 平台:直接使用 video 组件
  581. if (!this.videoContext) {
  582. this.videoContext = uni.createVideoContext('myVideo', this);
  583. }
  584. if (res.data.liveType === 1) {
  585. // 回放:跳转到指定位置
  586. this.videoContext.seek(res.data.nowDuration || 0);
  587. } else {
  588. // 直播:直接播放
  589. this.videoContext.play();
  590. }
  591. });
  592. }).catch(err => {
  593. console.error("获取直播信息失败:", err);
  594. uni.showToast({
  595. title: "获取直播信息失败",
  596. icon: 'none'
  597. });
  598. });
  599. },
  600. maskString(str, maskChar = '*') {
  601. // 新增:如果str是undefined或null,直接返回空字符串
  602. if (!str) return '';
  603. // 确保str是字符串(如果是数字等类型,先转为字符串)
  604. const strVal = String(str);
  605. return strVal.split('').map((char, index) => (index === 0 ? char : maskChar)).join('');
  606. },
  607. getPureDecimal(num, precision = 6) {
  608. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  609. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  610. },
  611. // 返回上一个页面并关闭WebSocket
  612. goBack() {
  613. uni.navigateBack();
  614. this.closeWebSocket();
  615. },
  616. //直播间点赞、关注、在线人数数据
  617. getliveViewData() {
  618. getLiveViewData(this.liveId).then(res => {
  619. if (res.code == 200) {
  620. // console.log("直播间点赞、关注、在线人数数据>>>>", res)
  621. this.liveViewData = res
  622. } else {
  623. uni.showToast({
  624. title: res.msg,
  625. icon: 'none'
  626. });
  627. }
  628. },
  629. rej => {}
  630. );
  631. },
  632. //正在购买
  633. getliveOrder() {
  634. liveOrderUser(this.liveId).then(res => {
  635. if (res.code == 200) {
  636. console.log("正在购买>>>>", res)
  637. this.orderUser = res
  638. } else {
  639. uni.showToast({
  640. title: res.msg,
  641. icon: 'none'
  642. });
  643. }
  644. },
  645. rej => {}
  646. );
  647. },
  648. //小黄车 店铺展示
  649. getliveStore() {
  650. let data = {
  651. pageSize: 10,
  652. page: 1
  653. }
  654. liveStore(this.liveId, data).then(res => {
  655. if (res.code == 200) {
  656. console.log("小黄车 店铺展示>>>>", res)
  657. this.products = res.data
  658. } else {
  659. uni.showToast({
  660. title: res.msg,
  661. icon: 'none'
  662. });
  663. }
  664. },
  665. rej => {}
  666. );
  667. },
  668. // 获取直播间信息接口
  669. getLiveinformation() {
  670. getLiveInfo(this.liveId).then(res => {
  671. if (res.code == 200) {
  672. console.log("获取直播间信息接口>>>>", res)
  673. this.livingUrl = res.livingUrl
  674. } else {
  675. uni.showToast({
  676. title: res.msg,
  677. icon: 'none'
  678. });
  679. }
  680. },
  681. rej => {}
  682. );
  683. },
  684. // 获取直播间用户
  685. getliveUser() {
  686. getRecentLiveViewers(this.liveId).then(res => {
  687. if (res.code == 200) {
  688. console.log("获取直播间用户>>>>", res)
  689. this.liveViewers = res.recentLiveViewers
  690. } else {
  691. uni.showToast({
  692. title: res.msg,
  693. icon: 'none'
  694. });
  695. }
  696. },
  697. rej => {}
  698. );
  699. },
  700. // 点赞
  701. onLike() {
  702. liveDataLike(this.liveId).then(res => {
  703. if (res.code == 200) {
  704. if (res.like) {
  705. // this.liveData++
  706. this.liveViewData.like++
  707. } else {
  708. uni.showToast({
  709. title: res.msg,
  710. icon: 'none'
  711. });
  712. }
  713. } else {
  714. uni.showToast({
  715. title: res.msg,
  716. icon: 'none'
  717. });
  718. }
  719. },
  720. rej => {}
  721. );
  722. },
  723. // 去购买,跳商品详情
  724. goShop(productId, goodsId) {
  725. // console.log("去购买,跳商品详情")
  726. uni.navigateTo({
  727. url: '/pages_shop/goods?productId=' + productId + '&liveId=' + this.liveId + '&goodsId=' +
  728. goodsId
  729. })
  730. },
  731. // 收藏
  732. onCollect(item) {
  733. // console.log("item>>>", item.productId)
  734. // uni.setStorageSync("storeId", storeId);
  735. let data = {
  736. liveId: this.liveId,
  737. productId: item.productId,
  738. storeId: this.products.storeId
  739. }
  740. collectStore(data).then(res => {
  741. if (res.code == 200) {
  742. console.log("收藏lcollectStore>>>>", res)
  743. } else {
  744. uni.showToast({
  745. title: res.msg,
  746. icon: 'none'
  747. });
  748. }
  749. },
  750. rej => {}
  751. );
  752. },
  753. // 关注
  754. onFollow() {
  755. follow(this.liveId).then(res => {
  756. this.isFollow = !this.isFollow
  757. uni.showToast({
  758. title: res.msg,
  759. icon: 'none'
  760. });
  761. },
  762. rej => {}
  763. );
  764. },
  765. initTime() {
  766. const now = new Date();
  767. this.timestamp = now.getTime(); // 例如:'2023-04-01 12:00:00'
  768. },
  769. // initWebSocket() {
  770. // const liveWS = new LiveWS('ws://your-server.com', 123, 456);
  771. // // 从 URL 中解析 timestamp
  772. // const urlParams = new URL(liveWS.url).searchParams;
  773. // this.timestamp = urlParams.get('timestamp');
  774. // // console.log('Timestamp:', timestamp);
  775. // },
  776. // 弹幕滚动
  777. lowerChat: function(e) {
  778. console.log(e)
  779. },
  780. scroll: function(e) {
  781. console.log(e)
  782. this.old.scrollTop = e.detail.scrollTop
  783. },
  784. loadmore() {
  785. // for (let i = 0; i < 30; i++) {
  786. // this.indexList.push({
  787. // url: this.shopList[uni.$u.random(0, this.shopList.length - 1)],
  788. // });
  789. // }
  790. },
  791. // 弹幕
  792. scrollchat() {
  793. // this.loadmore();
  794. },
  795. noredanswer() {
  796. if (this.Answerlistall > 0) {
  797. this.showAnswer = !this.this.showAnswer
  798. } else {
  799. uni.showToast({
  800. title: '暂无题目',
  801. icon: 'none',
  802. });
  803. }
  804. },
  805. redbagAnswer() {
  806. this.showAnswerred = !this.showAnswerred
  807. this.answerbtn = !this.answerbtn
  808. },
  809. submitAnswers() {
  810. if (this.isSubmit) return;
  811. this.isSubmit = true;
  812. const data = {
  813. questionId: this.answerlist.id,
  814. answer: this.checkboxFormValue
  815. }
  816. submitAnswer(data).then(res => {
  817. if (res.code == 200) {
  818. uni.showToast({
  819. title: res.msg,
  820. icon: 'none',
  821. });
  822. }
  823. // 本地切换下一题
  824. if (this.answerfrist < this.Answerlistall - 1) {
  825. this.answerfrist++;
  826. this.answerlist = this.allAnswerLists[this.answerfrist];
  827. this.answerlist.content = JSON.parse(this.answerlist.content);
  828. } else {
  829. uni.showToast({
  830. title: '已是最后一题',
  831. icon: 'none'
  832. });
  833. this.showAnswer = false; // 自动关闭弹窗
  834. }
  835. this.checkboxValue = []
  836. this.checkboxFormValue = "";
  837. uni.showToast({
  838. title: res.msg,
  839. icon: 'none'
  840. });
  841. }).finally(e => {
  842. this.isSubmit = false;
  843. })
  844. },
  845. // handleCheckboxSelect(value) {
  846. // const index = this.checkboxValue.indexOf(value)
  847. // console.log(value)
  848. // if (this.answerlist.type == 1) {
  849. // this.checkboxValue = [value]
  850. // this.checkboxFormValue = this.checkboxValue.join(',')
  851. // setTimeout(() => {
  852. // uni.showToast({
  853. // title: '准备下一题',
  854. // icon: 'none',
  855. // duration: 2000
  856. // });
  857. // }, 1000);
  858. // this.submitAnswers()
  859. // console.log(this.checkboxValue)
  860. // } else if (this.answerlist.type == 2) {
  861. // if (index > -1) {
  862. // this.checkboxValue.splice(index, 1)
  863. // this.checkboxFormValue = this.checkboxValue.join(',')
  864. // } else {
  865. // this.checkboxValue.push(value)
  866. // this.checkboxFormValue = this.checkboxValue.join(',')
  867. // }
  868. // console.log(this.checkboxFormValue)
  869. // }
  870. // },
  871. getAnswerlists() {
  872. console.log(123)
  873. const data = {
  874. liveId: this.liveId
  875. }
  876. getAnswerlist(data).then(res => {
  877. if (res.code == 200) {
  878. if (res.data.length > 0) {
  879. this.allAnswerLists = res.data; // 存储所有题目
  880. this.Answerlistall = res.data.length;
  881. if (this.allAnswerLists.length > 0) {
  882. this.answerlist = this.allAnswerLists[0];
  883. this.answerlist.content = JSON.parse(this.allAnswerLists[0].content);
  884. }
  885. this.showAnswer = true
  886. } else {
  887. this.showAnswer = false
  888. }
  889. }
  890. })
  891. },
  892. gettalklist() {
  893. const param = {
  894. id: this.liveId
  895. }
  896. gettextlist(param).then(res => {
  897. if (res.code == 200) {
  898. this.talklist = res.data
  899. // console.log(res.data);
  900. this.$nextTick(() => {
  901. this.scrollIntoView = `list_${this.talklist.length-1}`
  902. })
  903. }
  904. })
  905. },
  906. open() {
  907. },
  908. close() {
  909. this.showadd = !this.showadd
  910. },
  911. closes() {
  912. this.showziliao = !this.showziliao
  913. },
  914. closest() {
  915. this.showAnswer = !this.showAnswer
  916. },
  917. closestred() {
  918. this.showAnswerred = !this.showAnswerred
  919. },
  920. closeanswer() {
  921. this.answerbtn = !this.answerbtn
  922. },
  923. // 关闭小黄车
  924. closeshop() {
  925. this.shopping = !this.shopping
  926. },
  927. longPress() {
  928. this.timeout = setTimeout(() => {
  929. this.isLongPress = true;
  930. // 执行保存图片的操作
  931. uni.saveImageToPhotosAlbum({
  932. filePath: this.livedata.qwQrCode, // 图片的本地路径或网络路径
  933. success: () => {
  934. uni.showToast({
  935. title: '保存成功'
  936. });
  937. },
  938. fail: () => {
  939. uni.showToast({
  940. title: '',
  941. icon: 'none'
  942. });
  943. }
  944. });
  945. }, 500); // 设置长按的阈值时间,这里是500毫秒
  946. },
  947. cancelLongPress() {
  948. clearTimeout(this.timeout);
  949. this.isLongPress = false;
  950. },
  951. // 触摸开始
  952. handleTouchStart() {
  953. this.isZoom = true; // 触发放大效果
  954. },
  955. // 触摸结束
  956. handleTouchEnd() {
  957. this.isZoom = false; // 恢复原状
  958. },
  959. getEWechatSdk() {
  960. // 只在H5平台执行
  961. // #ifdef H5
  962. let eWechatSdk = '';
  963. if (/(Android)/i.test(navigator.userAgent)) {
  964. eWechatSdk = 'jWeixin';
  965. } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  966. eWechatSdk = 'wx';
  967. } else {
  968. eWechatSdk = 'jWeixin';
  969. }
  970. uni.setStorageSync("wxSdk", eWechatSdk);
  971. // #endif
  972. },
  973. closeWebSocket() {
  974. clearInterval(this.pingpangTimes);
  975. clearTimeout(this.reconnectTimer);
  976. if (socket && isSocketOpen) {
  977. try {
  978. uni.closeSocket();
  979. isSocketOpen = false;
  980. console.log('WebSocket已主动关闭');
  981. } catch (e) {
  982. console.error('关闭WebSocket时出错:', e);
  983. }
  984. }
  985. },
  986. reConnect() {
  987. var that = this;
  988. try {
  989. uni.closeSocket();
  990. } catch (e) {
  991. }
  992. setTimeout(function() {
  993. that.initSocket();
  994. }, 10000);
  995. },
  996. startHeartbeat() {
  997. clearInterval(this.pingpangTimes);
  998. // 实现心跳检测逻辑
  999. console.log('开始心跳检测');
  1000. this.pingpangTimes = setInterval(() => {
  1001. if (isSocketOpen) {
  1002. const pingData = {
  1003. cmd: 'ping',
  1004. timestamp: new Date().getTime()
  1005. };
  1006. socket.send({
  1007. data: JSON.stringify(pingData),
  1008. success: () => {
  1009. console.log('心跳发送成功');
  1010. },
  1011. fail: (err) => {
  1012. console.error('心跳发送失败:', err);
  1013. // 心跳失败也触发重连
  1014. this.scheduleReconnect();
  1015. }
  1016. });
  1017. }
  1018. }, 30000);
  1019. },
  1020. initSocket() {
  1021. if (this.reconnectCount >= this.maxReconnectAttempts) {
  1022. console.log('已达到最大重连次数,不再尝试连接');
  1023. uni.showToast({
  1024. title: '连接失败,请稍后再试',
  1025. icon: 'none'
  1026. });
  1027. return;
  1028. }
  1029. this.userinfo = JSON.parse(uni.getStorageSync("userInfo"));
  1030. let signature = CryptoJS.HmacSHA256(
  1031. CryptoJS.enc.Utf8.parse(this.liveId.toString() + this.userinfo.userId + this.userType + this
  1032. .timestamp),
  1033. CryptoJS.enc.Utf8.parse(this.timestamp)).toString(CryptoJS.enc.Hex);
  1034. const that = this;
  1035. // 先清除之前的连接和心跳
  1036. this.closeWebSocket();
  1037. // 创建一个新的socket连接
  1038. socket = uni.connectSocket({
  1039. url: wsUrl + "?userId=" + this.userinfo.userId + "&liveId=" + this.liveId + "&userType=" + this
  1040. .userType +
  1041. "&timestamp=" + this.timestamp + "&signature=" + signature,
  1042. multiple: true,
  1043. success: res => {
  1044. this.reconnectCount++; // 增加重连计数
  1045. // 清除之前的心跳定时器
  1046. clearInterval(this.pingpangTimes);
  1047. uni.onSocketMessage((res) => {
  1048. if (res.data.code == 500) {
  1049. uni.showToast({
  1050. title: res.data.msg,
  1051. icon: 'none',
  1052. duration: 2000
  1053. });
  1054. }
  1055. const redata = JSON.parse(res.data);
  1056. console.log("WebSocket拿到的东西", redata)
  1057. this.talklist.push(redata.data)
  1058. this.$nextTick(() => {
  1059. this.scrollIntoView = `list_${this.talklist.length-1}`
  1060. })
  1061. if (redata.cmd == 'deleteId') {
  1062. uni.$emit('deleteId');
  1063. } else if (redata.cmd == 'init') {
  1064. uni.$emit('init', redata.data);
  1065. } else if (redata.cmd == 'reload') {
  1066. uni.$emit('reload');
  1067. } else if (redata.data.cmd == 'sendRedPacketQuestion') {
  1068. const list = JSON.parse(redata.data.data)
  1069. this.redanswerAll = [...this.redanswerAll, ...list]
  1070. if (this.redanswerAll[1].randomAmount !== null) {
  1071. this.redanswertips = JSON.parse(this.redanswerAll[0].randomAmount)
  1072. }
  1073. console.log(this.redanswertips)
  1074. console.log(this.redanswerAll)
  1075. } else if (redata.data.cmd == 'entry') {
  1076. this.showWelcomeMessage = true
  1077. // setTimeout(() => {
  1078. // this.showWelcomeMessage = false;
  1079. // }, 1000);
  1080. uni.$emit('entry', redata.data);
  1081. }
  1082. })
  1083. },
  1084. fail: res => {
  1085. uni.$emit('websocket', 0);
  1086. console.log(res);
  1087. this.scheduleReconnect();
  1088. },
  1089. })
  1090. //监听socket打开
  1091. uni.onSocketOpen(() => {
  1092. isSocketOpen = true;
  1093. this.reconnectCount = 0; // 重置重连计数器
  1094. console.log('WebSocket 连接成功');
  1095. this.startHeartbeat();
  1096. });
  1097. //监听socket关闭
  1098. uni.onSocketClose(() => {
  1099. isSocketOpen = false;
  1100. console.log('WebSocket连接已关闭!');
  1101. this.scheduleReconnect();
  1102. });
  1103. //监听socket错误
  1104. uni.onSocketError((err) => {
  1105. isSocketOpen = false;
  1106. console.error('WebSocket 连接错误:', err);
  1107. this.scheduleReconnect();
  1108. });
  1109. },
  1110. scheduleReconnect() {
  1111. if (this.reconnectCount >= this.maxReconnectAttempts) {
  1112. console.log('已达到最大重连次数,不再尝试连接');
  1113. uni.showToast({
  1114. title: '连接失败,请刷新页面重试',
  1115. icon: 'none'
  1116. });
  1117. return;
  1118. }
  1119. // 清除之前的定时器和连接
  1120. clearTimeout(this.reconnectTimer);
  1121. this.closeWebSocket();
  1122. // 指数退避策略,重连间隔逐渐增加
  1123. const delay = Math.min(1000 * Math.pow(2, this.reconnectCount), 30000);
  1124. console.log(`将在 ${delay}ms 后尝试第 ${this.reconnectCount + 1} 次重连`);
  1125. this.reconnectTimer = setTimeout(() => {
  1126. this.initSocket();
  1127. }, delay);
  1128. },
  1129. sendMsg() {
  1130. if (isSocketOpen) {
  1131. const data = {
  1132. liveId: this.liveId,
  1133. userId: this.userinfo.userId,
  1134. userType: 0,
  1135. cmd: "sendMsg",
  1136. msg: this.value,
  1137. nickName: this.userinfo.nickName,
  1138. avatar: this.userinfo.avatar
  1139. }
  1140. if (this.value == "") {
  1141. uni.showToast({
  1142. title: "不能发送空消息",
  1143. icon: 'none',
  1144. });
  1145. } else {
  1146. socket.send({
  1147. data: JSON.stringify(data),
  1148. success: () => {
  1149. console.log("发送成功")
  1150. this.value = ''
  1151. },
  1152. fail: () => {
  1153. console.log("发送失败")
  1154. }
  1155. })
  1156. }
  1157. }
  1158. },
  1159. },
  1160. };
  1161. </script>
  1162. <style scoped lang="scss">
  1163. // 抽奖
  1164. // .answerpop {
  1165. // background: linear-gradient(to right, #fff7f8, #fee1e2);
  1166. // margin-top: 30rpx;
  1167. // padding: 10rpx 20rpx;
  1168. // width: calc(100% - 40rpx);
  1169. // border-radius: 20rpx;
  1170. // display: flex;
  1171. // align-items: center;
  1172. // justify-content: space-between;
  1173. // box-shadow: 2px 2px 4px 0 rgba(255, 124, 126, 0.1);
  1174. // .answera {
  1175. // display: flex;
  1176. // justify-content: center;
  1177. // background-color: #fff;
  1178. // padding: 20rpx 0;
  1179. // width: 35%;
  1180. // border-radius: 40rpx;
  1181. // align-items: center;
  1182. // margin: 10rpx 0;
  1183. // box-shadow: 2px 2px 4px 0 rgba(72, 72, 72, 0.1);
  1184. // image {
  1185. // width: 40rpx;
  1186. // height: 40rpx;
  1187. // margin-right: 10rpx;
  1188. // }
  1189. // }
  1190. // }
  1191. // .submitbtn {
  1192. // width: 260rpx;
  1193. // margin: 0 auto;
  1194. // text-align: center;
  1195. // border-radius: 80rpx;
  1196. // padding: 20rpx 0;
  1197. // color: #fff;
  1198. // background-color: #ff5c03;
  1199. // }
  1200. // .itemanswer {
  1201. // padding: 20rpx 20rpx;
  1202. // text-align: center;
  1203. // border-radius: 80rpx;
  1204. // border: 2rpx solid #dddddd;
  1205. // margin: 12rpx 0;
  1206. // color: #555;
  1207. // width: calc(100% - 40rpx);
  1208. // }
  1209. // .answeract {
  1210. // background-color: rgba(0, 202, 166, 1);
  1211. // color: #fff;
  1212. // }
  1213. // .answerbox {
  1214. // width: 600rpx;
  1215. // border-radius: 20rpx;
  1216. // }
  1217. // .welcome-message {
  1218. // position: fixed;
  1219. // width: 100%;
  1220. // bottom: 120rpx;
  1221. // left: 50%;
  1222. // transform: translateX(-50%);
  1223. // color: white;
  1224. // padding: 10px 20px;
  1225. // border-radius: 20px;
  1226. // animation: fadeOut 1s ease 1s forwards;
  1227. // z-index: 1000;
  1228. // }
  1229. // @keyframes fadeOut {
  1230. // from {
  1231. // opacity: 1;
  1232. // }
  1233. // to {
  1234. // opacity: 0;
  1235. // }
  1236. // }
  1237. // .container {
  1238. // position: relative;
  1239. // width: 100%;
  1240. // height: 100vh;
  1241. // overflow: hidden;
  1242. // }
  1243. // .talktext {
  1244. // border-radius: 8rpx;
  1245. // background-color: rgba(255, 255, 255, 0.1);
  1246. // view {
  1247. // width: 100%;
  1248. // }
  1249. // }
  1250. .talk-list {
  1251. border-radius: 30rpx;
  1252. background-color: rgba(33, 33, 33, 0.5);
  1253. padding: 10rpx 30rpx;
  1254. }
  1255. // .zoom-button-active {
  1256. // transform: scale(1.5);
  1257. // }
  1258. // .background-image {
  1259. // position: absolute;
  1260. // top: 0;
  1261. // left: -40rpx;
  1262. // width: 110%;
  1263. // height: 110%;
  1264. // object-fit: cover;
  1265. // filter: blur(20px);
  1266. // z-index: 0;
  1267. // }
  1268. // .background-images {
  1269. // position: absolute;
  1270. // top: 0;
  1271. // left: -40rpx;
  1272. // width: 110%;
  1273. // height: 110%;
  1274. // object-fit: cover;
  1275. // filter: blur(20px);
  1276. // z-index: 6;
  1277. // }
  1278. // .blackbg {
  1279. // position: absolute;
  1280. // top: 0;
  1281. // left: 0;
  1282. // width: 100%;
  1283. // height: 100%;
  1284. // background: rgba(0, 0, 0, 0.7);
  1285. // object-fit: cover;
  1286. // filter: blur(10px);
  1287. // z-index: 1;
  1288. // }
  1289. .content {
  1290. position: relative;
  1291. z-index: 2;
  1292. height: 100%;
  1293. width: 100%;
  1294. top: 0;
  1295. left: 0;
  1296. display: flex;
  1297. flex-direction: column;
  1298. justify-content: space-between;
  1299. .content-top {
  1300. width: 100%;
  1301. margin-top: 150rpx;
  1302. display: flex;
  1303. align-items: center;
  1304. justify-content: space-between;
  1305. padding: 0 24rpx;
  1306. box-sizing: border-box;
  1307. .sum {
  1308. width: 80rpx;
  1309. height: 52rpx;
  1310. background: rgba(0, 0, 0, 0.5);
  1311. border-radius: 26rpx 26rpx 26rpx 26rpx;
  1312. font-size: 24rpx;
  1313. color: #FFFFFF;
  1314. text-align: center;
  1315. line-height: 52rpx;
  1316. }
  1317. }
  1318. .follow-btn {
  1319. padding: 8rpx 16rpx;
  1320. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1321. border-radius: 26rpx;
  1322. font-weight: 500;
  1323. font-size: 26rpx;
  1324. color: #FFFFFF;
  1325. }
  1326. }
  1327. .videolist {
  1328. position: relative;
  1329. }
  1330. .video {
  1331. // height: 500rpx;
  1332. height: 100vh;
  1333. /* 占屏幕高度的80% */
  1334. width: 100%;
  1335. background-color: rgba(0, 0, 0, 0.6);
  1336. }
  1337. .videotop {
  1338. width: 100%;
  1339. height: 100%;
  1340. }
  1341. .popup-video {
  1342. position: absolute;
  1343. top: 30%;
  1344. height: 500rpx;
  1345. display: flex;
  1346. flex-direction: column;
  1347. align-items: center;
  1348. justify-content: center;
  1349. width: 100%;
  1350. color: #fff;
  1351. z-index: 9;
  1352. .more {
  1353. background-color: #3280fe;
  1354. border-radius: 80rpx;
  1355. width: 280rpx;
  1356. text-align: center;
  1357. height: 60rpx;
  1358. line-height: 60rpx;
  1359. }
  1360. }
  1361. .icon-bg {
  1362. background-color: rgba(157, 157, 157, 0.8);
  1363. border-radius: 50%;
  1364. width: 72rpx;
  1365. height: 72rpx;
  1366. display: flex;
  1367. justify-content: center;
  1368. align-items: center;
  1369. transition: transform 0.2s ease;
  1370. }
  1371. .list {
  1372. width: 80%;
  1373. margin-bottom: 20rpx;
  1374. animation: xxxawdawd .2s;
  1375. }
  1376. @keyframes xxxawdawd {
  1377. from {
  1378. margin-top: 0rpx;
  1379. opacity: 0;
  1380. }
  1381. to {
  1382. margin-top: 20rpx;
  1383. opacity: 1;
  1384. }
  1385. }
  1386. .shop-prompt {
  1387. position: absolute;
  1388. bottom: 600rpx;
  1389. left: 24rpx;
  1390. padding: 6rpx 20rpx;
  1391. background: rgba(230, 154, 34, 0.7);
  1392. border-radius: 24rpx;
  1393. z-index: 9;
  1394. font-weight: 500;
  1395. font-size: 26rpx;
  1396. color: #FFFFFF;
  1397. }
  1398. .side-group {
  1399. position: absolute;
  1400. top: 30%;
  1401. right: 50rpx;
  1402. z-index: 9;
  1403. display: flex;
  1404. flex-direction: column;
  1405. align-items: center;
  1406. .side-item {
  1407. font-weight: 500;
  1408. font-size: 24rpx;
  1409. color: #FFFFFF;
  1410. margin-bottom: 32rpx;
  1411. text-align: center;
  1412. image {
  1413. width: 72rpx;
  1414. height: 72rpx;
  1415. }
  1416. }
  1417. }
  1418. .shoppop {
  1419. padding: 22rpx 16rpx;
  1420. .shoppop-top {
  1421. display: flex;
  1422. justify-content: space-between;
  1423. align-items: center;
  1424. padding: 0 16rpx 22rpx;
  1425. .search-input {
  1426. width: 414rpx;
  1427. height: 76rpx;
  1428. background: #FFFFFF;
  1429. border-radius: 36rpx;
  1430. margin-left: 20rpx;
  1431. padding: 0 32rpx;
  1432. box-sizing: border-box;
  1433. font-size: 24rpx;
  1434. margin-right: 24rpx;
  1435. }
  1436. .search-top {
  1437. font-size: 18rpx;
  1438. color: #222222;
  1439. }
  1440. }
  1441. .shop-list {
  1442. overflow: hidden;
  1443. .list-item {
  1444. display: flex;
  1445. align-items: center;
  1446. padding: 20rpx 16rpx;
  1447. background: #FFFFFF;
  1448. border-radius: 16rpx;
  1449. margin-bottom: 16rpx;
  1450. .goods-img {
  1451. width: 200rpx;
  1452. height: 200rpx;
  1453. border-radius: 16rpx;
  1454. overflow: hidden;
  1455. position: relative;
  1456. margin-right: 24rpx;
  1457. image {
  1458. width: 100%;
  1459. height: 100%;
  1460. }
  1461. .goods-label {
  1462. position: absolute;
  1463. top: 0;
  1464. width: 64rpx;
  1465. height: 40rpx;
  1466. background: rgba(0, 0, 0, 0.5);
  1467. border-radius: 16rpx 0rpx 16rpx 0rpx;
  1468. text-align: center;
  1469. font-weight: 500;
  1470. font-size: 28rpx;
  1471. color: #FFFFFF;
  1472. }
  1473. }
  1474. .goods-right {
  1475. flex: 1;
  1476. .goods-title {
  1477. font-weight: 500;
  1478. font-size: 28rpx;
  1479. color: #000000;
  1480. }
  1481. .goods-details {
  1482. font-size: 24rpx;
  1483. color: #999999;
  1484. margin: 10rpx 0 20rpx;
  1485. }
  1486. .goods-people {
  1487. font-size: 22rpx;
  1488. color: #E69A22;
  1489. height: 56rpx;
  1490. }
  1491. .goods-shop {
  1492. display: flex;
  1493. justify-content: space-between;
  1494. .nummber {
  1495. color: #FF5C03;
  1496. font-size: 22rpx;
  1497. font-weight: 500;
  1498. }
  1499. .btn-group {
  1500. text-align: center;
  1501. line-height: 56rpx;
  1502. .collect-btn {
  1503. width: 72rpx;
  1504. background: #F5F7FA;
  1505. border-radius: 8rpx 0rpx 0rpx 8rpx;
  1506. }
  1507. .shop-btn {
  1508. width: 152rpx;
  1509. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  1510. border-radius: 0rpx 8rpx 8rpx 0rpx;
  1511. font-weight: 500;
  1512. font-size: 26rpx;
  1513. color: #FFFFFF;
  1514. }
  1515. }
  1516. }
  1517. }
  1518. }
  1519. }
  1520. }
  1521. :deep(.u-list-item) {
  1522. width: 100%;
  1523. display: flex;
  1524. align-items: center;
  1525. }
  1526. </style>