LiveConsole.vue 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627
  1. <template>
  2. <div class="console">
  3. <div class="left-panel">
  4. <h2>学员列表</h2>
  5. <div class="search">
  6. <input type="text" placeholder="搜索用户昵称" v-model="searchKeyword">
  7. <button @click="searchUsers()">搜索</button>
  8. </div>
  9. <el-tabs class="live-console-tab-right" v-model="tabLeft.activeName" @tab-click="handleUserClick" :stretch="true">
  10. <el-tab-pane :label="alLabel" name="al">
  11. <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_al" style="height: 800px; width: 100%;">
  12. <el-row class='scrollbar-demo-item' v-for="u in alDisplayList" :key="u.userId">
  13. <el-col :span="20">
  14. <el-row type="flex" align="middle">
  15. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  16. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  17. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  18. </el-row>
  19. </el-col>
  20. <el-col :span="4" >
  21. <el-popover
  22. width="100"
  23. trigger="click">
  24. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  25. <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
  26. <i class="el-icon-more" slot="reference"></i>
  27. </el-popover>
  28. </el-col>
  29. </el-row>
  30. </el-scrollbar>
  31. </el-tab-pane>
  32. <el-tab-pane :label="onlineLabel" name="online">
  33. <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_online" style="height: 800px; width: 100%;">
  34. <el-row class='scrollbar-demo-item' v-for="u in onlineDisplayList" :key="u.userId">
  35. <el-col :span="20">
  36. <el-row type="flex" align="middle">
  37. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  38. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  39. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  40. </el-row>
  41. </el-col>
  42. <el-col :span="4" >
  43. <el-popover
  44. width="100"
  45. trigger="click">
  46. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  47. <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
  48. <i class="el-icon-more" slot="reference"></i>
  49. </el-popover>
  50. </el-col>
  51. </el-row>
  52. </el-scrollbar>
  53. </el-tab-pane>
  54. <el-tab-pane :label="offlineLabel" name="offline">
  55. <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_offline" style="height: 800px; width: 100%;">
  56. <el-row class='scrollbar-demo-item' v-for="u in offlineDisplayList" :key="u.userId">
  57. <el-col :span="20">
  58. <el-row type="flex" align="middle">
  59. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  60. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  61. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  62. </el-row>
  63. </el-col>
  64. <el-col :span="4" >
  65. <el-popover
  66. width="100"
  67. trigger="click">
  68. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  69. <i class="el-icon-more" slot="reference"></i>
  70. <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
  71. </el-popover>
  72. </el-col>
  73. </el-row>
  74. </el-scrollbar>
  75. </el-tab-pane>
  76. <el-tab-pane :label="silencedUserLabel" name="silenced">
  77. <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_silenced" style="height: 800px; width: 100%;">
  78. <el-row class='scrollbar-demo-item' v-for="u in silencedDisplayList" :key="u.userId">
  79. <el-col :span="20">
  80. <el-row type="flex" align="middle">
  81. <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
  82. <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
  83. <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
  84. </el-row>
  85. </el-col>
  86. <el-col :span="4" >
  87. <el-popover
  88. width="100"
  89. trigger="click">
  90. <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  91. <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
  92. <i class="el-icon-more" slot="reference"></i>
  93. </el-popover>
  94. </el-col>
  95. </el-row>
  96. </el-scrollbar>
  97. </el-tab-pane>
  98. </el-tabs>
  99. </div>
  100. <div class="middle-panel">
  101. <h2>消息管理</h2>
  102. <div class="discussion-messages">
  103. <h3>讨论区消息</h3>
  104. <div class="message-settings">
  105. <label>
  106. <input type="checkbox" v-model="globalVisible" @change="globalVisibleChange">
  107. 全局用户自见
  108. </label>
  109. </div>
  110. <el-scrollbar class="custom-scrollbar" style="height: 500px; width: 100%;" ref="manageRightRef">
  111. <el-row v-for="m in msgList" :key="m.msgId">
  112. <el-row v-if="m.userId === userId && m.msgId == null" style="padding: 8px 0" type="flex" align="top" justify="end">
  113. <div style="display: flex;justify-content: flex-end">
  114. <div style="display: flex;justify-content: flex-end;flex-direction: column;max-width: 200px;align-items: flex-end">
  115. <div style="font-size: 12px; color: #999; margin-bottom: 3px;">{{ m.nickName }}</div>
  116. <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>
  117. </div>
  118. <el-avatar :src="m.avatar" style="margin-left: 10px; margin-right: 10px;"/>
  119. </div>
  120. </el-row>
  121. <el-row v-else style="margin-top: 5px" type="flex" align="top" >
  122. <el-col :span="3" style="margin-left: 10px"><el-avatar :src="m.avatar"/></el-col>
  123. <el-col :span="15">
  124. <el-row style="margin-left: 10px">
  125. <el-col><div style="font-size: 12px; color: #999; margin-bottom: 3px;">{{ m.nickName }}</div></el-col>
  126. <el-col :span="24" style="max-width: 200px;">
  127. <div style="white-space: normal; word-wrap: break-word;background-color: #f0f2f5; padding: 8px; border-radius: 5px;font-size: 14px;width: 100%;">
  128. {{ m.msg }}
  129. </div>
  130. </el-col>
  131. <el-col>
  132. <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click="changeUserState(m)">{{ m.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  133. <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click="blockUser(m)">拉黑</a>
  134. <a v-if="m.singleVisible === 1" style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click="singleVisible(m)">解除用户自见</a>
  135. <a v-else style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click="singleVisible(m)">用户自见</a>
  136. <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click="deleteMsg(m)">删除</a>
  137. </el-col>
  138. </el-row>
  139. </el-col>
  140. </el-row>
  141. </el-row>
  142. <!-- 底部留白 -->
  143. <div style="height: 20px;"></div>
  144. </el-scrollbar>
  145. <!-- <div class="message-list">-->
  146. <!-- <div class="message-item" v-for="msg in msgList" :key="msg.id">-->
  147. <!-- <div class="message-avatar">-->
  148. <!-- <img :src="msg.avatar" alt="用户头像">-->
  149. <!-- </div>-->
  150. <!-- <div class="message-content">-->
  151. <!-- <div class="message-user">{{ msg.user }}</div>-->
  152. <!-- <div class="message-text">{{ msg.text }}</div>-->
  153. <!-- </div>-->
  154. <!-- <div class="message-actions">-->
  155. <!--&lt;!&ndash; <button @click="toggleVisible(msg)">&ndash;&gt;-->
  156. <!--&lt;!&ndash; {{ msg.isVisible ? '仅用户自见' : '全局可见' }}&ndash;&gt;-->
  157. <!--&lt;!&ndash; </button>&ndash;&gt;-->
  158. <!-- <button @click="deleteMessage(msg)">删除</button>-->
  159. <!-- </div>-->
  160. <!-- </div>-->
  161. <!-- </div>-->
  162. </div>
  163. <div class="system-messages">
  164. <h3>系统消息</h3>
  165. <textarea placeholder="输入系统消息" v-model="newMsg"></textarea>
  166. <div class="message-actions">
  167. <button @click="sendMessage">发送消息</button>
  168. <button @click="sendPopMessage">弹窗消息</button>
  169. <button @click="showTopMsgDialog">顶部消息</button>
  170. </div>
  171. </div>
  172. </div>
  173. <div class="right-panel">
  174. <h2>运营工具</h2>
  175. <div class="live-player">
  176. <h3>直播观看</h3>
  177. <LivePlayer ref="livePlayer" :videoParam="videoParam" />
  178. </div>
  179. <div class="automation">
  180. <h3>运营自动化</h3>
  181. <div class="timeline">
  182. <h4>时间轴设置</h4>
  183. <div class="timeline-items">
  184. <div class="timeline-item" v-for="item in timelineItems.slice(0,2)" :key="item.time">
  185. <div class="time">{{ formatDate(item.absValue) }}</div>
  186. <div class="action">{{ item.taskName }}</div>
  187. <button class="delete" @click="removeTimelineItem(item)">删除</button>
  188. </div>
  189. </div>
  190. <!-- <button class="add" @click="addTimelineItem">添加时间节点</button>-->
  191. </div>
  192. </div>
  193. <div class="watermark">
  194. <h3>直播氛围自动化</h3>
  195. <div class="watermark-settings">
  196. <textarea :disabled="autoWatermark" v-model="watermarkTemplate" placeholder="水军弹幕内容模板,每行一条"></textarea>
  197. <div class="watermark-options">
  198. <label>
  199. 发送间隔:
  200. <input type="number" :disabled="autoWatermark" v-model.number="interval" min="1">
  201. </label>
  202. <label>
  203. <input type="checkbox" v-model="autoWatermark" @change="changeAutoWatermark">
  204. 启用水军自动化
  205. </label>
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. <!-- 顶部消息对话框 -->
  211. <el-dialog title="发送顶部消息" :visible.sync="topMsgDialogVisible" width="500px">
  212. <el-form :model="topMsgForm" label-width="100px">
  213. <el-form-item label="消息内容">
  214. <el-input
  215. type="textarea"
  216. v-model="topMsgForm.msg"
  217. placeholder="请输入消息内容"
  218. :rows="3"
  219. ></el-input>
  220. </el-form-item>
  221. <el-form-item label="显示时长">
  222. <el-input-number
  223. v-model="topMsgForm.duration"
  224. :min="1"
  225. :max="60"
  226. placeholder="请输入显示时长(分钟)"
  227. ></el-input-number>
  228. <span style="margin-left: 10px;">分钟</span>
  229. </el-form-item>
  230. </el-form>
  231. <div slot="footer" class="dialog-footer">
  232. <el-button @click="topMsgDialogVisible = false">取 消</el-button>
  233. <el-button type="primary" @click="sendTopMessage">确 定</el-button>
  234. </div>
  235. </el-dialog>
  236. </div>
  237. </template>
  238. <script>
  239. import LivePlayer from './LivePlayer.vue';
  240. import {blockUser, changeUserStatus, getLiveUserTotals, dashBoardWatchUserList} from '@/api/live/liveWatchUser'
  241. import { listLiveSingleMsg,delLiveMsg } from '@/api/live/liveMsg'
  242. import { getLive } from '@/api/live/live'
  243. import { consoleList } from '@/api/live/task'
  244. import ScreenScale from './ScreenScale.vue'; // 路径根据实际位置调整
  245. export default {
  246. components: {
  247. LivePlayer,ScreenScale
  248. },
  249. props: {
  250. liveId: {
  251. type: String,
  252. default: null
  253. }
  254. },
  255. data() {
  256. return {
  257. watermarkIndex: 0,
  258. watermarkList:[],
  259. watermarkTemplate: '',
  260. liveInfo: {},
  261. videoParam:{
  262. startTime:'',
  263. livingUrl: '',
  264. liveType: 1,
  265. videoUrl: '',
  266. },
  267. msgList:[],
  268. currentTab: 'al',
  269. searchKeyword: '',
  270. globalVisible: false,
  271. interval: 10,
  272. autoWatermark: false,
  273. streamUrl: 'rtmp://your-live-stream-url',
  274. users: [
  275. { id: 1, name: '用户1', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: false },
  276. { id: 2, name: '用户2', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: true },
  277. { id: 3, name: '用户3', avatar: 'https://via.placeholder.com/40', status: 'offline', statusText: '离线', silenced: true, msgStatus: false },
  278. { id: 4, name: '用户4', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: false },
  279. { id: 5, name: '用户5', avatar: 'https://via.placeholder.com/40', status: 'offline', statusText: '离线', silenced: false, msgStatus: false }
  280. ],
  281. messages: [
  282. { id: 1, user: '用户1', avatar: 'https://via.placeholder.com/30', text: '这个产品怎么样?', isVisible: true },
  283. { id: 2, user: '用户2', avatar: 'https://via.placeholder.com/30', text: '看起来不错', isVisible: true },
  284. { id: 3, user: '用户3', avatar: 'https://via.placeholder.com/30', text: '有优惠吗?', isVisible: true }
  285. ],
  286. timelineItems: [
  287. { "searchValue": null,
  288. "createBy": null,
  289. "createTime": "2025-09-23 10:36:17",
  290. "updateBy": null,
  291. "updateTime": "2025-10-17 09:18:00",
  292. "remark": null,
  293. "params": {},
  294. "id": 6573,
  295. "liveId": 128,
  296. "taskName": "2",
  297. "taskType": 1,
  298. "triggerType": 2,
  299. "triggerValue": "2025-01-01T00:02:00.000+0800",
  300. "absValue": "2025-11-23T10:43:00.000+0800",
  301. "status": 1,
  302. "finishStatus": 0 },
  303. ],
  304. userTotal: {
  305. online: 0, // 在线总人数
  306. offline: 0, // 离线总人数
  307. silenced: 0, // 禁言总人数
  308. al: 0
  309. },
  310. tabLeft: {
  311. activeName: "al",
  312. },
  313. taskParams:{
  314. currentPage: 1,
  315. pageSize: 20,
  316. prevPage: 0,
  317. totalLoaded: 0,
  318. total: 0,
  319. hasMore: true,
  320. hasPrev: false
  321. },
  322. loadMsgMaxPage: 2,
  323. liveWsUrl: process.env.VUE_APP_LIVE_WS_URL + '/app/webSocket',
  324. alDisplayList: [],
  325. onlineDisplayList: [], // 在线用户显示列表
  326. offlineDisplayList: [], // 离线用户显示列表
  327. silencedDisplayList: [], // 禁言用户显示列表
  328. // 各Tab的分页参数
  329. pageParams: {
  330. al: {
  331. currentPage: 1,
  332. pageSize: 20,
  333. prevPage: 0,
  334. totalLoaded: 0,
  335. total: 0,
  336. hasMore: true,
  337. hasPrev: false
  338. },
  339. online: {
  340. currentPage: 1, // 当前页(下一页加载用)
  341. pageSize: 20, // 当前页(下一页加载用)
  342. prevPage: 0, // 上一页页码(上一页加载用)
  343. totalLoaded: 0, // 已加载总条数
  344. total: 0, // 总数据量
  345. hasMore: true, // 是否有下一页
  346. hasPrev: false // 是否有上一页
  347. },
  348. offline: {
  349. currentPage: 1,
  350. pageSize: 20,
  351. prevPage: 0,
  352. totalLoaded: 0,
  353. total: 0,
  354. hasMore: true,
  355. hasPrev: false
  356. },
  357. silenced: {
  358. currentPage: 1,
  359. pageSize: 20,
  360. prevPage: 0,
  361. totalLoaded: 0,
  362. total: 0,
  363. hasMore: true,
  364. hasPrev: false
  365. }
  366. },
  367. scrLoading: {
  368. al: { next: false, prev: false },
  369. online: { next: false, prev: false },
  370. offline: { next: false, prev: false },
  371. silenced: { next: false, prev: false }
  372. },
  373. newMsg:'',
  374. autoMsgTimer: null,
  375. checkInterval: 2000, // 检查间隔(1分钟,可根据需求调整)
  376. topMsgDialogVisible: false,
  377. topMsgForm: {
  378. msg: '',
  379. duration: 5
  380. }
  381. };
  382. },
  383. computed: {
  384. userId() {
  385. return this.$store.state.user.user.userId
  386. },
  387. companyId() {
  388. return this.$store.state.user.user.companyId
  389. },
  390. onlineLabel() {
  391. return `在线(${this.userTotal.online})`;
  392. },
  393. alLabel() {
  394. return `全部(${this.userTotal.al})`;
  395. },
  396. offlineLabel() {
  397. return `离线(${this.userTotal.offline})`;
  398. },
  399. silencedUserLabel() {
  400. return `禁言(${this.userTotal.silenced})`;
  401. }
  402. },
  403. created() {
  404. if(!this.liveId) return
  405. this.getList()
  406. this.handleUserClick({name:'al'})
  407. this.connectWebSocket()
  408. this.getLive()
  409. },
  410. mounted() {
  411. this.$nextTick(() => {
  412. this.restoreChatScrollPosition();
  413. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  414. this.$refs.manageRightRef.wrap.addEventListener('scroll', this.saveChatScrollPosition);
  415. }
  416. });
  417. this.initScrollListeners();
  418. },
  419. methods: {
  420. singleVisible(m){
  421. // 过滤当前所有消息 找到userId的相同的消息 更改他们的自可见状态
  422. m.singleVisible= m.singleVisible === 1 ? 0 : 1
  423. this.msgList.forEach(m1 => {m1.singleVisible = m1.userId === m.userId ? m.singleVisible : !m.singleVisible})
  424. // 消息自可见
  425. let msg = {
  426. liveId: this.liveId,
  427. userId: m.userId,
  428. userType: 0,
  429. cmd: 'singleVisible',
  430. status:m.singleVisible
  431. }
  432. this.socket.send(JSON.stringify(msg))
  433. },
  434. deleteMsg(m){
  435. // 1. 弹出确认对话框
  436. this.$confirm('此操作将永久删除该消息, 是否继续?', '提示', {
  437. confirmButtonText: '确定',
  438. cancelButtonText: '取消',
  439. type: 'warning'
  440. }).then(() => {
  441. delLiveMsg(m.msgId).then(res => {
  442. if (res.code === 200) {
  443. const index = this.msgList.findIndex(item => item.msgId === m.msgId);
  444. if (index !== -1) {
  445. this.msgList.splice(index, 1);
  446. console.log(`消息 ${m.msgId} 已在本地删除。`);
  447. }
  448. let msg = {
  449. liveId: this.liveId,
  450. userId: m.userId,
  451. msg: m.msgId, // 关键:将消息ID发送给后台
  452. cmd: 'deleteMsg',
  453. };
  454. this.socket.send(JSON.stringify(msg));
  455. // 可以在这里给用户一个删除成功的提示
  456. this.$message({
  457. type: 'success',
  458. message: '消息删除成功!'
  459. });
  460. }
  461. })
  462. }).catch(() => {
  463. // 3. 用户点击“取消”或关闭对话框后的回调
  464. this.$message({
  465. type: 'info',
  466. message: '已取消删除'
  467. });
  468. });
  469. },
  470. globalVisibleChange( val){
  471. // 消息自可见
  472. let msg = {
  473. liveId: this.liveId,
  474. userId: '9999',
  475. userType: 0,
  476. cmd: 'globalVisible',
  477. status:this.globalVisible ? 1 :0
  478. }
  479. this.socket.send(JSON.stringify(msg))
  480. },
  481. changeAutoWatermark( val){
  482. this.watermarkList = this.watermarkTemplate
  483. .split('\n')
  484. .map(line => line.trim())
  485. .filter(line => line !== '');
  486. if(this.watermarkTemplate.length < 1 || this.watermarkList.length === 0) {
  487. this.$message.warning('请先填写水印模板')
  488. this.$nextTick(() => {
  489. this.autoWatermark = false
  490. });
  491. return
  492. }
  493. this.disabled = this.autoWatermark
  494. if(this.autoWatermark){
  495. this.autoMsgTimer = setInterval(() => {
  496. this.sendNormalMessage()
  497. }, 1000 * this.interval)
  498. } else {
  499. clearInterval(this.autoMsgTimer)
  500. this.watermarkIndex = 0;
  501. this.watermarkList = [];
  502. }
  503. },
  504. sendNormalMessage() {
  505. if(this.watermarkIndex >= this.watermarkList.length){
  506. clearInterval(this.autoMsgTimer)
  507. this.watermarkIndex = 0;
  508. this.watermarkList = [];
  509. this.$message.success('自动发送消息已结束');
  510. this.$nextTick(() => {
  511. this.autoWatermark = false
  512. });
  513. return;
  514. }
  515. const curMsg = this.watermarkList[this.watermarkIndex]
  516. // 发送前简单校验
  517. if (curMsg.trim() === '') {
  518. return;
  519. }
  520. let msg = {
  521. msg: curMsg,
  522. liveId: this.liveId,
  523. userId: '9999',
  524. userType: 0,
  525. cmd: 'sendNormalMsg',
  526. avatar: this.$store.state.user.user.avatar,
  527. nickName: this.$store.state.user.user.nickName,
  528. }
  529. this.socket.send(JSON.stringify(msg))
  530. this.watermarkIndex += 1
  531. },
  532. // 弹窗消息
  533. sendPopMessage() {
  534. // 发送前简单校验
  535. if (this.newMsg.trim() === '') {
  536. return;
  537. }
  538. let msg = {
  539. msg: this.newMsg,
  540. liveId: this.liveId,
  541. userId: this.userId,
  542. userType: 1,
  543. cmd: 'sendPopMsg',
  544. avatar: this.$store.state.user.user.avatar,
  545. nickName: this.$store.state.user.user.nickName,
  546. }
  547. this.socket.send(JSON.stringify(msg))
  548. this.newMsg = '';
  549. },
  550. // 显示顶部消息对话框
  551. showTopMsgDialog() {
  552. this.topMsgForm.msg = '';
  553. this.topMsgForm.duration = 5;
  554. this.topMsgDialogVisible = true;
  555. },
  556. // 发送顶部消息
  557. sendTopMessage() {
  558. // 发送前简单校验
  559. if (this.topMsgForm.msg.trim() === '') {
  560. this.$message.warning('请输入消息内容');
  561. return;
  562. }
  563. if (!this.topMsgForm.duration || this.topMsgForm.duration < 1) {
  564. this.$message.warning('请输入有效的显示时长');
  565. return;
  566. }
  567. let msg = {
  568. msg: this.topMsgForm.msg,
  569. duration: this.topMsgForm.duration,
  570. liveId: this.liveId,
  571. userId: this.userId,
  572. userType: 1,
  573. cmd: 'sendTopMsg',
  574. avatar: this.$store.state.user.user.avatar,
  575. nickName: this.$store.state.user.user.nickName,
  576. }
  577. this.socket.send(JSON.stringify(msg))
  578. this.topMsgDialogVisible = false;
  579. this.$message.success('顶部消息发送成功');
  580. },
  581. sendMessage() {
  582. // 发送前简单校验
  583. if (this.newMsg.trim() === '') {
  584. return;
  585. }
  586. let msg = {
  587. msg: this.newMsg,
  588. liveId: this.liveId,
  589. userId: this.userId,
  590. userType: 1,
  591. cmd: 'sendMsg',
  592. avatar: this.$store.state.user.user.avatar,
  593. nickName: this.$store.state.user.user.nickName,
  594. }
  595. this.socket.send(JSON.stringify(msg))
  596. this.newMsg = '';
  597. },
  598. handleWsMessage(event) {
  599. let { code, data } = JSON.parse(event.data)
  600. if (code === 200) {
  601. let { cmd } = data
  602. if (cmd === 'sendMsg') {
  603. let message = JSON.parse(data.data)
  604. let user = this.alDisplayList.find(u => u.userId === message.userId)
  605. if (user) {
  606. message.msgStatus = user.msgStatus
  607. } else {
  608. message.msgStatus = 0
  609. }
  610. delete message.params
  611. if(this.msgList.length > 50){
  612. this.msgList.shift()
  613. }
  614. this.msgList.push(message)
  615. // 移动到底部
  616. this.$nextTick(() => {
  617. setTimeout(() => {
  618. this.$refs.manageRightRef.wrap.scrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
  619. }, 200)
  620. })
  621. } else if (cmd === 'entry' || cmd === 'out') {
  622. const user = data;
  623. const online = cmd === 'entry' ? 0 : 1; // 0=在线,1=离线
  624. const info = {
  625. online:online,
  626. msgStatus: user.msgStatus || 0,
  627. nickName: user.nickName || '',
  628. userType: user.userType || 0,
  629. userId: user.userId || '',
  630. };
  631. // 1. 更新总人数(在线/离线互转)
  632. if (cmd === 'entry') {
  633. this.userTotal.online += 1;
  634. this.userTotal.offline = Math.max(0, this.userTotal.offline - 1); // 确保不小于0
  635. } else {
  636. this.userTotal.offline += 1;
  637. this.userTotal.online = Math.max(0, this.userTotal.online - 1); // 确保不小于0
  638. }
  639. // 2. 强制更新相关列表(无论当前激活哪个Tab)
  640. if (cmd === 'entry') {
  641. // 用户进入:从离线列表删除,添加到在线列表
  642. this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
  643. const newOnlineList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
  644. newOnlineList.push(info);
  645. this.onlineDisplayList = newOnlineList.slice(-40); // 限制最大50条
  646. } else {
  647. // 用户离开:从在线列表删除,添加到离线列表
  648. this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
  649. const newOfflineList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
  650. newOfflineList.push(info);
  651. this.offlineDisplayList = newOfflineList.slice(-40); // 限制最大50条
  652. }
  653. // 3. 处理禁言列表(如果用户是禁言状态,无论进出都要同步)
  654. if (info.msgStatus === 1) {
  655. // 禁言用户:从禁言列表删除旧数据,添加新数据
  656. const newSilencedList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
  657. newSilencedList.push(info);
  658. this.silencedDisplayList = newSilencedList.slice(-40);
  659. } else {
  660. // 非禁言用户:从禁言列表删除(如果存在)
  661. this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
  662. }
  663. } else if (cmd === 'live_start') {
  664. } else if (cmd === 'live_end') {
  665. }
  666. }
  667. },
  668. getLive(){
  669. getLive(this.liveId).then(res => {
  670. if (res.code == 200) {
  671. if (res.data.isAudit != 1) {
  672. this.$message.error("当前直播间未经审核");
  673. this.loading = false
  674. return
  675. }
  676. this.isAudit = true
  677. this.status = res.data.status
  678. this.videoParam.startTime = new Date(res.data.startTime).getTime()
  679. if(res.data.status == 4){
  680. this.videoParam.liveType = 3
  681. this.videoParam.videoUrl = res.data.videoUrl;
  682. }else {
  683. if (res.data.status != 2) {
  684. this.$message.error("当前直播间未直播");
  685. this.loading = false
  686. return
  687. }
  688. if (res.data.liveType == 1) {
  689. this.videoParam.livingUrl = res.data.flvHlsUrl
  690. this.videoParam.livingUrl = this.livingUrl.replace("flv","m3u8")
  691. // this.$nextTick(() => {
  692. // this.initPlayer()
  693. // })
  694. // this.processInterval = setInterval(this.updateLiveProgress, 1000);
  695. } else {
  696. this.videoParam.liveType = 2
  697. this.videoParam.videoUrl = res.data.videoUrl;
  698. // this.$nextTick(() => {
  699. // this.initVideoPlayer(res.data.startTime)
  700. // })
  701. }
  702. }
  703. this.$nextTick(() => {
  704. this.globalVisible = res.data.globalVisible
  705. this.$refs.livePlayer.initPlayer()
  706. })
  707. this.loading = false
  708. } else {
  709. this.$message.error(res.msg)
  710. this.loading = false
  711. }
  712. this.liveInfo = res.data
  713. })
  714. },
  715. connectWebSocket() {
  716. this.$store.dispatch('initLiveWs', {
  717. liveWsUrl: this.liveWsUrl,
  718. liveId: this.liveId,
  719. userId: this.userId
  720. })
  721. this.socket = this.$store.state.liveWs[this.liveId]
  722. this.socket.onmessage = (event) => this.handleWsMessage(event)
  723. },
  724. changeUserState(u) {
  725. const displayList = this[`${this.currentTab}DisplayList`];
  726. // 修改状态
  727. changeUserStatus({liveId: u.liveId, userId: u.userId}).then(response => {
  728. let { code } = response;
  729. if (200 === code) {
  730. u.msgStatus = u.msgStatus === 0 ? 1 : 0
  731. // 同步更新消息列表中相同用户的状态
  732. this.msgList.forEach(msg => {
  733. if (msg.userId === u.userId) {
  734. msg.msgStatus = u.msgStatus;
  735. }
  736. });
  737. displayList.forEach(user => {
  738. if (user.userId === u.userId) {
  739. user.msgStatus = u.msgStatus;
  740. }
  741. });
  742. // 4. 关键:重新筛选所有Tab的显示列表,确保状态同步
  743. this.refreshUserDisplayLists(u);
  744. let msg = u.msgStatus === 0 ? "已解禁" : "已禁言"
  745. this.msgSuccess(msg);
  746. return
  747. }
  748. this.msgError("操作失败");
  749. })
  750. },
  751. refreshUserDisplayLists(user) {
  752. const { userId, msgStatus: newStatus, online } = user;
  753. const oldStatus = newStatus === 1 ? 0 : 1; // 操作前的状态(反向)
  754. // 1. 禁言操作(newStatus=1):从原在线/离线列表移除,加入禁言列表
  755. if (newStatus === 1) {
  756. // 从在线/离线列表中移除该用户(根据当前在线状态)
  757. if (online === 0) {
  758. this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== userId);
  759. this.userTotal.online = Math.max(0, this.userTotal.online - 1);
  760. } else {
  761. this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== userId);
  762. this.userTotal.offline = Math.max(0, this.userTotal.offline - 1);
  763. }
  764. this.userTotal.silenced = this.userTotal.silenced + 1;
  765. // 添加到禁言列表(去重+限制长度)
  766. const silencedList = this.silencedDisplayList.filter(u => u.userId !== userId);
  767. silencedList.push(user);
  768. this.silencedDisplayList = silencedList.slice(-40);
  769. }
  770. // 2. 解禁操作(newStatus=0):从禁言列表移除,回到原在线/离线列表
  771. else {
  772. // 从禁言列表移除
  773. this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== userId);
  774. this.userTotal.silenced = Math.max(0, this.userTotal.silenced - 1);
  775. // 回到对应的在线/离线列表(根据当前在线状态)
  776. if (online === 0) {
  777. // 加入在线列表(去重+限制长度)
  778. const onlineList = this.onlineDisplayList.filter(u => u.userId !== userId);
  779. onlineList.push(user);
  780. this.onlineDisplayList = onlineList.slice(-40);
  781. this.userTotal.online = this.userTotal.online + 1;
  782. } else {
  783. // 加入离线列表(去重+限制长度)
  784. const offlineList = this.offlineDisplayList.filter(u => u.userId !== userId);
  785. offlineList.push(user);
  786. this.offlineDisplayList = offlineList.slice(-40);
  787. this.userTotal.offline = this.userTotal.offline + 1;
  788. }
  789. }
  790. },
  791. blockUser(u){
  792. this.$confirm('是否确认封禁用户账号为:"' + u.nickName + '-' + u.userId + '"?', "警告", {
  793. confirmButtonText: "确定",
  794. cancelButtonText: "取消",
  795. type: "warning"
  796. }).then(function() {
  797. return blockUser(u.userId);
  798. }).then(() => {
  799. if(u.msgStatus === 1){
  800. this.userTotal.silenced -= 1
  801. this.silencedDisplayList = this.silencedDisplayList.filter(user => user.userId !== u.userId)
  802. } else if( u.online === 0){
  803. this.userTotal.online -= 1
  804. this.onlineDisplayList = this.onlineDisplayList.filter(user => user.userId !== u.userId)
  805. } else {
  806. this.userTotal.offline -= 1
  807. this.offlineDisplayList = this.offlineDisplayList.filter(user => user.userId !== u.userId)
  808. }
  809. this.userTotal.al -= 1
  810. this.alDisplayList = this.alDisplayList.filter(user => user.userId !== u.userId)
  811. let msg = {
  812. msg: "",
  813. liveId: this.liveId,
  814. userId: u.userId,
  815. userType: 0,
  816. cmd: 'blockUser',
  817. avatar: this.$store.state.user.user.avatar,
  818. nickName: this.$store.state.user.user.nickName
  819. }
  820. this.socket.send(JSON.stringify(msg))
  821. this.msgSuccess("封禁成功");
  822. }).catch(() => {});
  823. },
  824. searchUsers(){
  825. this.resetUserParams()
  826. this.loadNextPage(this.currentTab)
  827. },
  828. handleUserClick(tab){
  829. const tabName = tab.name;
  830. this.currentTab = tabName;
  831. const params = this.pageParams[tabName];
  832. const displayList = this[`${tabName}DisplayList`];
  833. // 首次切换到该Tab或列表为空时初始化
  834. if (displayList.length < 20) {
  835. // 重置分页参数
  836. params.currentPage = 1;
  837. params.pageSize = 20;
  838. params.prevPage = 0;
  839. params.totalLoaded = 0;
  840. params.hasMore = true;
  841. params.hasPrev = false;
  842. // 加载第一页
  843. this.loadNextPage(tabName);
  844. } else {
  845. // 非首次切换,恢复滚动位置
  846. this.$nextTick(() => {
  847. const scrollEl = this.getScrollElement(tabName);
  848. if (scrollEl) {
  849. scrollEl.scrollTop = this.tabScrollPositions[tabName] || 0;
  850. }
  851. });
  852. }
  853. },
  854. loadNextPage(tabName) {
  855. const params = this.pageParams[tabName];
  856. const displayList = this[`${tabName}DisplayList`];
  857. // 若没有更多数据或正在加载,直接返回
  858. if (!params.hasMore || this.scrLoading[tabName].next) {
  859. return;
  860. }
  861. this.scrLoading[tabName].next = true;
  862. const queryParams = {
  863. liveId: this.liveId,
  864. pageNum: params.currentPage,
  865. pageSize: 20,
  866. online: tabName === 'online' ? 0 : 1,
  867. msgStatus: tabName === 'silenced' ? 1 : 0,
  868. all: tabName === 'al' ? 1 : 0,
  869. userName: this.searchKeyword
  870. };
  871. // 调用接口加载对应状态的分页数据(需后端支持按状态筛选)
  872. dashBoardWatchUserList(queryParams).then(response => {
  873. this.scrLoading[tabName].next = false;
  874. if (response.code !== 200) return;
  875. const { rows, total } = response;
  876. params.total = total; // 记录总数据量
  877. // 过滤重复数据(基于userId)
  878. const newRows = rows.filter(row =>
  879. !displayList.some(u => u.userId === row.userId)
  880. );
  881. displayList.push(...newRows)
  882. // 添加新数据并限制最大长度(避免内存占用过大)
  883. if (displayList.length >= 40) { // 最大保留100条
  884. this[`${tabName}DisplayList`] = displayList.slice(-40);
  885. // 记录滚动位置(用于加载后校准)
  886. const scrollEl = this.getScrollElement(tabName);
  887. // 校准滚动位置(保持视觉连续性)
  888. this.$nextTick(() => {
  889. if (scrollEl) {
  890. scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
  891. }
  892. });
  893. }
  894. // 更新分页状态
  895. params.hasMore = params.currentPage * params.pageSize < total;
  896. params.currentPage += 1;
  897. params.hasPrev = params.currentPage > 2; // 当前页>2时一定有上一页
  898. params.prevPage = params.currentPage - 2;
  899. }).catch(() => {
  900. this.scrLoading[tabName].next = false;
  901. });
  902. },
  903. // 新增:加载上一页(向上滚动时)
  904. loadPrevPage(tabName) {
  905. const params = this.pageParams[tabName];
  906. const displayList = this[`${tabName}DisplayList`];
  907. // 边界校验:无上一页/正在加载/当前页<=1
  908. console.log(`加载 ${tabName} 上一页`);
  909. console.log(!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1)
  910. if (!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1) {
  911. return;
  912. }
  913. this.scrLoading[tabName].prev = true;
  914. const targetPage = params.prevPage > 0 ? params.prevPage : params.currentPage - 2;
  915. const queryParams = {
  916. liveId: this.liveId,
  917. pageNum: targetPage,
  918. pageSize: 20,
  919. online: tabName === 'online' ? 0 : 1,
  920. msgStatus: tabName === 'silenced' ? 1 : 0,
  921. all: tabName === 'al' ? 1 : 0,
  922. userName: this.searchKeyword
  923. };
  924. dashBoardWatchUserList(queryParams).then(response => {
  925. this.scrLoading[tabName].prev = false;
  926. if (response.code !== 200) return;
  927. const { rows } = response;
  928. if (rows.length === 0) {
  929. params.hasPrev = false;
  930. return;
  931. }
  932. // 记录滚动位置(用于加载后校准)
  933. const scrollEl = this.getScrollElement(tabName);
  934. const scrollTop = scrollEl?.scrollTop || 0;
  935. const itemHeight = 80; // 预估行高(根据实际样式调整)
  936. const newItemsHeight = rows.length * itemHeight;
  937. // 过滤重复数据并添加到列表头部
  938. const newRows = rows.filter(row => !displayList.some(u => u.userId === row.userId));
  939. this[`${tabName}DisplayList`] = [...newRows, ...displayList];
  940. params.totalLoaded += newRows.length;
  941. // 限制最大长度
  942. if (this[`${tabName}DisplayList`].length > 40) {
  943. this[`${tabName}DisplayList`] = this[`${tabName}DisplayList`].slice(0, 40);
  944. }
  945. // 更新分页状态
  946. params.prevPage = targetPage - 1;
  947. params.hasPrev = targetPage > 1; // 上一页页码>1时还有更多上一页
  948. params.currentPage = params.currentPage - 1;
  949. if(params.currentPage * 20 < params.total) params.hasMore = true;
  950. // 校准滚动位置(保持视觉连续性)
  951. this.$nextTick(() => {
  952. if (scrollEl) {
  953. scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
  954. }
  955. });
  956. }).catch(() => {
  957. this.scrLoading[tabName].prev = false;
  958. });
  959. },
  960. getList() {
  961. this.resetUserParams()
  962. this.resetMsgParams()
  963. // this.loadUserList()
  964. this.loadUserTotals(); // 先加载总人数
  965. // this.handleClick('online')
  966. // this.handleClick({name:'online'})
  967. this.loadMsgList()
  968. this.loadLiveTask()
  969. },
  970. formatDate(value) {
  971. // 检查值是否存在且为日期类型(或可转换为日期)
  972. if (!value) return '';
  973. let date;
  974. // 处理字符串类型的日期
  975. if (typeof value === 'string') {
  976. date = new Date(value);
  977. }
  978. // 处理Date对象
  979. else if (value instanceof Date) {
  980. date = value;
  981. }
  982. // 无效类型直接返回原值
  983. else {
  984. return value;
  985. }
  986. // 检查是否为有效日期
  987. if (isNaN(date.getTime())) {
  988. return value;
  989. }
  990. // 格式化年月日时分秒(补零处理)
  991. const year = date.getFullYear();
  992. const month = String(date.getMonth() + 1).padStart(2, '0');
  993. const day = String(date.getDate()).padStart(2, '0');
  994. const hours = String(date.getHours()).padStart(2, '0');
  995. const minutes = String(date.getMinutes()).padStart(2, '0');
  996. const seconds = String(date.getSeconds()).padStart(2, '0');
  997. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  998. },
  999. loadLiveTask(){
  1000. if(!this.taskParams.hasMore) return
  1001. const queryParams = {
  1002. liveId: this.liveId,
  1003. pageSize: 10,
  1004. pageNum: 1
  1005. }
  1006. consoleList(queryParams).then(res => {
  1007. let {code, rows,total} = res;
  1008. if (code === 200) {
  1009. this.taskParams.total = total
  1010. this.timelineItems = rows
  1011. if(rows.length < this.taskParams.pageSize){
  1012. this.taskParams.hasMore = false
  1013. }
  1014. this.startTaskTimer()
  1015. } else {
  1016. this.stopTaskTimer()
  1017. }
  1018. })
  1019. },
  1020. loadMsgList(){
  1021. // 直播间消息
  1022. listLiveSingleMsg({
  1023. liveId:this.liveId,
  1024. pageNum: this.msgParams.pageNum,
  1025. pageSize: this.msgParams.pageSize
  1026. }).then(response => {
  1027. let {code, rows,total} = response;
  1028. if (code === 200) {
  1029. let totalPage = (total % this.msgParams.pageSize == 0) ? Math.floor(total / this.msgParams.pageSize) : Math.floor(total / this.msgParams.pageSize + 1);
  1030. rows.forEach(row => {
  1031. if (!this.msgList.some(m => m.msgId === row.msgId)) {
  1032. let user = this.alDisplayList.find(u => u.userId === row.userId)
  1033. if (user) {
  1034. row.msgStatus = user.msgStatus
  1035. } else {
  1036. row.msgStatus = 0
  1037. }
  1038. this.msgList.push(row)
  1039. // 移动到底部
  1040. this.$nextTick(() => {
  1041. setTimeout(() => {
  1042. this.$refs.manageRightRef.wrap.scrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
  1043. }, 200)
  1044. })
  1045. }
  1046. })
  1047. this.msgList.reverse()
  1048. // 同步更新消息列表中相同用户的状态
  1049. this.alDisplayList.forEach(u => {
  1050. this.msgList.filter(m => m.userId === u.userId).forEach(m => m.msgStatus = u.msgStatus)
  1051. })
  1052. }
  1053. })
  1054. // 添加滚动监听
  1055. this.$nextTick(() => {
  1056. this.$refs.manageRightRef.wrap.addEventListener("scroll", this.manageRightScroll)
  1057. })
  1058. },
  1059. loadUserTotals() {
  1060. if (!this.liveId) return;
  1061. // 假设后端提供一个接口返回总人数(如果没有,可通过首次加载全量数据后统计)
  1062. getLiveUserTotals({ liveId: this.liveId }).then(res => {
  1063. if (res.code === 200) {
  1064. this.userTotal = res.data; // { online, offline, silenced }
  1065. }
  1066. });
  1067. },
  1068. toggleBlack(user) {
  1069. user.isBlack = !user.isBlack;
  1070. },
  1071. toggleMute(user) {
  1072. user.isMuted = !user.isMuted;
  1073. },
  1074. toggleVisible(msg) {
  1075. msg.isVisible = !msg.isVisible;
  1076. },
  1077. deleteMessage(msg) {
  1078. const index = this.messages.indexOf(msg);
  1079. if (index > -1) {
  1080. this.messages.splice(index, 1);
  1081. }
  1082. },
  1083. addTimelineItem() {
  1084. this.timelineItems.push({ time: '00:00', action: '新动作' });
  1085. },
  1086. removeTimelineItem(item) {
  1087. const index = this.timelineItems.indexOf(item);
  1088. if (index > -1) {
  1089. this.timelineItems.splice(index, 1);
  1090. }
  1091. },
  1092. resetUserParams() {
  1093. // 重置各Tab的显示列表和分页参数
  1094. this.alDisplayList = [];
  1095. this.onlineDisplayList = []; // 在线用户显示列表
  1096. this.offlineDisplayList = []; // 离线用户显示列表
  1097. this.silencedDisplayList = []; // 禁言用户显示列表
  1098. this.pageParams= {
  1099. al: {
  1100. currentPage: 1,
  1101. pageSize: 20,
  1102. prevPage: 0,
  1103. totalLoaded: 0,
  1104. total: 0,
  1105. hasMore: true,
  1106. hasPrev: false
  1107. },
  1108. online: {
  1109. currentPage: 1, // 当前页(下一页加载用)
  1110. pageSize: 20, // 当前页(下一页加载用)
  1111. prevPage: 0, // 上一页页码(上一页加载用)
  1112. totalLoaded: 0, // 已加载总条数
  1113. total: 0, // 总数据量
  1114. hasMore: true, // 是否有下一页
  1115. hasPrev: false // 是否有上一页
  1116. },
  1117. offline: {
  1118. currentPage: 1,
  1119. pageSize: 20,
  1120. prevPage: 0,
  1121. totalLoaded: 0,
  1122. total: 0,
  1123. hasMore: true,
  1124. hasPrev: false
  1125. },
  1126. silenced: {
  1127. currentPage: 1,
  1128. pageSize: 20,
  1129. prevPage: 0,
  1130. totalLoaded: 0,
  1131. total: 0,
  1132. hasMore: true,
  1133. hasPrev: false
  1134. }
  1135. },
  1136. this.scrLoading = {
  1137. al: { next: false, prev: false },
  1138. online: { next: false, prev: false },
  1139. offline: { next: false, prev: false },
  1140. silenced: { next: false, prev: false }
  1141. }
  1142. },
  1143. resetMsgParams() {
  1144. // 消息参数保留
  1145. this.msgList = [];
  1146. this.msgParams = {
  1147. pageNum: 1,
  1148. pageSize: 30,
  1149. liveId: this.liveId
  1150. };
  1151. this.taskParams = {
  1152. currentPage: 1,
  1153. pageSize: 20,
  1154. prevPage: 0,
  1155. totalLoaded: 0,
  1156. total: 0,
  1157. hasMore: true,
  1158. hasPrev: false
  1159. }
  1160. },
  1161. getScrollElement(tabName) {
  1162. const scrollRefs = {
  1163. al: this.$refs.manageLeftRef_al,
  1164. online: this.$refs.manageLeftRef_online,
  1165. offline: this.$refs.manageLeftRef_offline,
  1166. silenced: this.$refs.manageLeftRef_silenced
  1167. };
  1168. return scrollRefs[tabName]?.wrap;
  1169. },
  1170. // 初始化滚动监听(在mounted中调用)
  1171. initScrollListeners() {
  1172. // 为每个Tab的滚动容器添加监听
  1173. this.$nextTick(() => {
  1174. const scrollRefs = {
  1175. al: this.$refs.manageLeftRef_al,
  1176. online: this.$refs.manageLeftRef_online,
  1177. offline: this.$refs.manageLeftRef_offline,
  1178. silenced: this.$refs.manageLeftRef_silenced
  1179. };
  1180. Object.keys(scrollRefs).forEach(tabName => {
  1181. const scrollEl = scrollRefs[tabName]?.wrap;
  1182. if (scrollEl) {
  1183. scrollEl.addEventListener('scroll', () =>
  1184. this.handleTabScroll(tabName, scrollEl)
  1185. );
  1186. }
  1187. });
  1188. });
  1189. },
  1190. // 处理Tab滚动事件(判断是否触底)
  1191. handleTabScroll(tabName, scrollEl) {
  1192. const { scrollTop, scrollHeight, clientHeight } = scrollEl;
  1193. const bottomThreshold = 50; // 距离底部100px触发下一页
  1194. const topThreshold = 50; // 距离顶部100px触发上一页
  1195. // 加载下一页(滚动到底部附近)
  1196. if (scrollHeight - scrollTop - clientHeight < bottomThreshold) {
  1197. this.loadNextPage(tabName);
  1198. }
  1199. // 加载上一页(滚动到顶部附近)
  1200. if (scrollTop < topThreshold) {
  1201. this.loadPrevPage(tabName);
  1202. }
  1203. },
  1204. // 恢复聊天滚动位置
  1205. restoreChatScrollPosition() {
  1206. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1207. this.$refs.manageRightRef.wrap.scrollTop = this.chatScrollTop;
  1208. }
  1209. },
  1210. // 保存聊天滚动位置
  1211. saveChatScrollPosition() {
  1212. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1213. this.chatScrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight;
  1214. }
  1215. },
  1216. /**
  1217. * 停止任务检测定时器
  1218. */
  1219. stopTaskTimer() {
  1220. if (this.taskTimer) {
  1221. clearInterval(this.taskTimer);
  1222. this.taskTimer = null;
  1223. }
  1224. },
  1225. /**
  1226. * 启动任务检测定时器
  1227. */
  1228. startTaskTimer() {
  1229. // 先清除已有定时器,避免重复
  1230. if (this.taskTimer) {
  1231. clearInterval(this.taskTimer);
  1232. }
  1233. // 立即执行一次检查
  1234. this.checkTaskExpiration();
  1235. // 启动定时器,定期检查
  1236. this.taskTimer = setInterval(() => {
  1237. this.checkTaskExpiration();
  1238. }, this.checkInterval);
  1239. },
  1240. /**
  1241. * 检查时间轴第一条任务是否过期
  1242. */
  1243. checkTaskExpiration() {
  1244. // 如果没有任务,直接返回
  1245. if (!this.timelineItems || this.timelineItems.length === 0) {
  1246. this.stopTaskTimer()
  1247. return;
  1248. };
  1249. // 获取第一条任务的时间
  1250. const firstTask = this.timelineItems[0];
  1251. const taskTime = new Date(firstTask.absValue).getTime();
  1252. const currentTime = new Date().getTime();
  1253. // 如果任务时间已过当前时间(过期),重新加载任务列表
  1254. if (taskTime < currentTime) {
  1255. this.timelineItems.shift()
  1256. this.loadLiveTask(); // 重新加载任务列表
  1257. }
  1258. },
  1259. },
  1260. beforeDestroy() {
  1261. if (this.autoMsgTimer != null) {
  1262. clearInterval(this.autoMsgTimer);
  1263. }
  1264. },
  1265. // 使用 deactivated 和 activated 钩子替代 beforeDestroy 和 destroyed
  1266. deactivated() {
  1267. this.saveChatScrollPosition();
  1268. },
  1269. activated() {
  1270. this.$nextTick(() => {
  1271. this.restoreChatScrollPosition();
  1272. });
  1273. // todo yhq
  1274. // this.$nextTick(() => {
  1275. // const video = this.$refs.videoPlayer;
  1276. // if (video != null) {
  1277. // this.initVideoPlayer(this.liveInfo.startTime)
  1278. // }
  1279. // })
  1280. },
  1281. };
  1282. </script>
  1283. <style scoped>
  1284. .console {
  1285. display: flex;
  1286. height: 100vh;
  1287. }
  1288. .left-panel, .middle-panel, .right-panel {
  1289. padding: 20px;
  1290. box-sizing: border-box;
  1291. }
  1292. .left-panel {
  1293. width: 30%;
  1294. background: #f8fafc;
  1295. border-right: 1px solid #e2e8f0;
  1296. }
  1297. .middle-panel {
  1298. width: 40%;
  1299. background: #f8fafc;
  1300. border-right: 1px solid #e2e8f0;
  1301. }
  1302. .right-panel {
  1303. width: 30%;
  1304. background: #f8fafc;
  1305. }
  1306. .search {
  1307. margin: 10px 0;
  1308. }
  1309. .search input {
  1310. width: 70%;
  1311. padding: 8px;
  1312. border: 1px solid #cbd5e1;
  1313. border-radius: 4px;
  1314. }
  1315. .search button {
  1316. padding: 8px 15px;
  1317. background: #3b82f6;
  1318. color: #fff;
  1319. border: none;
  1320. border-radius: 4px;
  1321. cursor: pointer;
  1322. }
  1323. .tabs {
  1324. display: flex;
  1325. margin: 10px 0;
  1326. }
  1327. .tabs button {
  1328. padding: 8px 15px;
  1329. border: 1px solid #e2e8f0;
  1330. background: #fff;
  1331. cursor: pointer;
  1332. }
  1333. .tabs button.active {
  1334. background: #3b82f6;
  1335. color: #fff;
  1336. border-color: #3b82f6;
  1337. }
  1338. .user-list {
  1339. max-height: 600px;
  1340. overflow-y: auto;
  1341. }
  1342. .user-item {
  1343. display: flex;
  1344. align-items: center;
  1345. padding: 10px;
  1346. border-bottom: 1px solid #e2e8f0;
  1347. }
  1348. .user-item img {
  1349. width: 40px;
  1350. height: 40px;
  1351. border-radius: 50%;
  1352. margin-right: 10px;
  1353. }
  1354. .user-info {
  1355. flex: 1;
  1356. }
  1357. .user-name {
  1358. font-weight: bold;
  1359. }
  1360. .user-status {
  1361. font-size: 12px;
  1362. color: #64748b;
  1363. }
  1364. .online {
  1365. color: #10b981;
  1366. }
  1367. .offline {
  1368. color: #94a3b8;
  1369. }
  1370. .user-actions {
  1371. display: flex;
  1372. }
  1373. .user-actions button {
  1374. padding: 5px 10px;
  1375. margin-left: 5px;
  1376. border: none;
  1377. border-radius: 4px;
  1378. cursor: pointer;
  1379. }
  1380. .block {
  1381. background: #ef4444;
  1382. color: #fff;
  1383. }
  1384. .unblock {
  1385. background: #10b981;
  1386. color: #fff;
  1387. }
  1388. .mute {
  1389. background: #f59e0b;
  1390. color: #fff;
  1391. }
  1392. .unmute {
  1393. background: #3b82f6;
  1394. color: #fff;
  1395. }
  1396. .system-messages, .discussion-messages {
  1397. margin: 20px 0;
  1398. background: #fff;
  1399. padding: 15px;
  1400. border-radius: 8px;
  1401. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  1402. }
  1403. .system-messages textarea {
  1404. width: 100%;
  1405. height: 100px;
  1406. border: 1px solid #e2e8f0;
  1407. border-radius: 4px;
  1408. padding: 8px;
  1409. box-sizing: border-box;
  1410. }
  1411. .message-actions {
  1412. margin-top: 10px;
  1413. }
  1414. .message-actions button {
  1415. padding: 5px 10px;
  1416. margin-right: 5px;
  1417. background: #3b82f6;
  1418. color: #fff;
  1419. border: none;
  1420. border-radius: 4px;
  1421. cursor: pointer;
  1422. }
  1423. .message-list {
  1424. max-height: 300px;
  1425. overflow-y: auto;
  1426. margin-top: 10px;
  1427. }
  1428. .message-item {
  1429. display: flex;
  1430. margin-bottom: 10px;
  1431. padding-bottom: 10px;
  1432. border-bottom: 1px solid #e2e8f0;
  1433. }
  1434. .message-avatar img {
  1435. width: 30px;
  1436. height: 30px;
  1437. border-radius: 50%;
  1438. margin-right: 10px;
  1439. }
  1440. .message-content {
  1441. flex: 1;
  1442. }
  1443. .message-user {
  1444. font-weight: bold;
  1445. }
  1446. .message-text {
  1447. font-size: 14px;
  1448. color: #64748b;
  1449. }
  1450. .message-actions button {
  1451. padding: 3px 8px;
  1452. font-size: 12px;
  1453. background: #3b82f6;
  1454. color: #fff;
  1455. border: none;
  1456. border-radius: 4px;
  1457. cursor: pointer;
  1458. }
  1459. .live-player, .automation, .watermark {
  1460. margin: 20px 0;
  1461. background: #fff;
  1462. padding: 15px;
  1463. border-radius: 8px;
  1464. box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  1465. }
  1466. .timeline-items {
  1467. margin: 10px 0;
  1468. }
  1469. .timeline-item {
  1470. display: flex;
  1471. justify-content: space-between;
  1472. align-items: center;
  1473. padding: 8px 0;
  1474. border-bottom: 1px solid #e2e8f0;
  1475. }
  1476. .delete {
  1477. background: #ef4444;
  1478. color: #fff;
  1479. border: none;
  1480. border-radius: 4px;
  1481. padding: 3px 8px;
  1482. cursor: pointer;
  1483. }
  1484. .add {
  1485. background: #10b981;
  1486. color: #fff;
  1487. border: none;
  1488. border-radius: 4px;
  1489. padding: 8px 15px;
  1490. cursor: pointer;
  1491. }
  1492. .watermark-settings textarea {
  1493. width: 100%;
  1494. height: 100px;
  1495. border: 1px solid #e2e8f0;
  1496. border-radius: 4px;
  1497. padding: 8px;
  1498. box-sizing: border-box;
  1499. }
  1500. .watermark-options {
  1501. margin-top: 10px;
  1502. }
  1503. .watermark-options label {
  1504. display: block;
  1505. margin-bottom: 5px;
  1506. }
  1507. /* 隐藏 el-scrollbar 的横向滚动条 */
  1508. .el-scrollbar__wrap {
  1509. overflow-x: hidden !important;
  1510. }
  1511. .custom-scrollbar .el-scrollbar__wrap {
  1512. overflow-x: hidden !important;
  1513. }
  1514. .scrollbar-demo-item{
  1515. display: flex;
  1516. align-items: center;
  1517. justify-content: center;
  1518. height: 50px;
  1519. margin: 10px;
  1520. text-align: center;
  1521. border-radius: 4px;
  1522. }
  1523. </style>