LiveDashboard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <div class="dashboard-page">
  3. <!-- 顶栏 -->
  4. <header class="dash-header">
  5. <div class="header-left">
  6. <h1 class="live-title">{{ liveName || '直播实时大屏' }}</h1>
  7. <div class="meta-tags">
  8. <span class="tag" v-if="startTime">
  9. <i class="el-icon-time"></i> 开播 {{ formatTime(startTime) }}
  10. </span>
  11. <span class="tag tag-live" v-if="!liveDataFrozen">直播中</span>
  12. <span class="tag tag-frozen" v-if="liveDataFrozen">直播数据已冻结</span>
  13. <span class="tag tag-frozen" v-if="replayDataFrozen && liveStatus === 4">回放数据已冻结</span>
  14. </div>
  15. </div>
  16. <div class="header-right">
  17. <span class="refresh-tip">{{ lastRefreshText }}</span>
  18. <el-button type="primary" size="small" icon="el-icon-refresh" :loading="loading" @click="refreshData">
  19. 刷新数据
  20. </el-button>
  21. </div>
  22. </header>
  23. <!-- 互动指标 -->
  24. <section class="section">
  25. <div class="section-title">实时互动</div>
  26. <div class="metric-grid metric-grid-4">
  27. <div class="metric-card accent-blue" v-for="item in interactionCards" :key="item.label">
  28. <div class="metric-icon">{{ item.icon }}</div>
  29. <div class="metric-body">
  30. <div class="metric-label">{{ item.label }}</div>
  31. <div class="metric-value">{{ item.value }}</div>
  32. <div class="metric-sub" v-if="item.sub">{{ item.sub }}</div>
  33. </div>
  34. </div>
  35. </div>
  36. </section>
  37. <!-- 订单整体数据 -->
  38. <section class="section">
  39. <div class="section-title">订单整体数据</div>
  40. <div class="metric-grid metric-grid-4">
  41. <div class="metric-card" v-for="item in orderCards" :key="item.label">
  42. <div class="metric-label">{{ item.label }}</div>
  43. <div class="metric-value" :class="{ money: item.isMoney }">{{ item.value }}</div>
  44. </div>
  45. </div>
  46. </section>
  47. <!-- 商品数据 + 邀请榜 -->
  48. <section class="section section-split">
  49. <div class="panel product-panel">
  50. <div class="section-title">商品数据</div>
  51. <el-table
  52. :data="productStats"
  53. size="small"
  54. height="320"
  55. class="dark-table"
  56. empty-text="暂无商品订单数据">
  57. <el-table-column prop="productName" label="商品" min-width="120" show-overflow-tooltip />
  58. <el-table-column prop="totalOrderCount" label="累计下单" width="80" align="center" />
  59. <el-table-column label="累计金额" width="100" align="right">
  60. <template slot-scope="{ row }">{{ formatMoney(row.totalOrderAmount) }}</template>
  61. </el-table-column>
  62. <el-table-column prop="paidOrderCount" label="成交数" width="70" align="center" />
  63. <el-table-column label="成交额" width="100" align="right">
  64. <template slot-scope="{ row }">{{ formatMoney(row.paidOrderAmount) }}</template>
  65. </el-table-column>
  66. <el-table-column prop="unpaidOrderCount" label="待支付" width="70" align="center" />
  67. <el-table-column prop="refundApplyCount" label="退款申请" width="80" align="center" />
  68. </el-table>
  69. </div>
  70. <div class="panel rank-panel">
  71. <div class="section-title">
  72. 销售邀请榜
  73. <span class="invite-total">共 {{ totalInviteCount }} 人</span>
  74. </div>
  75. <ul class="rank-list" v-if="rankList.length">
  76. <li v-for="(item, index) in rankList" :key="index" class="rank-item">
  77. <span class="rank-badge" :class="'rank-' + (index + 1)">{{ index + 1 }}</span>
  78. <span class="rank-name">{{ item.userName || '未知销售' }}</span>
  79. <span class="rank-count">{{ item.inviteNum }} 人</span>
  80. </li>
  81. </ul>
  82. <div class="empty-rank" v-else>暂无邀请数据</div>
  83. </div>
  84. </section>
  85. </div>
  86. </template>
  87. <script>
  88. import { dashboardData } from '@/api/live/liveData'
  89. export default {
  90. props: {
  91. liveId: { type: String, default: null }
  92. },
  93. data() {
  94. return {
  95. loading: false,
  96. liveName: '',
  97. startTime: null,
  98. liveStatus: null,
  99. liveDataFrozen: false,
  100. replayDataFrozen: false,
  101. totalInviteCount: 0,
  102. interactionCards: [],
  103. orderCards: [],
  104. productStats: [],
  105. rankList: [],
  106. lastRefreshAt: null,
  107. nowTick: Date.now(),
  108. timer: null,
  109. tickTimer: null
  110. }
  111. },
  112. computed: {
  113. lastRefreshText() {
  114. if (!this.lastRefreshAt) return '等待首次加载'
  115. const diff = Math.max(0, Math.floor((this.nowTick - this.lastRefreshAt) / 1000))
  116. if (diff < 60) return `${diff} 秒前更新`
  117. return `${Math.floor(diff / 60)} 分钟前更新`
  118. }
  119. },
  120. created() {
  121. this.refreshData()
  122. this.timer = setInterval(() => this.refreshData(), 30000)
  123. this.tickTimer = setInterval(() => {
  124. this.nowTick = Date.now()
  125. }, 1000)
  126. },
  127. beforeDestroy() {
  128. if (this.timer) clearInterval(this.timer)
  129. if (this.tickTimer) clearInterval(this.tickTimer)
  130. },
  131. methods: {
  132. refreshData() {
  133. if (!this.liveId) return
  134. this.loading = true
  135. dashboardData(this.liveId).then(res => {
  136. if (res.code === 200 && res.data) {
  137. this.applyData(res.data)
  138. this.lastRefreshAt = Date.now()
  139. }
  140. }).finally(() => {
  141. this.loading = false
  142. })
  143. },
  144. applyData(data) {
  145. this.liveName = data.liveName || ''
  146. this.startTime = data.startTime || null
  147. this.liveStatus = data.liveStatus
  148. this.liveDataFrozen = !!data.liveDataFrozen
  149. this.replayDataFrozen = !!data.replayDataFrozen
  150. this.totalInviteCount = data.totalInviteCount || 0
  151. this.rankList = data.inviteUserList || []
  152. this.productStats = data.productStats || []
  153. const totalView = (data.liveViewNum || 0) + (data.replayViewNum || 0)
  154. const totalLike = (data.liveLikeNum || 0) + (data.replayLikeNum || 0)
  155. const totalComment = Number(data.liveCommentNum || 0) + Number(data.replayCommentNum || 0)
  156. this.interactionCards = [
  157. { icon: '👁', label: '实时在线', value: data.onlineNum || 0, sub: `离线 ${data.offlineNum || 0}` },
  158. { icon: '📊', label: '累计观看人数', value: data.uniqueViewCount || 0, sub: `人次 ${totalView}` },
  159. { icon: '👍', label: '累计点赞', value: totalLike, sub: `直播 ${data.liveLikeNum || 0} / 回放 ${data.replayLikeNum || 0}` },
  160. { icon: '💬', label: '累计评论', value: totalComment, sub: `直播 ${data.liveCommentNum || 0} / 回放 ${data.replayCommentNum || 0}` }
  161. ]
  162. const os = data.orderStats || {}
  163. this.orderCards = [
  164. { label: '累计下单数', value: os.totalOrderCount || 0 },
  165. { label: '累计下单金额', value: this.formatMoney(os.totalOrderAmount), isMoney: true },
  166. { label: '现存成交订单数', value: os.paidOrderCount || 0 },
  167. { label: '现存成交额', value: this.formatMoney(os.paidOrderAmount), isMoney: true },
  168. { label: '申请退款订单数', value: os.refundApplyCount || 0 },
  169. { label: '申请退款金额', value: this.formatMoney(os.refundApplyAmount), isMoney: true },
  170. { label: '待支付订单数', value: os.unpaidOrderCount || 0 },
  171. { label: '待支付金额', value: this.formatMoney(os.unpaidOrderAmount), isMoney: true }
  172. ]
  173. },
  174. formatMoney(val) {
  175. const num = Number(val || 0)
  176. return '¥' + num.toFixed(2)
  177. },
  178. formatTime(val) {
  179. if (!val) return '-'
  180. const d = new Date(val)
  181. if (isNaN(d.getTime())) return val
  182. const p = n => String(n).padStart(2, '0')
  183. return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
  184. }
  185. }
  186. }
  187. </script>
  188. <style scoped>
  189. .dashboard-page {
  190. min-height: 92vh;
  191. background: #f5f8fc;
  192. color: #334155;
  193. padding: 20px 24px;
  194. box-sizing: border-box;
  195. overflow-y: auto;
  196. }
  197. .dash-header {
  198. display: flex;
  199. justify-content: space-between;
  200. align-items: flex-start;
  201. margin-bottom: 20px;
  202. padding-bottom: 14px;
  203. border-bottom: 1px solid #e8eef5;
  204. }
  205. .live-title {
  206. font-size: 20px;
  207. font-weight: 600;
  208. margin: 0 0 8px;
  209. color: #1e293b;
  210. }
  211. .meta-tags {
  212. display: flex;
  213. gap: 8px;
  214. flex-wrap: wrap;
  215. }
  216. .tag {
  217. font-size: 12px;
  218. padding: 3px 10px;
  219. border-radius: 20px;
  220. background: #eef2f7;
  221. color: #64748b;
  222. }
  223. .tag-live {
  224. background: #ecfdf5;
  225. color: #059669;
  226. }
  227. .tag-frozen {
  228. background: #fffbeb;
  229. color: #d97706;
  230. }
  231. .header-right {
  232. display: flex;
  233. align-items: center;
  234. gap: 12px;
  235. }
  236. .refresh-tip {
  237. font-size: 12px;
  238. color: #94a3b8;
  239. }
  240. .section {
  241. margin-bottom: 18px;
  242. }
  243. .section-title {
  244. font-size: 14px;
  245. font-weight: 600;
  246. color: #64748b;
  247. margin-bottom: 12px;
  248. letter-spacing: 0.3px;
  249. }
  250. .section-split {
  251. display: grid;
  252. grid-template-columns: 1fr 340px;
  253. gap: 16px;
  254. }
  255. .metric-grid {
  256. display: grid;
  257. gap: 12px;
  258. }
  259. .metric-grid-4 {
  260. grid-template-columns: repeat(4, 1fr);
  261. }
  262. @media (max-width: 1200px) {
  263. .metric-grid-4 { grid-template-columns: repeat(2, 1fr); }
  264. .section-split { grid-template-columns: 1fr; }
  265. }
  266. .metric-card {
  267. background: #fff;
  268. border: 1px solid #e8eef5;
  269. border-radius: 12px;
  270. padding: 16px;
  271. box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  272. transition: border-color 0.2s, box-shadow 0.2s;
  273. }
  274. .metric-card:hover {
  275. border-color: #c7d7fe;
  276. box-shadow: 0 4px 12px rgba(99, 102, 241, 0.08);
  277. }
  278. .metric-card.accent-blue {
  279. display: flex;
  280. align-items: center;
  281. gap: 12px;
  282. }
  283. .metric-icon {
  284. font-size: 28px;
  285. line-height: 1;
  286. }
  287. .metric-label {
  288. font-size: 12px;
  289. color: #94a3b8;
  290. margin-bottom: 6px;
  291. }
  292. .metric-value {
  293. font-size: 24px;
  294. font-weight: 700;
  295. color: #1e293b;
  296. line-height: 1.2;
  297. }
  298. .metric-value.money {
  299. color: #ea580c;
  300. }
  301. .metric-sub {
  302. font-size: 11px;
  303. color: #94a3b8;
  304. margin-top: 4px;
  305. }
  306. .panel {
  307. background: #fff;
  308. border: 1px solid #e8eef5;
  309. border-radius: 12px;
  310. padding: 16px;
  311. box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  312. }
  313. .invite-total {
  314. font-size: 12px;
  315. font-weight: 400;
  316. color: #4f46e5;
  317. margin-left: 8px;
  318. }
  319. .rank-list {
  320. list-style: none;
  321. padding: 0;
  322. margin: 0;
  323. max-height: 320px;
  324. overflow-y: auto;
  325. }
  326. .rank-item {
  327. display: flex;
  328. align-items: center;
  329. padding: 10px 8px;
  330. border-bottom: 1px solid #f1f5f9;
  331. font-size: 13px;
  332. }
  333. .rank-badge {
  334. width: 24px;
  335. height: 24px;
  336. border-radius: 6px;
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. font-size: 12px;
  341. font-weight: 700;
  342. background: #f1f5f9;
  343. color: #64748b;
  344. flex-shrink: 0;
  345. }
  346. .rank-1 { background: #fef3c7; color: #b45309; }
  347. .rank-2 { background: #e2e8f0; color: #475569; }
  348. .rank-3 { background: #ffedd5; color: #c2410c; }
  349. .rank-name {
  350. flex: 1;
  351. margin: 0 12px;
  352. color: #334155;
  353. overflow: hidden;
  354. text-overflow: ellipsis;
  355. white-space: nowrap;
  356. }
  357. .rank-count {
  358. color: #4f46e5;
  359. font-weight: 600;
  360. }
  361. .empty-rank {
  362. text-align: center;
  363. color: #94a3b8;
  364. padding: 40px 0;
  365. font-size: 13px;
  366. }
  367. .dark-table {
  368. background: transparent !important;
  369. }
  370. .dark-table >>> .el-table {
  371. background: transparent;
  372. color: #334155;
  373. }
  374. .dark-table >>> .el-table th {
  375. background: #f8fafc !important;
  376. color: #64748b;
  377. border-bottom: 1px solid #e8eef5;
  378. }
  379. .dark-table >>> .el-table td {
  380. background: #fff !important;
  381. border-bottom: 1px solid #f1f5f9;
  382. }
  383. .dark-table >>> .el-table tr {
  384. background: #fff !important;
  385. }
  386. .dark-table >>> .el-table--enable-row-hover .el-table__body tr:hover > td {
  387. background: #f8fafc !important;
  388. }
  389. .dark-table >>> .el-table::before {
  390. display: none;
  391. }
  392. </style>