fix: 修复API请求配置和代理设置
This commit is contained in:
parent
39b3a7c43f
commit
32ac9141ce
@ -139,7 +139,6 @@ import axiosInstance from '@/api/axios'
|
|||||||
import VChart from 'vue-echarts'
|
import VChart from 'vue-echarts'
|
||||||
import SmallBorder from '../SmallBorder01Co/index.vue'
|
import SmallBorder from '../SmallBorder01Co/index.vue'
|
||||||
import { height } from 'dom-helpers'
|
import { height } from 'dom-helpers'
|
||||||
import axios from 'axios'
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
chartConfig: {
|
chartConfig: {
|
||||||
type: Object as PropType<CreateComponentType & typeof option>,
|
type: Object as PropType<CreateComponentType & typeof option>,
|
||||||
@ -272,19 +271,14 @@ const formatAlarmItem = (item) => {
|
|||||||
};
|
};
|
||||||
const fetchRecentAlarms = async () => {
|
const fetchRecentAlarms = async () => {
|
||||||
try {
|
try {
|
||||||
isLoading.value = true;
|
isLoading.value = true
|
||||||
const res = await axios.get(
|
const res = await axiosInstance.get('/awjt/space/getRecentAlarms', { baseURL: '' });
|
||||||
`/awjt/space/getRecentAlarms`,
|
if (res.state === true) {
|
||||||
{
|
|
||||||
responseType: 'json',
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (res.data.state === true) {
|
|
||||||
let rawData = [];
|
let rawData = [];
|
||||||
if (Array.isArray(res.data.value.items)) {
|
if (Array.isArray(res.value.items)) {
|
||||||
rawData = res.data.value.items;
|
rawData = res.value.items;
|
||||||
} else if (Array.isArray(res.data.value)) {
|
} else if (Array.isArray(res.value)) {
|
||||||
rawData = res.data.value;
|
rawData = res.value;
|
||||||
}
|
}
|
||||||
option.dataset = rawData.map(formatAlarmItem);
|
option.dataset = rawData.map(formatAlarmItem);
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,6 +19,7 @@ import axios from 'axios';
|
|||||||
import config, { BarOption } from './config';
|
import config, { BarOption } from './config';
|
||||||
import { PropType, toRefs, ref, onMounted, computed, watch } from 'vue';
|
import { PropType, toRefs, ref, onMounted, computed, watch } from 'vue';
|
||||||
import dataJson from './data.json'
|
import dataJson from './data.json'
|
||||||
|
import axiosInstance from '@/api/axios';
|
||||||
|
|
||||||
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
const iframeRef = ref<HTMLIFrameElement | null>(null);
|
||||||
const isIframeReady = ref(false); // 2. 创建一个状态来跟踪 iframe 是否已加载
|
const isIframeReady = ref(false); // 2. 创建一个状态来跟踪 iframe 是否已加载
|
||||||
@ -72,9 +73,9 @@ const fetchData = async (url: string) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// 无后端接口, 此为预留
|
// 无后端接口, 此为预留
|
||||||
const response = await axios.get(`/dev${url}`);
|
const response: any = await axiosInstance.get(`/dev${url}`, { baseURL: '' });
|
||||||
if (response.data.state === true && response.data.value && response.data.value.length > 0) {
|
if (response.state === true && response.value && response.value.length > 0) {
|
||||||
return response.data.value; // 返回原始数据
|
return response.value; // 返回原始数据
|
||||||
} else {
|
} else {
|
||||||
console.warn('API调用失败或返回空数据,将使用静态数据。');
|
console.warn('API调用失败或返回空数据,将使用静态数据。');
|
||||||
return dataJson.barOptions;
|
return dataJson.barOptions;
|
||||||
|
@ -31,6 +31,7 @@ import {
|
|||||||
} from 'echarts/components'
|
} from 'echarts/components'
|
||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import axiosInstance from '@/api/axios'
|
||||||
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -187,22 +188,23 @@ const fetchAlarmData = async ({ startTime, endTime }: { startTime: string; endTi
|
|||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(
|
const res: any = await axiosInstance.get(
|
||||||
`/awjt/space/getNumberByAlarmLevel`,
|
`/awjt/space/getNumberByAlarmLevel`,
|
||||||
{
|
{
|
||||||
params: { startTime, endTime },
|
params: { startTime, endTime },
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
|
baseURL: ''
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// 检查 API 响应状态和数据是否有效且非空
|
// 检查 API 响应状态和数据是否有效且非空
|
||||||
if (res.data.state === true && res.data.value && res.data.value.length > 0) {
|
if (res.state === true && res.value && res.value.length > 0) {
|
||||||
console.log(res.data)
|
console.log(res)
|
||||||
return {
|
return {
|
||||||
dimensions: props.chartConfig.option.dataset.dimensions,
|
dimensions: props.chartConfig.option.dataset.dimensions,
|
||||||
source: res.data.value,
|
source: res.value,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
console.warn('API调用成功但数据为空或状态异常,显示默认无数据。', res.data)
|
console.warn('API调用成功但数据为空或状态异常,显示默认无数据。', res)
|
||||||
return defaultNoData;
|
return defaultNoData;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -45,6 +45,7 @@ import axios from 'axios'
|
|||||||
import { getUUID, isPreview } from '@/utils'
|
import { getUUID, isPreview } from '@/utils'
|
||||||
import { useYushiVideoStore } from '@/store/modules/yushiVideoStore/yushiVideoStore'
|
import { useYushiVideoStore } from '@/store/modules/yushiVideoStore/yushiVideoStore'
|
||||||
import SmallBaorder01 from '../SmallBorder01Co/index.vue'
|
import SmallBaorder01 from '../SmallBorder01Co/index.vue'
|
||||||
|
import axiosInstance from '@/api/axios'
|
||||||
|
|
||||||
const yushiStore = useYushiVideoStore()
|
const yushiStore = useYushiVideoStore()
|
||||||
let selectedList = []
|
let selectedList = []
|
||||||
@ -527,10 +528,11 @@ const getDataSource = (newData: any) => {
|
|||||||
const fetchCameraTree = async () => {
|
const fetchCameraTree = async () => {
|
||||||
console.log('fetchCameraTree: 正在获取摄像头树数据...');
|
console.log('fetchCameraTree: 正在获取摄像头树数据...');
|
||||||
try {
|
try {
|
||||||
const res = await axios.get('/awjt/api/camera/tree');
|
const res = await axiosInstance.get('/awjt/api/camera/tree', { baseURL: '' });
|
||||||
if (res.status === 200 && res.data && res.data.state) {
|
console.log("API 响应数据 (Camera Tree):", res);
|
||||||
console.log("API 响应数据 (Camera Tree):", res.data.value);
|
if (res && res.state === true) {
|
||||||
return res.data.value;
|
console.log("API 响应数据 (Camera Tree):", res.value);
|
||||||
|
return res.value;
|
||||||
} else {
|
} else {
|
||||||
console.warn('API 返回非预期数据结构或空数据:', res);
|
console.warn('API 返回非预期数据结构或空数据:', res);
|
||||||
return [];
|
return [];
|
||||||
|
Loading…
Reference in New Issue
Block a user