play_info.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <el-container class="play-info-container">
  3. <el-header style="height: auto; padding: 20px;">
  4. <el-row :gutter="20">
  5. <el-col :span="12">
  6. <el-card shadow="hover" class="stat-card overview-card">
  7. <!-- <template #header>
  8. <div class="card-header">
  9. <span>发布趋势</span>
  10. </div>
  11. </template>-->
  12. <el-row :gutter="20" align="middle">
  13. <el-col :span="8" class="text-center">
  14. <div class="stat-number total-num">{{ totalNum }}</div>
  15. <div class="stat-label">总发布量</div>
  16. </el-col>
  17. <el-col :span="16">
  18. <div ref="pushLine" style="height: 120px"></div>
  19. </el-col>
  20. </el-row>
  21. </el-card>
  22. </el-col>
  23. <el-col :span="6">
  24. <el-card shadow="hover" class="stat-card">
  25. <div class="stat-content">
  26. <el-icon class="stat-icon icon-image"><Picture /></el-icon>
  27. <div>
  28. <div class="stat-number image-num">{{ imageNum }}</div>
  29. <div class="stat-label">图片发布</div>
  30. </div>
  31. </div>
  32. </el-card>
  33. </el-col>
  34. <el-col :span="6">
  35. <el-card shadow="hover" class="stat-card">
  36. <div class="stat-content">
  37. <el-icon class="stat-icon icon-video"><VideoCameraFilled /></el-icon>
  38. <div>
  39. <div class="stat-number video-num">{{ videoNum }}</div>
  40. <div class="stat-label">视频发布</div>
  41. </div>
  42. </div>
  43. </el-card>
  44. </el-col>
  45. </el-row>
  46. </el-header>
  47. <el-main style="padding: 0 20px;height: 80vh">
  48. <el-card shadow="hover">
  49. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  50. <el-row justify="space-between" align="middle" style="width: 100%">
  51. <el-form-item prop="sourceName">
  52. <el-input v-model="queryParams.sourceName" placeholder="请输入文件名称" @input="getRecordList" clearable />
  53. </el-form-item>
  54. <el-form-item prop="sourceType">
  55. <el-select v-model="queryParams.sourceType" placeholder="请选择类型" @change="getRecordList" clearable>
  56. <el-option v-for="dict in smsb_source_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item prop="sourceTag">
  60. <el-select v-model="queryParams.sourceTag" placeholder="请选择分类" @change="getRecordList" clearable>
  61. <el-option v-for="dict in smsb_source_classify" :key="dict.value" :label="dict.label" :value="dict.value" />
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item prop="dataRage">
  65. <el-radio-group v-model="timeRadio" @change="handleDateRangeChange" style="margin-right: 10px;">
  66. <el-radio-button label="近7天" value="week" />
  67. <el-radio-button label="近30天" value="month" />
  68. <el-radio-button label="自定义" value="diy" />
  69. </el-radio-group>
  70. <el-date-picker v-model="dateRange" type="daterange" range-separator="-" start-placeholder="开始日期"
  71. end-placeholder="结束日期" :disabled="diyFlag" :clearable="false" @change="handleDateRangeChange" />
  72. </el-form-item>
  73. <el-button type="warning" plain icon="Download" style="margin-bottom: 15px" @click="handleExport">报表导出
  74. </el-button>
  75. </el-row>
  76. </el-form>
  77. <div class="table-content" style="margin-top: 10px;">
  78. <el-table v-loading="loading" :data="playRecordList" row-key="sourceId" header-cell-class-name="table-header">
  79. <el-table-column label="资源ID" prop="sourceId" width="250" />
  80. <el-table-column label="资源名称" prop="fileName" :show-overflow-tooltip="true" />
  81. <el-table-column label="播放次数" align="center" prop="playTimes" width="150" />
  82. <el-table-column label="播放时长" align="center" prop="playDuration" width="150" />
  83. <el-table-column label="分类" align="center" prop="fileTag" width="120">
  84. <template #default="scope">
  85. <dict-tag :options="smsb_source_classify" :value="scope.row.fileTag" />
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="类型" align="center" prop="fileType" width="120">
  89. <template #default="scope">
  90. <dict-tag :options="smsb_source_type" :value="scope.row.fileType" />
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
  94. <template #default="scope">
  95. <el-button link type="primary" icon="View" @click="handleView(scope.row)">查看详情</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. </div>
  100. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
  101. v-model:limit="queryParams.pageSize" @pagination="getRecordList" />
  102. </el-card>
  103. </el-main>
  104. </el-container>
  105. <el-dialog :title="dialog.title" v-model="dialog.visible" width="70%" top="5vh" append-to-body
  106. custom-class="details-dialog">
  107. <el-container>
  108. <el-header style="height: auto; padding-bottom: 20px;">
  109. <el-row justify="end">
  110. <el-radio-group v-model="DTimeRadio" size="small" @change="DHandleDateRangeChange" style="margin-right: 10px;">
  111. <el-radio-button label="近7天" value="week" />
  112. <el-radio-button label="近30天" value="month" />
  113. </el-radio-group>
  114. <!-- <el-date-picker style="width: 280px" :disabled="true" v-model="DDateRange" type="daterange" range-separator="-"
  115. start-placeholder="开始日期" end-placeholder="结束日期" size="small" />-->
  116. </el-row>
  117. </el-header>
  118. <el-main style="padding: 0;">
  119. <el-card shadow="never" style="margin-bottom: 20px;">
  120. <div ref="tadLine" class="chart-placeholder"></div>
  121. </el-card>
  122. <div style="width: 100%">
  123. <el-row>
  124. <el-col :span="12">
  125. <el-card shadow="never">
  126. <template #header>
  127. <div class="card-header">
  128. <span>设备播放统计</span>
  129. </div>
  130. </template>
  131. <el-table v-loading="loading" :data="deviceRecordList" height="250px">
  132. <el-table-column label="设备名称" align="center" prop="deviceName" />
  133. <el-table-column label="播放次数" align="center" prop="playTimes" />
  134. <el-table-column label="播放时长" align="center" prop="duration" />
  135. </el-table>
  136. </el-card>
  137. </el-col>
  138. <el-col :span="12">
  139. <el-card shadow="never">
  140. <template #header>
  141. <div class="card-header">
  142. <span>节目播放统计</span>
  143. </div>
  144. </template>
  145. <el-table v-loading="loading" :data="itemRecordList" height="250px">
  146. <el-table-column label="组名称" align="center" prop="itemName" />
  147. <el-table-column label="类型" align="center" prop="itemType">
  148. <template #default="scope">
  149. <dict-tag :options="smsb_item_type" :value="scope.row.itemType" />
  150. </template>
  151. </el-table-column>
  152. <el-table-column label="播放次数" align="center" prop="playTimes" />
  153. <el-table-column label="播放时长" align="center" prop="duration" />
  154. </el-table>
  155. </el-card>
  156. </el-col>
  157. </el-row>
  158. </div>
  159. </el-main>
  160. </el-container>
  161. </el-dialog>
  162. </template>
  163. <script setup lang="ts">
  164. import * as echarts from 'echarts';
  165. import {
  166. getPushLine,
  167. listDeviceAndItem,
  168. listPlayRecordSummary,
  169. pushNumber,
  170. timesAndDurationLine
  171. } from '@/api/smsb/source/play_record';
  172. import {SourcePlayRecordForm, SourcePlayRecordQuery, SourcePlayRecordVO} from '@/api/smsb/source/play_record_type';
  173. import {onUnmounted} from 'vue';
  174. import {Picture, VideoCameraFilled} from '@element-plus/icons-vue';
  175. const {proxy} = getCurrentInstance() as ComponentInternalInstance;
  176. const {smsb_source_classify, smsb_source_type, smsb_item_type} = toRefs<any>(
  177. proxy?.useDict('smsb_source_classify', 'smsb_source_type', 'smsb_item_type')
  178. );
  179. const loading = ref(true);
  180. const playRecordList = ref<SourcePlayRecordVO[]>([]);
  181. const deviceRecordList = ref<SourcePlayRecordVO[]>([]);
  182. const itemRecordList = ref<SourcePlayRecordVO[]>([]);
  183. const timeRadio = ref('week');
  184. const DTimeRadio = ref('week');
  185. const dateRange = ref<(string | Date)[]>([]);
  186. const DDateRange = ref<(string | Date)[]>([]);
  187. const totalNum = ref(0);
  188. const imageNum = ref(0);
  189. const videoNum = ref(0);
  190. const pushLine = ref();
  191. const total = ref(0);
  192. const tadLine = ref();
  193. const dialogSourceId = ref();
  194. const diyFlag = ref(true);
  195. const dialog = reactive<DialogOption>({
  196. visible: false,
  197. title: ''
  198. });
  199. const data = reactive<PageData<SourcePlayRecordForm, SourcePlayRecordQuery>>({
  200. form: {},
  201. queryParams: {
  202. pageNum: 1,
  203. pageSize: 10,
  204. sourceType: null,
  205. sourceTag: null,
  206. startTime: null,
  207. endTime: null,
  208. sourceName: null
  209. },
  210. rules: {}
  211. });
  212. // ★★★★★【美化核心】: 定义通用的 ECharts 美化配置 ★★★★★
  213. const getBaseChartOptions = () => ({
  214. grid: {
  215. left: '5%',
  216. right: '5%',
  217. bottom: '10%',
  218. top: '15%',
  219. containLabel: true
  220. },
  221. tooltip: {
  222. trigger: 'axis',
  223. backgroundColor: 'rgba(255, 255, 255, 0.9)',
  224. borderColor: '#E5E5E5',
  225. borderWidth: 1,
  226. textStyle: {
  227. color: '#333'
  228. },
  229. axisPointer: {
  230. type: 'cross',
  231. label: {
  232. backgroundColor: '#6a7985'
  233. }
  234. }
  235. },
  236. toolbox: {
  237. show: false,
  238. feature: {
  239. saveAsImage: {
  240. title: '保存图片',
  241. pixelRatio: 2
  242. }
  243. },
  244. right: '20px'
  245. },
  246. xAxis: {
  247. type: 'category',
  248. boundaryGap: false,
  249. axisLine: {
  250. show: false
  251. },
  252. axisTick: {
  253. show: false
  254. },
  255. axisLabel: {
  256. color: '#888'
  257. }
  258. },
  259. yAxis: {
  260. type: 'value',
  261. axisLabel: {
  262. color: '#888'
  263. },
  264. splitLine: {
  265. lineStyle: {
  266. type: 'dashed',
  267. color: '#E5E5E5'
  268. }
  269. }
  270. },
  271. legend: {
  272. data: [],
  273. right: 'center',
  274. top: '5px',
  275. textStyle: {
  276. color: '#555'
  277. }
  278. }
  279. });
  280. const getTimesAndDurationLine = async () => {
  281. const params = {
  282. startTime: DDateRange.value[0],
  283. endTime: DDateRange.value[1],
  284. sourceId: dialogSourceId.value
  285. };
  286. const res = await timesAndDurationLine(params);
  287. const playDurationList = res.data.playDurationList.map((seconds: number) => Math.round((seconds / 60) * 100) / 100);
  288. if (tadLine.value) {
  289. echarts.dispose(tadLine.value);
  290. }
  291. const tadLineInstance = echarts.init(tadLine.value, 'macaroons');
  292. // 合并通用配置和特定配置
  293. const option = {
  294. ...getBaseChartOptions(),
  295. legend: {
  296. ...getBaseChartOptions().legend,
  297. data: ['播放次数', '播放时长(分钟)']
  298. },
  299. xAxis: {
  300. ...getBaseChartOptions().xAxis,
  301. data: res.data.timeList
  302. },
  303. series: [
  304. {
  305. name: '播放次数',
  306. type: 'line',
  307. smooth: true,
  308. showSymbol: false,
  309. itemStyle: { color: '#5470C6' },
  310. areaStyle: {
  311. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  312. { offset: 0, color: 'rgba(84, 112, 198, 0.4)' },
  313. { offset: 1, color: 'rgba(84, 112, 198, 0)' }
  314. ])
  315. },
  316. data: res.data.playTimesList
  317. },
  318. {
  319. name: '播放时长(分钟)',
  320. type: 'line',
  321. smooth: true,
  322. showSymbol: false,
  323. itemStyle: { color: '#91CC75' },
  324. areaStyle: {
  325. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  326. { offset: 0, color: 'rgba(145, 204, 117, 0.4)' },
  327. { offset: 1, color: 'rgba(145, 204, 117, 0)' }
  328. ])
  329. },
  330. data: playDurationList
  331. }
  332. ]
  333. };
  334. tadLineInstance.setOption(option);
  335. };
  336. const { queryParams, form, rules } = toRefs(data);
  337. // ★★★★★【应用美化】: 修改 getPushNumber 函数 ★★★★★
  338. const getPushNumber = async () => {
  339. const res = await pushNumber();
  340. totalNum.value = res.data.totalNum;
  341. imageNum.value = res.data.imageNum;
  342. videoNum.value = res.data.videoNum;
  343. const lineRes = await getPushLine();
  344. if (pushLine.value) {
  345. echarts.dispose(pushLine.value);
  346. }
  347. const pushLineInstance = echarts.init(pushLine.value, 'macaroons');
  348. // 合并通用配置和特定配置
  349. const option = {
  350. ...getBaseChartOptions(),
  351. grid: { // 针对小图表微调 grid
  352. left: '3%',
  353. right: '4%',
  354. bottom: '5%',
  355. top: '10%',
  356. containLabel: true
  357. },
  358. tooltip: { // 微调 tooltip
  359. ...getBaseChartOptions().tooltip
  360. },
  361. legend: {}, // 这个图表不需要 legend
  362. xAxis: {
  363. ...getBaseChartOptions().xAxis,
  364. data: lineRes.data.timeList
  365. },
  366. yAxis: {
  367. ...getBaseChartOptions().yAxis,
  368. axisLabel: { show: false }, // 小图表可以隐藏y轴标签
  369. splitLine: { show: false } // 隐藏分割线
  370. },
  371. series: [
  372. {
  373. name: '发布量',
  374. type: 'line',
  375. smooth: true,
  376. showSymbol: false,
  377. itemStyle: { color: '#34a853' }, // 与总发布量颜色一致
  378. areaStyle: {
  379. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  380. { offset: 0, color: 'rgba(52, 168, 83, 0.4)' },
  381. { offset: 1, color: 'rgba(52, 168, 83, 0)' }
  382. ])
  383. },
  384. data: lineRes.data.numberList
  385. }
  386. ]
  387. };
  388. pushLineInstance.setOption(option);
  389. };
  390. /** 导出按钮操作 */
  391. const handleExport = () => {
  392. proxy?.download(
  393. 'source/playRecord/summary/export',
  394. {
  395. ...queryParams.value
  396. },
  397. `playRecord_${new Date().getTime()}.xlsx`
  398. );
  399. };
  400. const handleView = async (row?: SourcePlayRecordVO) => {
  401. dialog.title = "详情 - " + row.fileName;
  402. dialog.visible = true;
  403. dialogSourceId.value = row.sourceId;
  404. DHandleDateRangeChange();
  405. };
  406. const getDeviceItemList = async () => {
  407. const params = {
  408. startTime: DDateRange.value[0],
  409. endTime: DDateRange.value[1],
  410. sourceId: dialogSourceId.value
  411. };
  412. const res = await listDeviceAndItem(params);
  413. deviceRecordList.value = res.data.deviceList;
  414. itemRecordList.value = res.data.itemList;
  415. };
  416. /** 查询资源播放记录列表 */
  417. const getRecordList = async () => {
  418. loading.value = true;
  419. queryParams.value.startTime = dateRange.value[0] as string;
  420. queryParams.value.endTime = dateRange.value[1] as string;
  421. const res = await listPlayRecordSummary(queryParams.value);
  422. playRecordList.value = res.rows;
  423. playRecordList.value.forEach((item) => {
  424. item.playDuration = formatDuration(item.playDuration);
  425. });
  426. total.value = res.total;
  427. loading.value = false;
  428. };
  429. // 格式化秒数为 HH:mm:ss
  430. const formatDuration = (seconds: number | null | undefined): string => {
  431. if (seconds === null || seconds === undefined) return '00:00:00';
  432. const hours = Math.floor(seconds / 3600);
  433. const minutes = Math.floor((seconds % 3600) / 60);
  434. const secs = seconds % 60;
  435. const paddedHours = String(hours).padStart(2, '0');
  436. const paddedMinutes = String(minutes).padStart(2, '0');
  437. const paddedSeconds = String(Math.round(secs)).padStart(2, '0');
  438. return `${paddedHours}:${paddedMinutes}:${paddedSeconds}`;
  439. };
  440. const formatDate = (date: Date | string): string => {
  441. if (!date) return '';
  442. const d = new Date(date);
  443. const year = d.getFullYear();
  444. const month = String(d.getMonth() + 1).padStart(2, '0');
  445. const day = String(d.getDate()).padStart(2, '0');
  446. return `${year}-${month}-${day}`;
  447. };
  448. const handleDateRangeChange = () => {
  449. const rangeType = timeRadio.value;
  450. const today = new Date();
  451. let startDate = new Date();
  452. const endDate = new Date();
  453. switch (rangeType) {
  454. case 'week':
  455. startDate.setDate(today.getDate() - 7);
  456. dateRange.value = [formatDate(startDate), formatDate(endDate)];
  457. diyFlag.value = true;
  458. break;
  459. case 'month':
  460. startDate.setMonth(today.getMonth() - 1);
  461. dateRange.value = [formatDate(startDate), formatDate(endDate)];
  462. diyFlag.value = true;
  463. break;
  464. case "diy" :
  465. diyFlag.value = false;
  466. if (dateRange.value && dateRange.value.length === 2) {
  467. dateRange.value = [formatDate(dateRange.value[0]), formatDate(dateRange.value[1])];
  468. }
  469. break;
  470. default:
  471. break
  472. }
  473. getRecordList();
  474. getPushNumber();
  475. };
  476. const DHandleDateRangeChange = () => {
  477. const rangeType = DTimeRadio.value;
  478. const today = new Date();
  479. let startDate = new Date();
  480. const endDate = new Date();
  481. switch (rangeType) {
  482. case 'today':
  483. startDate = today;
  484. break;
  485. case 'week':
  486. startDate.setDate(today.getDate() - 7);
  487. break;
  488. case 'month':
  489. startDate.setMonth(today.getMonth() - 1);
  490. break;
  491. default:
  492. throw new Error('Invalid range type');
  493. }
  494. DDateRange.value = [formatDate(startDate), formatDate(endDate)];
  495. getTimesAndDurationLine();
  496. getDeviceItemList();
  497. };
  498. onMounted(() => {
  499. handleDateRangeChange();
  500. });
  501. onUnmounted(() => {
  502. if (pushLine?.value) {
  503. echarts.dispose(pushLine.value);
  504. }
  505. if (tadLine?.value) {
  506. echarts.dispose(tadLine.value);
  507. }
  508. });
  509. </script>
  510. <style lang="scss" scoped>
  511. .play-info-container {
  512. background-color: #f0f2f5;
  513. height: 100%;
  514. }
  515. .stat-card {
  516. border-radius: 12px;
  517. border: none;
  518. height: 170px;
  519. display: flex;
  520. flex-direction: column;
  521. justify-content: center;
  522. &.overview-card {
  523. .card-header {
  524. font-weight: bold;
  525. }
  526. .text-center {
  527. border-right: 1px solid #e0e0e0;
  528. }
  529. }
  530. .stat-content {
  531. display: flex;
  532. align-items: center;
  533. justify-content: center;
  534. gap: 20px;
  535. }
  536. .stat-icon {
  537. font-size: 48px;
  538. &.icon-image { color: #ff9900; }
  539. &.icon-video { color: #34a853; }
  540. }
  541. .stat-number {
  542. font-size: 28px;
  543. font-weight: bold;
  544. line-height: 1.2;
  545. &.total-num { color: #34a853; }
  546. &.image-num { color: #ff9900; }
  547. &.video-num { color: #34a853; }
  548. }
  549. .stat-label {
  550. margin-top: 8px;
  551. font-size: 14px;
  552. color: #888;
  553. }
  554. }
  555. .el-card {
  556. border-radius: 12px;
  557. }
  558. .table-header {
  559. background-color: #f5f7fa !important;
  560. color: #333;
  561. font-weight: bold;
  562. }
  563. .chart-placeholder {
  564. height: 280px;
  565. width: 100%;
  566. }
  567. .details-dialog .el-dialog__body {
  568. padding: 10px 20px 30px 20px;
  569. max-height: calc(90vh - 120px);
  570. overflow-y: auto;
  571. }
  572. .card-header {
  573. font-weight: bold;
  574. font-size: 16px;
  575. color: #333;
  576. }
  577. </style>