xiaoyi
3 天以前 97b2e606968fbe7a55df1173f52edc7e11ccfd12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
 
import { Page } from '@vben/common-ui';
 
import { Select, Spin, Table } from 'ant-design-vue';
 
import { getKpiOverview } from '#/api/bi/decision/kpi';
 
defineOptions({ name: 'DecisionTrendAnalysis' });
 
const loading = ref(false);
const trendData = ref<any[]>([]);
const selectedCategory = ref<string>('');
 
const CATEGORY_OPTIONS = [
  { label: '全部', value: '' },
  { label: '供电量', value: 'power_supply' },
  { label: '设备运行', value: 'device_operation' },
  { label: '生产', value: 'production' },
  { label: '质量', value: 'quality' },
  { label: '采购', value: 'procurement' },
  { label: '安全', value: 'safety' },
];
 
const columns = [
  { title: 'KPI名称', dataIndex: 'name', key: 'name', width: 150 },
  { title: '分类', dataIndex: 'category', key: 'category', width: 100 },
  { title: '当前值', dataIndex: 'value', key: 'value', width: 120 },
  { title: '单位', dataIndex: 'unit', key: 'unit', width: 80 },
  { title: '预警状态', dataIndex: 'alertStatus', key: 'alertStatus', width: 100 },
];
 
async function loadData() {
  loading.value = true;
  try {
    const overview = await getKpiOverview();
    let list = overview.kpis || [];
    if (selectedCategory.value) {
      list = list.filter((k) => k.category === selectedCategory.value);
    }
    trendData.value = list;
  } catch {
    trendData.value = [];
  } finally {
    loading.value = false;
  }
}
 
onMounted(loadData);
</script>
 
<template>
  <Page :auto-content-height="true">
    <div class="p-4">
      <div class="mb-4 flex items-center gap-4">
        <h2 class="text-lg font-bold">趋势分析</h2>
        <Select
          v-model:value="selectedCategory"
          :options="CATEGORY_OPTIONS"
          style="width: 160px"
          allow-clear
          @change="loadData"
        />
      </div>
 
      <Spin :spinning="loading">
        <Table
          :columns="columns"
          :data-source="trendData"
          :pagination="{ pageSize: 20 }"
          row-key="code"
          bordered
          size="middle"
        >
          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'alertStatus'">
              <span v-if="record.alertStatus === 'critical'" class="text-red-500">严重</span>
              <span v-else-if="record.alertStatus === 'warn'" class="text-orange-500">警告</span>
              <span v-else class="text-green-500">正常</span>
            </template>
          </template>
        </Table>
      </Spin>
    </div>
  </Page>
</template>