1
Some checks failed
CI / build (push) Has been cancelled

This commit is contained in:
jrhlh
2025-07-18 18:49:59 +08:00
parent 3eeebab4f8
commit bd1fc93771
30 changed files with 119 additions and 177 deletions

View File

@ -62,7 +62,7 @@ import StatCardItem from './StatCardItem.vue';
// 总用户数
const totalUsers = ref(0);
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 设备相关
const devices = ref([]);
const totalDevicesCount = computed(() => devices.value?.length || 0); // 计算设备总数
@ -77,7 +77,7 @@ const repairDevicesCount = ref(0); // 初始化为0
// 获取用户总数
const fetchTotalUsers = async () => {
try {
const response = await axios.get('http://localhost:5000/personnel/users');
const response = await axios.get(`${apiUrl}/personnel/users`);
totalUsers.value = response.data.data.length;
} catch (error) {
console.error('获取用户总数失败:', error);
@ -88,7 +88,7 @@ const fetchTotalUsers = async () => {
// 获取设备列表
const fetchDevices = async () => {
try {
const response = await axios.get('http://localhost:5000/api/device/list');
const response = await axios.get(`${apiUrl}/api/device/list`);
if (response.data.success) {
devices.value = response.data.data;
}
@ -101,7 +101,7 @@ const fetchDevices = async () => {
const fetchDeviceATemperature = async () => {
try {
isTemperatureLoading.value = true;
const response = await axios.get('http://localhost:5000/temperature/daily/average', {
const response = await axios.get(`${apiUrl}/temperature/daily/average`, {
params: { deviceId: 1, date: '2025-05-27' }
});
@ -120,9 +120,9 @@ const fetchDeviceATemperature = async () => {
};
// 获取故障设备数
const fetchRepairDevicesCount = async () => {
const fetchRepairDevicesCount = async () => { `${apiUrl}/dashboard`
try {
const response = await axios.get('http://localhost:5000/dashboard');
const response = await axios.get(`${apiUrl}/dashboard`);
repairDevicesCount.value = response.data.todayFaults || 0;
} catch (error) {
console.error('获取维修设备数失败:', error);

View File

@ -53,6 +53,7 @@ import * as echarts from 'echarts';
const deviceId = ref('TEMP-001');
const lastUpdateTime = ref('刚刚更新');
const isLoading = ref(false);
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 图表相关变量
const chartContainer = ref(null);
@ -103,7 +104,7 @@ const fetchData = async () => {
try {
const [startTime, endTime] = getTimeRange();
const response = await axios.get('http://localhost:5000/api/weather/data', {
const response = await axios.get(`${apiUrl}/api/weather/data`, {
params: { start_time: startTime, end_time: endTime }
});

View File

@ -48,7 +48,7 @@ import Gu4 from "../components3/gu4.vue";
import Gu5 from "../components3/gu5.vue";
import Gu6 from "../components3/gu6.vue";
import Askai from "../components1/askai.vue";
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
export default {
name: 'FaultManagementDashboard',
components: {Askai, Gu6, Gu5, Gu4 },
@ -77,7 +77,7 @@ export default {
this.isLoading = true; // 显示加载状态
try {
// 调用后端故障仪表盘接口需与后端API路径一致
const response = await axios.get('http://localhost:5000/dashboard');
const response = await axios.get(`${apiUrl}/dashboard`);
const {todayFaults, increase, monthlyFaults, limit} = response.data;
// 更新数据到组件状态

View File

@ -8,7 +8,7 @@ const username = ref('');
const password = ref('');
const rememberMe = ref(false);
const errorMessage = ref('');
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 跳转到注册页面
const register = () => {
router.push('/register');
@ -17,7 +17,7 @@ const register = () => {
// 登录功能
const login = async () => {
try {
const response = await axios.post('http://localhost:5000/auth/login', {
const response = await axios.post(`${apiUrl}/auth/login`, {
username: username.value,
password: password.value
}, {

View File

@ -356,6 +356,7 @@ const emailError = ref('');
const phoneError = ref('');
const showDeleteConfirm = ref('');
const isLogsLoaded = ref(false);
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 统一错误处理函数
const handleError = (error, message = '操作失败') => {
@ -557,7 +558,7 @@ onMounted(() => {
// 获取用户数据
const fetchUsers = async () => {
try {
const response = await axios.get('http://localhost:5000/personnel/users', {
const response = await axios.get(`${apiUrl}/personnel/users`, {
headers: {
Authorization: `Bearer ${userInfo.token}`
}
@ -589,7 +590,7 @@ const fetchUsers = async () => {
// 获取日志数据
const fetchLogs = async () => {
try {
const response = await axios.get(`http://localhost:5000/personnel/logs`, {
const response = await axios.get(`${apiUrl}/personnel/logs`, {
headers: {
Authorization: `Bearer ${userInfo.token}`
}
@ -650,7 +651,7 @@ const handleAddUser = async () => {
};
try {
const response = await axios.post('http://localhost:5000/personnel/users', requestData, {
const response = await axios.post(`${apiUrl}/personnel/users`, requestData, {
headers: {
Authorization: `Bearer ${userInfo.token}`
}
@ -737,7 +738,7 @@ const handleEditUser = async () => {
try {
const response = await axios.put(
`http://localhost:5000/personnel/users/${editingUser.value.username}`,
`${apiUrl}/personnel/users/${editingUser.value.username}`,
payload,
{
headers: {
@ -779,7 +780,7 @@ const deleteUser = async (username) => {
if (!confirm(`确定要删除用户 ${username} 吗?此操作不可撤销。`)) return;
try {
const response = await axios.delete(`http://localhost:5000/personnel/users/${username}`, {
const response = await axios.delete(`${apiUrl}/personnel/users/${username}`, {
headers: {
Authorization: `Bearer ${userInfo.token}`
}

View File

@ -9,7 +9,7 @@ const username = ref('')
const password = ref('')
const verificationCode = ref('')
const errorMessage = ref('')
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
let countdownInterval: number | undefined;
const login = () => {
@ -23,7 +23,7 @@ const sendVerificationCode = async () => {
}
try {
await axios.post('http://localhost:5000/captcha/email', {
await axios.post(`${apiUrl}/captcha/email`, {
email: username.value
})
@ -69,7 +69,7 @@ const register = async () => {
}
try {
const response = await axios.post('http://localhost:5000/register', {
const response = await axios.post(`${apiUrl}/register`, {
username: username.value,
password: password.value,
code: verificationCode.value

View File

@ -241,8 +241,8 @@ import { ElMessage, ElMessageBox } from 'element-plus';
import axios from 'axios';
import Askai from "../components1/askai.vue";
// 配置后端基础URL
axios.defaults.baseURL = 'http://localhost:5000';
// ✅ 使用环境变量来配置基础URL
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
// 状态管理
const isLoading = ref(false);
@ -280,8 +280,7 @@ const editFormRules = {
const fetchDevices = async (page = 1, size = 10) => {
isLoading.value = true;
try {
// 使用相对路径自动拼接baseURL
const response = await axios.get('http://localhost:5000/api/device/list', { params: { page, size } });
const response = await axios.get(`${API_BASE_URL}/api/device/list`, { params: { page, size } });
if (response.data.success) {
devices.value = response.data.data;
totalDevices.value = response.data.total;
@ -299,8 +298,7 @@ const fetchDevices = async (page = 1, size = 10) => {
// 新增设备
const handleAddDevice = async () => {
try {
// 使用相对路径
const response = await axios.post('http://localhost:5000/api/device', newDevice.value);
const response = await axios.post(`${API_BASE_URL}/api/device`, newDevice.value);
if (response.data.success) {
ElMessage.success('设备新增成功');
showAddModal.value = false;
@ -318,8 +316,7 @@ const handleAddDevice = async () => {
// 编辑设备
const handleEditDevice = async () => {
try {
// 使用相对路径
const response = await axios.put(`http://localhost:5000/api/device/${editingDevice.value.id}`, editingDevice.value);
const response = await axios.put(`${API_BASE_URL}/api/device/${editingDevice.value.id}`, editingDevice.value);
if (response.data.success) {
ElMessage.success('设备编辑成功');
showEditModal.value = false;
@ -338,8 +335,7 @@ const handleDelete = async (id) => {
await ElMessageBox.confirm('确认删除该设备?', '警告', {
type: 'warning'
}).then(async () => {
// 使用相对路径
const response = await axios.delete(`http://localhost:5000/api/device/${id}`);
const response = await axios.delete(`${API_BASE_URL}/api/device/${id}`);
if (response.data.success) {
ElMessage.success('设备删除成功');
fetchDevices();

View File

@ -14,6 +14,7 @@ import { ElMessageBox, ElNotification, ElDialog, ElMessage } from 'element-plus'
import axios from 'axios';
import html2canvas from 'html2canvas';
import jsPDF from 'jspdf';
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
const drawerVisible = ref(false);
const drawerVisibleHumidity = ref(false);
@ -126,7 +127,7 @@ const fetchDeviceATemperature = async () => {
// Simulate getting humidity data
const fetchPhData = async () => {
try {
const response = await axios.get('http://localhost:5000/ph_data/get_ph_data');
const response = await axios.get(`${apiUrl}/ph_data/get_ph_data`);
if (response.data.data.length > 0) {
const avgPh = response.data.data.reduce((sum: number, item: { ph: number }) => sum + item.ph, 0) / response.data.data.length;
currentPh.value = avgPh.toFixed(2);
@ -138,7 +139,7 @@ const fetchPhData = async () => {
const fetchHumidityData = async () => {
try {
const response = await axios.get('http://localhost:5000/moisture');
const response = await axios.get(`${apiUrl}/moisture`);
if (Array.isArray(response.data) && response.data.length > 0) {
const avg = response.data.reduce((sum: number, item: { moisture: number }) => sum + item.moisture, 0) / response.data.length;
currentHumidity.value = `${Math.round(avg)}%`;