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

@ -0,0 +1 @@
VITE_API_BASE_URL=http://localhost:5000

1
platform/.env.production Normal file
View File

@ -0,0 +1 @@
VITE_API_BASE_URL=https://your-production-domain.com/api

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)}%`;

View File

@ -32,7 +32,7 @@
import { ref, onMounted, onBeforeUnmount, watch, nextTick } from 'vue';
import axios from 'axios';
import * as echarts from 'echarts';
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
const chartContainer = ref(null);
const selectedRange = ref('today');
const selectedDevice = ref(1);
@ -82,7 +82,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

@ -155,9 +155,10 @@ export default {
const uploadType = ref<'document' | 'image' | null>(null);
const uploadedFileName = ref('');
const isFileInterpretation = ref(false);
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// API配置
const API_BASE_URL = ref('http://localhost:5000/aiask');
const API_BASE_URL = ref(`${apiUrl}/aiask`);
const userId = ref('user_' + Math.random().toString(36).substr(2, 9));
// 轮询状态

View File

@ -18,7 +18,7 @@ import c6 from '../assets/c6.jpg';
// Array of available avatar images
const avatarImages = [c1, c2, c3, c4, c5, c6];
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// Function to get a random avatar
const getRandomAvatar = () => {
const randomIndex = Math.floor(Math.random() * avatarImages.length);
@ -43,7 +43,7 @@ let timeUpdateTimer: ReturnType<typeof setInterval> | null = null;
onMounted(async () => {
try {
// 调用后端接口获取维修设备数(假设接口为/get-repair-count
const response = await axios.get('http://localhost:5000/dashboard'); // 示例接口
const response = await axios.get(`${apiUrl}/dashboard`); // 示例接口
const { todayFaults } = response.data;
// 更新响应式变量
@ -85,7 +85,7 @@ const totalUsers = ref(0);
// 在组件挂载时获取用户总数
onMounted(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; // 假设返回的数据结构中有data数组
} catch (error) {
console.error('获取用户总数失败:', error);
@ -98,7 +98,7 @@ const devices = ref([]); // 确保已有这个声明
// 获取设备列表
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;
}
@ -126,7 +126,7 @@ const fetchDeviceATemperature = async () => {
temperatureError.value = '';
// 调用优化后的温度API
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'

View File

@ -40,11 +40,11 @@ const timeRanges = ref([]);
const data = ref([]);
const loading = ref(false);
const error = ref('');
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 获取时间范围选项
const fetchMetadata = async () => {
try {
const response = await axios.get('http://localhost:5000/ph_data/get_time_ranges');
const response = await axios.get(`${apiUrl}/ph_data/get_time_ranges`);
timeRanges.value = response.data.time_ranges;
} catch (err) {
console.error('获取时间范围失败:', err);
@ -58,7 +58,7 @@ const fetchData = async () => {
error.value = '';
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`, {
params: {
time_range: selectedTimeRange.value
}

View File

@ -411,12 +411,12 @@ const acidThreshold = ref(5.5)
const alkaliThreshold = ref(8.5)
const previousAcidThreshold = ref(5.5)
const previousAlkaliThreshold = ref(8.5)
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 获取当前pH值数据
const fetchPhData = async () => {
try {
// 调用后端API获取5月27日的pH数据假设后端接口已正确实现
const response = await axios.get('http://localhost:5000/ph_data/get_ph_data', {
const response = await axios.get(`${apiUrl}/ph_data/get_ph_data`, {
params: {
time_range: 'today',
sample_method: 'fixed'

View File

@ -341,11 +341,11 @@ const renderChart = (data) => {
chart.setOption(option);
};
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 获取初始数据
const fetchPhData = async () => {
try {
const response = await axios.get('http://localhost:5000/api/ph_data/get_ph_today');
const response = await axios.get(`${apiUrl}/api/ph_data/get_ph_today`);
chartData.value = response.data.data;
if (chartData.value.length === 0) {

View File

@ -35,7 +35,7 @@ const humidityData = ref([]);
const locations = ref(['设备1', '设备2', '设备3', '设备4', '设备5', '设备6', '设备7']);
const timeRange = ref('current');
const API_URL = 'http://localhost:5000/api/device-sd';
const API_URL = `${import.meta.env.VITE_API_BASE_URL}/api/device-sd`;
const handleTimeRangeChange = () => {
fetchData(timeRange.value);

View File

@ -120,12 +120,12 @@ const option = ref<echarts.EChartsOption>({
}
]
});
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 获取设备列表
const fetchDevices = async () => {
try {
loading.value = true;
const response = await axios.get('http://localhost:5000/api/devices');
const response = await axios.get(`${apiUrl}/api/devices`);
if (response.data.code === 200) {
deviceList.value = response.data.data;
if (Object.keys(response.data.data).length > 0) {

View File

@ -224,7 +224,7 @@ const checkAndTriggerWarning = () => {
}, 5000);
}
};
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
const getCurrentTime = () => {
const now = new Date();
const minutes = now.getMinutes();
@ -236,7 +236,7 @@ const getCurrentTime = () => {
const fetchDevices = async () => {
try {
const response = await axios.get('http://localhost:5000/api/chou1/devices');
const response = await axios.get(`${apiUrl}/api/chou1/devices`);
if (response.data.code === 200) {
return response.data.data;
}
@ -255,7 +255,7 @@ const fetchLatestActualSensorData = async (deviceId: string) => {
hasData.value = false;
const response = await axios.get(
`http://localhost:5000/api/sensor/device/${deviceId}/latest`
`${apiUrl}/api/sensor/device/${deviceId}/latest`
);
if (response.data.code === 200) {
@ -278,7 +278,7 @@ const fetchLatestActualSensorData = async (deviceId: string) => {
const fetchLatestTemperaturePrediction = async () => {
try {
const response = await axios.get('http://localhost:5000/api/prediction/temperature/latest');
const response = await axios.get(`${apiUrl}/api/prediction/temperature/latest`);
if (response.data.code === 200) {
return response.data.data as number;
}

View File

@ -85,11 +85,11 @@ const initChart = () => {
const handleResize = () => {
chartInstance?.resize();
};
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 获取故障类型数据
const fetchFaultData = async () => {
try {
const response = await axios.get('http://localhost:5000/fault-types');
const response = await axios.get(`${apiUrl}/fault-types`);
if (response.data.success) {
faultData.value = response.data.data;
}

View File

@ -97,6 +97,8 @@
</template>
<script>
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
export default {
name: 'FaultManagement',
data() {
@ -123,7 +125,7 @@ export default {
methods: {
async fetchFaults() {
try {
const response = await fetch(`http://localhost:5000/fault-list?page=${this.currentPage}&size=${this.pageSize}&search=${this.searchQuery}&status=${this.selectedStatus}`);
const response = await fetch(`${apiUrl}/fault-list?page=${this.currentPage}&size=${this.pageSize}&search=${this.searchQuery}&status=${this.selectedStatus}`);
const data = await response.json();
if (data.success) {
this.faults = data.data;
@ -159,7 +161,7 @@ export default {
},
async notifyResponsible(fault) {
try {
const response = await fetch(`http://localhost:5000/api/fault/notify/${fault.id}`, {
const response = await fetch(`${apiUrl}/api/fault/notify/${fault.id}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});

View File

@ -294,7 +294,7 @@ const refreshAlerts = () => {
// 模拟刷新数据
console.log('刷新预警数据')
}
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 通知负责人
const notifyResponsible = async () => {
if (!currentAlert.value) return
@ -303,7 +303,7 @@ const notifyResponsible = async () => {
notifyMessage.value = ''
try {
const response = await axios.post(`http://localhost:5000/api/fault/notify/${currentAlert.value.id}`)
const response = await axios.post(`${apiUrl}/api/fault/notify/${currentAlert.value.id}`)
if (response.data.success) {
notifyMessage.value = '通知已成功发送给负责人'

View File

@ -253,7 +253,7 @@ import axios from 'axios';
import Askai from "../components1/askai.vue";
// 配置后端基础URL
axios.defaults.baseURL = 'http://localhost:5000';
axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL;
// 状态管理
const isLoading = ref(false);

View File

@ -46,7 +46,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 },
@ -73,7 +73,7 @@ export default {
async fetchDashboardData() {
this.isLoading = true;
try {
const response = await axios.get('http://localhost:5000/dashboard');
const response = await axios.get(`${apiUrl}/dashboard`);
const {todayFaults, monthlyFaults, limit} = response.data;
this.todayFaults = todayFaults;

View File

@ -577,11 +577,11 @@ onMounted(() => {
fetchLogs();
}
});
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 获取用户数据
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}`
}
@ -613,7 +613,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}`
}
@ -674,7 +674,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}`
}
@ -761,7 +761,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: {
@ -803,7 +803,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

@ -13,11 +13,11 @@ const errorMessage = ref('');
const register = () => {
router.push('/register');
};
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
// 登录功能
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

@ -4,7 +4,7 @@ import axios, { type AxiosError } from 'axios'
import { useRouter } from 'vue-router'
const router = useRouter()
const apiUrl = import.meta.env.VITE_API_BASE_URL // 动态获取API基础URL
const username = ref('')
const password = ref('')
const verificationCode = ref('')
@ -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