chore(request): add dev proxy

This commit is contained in:
woody 2025-06-08 14:01:49 +08:00
parent 2b7fc03414
commit 83e62b7944
3 changed files with 22 additions and 30 deletions

View File

@ -1,17 +1,4 @@
~# just a flag ~# just a flag
ENV = 'development' ENV = 'development'
# base api VUE_APP_BASE_API = '/prod-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/'

View File

@ -9,14 +9,14 @@ import { MessageBox, Message, Loading } from 'element-ui'
import store from '@/store' import store from '@/store'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import errorCode from '@/utils/errorCode' import errorCode from '@/utils/errorCode'
import { tansParams, blobValidate } from "@/utils/ruoyi" import { tansParams, blobValidate } from '@/utils/ruoyi'
import { saveAs } from 'file-saver' import { saveAs } from 'file-saver'
// create an axios instance // create an axios instance
let downloadLoadingInstance let downloadLoadingInstance
// 是否显示重新登录 // 是否显示重新登录
export let isRelogin = { show: false } export const isRelogin = { show: false }
const service = axios.create({ const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests // withCredentials: true, // send cookies when cross-domain requests
@ -27,7 +27,7 @@ const service = axios.create({
service.interceptors.request.use( service.interceptors.request.use(
config => { config => {
if (localStorage.getItem('lang')) { if (localStorage.getItem('lang')) {
config.headers['Accept-Language'] = localStorage.getItem('lang'); config.headers['Accept-Language'] = localStorage.getItem('lang')
} else { } else {
config.headers['Accept-Language'] = 'zh-CN' config.headers['Accept-Language'] = 'zh-CN'
} }
@ -44,7 +44,7 @@ service.interceptors.request.use(
if (value !== null && typeof (value) !== 'undefined') { if (value !== null && typeof (value) !== 'undefined') {
if (typeof value === 'object') { if (typeof value === 'object') {
for (const key of Object.keys(value)) { for (const key of Object.keys(value)) {
let params = propName + '[' + key + ']' const params = propName + '[' + key + ']'
var subPart = encodeURIComponent(params) + '=' var subPart = encodeURIComponent(params) + '='
url += subPart + encodeURIComponent(value[key]) + '&' url += subPart + encodeURIComponent(value[key]) + '&'
} }
@ -140,7 +140,6 @@ service.interceptors.response.use(
} }
) )
// 通用下载方法 // 通用下载方法
export function download(url, params, filename, config) { export function download(url, params, filename, config) {
downloadLoadingInstance = Loading.service({ text: '正在下载数据,请稍候', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) 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' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: 'blob', responseType: 'blob',
...config ...config
}).then(async (data) => { }).then(async(data) => {
const isLogin = await blobValidate(data) const isLogin = await blobValidate(data)
if (isLogin) { if (isLogin) {
const blob = new Blob([data]) const blob = new Blob([data])

View File

@ -42,7 +42,13 @@ module.exports = {
warnings: false, warnings: false,
errors: true errors: true
}, },
before: require('./mock/mock-server.js') proxy: {
'/prod-api': {
target: 'http://192.168.1.100:8080',
changeOrigin: true,
pathRewrite: { '^/prod-api': '' }
}
}
}, },
configureWebpack: { configureWebpack: {
// provide the app's title in webpack's name field, so that // provide the app's title in webpack's name field, so that
@ -53,12 +59,12 @@ module.exports = {
'@': resolve('src') '@': resolve('src')
} }
}, },
externals:{ externals: {
'zhCN':'zhCN', 'zhCN': 'zhCN',
'enUS':'enUS', 'enUS': 'enUS',
'zhTC':'zhTC', 'zhTC': 'zhTC',
'ruRU':'ruRU', 'ruRU': 'ruRU',
'frFR':'frFR', 'frFR': 'frFR'
} }
}, },
chainWebpack(config) { chainWebpack(config) {