index.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <template>
  2. <!-- 直播中控台 start -->
  3. <el-row type="flex" justify="center" class="live-console" :gutter="10">
  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" >
  10. <el-row v-if="m.userId !== userId" style="margin-top: 5px" type="flex" align="top" >
  11. <el-col :span="3" style="margin-left: 10px"><el-avatar :src="m.avatar"/></el-col>
  12. <el-col :span="15">
  13. <el-row style="margin-left: 10px">
  14. <el-col><div style="font-size: 12px; color: #999; margin-bottom: 3px;">{{ m.nickName }}</div></el-col>
  15. <el-col :span="24" style="max-width: 200px;">
  16. <div style="white-space: normal; word-wrap: break-word;background-color: #f0f2f5; padding: 8px; border-radius: 5px;font-size: 14px;width: 100%;">
  17. {{ m.msg }}
  18. </div>
  19. </el-col>
  20. <el-col>
  21. <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click="changeUserState(m)">{{ m.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  22. </el-col>
  23. </el-row>
  24. </el-col>
  25. </el-row>
  26. <el-row v-if="m.userId === userId" style="padding: 8px 0" type="flex" align="top" justify="end">
  27. <div style="display: flex;justify-content: flex-end">
  28. <div style="display: flex;justify-content: flex-end;flex-direction: column;max-width: 200px;align-items: flex-end">
  29. <div style="font-size: 12px; color: #999; margin-bottom: 3px;">{{ m.nickName }}</div>
  30. <div style="white-space: normal; word-wrap: break-word;width: 100%; background-color: #e6f7ff; padding: 8px; border-radius: 5px;font-size: 14px;">{{ m.msg }}</div>
  31. </div>
  32. <el-avatar :src="m.avatar" style="margin-left: 10px; margin-right: 10px;"/>
  33. </div>
  34. </el-row>
  35. </el-row>
  36. <!-- 底部留白 -->
  37. <div style="height: 20px;"></div>
  38. </el-scrollbar>
  39. <!-- 消息输入区域 -->
  40. <div style="padding: 10px; border-top: 1px solid #ebeef5; background-color: #fff; min-height: 120px;">
  41. <el-input
  42. type="textarea"
  43. v-model="newMsg"
  44. placeholder="请输入消息..."
  45. :rows="8"
  46. @keyup.enter.native="sendMessage"
  47. clearable
  48. resize="none"
  49. style="flex: 1; margin-right: 10px;"
  50. >
  51. </el-input>
  52. <div style="display: flex; justify-content: flex-end; margin-top: 10px;">
  53. <el-button plain @click="sendMessage">发送</el-button>
  54. </div>
  55. </div>
  56. </el-tab-pane>
  57. </el-tabs>
  58. </el-col>
  59. <!-- 聊天 end -->
  60. <!-- 直播/视频 start -->
  61. <el-col class="live-console-col" :span="12">
  62. <div style="background: #000; border-radius: 5px; overflow: hidden; margin: 10px 5px;">
  63. <div style="border-radius: 5px; overflow: hidden;" v-if="liveType == 1">
  64. <video
  65. controls
  66. ref="livingPlayer"
  67. autoplay
  68. width="100%"
  69. style="display: block; background: #000; height: 45vh;"
  70. ></video>
  71. </div>
  72. <div style="border-radius: 5px; overflow: hidden;" v-else-if="liveType == 2">
  73. <video
  74. controls
  75. ref="videoPlayer"
  76. loop
  77. autoplay
  78. width="100%"
  79. :src="videoUrl"
  80. @click.prevent
  81. @contextmenu.prevent
  82. class="custom-video"
  83. style="display: block; background: #000; height: 45vh;"
  84. ></video>
  85. </div>
  86. <!-- <div style="border-radius: 5px; overflow: hidden;" v-else-if="!isAudit">-->
  87. <!-- <img :src="require('@/assets/images/videoIsAudit.png')" style="width: 100%; height: 45vh;">-->
  88. <!-- </div>-->
  89. <!-- <div style="border-radius: 5px; overflow: hidden;" v-else>-->
  90. <!-- <img :src="require('@/assets/images/videoNotStart.png')" style="width: 100%; height: 45vh;">-->
  91. <!-- </div>-->
  92. </div>
  93. <!-- 底部导航栏 -->
  94. <div style="display: flex; justify-content: space-around; padding: 15px 0; background: #fff; border-top: 1px solid #f0f0f0;">
  95. <div style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickRed">
  96. <i class="el-icon-money" style="font-size: 20px;"></i>
  97. <span style="font-size: 12px; margin-top: 4px;">红包配置</span>
  98. </div>
  99. <div style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickLottery">
  100. <i class="el-icon-present" style="font-size: 20px;"></i>
  101. <span style="font-size: 12px; margin-top: 4px;">抽奖配置</span>
  102. </div>
  103. <div style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickGoods">
  104. <i class="el-icon-goods" style="font-size: 20px;"></i>
  105. <span style="font-size: 12px; margin-top: 4px;">商品</span>
  106. </div>
  107. <div style="display: flex; flex-direction: column; align-items: center; cursor: pointer;" @click="handleClickOrder">
  108. <i class="el-icon-goods" style="font-size: 20px;"></i>
  109. <span style="font-size: 12px; margin-top: 4px;">直播订单</span>
  110. </div>
  111. </div>
  112. <el-radio-group v-model="tableRadio" >
  113. <el-radio-button label="订单数">订单数</el-radio-button>
  114. </el-radio-group>
  115. <div style="position: relative;width: 100%; height: 300px;">
  116. <div ref="chartContainer" style="width: 100%; height: 100%;"></div>
  117. <div style="position: absolute; top: 10px; right: 10px; background: #fff; padding: 5px; z-index: 1;">
  118. <el-select v-model="searchQuery.timeOptions" placeholder="请选择" style="width: 150px" @change="timeChange">
  119. <el-option
  120. v-for="item in timeOptions"
  121. :key="item.value"
  122. :label="item.label"
  123. :value="item.value">
  124. </el-option>
  125. </el-select>
  126. <el-select v-model="searchQuery.timeGranularity" placeholder="请选择" style="width: 150px" @change="timeGranularityChange">
  127. <el-option
  128. v-for="item in timeGranularity"
  129. :key="item.value"
  130. :label="item.label"
  131. :value="item.value">
  132. </el-option>
  133. </el-select>
  134. <!-- <el-button type="primary" @click="applyFilter">搜索</el-button>-->
  135. </div>
  136. </div>
  137. </el-col>
  138. <!-- 直播/视频 end -->
  139. <!-- 用户列表 start -->
  140. <el-col class="live-console-col" :span="6">
  141. <el-tabs class="live-console-tab-right" v-model="tabLeft.activeName" @tab-click="handleClick" :stretch="true">
  142. <el-tab-pane :label="onlineLabel" name="online">
  143. <el-scrollbar ref="manageLeftRef_online" style="height: 800px; width: 100%;">
  144. <el-row style="margin-top: 10px" type="flex" align="middle" v-for="u in onlineUserList">
  145. <el-col :span="20">
  146. <el-row type="flex" align="middle">
  147. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  148. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  149. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  150. </el-row>
  151. </el-col>
  152. <el-col :span="4" >
  153. <el-popover
  154. width="100"
  155. trigger="click">
  156. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  157. <i class="el-icon-more" slot="reference"></i>
  158. </el-popover>
  159. </el-col>
  160. </el-row>
  161. </el-scrollbar>
  162. </el-tab-pane>
  163. <el-tab-pane :label="offlineLabel" name="offline">
  164. <el-scrollbar ref="manageLeftRef_offline" style="height: 800px; width: 100%;">
  165. <el-row style="margin-top: 10px" type="flex" align="middle" v-for="u in offlineUserList">
  166. <el-col :span="20">
  167. <el-row type="flex" align="middle">
  168. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  169. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  170. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  171. </el-row>
  172. </el-col>
  173. <el-col :span="4" >
  174. <el-popover
  175. width="100"
  176. trigger="click">
  177. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  178. <i class="el-icon-more" slot="reference"></i>
  179. </el-popover>
  180. </el-col>
  181. </el-row>
  182. </el-scrollbar>
  183. </el-tab-pane>
  184. <el-tab-pane :label="silencedUserLabel" name="silenced">
  185. <el-scrollbar ref="manageLeftRef_silenced" style="height: 800px; width: 100%;">
  186. <el-row style="margin-top: 10px" type="flex" align="middle" v-for="u in silencedUserList">
  187. <el-col :span="20">
  188. <el-row type="flex" align="middle">
  189. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  190. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  191. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  192. </el-row>
  193. </el-col>
  194. <el-col :span="4" >
  195. <el-popover
  196. width="100"
  197. trigger="click">
  198. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  199. <i class="el-icon-more" slot="reference"></i>
  200. </el-popover>
  201. </el-col>
  202. </el-row>
  203. </el-scrollbar>
  204. </el-tab-pane>
  205. </el-tabs>
  206. </el-col>
  207. <!-- 用户列表 end -->
  208. </el-row>
  209. <!-- 直播中控台 end -->
  210. </template>
  211. <script>
  212. import { changeUserStatus, watchUserList } from '@/api/live/liveWatchUser'
  213. import { getLiveVideoByLiveId } from '@/api/live/liveVideo'
  214. import { getLivingUrl,getLive } from '@/api/live/live'
  215. import { getLiveOrderTimeGranularity } from '@/api/live/liveOrder'
  216. import { listLiveMsg } from '@/api/live/liveMsg'
  217. import Hls from 'hls.js';
  218. import LiveLotteryConf from '@/views/live/liveLotteryConf/index.vue'
  219. import LiveRedConf from '@/views/live/liveRedConf/index.vue'
  220. import LiveGoods from '@/views/live/liveGoods/index.vue'
  221. import LiveOrder from '@/views/live/liveOrder/index.vue'
  222. import echarts from 'echarts'
  223. export default {
  224. name: "LiveConsole",
  225. components: { LiveLotteryConf,LiveRedConf,LiveGoods },
  226. data() {
  227. return {
  228. tabLeft: {
  229. activeName: "online",
  230. },
  231. tabRight: {
  232. activeName: "talk",
  233. },
  234. livingUrl: "",
  235. videoUrl: "",
  236. status: 0,
  237. loadMsgMaxPage: 2,
  238. his: null,
  239. liveVideo: {},
  240. socket: null,
  241. liveWsUrl: process.env.VUE_APP_LIVE_WS_URL + '/app/webSocket',
  242. userParams:{
  243. pageNum: 1,
  244. pageSize: 10,
  245. liveId: null
  246. },
  247. msgParams: {
  248. pageNum: 1,
  249. pageSize: 10,
  250. liveId: null
  251. },
  252. userList: [],
  253. msgList: [],
  254. newMsg: '',
  255. isAudit: false,
  256. myChart: null, // 用于存储 ECharts 实例
  257. liveType: 1,
  258. tableRadio: '订单数',
  259. // ... 其他数据 ...
  260. searchQuery: {timeOptions:'2',timeGranularity:'10',liveId: null}, // 搜索查询条件
  261. timeOptions: [
  262. {value:'2',label:'最近2小时',key:'2'},
  263. {value:'4',label:'最近4小时',key:'4'},
  264. {value:'all',label:'全场',key:'all'},
  265. ],
  266. timeGranularity: [
  267. {value:'10',label:'10分钟',key:'10'},
  268. {value:'30',label:'30分钟',key:'30'},
  269. {value:'60',label:'1小时',key:'60'},
  270. ],
  271. }
  272. },
  273. created() {
  274. // this.getLiveVideo()
  275. this.getList()
  276. this.connectWebSocket()
  277. this.getLive()
  278. this.searchQuery.liveId = this.liveId
  279. },
  280. computed: {
  281. liveId() {
  282. return this.$route.params.liveId;
  283. },
  284. userId() {
  285. return this.$store.state.user.user.userId
  286. },
  287. companyId() {
  288. return this.$store.state.user.user.companyId
  289. },
  290. onlineUserList() {
  291. return this.userList.filter(u => u.online === 0)
  292. },
  293. onlineLabel() {
  294. if (this.onlineUserList.length > 0) {
  295. return '在线(' + this.onlineUserList.length + ')'
  296. }
  297. return '在线'
  298. },
  299. offlineUserList() {
  300. return this.userList.filter(u => u.online === 1)
  301. },
  302. offlineLabel() {
  303. if (this.offlineUserList.length > 0) {
  304. return '离线(' + this.offlineUserList.length + ')'
  305. }
  306. return '离线'
  307. },
  308. silencedUserList() {
  309. return this.userList.filter(u => u.msgStatus === 1)
  310. },
  311. silencedUserLabel() {
  312. if (this.silencedUserList.length > 0) {
  313. return '禁言(' + this.silencedUserList.length + ')'
  314. }
  315. return '禁言'
  316. }
  317. },
  318. mounted() {
  319. this.getEchartsTables();
  320. if (this.videoUrl.length > 0) {
  321. const video = this.$refs.videoPlayer;
  322. video.play()
  323. }
  324. },
  325. methods: {
  326. // 切换音量状态
  327. toggleVolume() {
  328. const video = this.$refs.videoPlayer;
  329. if (video.volume > 0) {
  330. // 保存当前音量并静音
  331. this.lastVolume = video.volume;
  332. video.volume = 0;
  333. this.isMuted = true;
  334. } else {
  335. // 恢复之前的音量
  336. video.volume = this.lastVolume || this.initialVolume;
  337. this.isMuted = false;
  338. }
  339. },
  340. getLive(){
  341. getLive(this.liveId).then(res => {
  342. if (res.code == 200) {
  343. if (res.data.isAudit != 1) {
  344. this.$message.error("当前直播间未经审核");
  345. return
  346. }
  347. this.isAudit = true
  348. this.status = res.data.status
  349. if (res.data.status != 2) {
  350. this.$message.error("当前直播间未直播");
  351. return
  352. }
  353. if (res.data.liveType == 1) {
  354. this.getLiveUrl();
  355. } else {
  356. this.liveType = 2
  357. this.videoUrl = res.data.videoUrl;
  358. }
  359. } else {
  360. this.$message.error(res.msg)
  361. }
  362. this.liveInfo = res.data
  363. })
  364. },
  365. // ... 其他方法 ...
  366. timeChange(val) {
  367. this.searchQuery.timeOptions = val
  368. this.getEchartsTables(this.searchQuery)
  369. this.initChart()
  370. },
  371. timeGranularityChange(val) {
  372. this.searchQuery.timeGranularity = val
  373. this.getEchartsTables()
  374. this.initChart()
  375. },
  376. getEchartsTables() {
  377. getLiveOrderTimeGranularity(this.searchQuery).then(res => {
  378. if (res.code == 200) {
  379. this.echartsXLine = res.hourlySlots
  380. this.echartsXValue = res.hourlySlotsValue
  381. this.initChart()
  382. }
  383. })
  384. },
  385. initChart() {
  386. const chartDom = this.$refs.chartContainer;
  387. this.myChart = echarts.init(chartDom);
  388. const option = {
  389. tooltip: {trigger: 'axis'},
  390. legend: {data: ['订单数']},
  391. xAxis: {type: 'category', boundaryGap: false, data: this.echartsXLine},
  392. yAxis: {type: 'value'},
  393. series: [
  394. {name: '订单数', type: 'line', data: this.echartsXValue}
  395. ],
  396. };
  397. this.myChart.setOption(option);
  398. },
  399. getLiveUrl(){
  400. getLivingUrl(this.liveId).then(res=>{
  401. if(res.code === 200) {
  402. this.livingUrl = res.livingUrl
  403. this.initPlayer()
  404. } else {
  405. this.msgError(res.msg);
  406. }
  407. })
  408. },
  409. handleClickRed(){
  410. this.$router.push({
  411. name: 'LiveRedConf',
  412. query: {
  413. liveId: this.liveId
  414. }
  415. })
  416. },
  417. handleClickLottery(){
  418. this.$router.push({
  419. name: 'LiveLotteryConf',
  420. query: {
  421. liveId: this.liveId
  422. }
  423. })
  424. },
  425. handleClickGoods(){
  426. this.$router.push({
  427. name: 'LiveGoods',
  428. query: {
  429. liveId: this.liveId
  430. }
  431. })
  432. },
  433. handleClickOrder(){
  434. this.$router.push({
  435. name: 'LiveOrder',
  436. query: {
  437. liveId: this.liveId
  438. }
  439. })
  440. },
  441. initPlayer(){
  442. var isUrl = this.livingUrl === null || this.livingUrl.trim() === ''
  443. if (Hls.isSupported() && !isUrl) {
  444. const videoElement = this.$refs.livingPlayer
  445. this.hls = new Hls();
  446. this.hls.attachMedia(videoElement);
  447. this.hls.on(Hls.Events.MEDIA_ATTACHED, () => {
  448. this.hls.loadSource(this.livingUrl);
  449. this.hls.on(Hls.Events.STREAM_LOADED, (event, data) => {
  450. videoElement.play();
  451. });
  452. });
  453. }
  454. },
  455. handleClick(tab) {
  456. },
  457. getLiveVideo() {
  458. getLiveVideoByLiveId(this.liveId).then(res => {
  459. this.liveVideo = res.data
  460. })
  461. },
  462. getList() {
  463. this.resetParams()
  464. this.loadUserList()
  465. this.loadMsgList()
  466. },
  467. resetParams() {
  468. this.userList= []
  469. this.userParams = {
  470. pageNum: 1,
  471. pageSize: 10,
  472. liveId: this.liveId
  473. }
  474. this.msgList = []
  475. this.msgParams = {
  476. pageNum: 1,
  477. pageSize: 10,
  478. liveId: this.liveId
  479. }
  480. },
  481. loadUserList() {
  482. // 直播间用户
  483. watchUserList({
  484. liveId: this.liveId,
  485. pageNum: this.userParams.pageNum,
  486. pageSize: this.userParams.pageSize
  487. }).then(response => {
  488. let {code,rows,total} = response
  489. if (code === 200) {
  490. let totalPage = (total % this.userParams.pageSize == 0) ? Math.floor(total / this.userParams.pageSize) : Math.floor(total / this.userParams.pageSize + 1);
  491. rows.forEach(row => {
  492. if (!this.userList.some(u => u.userId === row.userId)) {
  493. this.userList.push(row)
  494. }
  495. })
  496. // 没加载完继续加载
  497. if (this.userParams.pageNum < totalPage) {
  498. this.userParams.pageNum = parseInt(this.userParams.pageNum) + 1;
  499. this.loadUserList()
  500. }
  501. }
  502. })
  503. },
  504. loadMsgList() {
  505. // 直播间消息
  506. listLiveMsg({
  507. liveId:this.liveId,
  508. pageNum: this.msgParams.pageNum,
  509. pageSize: this.msgParams.pageSize
  510. }).then(response => {
  511. let {code, rows,total} = response;
  512. if (code === 200) {
  513. let totalPage = (total % this.msgParams.pageSize == 0) ? Math.floor(total / this.msgParams.pageSize) : Math.floor(total / this.msgParams.pageSize + 1);
  514. rows.forEach(row => {
  515. if (!this.msgList.some(m => m.msgId === row.msgId)) {
  516. let user = this.userList.find(u => u.userId === row.userId)
  517. if (user) {
  518. row.msgStatus = user.msgStatus
  519. } else {
  520. row.msgStatus = 0
  521. }
  522. this.msgList.push(row)
  523. // 移动到底部
  524. this.$nextTick(() => {
  525. setTimeout(() => {
  526. this.$refs.manageRightRef.wrap.scrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
  527. }, 200)
  528. })
  529. }
  530. })
  531. // 没加载完继续加载
  532. if (this.msgParams.pageNum < this.loadMsgMaxPage) {
  533. this.msgParams.pageNum = parseInt(this.msgParams.pageNum) + 1;
  534. this.loadMsgList()
  535. }
  536. // 同步更新消息列表中相同用户的状态
  537. this.userList.forEach(u => {
  538. this.msgList.filter(m => m.userId === u.userId).forEach(m => m.msgStatus = u.msgStatus)
  539. })
  540. }
  541. })
  542. // 添加滚动监听
  543. this.$nextTick(() => {
  544. this.$refs.manageRightRef.wrap.addEventListener("scroll", this.manageRightScroll)
  545. })
  546. },
  547. manageRightScroll() {
  548. let max = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
  549. let current = this.$refs.manageRightRef.wrap.scrollTop
  550. console.log("manageRightMax", max);
  551. console.log("manageRight", current)
  552. },
  553. changeUserState(u) {
  554. // 修改状态
  555. changeUserStatus({liveId: u.liveId, userId: u.userId}).then(response => {
  556. let { code } = response;
  557. if (200 === code) {
  558. u.msgStatus = u.msgStatus === 0 ? 1 : 0
  559. // 同步更新消息列表中相同用户的状态
  560. this.msgList.forEach(msg => {
  561. if (msg.userId === u.userId) {
  562. msg.msgStatus = u.msgStatus;
  563. }
  564. });
  565. this.userList.forEach(user => {
  566. if (user.userId === u.userId) {
  567. user.msgStatus = u.msgStatus;
  568. }
  569. });
  570. let msg = u.msgStatus === 0 ? "已解禁" : "已禁言"
  571. this.msgSuccess(msg);
  572. return
  573. }
  574. this.msgError("操作失败");
  575. })
  576. },
  577. connectWebSocket() {
  578. this.$store.dispatch('initLiveWs', {
  579. liveWsUrl: this.liveWsUrl,
  580. liveId: this.liveId,
  581. userId: this.userId
  582. })
  583. this.socket = this.$store.state.liveWs
  584. this.socket.onmessage = (event) => this.handleWsMessage(event)
  585. },
  586. handleWsMessage(event) {
  587. let { code, data } = JSON.parse(event.data)
  588. if (code === 200) {
  589. let { cmd } = data
  590. if (cmd === 'sendMsg') {
  591. let message = JSON.parse(data.data)
  592. let user = this.userList.find(u => u.userId === message.userId)
  593. if (user) {
  594. message.msgStatus = user.msgStatus
  595. } else {
  596. message.msgStatus = 0
  597. }
  598. delete message.params
  599. this.msgList.push(message)
  600. // 移动到底部
  601. this.$nextTick(() => {
  602. setTimeout(() => {
  603. this.$refs.manageRightRef.wrap.scrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
  604. }, 200)
  605. })
  606. }
  607. else if (cmd === 'entry' || cmd === 'out') {
  608. let user = data
  609. if(this.userList.length > 0){
  610. this.userList = this.userList.filter(u => u.userId !== user.userId)
  611. }
  612. this.userList.push(user)
  613. }
  614. }
  615. },
  616. sendMessage() {
  617. // 发送前简单校验
  618. if (this.newMsg.trim() === '') {
  619. return;
  620. }
  621. let msg = {
  622. msg: this.newMsg,
  623. liveId: this.liveId,
  624. userId: this.userId,
  625. userType: 1,
  626. cmd: 'sendMsg',
  627. avatar: this.$store.state.user.user.avatar,
  628. nickName: this.$store.state.user.user.nickName
  629. }
  630. this.socket.send(JSON.stringify(msg))
  631. this.newMsg = '';
  632. }
  633. },
  634. destroyed() {
  635. this.socket?.close()
  636. this.hls?.destroy();
  637. }
  638. }
  639. </script>
  640. <style scoped>
  641. .talk-list{
  642. display: flex;
  643. }
  644. .live-console {
  645. width: 90vw;
  646. padding: 10px 0;
  647. background-color: #f5f4f4;
  648. }
  649. .live-console .live-console-col {
  650. height: 88vh;
  651. margin-left: 5px;
  652. padding: 0 10px;
  653. background-color: white;
  654. border-radius: 4px;
  655. }
  656. /*隐藏水平滚动条*/
  657. ::v-deep .el-scrollbar__wrap {
  658. overflow-x: hidden;
  659. }
  660. /* 消息输入区域 */
  661. .chat-input {
  662. display: flex;
  663. padding: 10px;
  664. border-top: 1px solid #ebeef5;
  665. background-color: #fff;
  666. min-height: 120px;
  667. }
  668. .chat-input .el-input {
  669. flex: 1;
  670. margin-right: 10px;
  671. }
  672. .chat-input .el-textarea__inner {
  673. resize: none;
  674. min-height: 100px;
  675. }
  676. ::v-deep .el-textarea__inner {
  677. border: none !important;
  678. box-shadow: none !important;
  679. resize: none !important;
  680. }
  681. ::v-deep .el-textarea__inner:focus {
  682. border: none !important;
  683. box-shadow: none !important;
  684. }
  685. ::v-deep .el-tabs__item {
  686. padding: 0;
  687. }
  688. .live-console-tab-left ::v-deep .el-tabs__active-bar {
  689. width: 41px!important;
  690. margin-left: calc((100% / 1 - 41px) / 2);
  691. height: 4px;
  692. border-radius: 4px;
  693. }
  694. /* calc 3是tab数量 */
  695. .live-console-tab-right ::v-deep .el-tabs__active-bar {
  696. width: 51px!important;
  697. margin-left: calc((100% / 3 - 51px) / 2);
  698. height: 4px;
  699. border-radius: 4px;
  700. }
  701. .custom-video {
  702. pointer-events: none !important; /* 完全禁止鼠标交互,避免悬停时显示工具栏 */
  703. }
  704. </style>