fix: 修复API请求配置和代理设置

This commit is contained in:
Free-sss 2025-09-02 14:24:21 +08:00
parent 39b3a7c43f
commit 32ac9141ce
4 changed files with 26 additions and 27 deletions

View File

@ -139,7 +139,6 @@ import axiosInstance from '@/api/axios'
import VChart from 'vue-echarts'
import SmallBorder from '../SmallBorder01Co/index.vue'
import { height } from 'dom-helpers'
import axios from 'axios'
const props = defineProps({
chartConfig: {
type: Object as PropType<CreateComponentType & typeof option>,
@ -272,19 +271,14 @@ const formatAlarmItem = (item) => {
};
const fetchRecentAlarms = async () => {
try {
isLoading.value = true;
const res = await axios.get(
`/awjt/space/getRecentAlarms`,
{
responseType: 'json',
}
);
if (res.data.state === true) {
isLoading.value = true
const res = await axiosInstance.get('/awjt/space/getRecentAlarms', { baseURL: '' });
if (res.state === true) {
let rawData = [];
if (Array.isArray(res.data.value.items)) {
rawData = res.data.value.items;
} else if (Array.isArray(res.data.value)) {
rawData = res.data.value;
if (Array.isArray(res.value.items)) {
rawData = res.value.items;
} else if (Array.isArray(res.value)) {
rawData = res.value;
}
option.dataset = rawData.map(formatAlarmItem);
} else {

View File

@ -19,6 +19,7 @@ import axios from 'axios';
import config, { BarOption } from './config';
import { PropType, toRefs, ref, onMounted, computed, watch } from 'vue';
import dataJson from './data.json'
import axiosInstance from '@/api/axios';
const iframeRef = ref<HTMLIFrameElement | null>(null);
const isIframeReady = ref(false); // 2. iframe
@ -72,9 +73,9 @@ const fetchData = async (url: string) => {
}
try {
//
const response = await axios.get(`/dev${url}`);
if (response.data.state === true && response.data.value && response.data.value.length > 0) {
return response.data.value; //
const response: any = await axiosInstance.get(`/dev${url}`, { baseURL: '' });
if (response.state === true && response.value && response.value.length > 0) {
return response.value; //
} else {
console.warn('API调用失败或返回空数据将使用静态数据。');
return dataJson.barOptions;

View File

@ -31,6 +31,7 @@ import {
} from 'echarts/components'
import axios from 'axios'
import axiosInstance from '@/api/axios'
const props = defineProps({
@ -187,22 +188,23 @@ const fetchAlarmData = async ({ startTime, endTime }: { startTime: string; endTi
}],
};
try {
const res = await axios.get(
`/awjt/space/getNumberByAlarmLevel`,
const res: any = await axiosInstance.get(
`/awjt/space/getNumberByAlarmLevel`,
{
params: { startTime, endTime },
params: { startTime, endTime },
responseType: 'json',
baseURL: ''
}
);
// API
if (res.data.state === true && res.data.value && res.data.value.length > 0) {
console.log(res.data)
if (res.state === true && res.value && res.value.length > 0) {
console.log(res)
return {
dimensions: props.chartConfig.option.dataset.dimensions,
source: res.data.value,
source: res.value,
};
} else {
console.warn('API调用成功但数据为空或状态异常显示默认无数据。', res.data)
console.warn('API调用成功但数据为空或状态异常显示默认无数据。', res)
return defaultNoData;
}
} catch (error) {

View File

@ -45,6 +45,7 @@ import axios from 'axios'
import { getUUID, isPreview } from '@/utils'
import { useYushiVideoStore } from '@/store/modules/yushiVideoStore/yushiVideoStore'
import SmallBaorder01 from '../SmallBorder01Co/index.vue'
import axiosInstance from '@/api/axios'
const yushiStore = useYushiVideoStore()
let selectedList = []
@ -527,10 +528,11 @@ const getDataSource = (newData: any) => {
const fetchCameraTree = async () => {
console.log('fetchCameraTree: 正在获取摄像头树数据...');
try {
const res = await axios.get('/awjt/api/camera/tree');
if (res.status === 200 && res.data && res.data.state) {
console.log("API 响应数据 (Camera Tree):", res.data.value);
return res.data.value;
const res = await axiosInstance.get('/awjt/api/camera/tree', { baseURL: '' });
console.log("API 响应数据 (Camera Tree):", res);
if (res && res.state === true) {
console.log("API 响应数据 (Camera Tree):", res.value);
return res.value;
} else {
console.warn('API 返回非预期数据结构或空数据:', res);
return [];