zouyu
7 天以前 09f49269f00a1fa70bbf9d52476b01bf917c948e
src/views/index.vue
@@ -1,674 +1,392 @@
<template>
  <div class="dashboard">
    <!-- 顶部横向两栏 -->
    <div class="dashboard-top">
      <!-- 左:系统概览+数据卡片 -->
      <div class="top-left">
        <div class="system-info">
          <div class="section-title">承包商管理系统</div>
          <div style="display: flex; align-items: center; gap: 20px">
            <div class="system-card">
              <div class="system-name">承包商管理系统</div>
              <div class="system-meta">资质审核 · 合同管理 · 绩效评估</div>
            </div>
            <div style="display: flex; align-items: center; gap: 8px">
              <el-icon color="#5053B5" size="22"><Clock /></el-icon>
              <span>当前时间:{{ currentTime }}</span>
  <div class="dashboard-container">
    <!-- 统计卡片 -->
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card class="statistics-card" shadow="hover">
          <div class="card-content">
            <div class="card-title">设备在线率</div>
            <div class="card-value">{{ onlineRate }}%</div>
            <div class="card-desc">
              当前在线设备数:{{ onlineCount }} / {{ totalDevices }}
            </div>
          </div>
        </div>
        <div class="data-cards">
          <div class="data-card total">
            <div class="data-title">总承包商数</div>
            <div class="data-value">{{ contractorStats.total }}</div>
            <div class="data-desc">
              已审核 {{ contractorStats.approved }} | 待审核
              {{ contractorStats.pending }}
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="statistics-card" shadow="hover">
          <div class="card-content">
            <div class="card-title">故障预警数</div>
            <div class="card-value">{{ warningCount }}</div>
            <div class="card-desc">
              高风险:{{ highRiskCount }} | 中风险:{{ mediumRiskCount }} |
              低风险:{{ lowRiskCount }}
            </div>
          </div>
          <div class="data-card pending">
            <div class="data-title">待审核承包商</div>
            <div class="data-value">{{ contractorStats.pending }}</div>
            <div class="data-desc">
              A级 {{ contractorStats.aPending }} | B级
              {{ contractorStats.bPending }} | C级
              {{ contractorStats.cPending }}
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="statistics-card" shadow="hover">
          <div class="card-content">
            <div class="card-title">待处理维修单</div>
            <div class="card-value">{{ pendingOrders }}</div>
            <div class="card-desc">
              处理中:{{ processingOrders }} | 已完成:{{ completedOrders }}
            </div>
          </div>
          <div class="data-card today">
            <div class="data-title">本月新增</div>
            <div class="data-value">{{ contractorStats.monthly }}</div>
            <div class="data-desc">
              同比 {{ contractorStats.monthly同比 }}% | 环比
              {{ contractorStats.monthly环比 }}%
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card class="statistics-card" shadow="hover">
          <div class="card-content">
            <div class="card-title">重点设备运行状态</div>
            <div class="card-value">{{ normalDevices }} 正常</div>
            <div class="card-desc">
              异常:{{ abnormalDevices }} | 故障:{{ faultDevices }}
            </div>
          </div>
        </div>
      </div>
      <!-- 右:待处理报警列表 -->
      <div class="alarm-panel">
        <div class="section-title">待审核承包商</div>
        <ul class="alarm-list" v-if="pendingContractors.length > 0">
          <li v-for="item in pendingContractors" :key="item.id">
            <div
              style="
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                width: 100%;
                gap: 10px;
              "
            >
              <div
                style="
                  display: flex;
                  justify-content: space-between;
                  align-items: center;
                "
              >
                <div class="alarm-title">{{ item.name }} - {{ item.type }}</div>
                <el-tag :type="getContractorLevelType(item.level)"
                  >{{ item.level }}级</el-tag
                >
              </div>
              <div
                style="
                  display: flex;
                  justify-content: space-between;
                  align-items: center;
                "
              >
                <div class="alarm-value">
                  联系人: {{ item.contact }} | 注册时间: {{ item.registerDate }}
                </div>
                <div class="alarm-time">{{ item.applyDate }}</div>
              </div>
            </div>
          </li>
        </ul>
        <div v-else style="text-align: center; color: #909399; padding: 20px">
          暂无待审核承包商
        </div>
      </div>
    </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 中部横向两栏 -->
    <div class="dashboard-row">
      <div class="main-panel">
        <div class="section-title">承包商增长趋势</div>
        <Echarts
          ref="chart"
          :chartStyle="chartStyle"
          :grid="grid"
          :legend="lineLegend"
          :series="lineSeries"
          :tooltip="tooltipLine"
          :xAxis="xAxis"
          :yAxis="yAxis"
          style="height: 300px"
        ></Echarts>
    <!-- 图表区域 -->
    <el-row :gutter="20" style="margin-top: 20px">
      <!-- 设备健康度趋势图 -->
      <el-col :span="12">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>设备健康度趋势图</span>
      </div>
      <div class="main-panel">
        <div class="section-title">承包商资质分布</div>
        <div
          style="
            display: flex;
            align-items: center;
            gap: 20px;
            justify-content: space-evenly;
            height: 300px;
          "
        >
          <div style="width: 50%">
            <Echarts
              ref="chart"
              :legend="pieLegend"
              :chartStyle="chartStylePie"
              :series="levelPieSeries"
              :tooltip="pieTooltip"
            ></Echarts>
          </template>
          <div ref="healthChartRef" class="chart-container"></div>
        </el-card>
      </el-col>
      <!-- 近7日故障类型统计 -->
      <el-col :span="12">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>近7日故障类型统计</span>
          </div>
          <ul class="level-list" style="width: 50%">
            <li v-for="item in levelPieSeries[0].data" :key="item.name">
              <div
                style="
                  display: flex;
                  align-items: center;
                  justify-content: space-between;
                  width: 100%;
                "
              >
                <div class="line" :style="{ color: item.itemStyle.color }">
                  ●{{ item.name }}
                </div>
                <div style="width: 60px">{{ item.value }}家</div>
                <div style="width: 60px">{{ item.rate }}%</div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
          </template>
          <div ref="faultChartRef" class="chart-container"></div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 底部横向两栏 -->
    <div class="dashboard-row">
      <div class="main-panel">
        <div class="section-title">承包商类型分布</div>
        <Echarts
          ref="chart"
          :color="barColors"
          :chartStyle="chartStyle"
          :grid="grid"
          :series="equipmentBarSeries"
          :tooltip="tooltip"
          :xAxis="equipmentXAxis"
          :yAxis="yAxis"
          style="height: 300px"
        ></Echarts>
    <!-- 重点设备运行状态卡片 -->
    <el-card shadow="hover" style="margin-top: 20px">
      <template #header>
        <div class="card-header">
          <span>重点设备运行状态</span>
      </div>
      <div class="main-panel">
        <div class="section-title">承包商审核时效</div>
        <Echarts
          ref="chart"
          :color="barColors"
          :chartStyle="chartStyle"
          :grid="grid"
          :series="handlingTimeSeries"
          :tooltip="tooltip"
          :xAxis="handlingTimeXAxis"
          :yAxis="yAxis"
          style="height: 300px"
        ></Echarts>
      </div>
    </div>
      </template>
      <el-table :data="keyDevices" stripe style="width: 100%">
        <el-table-column
          prop="name"
          label="设备名称"
          width="180"
        ></el-table-column>
        <el-table-column
          prop="model"
          label="型号"
          width="120"
        ></el-table-column>
        <el-table-column prop="ip" label="IP地址" width="150"></el-table-column>
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag
              :type="
                scope.row.status === 'online'
                  ? 'success'
                  : scope.row.status === 'warning'
                  ? 'warning'
                  : 'danger'
              "
            >
              {{
                scope.row.status === "online"
                  ? "在线"
                  : scope.row.status === "warning"
                  ? "预警"
                  : "故障"
              }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="temperature"
          label="温度(℃)"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="pressure"
          label="压力(MPa)"
          width="100"
        ></el-table-column>
        <el-table-column
          prop="speed"
          label="转速(rpm)"
          width="100"
        ></el-table-column>
        <el-table-column prop="health" label="健康度" width="120">
          <template #default="scope">
            <el-progress
              :percentage="scope.row.health"
              :stroke-width="10"
            ></el-progress>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script setup>
import { ref, onMounted, reactive, computed } from "vue";
import Echarts from "@/components/Echarts/echarts.vue";
import { Clock } from "@element-plus/icons-vue";
import { ref, onMounted, onUnmounted } from "vue";
import * as echarts from "echarts";
// 当前时间
const currentTime = computed(() => {
  const now = new Date();
  return now.toLocaleString("zh-CN");
});
// 统计数据
const onlineRate = ref(85);
const onlineCount = ref(170);
const totalDevices = ref(200);
const warningCount = ref(23);
const highRiskCount = ref(5);
const mediumRiskCount = ref(12);
const lowRiskCount = ref(6);
const pendingOrders = ref(15);
const processingOrders = ref(8);
const completedOrders = ref(45);
const normalDevices = ref(162);
const abnormalDevices = ref(18);
const faultDevices = ref(10);
// 承包商统计数据
const contractorStats = reactive({
  total: 156,
  approved: 132,
  pending: 24,
  aPending: 8,
  bPending: 12,
  cPending: 4,
  monthly: 28,
  monthly同比: "+18.5",
  monthly环比: "+5.2",
});
// 待审核承包商列表
const pendingContractors = ref([
// 重点设备列表
const keyDevices = ref([
  {
    id: 1,
    name: "建筑工程有限公司",
    type: "建筑施工",
    contact: "张三",
    registerDate: "2025-01-15",
    applyDate: "2025-12-16 14:30:23",
    level: "A",
    name: "空压机A-001",
    model: "KA-200",
    ip: "192.168.1.101",
    status: "online",
    temperature: 42,
    pressure: 0.8,
    speed: 1450,
    health: 92,
  },
  {
    id: 2,
    name: "机电安装工程公司",
    type: "机电安装",
    contact: "李四",
    registerDate: "2025-03-20",
    applyDate: "2025-12-16 14:28:15",
    level: "B",
    name: "冷却塔B-002",
    model: "CT-300",
    ip: "192.168.1.102",
    status: "warning",
    temperature: 58,
    pressure: 0.6,
    speed: 980,
    health: 75,
  },
  {
    id: 3,
    name: "装饰装修工程公司",
    type: "装饰装修",
    contact: "王五",
    registerDate: "2025-05-10",
    applyDate: "2025-12-16 14:22:18",
    level: "B",
    name: "水泵C-003",
    model: "WP-150",
    ip: "192.168.1.103",
    status: "online",
    temperature: 38,
    pressure: 1.2,
    speed: 1200,
    health: 88,
  },
  {
    id: 4,
    name: "绿化工程有限公司",
    type: "园林绿化",
    contact: "赵六",
    registerDate: "2025-08-05",
    applyDate: "2025-12-16 14:18:55",
    level: "C",
    name: "发电机D-004",
    model: "GE-500",
    ip: "192.168.1.104",
    status: "danger",
    temperature: 75,
    pressure: 0.5,
    speed: 1500,
    health: 60,
  },
  {
    name: "变压器E-005",
    model: "TR-1000",
    ip: "192.168.1.105",
    status: "online",
    temperature: 45,
    pressure: 0,
    speed: 0,
    health: 95,
  },
]);
// 图表样式
const chartStyle = {
  width: "100%",
  height: "100%",
// 图表引用
const healthChartRef = ref(null);
const faultChartRef = ref(null);
let healthChart = null;
let faultChart = null;
// 健康度趋势数据
const healthTrendData = {
  dates: ["12-10", "12-11", "12-12", "12-13", "12-14", "12-15", "12-16"],
  values: [88, 90, 85, 87, 92, 91, 93],
};
const chartStylePie = {
  width: "100%",
  height: "100%",
// 故障类型统计数据
const faultTypeData = {
  types: ["温度异常", "压力超标", "转速异常", "振动过大", "其他"],
  values: [15, 8, 12, 6, 3],
};
const grid = {
// 初始化健康度趋势图
const initHealthChart = () => {
  if (healthChartRef.value) {
    healthChart = echarts.init(healthChartRef.value);
    const option = {
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "cross",
          label: {
            backgroundColor: "#6a7985",
          },
        },
      },
      grid: {
  left: "3%",
  right: "4%",
  bottom: "3%",
  containLabel: true,
};
// 承包商增长趋势 - 折线图
const lineLegend = {
  show: true,
  data: ["A级", "B级", "C级"],
};
const tooltipLine = {
  trigger: "axis",
  axisPointer: {
    type: "cross",
  },
};
const xAxis = ref({
      xAxis: {
  type: "category",
  data: ["12-01", "12-02", "12-03", "12-04", "12-05", "12-06", "12-07"],
});
const yAxis = ref({
        boundaryGap: false,
        data: healthTrendData.dates,
      },
      yAxis: {
  type: "value",
  name: "承包商数量",
});
const lineSeries = ref([
        min: 70,
        max: 100,
        name: "健康度(%)",
      },
      series: [
  {
    name: "A级",
          name: "健康度",
    type: "line",
    data: [15, 18, 20, 22, 25, 28, 30],
    itemStyle: {
      color: "#f56c6c",
          stack: "总量",
          areaStyle: {},
          emphasis: {
            focus: "series",
    },
    lineStyle: {
      width: 2,
    },
    showSymbol: true,
  },
  {
    name: "B级",
    type: "line",
    data: [45, 52, 58, 65, 70, 75, 80],
    itemStyle: {
      color: "#e6a23c",
    },
    lineStyle: {
      width: 2,
    },
    showSymbol: true,
  },
  {
    name: "C级",
    type: "line",
    data: [30, 35, 40, 45, 50, 55, 60],
          data: healthTrendData.values,
    itemStyle: {
      color: "#67c23a",
    },
    lineStyle: {
      width: 2,
            width: 3,
    },
    showSymbol: true,
  },
]);
// 承包商资质分布 - 饼图
const pieLegend = {
  show: false,
};
const pieTooltip = {
  trigger: "item",
  formatter: "{b}: {c}家 ({d}%)",
};
const levelPieSeries = ref([
  {
    type: "pie",
    radius: ["60%", "80%"],
    avoidLabelOverlap: false,
    itemStyle: {
      borderColor: "#fff",
      borderWidth: 2,
    },
    label: {
      show: false,
    },
    data: [
      {
        name: "A级",
        value: 45,
        rate: 28.85,
        itemStyle: { color: "#f56c6c" },
      },
      {
        name: "B级",
        value: 70,
        rate: 44.87,
        itemStyle: { color: "#e6a23c" },
      },
      {
        name: "C级",
        value: 41,
        rate: 26.28,
        itemStyle: { color: "#67c23a" },
      },
    ],
  },
]);
// 承包商类型分布 - 柱状图
const barColors = ["#409eff", "#67c23a", "#e6a23c", "#f56c6c", "#909399"];
const tooltip = {
  trigger: "axis",
  axisPointer: {
    type: "shadow",
  },
};
const equipmentXAxis = ref({
  type: "category",
  data: ["建筑施工", "机电安装", "装饰装修", "园林绿化", "其他"],
});
const equipmentBarSeries = ref([
  {
    name: "承包商数量",
    type: "bar",
    data: [45, 35, 25, 20, 31],
    itemStyle: {
      color: function (params) {
        return barColors[params.dataIndex % barColors.length];
      },
    },
    label: {
      show: true,
      position: "top",
    },
  },
]);
// 承包商审核时效分析 - 柱状图
const handlingTimeXAxis = ref({
  type: "category",
  data: ["0-1天", "1-3天", "3-7天", "7天以上"],
});
const handlingTimeSeries = ref([
  {
    name: "审核数量",
    type: "bar",
    data: [85, 45, 20, 10],
    itemStyle: {
      color: function (params) {
        return barColors[params.dataIndex % barColors.length];
      },
    },
    label: {
      show: true,
      position: "top",
    },
  },
]);
// 获取承包商级别样式
const getContractorLevelType = (level) => {
  switch (level) {
    case "A":
      return "danger";
    case "B":
      return "warning";
    case "C":
      return "info";
    default:
      return "info";
    healthChart.setOption(option);
  }
};
// 初始化故障类型统计饼图
const initFaultChart = () => {
  if (faultChartRef.value) {
    faultChart = echarts.init(faultChartRef.value);
    const option = {
      tooltip: {
        trigger: "item",
      },
      legend: {
        orient: "vertical",
        left: "left",
      },
      series: [
        {
          name: "故障类型",
          type: "pie",
          radius: "50%",
          data: faultTypeData.types.map((type, index) => ({
            name: type,
            value: faultTypeData.values[index],
          })),
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: "rgba(0, 0, 0, 0.5)",
            },
          },
        },
      ],
    };
    faultChart.setOption(option);
  }
};
// 监听窗口大小变化,调整图表大小
const handleResize = () => {
  healthChart?.resize();
  faultChart?.resize();
};
onMounted(() => {
  // 页面加载完成后的初始化操作
  initHealthChart();
  initFaultChart();
  window.addEventListener("resize", handleResize);
});
onUnmounted(() => {
  window.removeEventListener("resize", handleResize);
  healthChart?.dispose();
  faultChart?.dispose();
});
</script>
<style scoped>
.dashboard {
  background: #f5f7fa;
.dashboard-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
  padding: 20px;
  box-sizing: border-box;
}
.dashboard-top {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
.statistics-card {
  height: 180px;
}
.system-info {
.card-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  min-width: 0;
  background-color: #eff2fb;
  border-radius: 12px;
  height: 138px;
}
.system-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  padding-right: 15px;
}
.system-name {
  font-weight: 600;
  font-size: 18px;
  color: #161a9a;
}
.system-meta {
  font-weight: 400;
  font-size: 12px;
  color: #818185;
}
.data-cards {
  display: flex;
  gap: 16px;
  justify-content: flex-start;
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
}
.data-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  min-width: 160px;
  box-shadow: 0 2px 8px #eee;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: center;
  width: 32%;
  height: 140px;
  transition: all 0.3s ease;
  align-items: center;
}
.data-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.data-card.total {
  background: linear-gradient(135deg, #409eff 0%, #66b1ff 100%);
  color: #fff;
}
.data-card.pending {
  background: linear-gradient(135deg, #f56c6c 0%, #f78989 100%);
  color: #fff;
}
.data-card.today {
  background: linear-gradient(135deg, #67c23a 0%, #85ce61 100%);
  color: #fff;
}
.data-title {
  font-weight: 600;
.card-title {
  font-size: 16px;
  margin-bottom: 12px;
  color: #606266;
  margin-bottom: 10px;
}
.data-value {
.card-value {
  font-size: 32px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 8px;
}
.data-desc {
  font-size: 12px;
  opacity: 0.9;
}
.top-left {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 60%;
}
.alarm-panel {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  width: 40%;
}
.alarm-list {
  list-style: none;
  padding: 0;
  margin: 0;
.card-desc {
  font-size: 14px;
  overflow-y: auto;
  height: 260px;
}
.alarm-list li {
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
  border-left: 4px solid #409eff;
  transition: all 0.3s ease;
}
.alarm-list li:hover {
  background: #e9ecef;
  transform: translateX(4px);
}
.alarm-title {
  font-weight: 600;
  font-size: 14px;
  color: #303133;
}
.alarm-value {
  font-size: 12px;
  color: #606266;
}
.alarm-time {
  font-size: 12px;
  color: #909399;
}
.dashboard-row {
.card-header {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  justify-content: space-between;
  align-items: center;
}
.main-panel {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.section-title {
  position: relative;
  font-size: 18px;
  color: #333;
  padding-left: 10px;
  margin-bottom: 20px;
  font-weight: 700;
}
.section-title::before {
  position: absolute;
  left: 0;
  top: 4px;
  content: "";
  width: 4px;
  height: 18px;
  background-color: #409eff;
  border-radius: 2px;
}
.level-list {
  margin: 0;
  padding: 0;
  list-style: none;
  height: 200px;
  overflow-y: auto;
.chart-container {
  width: 100%;
}
.level-list li {
  margin-bottom: 15px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 6px;
  transition: all 0.3s ease;
}
.level-list li:hover {
  background: #e9ecef;
}
.line {
  position: relative;
  width: 80px;
  font-weight: 500;
  height: 350px;
}
</style>