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

This commit is contained in:
Free-sss 2025-09-02 14:41:58 +08:00
parent 49b4b663d2
commit 161b180e01
7 changed files with 24 additions and 25 deletions

View File

@ -30,7 +30,6 @@ import {
TitleComponent, GraphicComponent
} from 'echarts/components'
import axios from 'axios'
import axiosInstance from '@/api/axios'

View File

@ -528,7 +528,7 @@ const getDataSource = (newData: any) => {
const fetchCameraTree = async () => {
console.log('fetchCameraTree: 正在获取摄像头树数据...');
try {
const res = await axiosInstance.get('/awjt/api/camera/tree', { baseURL: '' });
const res = await axiosInstance.get('/awjt/api/camera/tree', { baseURL: '' ,responseType: 'json' });
console.log("API 响应数据 (Camera Tree):", res);
if (res && res.state === true) {
console.log("API 响应数据 (Camera Tree):", res.value);

View File

@ -88,8 +88,8 @@ const convertTimestampToDateTime = (timestamp: number | string) => {
const fetchRecentAlarms = async () => {
try {
const res = await axiosInstance.get(
`/awjt/space/getRecentAlarms`, // dev
const res:any = await axiosInstance.get(
`/awjt/space/getRecentAlarms`,
{
responseType: 'json',
baseURL:''
@ -97,12 +97,12 @@ const fetchRecentAlarms = async () => {
);
if (res.data.state === true) {
if (res.state === true) {
let rawData = [];
if (Array.isArray(res.data.value.items)) {
if (Array.isArray(res.value.items)) {
rawData = res.data.value.items;
} else if (Array.isArray(res.data.value)) {
rawData = res.data.value;
} else if (Array.isArray(res.value)) {
rawData = res.value;
}
const formattedData = rawData.map((item: any) => {

View File

@ -74,12 +74,12 @@ use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponen
// API
const fetchChartData = async (timeType: string, riskLevel: number) => {
try {
const response = await axiosInstance.get(`/awjt/screen/alarmByOption/${timeType}/${riskLevel}`,
const response:any = await axiosInstance.get(`/awjt/screen/alarmByOption/${timeType}/${riskLevel}`,
{baseURL:''})
if (response.data.state === true) {
return response.data.value || []
if (response.state === true) {
return response.value || []
} else {
console.error('API调用失败:', response.data)
console.error('API调用失败:', response)
return []
}
} catch (error) {

View File

@ -82,11 +82,11 @@ const selectedTimeRange = ref('day')
// API
const fetchChartData = async (option: string) => {
try {
const response = await axiosInstance.get(`/awjt/screen/handleByOption/${option}`,{baseURL:''})
if (response.data.state === true) {
return response.data.value || []
const response:any = await axiosInstance.get(`/awjt/screen/handleByOption/${option}`,{baseURL:''})
if (response.state === true) {
return response.value || []
} else {
console.error('API调用失败:', response.data)
console.error('API调用失败:', response)
return []
}
} catch (error) {

View File

@ -236,7 +236,7 @@ function generateTimeRange(period: string): { startTime: string; endTime: string
//
async function fetchAlarmData({ startTime, endTime }: { startTime: string; endTime: string }) {
try {
const res = await axiosInstance.get(
const res:any = await axiosInstance.get(
`/awjt/getAlarmdataRecord`,
{
params: { startTime, endTime }, //
@ -245,12 +245,12 @@ async function fetchAlarmData({ startTime, endTime }: { startTime: string; endTi
}
);
if (res.status === 200 && res.data) {
console.log("API 响应数据:", res.data);
if ( res) {
console.log("API 响应数据:", res);
//
return {
dimensions: ['name', 'value'],
source: res.data.map((item: any) => ({
source: res.map((item: any) => ({
name: item.alarmLevel,
value: item.alarmNun
}))

View File

@ -68,7 +68,7 @@ const option = computed(() => props.chartConfig.option)
const selectedOption = ref(props.chartConfig.option.dropdownDefault)
// API
const displayData = ref([])
const displayData: any = ref([])
const dropdownOptions = computed(() => {
return props.chartConfig.option.dropdownOptions.map(opt => ({
@ -89,11 +89,11 @@ const calculateWidth = (value: number) => {
// API
const fetchCorpsData = async (option: string) => {
try {
const response = await axiosInstance.get(`/awjt/screen/corpsFive/${option}`,{baseURL:''})
if (response.data.state === true) {
displayData.value = response.data.value || []
const response: any = await axiosInstance.get(`/awjt/screen/corpsFive/${option}`, { baseURL: '' })
if (response.state === true) {
displayData.value = response.value || []
} else {
console.error('API调用失败:', response.data)
console.error('API调用失败:', response)
displayData.value = []
}
} catch (error) {