| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743 |
- <template>
- <div class="console">
- <div class="left-panel">
- <h2>学员列表</h2>
- <div class="search">
- <input type="text" placeholder="搜索用户昵称" v-model="searchKeyword">
- <button @click="searchUsers()">搜索</button>
- </div>
- <el-tabs class="live-console-tab-right" v-model="tabLeft.activeName" @tab-click="handleUserClick" :stretch="true">
- <el-tab-pane :label="alLabel" name="al">
- <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_al" style="height: 800px; width: 100%;">
- <el-row class='scrollbar-demo-item' v-for="u in alDisplayList" :key="u.userId">
- <el-col :span="20">
- <el-row type="flex" align="middle">
- <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
- <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
- <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
- </el-row>
- </el-col>
- <el-col :span="4" >
- <el-popover
- width="100"
- trigger="click">
- <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
- <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
- <i class="el-icon-more" slot="reference"></i>
- </el-popover>
- </el-col>
- </el-row>
- </el-scrollbar>
- </el-tab-pane>
- <el-tab-pane :label="onlineLabel" name="online">
- <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_online" style="height: 800px; width: 100%;">
- <el-row class='scrollbar-demo-item' v-for="u in onlineDisplayList" :key="u.userId">
- <el-col :span="20">
- <el-row type="flex" align="middle">
- <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
- <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
- <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
- </el-row>
- </el-col>
- <el-col :span="4" >
- <el-popover
- width="100"
- trigger="click">
- <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
- <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
- <i class="el-icon-more" slot="reference"></i>
- </el-popover>
- </el-col>
- </el-row>
- </el-scrollbar>
- </el-tab-pane>
- <el-tab-pane :label="offlineLabel" name="offline">
- <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_offline" style="height: 800px; width: 100%;">
- <el-row class='scrollbar-demo-item' v-for="u in offlineDisplayList" :key="u.userId">
- <el-col :span="20">
- <el-row type="flex" align="middle">
- <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
- <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
- <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
- </el-row>
- </el-col>
- <el-col :span="4" >
- <el-popover
- width="100"
- trigger="click">
- <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
- <i class="el-icon-more" slot="reference"></i>
- <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
- </el-popover>
- </el-col>
- </el-row>
- </el-scrollbar>
- </el-tab-pane>
- <el-tab-pane :label="silencedUserLabel" name="silenced">
- <el-scrollbar class="custom-scrollbar" ref="manageLeftRef_silenced" style="height: 800px; width: 100%;">
- <el-row class='scrollbar-demo-item' v-for="u in silencedDisplayList" :key="u.userId">
- <el-col :span="20">
- <el-row type="flex" align="middle">
- <el-col :span="4" style="padding-left: 10px;"><el-avatar :src="u.avatar"></el-avatar></el-col>
- <el-col :span="19" :offset="1">{{ u.nickName }}</el-col>
- <el-col :span="19" :offset="1">{{ u.userId }}</el-col>
- </el-row>
- </el-col>
- <el-col :span="4" >
- <el-popover
- width="100"
- trigger="click">
- <a style="cursor: pointer;color: #ff0000;" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
- <a style="cursor: pointer;color: #ff0000;margin-left:10px" @click="blockUser(u)">拉黑</a>
- <i class="el-icon-more" slot="reference"></i>
- </el-popover>
- </el-col>
- </el-row>
- </el-scrollbar>
- </el-tab-pane>
- </el-tabs>
- </div>
- <div class="middle-panel">
- <h2>消息管理</h2>
- <div class="discussion-messages">
- <h3>讨论区消息</h3>
- <div class="message-settings">
- <label>
- <input type="checkbox" v-model="globalVisible" @change="globalVisibleChange">
- 全局用户自见
- </label>
- </div>
- <div class="message-container" @click="handleMessageBoxClick">
- <el-scrollbar class="custom-scrollbar" style="height: 500px; width: 100%;" ref="manageRightRef">
- <el-row v-for="m in msgList" :key="m.msgId">
- <el-row v-if="m.userId !== userId" style="margin-top: 5px" type="flex" align="top" >
- <el-col :span="3" style="margin-left: 10px"><el-avatar :src="m.avatar"/></el-col>
- <el-col :span="15">
- <el-row style="margin-left: 10px">
- <el-col><div style="font-size: 12px; color: #999; margin-bottom: 3px;">{{ m.nickName }}</div></el-col>
- <el-col :span="24" style="max-width: 200px;">
- <div style="white-space: normal; word-wrap: break-word;background-color: #f0f2f5; padding: 8px; border-radius: 5px;font-size: 14px;width: 100%;">
- {{ m.msg }}
- </div>
- </el-col>
- <el-col>
- <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click.stop="changeUserState(m)">{{ m.msgStatus === 1 ? '解禁' : '禁言' }}</a>
- <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click.stop="blockUser(m)">拉黑</a>
- <a v-if="m.singleVisible === 1" style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click.stop="singleVisible(m)">解除用户自见</a>
- <a v-else style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click.stop="singleVisible(m)">用户自见</a>
- <a style="cursor: pointer;color: #ff0000;padding: 8px 8px 0 0;font-size: 12px;" @click.stop="deleteMsg(m)">删除</a>
- </el-col>
- </el-row>
- </el-col>
- </el-row>
- <el-row v-if="m.userId === userId" style="padding: 8px 0" type="flex" align="top" justify="end">
- <div style="display: flex;justify-content: flex-end">
- <div style="display: flex;justify-content: flex-end;flex-direction: column;max-width: 200px;align-items: flex-end">
- <div style="font-size: 12px; color: #999; margin-bottom: 3px;">{{ m.nickName }}</div>
- <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>
- </div>
- <el-avatar :src="m.avatar" style="margin-left: 10px; margin-right: 10px;"/>
- </div>
- </el-row>
- </el-row>
- <!-- 底部留白 -->
- <div style="height: 20px;"></div>
- </el-scrollbar>
- <!-- 加载最新消息按钮 -->
- <el-button
- v-if="showLoadLatestBtn"
- class="load-latest-btn"
- type="primary"
- size="small"
- @click.stop="loadLatestMessages"
- icon="el-icon-refresh">
- 加载最新消息
- </el-button>
- </div>
- <!-- <div class="message-list">-->
- <!-- <div class="message-item" v-for="msg in msgList" :key="msg.id">-->
- <!-- <div class="message-avatar">-->
- <!-- <img :src="msg.avatar" alt="用户头像">-->
- <!-- </div>-->
- <!-- <div class="message-content">-->
- <!-- <div class="message-user">{{ msg.user }}</div>-->
- <!-- <div class="message-text">{{ msg.text }}</div>-->
- <!-- </div>-->
- <!-- <div class="message-actions">-->
- <!--<!– <button @click="toggleVisible(msg)">–>-->
- <!--<!– {{ msg.isVisible ? '仅用户自见' : '全局可见' }}–>-->
- <!--<!– </button>–>-->
- <!-- <button @click="deleteMessage(msg)">删除</button>-->
- <!-- </div>-->
- <!-- </div>-->
- <!-- </div>-->
- </div>
- <div class="system-messages">
- <h3>系统消息</h3>
- <textarea placeholder="输入系统消息" v-model="newMsg"></textarea>
- <div class="message-actions">
- <button @click="sendMessage">发送消息</button>
- <button @click="sendPopMessage">弹窗消息</button>
- <button @click="showTopMsgDialog">顶部消息</button>
- </div>
- </div>
- </div>
- <div class="right-panel">
- <h2>运营工具</h2>
- <div class="live-player">
- <h3>直播观看</h3>
- <LivePlayer ref="livePlayer" :videoParam="videoParam" />
- </div>
- <div class="automation">
- <h3>运营自动化</h3>
- <div class="timeline">
- <h4>时间轴设置</h4>
- <div class="timeline-items">
- <div class="timeline-item" v-for="item in timelineItems.slice(0,2)" :key="item.time">
- <div class="time">{{ formatDate(item.absValue) }}</div>
- <div class="action">{{ item.taskName }}</div>
- <button class="delete" @click="removeTimelineItem(item)">删除</button>
- </div>
- </div>
- <!-- <button class="add" @click="addTimelineItem">添加时间节点</button>-->
- </div>
- </div>
- <div class="watermark">
- <h3>直播氛围自动化</h3>
- <div class="watermark-settings">
- <textarea :disabled="autoWatermark" v-model="watermarkTemplate" placeholder="水军弹幕内容模板,每行一条"></textarea>
- <div class="watermark-options">
- <label>
- 发送间隔:
- <input type="number" :disabled="autoWatermark" v-model.number="interval" min="1">
- 秒
- </label>
- <label>
- <input type="checkbox" v-model="autoWatermark" @change="changeAutoWatermark">
- 启用水军自动化
- </label>
- </div>
- </div>
- </div>
- </div>
- <!-- 顶部消息对话框 -->
- <el-dialog title="发送顶部消息" :visible.sync="topMsgDialogVisible" width="500px">
- <el-form :model="topMsgForm" label-width="100px">
- <el-form-item label="消息内容">
- <el-input
- type="textarea"
- v-model="topMsgForm.msg"
- placeholder="请输入消息内容"
- :rows="3"
- ></el-input>
- </el-form-item>
- <el-form-item label="显示时长">
- <el-input-number
- v-model="topMsgForm.duration"
- :min="1"
- :max="60"
- placeholder="请输入显示时长(分钟)"
- ></el-input-number>
- <span style="margin-left: 10px;">分钟</span>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="topMsgDialogVisible = false">取 消</el-button>
- <el-button type="primary" @click="sendTopMessage">确 定</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import LivePlayer from './LivePlayer.vue';
- import {blockUser, changeUserStatus, getLiveUserTotals, dashBoardWatchUserList} from '@/api/live/liveWatchUser'
- import { listLiveSingleMsg,delLiveMsg } from '@/api/live/liveMsg'
- import { getLive } from '@/api/live/live'
- import { consoleList } from '@/api/live/task'
- import ScreenScale from './ScreenScale.vue'; // 路径根据实际位置调整
- export default {
- components: {
- LivePlayer,ScreenScale
- },
- props: {
- liveId: {
- type: String,
- default: null
- }
- },
- data() {
- return {
- watermarkIndex: 0,
- watermarkList:[],
- watermarkTemplate: '',
- liveInfo: {},
- videoParam:{
- startTime:'',
- livingUrl: '',
- liveType: 1,
- videoUrl: '',
- },
- msgList:[],
- currentTab: 'al',
- searchKeyword: '',
- globalVisible: false,
- interval: 10,
- autoWatermark: false,
- streamUrl: 'rtmp://your-live-stream-url',
- users: [
- { id: 1, name: '用户1', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: false },
- { id: 2, name: '用户2', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: true },
- { id: 3, name: '用户3', avatar: 'https://via.placeholder.com/40', status: 'offline', statusText: '离线', silenced: true, msgStatus: false },
- { id: 4, name: '用户4', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: false },
- { id: 5, name: '用户5', avatar: 'https://via.placeholder.com/40', status: 'offline', statusText: '离线', silenced: false, msgStatus: false }
- ],
- messages: [
- { id: 1, user: '用户1', avatar: 'https://via.placeholder.com/30', text: '这个产品怎么样?', isVisible: true },
- { id: 2, user: '用户2', avatar: 'https://via.placeholder.com/30', text: '看起来不错', isVisible: true },
- { id: 3, user: '用户3', avatar: 'https://via.placeholder.com/30', text: '有优惠吗?', isVisible: true }
- ],
- timelineItems: [
- { "searchValue": null,
- "createBy": null,
- "createTime": "2025-09-23 10:36:17",
- "updateBy": null,
- "updateTime": "2025-10-17 09:18:00",
- "remark": null,
- "params": {},
- "id": 6573,
- "liveId": 128,
- "taskName": "2",
- "taskType": 1,
- "triggerType": 2,
- "triggerValue": "2025-01-01T00:02:00.000+0800",
- "absValue": "2025-11-23T10:43:00.000+0800",
- "status": 1,
- "finishStatus": 0 },
- ],
- userTotal: {
- online: 0, // 在线总人数
- offline: 0, // 离线总人数
- silenced: 0, // 禁言总人数
- al: 0
- },
- tabLeft: {
- activeName: "al",
- },
- taskParams:{
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- },
- loadMsgMaxPage: 2,
- liveWsUrl: process.env.VUE_APP_LIVE_WS_URL + '/app/webSocket',
- alDisplayList: [],
- onlineDisplayList: [], // 在线用户显示列表
- offlineDisplayList: [], // 离线用户显示列表
- silencedDisplayList: [], // 禁言用户显示列表
- // 各Tab的分页参数
- pageParams: {
- al: {
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- },
- online: {
- currentPage: 1, // 当前页(下一页加载用)
- pageSize: 20, // 当前页(下一页加载用)
- prevPage: 0, // 上一页页码(上一页加载用)
- totalLoaded: 0, // 已加载总条数
- total: 0, // 总数据量
- hasMore: true, // 是否有下一页
- hasPrev: false // 是否有上一页
- },
- offline: {
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- },
- silenced: {
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- }
- },
- scrLoading: {
- al: { next: false, prev: false },
- online: { next: false, prev: false },
- offline: { next: false, prev: false },
- silenced: { next: false, prev: false }
- },
- newMsg:'',
- autoMsgTimer: null,
- checkInterval: 2000, // 检查间隔(1分钟,可根据需求调整)
- topMsgDialogVisible: false,
- topMsgForm: {
- msg: '',
- duration: 5
- },
- // 消息滚动控制
- isAutoScrollEnabled: true, // 是否启用自动滚动
- autoScrollTimer: null, // 自动滚动定时器
- showLoadLatestBtn: false, // 是否显示加载最新消息按钮
- msgParams: {
- pageNum: 1,
- pageSize: 30,
- liveId: null
- }
- };
- },
- computed: {
- userId() {
- return this.$store.state.user.user.userId
- },
- companyId() {
- return this.$store.state.user.user.companyId
- },
- onlineLabel() {
- return `在线(${this.userTotal.online})`;
- },
- alLabel() {
- return `全部(${this.userTotal.al})`;
- },
- offlineLabel() {
- return `离线(${this.userTotal.offline})`;
- },
- silencedUserLabel() {
- return `禁言(${this.userTotal.silenced})`;
- }
- },
- created() {
- if(!this.liveId) return
- this.getList()
- this.handleUserClick({name:'al'})
- this.connectWebSocket()
- this.getLive()
- },
- mounted() {
- this.$nextTick(() => {
- this.restoreChatScrollPosition();
- if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
- this.$refs.manageRightRef.wrap.addEventListener('scroll', this.saveChatScrollPosition);
- }
- });
- this.initScrollListeners();
- },
- methods: {
- // 点击消息框
- handleMessageBoxClick() {
- // 点击消息框时,停止自动滚动
- this.isAutoScrollEnabled = false;
- // 停止自动滚动定时器
- if (this.autoScrollTimer) {
- clearTimeout(this.autoScrollTimer);
- this.autoScrollTimer = null;
- }
- // 检查是否在底部,如果不在底部则显示加载最新消息按钮
- this.$nextTick(() => {
- if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
- const wrap = this.$refs.manageRightRef.wrap;
- const scrollHeight = wrap.scrollHeight;
- const clientHeight = wrap.clientHeight;
- const currentScrollTop = wrap.scrollTop;
- const maxScrollTop = scrollHeight - clientHeight;
- if (currentScrollTop < maxScrollTop - 50) {
- this.showLoadLatestBtn = true;
- }
- }
- });
- },
- // 滚动到底部
- scrollToBottom(forceScroll = false) {
- // 如果自动滚动被禁用且不是强制滚动,则不执行
- console.log("scrollToBottom")
- console.log(!this.isAutoScrollEnabled && !forceScroll)
- console.log(this.$refs.manageRightRef && this.$refs.manageRightRef.wrap)
- console.log(forceScroll || this.isAutoScrollEnabled)
- if (!this.isAutoScrollEnabled && !forceScroll) {
- return;
- }
- if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
- this.$nextTick(() => {
- const wrap = this.$refs.manageRightRef.wrap;
- if (!wrap) return;
- // 强制滚动或启用自动滚动时,直接滚动到底部并隐藏按钮
- if (forceScroll || this.isAutoScrollEnabled) {
- this.showLoadLatestBtn = false;
- this.$refs.manageRightRef.wrap.scrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight
- }
- });
- }
- },
- // 加载最新消息
- loadLatestMessages() {
- this.showLoadLatestBtn = false;
- // 恢复自动滚动
- this.isAutoScrollEnabled = true;
- // 重新请求最新消息
- this.resetMsgParams();
- // loadMsgList 中会自动滚动到底部,因为 isAutoScrollEnabled 已经是 true
- this.loadMsgList();
- },
- singleVisible(m){
- // 过滤当前所有消息 找到userId的相同的消息 更改他们的自可见状态
- m.singleVisible= m.singleVisible === 1 ? 0 : 1
- this.msgList.forEach(m1 => {m1.singleVisible = m1.userId === m.userId ? m.singleVisible : !m.singleVisible})
- // 消息自可见
- let msg = {
- liveId: this.liveId,
- userId: m.userId,
- userType: 0,
- cmd: 'singleVisible',
- status:m.singleVisible
- }
- this.socket.send(JSON.stringify(msg))
- },
- deleteMsg(m){
- // 1. 弹出确认对话框
- this.$confirm('此操作将永久删除该消息, 是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- delLiveMsg(m.msgId).then(res => {
- if (res.code === 200) {
- const index = this.msgList.findIndex(item => item.msgId === m.msgId);
- if (index !== -1) {
- this.msgList.splice(index, 1);
- console.log(`消息 ${m.msgId} 已在本地删除。`);
- }
- let msg = {
- liveId: this.liveId,
- userId: m.userId,
- msg: m.msgId, // 关键:将消息ID发送给后台
- cmd: 'deleteMsg',
- };
- this.socket.send(JSON.stringify(msg));
- // 可以在这里给用户一个删除成功的提示
- this.$message({
- type: 'success',
- message: '消息删除成功!'
- });
- }
- })
- }).catch(() => {
- // 3. 用户点击“取消”或关闭对话框后的回调
- this.$message({
- type: 'info',
- message: '已取消删除'
- });
- });
- },
- globalVisibleChange( val){
- // 消息自可见
- let msg = {
- liveId: this.liveId,
- userId: '9999',
- userType: 0,
- cmd: 'globalVisible',
- status:this.globalVisible ? 1 :0
- }
- this.socket.send(JSON.stringify(msg))
- },
- changeAutoWatermark( val){
- this.watermarkList = this.watermarkTemplate
- .split('\n')
- .map(line => line.trim())
- .filter(line => line !== '');
- if(this.watermarkTemplate.length < 1 || this.watermarkList.length === 0) {
- this.$message.warning('请先填写水印模板')
- this.$nextTick(() => {
- this.autoWatermark = false
- });
- return
- }
- this.disabled = this.autoWatermark
- if(this.autoWatermark){
- this.autoMsgTimer = setInterval(() => {
- this.sendNormalMessage()
- }, 1000 * this.interval)
- } else {
- clearInterval(this.autoMsgTimer)
- this.watermarkIndex = 0;
- this.watermarkList = [];
- }
- },
- sendNormalMessage() {
- if(this.watermarkIndex >= this.watermarkList.length){
- clearInterval(this.autoMsgTimer)
- this.watermarkIndex = 0;
- this.watermarkList = [];
- this.$message.success('自动发送消息已结束');
- this.$nextTick(() => {
- this.autoWatermark = false
- });
- return;
- }
- const curMsg = this.watermarkList[this.watermarkIndex]
- // 发送前简单校验
- if (curMsg.trim() === '') {
- return;
- }
- let msg = {
- msg: curMsg,
- liveId: this.liveId,
- userId: '9999',
- userType: 0,
- cmd: 'sendNormalMsg',
- avatar: this.$store.state.user.user.avatar,
- nickName: this.$store.state.user.user.nickName,
- }
- this.socket.send(JSON.stringify(msg))
- this.watermarkIndex += 1
- },
- // 弹窗消息
- sendPopMessage() {
- // 发送前简单校验
- if (this.newMsg.trim() === '') {
- return;
- }
- let msg = {
- msg: this.newMsg,
- liveId: this.liveId,
- userId: this.userId,
- userType: 1,
- cmd: 'sendPopMsg',
- avatar: this.$store.state.user.user.avatar,
- nickName: this.$store.state.user.user.nickName,
- }
- this.socket.send(JSON.stringify(msg))
- this.newMsg = '';
- },
- // 显示顶部消息对话框
- showTopMsgDialog() {
- this.topMsgForm.msg = '';
- this.topMsgForm.duration = 5;
- this.topMsgDialogVisible = true;
- },
- // 发送顶部消息
- sendTopMessage() {
- // 发送前简单校验
- if (this.topMsgForm.msg.trim() === '') {
- this.$message.warning('请输入消息内容');
- return;
- }
- if (!this.topMsgForm.duration || this.topMsgForm.duration < 1) {
- this.$message.warning('请输入有效的显示时长');
- return;
- }
- let msg = {
- msg: this.topMsgForm.msg,
- duration: this.topMsgForm.duration,
- liveId: this.liveId,
- userId: this.userId,
- userType: 1,
- cmd: 'sendTopMsg',
- avatar: this.$store.state.user.user.avatar,
- nickName: this.$store.state.user.user.nickName,
- }
- this.socket.send(JSON.stringify(msg))
- this.topMsgDialogVisible = false;
- this.$message.success('顶部消息发送成功');
- },
- sendMessage() {
- // 发送前简单校验
- if (this.newMsg.trim() === '') {
- return;
- }
- let msg = {
- msg: this.newMsg,
- liveId: this.liveId,
- userId: this.userId,
- userType: 1,
- cmd: 'sendMsg',
- avatar: this.$store.state.user.user.avatar,
- nickName: this.$store.state.user.user.nickName,
- }
- this.socket.send(JSON.stringify(msg))
- this.newMsg = '';
- },
- handleWsMessage(event) {
- let { code, data } = JSON.parse(event.data)
- if (code === 200) {
- let { cmd } = data
- if (cmd === 'sendMsg') {
- let message = JSON.parse(data.data)
- let user = this.alDisplayList.find(u => u.userId === message.userId)
- if (user) {
- message.msgStatus = user.msgStatus
- } else {
- message.msgStatus = 0
- }
- delete message.params
- if(this.msgList.length > 50){
- this.msgList.shift()
- }
- this.msgList.push(message)
- // 如果启用自动滚动,自动滚动到底部
- console.log("handleWsMessage")
- console.log(this.isAutoScrollEnabled)
- if (this.isAutoScrollEnabled) {
- this.$nextTick(() => {
- this.autoScrollTimer = setTimeout(() => {
- this.scrollToBottom();
- }, 200);
- });
- } else {
- // 自动滚动被禁用时,显示加载最新消息按钮
- this.showLoadLatestBtn = true;
- }
- } else if (cmd === 'entry' || cmd === 'out') {
- const user = data;
- const online = cmd === 'entry' ? 0 : 1; // 0=在线,1=离线
- const info = {
- online:online,
- msgStatus: user.msgStatus || 0,
- nickName: user.nickName || '',
- userType: user.userType || 0,
- userId: user.userId || '',
- };
- // 1. 更新总人数(在线/离线互转)
- if (cmd === 'entry') {
- this.userTotal.online += 1;
- this.userTotal.offline = Math.max(0, this.userTotal.offline - 1); // 确保不小于0
- } else {
- this.userTotal.offline += 1;
- this.userTotal.online = Math.max(0, this.userTotal.online - 1); // 确保不小于0
- }
- // 2. 强制更新相关列表(无论当前激活哪个Tab)
- if (cmd === 'entry') {
- // 用户进入:从离线列表删除,添加到在线列表
- this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
- const newOnlineList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
- newOnlineList.push(info);
- this.onlineDisplayList = newOnlineList.slice(-40); // 限制最大50条
- } else {
- // 用户离开:从在线列表删除,添加到离线列表
- this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
- const newOfflineList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
- newOfflineList.push(info);
- this.offlineDisplayList = newOfflineList.slice(-40); // 限制最大50条
- }
- // 3. 处理禁言列表(如果用户是禁言状态,无论进出都要同步)
- if (info.msgStatus === 1) {
- // 禁言用户:从禁言列表删除旧数据,添加新数据
- const newSilencedList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
- newSilencedList.push(info);
- this.silencedDisplayList = newSilencedList.slice(-40);
- } else {
- // 非禁言用户:从禁言列表删除(如果存在)
- this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
- }
- } else if (cmd === 'live_start') {
- } else if (cmd === 'live_end') {
- }
- }
- },
- getLive(){
- getLive(this.liveId).then(res => {
- if (res.code == 200) {
- if (res.data.isAudit != 1) {
- this.$message.error("当前直播间未经审核");
- this.loading = false
- return
- }
- this.isAudit = true
- this.status = res.data.status
- this.videoParam.startTime = new Date(res.data.startTime).getTime()
- if(res.data.status == 4){
- this.videoParam.liveType = 3
- this.videoParam.videoUrl = res.data.videoUrl;
- }else {
- if (res.data.status != 2) {
- this.$message.error("当前直播间未直播");
- this.loading = false
- return
- }
- if (res.data.liveType == 1) {
- this.videoParam.livingUrl = res.data.flvHlsUrl
- this.videoParam.livingUrl = this.livingUrl.replace("flv","m3u8")
- // this.$nextTick(() => {
- // this.initPlayer()
- // })
- // this.processInterval = setInterval(this.updateLiveProgress, 1000);
- } else {
- this.videoParam.liveType = 2
- this.videoParam.videoUrl = res.data.videoUrl;
- // this.$nextTick(() => {
- // this.initVideoPlayer(res.data.startTime)
- // })
- }
- }
- this.$nextTick(() => {
- this.globalVisible = res.data.globalVisible
- this.$refs.livePlayer.initPlayer()
- })
- this.loading = false
- } else {
- this.$message.error(res.msg)
- this.loading = false
- }
- this.liveInfo = res.data
- })
- },
- connectWebSocket() {
- this.$store.dispatch('initLiveWs', {
- liveWsUrl: this.liveWsUrl,
- liveId: this.liveId,
- userId: this.userId
- })
- this.socket = this.$store.state.liveWs[this.liveId]
- this.socket.onmessage = (event) => this.handleWsMessage(event)
- },
- changeUserState(u) {
- const displayList = this[`${this.currentTab}DisplayList`];
- // 修改状态
- changeUserStatus({liveId: u.liveId, userId: u.userId}).then(response => {
- let { code } = response;
- if (200 === code) {
- u.msgStatus = u.msgStatus === 0 ? 1 : 0
- // 同步更新消息列表中相同用户的状态
- this.msgList.forEach(msg => {
- if (msg.userId === u.userId) {
- msg.msgStatus = u.msgStatus;
- }
- });
- displayList.forEach(user => {
- if (user.userId === u.userId) {
- user.msgStatus = u.msgStatus;
- }
- });
- // 4. 关键:重新筛选所有Tab的显示列表,确保状态同步
- this.refreshUserDisplayLists(u);
- let msg = u.msgStatus === 0 ? "已解禁" : "已禁言"
- this.msgSuccess(msg);
- return
- }
- this.msgError("操作失败");
- })
- },
- refreshUserDisplayLists(user) {
- const { userId, msgStatus: newStatus, online } = user;
- const oldStatus = newStatus === 1 ? 0 : 1; // 操作前的状态(反向)
- // 1. 禁言操作(newStatus=1):从原在线/离线列表移除,加入禁言列表
- if (newStatus === 1) {
- // 从在线/离线列表中移除该用户(根据当前在线状态)
- if (online === 0) {
- this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== userId);
- this.userTotal.online = Math.max(0, this.userTotal.online - 1);
- } else {
- this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== userId);
- this.userTotal.offline = Math.max(0, this.userTotal.offline - 1);
- }
- this.userTotal.silenced = this.userTotal.silenced + 1;
- // 添加到禁言列表(去重+限制长度)
- const silencedList = this.silencedDisplayList.filter(u => u.userId !== userId);
- silencedList.push(user);
- this.silencedDisplayList = silencedList.slice(-40);
- }
- // 2. 解禁操作(newStatus=0):从禁言列表移除,回到原在线/离线列表
- else {
- // 从禁言列表移除
- this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== userId);
- this.userTotal.silenced = Math.max(0, this.userTotal.silenced - 1);
- // 回到对应的在线/离线列表(根据当前在线状态)
- if (online === 0) {
- // 加入在线列表(去重+限制长度)
- const onlineList = this.onlineDisplayList.filter(u => u.userId !== userId);
- onlineList.push(user);
- this.onlineDisplayList = onlineList.slice(-40);
- this.userTotal.online = this.userTotal.online + 1;
- } else {
- // 加入离线列表(去重+限制长度)
- const offlineList = this.offlineDisplayList.filter(u => u.userId !== userId);
- offlineList.push(user);
- this.offlineDisplayList = offlineList.slice(-40);
- this.userTotal.offline = this.userTotal.offline + 1;
- }
- }
- },
- blockUser(u){
- this.$confirm('是否确认封禁用户账号为:"' + u.nickName + '-' + u.userId + '"?', "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(function() {
- return blockUser(u.userId);
- }).then(() => {
- if(u.msgStatus === 1){
- this.userTotal.silenced -= 1
- this.silencedDisplayList = this.silencedDisplayList.filter(user => user.userId !== u.userId)
- } else if( u.online === 0){
- this.userTotal.online -= 1
- this.onlineDisplayList = this.onlineDisplayList.filter(user => user.userId !== u.userId)
- } else {
- this.userTotal.offline -= 1
- this.offlineDisplayList = this.offlineDisplayList.filter(user => user.userId !== u.userId)
- }
- this.userTotal.al -= 1
- this.alDisplayList = this.alDisplayList.filter(user => user.userId !== u.userId)
- let msg = {
- msg: "",
- liveId: this.liveId,
- userId: u.userId,
- userType: 0,
- cmd: 'blockUser',
- avatar: this.$store.state.user.user.avatar,
- nickName: this.$store.state.user.user.nickName
- }
- this.socket.send(JSON.stringify(msg))
- this.msgSuccess("封禁成功");
- }).catch(() => {});
- },
- searchUsers(){
- this.resetUserParams()
- this.loadNextPage(this.currentTab)
- },
- handleUserClick(tab){
- const tabName = tab.name;
- this.currentTab = tabName;
- const params = this.pageParams[tabName];
- const displayList = this[`${tabName}DisplayList`];
- // 首次切换到该Tab或列表为空时初始化
- if (displayList.length < 20) {
- // 重置分页参数
- params.currentPage = 1;
- params.pageSize = 20;
- params.prevPage = 0;
- params.totalLoaded = 0;
- params.hasMore = true;
- params.hasPrev = false;
- // 加载第一页
- this.loadNextPage(tabName);
- } else {
- // 非首次切换,恢复滚动位置
- this.$nextTick(() => {
- const scrollEl = this.getScrollElement(tabName);
- if (scrollEl) {
- scrollEl.scrollTop = this.tabScrollPositions[tabName] || 0;
- }
- });
- }
- },
- loadNextPage(tabName) {
- const params = this.pageParams[tabName];
- const displayList = this[`${tabName}DisplayList`];
- // 若没有更多数据或正在加载,直接返回
- if (!params.hasMore || this.scrLoading[tabName].next) {
- return;
- }
- this.scrLoading[tabName].next = true;
- const queryParams = {
- liveId: this.liveId,
- pageNum: params.currentPage,
- pageSize: 20,
- online: tabName === 'online' ? 0 : 1,
- msgStatus: tabName === 'silenced' ? 1 : 0,
- all: tabName === 'al' ? 1 : 0,
- userName: this.searchKeyword
- };
- // 调用接口加载对应状态的分页数据(需后端支持按状态筛选)
- dashBoardWatchUserList(queryParams).then(response => {
- this.scrLoading[tabName].next = false;
- if (response.code !== 200) return;
- const { rows, total } = response;
- params.total = total; // 记录总数据量
- // 过滤重复数据(基于userId)
- const newRows = rows.filter(row =>
- !displayList.some(u => u.userId === row.userId)
- );
- displayList.push(...newRows)
- // 添加新数据并限制最大长度(避免内存占用过大)
- if (displayList.length >= 40) { // 最大保留100条
- this[`${tabName}DisplayList`] = displayList.slice(-40);
- // 记录滚动位置(用于加载后校准)
- const scrollEl = this.getScrollElement(tabName);
- // 校准滚动位置(保持视觉连续性)
- this.$nextTick(() => {
- if (scrollEl) {
- scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
- }
- });
- }
- // 更新分页状态
- params.hasMore = params.currentPage * params.pageSize < total;
- params.currentPage += 1;
- params.hasPrev = params.currentPage > 2; // 当前页>2时一定有上一页
- params.prevPage = params.currentPage - 2;
- }).catch(() => {
- this.scrLoading[tabName].next = false;
- });
- },
- // 新增:加载上一页(向上滚动时)
- loadPrevPage(tabName) {
- const params = this.pageParams[tabName];
- const displayList = this[`${tabName}DisplayList`];
- // 边界校验:无上一页/正在加载/当前页<=1
- console.log(`加载 ${tabName} 上一页`);
- console.log(!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1)
- if (!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1) {
- return;
- }
- this.scrLoading[tabName].prev = true;
- const targetPage = params.prevPage > 0 ? params.prevPage : params.currentPage - 2;
- const queryParams = {
- liveId: this.liveId,
- pageNum: targetPage,
- pageSize: 20,
- online: tabName === 'online' ? 0 : 1,
- msgStatus: tabName === 'silenced' ? 1 : 0,
- all: tabName === 'al' ? 1 : 0,
- userName: this.searchKeyword
- };
- dashBoardWatchUserList(queryParams).then(response => {
- this.scrLoading[tabName].prev = false;
- if (response.code !== 200) return;
- const { rows } = response;
- if (rows.length === 0) {
- params.hasPrev = false;
- return;
- }
- // 记录滚动位置(用于加载后校准)
- const scrollEl = this.getScrollElement(tabName);
- const scrollTop = scrollEl?.scrollTop || 0;
- const itemHeight = 80; // 预估行高(根据实际样式调整)
- const newItemsHeight = rows.length * itemHeight;
- // 过滤重复数据并添加到列表头部
- const newRows = rows.filter(row => !displayList.some(u => u.userId === row.userId));
- this[`${tabName}DisplayList`] = [...newRows, ...displayList];
- params.totalLoaded += newRows.length;
- // 限制最大长度
- if (this[`${tabName}DisplayList`].length > 40) {
- this[`${tabName}DisplayList`] = this[`${tabName}DisplayList`].slice(0, 40);
- }
- // 更新分页状态
- params.prevPage = targetPage - 1;
- params.hasPrev = targetPage > 1; // 上一页页码>1时还有更多上一页
- params.currentPage = params.currentPage - 1;
- if(params.currentPage * 20 < params.total) params.hasMore = true;
- // 校准滚动位置(保持视觉连续性)
- this.$nextTick(() => {
- if (scrollEl) {
- scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
- }
- });
- }).catch(() => {
- this.scrLoading[tabName].prev = false;
- });
- },
- getList() {
- this.resetUserParams()
- this.resetMsgParams()
- // this.loadUserList()
- this.loadUserTotals(); // 先加载总人数
- // this.handleClick('online')
- // this.handleClick({name:'online'})
- this.loadMsgList()
- this.loadLiveTask()
- },
- formatDate(value) {
- // 检查值是否存在且为日期类型(或可转换为日期)
- if (!value) return '';
- let date;
- // 处理字符串类型的日期
- if (typeof value === 'string') {
- date = new Date(value);
- }
- // 处理Date对象
- else if (value instanceof Date) {
- date = value;
- }
- // 无效类型直接返回原值
- else {
- return value;
- }
- // 检查是否为有效日期
- if (isNaN(date.getTime())) {
- return value;
- }
- // 格式化年月日时分秒(补零处理)
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- const seconds = String(date.getSeconds()).padStart(2, '0');
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
- },
- loadLiveTask(){
- if(!this.taskParams.hasMore) return
- const queryParams = {
- liveId: this.liveId,
- pageSize: 10,
- pageNum: 1
- }
- consoleList(queryParams).then(res => {
- let {code, rows,total} = res;
- if (code === 200) {
- this.taskParams.total = total
- this.timelineItems = rows
- if(rows.length < this.taskParams.pageSize){
- this.taskParams.hasMore = false
- }
- this.startTaskTimer()
- } else {
- this.stopTaskTimer()
- }
- })
- },
- loadMsgList(){
- // 直播间消息
- listLiveSingleMsg({
- liveId:this.liveId,
- pageNum: this.msgParams.pageNum,
- pageSize: this.msgParams.pageSize
- }).then(response => {
- let {code, rows,total} = response;
- if (code === 200) {
- let totalPage = (total % this.msgParams.pageSize == 0) ? Math.floor(total / this.msgParams.pageSize) : Math.floor(total / this.msgParams.pageSize + 1);
- rows.forEach(row => {
- if (!this.msgList.some(m => m.msgId === row.msgId)) {
- let user = this.alDisplayList.find(u => u.userId === row.userId)
- if (user) {
- row.msgStatus = user.msgStatus
- } else {
- row.msgStatus = 0
- }
- this.msgList.push(row)
- }
- })
- this.msgList.reverse()
- // 同步更新消息列表中相同用户的状态
- this.alDisplayList.forEach(u => {
- this.msgList.filter(m => m.userId === u.userId).forEach(m => m.msgStatus = u.msgStatus)
- })
- // 所有消息加载完成后,根据自动滚动状态决定是否滚动
- this.$nextTick(() => {
- setTimeout(() => {
- if (this.isAutoScrollEnabled) {
- // 如果启用自动滚动,强制滚动到底部并隐藏按钮
- this.scrollToBottom(true);
- } else {
- // 如果禁用自动滚动,检查是否在底部,决定是否显示按钮
- if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
- const wrap = this.$refs.manageRightRef.wrap;
- const scrollHeight = wrap.scrollHeight;
- const clientHeight = wrap.clientHeight;
- const currentScrollTop = wrap.scrollTop;
- const maxScrollTop = scrollHeight - clientHeight;
- if (currentScrollTop < maxScrollTop - 50) {
- // this.showLoadLatestBtn = true;
- } else {
- this.showLoadLatestBtn = false;
- }
- }
- }
- }, 300);
- });
- }
- })
- // 添加滚动监听
- this.$nextTick(() => {
- this.$refs.manageRightRef.wrap.addEventListener("scroll", this.manageRightScroll)
- })
- },
- loadUserTotals() {
- if (!this.liveId) return;
- // 假设后端提供一个接口返回总人数(如果没有,可通过首次加载全量数据后统计)
- getLiveUserTotals({ liveId: this.liveId }).then(res => {
- if (res.code === 200) {
- this.userTotal = res.data; // { online, offline, silenced }
- }
- });
- },
- toggleBlack(user) {
- user.isBlack = !user.isBlack;
- },
- toggleMute(user) {
- user.isMuted = !user.isMuted;
- },
- toggleVisible(msg) {
- msg.isVisible = !msg.isVisible;
- },
- deleteMessage(msg) {
- const index = this.messages.indexOf(msg);
- if (index > -1) {
- this.messages.splice(index, 1);
- }
- },
- addTimelineItem() {
- this.timelineItems.push({ time: '00:00', action: '新动作' });
- },
- removeTimelineItem(item) {
- const index = this.timelineItems.indexOf(item);
- if (index > -1) {
- this.timelineItems.splice(index, 1);
- }
- },
- resetUserParams() {
- // 重置各Tab的显示列表和分页参数
- this.alDisplayList = [];
- this.onlineDisplayList = []; // 在线用户显示列表
- this.offlineDisplayList = []; // 离线用户显示列表
- this.silencedDisplayList = []; // 禁言用户显示列表
- this.pageParams= {
- al: {
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- },
- online: {
- currentPage: 1, // 当前页(下一页加载用)
- pageSize: 20, // 当前页(下一页加载用)
- prevPage: 0, // 上一页页码(上一页加载用)
- totalLoaded: 0, // 已加载总条数
- total: 0, // 总数据量
- hasMore: true, // 是否有下一页
- hasPrev: false // 是否有上一页
- },
- offline: {
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- },
- silenced: {
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- }
- },
- this.scrLoading = {
- al: { next: false, prev: false },
- online: { next: false, prev: false },
- offline: { next: false, prev: false },
- silenced: { next: false, prev: false }
- }
- },
- resetMsgParams() {
- // 消息参数保留
- this.msgList = [];
- this.msgParams = {
- pageNum: 1,
- pageSize: 30,
- liveId: this.liveId
- };
- // 重置时不改变按钮状态,由后续的滚动逻辑决定
- this.taskParams = {
- currentPage: 1,
- pageSize: 20,
- prevPage: 0,
- totalLoaded: 0,
- total: 0,
- hasMore: true,
- hasPrev: false
- }
- },
- getScrollElement(tabName) {
- const scrollRefs = {
- al: this.$refs.manageLeftRef_al,
- online: this.$refs.manageLeftRef_online,
- offline: this.$refs.manageLeftRef_offline,
- silenced: this.$refs.manageLeftRef_silenced
- };
- return scrollRefs[tabName]?.wrap;
- },
- // 初始化滚动监听(在mounted中调用)
- initScrollListeners() {
- // 为每个Tab的滚动容器添加监听
- this.$nextTick(() => {
- const scrollRefs = {
- al: this.$refs.manageLeftRef_al,
- online: this.$refs.manageLeftRef_online,
- offline: this.$refs.manageLeftRef_offline,
- silenced: this.$refs.manageLeftRef_silenced
- };
- Object.keys(scrollRefs).forEach(tabName => {
- const scrollEl = scrollRefs[tabName]?.wrap;
- if (scrollEl) {
- scrollEl.addEventListener('scroll', () =>
- this.handleTabScroll(tabName, scrollEl)
- );
- }
- });
- });
- },
- // 处理Tab滚动事件(判断是否触底)
- handleTabScroll(tabName, scrollEl) {
- const { scrollTop, scrollHeight, clientHeight } = scrollEl;
- const bottomThreshold = 50; // 距离底部100px触发下一页
- const topThreshold = 50; // 距离顶部100px触发上一页
- // 加载下一页(滚动到底部附近)
- if (scrollHeight - scrollTop - clientHeight < bottomThreshold) {
- this.loadNextPage(tabName);
- }
- // 加载上一页(滚动到顶部附近)
- if (scrollTop < topThreshold) {
- this.loadPrevPage(tabName);
- }
- },
- // 恢复聊天滚动位置
- restoreChatScrollPosition() {
- if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
- this.$refs.manageRightRef.wrap.scrollTop = this.chatScrollTop;
- }
- },
- // 保存聊天滚动位置
- saveChatScrollPosition() {
- if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
- this.chatScrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight;
- }
- },
- /**
- * 停止任务检测定时器
- */
- stopTaskTimer() {
- if (this.taskTimer) {
- clearInterval(this.taskTimer);
- this.taskTimer = null;
- }
- },
- /**
- * 启动任务检测定时器
- */
- startTaskTimer() {
- // 先清除已有定时器,避免重复
- if (this.taskTimer) {
- clearInterval(this.taskTimer);
- }
- // 立即执行一次检查
- this.checkTaskExpiration();
- // 启动定时器,定期检查
- this.taskTimer = setInterval(() => {
- this.checkTaskExpiration();
- }, this.checkInterval);
- },
- /**
- * 检查时间轴第一条任务是否过期
- */
- checkTaskExpiration() {
- // 如果没有任务,直接返回
- if (!this.timelineItems || this.timelineItems.length === 0) {
- this.stopTaskTimer()
- return;
- };
- // 获取第一条任务的时间
- const firstTask = this.timelineItems[0];
- const taskTime = new Date(firstTask.absValue).getTime();
- const currentTime = new Date().getTime();
- // 如果任务时间已过当前时间(过期),重新加载任务列表
- if (taskTime < currentTime) {
- this.timelineItems.shift()
- this.loadLiveTask(); // 重新加载任务列表
- }
- },
- },
- beforeDestroy() {
- if (this.autoMsgTimer != null) {
- clearInterval(this.autoMsgTimer);
- }
- if (this.autoScrollTimer) {
- clearTimeout(this.autoScrollTimer);
- }
- },
- // 使用 deactivated 和 activated 钩子替代 beforeDestroy 和 destroyed
- deactivated() {
- this.saveChatScrollPosition();
- },
- activated() {
- this.$nextTick(() => {
- this.restoreChatScrollPosition();
- });
- // todo yhq
- // this.$nextTick(() => {
- // const video = this.$refs.videoPlayer;
- // if (video != null) {
- // this.initVideoPlayer(this.liveInfo.startTime)
- // }
- // })
- },
- };
- </script>
- <style scoped>
- .console {
- display: flex;
- height: 100vh;
- }
- .left-panel, .middle-panel, .right-panel {
- padding: 20px;
- box-sizing: border-box;
- }
- .left-panel {
- width: 30%;
- background: #f8fafc;
- border-right: 1px solid #e2e8f0;
- }
- .middle-panel {
- width: 40%;
- background: #f8fafc;
- border-right: 1px solid #e2e8f0;
- }
- .right-panel {
- width: 30%;
- background: #f8fafc;
- }
- .search {
- margin: 10px 0;
- }
- .search input {
- width: 70%;
- padding: 8px;
- border: 1px solid #cbd5e1;
- border-radius: 4px;
- }
- .search button {
- padding: 8px 15px;
- background: #3b82f6;
- color: #fff;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- }
- .tabs {
- display: flex;
- margin: 10px 0;
- }
- .tabs button {
- padding: 8px 15px;
- border: 1px solid #e2e8f0;
- background: #fff;
- cursor: pointer;
- }
- .tabs button.active {
- background: #3b82f6;
- color: #fff;
- border-color: #3b82f6;
- }
- .user-list {
- max-height: 600px;
- overflow-y: auto;
- }
- .user-item {
- display: flex;
- align-items: center;
- padding: 10px;
- border-bottom: 1px solid #e2e8f0;
- }
- .user-item img {
- width: 40px;
- height: 40px;
- border-radius: 50%;
- margin-right: 10px;
- }
- .user-info {
- flex: 1;
- }
- .user-name {
- font-weight: bold;
- }
- .user-status {
- font-size: 12px;
- color: #64748b;
- }
- .online {
- color: #10b981;
- }
- .offline {
- color: #94a3b8;
- }
- .user-actions {
- display: flex;
- }
- .user-actions button {
- padding: 5px 10px;
- margin-left: 5px;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- }
- .block {
- background: #ef4444;
- color: #fff;
- }
- .unblock {
- background: #10b981;
- color: #fff;
- }
- .mute {
- background: #f59e0b;
- color: #fff;
- }
- .unmute {
- background: #3b82f6;
- color: #fff;
- }
- .system-messages, .discussion-messages {
- margin: 20px 0;
- background: #fff;
- padding: 15px;
- border-radius: 8px;
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
- }
- .system-messages textarea {
- width: 100%;
- height: 100px;
- border: 1px solid #e2e8f0;
- border-radius: 4px;
- padding: 8px;
- box-sizing: border-box;
- }
- .message-actions {
- margin-top: 10px;
- }
- .message-actions button {
- padding: 5px 10px;
- margin-right: 5px;
- background: #3b82f6;
- color: #fff;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- }
- .message-list {
- max-height: 300px;
- overflow-y: auto;
- margin-top: 10px;
- }
- .message-item {
- display: flex;
- margin-bottom: 10px;
- padding-bottom: 10px;
- border-bottom: 1px solid #e2e8f0;
- }
- .message-avatar img {
- width: 30px;
- height: 30px;
- border-radius: 50%;
- margin-right: 10px;
- }
- .message-content {
- flex: 1;
- }
- .message-user {
- font-weight: bold;
- }
- .message-text {
- font-size: 14px;
- color: #64748b;
- }
- .message-actions button {
- padding: 3px 8px;
- font-size: 12px;
- background: #3b82f6;
- color: #fff;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- }
- .live-player, .automation, .watermark {
- margin: 20px 0;
- background: #fff;
- padding: 15px;
- border-radius: 8px;
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
- }
- .timeline-items {
- margin: 10px 0;
- }
- .timeline-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 8px 0;
- border-bottom: 1px solid #e2e8f0;
- }
- .delete {
- background: #ef4444;
- color: #fff;
- border: none;
- border-radius: 4px;
- padding: 3px 8px;
- cursor: pointer;
- }
- .add {
- background: #10b981;
- color: #fff;
- border: none;
- border-radius: 4px;
- padding: 8px 15px;
- cursor: pointer;
- }
- .watermark-settings textarea {
- width: 100%;
- height: 100px;
- border: 1px solid #e2e8f0;
- border-radius: 4px;
- padding: 8px;
- box-sizing: border-box;
- }
- .watermark-options {
- margin-top: 10px;
- }
- .watermark-options label {
- display: block;
- margin-bottom: 5px;
- }
- /* 隐藏 el-scrollbar 的横向滚动条 */
- .el-scrollbar__wrap {
- overflow-x: hidden !important;
- }
- .custom-scrollbar .el-scrollbar__wrap {
- overflow-x: hidden !important;
- }
- .scrollbar-demo-item{
- display: flex;
- align-items: center;
- justify-content: center;
- height: 50px;
- margin: 10px;
- text-align: center;
- border-radius: 4px;
- }
- .message-container {
- position: relative;
- }
- .load-latest-btn {
- position: absolute;
- bottom: 20px;
- right: 20px;
- z-index: 10;
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
- }
- </style>
|