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

更新vite配置中的代理目标地址并添加路径重写规则
统一使用axiosInstance替代直接axios调用
移除未使用的axios导入并设置baseURL为空
This commit is contained in:
gaohaifeng 2025-09-02 13:47:51 +08:00
parent 7169e824b3
commit 5752682808
8 changed files with 27 additions and 16 deletions

View File

@ -19,7 +19,7 @@ export interface MyRequestInstance extends Axios {
<T = any>(config: AxiosRequestConfig): Promise<MyResponseType<T>>
}
const axiosInstance = axios.create({
const a = axios.create({
baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`,
timeout: ResultEnum.TIMEOUT
}) as unknown as MyRequestInstance

View File

@ -139,7 +139,7 @@ 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>,
@ -273,10 +273,11 @@ const formatAlarmItem = (item) => {
const fetchRecentAlarms = async () => {
try {
isLoading.value = true;
const res = await axios.get(
const res = await axiosInstance.get(
`/awjt/space/getRecentAlarms`,
{
responseType: 'json',
baseURL: '',
}
);
if (res.data.state === true) {

View File

@ -59,7 +59,8 @@
import { PropType, computed, ref, onMounted, onUnmounted } from 'vue'
import { option as configOption } from './config'
import SmallBorder from '../SmallBorder/index.vue'
import axios from 'axios'
import axiosInstance from '@/api/axios'
const props = defineProps({
chartConfig: {
type: Object as PropType<{ option: typeof configOption }>,
@ -87,10 +88,11 @@ const convertTimestampToDateTime = (timestamp: number | string) => {
const fetchRecentAlarms = async () => {
try {
const res = await axios.get(
const res = await axiosInstance.get(
`/awjt/space/getRecentAlarms`, // dev
{
responseType: 'json',
baseURL:''
}
);

View File

@ -38,7 +38,7 @@ import { mergeTheme } from '@/packages/public/chart'
import config, { includes } from './config'
import { DatasetComponent, GridComponent, TooltipComponent } from 'echarts/components'
import CustomSelect from './select.vue'
import axios from 'axios'
import axiosInstance from '@/api/axios'
const props = defineProps({
themeSetting: {
@ -74,7 +74,8 @@ use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponen
// API
const fetchChartData = async (timeType: string, riskLevel: number) => {
try {
const response = await axios.get(`/awjt/screen/alarmByOption/${timeType}/${riskLevel}`)
const response = await axiosInstance.get(`/awjt/screen/alarmByOption/${timeType}/${riskLevel}`,
{baseURL:''})
if (response.data.state === true) {
return response.data.value || []
} else {

View File

@ -49,7 +49,7 @@ import { useChartDataFetch } from '@/hooks'
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
import isObject from 'lodash/isObject'
import CustomSelect from './select.vue'
import axios from 'axios'
import axiosInstance from '@/api/axios'
const props = defineProps({
themeSetting: {
@ -82,7 +82,7 @@ const selectedTimeRange = ref('day')
// API
const fetchChartData = async (option: string) => {
try {
const response = await axios.get(`/awjt/screen/handleByOption/${option}`)
const response = await axiosInstance.get(`/awjt/screen/handleByOption/${option}`,{baseURL:''})
if (response.data.state === true) {
return response.data.value || []
} else {

View File

@ -24,7 +24,7 @@ import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent, GraphicComponent } from 'echarts/components'
import CustomSelect from './select.vue'
import dataJson from './data.json'
import axios from 'axios'
import axiosInstance from '@/api/axios'
const props = defineProps({
themeSetting: {
@ -236,11 +236,12 @@ function generateTimeRange(period: string): { startTime: string; endTime: string
//
async function fetchAlarmData({ startTime, endTime }: { startTime: string; endTime: string }) {
try {
const res = await axios.get(
const res = await axiosInstance.get(
`/awjt/getAlarmdataRecord`,
{
params: { startTime, endTime }, //
responseType: 'json',
baseURL:''
}
);

View File

@ -55,7 +55,7 @@ import { ref, computed, PropType, onMounted } from 'vue'
import { option as configOption } from './config'
import SmallBorder from '../SmallBorder/index.vue'
import CustomSelect from './select.vue'
import axios from 'axios'
import axiosInstance from '@/api/axios'
const props = defineProps({
chartConfig: {
@ -89,7 +89,7 @@ const calculateWidth = (value: number) => {
// API
const fetchCorpsData = async (option: string) => {
try {
const response = await axios.get(`/awjt/screen/corpsFive/${option}`)
const response = await axiosInstance.get(`/awjt/screen/corpsFive/${option}`,{baseURL:''})
if (response.data.state === true) {
displayData.value = response.data.value || []
} else {

View File

@ -66,9 +66,15 @@ export default ({ mode }) =>
rewrite: (path) => path.replace(/^\/aw/, '')
},
'/awjt/': {
target: 'http://127.0.0.1:8921/',
changeOrigin: true
}, '/dev': {
target: 'http://127.0.0.1:8080/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/awjt/, '')
},
// '/awjt/': {
// target: 'http://127.0.0.1:8921/',
// changeOrigin: true
// },
'/dev': {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/dev/, '')