play_info.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <el-container>
  3. <el-header style="margin-top: 10px">
  4. <el-row :gutter="20">
  5. <el-col :span="12">
  6. <el-card shadow="hover" class="stat-card">
  7. <el-row :gutter="20">
  8. <el-col :span="8">
  9. <h2 style="color: green; font-size: 30px">{{ totalNum }}</h2>
  10. <p class="success">总发布量</p>
  11. </el-col>
  12. <el-col :span="16">
  13. <div ref="pushLine" style="height: 150px"></div>
  14. </el-col>
  15. </el-row>
  16. </el-card>
  17. </el-col>
  18. <el-col :span="6">
  19. <el-card shadow="hover" class="stat-card">
  20. <h2 style="color: orange; font-size: 30px">{{ imageNum }}</h2>
  21. <p class="warning">图片发布</p>
  22. </el-card>
  23. </el-col>
  24. <el-col :span="6">
  25. <el-card shadow="hover" class="stat-card">
  26. <h2 style="color: green; font-size: 30px">{{ videoNum }}</h2>
  27. <p class="success">视频发布</p>
  28. </el-card>
  29. </el-col>
  30. </el-row>
  31. </el-header>
  32. <el-main style="margin-top: 90px">
  33. <el-card shadow="hover" style="margin-top: 10px; height: 60px">
  34. <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="40px">
  35. <el-form-item label="">
  36. <el-button type="warning" plain icon="Download" @click="handleExport">报表导出</el-button>
  37. </el-form-item>
  38. <el-form-item label="" prop="sourceType">
  39. <el-select v-model="queryParams.sourceType" style="width: 150px" placeholder="请选择类型" @change="getRecordList"
  40. clearable>
  41. <el-option v-for="dict in smsb_source_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="" prop="sourceTag">
  45. <el-select v-model="queryParams.sourceTag" style="width: 150px" placeholder="请选择分类" @change="getRecordList"
  46. clearable>
  47. <el-option v-for="dict in smsb_source_classify" :key="dict.value" :label="dict.label"
  48. :value="dict.value" />
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="" prop="dataRage" style="width: 500px">
  52. <el-col :span="12" style="text-align: right">
  53. <el-radio-group v-model="timeRadio" size="small" @change="handleDateRangeChange">
  54. <!-- <el-radio-button label="今日" value="today" />-->
  55. <el-radio-button label="近7天" value="week" />
  56. <el-radio-button label="近30天" value="month" />
  57. <el-radio-button label="自定义" value="diy" />
  58. </el-radio-group>
  59. </el-col>
  60. <el-col :span="12" style="text-align: right">
  61. <el-date-picker v-model="dateRange" type="daterange" range-separator="-"
  62. start-placeholder="开始日期" :disabled="diyFlag" :clearable="false" @change="handleDateRangeChange" end-placeholder="结束日期" style="margin-left: 10px; margin-right: 30px" />
  63. </el-col>
  64. </el-form-item>
  65. </el-form>
  66. </el-card>
  67. <el-card style="margin-top: 10px">
  68. <div class="table-content">
  69. <el-table v-loading="loading" :data="playRecordList">
  70. <el-table-column label="资源ID" align="left" prop="sourceId" width="250" />
  71. <el-table-column label="资源名称" align="left" prop="fileName" :show-overflow-tooltip="true" />
  72. <el-table-column label="播放次数" align="center" prop="playTimes" width="200" />
  73. <el-table-column label="播放时长" align="center" prop="playDuration" width="200" />
  74. <el-table-column label="分类" align="center" prop="fileTag" width="120">
  75. <template #default="scope">
  76. <dict-tag :options="smsb_source_classify" :value="scope.row.fileTag" />
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="类型" align="center" prop="fileType" width="120">
  80. <template #default="scope">
  81. <dict-tag :options="smsb_source_type" :value="scope.row.fileType" />
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
  85. <template #default="scope">
  86. <el-tooltip content="查看详情" placement="top">
  87. <el-button link type="primary" icon="View" @click="handleView(scope.row)"></el-button>
  88. </el-tooltip>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. </div>
  93. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
  94. v-model:limit="queryParams.pageSize" @pagination="getRecordList" />
  95. </el-card>
  96. </el-main>
  97. </el-container>
  98. <el-dialog :title="dialog.title" v-model="dialog.visible" width="1200px" append-to-body :style="{ height: '850px' }">
  99. <div>
  100. <el-row :gutter="20">
  101. <el-col :span="16" style="text-align: right">
  102. <el-radio-group v-model="DTimeRadio" size="small" @change="DHandleDateRangeChange">
  103. <!-- <el-radio-button label="今日" value="today" />-->
  104. <el-radio-button label="近7天" value="week" />
  105. <el-radio-button label="近30天" value="month" />
  106. </el-radio-group>
  107. </el-col>
  108. <el-col :span="8" style="text-align: right">
  109. <el-date-picker :disabled="true" v-model="DDateRange" type="daterange" range-separator="-"
  110. start-placeholder="开始日期" end-placeholder="结束日期" style="margin-left: 10px; margin-right: 30px" />
  111. </el-col>
  112. </el-row>
  113. </div>
  114. <div ref="tadLine" class="chart-placeholder"></div>
  115. <div>
  116. <el-row :gutter="20">
  117. <el-col :span="12">
  118. <el-table v-loading="loading" :data="deviceRecordList">
  119. <el-table-column label="设备名称" align="center" prop="deviceName" />
  120. <el-table-column label="播放次数" align="center" prop="playTimes" />
  121. <el-table-column label="播放时长" align="center" prop="duration" />
  122. </el-table>
  123. </el-col>
  124. <el-col :span="12">
  125. <el-table v-loading="loading" :data="itemRecordList">
  126. <el-table-column label="组名称" align="center" prop="itemName" />
  127. <el-table-column label="类型" align="center" prop="itemType">
  128. <template #default="scope">
  129. <dict-tag :options="smsb_item_type" :value="scope.row.itemType" />
  130. </template>
  131. </el-table-column>
  132. <el-table-column label="播放次数" align="center" prop="playTimes" />
  133. <el-table-column label="播放时长" align="center" prop="duration" />
  134. </el-table>
  135. </el-col>
  136. </el-row>
  137. </div>
  138. </el-dialog>
  139. </template>
  140. <script setup lang="ts">
  141. import * as echarts from 'echarts';
  142. import { getPushLine, listDeviceAndItem, listPlayRecordSummary, pushNumber, timesAndDurationLine } from '@/api/smsb/source/play_record';
  143. import { SourcePlayRecordForm, SourcePlayRecordQuery, SourcePlayRecordVO } from '@/api/smsb/source/play_record_type';
  144. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  145. const { smsb_source_classify, smsb_source_type, smsb_item_type } = toRefs<any>(
  146. proxy?.useDict('smsb_source_classify', 'smsb_source_type', 'smsb_item_type')
  147. );
  148. const loading = ref(true);
  149. const playRecordList = ref<SourcePlayRecordVO[]>([]);
  150. const deviceRecordList = ref<SourcePlayRecordVO[]>([]);
  151. const itemRecordList = ref<SourcePlayRecordVO[]>([]);
  152. const timeRadio = ref('week');
  153. const DTimeRadio = ref('week');
  154. const dateRange = ref(['2025-01-01', '2025-01-01']);
  155. const DDateRange = ref(['2025-01-01', '2025-01-01']);
  156. const totalNum = ref(0);
  157. const imageNum = ref(0);
  158. const videoNum = ref(0);
  159. const pushLine = ref();
  160. const total = ref(0);
  161. const tadLine = ref();
  162. const dialogSourceId = ref();
  163. const diyFlag = ref(true);
  164. const dialog = reactive<DialogOption>({
  165. visible: false,
  166. title: ''
  167. });
  168. const data = reactive<PageData<SourcePlayRecordForm, SourcePlayRecordQuery>>({
  169. form: {},
  170. queryParams: {
  171. pageNum: 1,
  172. pageSize: 10,
  173. sourceType: null,
  174. sourceTag: null,
  175. startTime: null,
  176. endTime: null
  177. },
  178. rules: {}
  179. });
  180. const getTimesAndDurationLine = async () => {
  181. const params = {
  182. startTime: DDateRange.value[0],
  183. endTime: DDateRange.value[1],
  184. sourceId: dialogSourceId.value
  185. };
  186. const res = await timesAndDurationLine(params);
  187. const playDurationList = res.data.playDurationList.map((seconds) => Math.round((seconds / 60) * 100) / 100);
  188. if (!tadLine.value) {
  189. // console.log('[tadLine] ref is null when initializing echarts');
  190. } else {
  191. // console.log('[tadLine] ref:', tadLine.value);
  192. }
  193. if (tadLine.value) {
  194. echarts.dispose(tadLine.value);
  195. // console.log('[tadLine] echarts instance disposed before init');
  196. }
  197. const tadLineInstance = echarts.init(tadLine.value, 'macaroons');
  198. // console.log('[tadLine] echarts instance created:', tadLineInstance);
  199. tadLineInstance.setOption({
  200. title: {
  201. text: ''
  202. },
  203. tooltip: {
  204. trigger: 'axis'
  205. },
  206. legend: {
  207. data: ['播放次数', '播放时长(分钟)']
  208. },
  209. grid: {
  210. left: '3%',
  211. right: '4%',
  212. bottom: '3%',
  213. containLabel: true
  214. },
  215. toolbox: {
  216. feature: {
  217. saveAsImage: {}
  218. }
  219. },
  220. xAxis: {
  221. type: 'category',
  222. boundaryGap: false,
  223. data: res.data.timeList
  224. },
  225. yAxis: {
  226. type: 'value'
  227. },
  228. series: [
  229. {
  230. name: '播放次数',
  231. type: 'line',
  232. stack: 'Total',
  233. data: res.data.playTimesList
  234. },
  235. {
  236. name: '播放时长(分钟)',
  237. type: 'line',
  238. stack: 'Total',
  239. data: playDurationList
  240. }
  241. ]
  242. });
  243. };
  244. const { queryParams, form, rules } = toRefs(data);
  245. const getPushNumber = async () => {
  246. const res = await pushNumber();
  247. totalNum.value = res.data.totalNum;
  248. imageNum.value = res.data.imageNum;
  249. videoNum.value = res.data.videoNum;
  250. const lineRes = await getPushLine();
  251. if (!pushLine.value) {
  252. // console.log('[pushLine] ref is null when initializing echarts');
  253. } else {
  254. // console.log('[pushLine] ref:', pushLine.value);
  255. }
  256. if (pushLine.value) {
  257. echarts.dispose(pushLine.value);
  258. // console.log('[pushLine] echarts instance disposed before init');
  259. }
  260. const pushLineInstance = echarts.init(pushLine.value, 'macaroons');
  261. // console.log('[pushLine] echarts instance created:', pushLineInstance);
  262. pushLineInstance.setOption({
  263. title: {
  264. text: ''
  265. },
  266. tooltip: {
  267. trigger: 'axis'
  268. },
  269. legend: {
  270. data: ['']
  271. },
  272. grid: {
  273. left: '3%',
  274. right: '4%',
  275. bottom: '3%',
  276. containLabel: true
  277. },
  278. toolbox: {
  279. feature: {
  280. saveAsImage: {}
  281. }
  282. },
  283. xAxis: {
  284. type: 'category',
  285. boundaryGap: false,
  286. data: lineRes.data.timeList
  287. },
  288. yAxis: {
  289. type: 'value'
  290. },
  291. series: [
  292. {
  293. name: '',
  294. type: 'line',
  295. stack: 'Total',
  296. data: lineRes.data.numberList
  297. }
  298. ]
  299. });
  300. };
  301. /** 导出按钮操作 */
  302. const handleExport = () => {
  303. proxy?.download(
  304. 'source/playRecord/summary/export',
  305. {
  306. ...queryParams.value
  307. },
  308. `playRecord_${new Date().getTime()}.xlsx`
  309. );
  310. };
  311. const handleView = async (row?: SourcePlayRecordVO) => {
  312. dialog.title = row.fileName;
  313. dialog.visible = true;
  314. dialogSourceId.value = row.sourceId;
  315. DHandleDateRangeChange();
  316. };
  317. const getDeviceItemList = async () => {
  318. const params = {
  319. startTime: DDateRange.value[0],
  320. endTime: DDateRange.value[1],
  321. sourceId: dialogSourceId.value
  322. };
  323. const res = await listDeviceAndItem(params);
  324. deviceRecordList.value = res.data.deviceList;
  325. itemRecordList.value = res.data.itemList;
  326. };
  327. /** 查询资源播放记录列表 */
  328. const getRecordList = async () => {
  329. loading.value = true;
  330. queryParams.value.startTime = dateRange.value[0];
  331. queryParams.value.endTime = dateRange.value[1];
  332. const res = await listPlayRecordSummary(queryParams.value);
  333. playRecordList.value = res.rows;
  334. playRecordList.value.forEach((item) => {
  335. item.playDuration = formatDuration(item.playDuration);
  336. });
  337. total.value = res.total;
  338. loading.value = false;
  339. };
  340. // 格式化秒数为 HH:mm:ss
  341. const formatDuration = (seconds) => {
  342. const hours = Math.floor(seconds / 3600);
  343. const minutes = Math.floor((seconds % 3600) / 60);
  344. const secs = seconds % 60;
  345. const paddedHours = String(hours).padStart(2, '0');
  346. const paddedMinutes = String(minutes).padStart(2, '0');
  347. const paddedSeconds = String(secs).padStart(2, '0');
  348. return `${paddedHours}:${paddedMinutes}:${paddedSeconds}`;
  349. };
  350. const handleDateRangeChange = () => {
  351. const rangeType = timeRadio.value;
  352. const today = new Date();
  353. const startDate = new Date();
  354. const endDate = new Date();
  355. switch (rangeType) {
  356. case 'week':
  357. startDate.setDate(today.getDate() - 7);
  358. dateRange.value = [formatDate(startDate), formatDate(endDate)];
  359. diyFlag.value = true;
  360. break;
  361. case 'month':
  362. startDate.setMonth(today.getMonth() - 1);
  363. dateRange.value = [formatDate(startDate), formatDate(endDate)];
  364. diyFlag.value = true;
  365. break;
  366. case "diy" :
  367. diyFlag.value = false;
  368. dateRange.value = [formatDate(dateRange.value[0]), formatDate(dateRange.value[1])];
  369. break;
  370. default:
  371. break
  372. // throw new Error('Invalid range type');
  373. }
  374. getRecordList();
  375. getPushNumber();
  376. };
  377. const DHandleDateRangeChange = () => {
  378. const rangeType = DTimeRadio.value;
  379. const today = new Date();
  380. const startDate = new Date();
  381. const endDate = new Date();
  382. switch (rangeType) {
  383. case 'today':
  384. break;
  385. case 'week':
  386. startDate.setDate(today.getDate() - 7);
  387. break;
  388. case 'month':
  389. startDate.setMonth(today.getMonth() - 1);
  390. break;
  391. default:
  392. throw new Error('Invalid range type');
  393. }
  394. DDateRange.value = [formatDate(startDate), formatDate(endDate)];
  395. getTimesAndDurationLine();
  396. getDeviceItemList();
  397. };
  398. const formatDate = (date: Date) => {
  399. const year = date.getFullYear();
  400. const month = String(date.getMonth() + 1).padStart(2, '0');
  401. const day = String(date.getDate()).padStart(2, '0');
  402. return `${year}-${month}-${day}`;
  403. };
  404. onMounted(() => {
  405. handleDateRangeChange();
  406. // getPushNumber();
  407. // getRecordList();
  408. });
  409. import { onUnmounted, nextTick } from 'vue';
  410. onUnmounted(() => {
  411. if (pushLine?.value) {
  412. echarts.dispose(pushLine.value);
  413. // console.log('[play_info] pushLine disposed on unmount');
  414. }
  415. if (tadLine?.value) {
  416. echarts.dispose(tadLine.value);
  417. // console.log('[play_info] tadLine disposed on unmount');
  418. }
  419. });
  420. </script>
  421. <style scoped>
  422. .stat-card {
  423. text-align: center;
  424. height: 170px;
  425. }
  426. .number {
  427. font-size: 24px;
  428. font-weight: bold;
  429. }
  430. .success {
  431. color: green;
  432. }
  433. .danger {
  434. color: red;
  435. }
  436. .warning {
  437. color: orange;
  438. }
  439. .chart-placeholder {
  440. height: 250px;
  441. /*background: #f5f5f5;*/
  442. border-radius: 8px;
  443. }
  444. .disk-progress .el-progress--line {
  445. margin-bottom: 15px;
  446. max-width: 600px;
  447. margin-top: 50px;
  448. }
  449. </style>