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>> <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}`, baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`,
timeout: ResultEnum.TIMEOUT timeout: ResultEnum.TIMEOUT
}) as unknown as MyRequestInstance }) as unknown as MyRequestInstance

View File

@ -139,7 +139,7 @@ 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>,
@ -273,10 +273,11 @@ 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`, `/awjt/space/getRecentAlarms`,
{ {
responseType: 'json', responseType: 'json',
baseURL: '',
} }
); );
if (res.data.state === true) { if (res.data.state === true) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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