Newer
Older
smartwell_front / src / views / home / monitor / time / index.vue
liyaguang on 11 Mar 2 KB 功能优化
<!--
  Description: 系统监控-定时任务
  Author: 李亚光
  Date: 2024-09-04
 -->
<script lang="ts" setup name="SystemMonitorTime">
import { getSysMonitortListPage } from '@/api/home/monitor/monitor'
import dayjs from 'dayjs'
// 表格数据
const list = ref([])
const total = ref(0)
// 初始展示列
const columns = ref<any>([
  { text: '定时任务', value: 'serverName', align: 'center' },
  { text: '定时任务名称', value: 'remark', align: 'center' },
  { text: '运行状态', value: 'status', align: 'center' },
  { text: '最新运行时间', value: 'ts', align: 'center' },
])
// 最终展示列
const columnsConfig = ref([])
// 修改列
const editColumns = (data: any) => {
  columnsConfig.value = data
}
const loadingTable = ref(true)
//  查询条件
const listQuery = ref({
  limit: 20,
  offset: 1,
  serverType: '1'
})
// 查询数据
const fetchData = () => {
  loadingTable.value = true
  getSysMonitortListPage(listQuery.value).then((res) => {
    list.value = res.data.rows.map((item: any) => ({
      ...item,
      status: item.status ? item.status === '1' ? '正常' : item.status === '0' ? '异常' : '' : '',
      ts: item.ts ? dayjs(item.ts).format('YYYY-MM-DD HH:mm:ss') : ''
    }))
    total.value = res.data.total
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData()
}
onMounted(async () => {
  fetchData()
})
const { proxy } = getCurrentInstance() as any
</script>

<template>
  <!-- 布局 -->
  <app-container>
    <!-- 表头标题 -->
    <table-container :is-config="true" config-title="monitor-time" :columns="columns" :config-columns="columnsConfig"
      :edit="editColumns">
      <template #btns-right>
        <!-- 操作 -->
        <!-- <div>
          <el-button v-if="proxy.hasPerm('/monitor/time/add')" type="primary">
            新建
          </el-button>
        </div> -->
      </template>
      <!-- 查询结果Table显示 -->
      <normal-table :data="list" :total="total" :columns="columnsConfig" :query="listQuery" :list-loading="loadingTable"
        @change="changePage">
        <template #preColumns>
          <el-table-column label="序号" width="80" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>