index.vue 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. <template>
  2. <!-- 直播中控台 start -->
  3. <el-row type="flex" justify="center" class="live-console" :gutter="10" v-loading="loading">>
  4. <!-- 聊天 start -->
  5. <el-col class="live-console-col" :span="6">
  6. <el-tabs class="live-console-tab-left" v-model="tabRight.activeName" @tab-click="handleClick" :stretch="true">
  7. <el-tab-pane label="讨论" name="talk">
  8. <el-scrollbar style="height: 500px; width: 100%;" ref="manageRightRef">
  9. <el-row v-for="m in msgList" style="margin-bottom: 20px;">
  10. <el-row v-if="m.userId !== userId" type="flex" align="top" >
  11. <el-col :span="24" style="display: flex; align-items: center;">
  12. <el-avatar style="width: 36px;height: 36px;" :src="m.avatar!==null?m.avatar: require('@/assets/image/default-a.png')"/>
  13. <div style="font-size: 14px; color: #999;margin: 0 12px;">{{ m.nickName }}</div>
  14. <div style="display: flex; align-items: center; gap: 8px;">
  15. <a style="cursor: pointer;color: #13C2C2;font-size: 14px;" @click="changeUserState(m)">{{ m.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  16. <span style="color:#13C2C2;">|</span>
  17. <a style="cursor: pointer;color: #13C2C2;font-size: 14px;" @click="blockUser(m)">拉黑</a>
  18. <span style="color:#13C2C2;">|</span>
  19. <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click="deleteMsg(m)">删除</a>
  20. </div>
  21. </el-col>
  22. </el-row>
  23. <el-row v-if="m.userId !== userId" type="flex" align="top">
  24. <el-col :span="19" :offset="3">
  25. <div class="msg-box">
  26. {{ m.msg }}
  27. </div>
  28. </el-col>
  29. </el-row>
  30. <el-row v-if="m.userId === userId" style="padding: 8px 0;margin-right: 10px;" type="flex" align="top" justify="end">
  31. <div style="display: flex;justify-content: flex-end">
  32. <div style="display: flex;justify-content: flex-end;flex-direction: column;max-width: 200px;align-items: flex-end">
  33. <div style="display: flex;align-items: center;">
  34. <div style="font-size: 14px; color: #999;margin-right: 12px;">{{ m.nickName }}</div>
  35. <el-avatar :src="m.avatar?m.avatar: require('@/assets/image/default-a.png')" style="width: 36px;height: 36px;"/>
  36. </div>
  37. <div class="msg-box-right">
  38. {{ m.msg }}</div>
  39. </div>
  40. </div>
  41. </el-row>
  42. </el-row>
  43. <!-- 底部留白 -->
  44. <div style="height: 20px;"></div>
  45. </el-scrollbar>
  46. <!-- 消息输入区域 -->
  47. <div class="shuru" style="padding: 20px; border-top: 1px solid #ebeef5; background-color: #fff; min-height: 120px;">
  48. <el-input
  49. type="textarea"
  50. v-model="newMsg"
  51. placeholder="请输入消息..."
  52. :rows="8"
  53. @keyup.enter.native="sendMessage"
  54. clearable
  55. resize="none"
  56. style="flex: 1; margin-right: 10px;"
  57. >
  58. </el-input>
  59. <div style="display: flex; justify-content: flex-end; margin-top: 10px;">
  60. <el-button style="background: #13C2C2;color: #fff;" @click="showTopMsgDialog">顶部消息</el-button>
  61. <el-button style="background: #13C2C2;color: #fff;" @click="sendMessage">发送</el-button>
  62. </div>
  63. </div>
  64. </el-tab-pane>
  65. </el-tabs>
  66. </el-col>
  67. <!-- 聊天 end -->
  68. <!-- 直播/视频 start -->
  69. <el-col class="live-console-col" :span="12">
  70. <div style="background: #000; border-radius: 5px; overflow: hidden; margin: 10px 5px;">
  71. <div style="border-radius: 5px; overflow: hidden;" v-if="!isAudit">
  72. <img :src="require('@/assets/image/videoIsAudit.png')" style="width: 100%; height: 45vh;">
  73. </div>
  74. <div style="border-radius: 5px; overflow: hidden;" v-else-if="status != 2 && status != 4">
  75. <img :src="require('@/assets/image/videoNotStart.png')" style="width: 100%; height: 45vh;">
  76. </div>
  77. <div style="border-radius: 5px; overflow: hidden;" v-else-if="liveType == 1">
  78. <video
  79. controls
  80. ref="livingPlayer"
  81. autoplay
  82. @click.prevent
  83. @contextmenu.prevent
  84. class="custom-video"
  85. width="100%"
  86. style="display: block; background: #000; height: 45vh;"
  87. ></video>
  88. <!-- 时间显示(可选) -->
  89. <div ref="liveElapsedTime" class="time-display">
  90. 已播放:<span id="liveElapsedTime">00:00:00</span>
  91. </div>
  92. </div>
  93. <div style="border-radius: 5px; overflow: hidden;" v-else-if="liveType == 2">
  94. <video
  95. controls
  96. ref="videoPlayer"
  97. loop
  98. autoplay
  99. width="100%"
  100. muted
  101. playsinline
  102. @click.prevent
  103. @contextmenu.prevent
  104. class="custom-video"
  105. style="display: block; background: #000; height: 40vh;"
  106. >
  107. <source :src="videoUrl" type="application/x-mpegURL">
  108. </video>
  109. <!-- 自定义进度条容器 -->
  110. <div ref="progressBar" class="progress-container">
  111. <div id="progressBar" class="progress-bar"></div>
  112. </div>
  113. <!-- 时间显示(可选) -->
  114. <div ref="elapsedTime" class="time-display">
  115. 已播放:<span id="elapsedTime">00:00:00</span>
  116. </div>
  117. </div>
  118. <div style="border-radius: 5px; overflow: hidden;" v-else-if="liveType == 3">
  119. <video
  120. controls
  121. ref="liveReplay"
  122. loop
  123. autoplay
  124. width="100%"
  125. playsinline
  126. style="display: block; background: #000; height: 40vh;"
  127. >
  128. <source :src="videoUrl" type="application/x-mpegURL">
  129. </video>
  130. </div>
  131. <div style="border-radius: 5px; overflow: hidden;" v-else>
  132. <img :src="require('@/assets/image/videoNotStart.png')" style="width: 100%; height: 45vh;">
  133. </div>
  134. </div>
  135. <!-- 底部导航栏 -->
  136. <div style="display: flex; justify-content: space-around; padding: 15px 0; background: #fff; border-top: 1px solid #f0f0f0;">
  137. <div class="top-box" style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickRed">
  138. <!-- <i class="el-icon-money" style="font-size: 20px;"></i> -->
  139. <img src="@/assets/image/hbpz.png" width="48"/>
  140. <span style="font-size: 12px; margin-top: 10px;">红包配置</span>
  141. </div>
  142. <div class="top-box" style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickLottery">
  143. <!-- <i class="el-icon-present" style="font-size: 20px;"></i> -->
  144. <img src="@/assets/image/cjpz.png" width="48"/>
  145. <span style="font-size: 12px; margin-top: 10px;">抽奖配置</span>
  146. </div>
  147. <div class="top-box" style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickGoods">
  148. <!-- <i class="el-icon-goods" style="font-size: 20px;"></i> -->
  149. <img src="@/assets/image/sp.png" width="48"/>
  150. <span style="font-size: 12px; margin-top: 10px;">商品</span>
  151. </div>
  152. <div class="top-box" style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickOrder">
  153. <!-- <i class="el-icon-goods" style="font-size: 20px;"></i> -->
  154. <img src="@/assets/image/zbdd.png" width="48"/>
  155. <span style="font-size: 12px;margin-top: 10px;">直播订单</span>
  156. </div>
  157. <div class="top-box" style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickCoupon">
  158. <!-- <i class="el-icon-goods" style="font-size: 20px;"></i> -->
  159. <img src="@/assets/image/zbyhq.png" width="48"/>
  160. <span style="font-size: 12px; margin-top: 10px;">直播优惠券</span>
  161. </div>
  162. </div>
  163. <!-- <el-radio-group v-model="tableRadio" >
  164. <el-radio-button label="订单数">订单数</el-radio-button>
  165. </el-radio-group> -->
  166. <div style="position: relative;width: 100%; height: 270px;margin-top: 20px;">
  167. <div ref="chartContainer" style="width: 100%; height: 100%;"></div>
  168. <div style="position: absolute; top: 10px; right: 10px; background: #fff; padding: 5px; z-index: 1;">
  169. <el-select v-model="searchQuery.timeOptions" placeholder="请选择" style="width: 150px" @change="timeChange">
  170. <el-option
  171. v-for="item in timeOptions"
  172. :key="item.value"
  173. :label="item.label"
  174. :value="item.value">
  175. </el-option>
  176. </el-select>
  177. <el-select v-model="searchQuery.timeGranularity" placeholder="请选择" style="width: 150px" @change="timeGranularityChange">
  178. <el-option
  179. v-for="item in timeGranularity"
  180. :key="item.value"
  181. :label="item.label"
  182. :value="item.value">
  183. </el-option>
  184. </el-select>
  185. <!-- <el-button type="primary" @click="applyFilter">搜索</el-button>-->
  186. </div>
  187. </div>
  188. </el-col>
  189. <!-- 直播/视频 end -->
  190. <!-- 用户列表 start -->
  191. <el-col class="live-console-col" :span="6">
  192. <el-tabs class="live-console-tab-right" v-model="tabLeft.activeName" @tab-click="handleClick" :stretch="true">
  193. <el-tab-pane :label="onlineLabel" name="online" style="height: 100%;">
  194. <el-scrollbar ref="manageLeftRef_online" style="height:100%; width: 100%;padding: 10px;">
  195. <el-row class="row-box" style="margin-bottom:10px" type="flex" align="middle" v-for="u in onlineDisplayList" :key="u.userId">
  196. <el-col :span="20">
  197. <el-row type="flex" align="middle">
  198. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  199. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  200. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  201. </el-row>
  202. </el-col>
  203. <el-col :span="4" >
  204. <el-popover
  205. width="100"
  206. style="text-align: center;"
  207. trigger="click">
  208. <div style="text-align: center;">
  209. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  210. <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
  211. </div>
  212. <i class="el-icon-more" slot="reference"></i>
  213. </el-popover>
  214. </el-col>
  215. </el-row>
  216. </el-scrollbar>
  217. </el-tab-pane>
  218. <el-tab-pane :label="offlineLabel" name="offline" style="height: 100%;">
  219. <el-scrollbar ref="manageLeftRef_offline" style="height:100%; width: 100%;padding: 10px;">
  220. <el-row class="row-box" style="margin-bottom:10px" type="flex" align="middle" v-for="u in offlineDisplayList" :key="u.userId">
  221. <el-col :span="20">
  222. <el-row type="flex" align="middle">
  223. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  224. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  225. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  226. </el-row>
  227. </el-col>
  228. <el-col :span="4" >
  229. <el-popover
  230. width="100"
  231. trigger="click">
  232. <div style="text-align: center;">
  233. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  234. <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
  235. </div>
  236. <i class="el-icon-more" slot="reference"></i>
  237. </el-popover>
  238. </el-col>
  239. </el-row>
  240. </el-scrollbar>
  241. </el-tab-pane>
  242. <el-tab-pane :label="silencedUserLabel" name="silenced" style="height: 100%;">
  243. <el-scrollbar ref="manageLeftRef_silenced" style="height: 800px; width: 100%;padding: 10px;">
  244. <el-row class="row-box" style="margin-bottom:10px" type="flex" align="middle" v-for="u in silencedDisplayList" :key="u.userId">
  245. <el-col :span="20">
  246. <el-row type="flex" align="middle">
  247. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  248. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  249. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  250. </el-row>
  251. </el-col>
  252. <el-col :span="4" >
  253. <el-popover
  254. width="100"
  255. trigger="click">
  256. <div style="text-align: center;">
  257. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  258. <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
  259. </div>
  260. <i class="el-icon-more" slot="reference"></i>
  261. </el-popover>
  262. </el-col>
  263. </el-row>
  264. </el-scrollbar>
  265. </el-tab-pane>
  266. </el-tabs>
  267. </el-col>
  268. <!-- 顶部消息对话框 -->
  269. <el-dialog title="发送顶部消息" :visible.sync="topMsgDialogVisible" width="500px">
  270. <el-form :model="topMsgForm" label-width="100px">
  271. <el-form-item label="消息内容">
  272. <el-input
  273. type="textarea"
  274. v-model="topMsgForm.msg"
  275. placeholder="请输入消息内容"
  276. :rows="3"
  277. ></el-input>
  278. </el-form-item>
  279. <el-form-item label="显示时长">
  280. <el-input-number
  281. v-model="topMsgForm.duration"
  282. :min="1"
  283. :max="60"
  284. placeholder="请输入显示时长(分钟)"
  285. ></el-input-number>
  286. <span style="margin-left: 10px;">分钟</span>
  287. </el-form-item>
  288. </el-form>
  289. <div slot="footer" class="dialog-footer">
  290. <el-button @click="topMsgDialogVisible = false">取 消</el-button>
  291. <el-button type="primary" @click="sendTopMessage">确 定</el-button>
  292. </div>
  293. </el-dialog>
  294. <!-- 用户列表 end -->
  295. </el-row>
  296. <!-- 直播中控台 end -->
  297. </template>
  298. <script>
  299. import {blockUser, changeUserStatus, getLiveUserTotals, watchUserList} from '@/api/live/liveWatchUser'
  300. import { getLiveVideoByLiveId } from '@/api/live/liveVideo'
  301. import {getLivingUrl, getLive, delLive} from '@/api/live/live'
  302. import { getLiveOrderTimeGranularity } from '@/api/live/liveOrder'
  303. import { listLiveMsg,delLiveMsg } from '@/api/live/liveMsg'
  304. import Hls from 'hls.js';
  305. import {onBeforeUnmount} from 'vue';
  306. import LiveLotteryConf from '@/views/live/liveConfig/liveLotteryConf.vue'
  307. import LiveRedConf from '@/views/live/liveConfig/liveRedConf.vue'
  308. import LiveGoods from '@/views/live/liveConfig/goods.vue'
  309. import LiveOrder from '@/views/live/liveOrder/index.vue'
  310. import LiveCoupon from '@/views/live/liveConfig/liveCoupon.vue'
  311. import echarts from 'echarts'
  312. export default {
  313. name: "LiveConsole",
  314. components: { LiveLotteryConf,LiveRedConf,LiveGoods },
  315. data() {
  316. return {
  317. loading: true,
  318. tabLeft: {
  319. activeName: "online",
  320. },
  321. tabRight: {
  322. activeName: "talk",
  323. },
  324. livingUrl: "",
  325. videoUrl: "",
  326. status: 0,
  327. loadMsgMaxPage: 2,
  328. his: null,
  329. liveVideo: {},
  330. socket: null,
  331. liveWsUrl: process.env.VUE_APP_LIVE_WS_URL + '/app/webSocket',
  332. userParams:{
  333. pageNum: 1,
  334. pageSize: 10,
  335. liveId: null
  336. },
  337. msgParams: {
  338. pageNum: 1,
  339. pageSize: 10,
  340. liveId: null
  341. },
  342. userList: [],
  343. msgList: [],
  344. newMsg: '',
  345. isAudit: false,
  346. myChart: null, // 用于存储 ECharts 实例
  347. liveType: 1,
  348. tableRadio: '订单数',
  349. // ... 其他数据 ...
  350. searchQuery: {timeOptions:'2',timeGranularity:'10',liveId: null}, // 搜索查询条件
  351. timeOptions: [
  352. {value:'2',label:'最近2小时',key:'2'},
  353. {value:'4',label:'最近4小时',key:'4'},
  354. {value:'all',label:'全场',key:'all'},
  355. ],
  356. timeGranularity: [
  357. {value:'10',label:'10分钟',key:'10'},
  358. {value:'30',label:'30分钟',key:'30'},
  359. {value:'60',label:'1小时',key:'60'},
  360. ],
  361. videoDuration: 0,
  362. startTime: null,
  363. processInterval: null,
  364. // ... 其他数据
  365. chatScrollTop: 0, // 保存聊天滚动位置,
  366. liveId: null,
  367. userTotal: {
  368. online: 0, // 在线总人数
  369. offline: 0, // 离线总人数
  370. silenced: 0 // 禁言总人数
  371. },
  372. // 各Tab的显示列表(仅存储当前需要展示的数据)
  373. onlineDisplayList: [], // 在线用户显示列表
  374. offlineDisplayList: [], // 离线用户显示列表
  375. silencedDisplayList: [], // 禁言用户显示列表
  376. // 各Tab的分页参数
  377. pageParams: {
  378. online: {
  379. currentPage: 1, // 当前页(下一页加载用)
  380. pageSize: 20, // 当前页(下一页加载用)
  381. prevPage: 0, // 上一页页码(上一页加载用)
  382. totalLoaded: 0, // 已加载总条数
  383. total: 0, // 总数据量
  384. hasMore: true, // 是否有下一页
  385. hasPrev: false // 是否有上一页
  386. },
  387. offline: {
  388. currentPage: 1,
  389. pageSize: 20,
  390. prevPage: 0,
  391. totalLoaded: 0,
  392. total: 0,
  393. hasMore: true,
  394. hasPrev: false
  395. },
  396. silenced: {
  397. currentPage: 1,
  398. pageSize: 20,
  399. prevPage: 0,
  400. totalLoaded: 0,
  401. total: 0,
  402. hasMore: true,
  403. hasPrev: false
  404. }
  405. },
  406. scrLoading: {
  407. online: { next: false, prev: false },
  408. offline: { next: false, prev: false },
  409. silenced: { next: false, prev: false }
  410. },
  411. topMsgDialogVisible: false,
  412. topMsgForm: {
  413. msg: '',
  414. duration: 5
  415. }
  416. }
  417. },
  418. created() {
  419. if (this.$route.params.liveId) {
  420. this.liveId = this.$route.params.liveId;
  421. }else {
  422. this.liveId = this.$route.query.liveId;
  423. }
  424. // this.getLiveVideo()
  425. this.getList()
  426. this.connectWebSocket()
  427. this.getLive()
  428. this.searchQuery.liveId = this.liveId
  429. },
  430. computed: {
  431. userId() {
  432. return this.$store.state.user.user.userId
  433. },
  434. companyId() {
  435. return this.$store.state.user.user.companyId
  436. },
  437. onlineLabel() {
  438. return `在线(${this.userTotal.online})`;
  439. },
  440. offlineLabel() {
  441. return `离线(${this.userTotal.offline})`;
  442. },
  443. silencedUserLabel() {
  444. return `禁言(${this.userTotal.silenced})`;
  445. }
  446. },
  447. mounted() {
  448. this.$nextTick(() => {
  449. this.restoreChatScrollPosition();
  450. });
  451. this.getEchartsTables();
  452. // 添加滚动事件监听器
  453. this.$nextTick(() => {
  454. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  455. this.$refs.manageRightRef.wrap.addEventListener('scroll', this.saveChatScrollPosition);
  456. }
  457. });
  458. this.initScrollListeners();
  459. },
  460. beforeDestroy() {
  461. this.saveTabScrollPositions()
  462. // 移除滚动监听(避免内存泄漏)
  463. const scrollRefs = {
  464. online: this.$refs.manageLeftRef_online,
  465. offline: this.$refs.manageLeftRef_offline,
  466. silenced: this.$refs.manageLeftRef_silenced
  467. };
  468. Object.keys(scrollRefs).forEach(tabName => {
  469. const scrollEl = scrollRefs[tabName]?.wrap;
  470. if (scrollEl) {
  471. scrollEl.removeEventListener('scroll', () =>
  472. this.handleTabScroll(tabName, scrollEl)
  473. );
  474. }
  475. })
  476. },
  477. // 使用 deactivated 和 activated 钩子替代 beforeDestroy 和 destroyed
  478. deactivated() {
  479. this.saveChatScrollPosition();
  480. },
  481. activated() {
  482. this.$nextTick(() => {
  483. this.restoreChatScrollPosition();
  484. });
  485. this.$nextTick(() => {
  486. const video = this.$refs.videoPlayer;
  487. if (video != null) {
  488. this.initVideoPlayer(this.liveInfo.startTime)
  489. }
  490. })
  491. },
  492. methods: {
  493. deleteMsg(m){
  494. // 1. 弹出确认对话框
  495. this.$confirm('此操作将永久删除该消息, 是否继续?', '提示', {
  496. confirmButtonText: '确定',
  497. cancelButtonText: '取消',
  498. type: 'warning'
  499. }).then(() => {
  500. delLiveMsg(m.msgId).then(res => {
  501. if (res.code === 200) {
  502. const index = this.msgList.findIndex(item => item.msgId === m.msgId);
  503. if (index !== -1) {
  504. this.msgList.splice(index, 1);
  505. console.log(`消息 ${m.msgId} 已在本地删除。`);
  506. }
  507. let msg = {
  508. liveId: this.liveId,
  509. userId: m.userId,
  510. msg: m.msgId, // 关键:将消息ID发送给后台
  511. cmd: 'deleteMsg',
  512. };
  513. this.socket.send(JSON.stringify(msg));
  514. // 可以在这里给用户一个删除成功的提示
  515. this.$message({
  516. type: 'success',
  517. message: '消息删除成功!'
  518. });
  519. }
  520. })
  521. }).catch(() => {
  522. // 3. 用户点击“取消”或关闭对话框后的回调
  523. this.$message({
  524. type: 'info',
  525. message: '已取消删除'
  526. });
  527. });
  528. },
  529. // 显示顶部消息对话框
  530. showTopMsgDialog() {
  531. this.topMsgForm.msg = '';
  532. this.topMsgForm.duration = 5;
  533. this.topMsgDialogVisible = true;
  534. },
  535. // 发送顶部消息
  536. sendTopMessage() {
  537. // 发送前简单校验
  538. if (this.topMsgForm.msg.trim() === '') {
  539. this.$message.warning('请输入消息内容');
  540. return;
  541. }
  542. if (!this.topMsgForm.duration || this.topMsgForm.duration < 1) {
  543. this.$message.warning('请输入有效的显示时长');
  544. return;
  545. }
  546. let msg = {
  547. msg: this.topMsgForm.msg,
  548. duration: this.topMsgForm.duration,
  549. liveId: this.liveId,
  550. userId: this.userId,
  551. userType: 1,
  552. cmd: 'sendTopMsg',
  553. avatar: this.$store.state.user.user.avatar,
  554. nickName: this.$store.state.user.user.nickName,
  555. }
  556. this.socket.send(JSON.stringify(msg))
  557. this.topMsgDialogVisible = false;
  558. this.$message.success('顶部消息发送成功');
  559. },
  560. handleClickCoupon(){
  561. this.$router.push({
  562. name: 'LiveCoupon',
  563. query: {
  564. liveId: this.liveId
  565. }
  566. })
  567. },
  568. // 保存聊天滚动位置
  569. saveChatScrollPosition() {
  570. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  571. this.chatScrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight;
  572. }
  573. },
  574. // 恢复聊天滚动位置
  575. restoreChatScrollPosition() {
  576. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  577. this.$refs.manageRightRef.wrap.scrollTop = this.chatScrollTop;
  578. }
  579. },
  580. getLive(){
  581. getLive(this.liveId).then(res => {
  582. if (res.code == 200) {
  583. if (res.data.isAudit != 1) {
  584. this.$message.error("当前直播间未经审核");
  585. this.loading = false
  586. return
  587. }
  588. this.isAudit = true
  589. this.status = res.data.status
  590. if(res.data.status == 4){
  591. this.liveType = 3
  592. this.videoUrl = res.data.videoUrl;
  593. }else {
  594. if (res.data.status != 2) {
  595. this.$message.error("当前直播间未直播");
  596. this.loading = false
  597. return
  598. }
  599. if (res.data.liveType == 1) {
  600. this.livingUrl = res.data.flvHlsUrl
  601. this.livingUrl = this.livingUrl.replace("flv","m3u8")
  602. this.$nextTick(() => {
  603. this.initPlayer()
  604. })
  605. this.startTime = new Date(res.data.startTime).getTime()
  606. this.processInterval = setInterval(this.updateLiveProgress, 1000);
  607. } else {
  608. this.liveType = 2
  609. this.videoUrl = res.data.videoUrl;
  610. this.$nextTick(() => {
  611. this.initVideoPlayer(res.data.startTime)
  612. })
  613. }
  614. }
  615. this.loading = false
  616. } else {
  617. this.$message.error(res.msg)
  618. this.loading = false
  619. }
  620. this.liveInfo = res.data
  621. })
  622. },
  623. initVideoPlayer: function (startTime) {
  624. const video = this.$refs.videoPlayer;
  625. this.hls = new Hls();
  626. this.hls.attachMedia(video);
  627. this.hls.on(Hls.Events.MEDIA_ATTACHED, () => {
  628. this.hls.loadSource(this.videoUrl);
  629. this.hls.on(Hls.Events.STREAM_LOADED, (event, data) => {
  630. video.play();
  631. });
  632. });
  633. this.hls.on(Hls.Events.ERROR, (event, data) => {
  634. console.error('HLS 错误:', data);
  635. });
  636. // 1. 初始化开播时间
  637. startTime = new Date(startTime).getTime();
  638. this.startTime = startTime;
  639. // 2. 监听视频元数据加载完成(获取视频时长)
  640. video.addEventListener('loadedmetadata', () => {
  641. this.videoDuration = video.duration; // 获取视频时长(秒)
  642. // 初始化视频播放位置
  643. this.updateVideoPosition(video);
  644. // 启动实时进度更新(每秒刷新一次)
  645. this.processInterval = setInterval(this.updateProgress, 1000);
  646. });
  647. },
  648. updateVideoPosition(video){
  649. const currentTime = new Date().getTime(); // 当前时间戳(毫秒)
  650. const elapsedTime = currentTime - this.startTime; // 已流逝时间(毫秒)
  651. if (elapsedTime < 0) {
  652. // 未开播:视频停在初始位置
  653. video.currentTime = 0;
  654. return;
  655. }
  656. // 已开播:计算视频循环后的位置(流逝时间 % 视频时长)
  657. const elapsedSeconds = elapsedTime / 1000; // 转换为秒
  658. const videoPosition = elapsedSeconds % this.videoDuration; // 视频内的播放位置(秒)
  659. // 设置视频播放位置
  660. video.currentTime = videoPosition;
  661. },
  662. updateProgress() {
  663. const progressBar = this.$refs.progressBar;
  664. const elapsedTimeEl = this.$refs.elapsedTime;
  665. if (!this.videoDuration) return; // 视频时长未加载时不更新
  666. const currentTime = new Date().getTime();
  667. const elapsedTime = currentTime - this.startTime; // 总流逝时间(毫秒)
  668. if (elapsedTime < 0) {
  669. // 未开播状态
  670. progressBar.style.width = '0%';
  671. elapsedTimeEl.textContent = '00:00:00';
  672. return;
  673. }
  674. // 计算进度百分比(基于视频循环)
  675. const elapsedSeconds = elapsedTime / 1000;
  676. const videoPosition = elapsedSeconds % this.videoDuration; // 当前在视频中的位置
  677. const progressPercent = (videoPosition / this.videoDuration) * 100; // 进度百分比
  678. // 更新进度条宽度
  679. progressBar.style.width = `${progressPercent}%`;
  680. // 格式化总流逝时间为“时:分:秒”并显示
  681. elapsedTimeEl.textContent = this.formatTime(elapsedTime);
  682. },
  683. updateLiveProgress() {
  684. const elapsedTimeEl = this.$refs.liveElapsedTime;
  685. const currentTime = new Date().getTime();
  686. const elapsedTime = currentTime - this.startTime; // 总流逝时间(毫秒)
  687. if (elapsedTime < 0) {
  688. elapsedTimeEl.textContent = '00:00:00';
  689. return;
  690. }
  691. // 格式化总流逝时间为“时:分:秒”并显示
  692. elapsedTimeEl.textContent = this.formatTime(elapsedTime);
  693. },
  694. formatTime(ms) {
  695. const totalSeconds = Math.floor(ms / 1000);
  696. const hours = Math.floor(totalSeconds / 3600);
  697. const minutes = Math.floor((totalSeconds % 3600) / 60);
  698. const seconds = totalSeconds % 60;
  699. // 补零处理(确保两位数)
  700. return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
  701. },
  702. // ... 其他方法 ...
  703. timeChange(val) {
  704. this.searchQuery.timeOptions = val
  705. this.getEchartsTables(this.searchQuery)
  706. this.initChart()
  707. },
  708. timeGranularityChange(val) {
  709. this.searchQuery.timeGranularity = val
  710. this.getEchartsTables()
  711. this.initChart()
  712. },
  713. getEchartsTables() {
  714. getLiveOrderTimeGranularity(this.searchQuery).then(res => {
  715. if (res.code == 200) {
  716. this.echartsXLine = res.hourlySlots
  717. this.echartsXValue = res.hourlySlotsValue
  718. this.initChart()
  719. }
  720. })
  721. },
  722. initChart() {
  723. const chartDom = this.$refs.chartContainer;
  724. this.myChart = echarts.init(chartDom);
  725. const option = {
  726. tooltip: {trigger: 'axis'},
  727. legend: {data: ['订单数']},
  728. xAxis: {type: 'category', boundaryGap: false, data: this.echartsXLine},
  729. yAxis: {type: 'value'},
  730. series: [
  731. {name: '订单数', type: 'line', data: this.echartsXValue}
  732. ],
  733. };
  734. this.myChart.setOption(option);
  735. },
  736. handleClickRed(){
  737. this.$router.push({
  738. name: 'LiveRedConf',
  739. query: {
  740. liveId: this.liveId
  741. }
  742. })
  743. },
  744. handleClickLottery(){
  745. this.$router.push({
  746. name: 'LiveLotteryConf',
  747. query: {
  748. liveId: this.liveId
  749. }
  750. })
  751. },
  752. handleClickGoods(){
  753. this.$router.push({
  754. name: 'LiveGoods',
  755. query: {
  756. liveId: this.liveId
  757. }
  758. })
  759. },
  760. handleClickOrder(){
  761. this.$router.push({
  762. name: 'LiveOrder',
  763. query: {
  764. liveId: this.liveId
  765. }
  766. })
  767. },
  768. initPlayer(){
  769. var isUrl = this.livingUrl === null || this.livingUrl.trim() === ''
  770. if (isUrl) {
  771. console.error('直播地址为空,无法初始化播放器')
  772. return
  773. }
  774. if (Hls.isSupported() && !isUrl) {
  775. const videoElement = this.$refs.livingPlayer
  776. if (!videoElement) {
  777. console.error('找不到 video 元素')
  778. return
  779. }
  780. this.hls = new Hls();
  781. this.hls.attachMedia(videoElement);
  782. this.hls.on(Hls.Events.MEDIA_ATTACHED, () => {
  783. this.hls.loadSource(this.livingUrl);
  784. this.hls.on(Hls.Events.STREAM_LOADED, (event, data) => {
  785. videoElement.play();
  786. });
  787. });
  788. this.hls.on(Hls.Events.ERROR, (event, data) => {
  789. console.error('HLS 错误:', data);
  790. });
  791. } else {
  792. console.error('浏览器不支持 HLS')
  793. }
  794. },
  795. handleClick(tab) {
  796. const tabName = tab.name;
  797. const params = this.pageParams[tabName];
  798. const displayList = this[`${tabName}DisplayList`];
  799. // 首次切换到该Tab或列表为空时初始化
  800. if (displayList.length < 20) {
  801. // 重置分页参数
  802. params.currentPage = 1;
  803. params.pageSize = 20;
  804. params.prevPage = 0;
  805. params.totalLoaded = 0;
  806. params.hasMore = true;
  807. params.hasPrev = false;
  808. // 加载第一页
  809. this.loadNextPage(tabName);
  810. } else {
  811. // 非首次切换,恢复滚动位置
  812. this.$nextTick(() => {
  813. const scrollEl = this.getScrollElement(tabName);
  814. if (scrollEl) {
  815. scrollEl.scrollTop = this.tabScrollPositions[tabName] || 0;
  816. }
  817. });
  818. }
  819. },
  820. saveTabScrollPositions() {
  821. this.tabScrollPositions = {
  822. online: this.getScrollElement('online')?.scrollTop || 0,
  823. offline: this.getScrollElement('offline')?.scrollTop || 0,
  824. silenced: this.getScrollElement('silenced')?.scrollTop || 0
  825. };
  826. },
  827. // 加载指定Tab的用户列表(核心加载逻辑)
  828. loadNextPage(tabName) {
  829. const params = this.pageParams[tabName];
  830. const displayList = this[`${tabName}DisplayList`];
  831. console.log(`加载 ${tabName} 用户列表`)
  832. console.log(!params.hasMore || this.scrLoading[tabName].next)
  833. console.log(params.currentPage)
  834. // 若没有更多数据或正在加载,直接返回
  835. if (!params.hasMore || this.scrLoading[tabName].next) {
  836. return;
  837. }
  838. this.scrLoading[tabName].next = true;
  839. const queryParams = {
  840. liveId: this.liveId,
  841. pageNum: params.currentPage,
  842. pageSize: 20,
  843. online: tabName === 'online' ? 0 : 1,
  844. msgStatus: tabName === 'silenced' ? 1 : 0
  845. };
  846. // 调用接口加载对应状态的分页数据(需后端支持按状态筛选)
  847. watchUserList(queryParams).then(response => {
  848. this.scrLoading[tabName].next = false;
  849. if (response.code !== 200) return;
  850. const { rows, total } = response;
  851. params.total = total; // 记录总数据量
  852. // 过滤重复数据(基于userId)
  853. const newRows = rows.filter(row =>
  854. !displayList.some(u => u.userId === row.userId)
  855. );
  856. displayList.push(...newRows)
  857. // 添加新数据并限制最大长度(避免内存占用过大)
  858. if (displayList.length >= 40) { // 最大保留100条
  859. this[`${tabName}DisplayList`] = displayList.slice(-40);
  860. // 记录滚动位置(用于加载后校准)
  861. const scrollEl = this.getScrollElement(tabName);
  862. // 校准滚动位置(保持视觉连续性)
  863. this.$nextTick(() => {
  864. if (scrollEl) {
  865. scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
  866. }
  867. });
  868. }
  869. // 更新分页状态
  870. params.hasMore = params.currentPage * params.pageSize < total;
  871. params.currentPage += 1;
  872. params.hasPrev = params.currentPage > 2; // 当前页>2时一定有上一页
  873. params.prevPage = params.currentPage - 2;
  874. }).catch(() => {
  875. this.scrLoading[tabName].next = false;
  876. });
  877. },
  878. // 新增:加载上一页(向上滚动时)
  879. loadPrevPage(tabName) {
  880. const params = this.pageParams[tabName];
  881. const displayList = this[`${tabName}DisplayList`];
  882. // 边界校验:无上一页/正在加载/当前页<=1
  883. console.log(`加载 ${tabName} 上一页`);
  884. console.log(!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1)
  885. if (!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1) {
  886. return;
  887. }
  888. this.scrLoading[tabName].prev = true;
  889. const targetPage = params.prevPage > 0 ? params.prevPage : params.currentPage - 2;
  890. const queryParams = {
  891. liveId: this.liveId,
  892. pageNum: targetPage,
  893. pageSize: 20,
  894. online: tabName === 'online' ? 0 : 1,
  895. msgStatus: tabName === 'silenced' ? 1 : 0
  896. };
  897. watchUserList(queryParams).then(response => {
  898. this.scrLoading[tabName].prev = false;
  899. if (response.code !== 200) return;
  900. const { rows } = response;
  901. if (rows.length === 0) {
  902. params.hasPrev = false;
  903. return;
  904. }
  905. // 记录滚动位置(用于加载后校准)
  906. const scrollEl = this.getScrollElement(tabName);
  907. const scrollTop = scrollEl?.scrollTop || 0;
  908. const itemHeight = 80; // 预估行高(根据实际样式调整)
  909. const newItemsHeight = rows.length * itemHeight;
  910. // 过滤重复数据并添加到列表头部
  911. const newRows = rows.filter(row => !displayList.some(u => u.userId === row.userId));
  912. this[`${tabName}DisplayList`] = [...newRows, ...displayList];
  913. params.totalLoaded += newRows.length;
  914. // 限制最大长度
  915. if (this[`${tabName}DisplayList`].length > 40) {
  916. this[`${tabName}DisplayList`] = this[`${tabName}DisplayList`].slice(0, 40);
  917. }
  918. // 更新分页状态
  919. params.prevPage = targetPage - 1;
  920. params.hasPrev = targetPage > 1; // 上一页页码>1时还有更多上一页
  921. params.currentPage = params.currentPage - 1;
  922. if(params.currentPage * 20 < params.total) params.hasMore = true;
  923. // 校准滚动位置(保持视觉连续性)
  924. this.$nextTick(() => {
  925. if (scrollEl) {
  926. scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
  927. }
  928. });
  929. }).catch(() => {
  930. this.scrLoading[tabName].prev = false;
  931. });
  932. },
  933. // 辅助:获取Tab对应的滚动容器
  934. getScrollElement(tabName) {
  935. const scrollRefs = {
  936. online: this.$refs.manageLeftRef_online,
  937. offline: this.$refs.manageLeftRef_offline,
  938. silenced: this.$refs.manageLeftRef_silenced
  939. };
  940. return scrollRefs[tabName]?.wrap;
  941. },
  942. getList() {
  943. this.resetParams()
  944. // this.loadUserList()
  945. this.loadUserTotals(); // 先加载总人数
  946. // this.handleClick('online')
  947. this.handleClick({name:'online'})
  948. this.loadMsgList()
  949. },
  950. loadUserTotals() {
  951. if (!this.liveId) return;
  952. // 假设后端提供一个接口返回总人数(如果没有,可通过首次加载全量数据后统计)
  953. getLiveUserTotals({ liveId: this.liveId }).then(res => {
  954. if (res.code === 200) {
  955. this.userTotal = res.data; // { online, offline, silenced }
  956. }
  957. });
  958. },
  959. resetParams() {
  960. // 重置各Tab的显示列表和分页参数
  961. this.onlineDisplayList = [];
  962. this.offlineDisplayList = [];
  963. this.silencedDisplayList = [];
  964. this.pageParams = {
  965. online: {
  966. currentPage: 1, // 当前页(下一页加载用)
  967. pageSize: 20, // 当前页(下一页加载用)
  968. prevPage: 0, // 上一页页码(上一页加载用)
  969. totalLoaded: 0, // 已加载总条数
  970. total: 0, // 总数据量
  971. hasMore: true, // 是否有下一页
  972. hasPrev: false // 是否有上一页
  973. },
  974. offline: {
  975. currentPage: 1,
  976. pageSize: 20,
  977. prevPage: 0,
  978. totalLoaded: 0,
  979. total: 0,
  980. hasMore: true,
  981. hasPrev: false
  982. },
  983. silenced: {
  984. currentPage: 1,
  985. pageSize: 20,
  986. prevPage: 0,
  987. totalLoaded: 0,
  988. total: 0,
  989. hasMore: true,
  990. hasPrev: false
  991. }
  992. };
  993. // 消息参数保留
  994. this.msgList = [];
  995. this.msgParams = {
  996. pageNum: 1,
  997. pageSize: 10,
  998. liveId: this.liveId
  999. };
  1000. },
  1001. loadUserList() {
  1002. if(this.liveId == null) return
  1003. // 直播间用户
  1004. watchUserList({
  1005. liveId: this.liveId,
  1006. pageNum: this.userParams.pageNum,
  1007. pageSize: this.userParams.pageSize
  1008. }).then(response => {
  1009. let {code,rows,total} = response
  1010. if (code === 200) {
  1011. let totalPage = (total % this.userParams.pageSize == 0) ? Math.floor(total / this.userParams.pageSize) : Math.floor(total / this.userParams.pageSize + 1);
  1012. rows.forEach(row => {
  1013. if (!this.userList.some(u => u.userId === row.userId)) {
  1014. this.userList.push(row)
  1015. }
  1016. })
  1017. // 没加载完继续加载
  1018. if (this.userParams.pageNum < totalPage) {
  1019. this.userParams.pageNum = parseInt(this.userParams.pageNum) + 1;
  1020. this.loadUserList()
  1021. }
  1022. }
  1023. })
  1024. },
  1025. loadMsgList() {
  1026. // 直播间消息
  1027. listLiveMsg({
  1028. liveId:this.liveId,
  1029. pageNum: this.msgParams.pageNum,
  1030. pageSize: this.msgParams.pageSize
  1031. }).then(response => {
  1032. let {code, rows,total} = response;
  1033. if (code === 200) {
  1034. let totalPage = (total % this.msgParams.pageSize == 0) ? Math.floor(total / this.msgParams.pageSize) : Math.floor(total / this.msgParams.pageSize + 1);
  1035. rows.forEach(row => {
  1036. if (!this.msgList.some(m => m.msgId === row.msgId)) {
  1037. let user = this.userList.find(u => u.userId === row.userId)
  1038. if (user) {
  1039. row.msgStatus = user.msgStatus
  1040. } else {
  1041. row.msgStatus = 0
  1042. }
  1043. this.msgList.push(row)
  1044. // 移动到底部
  1045. this.$nextTick(() => {
  1046. setTimeout(() => {
  1047. this.$refs.manageRightRef.wrap.scrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
  1048. }, 200)
  1049. })
  1050. }
  1051. })
  1052. // 没加载完继续加载
  1053. if (this.msgParams.pageNum < this.loadMsgMaxPage) {
  1054. this.msgParams.pageNum = parseInt(this.msgParams.pageNum) + 1;
  1055. this.loadMsgList()
  1056. }
  1057. // 同步更新消息列表中相同用户的状态
  1058. this.userList.forEach(u => {
  1059. this.msgList.filter(m => m.userId === u.userId).forEach(m => m.msgStatus = u.msgStatus)
  1060. })
  1061. }
  1062. })
  1063. // 添加滚动监听
  1064. this.$nextTick(() => {
  1065. this.$refs.manageRightRef.wrap.addEventListener("scroll", this.manageRightScroll)
  1066. })
  1067. },
  1068. manageRightScroll() {
  1069. this.saveChatScrollPosition();
  1070. },
  1071. blockUser(u){
  1072. this.$confirm('是否确认封禁用户账号为:"' + u.nickName + '-' + u.userId + '"?', "警告", {
  1073. confirmButtonText: "确定",
  1074. cancelButtonText: "取消",
  1075. type: "warning"
  1076. }).then(() => {
  1077. return blockUser(u.userId);
  1078. }).then(() => {
  1079. let msg = {
  1080. msg: "",
  1081. liveId: this.liveId,
  1082. userId: u.userId,
  1083. userType: 0,
  1084. cmd: 'blockUser',
  1085. avatar: this.$store.state.user.user.avatar,
  1086. nickName: this.$store.state.user.user.nickName
  1087. }
  1088. this.socket.send(JSON.stringify(msg))
  1089. this.msgSuccess("封禁成功");
  1090. }).catch(() => {});
  1091. },
  1092. changeUserState(u) {
  1093. // 修改状态
  1094. changeUserStatus({liveId: u.liveId, userId: u.userId}).then(response => {
  1095. let { code } = response;
  1096. if (200 === code) {
  1097. u.msgStatus = u.msgStatus === 0 ? 1 : 0
  1098. // 同步更新消息列表中相同用户的状态
  1099. this.msgList.forEach(msg => {
  1100. if (msg.userId === u.userId) {
  1101. msg.msgStatus = u.msgStatus;
  1102. }
  1103. });
  1104. this.userList.forEach(user => {
  1105. if (user.userId === u.userId) {
  1106. user.msgStatus = u.msgStatus;
  1107. }
  1108. });
  1109. // 4. 关键:重新筛选所有Tab的显示列表,确保状态同步
  1110. this.refreshUserDisplayLists(u);
  1111. let msg = u.msgStatus === 0 ? "已解禁" : "已禁言"
  1112. this.msgSuccess(msg);
  1113. return
  1114. }
  1115. this.msgError("操作失败");
  1116. })
  1117. },
  1118. // 新增:重新筛选所有Tab的显示列表
  1119. refreshUserDisplayLists(user) {
  1120. const { userId, msgStatus: newStatus, online } = user;
  1121. const oldStatus = newStatus === 1 ? 0 : 1; // 操作前的状态(反向)
  1122. // 1. 禁言操作(newStatus=1):从原在线/离线列表移除,加入禁言列表
  1123. if (newStatus === 1) {
  1124. // 从在线/离线列表中移除该用户(根据当前在线状态)
  1125. if (online === 0) {
  1126. this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== userId);
  1127. this.userTotal.online = Math.max(0, this.userTotal.online - 1);
  1128. } else {
  1129. this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== userId);
  1130. this.userTotal.offline = Math.max(0, this.userTotal.offline - 1);
  1131. }
  1132. this.userTotal.silenced = this.userTotal.silenced + 1;
  1133. // 添加到禁言列表(去重+限制长度)
  1134. const silencedList = this.silencedDisplayList.filter(u => u.userId !== userId);
  1135. silencedList.push(user);
  1136. this.silencedDisplayList = silencedList.slice(-40);
  1137. }
  1138. // 2. 解禁操作(newStatus=0):从禁言列表移除,回到原在线/离线列表
  1139. else {
  1140. // 从禁言列表移除
  1141. this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== userId);
  1142. this.userTotal.silenced = Math.max(0, this.userTotal.silenced - 1);
  1143. // 回到对应的在线/离线列表(根据当前在线状态)
  1144. if (online === 0) {
  1145. // 加入在线列表(去重+限制长度)
  1146. const onlineList = this.onlineDisplayList.filter(u => u.userId !== userId);
  1147. onlineList.push(user);
  1148. this.onlineDisplayList = onlineList.slice(-40);
  1149. this.userTotal.online = this.userTotal.online + 1;
  1150. } else {
  1151. // 加入离线列表(去重+限制长度)
  1152. const offlineList = this.offlineDisplayList.filter(u => u.userId !== userId);
  1153. offlineList.push(user);
  1154. this.offlineDisplayList = offlineList.slice(-40);
  1155. this.userTotal.offline = this.userTotal.offline + 1;
  1156. }
  1157. }
  1158. },
  1159. connectWebSocket() {
  1160. this.$store.dispatch('initLiveWs', {
  1161. liveWsUrl: this.liveWsUrl,
  1162. liveId: this.liveId,
  1163. userId: this.userId
  1164. })
  1165. this.socket = this.$store.state.liveWs[this.liveId]
  1166. this.socket.onmessage = (event) => this.handleWsMessage(event)
  1167. },
  1168. handleWsMessage(event) {
  1169. let { code, data } = JSON.parse(event.data)
  1170. if (code === 200) {
  1171. let { cmd } = data
  1172. if (cmd === 'sendMsg') {
  1173. let message = JSON.parse(data.data)
  1174. let user = this.userList.find(u => u.userId === message.userId)
  1175. if (user) {
  1176. message.msgStatus = user.msgStatus
  1177. } else {
  1178. message.msgStatus = 0
  1179. }
  1180. delete message.params
  1181. if(this.msgList.length > 50){
  1182. this.msgList.shift()
  1183. }
  1184. this.msgList.push(message)
  1185. // 移动到底部
  1186. this.$nextTick(() => {
  1187. setTimeout(() => {
  1188. this.$refs.manageRightRef.wrap.scrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
  1189. }, 200)
  1190. })
  1191. } else if (cmd === 'entry' || cmd === 'out') {
  1192. const user = data;
  1193. const online = cmd === 'entry' ? 0 : 1; // 0=在线,1=离线
  1194. const info = {
  1195. online:online,
  1196. msgStatus: user.msgStatus || 0,
  1197. nickName: user.nickName || '',
  1198. userType: user.userType || 0,
  1199. userId: user.userId || '',
  1200. };
  1201. // 1. 更新总人数(在线/离线互转)
  1202. if (cmd === 'entry') {
  1203. this.userTotal.online += 1;
  1204. this.userTotal.offline = Math.max(0, this.userTotal.offline - 1); // 确保不小于0
  1205. } else {
  1206. this.userTotal.offline += 1;
  1207. this.userTotal.online = Math.max(0, this.userTotal.online - 1); // 确保不小于0
  1208. }
  1209. // 2. 强制更新相关列表(无论当前激活哪个Tab)
  1210. if (cmd === 'entry') {
  1211. // 用户进入:从离线列表删除,添加到在线列表
  1212. this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
  1213. const newOnlineList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
  1214. newOnlineList.push(info);
  1215. this.onlineDisplayList = newOnlineList.slice(-40); // 限制最大50条
  1216. } else {
  1217. // 用户离开:从在线列表删除,添加到离线列表
  1218. this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
  1219. const newOfflineList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
  1220. newOfflineList.push(info);
  1221. this.offlineDisplayList = newOfflineList.slice(-40); // 限制最大50条
  1222. }
  1223. // 3. 处理禁言列表(如果用户是禁言状态,无论进出都要同步)
  1224. if (info.msgStatus === 1) {
  1225. // 禁言用户:从禁言列表删除旧数据,添加新数据
  1226. const newSilencedList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
  1227. newSilencedList.push(info);
  1228. this.silencedDisplayList = newSilencedList.slice(-40);
  1229. } else {
  1230. // 非禁言用户:从禁言列表删除(如果存在)
  1231. this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
  1232. }
  1233. } else if (cmd === 'live_start') {
  1234. } else if (cmd === 'live_end') {
  1235. }
  1236. }
  1237. },
  1238. sendMessage() {
  1239. // 发送前简单校验
  1240. if (this.newMsg.trim() === '') {
  1241. return;
  1242. }
  1243. let msg = {
  1244. msg: this.newMsg,
  1245. liveId: this.liveId,
  1246. userId: this.userId,
  1247. userType: 1,
  1248. cmd: 'sendMsg',
  1249. avatar: this.$store.state.user.user.avatar,
  1250. nickName: this.$store.state.user.user.nickName
  1251. }
  1252. this.socket.send(JSON.stringify(msg))
  1253. this.newMsg = '';
  1254. },
  1255. // 初始化滚动监听(在mounted中调用)
  1256. initScrollListeners() {
  1257. // 为每个Tab的滚动容器添加监听
  1258. this.$nextTick(() => {
  1259. const scrollRefs = {
  1260. online: this.$refs.manageLeftRef_online,
  1261. offline: this.$refs.manageLeftRef_offline,
  1262. silenced: this.$refs.manageLeftRef_silenced
  1263. };
  1264. Object.keys(scrollRefs).forEach(tabName => {
  1265. const scrollEl = scrollRefs[tabName]?.wrap;
  1266. if (scrollEl) {
  1267. scrollEl.addEventListener('scroll', () =>
  1268. this.handleTabScroll(tabName, scrollEl)
  1269. );
  1270. }
  1271. });
  1272. });
  1273. },
  1274. // 处理Tab滚动事件(判断是否触底)
  1275. handleTabScroll(tabName, scrollEl) {
  1276. const { scrollTop, scrollHeight, clientHeight } = scrollEl;
  1277. const bottomThreshold = 50; // 距离底部100px触发下一页
  1278. const topThreshold = 50; // 距离顶部100px触发上一页
  1279. // 加载下一页(滚动到底部附近)
  1280. if (scrollHeight - scrollTop - clientHeight < bottomThreshold) {
  1281. this.loadNextPage(tabName);
  1282. }
  1283. // 加载上一页(滚动到顶部附近)
  1284. if (scrollTop < topThreshold) {
  1285. this.loadPrevPage(tabName);
  1286. }
  1287. },
  1288. },
  1289. destroyed() {
  1290. this.hls?.destroy();
  1291. clearInterval(this.processInterval)
  1292. }
  1293. }
  1294. </script>
  1295. <style lang="stylus" scoped>
  1296. .top-box{
  1297. justify-content: center;
  1298. width: 140px;
  1299. height: 110px;
  1300. background: #FFFFFF;
  1301. border-radius: 16px 16px 16px 16px;
  1302. border: 1px solid #EBF0F9;
  1303. }
  1304. .row-box{
  1305. padding: 10px 16px;
  1306. background: #FAFBFD;
  1307. border-radius: 8px 8px 8px 8px;
  1308. }
  1309. .msg-box{
  1310. word-break: break-all;
  1311. word-wrap: break-word;
  1312. white-space: pre-wrap;
  1313. background-color: #F7F8FA;
  1314. padding: 10px;
  1315. border-radius: 0px 12px 12px 12px;
  1316. font-size: 14px;
  1317. display: inline-block;
  1318. }
  1319. .msg-box-right{
  1320. margin-right: 50px;
  1321. word-break: break-all;
  1322. word-wrap: break-word;
  1323. white-space: pre-wrap;
  1324. background-color:#13C2C2;
  1325. padding: 10px;
  1326. color: #fff;
  1327. border-radius: 12px 0px 12px 12px;
  1328. font-size: 14px;
  1329. display: inline-block;
  1330. }
  1331. .shuru ::v-deep.el-textarea__inner{
  1332. background-color: #F7F8FA !important;
  1333. border-radius: 12px;
  1334. }
  1335. .el-icon-more{
  1336. color:#D9D9D9
  1337. }
  1338. .live-console-tab-right{
  1339. height: 100%;
  1340. }
  1341. .live-console-tab-right .el-scrollbar__view{
  1342. padding: 10px;
  1343. }
  1344. .live-console-tab-right .el-col-offset-1{
  1345. color:#666
  1346. }
  1347. .live-console-tab-right ::v-deep.el-tabs__content{
  1348. height: 90%;
  1349. }
  1350. </style>
  1351. <style scoped>
  1352. .talk-list{
  1353. display: flex;
  1354. }
  1355. .live-console {
  1356. width: 90vw;
  1357. padding: 10px 0;
  1358. }
  1359. .live-console .live-console-col {
  1360. height: 88vh;
  1361. margin-left: 5px;
  1362. padding: 0 10px;
  1363. background-color: white;
  1364. border-radius: 4px;
  1365. }
  1366. /*隐藏水平滚动条*/
  1367. ::v-deep .el-scrollbar__wrap {
  1368. overflow-x: hidden;
  1369. }
  1370. /* 消息输入区域 */
  1371. .chat-input {
  1372. display: flex;
  1373. padding: 10px;
  1374. border-top: 1px solid #ebeef5;
  1375. background-color: #fff;
  1376. min-height: 120px;
  1377. }
  1378. .chat-input .el-input {
  1379. flex: 1;
  1380. margin-right: 10px;
  1381. }
  1382. .chat-input .el-textarea__inner {
  1383. resize: none;
  1384. min-height: 100px;
  1385. }
  1386. ::v-deep .el-textarea__inner {
  1387. border: none !important;
  1388. box-shadow: none !important;
  1389. resize: none !important;
  1390. }
  1391. ::v-deep .el-textarea__inner:focus {
  1392. border: none !important;
  1393. box-shadow: none !important;
  1394. }
  1395. </style>