LiveConsole.vue 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
  1. <template>
  2. <div class="console">
  3. <div class="left-panel">
  4. <h2 class="panel-title">学员列表</h2>
  5. <div class="search-bar">
  6. <el-input
  7. v-model="searchKeyword"
  8. placeholder="搜索用户昵称"
  9. size="small"
  10. clearable
  11. @keyup.enter.native="searchUsers"
  12. />
  13. <el-button type="primary" size="small" @click="searchUsers">搜索</el-button>
  14. </div>
  15. <el-tabs class="console-tabs" v-model="tabLeft.activeName" @tab-click="handleUserClick" :stretch="true">
  16. <el-tab-pane :label="alLabel" name="al">
  17. <el-scrollbar class="panel-scroll" ref="manageLeftRef_al">
  18. <div class="user-list-item" v-for="u in alDisplayList" :key="u.userId">
  19. <el-avatar :size="36" :src="u.avatar" class="user-avatar" />
  20. <div class="user-meta">
  21. <div class="user-name">{{ u.nickName }}</div>
  22. <div class="user-id">{{ u.userId }}</div>
  23. </div>
  24. <el-popover width="120" trigger="click" popper-class="user-action-popover">
  25. <a class="action-link" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  26. <a class="action-link" @click="blockUser(u)">拉黑</a>
  27. <i class="el-icon-more user-more-btn" slot="reference"></i>
  28. </el-popover>
  29. </div>
  30. </el-scrollbar>
  31. </el-tab-pane>
  32. <el-tab-pane :label="onlineLabel" name="online">
  33. <el-scrollbar class="panel-scroll" ref="manageLeftRef_online">
  34. <div class="user-list-item" v-for="u in onlineDisplayList" :key="u.userId">
  35. <el-avatar :size="36" :src="u.avatar" class="user-avatar" />
  36. <div class="user-meta">
  37. <div class="user-name">{{ u.nickName }}</div>
  38. <div class="user-id">{{ u.userId }}</div>
  39. </div>
  40. <el-popover width="120" trigger="click" popper-class="user-action-popover">
  41. <a class="action-link" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  42. <a class="action-link" @click="blockUser(u)">拉黑</a>
  43. <i class="el-icon-more user-more-btn" slot="reference"></i>
  44. </el-popover>
  45. </div>
  46. </el-scrollbar>
  47. </el-tab-pane>
  48. <el-tab-pane :label="offlineLabel" name="offline">
  49. <el-scrollbar class="panel-scroll" ref="manageLeftRef_offline">
  50. <div class="user-list-item" v-for="u in offlineDisplayList" :key="u.userId">
  51. <el-avatar :size="36" :src="u.avatar" class="user-avatar" />
  52. <div class="user-meta">
  53. <div class="user-name">{{ u.nickName }}</div>
  54. <div class="user-id">{{ u.userId }}</div>
  55. </div>
  56. <el-popover width="120" trigger="click" popper-class="user-action-popover">
  57. <a class="action-link" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  58. <a class="action-link" @click="blockUser(u)">拉黑</a>
  59. <i class="el-icon-more user-more-btn" slot="reference"></i>
  60. </el-popover>
  61. </div>
  62. </el-scrollbar>
  63. </el-tab-pane>
  64. <el-tab-pane :label="silencedUserLabel" name="silenced">
  65. <el-scrollbar class="panel-scroll" ref="manageLeftRef_silenced">
  66. <div class="user-list-item" v-for="u in silencedDisplayList" :key="u.userId">
  67. <el-avatar :size="36" :src="u.avatar" class="user-avatar" />
  68. <div class="user-meta">
  69. <div class="user-name">{{ u.nickName }}</div>
  70. <div class="user-id">{{ u.userId }}</div>
  71. </div>
  72. <el-popover width="120" trigger="click" popper-class="user-action-popover">
  73. <a class="action-link" @click="changeUserState(u)">{{ u.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  74. <a class="action-link" @click="blockUser(u)">拉黑</a>
  75. <i class="el-icon-more user-more-btn" slot="reference"></i>
  76. </el-popover>
  77. </div>
  78. </el-scrollbar>
  79. </el-tab-pane>
  80. </el-tabs>
  81. </div>
  82. <div class="middle-panel">
  83. <h2 class="panel-title">消息管理</h2>
  84. <div class="panel-card discussion-messages">
  85. <div class="section-header">
  86. <h3 class="section-title">讨论区消息</h3>
  87. <el-checkbox v-model="globalVisible" @change="globalVisibleChange">全局用户自见</el-checkbox>
  88. </div>
  89. <div class="message-container" @click="handleMessageBoxClick">
  90. <el-scrollbar class="msg-scroll" ref="manageRightRef">
  91. <div v-for="m in msgList" :key="m.msgId" class="msg-item">
  92. <div v-if="m.userId === userId && m.msgId == null" class="msg-row msg-row--self">
  93. <div class="msg-content msg-content--self">
  94. <div class="msg-nickname">{{ m.nickName }}</div>
  95. <div class="msg-bubble msg-bubble--self">{{ m.msg }}</div>
  96. </div>
  97. <el-avatar :size="32" :src="m.avatar" class="msg-avatar" />
  98. </div>
  99. <div v-else class="msg-row">
  100. <el-avatar :size="32" :src="m.avatar" class="msg-avatar" />
  101. <div class="msg-content">
  102. <div class="msg-nickname">{{ m.nickName }}</div>
  103. <div class="msg-bubble">{{ m.msg }}</div>
  104. <div class="msg-actions">
  105. <a class="action-link" @click.stop="changeUserState(m)">{{ m.msgStatus === 1 ? '解禁' : '禁言' }}</a>
  106. <a class="action-link" @click.stop="blockUser(m)">拉黑</a>
  107. <a class="action-link" @click.stop="singleVisible(m)">{{ m.singleVisible === 1 ? '解除用户自见' : '用户自见' }}</a>
  108. <a class="action-link" @click.stop="deleteMsg(m)">删除</a>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <div class="scroll-bottom-space"></div>
  114. </el-scrollbar>
  115. <el-button
  116. v-if="showLoadLatestBtn"
  117. class="load-latest-btn"
  118. type="primary"
  119. size="mini"
  120. @click.stop="loadLatestMessages"
  121. :disabled="isLoadingLatest"
  122. :loading="isLoadingLatest"
  123. icon="el-icon-refresh"
  124. >加载最新消息</el-button>
  125. </div>
  126. </div>
  127. <div class="panel-card ops-panel">
  128. <el-tabs v-model="opsTabActive" class="ops-tabs">
  129. <el-tab-pane label="营销" name="marketing">
  130. <div class="marketing-panel" v-loading="marketingLoading">
  131. <div class="marketing-toolbar">
  132. <span class="toolbar-label">显示购物车</span>
  133. <el-switch v-model="showCart" @change="showCartChange" />
  134. <el-alert
  135. class="marketing-tip"
  136. title="置顶商品弹窗优先展示时,其他同位置弹窗将不再展示"
  137. type="info"
  138. :closable="false"
  139. show-icon
  140. />
  141. </div>
  142. <el-radio-group v-model="marketingCategory" size="mini" class="marketing-categories" @change="clearMarketingSelection">
  143. <el-radio-button v-for="cat in marketingCategories" :key="cat.key" :label="cat.key">{{ cat.label }}</el-radio-button>
  144. </el-radio-group>
  145. <el-scrollbar class="marketing-scroll">
  146. <!-- 商品:图片卡片 -->
  147. <div class="marketing-cards" v-if="marketingCategory === 'goods' && currentMarketingList.length">
  148. <div
  149. v-for="item in currentMarketingList"
  150. :key="getMarketingItemKey(item)"
  151. class="marketing-card"
  152. :class="{ selected: isMarketingItemSelected(item) }"
  153. @click="selectMarketingItem(item)"
  154. >
  155. <div class="card-image-wrap">
  156. <img :src="item.imgUrl || item.image" class="card-image" />
  157. <div class="card-tags">
  158. <el-tag v-if="item.isShow" type="warning" size="mini" effect="dark">展示中</el-tag>
  159. <el-tag v-if="item.status == 1" type="success" size="mini" effect="dark">已上架</el-tag>
  160. </div>
  161. <div class="card-overlay">
  162. <el-button size="mini" round :disabled="item.status == 1" @click.stop="handleGoodsShelf(item, 1)">上架</el-button>
  163. <el-button size="mini" type="danger" round :disabled="item.status == 0" @click.stop="handleGoodsShelf(item, 0)">下架</el-button>
  164. <el-button size="mini" type="primary" round @click.stop="handleGoodsShowToggle(item)">{{ item.isShow ? '收起' : '展示' }}</el-button>
  165. </div>
  166. </div>
  167. <div class="card-info">
  168. <div class="card-title" :title="item.productName">{{ item.productName }}</div>
  169. <div class="card-bottom">
  170. <span class="card-price" v-if="item.price">¥{{ item.price }}</span>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. <!-- 优惠券 / 核销券 / 红包 / 抽奖:列表 -->
  176. <div class="marketing-list" v-else-if="marketingCategory !== 'goods' && currentMarketingList.length">
  177. <div
  178. v-for="item in currentMarketingList"
  179. :key="getMarketingItemKey(item)"
  180. class="marketing-list-item"
  181. :class="{ selected: isMarketingItemSelected(item) }"
  182. @click="selectMarketingItem(item)"
  183. >
  184. <div class="list-main">
  185. <div class="list-title" :title="getMarketingItemTitle(item)">{{ getMarketingItemTitle(item) }}</div>
  186. <div class="list-meta">
  187. <span v-if="getMarketingItemPrice(item)" class="list-price">¥{{ getMarketingItemPrice(item) }}</span>
  188. <span v-if="getMarketingListMeta(item)">{{ getMarketingListMeta(item) }}</span>
  189. </div>
  190. <div class="list-tags">
  191. <el-tag v-if="(marketingCategory === 'coupon' || marketingCategory === 'verifyCoupon') && item.isShow" type="warning" size="mini">展示中</el-tag>
  192. <el-tag v-if="(marketingCategory === 'lottery' || marketingCategory === 'red') && isRedLotteryRunning(item)" type="success" size="mini">进行中</el-tag>
  193. </div>
  194. </div>
  195. <div class="list-actions" @click.stop>
  196. <template v-if="marketingCategory === 'lottery'">
  197. <el-button size="mini" type="primary" @click="handleLotteryStatusChange(item, '1')">开始</el-button>
  198. <el-button size="mini" @click="handleLotteryStatusChange(item, '3')">暂停</el-button>
  199. <el-button size="mini" type="danger" @click="handleLotteryStatusChange(item, '2')">结算</el-button>
  200. </template>
  201. <template v-else-if="marketingCategory === 'red'">
  202. <el-button size="mini" type="primary" @click="handleRedStatusChange(item, '1')">开始</el-button>
  203. <el-button size="mini" @click="handleRedStatusChange(item, '3')">暂停</el-button>
  204. <el-button size="mini" type="danger" @click="handleRedStatusChange(item, '2')">结算</el-button>
  205. </template>
  206. <template v-else-if="marketingCategory === 'coupon'">
  207. <el-button size="mini" @click="openCouponBindDialog(item)">绑定商品</el-button>
  208. <el-button size="mini" type="primary" @click="handleCouponShowToggle(item)">{{ item.isShow ? '收起' : '展示' }}</el-button>
  209. </template>
  210. <template v-else-if="marketingCategory === 'verifyCoupon'">
  211. <el-button size="mini" type="primary" @click="handleCouponShowToggle(item)">{{ item.isShow ? '收起' : '展示' }}</el-button>
  212. </template>
  213. </div>
  214. </div>
  215. </div>
  216. <el-empty v-else description="暂无数据" :image-size="60" />
  217. </el-scrollbar>
  218. <div class="panel-footer">
  219. <el-button size="mini" @click="handleActivityRecord">活动记录</el-button>
  220. <el-button size="mini" @click="handleDistributionRecord">发放记录</el-button>
  221. </div>
  222. </div>
  223. </el-tab-pane>
  224. <el-tab-pane label="系统消息" name="systemMsg">
  225. <div class="system-msg-panel">
  226. <el-input
  227. type="textarea"
  228. :rows="3"
  229. placeholder="输入系统消息"
  230. v-model="newMsg"
  231. resize="none"
  232. />
  233. <div class="panel-footer">
  234. <el-button type="primary" size="mini" @click="sendMessage">发送消息</el-button>
  235. </div>
  236. </div>
  237. </el-tab-pane>
  238. </el-tabs>
  239. </div>
  240. </div>
  241. <div class="right-panel">
  242. <h2 class="panel-title">运营工具</h2>
  243. <div class="panel-card live-player">
  244. <h3 class="section-title">直播观看</h3>
  245. <LivePlayer ref="livePlayer" :videoParam="videoParam" />
  246. </div>
  247. <div class="panel-card automation">
  248. <h3 class="section-title">运营自动化</h3>
  249. <p class="section-subtitle">时间轴设置</p>
  250. <div class="timeline-items">
  251. <div class="timeline-item" v-for="item in timelineItems.slice(0, 2)" :key="item.id || item.absValue">
  252. <div class="timeline-info">
  253. <div class="timeline-time">{{ formatDate(item.absValue) }}</div>
  254. <div class="timeline-action">{{ item.taskName }}</div>
  255. </div>
  256. <el-button type="text" size="mini" class="action-link" @click="removeTimelineItem(item)">删除</el-button>
  257. </div>
  258. <el-empty v-if="!timelineItems.length" description="暂无任务" :image-size="48" />
  259. </div>
  260. </div>
  261. <div class="panel-card watermark">
  262. <h3 class="section-title">直播氛围自动化</h3>
  263. <el-input
  264. type="textarea"
  265. :rows="4"
  266. :disabled="autoWatermark"
  267. v-model="watermarkTemplate"
  268. placeholder="水军弹幕内容模板,每行一条"
  269. resize="none"
  270. />
  271. <div class="watermark-options">
  272. <span class="toolbar-label">发送间隔</span>
  273. <el-input-number v-model="interval" :min="1" :disabled="autoWatermark" size="mini" controls-position="right" />
  274. <span class="toolbar-label">秒</span>
  275. <el-checkbox v-model="autoWatermark" @change="changeAutoWatermark">启用水军自动化</el-checkbox>
  276. </div>
  277. </div>
  278. </div>
  279. <el-dialog title="绑定商品" :visible.sync="couponBindDialogVisible" width="480px" append-to-body>
  280. <el-form label-width="80px">
  281. <el-form-item label="直播商品">
  282. <el-select v-model="couponBindForm.goodsId" placeholder="请选择商品" filterable style="width: 100%;">
  283. <el-option
  284. v-for="g in bindGoodsOptions"
  285. :key="g.goodsId"
  286. :label="g.productName"
  287. :value="g.goodsId"
  288. />
  289. </el-select>
  290. </el-form-item>
  291. </el-form>
  292. <div slot="footer">
  293. <el-button @click="couponBindDialogVisible = false">取 消</el-button>
  294. <el-button type="primary" @click="confirmCouponBind">确 定</el-button>
  295. </div>
  296. </el-dialog>
  297. </div>
  298. </template>
  299. <script>
  300. import LivePlayer from './LivePlayer.vue';
  301. import {blockUser, changeUserStatus, getLiveUserTotals, dashBoardWatchUserList} from '@/api/live/liveWatchUser'
  302. import { listLiveSingleMsg,delLiveMsg } from '@/api/live/liveMsg'
  303. import { getLive, updateShowCart } from '@/api/live/live'
  304. import { consoleList } from '@/api/live/task'
  305. import { listLiveGoods, handleShelfOrUn, handleIsShowChange as handleGoodsIsShowChange } from '@/api/live/liveGoods'
  306. import { listLiveCoupon, handleIsShowChange as handleCouponIsShowChange, updateLiveCouponBind } from '@/api/live/liveCoupon'
  307. import { listLiveLotteryConf, updateLiveLotteryConf } from '@/api/live/liveLotteryConf'
  308. import { listLiveRedConf, updateLiveRedConf } from '@/api/live/liveRedConf'
  309. import ScreenScale from './ScreenScale.vue'; // 路径根据实际位置调整
  310. export default {
  311. components: {
  312. LivePlayer,ScreenScale
  313. },
  314. props: {
  315. liveId: {
  316. type: String,
  317. default: null
  318. }
  319. },
  320. data() {
  321. return {
  322. watermarkIndex: 0,
  323. watermarkList:[],
  324. watermarkTemplate: '',
  325. liveInfo: {},
  326. videoParam:{
  327. startTime:'',
  328. livingUrl: '',
  329. liveType: 1,
  330. videoUrl: '',
  331. },
  332. msgList:[],
  333. currentTab: 'al',
  334. searchKeyword: '',
  335. globalVisible: false,
  336. interval: 10,
  337. autoWatermark: false,
  338. streamUrl: 'rtmp://your-live-stream-url',
  339. users: [
  340. { id: 1, name: '用户1', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: false },
  341. { id: 2, name: '用户2', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: true },
  342. { id: 3, name: '用户3', avatar: 'https://via.placeholder.com/40', status: 'offline', statusText: '离线', silenced: true, msgStatus: false },
  343. { id: 4, name: '用户4', avatar: 'https://via.placeholder.com/40', status: 'online', statusText: '在线', silenced: false, msgStatus: false },
  344. { id: 5, name: '用户5', avatar: 'https://via.placeholder.com/40', status: 'offline', statusText: '离线', silenced: false, msgStatus: false }
  345. ],
  346. messages: [
  347. { id: 1, user: '用户1', avatar: 'https://via.placeholder.com/30', text: '这个产品怎么样?', isVisible: true },
  348. { id: 2, user: '用户2', avatar: 'https://via.placeholder.com/30', text: '看起来不错', isVisible: true },
  349. { id: 3, user: '用户3', avatar: 'https://via.placeholder.com/30', text: '有优惠吗?', isVisible: true }
  350. ],
  351. timelineItems: [
  352. { "searchValue": null,
  353. "createBy": null,
  354. "createTime": "2025-09-23 10:36:17",
  355. "updateBy": null,
  356. "updateTime": "2025-10-17 09:18:00",
  357. "remark": null,
  358. "params": {},
  359. "id": 6573,
  360. "liveId": 128,
  361. "taskName": "2",
  362. "taskType": 1,
  363. "triggerType": 2,
  364. "triggerValue": "2025-01-01T00:02:00.000+0800",
  365. "absValue": "2025-11-23T10:43:00.000+0800",
  366. "status": 1,
  367. "finishStatus": 0 },
  368. ],
  369. userTotal: {
  370. online: 0, // 在线总人数
  371. offline: 0, // 离线总人数
  372. silenced: 0, // 禁言总人数
  373. al: 0
  374. },
  375. tabLeft: {
  376. activeName: "al",
  377. },
  378. taskParams:{
  379. currentPage: 1,
  380. pageSize: 20,
  381. prevPage: 0,
  382. totalLoaded: 0,
  383. total: 0,
  384. hasMore: true,
  385. hasPrev: false
  386. },
  387. loadMsgMaxPage: 2,
  388. liveWsUrl: process.env.VUE_APP_LIVE_WS_URL + '/app/webSocket',
  389. alDisplayList: [],
  390. onlineDisplayList: [], // 在线用户显示列表
  391. offlineDisplayList: [], // 离线用户显示列表
  392. silencedDisplayList: [], // 禁言用户显示列表
  393. // 各Tab的分页参数
  394. pageParams: {
  395. al: {
  396. currentPage: 1,
  397. pageSize: 20,
  398. prevPage: 0,
  399. totalLoaded: 0,
  400. total: 0,
  401. hasMore: true,
  402. hasPrev: false
  403. },
  404. online: {
  405. currentPage: 1, // 当前页(下一页加载用)
  406. pageSize: 20, // 当前页(下一页加载用)
  407. prevPage: 0, // 上一页页码(上一页加载用)
  408. totalLoaded: 0, // 已加载总条数
  409. total: 0, // 总数据量
  410. hasMore: true, // 是否有下一页
  411. hasPrev: false // 是否有上一页
  412. },
  413. offline: {
  414. currentPage: 1,
  415. pageSize: 20,
  416. prevPage: 0,
  417. totalLoaded: 0,
  418. total: 0,
  419. hasMore: true,
  420. hasPrev: false
  421. },
  422. silenced: {
  423. currentPage: 1,
  424. pageSize: 20,
  425. prevPage: 0,
  426. totalLoaded: 0,
  427. total: 0,
  428. hasMore: true,
  429. hasPrev: false
  430. }
  431. },
  432. scrLoading: {
  433. al: { next: false, prev: false },
  434. online: { next: false, prev: false },
  435. offline: { next: false, prev: false },
  436. silenced: { next: false, prev: false }
  437. },
  438. newMsg:'',
  439. autoMsgTimer: null,
  440. checkInterval: 2000, // 检查间隔(1分钟,可根据需求调整)
  441. // 消息滚动控制
  442. isAutoScrollEnabled: true, // 是否启用自动滚动
  443. autoScrollTimer: null, // 自动滚动定时器
  444. showLoadLatestBtn: false, // 是否显示加载最新消息按钮
  445. isLoadingLatest: false, // 是否正在加载最新消息
  446. scrollDebounceTimer: null, // 滚动防抖定时器
  447. msgParams: {
  448. pageNum: 1,
  449. pageSize: 30,
  450. liveId: null
  451. },
  452. opsTabActive: 'marketing',
  453. marketingCategory: 'goods',
  454. marketingCategories: [
  455. { key: 'goods', label: '商品' },
  456. { key: 'coupon', label: '优惠券' },
  457. { key: 'verifyCoupon', label: '核销券' },
  458. { key: 'red', label: '红包' },
  459. { key: 'lottery', label: '抽奖' }
  460. ],
  461. marketingLoading: false,
  462. showCart: true,
  463. goodsLiveList: [],
  464. couponLiveList: [],
  465. lotteryList: [],
  466. redList: [],
  467. couponTypeOptions: [],
  468. lotteryStatusOptions: [],
  469. redStatusOptions: [],
  470. selectedMarketingItem: null,
  471. couponBindDialogVisible: false,
  472. couponBindForm: { couponId: null, goodsId: null },
  473. bindGoodsOptions: []
  474. };
  475. },
  476. computed: {
  477. userId() {
  478. return this.$store.state.user.user.userId
  479. },
  480. companyId() {
  481. return this.$store.state.user.user.companyId
  482. },
  483. onlineLabel() {
  484. return `在线(${this.userTotal.online})`;
  485. },
  486. alLabel() {
  487. return `全部(${this.userTotal.al})`;
  488. },
  489. offlineLabel() {
  490. return `离线(${this.userTotal.offline})`;
  491. },
  492. silencedUserLabel() {
  493. return `禁言(${this.userTotal.silenced})`;
  494. },
  495. currentMarketingList() {
  496. if (this.marketingCategory === 'goods') {
  497. return this.goodsLiveList;
  498. }
  499. if (this.marketingCategory === 'lottery') {
  500. return this.lotteryList;
  501. }
  502. if (this.marketingCategory === 'red') {
  503. return this.redList;
  504. }
  505. if (this.marketingCategory === 'coupon') {
  506. return this.couponLiveList.filter(item => !this.isVerifyCouponType(item));
  507. }
  508. return this.couponLiveList.filter(item => this.isVerifyCouponType(item));
  509. }
  510. },
  511. created() {
  512. if(!this.liveId) return
  513. this.loadMarketingDicts()
  514. this.getList()
  515. this.handleUserClick({name:'al'})
  516. this.connectWebSocket()
  517. this.getLive()
  518. },
  519. mounted() {
  520. this.$nextTick(() => {
  521. this.restoreChatScrollPosition();
  522. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  523. this.$refs.manageRightRef.wrap.addEventListener('scroll', this.saveChatScrollPosition);
  524. }
  525. });
  526. this.initScrollListeners();
  527. },
  528. methods: {
  529. loadMarketingDicts() {
  530. this.getDicts('store_coupon_type').then(response => {
  531. this.couponTypeOptions = response.data || [];
  532. });
  533. this.getDicts('sys_live_lottery_status').then(response => {
  534. this.lotteryStatusOptions = response.data || [];
  535. });
  536. this.getDicts('sys_live_red_status').then(response => {
  537. this.redStatusOptions = response.data || [];
  538. });
  539. },
  540. loadMarketingData() {
  541. if (!this.liveId) return;
  542. this.marketingLoading = true;
  543. const query = { liveId: this.liveId, pageNum: 1, pageSize: 100 };
  544. Promise.all([
  545. listLiveGoods(query),
  546. listLiveCoupon(query),
  547. listLiveLotteryConf(query),
  548. listLiveRedConf(query)
  549. ]).then(([goodsRes, couponRes, lotteryRes, redRes]) => {
  550. if (goodsRes.code === 200) {
  551. this.goodsLiveList = (goodsRes.rows || []).map(item => ({
  552. ...item,
  553. isShow: item.isShow === 1 || item.isShow === true
  554. }));
  555. }
  556. if (couponRes.code === 200) {
  557. this.couponLiveList = (couponRes.rows || []).map(item => ({
  558. ...item,
  559. isShow: item.isShow === 1 || item.isShow === true
  560. }));
  561. }
  562. if (lotteryRes.code === 200) {
  563. this.lotteryList = lotteryRes.rows || [];
  564. }
  565. if (redRes.code === 200) {
  566. this.redList = redRes.rows || [];
  567. }
  568. }).finally(() => {
  569. this.marketingLoading = false;
  570. });
  571. },
  572. clearMarketingSelection() {
  573. this.selectedMarketingItem = null;
  574. },
  575. isVerifyCouponType(item) {
  576. const label = this.selectDictLabel(this.couponTypeOptions, item.type) || '';
  577. return label.includes('核销') || label.includes('代金券');
  578. },
  579. getMarketingItemKey(item) {
  580. if (this.marketingCategory === 'goods') return `goods-${item.goodsId}`;
  581. if (this.marketingCategory === 'lottery') return `lottery-${item.lotteryId}`;
  582. if (this.marketingCategory === 'red') return `red-${item.redId}`;
  583. return `coupon-${item.id || item.couponId}`;
  584. },
  585. getMarketingItemTitle(item) {
  586. if (this.marketingCategory === 'lottery') {
  587. return item.desc || `抽奖 #${item.lotteryId}`;
  588. }
  589. if (this.marketingCategory === 'red') {
  590. return item.desc || `红包 #${item.redId}`;
  591. }
  592. return item.productName || item.title || '-';
  593. },
  594. getMarketingItemPrice(item) {
  595. if (this.marketingCategory === 'goods') {
  596. return item.price;
  597. }
  598. if (this.marketingCategory === 'coupon' || this.marketingCategory === 'verifyCoupon') {
  599. return item.couponPrice;
  600. }
  601. return '';
  602. },
  603. getMarketingListMeta(item) {
  604. if (this.marketingCategory === 'lottery') {
  605. return this.selectDictLabel(this.lotteryStatusOptions, item.lotteryStatus) || '';
  606. }
  607. if (this.marketingCategory === 'red') {
  608. return this.selectDictLabel(this.redStatusOptions, item.redStatus) || '';
  609. }
  610. const typeLabel = this.selectDictLabel(this.couponTypeOptions, item.type);
  611. const parts = [];
  612. if (item.useMinPrice) {
  613. parts.push(`满${item.useMinPrice}可用`);
  614. }
  615. if (this.marketingCategory === 'coupon' && item.productName) {
  616. parts.push(`已绑:${item.productName}`);
  617. }
  618. if (typeLabel) {
  619. parts.push(typeLabel);
  620. }
  621. return parts.join(' · ');
  622. },
  623. isRedLotteryRunning(item) {
  624. const status = this.marketingCategory === 'red' ? item.redStatus : item.lotteryStatus;
  625. return status + '' === '1' || status + '' === '3';
  626. },
  627. isMarketingItemSelected(item) {
  628. if (!this.selectedMarketingItem) return false;
  629. return this.getMarketingItemKey(item) === this.getMarketingItemKey(this.selectedMarketingItem);
  630. },
  631. selectMarketingItem(item) {
  632. this.selectedMarketingItem = item;
  633. },
  634. ensureSocket() {
  635. if (!this.socket) {
  636. this.$message.error('请从直播间开启 WebSocket 连接');
  637. return false;
  638. }
  639. return true;
  640. },
  641. handleGoodsShelf(row, status) {
  642. handleShelfOrUn({ goodsIds: [row.goodsId], status, liveId: this.liveId }).then(res => {
  643. if (res.code === 200) {
  644. row.status = status;
  645. this.$message.success(status === 1 ? '上架成功' : '下架成功');
  646. } else {
  647. this.$message.error(res.msg);
  648. }
  649. });
  650. },
  651. handleGoodsShowToggle(row) {
  652. this.toggleGoodsShow(row, !row.isShow);
  653. },
  654. handleCouponShowToggle(row) {
  655. this.toggleCouponShow(row, !row.isShow);
  656. },
  657. openCouponBindDialog(row) {
  658. this.couponBindForm = { couponId: row.id, goodsId: row.goodsId || null };
  659. listLiveGoods({ liveId: this.liveId, pageNum: 1, pageSize: 100 }).then(res => {
  660. if (res.code === 200) {
  661. this.bindGoodsOptions = res.rows || [];
  662. this.couponBindDialogVisible = true;
  663. }
  664. });
  665. },
  666. confirmCouponBind() {
  667. if (!this.couponBindForm.goodsId) {
  668. this.$message.warning('请选择商品');
  669. return;
  670. }
  671. updateLiveCouponBind({
  672. goodsId: this.couponBindForm.goodsId,
  673. couponId: this.couponBindForm.couponId,
  674. liveId: this.liveId
  675. }).then(res => {
  676. if (res.code === 200) {
  677. this.$message.success('绑定成功');
  678. this.couponBindDialogVisible = false;
  679. this.loadMarketingData();
  680. } else {
  681. this.$message.error(res.msg);
  682. }
  683. });
  684. },
  685. toggleGoodsShow(row, targetStatus) {
  686. if (!this.ensureSocket()) return;
  687. handleGoodsIsShowChange({
  688. goodsIds: [row.goodsId],
  689. isShow: targetStatus,
  690. liveId: this.liveId
  691. }).then(res => {
  692. if (res.code === 200) {
  693. row.isShow = res.isShow;
  694. if (res.msg === '目前仅支持单一物品展示') {
  695. this.$message.error(res.msg);
  696. }
  697. this.socket.send(JSON.stringify({
  698. cmd: 'goods',
  699. data: { liveId: this.liveId, goodsId: row.goodsId, status: targetStatus ? 1 : 0 }
  700. }));
  701. }
  702. });
  703. },
  704. toggleCouponShow(row, targetStatus) {
  705. if (!this.ensureSocket()) return;
  706. handleCouponIsShowChange({
  707. couponId: row.id,
  708. isShow: targetStatus,
  709. liveId: this.liveId
  710. }).then(res => {
  711. if (res.code === 200) {
  712. row.isShow = targetStatus;
  713. if (res.msg === '目前仅支持单一优惠券推送') {
  714. this.$message.error(res.msg);
  715. return;
  716. }
  717. this.socket.send(JSON.stringify({
  718. cmd: 'coupon',
  719. data: {
  720. liveId: this.liveId,
  721. couponIssueId: row.id,
  722. status: targetStatus ? 1 : 0,
  723. goodsId: row.goodsId,
  724. couponName: row.title,
  725. couponPrice: row.couponPrice,
  726. useMinPrice: row.useMinPrice,
  727. couponTime: row.couponTime
  728. }
  729. }));
  730. }
  731. });
  732. },
  733. handleLotteryStatusChange(row, status) {
  734. if (!this.ensureSocket()) return;
  735. if (row.lotteryStatus + '' === '2') {
  736. this.$message.error('已结束的抽奖不能进行操作');
  737. return;
  738. }
  739. if (status === '1' && row.lotteryStatus + '' !== '0' && row.lotteryStatus + '' !== '3') {
  740. this.$message.error('只能对未开始或暂停的抽奖进行开始操作');
  741. return;
  742. }
  743. if (status === '2' && row.lotteryStatus + '' !== '1' && row.lotteryStatus + '' !== '3') {
  744. this.$message.error('只能对进行中或暂停的抽奖进行结算');
  745. return;
  746. }
  747. if (status === '3' && row.lotteryStatus + '' !== '1') {
  748. this.$message.error('只能对进行中的抽奖执行暂停操作');
  749. return;
  750. }
  751. const param = {
  752. lotteryId: row.lotteryId,
  753. lotteryStatus: status,
  754. duration: row.duration,
  755. liveId: this.liveId,
  756. status
  757. };
  758. updateLiveLotteryConf(param).then(response => {
  759. if (response.code === 200) {
  760. this.socket.send(JSON.stringify({ cmd: 'lottery', data: param }));
  761. this.$message.success('操作成功');
  762. this.loadMarketingData();
  763. } else {
  764. this.$message.error(response.msg);
  765. }
  766. });
  767. },
  768. handleRedStatusChange(row, status) {
  769. if (!this.ensureSocket()) return;
  770. if (row.redStatus + '' === '2') {
  771. this.$message.error('已结束的红包不能进行操作');
  772. return;
  773. }
  774. if (status === '1' && row.redStatus + '' !== '0' && row.redStatus + '' !== '3') {
  775. this.$message.error('只能对未开始或暂停的红包进行开始操作');
  776. return;
  777. }
  778. if (status === '2' && row.redStatus + '' !== '1' && row.redStatus + '' !== '3') {
  779. this.$message.error('只能对进行中或暂停的红包进行结算');
  780. return;
  781. }
  782. if (status === '3' && row.redStatus + '' !== '1') {
  783. this.$message.error('只能对进行中的红包执行暂停操作');
  784. return;
  785. }
  786. const param = {
  787. redId: row.redId,
  788. redStatus: status,
  789. totalLots: row.totalLots,
  790. totalSend: row.totalSend,
  791. redType: row.redType,
  792. redNum: row.redNum,
  793. liveId: this.liveId,
  794. duration: row.duration,
  795. status
  796. };
  797. updateLiveRedConf(param).then(response => {
  798. if (response.code === 200) {
  799. this.socket.send(JSON.stringify({ cmd: 'red', data: param }));
  800. this.$message.success('操作成功');
  801. this.loadMarketingData();
  802. } else {
  803. this.$message.error(response.msg);
  804. }
  805. });
  806. },
  807. handleActivityRecord() {
  808. if (!this.timelineItems.length) {
  809. this.$message.info('暂无活动记录');
  810. return;
  811. }
  812. const names = this.timelineItems.map(item => `${this.formatDate(item.absValue)} ${item.taskName}`).join('\n');
  813. this.$alert(names, '活动记录', { confirmButtonText: '确定' });
  814. },
  815. handleDistributionRecord() {
  816. this.$message.info('发放记录请在直播配置-优惠券/红包配置中查看');
  817. },
  818. // 点击消息框
  819. handleMessageBoxClick() {
  820. // 点击消息框时,停止自动滚动
  821. this.isAutoScrollEnabled = false;
  822. // 停止自动滚动定时器
  823. if (this.autoScrollTimer) {
  824. clearTimeout(this.autoScrollTimer);
  825. this.autoScrollTimer = null;
  826. }
  827. // 检查是否在底部,如果不在底部则显示加载最新消息按钮
  828. this.$nextTick(() => {
  829. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  830. const wrap = this.$refs.manageRightRef.wrap;
  831. const scrollHeight = wrap.scrollHeight;
  832. const clientHeight = wrap.clientHeight;
  833. const currentScrollTop = wrap.scrollTop;
  834. const maxScrollTop = scrollHeight - clientHeight;
  835. if (currentScrollTop < maxScrollTop - 50) {
  836. this.showLoadLatestBtn = true;
  837. }
  838. }
  839. });
  840. },
  841. // 滚动到底部
  842. scrollToBottom(forceScroll = false) {
  843. // 如果自动滚动被禁用且不是强制滚动,则不执行
  844. if (!this.isAutoScrollEnabled && !forceScroll) {
  845. return;
  846. }
  847. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  848. this.$nextTick(() => {
  849. const wrap = this.$refs.manageRightRef.wrap;
  850. if (!wrap) return;
  851. const scrollHeight = wrap.scrollHeight;
  852. const clientHeight = wrap.clientHeight;
  853. const currentScrollTop = wrap.scrollTop;
  854. const maxScrollTop = scrollHeight - clientHeight;
  855. // 强制滚动或启用自动滚动时,直接滚动到底部并隐藏按钮
  856. if (forceScroll || this.isAutoScrollEnabled) {
  857. this.showLoadLatestBtn = false;
  858. wrap.scrollTop = maxScrollTop;
  859. }
  860. });
  861. }
  862. },
  863. // 加载最新消息
  864. loadLatestMessages() {
  865. // 如果正在加载,直接返回
  866. if (this.isLoadingLatest) {
  867. return;
  868. }
  869. this.isLoadingLatest = true;
  870. this.showLoadLatestBtn = false;
  871. // 恢复自动滚动
  872. this.isAutoScrollEnabled = true;
  873. // 重新请求最新消息
  874. this.resetMsgParams();
  875. // loadMsgList 中会自动滚动到底部,因为 isAutoScrollEnabled 已经是 true
  876. this.loadMsgList();
  877. },
  878. singleVisible(m){
  879. // 过滤当前所有消息 找到userId的相同的消息 更改他们的自可见状态
  880. m.singleVisible= m.singleVisible === 1 ? 0 : 1
  881. this.msgList.forEach(m1 => {m1.singleVisible = m1.userId === m.userId ? m.singleVisible : !m.singleVisible})
  882. // 消息自可见
  883. let msg = {
  884. liveId: this.liveId,
  885. userId: m.userId,
  886. userType: 0,
  887. cmd: 'singleVisible',
  888. status:m.singleVisible
  889. }
  890. this.socket.send(JSON.stringify(msg))
  891. },
  892. deleteMsg(m){
  893. // 1. 弹出确认对话框
  894. this.$confirm('此操作将永久删除该消息, 是否继续?', '提示', {
  895. confirmButtonText: '确定',
  896. cancelButtonText: '取消',
  897. type: 'warning'
  898. }).then(() => {
  899. delLiveMsg(m.msgId).then(res => {
  900. if (res.code === 200) {
  901. const index = this.msgList.findIndex(item => item.msgId === m.msgId);
  902. if (index !== -1) {
  903. this.msgList.splice(index, 1);
  904. console.log(`消息 ${m.msgId} 已在本地删除。`);
  905. }
  906. let msg = {
  907. liveId: this.liveId,
  908. userId: m.userId,
  909. msg: m.msgId, // 关键:将消息ID发送给后台
  910. cmd: 'deleteMsg',
  911. };
  912. this.socket.send(JSON.stringify(msg));
  913. // 可以在这里给用户一个删除成功的提示
  914. this.$message({
  915. type: 'success',
  916. message: '消息删除成功!'
  917. });
  918. }
  919. })
  920. }).catch(() => {
  921. // 3. 用户点击“取消”或关闭对话框后的回调
  922. this.$message({
  923. type: 'info',
  924. message: '已取消删除'
  925. });
  926. });
  927. },
  928. globalVisibleChange( val){
  929. // 消息自可见
  930. let msg = {
  931. liveId: this.liveId,
  932. userId: '9999',
  933. userType: 0,
  934. cmd: 'globalVisible',
  935. status:this.globalVisible ? 1 :0
  936. }
  937. this.socket.send(JSON.stringify(msg))
  938. },
  939. showCartChange(val) {
  940. const status = val ? 1 : 0
  941. updateShowCart({ liveId: this.liveId, showCart: status }).then(res => {
  942. if (res.code !== 200) {
  943. this.$message.error(res.msg || '更新购物车显示状态失败')
  944. this.showCart = !val
  945. return
  946. }
  947. if (this.socket && this.socket.readyState === WebSocket.OPEN) {
  948. this.socket.send(JSON.stringify({
  949. liveId: this.liveId,
  950. userId: '9999',
  951. userType: 0,
  952. cmd: 'showCart',
  953. status
  954. }))
  955. }
  956. }).catch(() => {
  957. this.showCart = !val
  958. this.$message.error('更新购物车显示状态失败')
  959. })
  960. },
  961. changeAutoWatermark( val){
  962. this.watermarkList = this.watermarkTemplate
  963. .split('\n')
  964. .map(line => line.trim())
  965. .filter(line => line !== '');
  966. if(this.watermarkTemplate.length < 1 || this.watermarkList.length === 0) {
  967. this.$message.warning('请先填写水印模板')
  968. this.$nextTick(() => {
  969. this.autoWatermark = false
  970. });
  971. return
  972. }
  973. this.disabled = this.autoWatermark
  974. if(this.autoWatermark){
  975. this.autoMsgTimer = setInterval(() => {
  976. this.sendNormalMessage()
  977. }, 1000 * this.interval)
  978. } else {
  979. clearInterval(this.autoMsgTimer)
  980. this.watermarkIndex = 0;
  981. this.watermarkList = [];
  982. }
  983. },
  984. sendNormalMessage() {
  985. if(this.watermarkIndex >= this.watermarkList.length){
  986. clearInterval(this.autoMsgTimer)
  987. this.watermarkIndex = 0;
  988. this.watermarkList = [];
  989. this.$message.success('自动发送消息已结束');
  990. this.$nextTick(() => {
  991. this.autoWatermark = false
  992. });
  993. return;
  994. }
  995. const curMsg = this.watermarkList[this.watermarkIndex]
  996. // 发送前简单校验
  997. if (curMsg.trim() === '') {
  998. return;
  999. }
  1000. let msg = {
  1001. msg: curMsg,
  1002. liveId: this.liveId,
  1003. userId: '9999',
  1004. userType: 0,
  1005. cmd: 'sendNormalMsg',
  1006. avatar: this.$store.state.user.user.avatar,
  1007. nickName: this.$store.state.user.user.nickName,
  1008. }
  1009. this.socket.send(JSON.stringify(msg))
  1010. this.watermarkIndex += 1
  1011. },
  1012. sendMessage() {
  1013. // 发送前简单校验
  1014. if (this.newMsg.trim() === '') {
  1015. return;
  1016. }
  1017. let msg = {
  1018. msg: this.newMsg,
  1019. liveId: this.liveId,
  1020. userId: this.userId,
  1021. userType: 1,
  1022. cmd: 'sendMsg',
  1023. avatar: this.$store.state.user.user.avatar,
  1024. nickName: this.$store.state.user.user.nickName,
  1025. }
  1026. this.socket.send(JSON.stringify(msg))
  1027. this.newMsg = '';
  1028. },
  1029. handleWsMessage(event) {
  1030. let { code, data } = JSON.parse(event.data)
  1031. if (code === 200) {
  1032. let { cmd } = data
  1033. if (cmd === 'sendMsg') {
  1034. let message = JSON.parse(data.data)
  1035. let user = this.alDisplayList.find(u => u.userId === message.userId)
  1036. if (user) {
  1037. message.msgStatus = user.msgStatus
  1038. } else {
  1039. message.msgStatus = 0
  1040. }
  1041. delete message.params
  1042. if(this.msgList.length > 50){
  1043. this.msgList.shift()
  1044. }
  1045. this.msgList.push(message)
  1046. // 如果启用自动滚动,自动滚动到底部
  1047. if (this.isAutoScrollEnabled) {
  1048. this.$nextTick(() => {
  1049. this.autoScrollTimer = setTimeout(() => {
  1050. this.scrollToBottom();
  1051. }, 200);
  1052. });
  1053. } else {
  1054. // 自动滚动被禁用时,显示加载最新消息按钮
  1055. this.showLoadLatestBtn = true;
  1056. }
  1057. } else if (cmd === 'entry' || cmd === 'out') {
  1058. const user = data;
  1059. const online = cmd === 'entry' ? 0 : 1; // 0=在线,1=离线
  1060. const info = {
  1061. online:online,
  1062. msgStatus: user.msgStatus || 0,
  1063. nickName: user.nickName || '',
  1064. userType: user.userType || 0,
  1065. userId: user.userId || '',
  1066. };
  1067. // 1. 更新总人数(在线/离线互转)
  1068. if (cmd === 'entry') {
  1069. this.userTotal.online += 1;
  1070. this.userTotal.offline = Math.max(0, this.userTotal.offline - 1); // 确保不小于0
  1071. } else {
  1072. this.userTotal.offline += 1;
  1073. this.userTotal.online = Math.max(0, this.userTotal.online - 1); // 确保不小于0
  1074. }
  1075. // 2. 强制更新相关列表(无论当前激活哪个Tab)
  1076. if (cmd === 'entry') {
  1077. // 用户进入:从离线列表删除,添加到在线列表
  1078. this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
  1079. const newOnlineList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
  1080. newOnlineList.push(info);
  1081. this.onlineDisplayList = newOnlineList.slice(-40); // 限制最大50条
  1082. } else {
  1083. // 用户离开:从在线列表删除,添加到离线列表
  1084. this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== user.userId);
  1085. const newOfflineList = this.offlineDisplayList.filter(u => u.userId !== user.userId);
  1086. newOfflineList.push(info);
  1087. this.offlineDisplayList = newOfflineList.slice(-40); // 限制最大50条
  1088. }
  1089. // 3. 处理禁言列表(如果用户是禁言状态,无论进出都要同步)
  1090. if (info.msgStatus === 1) {
  1091. // 禁言用户:从禁言列表删除旧数据,添加新数据
  1092. const newSilencedList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
  1093. newSilencedList.push(info);
  1094. this.silencedDisplayList = newSilencedList.slice(-40);
  1095. } else {
  1096. // 非禁言用户:从禁言列表删除(如果存在)
  1097. this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== user.userId);
  1098. }
  1099. } else if (cmd === 'live_start') {
  1100. } else if (cmd === 'live_end') {
  1101. }
  1102. }
  1103. },
  1104. getLive(){
  1105. getLive(this.liveId).then(res => {
  1106. if (res.code == 200) {
  1107. if (res.data.isAudit != 1) {
  1108. this.$message.error("当前直播间未经审核");
  1109. this.loading = false
  1110. return
  1111. }
  1112. this.isAudit = true
  1113. this.status = res.data.status
  1114. this.videoParam.startTime = new Date(res.data.startTime).getTime()
  1115. if(res.data.status == 4){
  1116. this.videoParam.liveType = 3
  1117. this.videoParam.videoUrl = res.data.videoUrl;
  1118. }else {
  1119. if (res.data.status != 2) {
  1120. this.$message.error("当前直播间未直播");
  1121. this.loading = false
  1122. return
  1123. }
  1124. if (res.data.liveType == 1) {
  1125. this.videoParam.livingUrl = res.data.flvHlsUrl
  1126. this.videoParam.livingUrl = this.videoParam.livingUrl.replace("flv","m3u8")
  1127. // this.$nextTick(() => {
  1128. // this.initPlayer()
  1129. // })
  1130. // this.processInterval = setInterval(this.updateLiveProgress, 1000);
  1131. } else {
  1132. this.videoParam.liveType = 2
  1133. this.videoParam.videoUrl = res.data.videoUrl;
  1134. // this.$nextTick(() => {
  1135. // this.initVideoPlayer(res.data.startTime)
  1136. // })
  1137. }
  1138. }
  1139. this.$nextTick(() => {
  1140. this.globalVisible = res.data.globalVisible
  1141. this.showCart = res.data.showCart == null || res.data.showCart === 1
  1142. this.$refs.livePlayer.initPlayer()
  1143. })
  1144. this.loading = false
  1145. } else {
  1146. this.$message.error(res.msg)
  1147. this.loading = false
  1148. }
  1149. this.liveInfo = res.data
  1150. })
  1151. },
  1152. connectWebSocket() {
  1153. this.$store.dispatch('initLiveWs', {
  1154. liveWsUrl: this.liveWsUrl,
  1155. liveId: this.liveId,
  1156. userId: this.userId
  1157. })
  1158. this.socket = this.$store.state.liveWs[this.liveId]
  1159. this.socket.onmessage = (event) => this.handleWsMessage(event)
  1160. },
  1161. changeUserState(u) {
  1162. const displayList = this[`${this.currentTab}DisplayList`];
  1163. // 修改状态
  1164. changeUserStatus({liveId: u.liveId, userId: u.userId}).then(response => {
  1165. let { code } = response;
  1166. if (200 === code) {
  1167. u.msgStatus = u.msgStatus === 0 ? 1 : 0
  1168. // 同步更新消息列表中相同用户的状态
  1169. this.msgList.forEach(msg => {
  1170. if (msg.userId === u.userId) {
  1171. msg.msgStatus = u.msgStatus;
  1172. }
  1173. });
  1174. displayList.forEach(user => {
  1175. if (user.userId === u.userId) {
  1176. user.msgStatus = u.msgStatus;
  1177. }
  1178. });
  1179. // 4. 关键:重新筛选所有Tab的显示列表,确保状态同步
  1180. this.refreshUserDisplayLists(u);
  1181. let msg = u.msgStatus === 0 ? "已解禁" : "已禁言"
  1182. this.msgSuccess(msg);
  1183. return
  1184. }
  1185. this.msgError("操作失败");
  1186. })
  1187. },
  1188. refreshUserDisplayLists(user) {
  1189. const { userId, msgStatus: newStatus, online } = user;
  1190. const oldStatus = newStatus === 1 ? 0 : 1; // 操作前的状态(反向)
  1191. // 1. 禁言操作(newStatus=1):从原在线/离线列表移除,加入禁言列表
  1192. if (newStatus === 1) {
  1193. // 从在线/离线列表中移除该用户(根据当前在线状态)
  1194. if (online === 0) {
  1195. this.onlineDisplayList = this.onlineDisplayList.filter(u => u.userId !== userId);
  1196. this.userTotal.online = Math.max(0, this.userTotal.online - 1);
  1197. } else {
  1198. this.offlineDisplayList = this.offlineDisplayList.filter(u => u.userId !== userId);
  1199. this.userTotal.offline = Math.max(0, this.userTotal.offline - 1);
  1200. }
  1201. this.userTotal.silenced = this.userTotal.silenced + 1;
  1202. // 添加到禁言列表(去重+限制长度)
  1203. const silencedList = this.silencedDisplayList.filter(u => u.userId !== userId);
  1204. silencedList.push(user);
  1205. this.silencedDisplayList = silencedList.slice(-40);
  1206. }
  1207. // 2. 解禁操作(newStatus=0):从禁言列表移除,回到原在线/离线列表
  1208. else {
  1209. // 从禁言列表移除
  1210. this.silencedDisplayList = this.silencedDisplayList.filter(u => u.userId !== userId);
  1211. this.userTotal.silenced = Math.max(0, this.userTotal.silenced - 1);
  1212. // 回到对应的在线/离线列表(根据当前在线状态)
  1213. if (online === 0) {
  1214. // 加入在线列表(去重+限制长度)
  1215. const onlineList = this.onlineDisplayList.filter(u => u.userId !== userId);
  1216. onlineList.push(user);
  1217. this.onlineDisplayList = onlineList.slice(-40);
  1218. this.userTotal.online = this.userTotal.online + 1;
  1219. } else {
  1220. // 加入离线列表(去重+限制长度)
  1221. const offlineList = this.offlineDisplayList.filter(u => u.userId !== userId);
  1222. offlineList.push(user);
  1223. this.offlineDisplayList = offlineList.slice(-40);
  1224. this.userTotal.offline = this.userTotal.offline + 1;
  1225. }
  1226. }
  1227. },
  1228. blockUser(u){
  1229. this.$confirm('是否确认封禁用户账号为:"' + u.nickName + '-' + u.userId + '"?', "警告", {
  1230. confirmButtonText: "确定",
  1231. cancelButtonText: "取消",
  1232. type: "warning"
  1233. }).then(function() {
  1234. return blockUser(u.userId);
  1235. }).then(() => {
  1236. if(u.msgStatus === 1){
  1237. this.userTotal.silenced -= 1
  1238. this.silencedDisplayList = this.silencedDisplayList.filter(user => user.userId !== u.userId)
  1239. } else if( u.online === 0){
  1240. this.userTotal.online -= 1
  1241. this.onlineDisplayList = this.onlineDisplayList.filter(user => user.userId !== u.userId)
  1242. } else {
  1243. this.userTotal.offline -= 1
  1244. this.offlineDisplayList = this.offlineDisplayList.filter(user => user.userId !== u.userId)
  1245. }
  1246. this.userTotal.al -= 1
  1247. this.alDisplayList = this.alDisplayList.filter(user => user.userId !== u.userId)
  1248. let msg = {
  1249. msg: "",
  1250. liveId: this.liveId,
  1251. userId: u.userId,
  1252. userType: 0,
  1253. cmd: 'blockUser',
  1254. avatar: this.$store.state.user.user.avatar,
  1255. nickName: this.$store.state.user.user.nickName
  1256. }
  1257. this.socket.send(JSON.stringify(msg))
  1258. this.msgSuccess("封禁成功");
  1259. }).catch(() => {});
  1260. },
  1261. searchUsers(){
  1262. this.resetUserParams()
  1263. this.loadNextPage(this.currentTab)
  1264. },
  1265. handleUserClick(tab){
  1266. const tabName = tab.name;
  1267. this.currentTab = tabName;
  1268. const params = this.pageParams[tabName];
  1269. const displayList = this[`${tabName}DisplayList`];
  1270. // 首次切换到该Tab或列表为空时初始化
  1271. if (displayList.length < 20) {
  1272. // 重置分页参数
  1273. params.currentPage = 1;
  1274. params.pageSize = 20;
  1275. params.prevPage = 0;
  1276. params.totalLoaded = 0;
  1277. params.hasMore = true;
  1278. params.hasPrev = false;
  1279. // 加载第一页
  1280. this.loadNextPage(tabName);
  1281. } else {
  1282. // 非首次切换,恢复滚动位置
  1283. this.$nextTick(() => {
  1284. const scrollEl = this.getScrollElement(tabName);
  1285. if (scrollEl) {
  1286. scrollEl.scrollTop = this.tabScrollPositions[tabName] || 0;
  1287. }
  1288. });
  1289. }
  1290. },
  1291. loadNextPage(tabName) {
  1292. const params = this.pageParams[tabName];
  1293. const displayList = this[`${tabName}DisplayList`];
  1294. // 若没有更多数据或正在加载,直接返回
  1295. if (!params.hasMore || this.scrLoading[tabName].next) {
  1296. return;
  1297. }
  1298. this.scrLoading[tabName].next = true;
  1299. const queryParams = {
  1300. liveId: this.liveId,
  1301. pageNum: params.currentPage,
  1302. pageSize: 20,
  1303. online: tabName === 'online' ? 0 : 1,
  1304. msgStatus: tabName === 'silenced' ? 1 : 0,
  1305. all: tabName === 'al' ? 1 : 0,
  1306. userName: this.searchKeyword
  1307. };
  1308. // 调用接口加载对应状态的分页数据(需后端支持按状态筛选)
  1309. dashBoardWatchUserList(queryParams).then(response => {
  1310. this.scrLoading[tabName].next = false;
  1311. if (response.code !== 200) return;
  1312. const { rows, total } = response;
  1313. params.total = total; // 记录总数据量
  1314. // 过滤重复数据(基于userId)
  1315. const newRows = rows.filter(row =>
  1316. !displayList.some(u => u.userId === row.userId)
  1317. );
  1318. displayList.push(...newRows)
  1319. // 添加新数据并限制最大长度(避免内存占用过大)
  1320. if (displayList.length >= 40) { // 最大保留100条
  1321. this[`${tabName}DisplayList`] = displayList.slice(-40);
  1322. // 记录滚动位置(用于加载后校准)
  1323. const scrollEl = this.getScrollElement(tabName);
  1324. // 校准滚动位置(保持视觉连续性)
  1325. this.$nextTick(() => {
  1326. if (scrollEl) {
  1327. scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
  1328. }
  1329. });
  1330. }
  1331. // 更新分页状态
  1332. params.hasMore = params.currentPage * params.pageSize < total;
  1333. params.currentPage += 1;
  1334. params.hasPrev = params.currentPage > 2; // 当前页>2时一定有上一页
  1335. params.prevPage = params.currentPage - 2;
  1336. }).catch(() => {
  1337. this.scrLoading[tabName].next = false;
  1338. });
  1339. },
  1340. // 新增:加载上一页(向上滚动时)
  1341. loadPrevPage(tabName) {
  1342. const params = this.pageParams[tabName];
  1343. const displayList = this[`${tabName}DisplayList`];
  1344. // 边界校验:无上一页/正在加载/当前页<=1
  1345. console.log(`加载 ${tabName} 上一页`);
  1346. console.log(!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1)
  1347. if (!params.hasPrev || this.scrLoading[tabName].prev || params.currentPage <= 1) {
  1348. return;
  1349. }
  1350. this.scrLoading[tabName].prev = true;
  1351. const targetPage = params.prevPage > 0 ? params.prevPage : params.currentPage - 2;
  1352. const queryParams = {
  1353. liveId: this.liveId,
  1354. pageNum: targetPage,
  1355. pageSize: 20,
  1356. online: tabName === 'online' ? 0 : 1,
  1357. msgStatus: tabName === 'silenced' ? 1 : 0,
  1358. all: tabName === 'al' ? 1 : 0,
  1359. userName: this.searchKeyword
  1360. };
  1361. dashBoardWatchUserList(queryParams).then(response => {
  1362. this.scrLoading[tabName].prev = false;
  1363. if (response.code !== 200) return;
  1364. const { rows } = response;
  1365. if (rows.length === 0) {
  1366. params.hasPrev = false;
  1367. return;
  1368. }
  1369. // 记录滚动位置(用于加载后校准)
  1370. const scrollEl = this.getScrollElement(tabName);
  1371. const scrollTop = scrollEl?.scrollTop || 0;
  1372. const itemHeight = 80; // 预估行高(根据实际样式调整)
  1373. const newItemsHeight = rows.length * itemHeight;
  1374. // 过滤重复数据并添加到列表头部
  1375. const newRows = rows.filter(row => !displayList.some(u => u.userId === row.userId));
  1376. this[`${tabName}DisplayList`] = [...newRows, ...displayList];
  1377. params.totalLoaded += newRows.length;
  1378. // 限制最大长度
  1379. if (this[`${tabName}DisplayList`].length > 40) {
  1380. this[`${tabName}DisplayList`] = this[`${tabName}DisplayList`].slice(0, 40);
  1381. }
  1382. // 更新分页状态
  1383. params.prevPage = targetPage - 1;
  1384. params.hasPrev = targetPage > 1; // 上一页页码>1时还有更多上一页
  1385. params.currentPage = params.currentPage - 1;
  1386. if(params.currentPage * 20 < params.total) params.hasMore = true;
  1387. // 校准滚动位置(保持视觉连续性)
  1388. this.$nextTick(() => {
  1389. if (scrollEl) {
  1390. scrollEl.scrollTop = scrollEl.scrollHeight * 0.5;
  1391. }
  1392. });
  1393. }).catch(() => {
  1394. this.scrLoading[tabName].prev = false;
  1395. });
  1396. },
  1397. getList() {
  1398. this.resetUserParams()
  1399. this.resetMsgParams()
  1400. // this.loadUserList()
  1401. this.loadUserTotals(); // 先加载总人数
  1402. // this.handleClick('online')
  1403. // this.handleClick({name:'online'})
  1404. this.loadMsgList()
  1405. this.loadLiveTask()
  1406. this.loadMarketingData()
  1407. },
  1408. formatDate(value) {
  1409. // 检查值是否存在且为日期类型(或可转换为日期)
  1410. if (!value) return '';
  1411. let date;
  1412. // 处理字符串类型的日期
  1413. if (typeof value === 'string') {
  1414. date = new Date(value);
  1415. }
  1416. // 处理Date对象
  1417. else if (value instanceof Date) {
  1418. date = value;
  1419. }
  1420. // 无效类型直接返回原值
  1421. else {
  1422. return value;
  1423. }
  1424. // 检查是否为有效日期
  1425. if (isNaN(date.getTime())) {
  1426. return value;
  1427. }
  1428. // 格式化年月日时分秒(补零处理)
  1429. const year = date.getFullYear();
  1430. const month = String(date.getMonth() + 1).padStart(2, '0');
  1431. const day = String(date.getDate()).padStart(2, '0');
  1432. const hours = String(date.getHours()).padStart(2, '0');
  1433. const minutes = String(date.getMinutes()).padStart(2, '0');
  1434. const seconds = String(date.getSeconds()).padStart(2, '0');
  1435. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  1436. },
  1437. loadLiveTask(){
  1438. if(!this.taskParams.hasMore) return
  1439. const queryParams = {
  1440. liveId: this.liveId,
  1441. pageSize: 10,
  1442. pageNum: 1
  1443. }
  1444. consoleList(queryParams).then(res => {
  1445. let {code, rows,total} = res;
  1446. if (code === 200) {
  1447. this.taskParams.total = total
  1448. this.timelineItems = rows
  1449. if(rows.length < this.taskParams.pageSize){
  1450. this.taskParams.hasMore = false
  1451. }
  1452. this.startTaskTimer()
  1453. } else {
  1454. this.stopTaskTimer()
  1455. }
  1456. })
  1457. },
  1458. loadMsgList(){
  1459. // 直播间消息
  1460. listLiveSingleMsg({
  1461. liveId:this.liveId,
  1462. pageNum: this.msgParams.pageNum,
  1463. pageSize: this.msgParams.pageSize
  1464. }).then(response => {
  1465. let {code, rows,total} = response;
  1466. if (code === 200) {
  1467. let totalPage = (total % this.msgParams.pageSize == 0) ? Math.floor(total / this.msgParams.pageSize) : Math.floor(total / this.msgParams.pageSize + 1);
  1468. rows.forEach(row => {
  1469. if (!this.msgList.some(m => m.msgId === row.msgId)) {
  1470. let user = this.alDisplayList.find(u => u.userId === row.userId)
  1471. if (user) {
  1472. row.msgStatus = user.msgStatus
  1473. } else {
  1474. row.msgStatus = 0
  1475. }
  1476. this.msgList.push(row)
  1477. }
  1478. })
  1479. this.msgList.reverse()
  1480. // 同步更新消息列表中相同用户的状态
  1481. this.alDisplayList.forEach(u => {
  1482. this.msgList.filter(m => m.userId === u.userId).forEach(m => m.msgStatus = u.msgStatus)
  1483. })
  1484. // 所有消息加载完成后,根据自动滚动状态决定是否滚动
  1485. this.$nextTick(() => {
  1486. setTimeout(() => {
  1487. // 重置加载状态
  1488. this.isLoadingLatest = false;
  1489. if (this.isAutoScrollEnabled) {
  1490. // 如果启用自动滚动,强制滚动到底部并隐藏按钮
  1491. this.scrollToBottom(true);
  1492. } else {
  1493. // 如果禁用自动滚动,检查是否在底部,决定是否显示按钮
  1494. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1495. const wrap = this.$refs.manageRightRef.wrap;
  1496. const scrollHeight = wrap.scrollHeight;
  1497. const clientHeight = wrap.clientHeight;
  1498. const currentScrollTop = wrap.scrollTop;
  1499. const maxScrollTop = scrollHeight - clientHeight;
  1500. if (currentScrollTop < maxScrollTop - 50) {
  1501. this.showLoadLatestBtn = true;
  1502. } else {
  1503. this.showLoadLatestBtn = false;
  1504. }
  1505. }
  1506. }
  1507. }, 300);
  1508. });
  1509. }
  1510. })
  1511. // 添加滚动监听
  1512. this.$nextTick(() => {
  1513. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1514. this.$refs.manageRightRef.wrap.addEventListener("scroll", this.manageRightScroll)
  1515. }
  1516. })
  1517. },
  1518. // 消息滚动监听(带防抖)
  1519. manageRightScroll() {
  1520. // 清除之前的防抖定时器
  1521. if (this.scrollDebounceTimer) {
  1522. clearTimeout(this.scrollDebounceTimer);
  1523. }
  1524. // 设置防抖,300ms内只执行一次
  1525. this.scrollDebounceTimer = setTimeout(() => {
  1526. this.saveChatScrollPosition();
  1527. // 检查是否滚动到底部
  1528. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1529. const wrap = this.$refs.manageRightRef.wrap;
  1530. const scrollHeight = wrap.scrollHeight;
  1531. const clientHeight = wrap.clientHeight;
  1532. const currentScrollTop = wrap.scrollTop;
  1533. const maxScrollTop = scrollHeight - clientHeight;
  1534. // 如果滚动到底部(距离底部小于50px),隐藏按钮并恢复自动滚动
  1535. if (currentScrollTop >= maxScrollTop - 50) {
  1536. this.showLoadLatestBtn = false;
  1537. this.isAutoScrollEnabled = true;
  1538. }
  1539. }
  1540. }, 300);
  1541. },
  1542. loadUserTotals() {
  1543. if (!this.liveId) return;
  1544. // 假设后端提供一个接口返回总人数(如果没有,可通过首次加载全量数据后统计)
  1545. getLiveUserTotals({ liveId: this.liveId }).then(res => {
  1546. if (res.code === 200) {
  1547. this.userTotal = res.data; // { online, offline, silenced }
  1548. }
  1549. });
  1550. },
  1551. toggleBlack(user) {
  1552. user.isBlack = !user.isBlack;
  1553. },
  1554. toggleMute(user) {
  1555. user.isMuted = !user.isMuted;
  1556. },
  1557. toggleVisible(msg) {
  1558. msg.isVisible = !msg.isVisible;
  1559. },
  1560. deleteMessage(msg) {
  1561. const index = this.messages.indexOf(msg);
  1562. if (index > -1) {
  1563. this.messages.splice(index, 1);
  1564. }
  1565. },
  1566. addTimelineItem() {
  1567. this.timelineItems.push({ time: '00:00', action: '新动作' });
  1568. },
  1569. removeTimelineItem(item) {
  1570. const index = this.timelineItems.indexOf(item);
  1571. if (index > -1) {
  1572. this.timelineItems.splice(index, 1);
  1573. }
  1574. },
  1575. resetUserParams() {
  1576. // 重置各Tab的显示列表和分页参数
  1577. this.alDisplayList = [];
  1578. this.onlineDisplayList = []; // 在线用户显示列表
  1579. this.offlineDisplayList = []; // 离线用户显示列表
  1580. this.silencedDisplayList = []; // 禁言用户显示列表
  1581. this.pageParams= {
  1582. al: {
  1583. currentPage: 1,
  1584. pageSize: 20,
  1585. prevPage: 0,
  1586. totalLoaded: 0,
  1587. total: 0,
  1588. hasMore: true,
  1589. hasPrev: false
  1590. },
  1591. online: {
  1592. currentPage: 1, // 当前页(下一页加载用)
  1593. pageSize: 20, // 当前页(下一页加载用)
  1594. prevPage: 0, // 上一页页码(上一页加载用)
  1595. totalLoaded: 0, // 已加载总条数
  1596. total: 0, // 总数据量
  1597. hasMore: true, // 是否有下一页
  1598. hasPrev: false // 是否有上一页
  1599. },
  1600. offline: {
  1601. currentPage: 1,
  1602. pageSize: 20,
  1603. prevPage: 0,
  1604. totalLoaded: 0,
  1605. total: 0,
  1606. hasMore: true,
  1607. hasPrev: false
  1608. },
  1609. silenced: {
  1610. currentPage: 1,
  1611. pageSize: 20,
  1612. prevPage: 0,
  1613. totalLoaded: 0,
  1614. total: 0,
  1615. hasMore: true,
  1616. hasPrev: false
  1617. }
  1618. },
  1619. this.scrLoading = {
  1620. al: { next: false, prev: false },
  1621. online: { next: false, prev: false },
  1622. offline: { next: false, prev: false },
  1623. silenced: { next: false, prev: false }
  1624. }
  1625. },
  1626. resetMsgParams() {
  1627. // 消息参数保留
  1628. this.msgList = [];
  1629. this.msgParams = {
  1630. pageNum: 1,
  1631. pageSize: 30,
  1632. liveId: this.liveId
  1633. };
  1634. // 重置时不改变按钮状态,由后续的滚动逻辑决定
  1635. this.taskParams = {
  1636. currentPage: 1,
  1637. pageSize: 20,
  1638. prevPage: 0,
  1639. totalLoaded: 0,
  1640. total: 0,
  1641. hasMore: true,
  1642. hasPrev: false
  1643. }
  1644. },
  1645. getScrollElement(tabName) {
  1646. const scrollRefs = {
  1647. al: this.$refs.manageLeftRef_al,
  1648. online: this.$refs.manageLeftRef_online,
  1649. offline: this.$refs.manageLeftRef_offline,
  1650. silenced: this.$refs.manageLeftRef_silenced
  1651. };
  1652. return scrollRefs[tabName]?.wrap;
  1653. },
  1654. // 初始化滚动监听(在mounted中调用)
  1655. initScrollListeners() {
  1656. // 为每个Tab的滚动容器添加监听
  1657. this.$nextTick(() => {
  1658. const scrollRefs = {
  1659. al: this.$refs.manageLeftRef_al,
  1660. online: this.$refs.manageLeftRef_online,
  1661. offline: this.$refs.manageLeftRef_offline,
  1662. silenced: this.$refs.manageLeftRef_silenced
  1663. };
  1664. Object.keys(scrollRefs).forEach(tabName => {
  1665. const scrollEl = scrollRefs[tabName]?.wrap;
  1666. if (scrollEl) {
  1667. scrollEl.addEventListener('scroll', () =>
  1668. this.handleTabScroll(tabName, scrollEl)
  1669. );
  1670. }
  1671. });
  1672. });
  1673. },
  1674. // 处理Tab滚动事件(判断是否触底)
  1675. handleTabScroll(tabName, scrollEl) {
  1676. const { scrollTop, scrollHeight, clientHeight } = scrollEl;
  1677. const bottomThreshold = 50; // 距离底部100px触发下一页
  1678. const topThreshold = 50; // 距离顶部100px触发上一页
  1679. // 加载下一页(滚动到底部附近)
  1680. if (scrollHeight - scrollTop - clientHeight < bottomThreshold) {
  1681. this.loadNextPage(tabName);
  1682. }
  1683. // 加载上一页(滚动到顶部附近)
  1684. if (scrollTop < topThreshold) {
  1685. this.loadPrevPage(tabName);
  1686. }
  1687. },
  1688. // 恢复聊天滚动位置
  1689. restoreChatScrollPosition() {
  1690. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1691. this.$refs.manageRightRef.wrap.scrollTop = this.chatScrollTop;
  1692. }
  1693. },
  1694. // 保存聊天滚动位置
  1695. saveChatScrollPosition() {
  1696. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1697. this.chatScrollTop = this.$refs.manageRightRef.wrap.scrollHeight - this.$refs.manageRightRef.wrap.clientHeight;
  1698. }
  1699. },
  1700. /**
  1701. * 停止任务检测定时器
  1702. */
  1703. stopTaskTimer() {
  1704. if (this.taskTimer) {
  1705. clearInterval(this.taskTimer);
  1706. this.taskTimer = null;
  1707. }
  1708. },
  1709. /**
  1710. * 启动任务检测定时器
  1711. */
  1712. startTaskTimer() {
  1713. // 先清除已有定时器,避免重复
  1714. if (this.taskTimer) {
  1715. clearInterval(this.taskTimer);
  1716. }
  1717. // 立即执行一次检查
  1718. this.checkTaskExpiration();
  1719. // 启动定时器,定期检查
  1720. this.taskTimer = setInterval(() => {
  1721. this.checkTaskExpiration();
  1722. }, this.checkInterval);
  1723. },
  1724. /**
  1725. * 检查时间轴第一条任务是否过期
  1726. */
  1727. checkTaskExpiration() {
  1728. // 如果没有任务,直接返回
  1729. if (!this.timelineItems || this.timelineItems.length === 0) {
  1730. this.stopTaskTimer()
  1731. return;
  1732. };
  1733. // 获取第一条任务的时间
  1734. const firstTask = this.timelineItems[0];
  1735. const taskTime = new Date(firstTask.absValue).getTime();
  1736. const currentTime = new Date().getTime();
  1737. // 如果任务时间已过当前时间(过期),重新加载任务列表
  1738. if (taskTime < currentTime) {
  1739. this.timelineItems.shift()
  1740. this.loadLiveTask(); // 重新加载任务列表
  1741. }
  1742. },
  1743. },
  1744. beforeDestroy() {
  1745. if (this.autoMsgTimer != null) {
  1746. clearInterval(this.autoMsgTimer);
  1747. }
  1748. if (this.autoScrollTimer) {
  1749. clearTimeout(this.autoScrollTimer);
  1750. }
  1751. if (this.scrollDebounceTimer) {
  1752. clearTimeout(this.scrollDebounceTimer);
  1753. }
  1754. // 移除滚动监听器
  1755. if (this.$refs.manageRightRef && this.$refs.manageRightRef.wrap) {
  1756. this.$refs.manageRightRef.wrap.removeEventListener("scroll", this.manageRightScroll);
  1757. }
  1758. },
  1759. // 使用 deactivated 和 activated 钩子替代 beforeDestroy 和 destroyed
  1760. deactivated() {
  1761. this.saveChatScrollPosition();
  1762. },
  1763. activated() {
  1764. this.$nextTick(() => {
  1765. this.restoreChatScrollPosition();
  1766. });
  1767. // todo yhq
  1768. // this.$nextTick(() => {
  1769. // const video = this.$refs.videoPlayer;
  1770. // if (video != null) {
  1771. // this.initVideoPlayer(this.liveInfo.startTime)
  1772. // }
  1773. // })
  1774. },
  1775. };
  1776. </script>
  1777. <style scoped>
  1778. /* 布局 */
  1779. .console {
  1780. display: flex;
  1781. height: 100vh;
  1782. overflow: hidden;
  1783. background: #f5f7fa;
  1784. }
  1785. .left-panel,
  1786. .middle-panel,
  1787. .right-panel {
  1788. display: flex;
  1789. flex-direction: column;
  1790. padding: 16px;
  1791. box-sizing: border-box;
  1792. overflow: hidden;
  1793. }
  1794. .left-panel {
  1795. width: 28%;
  1796. border-right: 1px solid #ebeef5;
  1797. }
  1798. .middle-panel {
  1799. width: 42%;
  1800. border-right: 1px solid #ebeef5;
  1801. gap: 12px;
  1802. }
  1803. .right-panel {
  1804. width: 30%;
  1805. overflow-y: auto;
  1806. gap: 12px;
  1807. }
  1808. /* 通用标题与卡片 */
  1809. .panel-title {
  1810. margin: 0 0 12px;
  1811. font-size: 16px;
  1812. font-weight: 600;
  1813. color: #303133;
  1814. line-height: 1.4;
  1815. }
  1816. .section-title {
  1817. margin: 0;
  1818. font-size: 14px;
  1819. font-weight: 600;
  1820. color: #303133;
  1821. }
  1822. .section-subtitle {
  1823. margin: 0 0 8px;
  1824. font-size: 13px;
  1825. color: #909399;
  1826. }
  1827. .section-header {
  1828. display: flex;
  1829. align-items: center;
  1830. justify-content: space-between;
  1831. margin-bottom: 10px;
  1832. }
  1833. .panel-card {
  1834. background: #fff;
  1835. border: 1px solid #ebeef5;
  1836. border-radius: 4px;
  1837. padding: 12px;
  1838. box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  1839. }
  1840. .toolbar-label {
  1841. font-size: 13px;
  1842. color: #606266;
  1843. }
  1844. .action-link {
  1845. display: inline-block;
  1846. margin-right: 10px;
  1847. font-size: 12px;
  1848. color: #f56c6c;
  1849. cursor: pointer;
  1850. }
  1851. .action-link:hover {
  1852. opacity: 0.85;
  1853. }
  1854. .panel-footer {
  1855. display: flex;
  1856. justify-content: flex-end;
  1857. flex-wrap: wrap;
  1858. gap: 8px;
  1859. margin-top: 10px;
  1860. padding-top: 10px;
  1861. border-top: 1px solid #ebeef5;
  1862. }
  1863. /* 学员列表 */
  1864. .search-bar {
  1865. display: flex;
  1866. gap: 8px;
  1867. margin-bottom: 10px;
  1868. }
  1869. .search-bar .el-input {
  1870. flex: 1;
  1871. }
  1872. .console-tabs {
  1873. flex: 1;
  1874. min-height: 0;
  1875. }
  1876. .console-tabs ::v-deep .el-tabs__content {
  1877. height: calc(100% - 40px);
  1878. }
  1879. .console-tabs ::v-deep .el-tab-pane {
  1880. height: 100%;
  1881. }
  1882. .panel-scroll {
  1883. height: calc(100vh - 180px);
  1884. }
  1885. .user-list-item {
  1886. display: flex;
  1887. align-items: center;
  1888. gap: 10px;
  1889. padding: 10px 8px;
  1890. border-bottom: 1px solid #f2f6fc;
  1891. }
  1892. .user-list-item:hover {
  1893. background: #f5f7fa;
  1894. }
  1895. .user-meta {
  1896. flex: 1;
  1897. min-width: 0;
  1898. }
  1899. .user-name {
  1900. font-size: 13px;
  1901. color: #303133;
  1902. overflow: hidden;
  1903. text-overflow: ellipsis;
  1904. white-space: nowrap;
  1905. }
  1906. .user-id {
  1907. margin-top: 2px;
  1908. font-size: 12px;
  1909. color: #909399;
  1910. }
  1911. .user-more-btn {
  1912. color: #909399;
  1913. cursor: pointer;
  1914. padding: 4px;
  1915. }
  1916. .user-more-btn:hover {
  1917. color: #409eff;
  1918. }
  1919. /* 讨论区消息 */
  1920. .discussion-messages {
  1921. flex: 1;
  1922. min-height: 0;
  1923. display: flex;
  1924. flex-direction: column;
  1925. }
  1926. .message-container {
  1927. position: relative;
  1928. flex: 1;
  1929. min-height: 0;
  1930. }
  1931. .msg-scroll {
  1932. height: calc(100vh - 520px);
  1933. min-height: 180px;
  1934. }
  1935. .msg-item + .msg-item {
  1936. margin-top: 8px;
  1937. }
  1938. .msg-row {
  1939. display: flex;
  1940. align-items: flex-start;
  1941. gap: 8px;
  1942. }
  1943. .msg-row--self {
  1944. justify-content: flex-end;
  1945. }
  1946. .msg-content {
  1947. max-width: 72%;
  1948. }
  1949. .msg-content--self {
  1950. display: flex;
  1951. flex-direction: column;
  1952. align-items: flex-end;
  1953. }
  1954. .msg-nickname {
  1955. margin-bottom: 4px;
  1956. font-size: 12px;
  1957. color: #909399;
  1958. }
  1959. .msg-bubble {
  1960. padding: 8px 10px;
  1961. border-radius: 4px;
  1962. background: #f4f4f5;
  1963. font-size: 13px;
  1964. line-height: 1.5;
  1965. color: #303133;
  1966. word-break: break-word;
  1967. }
  1968. .msg-bubble--self {
  1969. background: #ecf5ff;
  1970. }
  1971. .msg-actions {
  1972. margin-top: 6px;
  1973. }
  1974. .msg-avatar {
  1975. flex-shrink: 0;
  1976. }
  1977. .scroll-bottom-space {
  1978. height: 16px;
  1979. }
  1980. .load-latest-btn {
  1981. position: absolute;
  1982. right: 12px;
  1983. bottom: 12px;
  1984. z-index: 2;
  1985. }
  1986. /* 营销 / 系统消息 */
  1987. .ops-panel {
  1988. flex-shrink: 0;
  1989. }
  1990. .ops-tabs ::v-deep .el-tabs__header {
  1991. margin-bottom: 10px;
  1992. }
  1993. .ops-tabs ::v-deep .el-tabs__content {
  1994. overflow: visible;
  1995. }
  1996. .marketing-panel,
  1997. .system-msg-panel {
  1998. display: flex;
  1999. flex-direction: column;
  2000. }
  2001. .marketing-toolbar {
  2002. display: flex;
  2003. align-items: center;
  2004. gap: 10px;
  2005. margin-bottom: 10px;
  2006. flex-wrap: wrap;
  2007. }
  2008. .marketing-tip {
  2009. flex: 1;
  2010. min-width: 200px;
  2011. padding: 4px 8px;
  2012. }
  2013. .marketing-tip ::v-deep .el-alert__title {
  2014. font-size: 12px;
  2015. }
  2016. .marketing-categories {
  2017. margin-bottom: 10px;
  2018. }
  2019. .marketing-scroll {
  2020. height: 150px;
  2021. }
  2022. .marketing-cards {
  2023. display: grid;
  2024. grid-template-columns: repeat(2, 1fr);
  2025. gap: 8px;
  2026. padding-right: 4px;
  2027. }
  2028. .marketing-card {
  2029. border: 1px solid #ebeef5;
  2030. border-radius: 4px;
  2031. overflow: hidden;
  2032. cursor: pointer;
  2033. background: #fff;
  2034. transition: border-color 0.2s;
  2035. }
  2036. .marketing-card:hover,
  2037. .marketing-card.selected {
  2038. border-color: #409eff;
  2039. }
  2040. .card-image-wrap {
  2041. position: relative;
  2042. height: 72px;
  2043. overflow: hidden;
  2044. background: #f5f7fa;
  2045. }
  2046. .card-image {
  2047. width: 100%;
  2048. height: 100%;
  2049. object-fit: cover;
  2050. }
  2051. .card-tags {
  2052. position: absolute;
  2053. top: 6px;
  2054. left: 6px;
  2055. display: flex;
  2056. gap: 4px;
  2057. }
  2058. .card-overlay {
  2059. position: absolute;
  2060. inset: 0;
  2061. display: flex;
  2062. flex-wrap: wrap;
  2063. align-items: center;
  2064. justify-content: center;
  2065. gap: 4px;
  2066. padding: 6px;
  2067. background: rgba(0, 0, 0, 0.5);
  2068. opacity: 0;
  2069. transition: opacity 0.2s;
  2070. }
  2071. .marketing-card:hover .card-overlay {
  2072. opacity: 1;
  2073. }
  2074. .card-info {
  2075. padding: 6px 8px;
  2076. }
  2077. .card-title {
  2078. font-size: 12px;
  2079. color: #303133;
  2080. overflow: hidden;
  2081. text-overflow: ellipsis;
  2082. white-space: nowrap;
  2083. }
  2084. .card-bottom {
  2085. display: flex;
  2086. align-items: center;
  2087. justify-content: space-between;
  2088. margin-top: 4px;
  2089. }
  2090. .card-price {
  2091. font-size: 12px;
  2092. font-weight: 600;
  2093. color: #f56c6c;
  2094. }
  2095. .marketing-list {
  2096. display: flex;
  2097. flex-direction: column;
  2098. gap: 8px;
  2099. padding-right: 4px;
  2100. }
  2101. .marketing-list-item {
  2102. display: flex;
  2103. align-items: center;
  2104. justify-content: space-between;
  2105. gap: 10px;
  2106. padding: 10px;
  2107. border: 1px solid #ebeef5;
  2108. border-radius: 4px;
  2109. background: #fff;
  2110. cursor: pointer;
  2111. transition: border-color 0.2s;
  2112. }
  2113. .marketing-list-item:hover,
  2114. .marketing-list-item.selected {
  2115. border-color: #409eff;
  2116. background: #f5f9ff;
  2117. }
  2118. .list-main {
  2119. flex: 1;
  2120. min-width: 0;
  2121. }
  2122. .list-title {
  2123. font-size: 13px;
  2124. color: #303133;
  2125. overflow: hidden;
  2126. text-overflow: ellipsis;
  2127. white-space: nowrap;
  2128. }
  2129. .list-meta {
  2130. margin-top: 4px;
  2131. font-size: 12px;
  2132. color: #909399;
  2133. overflow: hidden;
  2134. text-overflow: ellipsis;
  2135. white-space: nowrap;
  2136. }
  2137. .list-price {
  2138. margin-right: 6px;
  2139. color: #f56c6c;
  2140. font-weight: 600;
  2141. }
  2142. .list-tags {
  2143. display: flex;
  2144. flex-wrap: wrap;
  2145. gap: 4px;
  2146. margin-top: 6px;
  2147. }
  2148. .list-actions {
  2149. display: flex;
  2150. flex-shrink: 0;
  2151. flex-wrap: wrap;
  2152. gap: 4px;
  2153. justify-content: flex-end;
  2154. }
  2155. /* 右侧运营工具 */
  2156. .live-player,
  2157. .automation,
  2158. .watermark {
  2159. margin: 0;
  2160. }
  2161. .timeline-items {
  2162. margin-top: 4px;
  2163. }
  2164. .timeline-item {
  2165. display: flex;
  2166. align-items: center;
  2167. justify-content: space-between;
  2168. gap: 8px;
  2169. padding: 8px 0;
  2170. border-bottom: 1px solid #f2f6fc;
  2171. }
  2172. .timeline-time {
  2173. font-size: 12px;
  2174. color: #909399;
  2175. }
  2176. .timeline-action {
  2177. margin-top: 2px;
  2178. font-size: 13px;
  2179. color: #303133;
  2180. }
  2181. .watermark-options {
  2182. display: flex;
  2183. align-items: center;
  2184. flex-wrap: wrap;
  2185. gap: 8px;
  2186. margin-top: 10px;
  2187. }
  2188. /* 滚动条 */
  2189. ::v-deep .el-scrollbar__wrap {
  2190. overflow-x: hidden !important;
  2191. }
  2192. </style>
  2193. <style>
  2194. .user-action-popover .action-link {
  2195. display: block;
  2196. margin: 0 0 8px;
  2197. font-size: 13px;
  2198. color: #f56c6c;
  2199. cursor: pointer;
  2200. }
  2201. .user-action-popover .action-link:last-child {
  2202. margin-bottom: 0;
  2203. }
  2204. </style>