index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div class="table-box">
  3. <div class="card table-main">
  4. <!-- 表格头部 操作按钮 -->
  5. <div class="table-header">
  6. <div class="header-button-lf">
  7. <el-form :model="pageable" label-width="auto" :inline="true">
  8. <el-form-item label="名称:">
  9. <el-input v-model="pageable.processName" style="width: 200px" placeholder="请输入名称" />
  10. </el-form-item>
  11. <el-form-item label="应用:">
  12. <el-input v-model="pageable.programName" style="width: 200px" placeholder="请输入应用" />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" @click="handleQuery"> 查询 </el-button>
  16. <el-button style="margin-left: 10px" @click="resetQuery"> 重置 </el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. </div>
  21. <!-- 表格主体 -->
  22. <el-table stripe ref="tableRef" :border="true" :data="showList" size="small">
  23. <el-table-column align="left" label="序号" width="80px" :show-overflow-tooltip="true" >
  24. <template #default="scope">
  25. {{ (pageable.pageNum - 1) * pageable.pageSize + scope.$index + 1 }}
  26. </template>
  27. </el-table-column>
  28. <template v-for="item in columns" :key="item">
  29. <el-table-column v-bind="item" :align="item.align ?? 'left'" :reserve-selection="item.type == 'selection'" :show-overflow-tooltip="true" >
  30. </el-table-column>
  31. </template>
  32. <!-- 无数据 -->
  33. <template #empty>
  34. <div class="table-empty">
  35. <slot name="empty">
  36. <img src="@/assets/images/notData.png" alt="notData" />
  37. <div>暂无数据</div>
  38. </slot>
  39. </div>
  40. </template>
  41. </el-table>
  42. <!-- 分页组件 -->
  43. <Pagination :pageable="pageable" :handle-size-change="handleSizeChange" :handle-current-change="handleCurrentChange" />
  44. </div>
  45. </div>
  46. </template>
  47. <script setup lang="ts" name="useProTable">
  48. import Pagination from "@/components/ProTable/components/Pagination.vue";
  49. import {ref, reactive, onMounted, computed, onActivated, onDeactivated} from "vue";
  50. import { ColumnProps } from "@/components/ProTable/interface";
  51. import {getQueryAllSysItem} from "@/api/modules/allData";
  52. //原始数据源
  53. const dataList = ref([])
  54. const pageable = ref<any>({
  55. programName:'',
  56. processName:'',
  57. pageNum: 1,
  58. pageSize: 20,
  59. total: 0
  60. });
  61. // 计算属性,根据分页参数和查询条件计算当前页的数据范围
  62. const showList = computed(() => {
  63. // 过滤数据
  64. const filteredData = dataList.value.filter(item => {
  65. return (!pageable.value.programName || item.programName.includes(pageable.value.programName)) &&
  66. (!pageable.value.processName || item.processName.includes(pageable.value.processName));
  67. });
  68. // 更新总数
  69. pageable.value.total = filteredData.length;
  70. // 计算当前页的数据范围
  71. const start = (pageable.value.pageNum - 1) * pageable.value.pageSize;
  72. const end = start + pageable.value.pageSize;
  73. // 根据分页参数截取数据
  74. return filteredData.slice(start, end);
  75. });
  76. // 查询功能
  77. const handleQuery = () => {
  78. pageable.value.pageNum = 1; // 重置到第一页
  79. };
  80. // 重置功能
  81. const resetQuery = () => {
  82. pageable.value.programName = ''; // 清除查询条件
  83. pageable.value.processName = '';
  84. pageable.value.pageNum = 1; // 重置到第一页
  85. };
  86. // 每页条数改变
  87. const handleSizeChange = (val: number) => {
  88. pageable.value.pageSize = val;
  89. };
  90. // 当前页改变
  91. const handleCurrentChange = (val: number) => {
  92. pageable.value.pageNum = val;
  93. };
  94. // 表格配置项
  95. const columns = reactive<ColumnProps[]>([
  96. { prop: "processName", label: "名称" },
  97. { prop: "programName", label: "应用" },
  98. { prop: "processId", label: "PID" },
  99. { prop: "cpuUsage", label: "内存" },
  100. { prop: "memoryUsage", label: "CPU" },
  101. { prop: "status", label: "状态",width:100},
  102. ]);
  103. const processData = ref([]);
  104. const getList= async ()=>{
  105. dataList.value = []
  106. const { data } = await getQueryAllSysItem();
  107. processData.value = data.list
  108. processData.value.forEach(function(item) {
  109. if(item.item_key==='24'||item.item_key==='25'||item.item_key==='26'||item.item_key==='27'){
  110. const values = item.item_value.split('|');
  111. const obj = {
  112. processName: values[0],
  113. programName: values[1],
  114. processId: values[2],
  115. cpuUsage: values[4],
  116. memoryUsage: values[3],
  117. statusUpdateTime: new Date(parseInt(values[5]) * 1000), // 将时间戳转换为 Date 对象
  118. status:''
  119. };
  120. // 获取当前时间
  121. const currentTime = new Date();
  122. // 计算时间差(以毫秒为单位)
  123. const timeDifference = currentTime - obj.statusUpdateTime;
  124. // 判断是否超过3分钟(3分钟 = 3 * 60 * 1000 毫秒)
  125. if (timeDifference > 3 * 60 * 1000) {
  126. obj.status = '停止中';
  127. } else {
  128. obj.status = '运行中';
  129. }
  130. dataList.value.push(obj);
  131. }
  132. })
  133. pageable.value.total = dataList.value.length
  134. }
  135. onMounted(() => {
  136. getList()
  137. });
  138. let intervalId;
  139. onActivated(() => {
  140. intervalId = setInterval(() => {
  141. getList()
  142. }, 30 * 1000);
  143. });
  144. onDeactivated(() => {
  145. clearInterval(intervalId);
  146. });
  147. </script>