1
huangxiaoqiang
15 小时以前 af5847927931d3f491d7be5e0178cff3c37ac6f9
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
  <div class="chart_left" style="margin-left: 20px;">
    <div class="titles">
      <el-icon class="icons" :size="24" color="#409EFF">
        <Checked />
      </el-icon>
      任务进行中
    </div>
    <div style="margin-top: 20px;"></div>
    <div class="item_center">
      <Task-List :data="chartData" :options="chartOptions" />
    </div>
  </div>
  <div class="chart_left" style="margin-left: 20px;">
    <div class="titles">
      <el-icon class="icons" :size="24" color="#409EFF">
        <Checked />
      </el-icon>
      任务进行中
    </div>
    <div style="margin-top: 20px;"></div>
    <div class="item_center">
      <Task-List :data="chartData" :options="chartOptions" />
    </div>
  </div>
</template>
<script setup>
import TaskList from '../components/index/TaskList.vue';
import http from '../api/http.js';
import { ref, onMounted, onUnmounted, watch } from 'vue'; 
const taskListRef = ref(null); 
// 示例数据
const chartData = ref([
  // { value: 103, name: '已取消', itemStyle: { color: '#FF6B6B' } },
  // { value: 735, name: '已完成', itemStyle: { color: '#4ECDC4' } },
]);
 
const fetchData = async () => {
  try {
    const response = await http.post("api/Task/GetTaskData", {});
    chartData.value = response.data; 
 
    if (taskListRef.value) taskListRef.value.initChart();
  } catch (error) {
    console.error('API请求失败:', error);
  }
};
const intervalId = ref(null)
const startPolling = () => {
  fetchData(); // 初始加载
  intervalId.value = setInterval(fetchData, 5 * 60 * 1000); // 5分钟
};
 
// 清理定时器
const stopPolling = () => {
  if (intervalId.value) {
    clearInterval(intervalId.value);
    console.log('已停止数据轮询');
  }
};
onMounted(() => {
  startPolling();
});
onUnmounted(() => {
  stopPolling();
});
const chartOptions = ref({
  tooltip: {
    formatter: '{b}: {c} ({d}%)'
  },
  legend: {
    itemWidth: 14,
    itemHeight: 14,
    textStyle: { fontSize: 12 }
  }
});
</script>
<style scoped>
.dashboard {
  width: 100%;
  height: 100vh;
  padding: 20px;
  box-sizing: border-box;
}
 
.m-charts {
  display: grid;
  margin: 10px;
  grid-template-columns: 33% 33% 95%;
  justify-content: space-between;
}
 
.labelContent {
  padding-top: 3vh;
}
 
.chart_left {
  position: relative;
  border-radius: 10px;
  background-color: white;
  box-shadow: 0px 0px 10px 0px #ccc;
  height: 100%;
  width: 550px;
}
 
.icons {
  margin-right: 5px;
}
 
.indexModel .item_center {
  height: 90vh;
  width: 98%;
  margin: 0vh 20%;
}
 
.titles {
  width: 200px;
  height: 5vh;
  display: flex;
  align-items: center;
  font-size: 1.5rem;
  font-weight: 600;
  position: absolute;
  top: 0px;
  left: 15px;
}</style>