Query.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div>
  3. <el-button type="primary" @click="showWorkshopData()">车间统计数据</el-button>
  4. <el-button type="primary" @click="showCameraData()">相机统计数据</el-button>
  5. <QueryTable
  6. v-if="tableData !== undefined"
  7. :department-list="departmentList"
  8. :workshop-list="flattenedWorkshops"
  9. :table-data="tableData"
  10. table-label="访问次数"
  11. @table-params-changed="
  12. (v) => {
  13. tableQueryParams = _.cloneDeep(v);
  14. }
  15. "
  16. />
  17. <el-dialog
  18. v-model="dialogVisible"
  19. width="1000px"
  20. :title="dialogTitle"
  21. :close-on-click-modal="true"
  22. :destroy-on-close="true"
  23. center
  24. >
  25. <DialogNavBar
  26. :workshop-list="dialogTitle === '相机统计数据' ? flattenedWorkshops : undefined"
  27. @chart-params-changed="
  28. async (v) => {
  29. await getChartData(v);
  30. }
  31. "
  32. />
  33. <BarChart :chart-data="chartData.val" :chart-lable="chartData.label" />
  34. </el-dialog>
  35. </div>
  36. </template>
  37. <script setup lang="ts">
  38. import QueryTable from '../common/QueryTable.vue';
  39. import DialogNavBar from '../common/DialogNavBar.vue';
  40. import BarChart from '../../charts/BarChart.vue';
  41. import { ref, onMounted, watch } from 'vue';
  42. import { useSceneInfos } from '@/hooks/useSceneInfos';
  43. import {
  44. type UserAccessRecordQueryParams,
  45. type UserAccessRecordList,
  46. type ChartQuery,
  47. getUserAccessRecords,
  48. getCameraVisitedTimes,
  49. getWorkshopVisitedTimes,
  50. } from '@/api/datamanagement/dataplatform';
  51. import { formatWorkshopChart, formatCameraChart } from '@/utils/platformUtils';
  52. import { getAllDepartments } from '@/api/auth/dept';
  53. import _ from 'lodash-es';
  54. import { PaginationRequest } from '@/types/common/type';
  55. const departmentList = ref<any[]>([]);
  56. // 下拉菜单车间列表数据
  57. const sceneInfos = useSceneInfos();
  58. const { flattenedWorkshops, getScenesTree, calculateTreeData } = sceneInfos;
  59. onMounted(() => {
  60. getScenesTree({ level: 1, valueKey: 'code', labelKey: 'name', disabled: true });
  61. getAllDepartments().then((res) => {
  62. departmentList.value = calculateTreeData(res, { level: 3, valueKey: 'id', labelKey: 'deptName' }, 1);
  63. });
  64. });
  65. // dialog显示
  66. const dialogVisible = ref(false);
  67. const dialogTitle = ref('');
  68. const showWorkshopData = () => {
  69. dialogVisible.value = true;
  70. dialogTitle.value = '车间统计数据';
  71. };
  72. const showCameraData = () => {
  73. dialogVisible.value = true;
  74. dialogTitle.value = '相机统计数据';
  75. };
  76. // 请求画图数据
  77. const getChartData = async (cp: ChartQuery) => {
  78. if (dialogTitle.value.includes('车间')) {
  79. const data = await getWorkshopVisitedTimes(cp);
  80. chartData.value = formatWorkshopChart(data);
  81. } else {
  82. const data = await getCameraVisitedTimes(cp);
  83. chartData.value = formatCameraChart(data);
  84. }
  85. };
  86. const chartData = ref<{
  87. label: string[];
  88. val: number[];
  89. }>({
  90. label: [],
  91. val: [],
  92. });
  93. // 请求表格数据
  94. const tableQueryParams = ref<PaginationRequest & { queryParam: UserAccessRecordQueryParams }>({
  95. pageNumber: 1,
  96. pageSize: 10,
  97. queryParam: {},
  98. // nickname: '',
  99. // username: '',
  100. // sortKey: 'statisticAll',
  101. // sortType: 'asc',
  102. });
  103. const tableData = ref<UserAccessRecordList>();
  104. watch(
  105. () => tableQueryParams.value,
  106. async () => {
  107. const data = await getUserAccessRecords(tableQueryParams.value);
  108. tableData.value = {
  109. list: data.records,
  110. pageNumber: data.pageNumber,
  111. pageSize: data.pageSize,
  112. total: data.totalRow,
  113. };
  114. },
  115. {
  116. immediate: true,
  117. deep: true,
  118. },
  119. );
  120. </script>
  121. <style scoped lang="scss">
  122. :deep(.el-dialog__header) {
  123. text-align: left;
  124. border-bottom: 1px solid rgba(232, 232, 232, 1);
  125. padding-bottom: 16px;
  126. margin-bottom: 16px;
  127. }
  128. :deep(.el-dialog__title) {
  129. font-weight: 600;
  130. font-size: 16px;
  131. color: rgba(0, 0, 0, 0.88);
  132. line-height: 24px;
  133. }
  134. </style>