From 83e62b79446ab7ea0af8ffd3500a9e44f79f7819 Mon Sep 17 00:00:00 2001 From: woody Date: Sun, 8 Jun 2025 14:01:49 +0800 Subject: [PATCH] chore(request): add dev proxy --- .env.development | 15 +-------------- src/utils/request.js | 13 ++++++------- vue.config.js | 24 +++++++++++++++--------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/.env.development b/.env.development index b438539..8370733 100644 --- a/.env.development +++ b/.env.development @@ -1,17 +1,4 @@ ~# just a flag ENV = 'development' -# base api -#开发 -#VUE_APP_BASE_API = 'http://182.92.11.203:8050' - - -#超 -#VUE_APP_BASE_API = 'http://192.168.31.159:8080' -VUE_APP_BASE_API = 'http://localhost:8080' - -#测试 -# VUE_APP_BASE_API = 'http://a1.hzs413.com/prod-api' -# VUE_APP_BASE_API = 'http://s.hzs413.com/prod-api' -VUE_APP_ADDRESS = 'https://yx.hzs413.com/' -VUE_APP_ADDRESS1 = 'https://cn.hzs413.com/' +VUE_APP_BASE_API = '/prod-api' diff --git a/src/utils/request.js b/src/utils/request.js index 1cb0d8c..760e44c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -9,14 +9,14 @@ import { MessageBox, Message, Loading } from 'element-ui' import store from '@/store' import { getToken } from '@/utils/auth' import errorCode from '@/utils/errorCode' -import { tansParams, blobValidate } from "@/utils/ruoyi" +import { tansParams, blobValidate } from '@/utils/ruoyi' import { saveAs } from 'file-saver' // create an axios instance let downloadLoadingInstance // 是否显示重新登录 -export let isRelogin = { show: false } +export const isRelogin = { show: false } const service = axios.create({ baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url // withCredentials: true, // send cookies when cross-domain requests @@ -27,7 +27,7 @@ const service = axios.create({ service.interceptors.request.use( config => { if (localStorage.getItem('lang')) { - config.headers['Accept-Language'] = localStorage.getItem('lang'); + config.headers['Accept-Language'] = localStorage.getItem('lang') } else { config.headers['Accept-Language'] = 'zh-CN' } @@ -44,7 +44,7 @@ service.interceptors.request.use( if (value !== null && typeof (value) !== 'undefined') { if (typeof value === 'object') { for (const key of Object.keys(value)) { - let params = propName + '[' + key + ']' + const params = propName + '[' + key + ']' var subPart = encodeURIComponent(params) + '=' url += subPart + encodeURIComponent(value[key]) + '&' } @@ -109,7 +109,7 @@ service.interceptors.response.use( isRelogin.show = false location.href = '/login' store.dispatch('user/Logout').then(() => { - + }) }).catch(() => { isRelogin.show = false @@ -140,7 +140,6 @@ service.interceptors.response.use( } ) - // 通用下载方法 export function download(url, params, filename, config) { downloadLoadingInstance = Loading.service({ text: '正在下载数据,请稍候', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) @@ -151,7 +150,7 @@ export function download(url, params, filename, config) { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, responseType: 'blob', ...config - }).then(async (data) => { + }).then(async(data) => { const isLogin = await blobValidate(data) if (isLogin) { const blob = new Blob([data]) diff --git a/vue.config.js b/vue.config.js index 5a57568..46bb8d8 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,6 +1,6 @@ /* - * @Descripttion: - * @version: + * @Descripttion: + * @version: * @Author: 王三华 * @Date: 2022-10-24 10:45:39 */ @@ -42,7 +42,13 @@ module.exports = { warnings: false, errors: true }, - before: require('./mock/mock-server.js') + proxy: { + '/prod-api': { + target: 'http://192.168.1.100:8080', + changeOrigin: true, + pathRewrite: { '^/prod-api': '' } + } + } }, configureWebpack: { // provide the app's title in webpack's name field, so that @@ -53,12 +59,12 @@ module.exports = { '@': resolve('src') } }, - externals:{ - 'zhCN':'zhCN', - 'enUS':'enUS', - 'zhTC':'zhTC', - 'ruRU':'ruRU', - 'frFR':'frFR', + externals: { + 'zhCN': 'zhCN', + 'enUS': 'enUS', + 'zhTC': 'zhTC', + 'ruRU': 'ruRU', + 'frFR': 'frFR' } }, chainWebpack(config) {