Browse Source

网络请求适配修改

master
453530270@qq.com 3 years ago
parent
commit
e706a1874d
  1. 193
      config/index.js
  2. 93
      src/main.js
  3. 121
      src/utils/request.js

193
config/index.js

@ -1,96 +1,97 @@
'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
module.exports = {
// configureWebpack: {
// name:"wenhua",
// resolve: {
// alias: {
// '@': resolve('src'),
// 'views': resolve('src/views')
// }
// }
// },
chainWebpack: config => {
// ......
config.module
.rule('svg')
.exclude.add(resolve('../src/assets/icons/svg'))
.end();
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('../src/assets/icons/svg'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]',
})
.end()
},
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-module-eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}
'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
module.exports = {
// configureWebpack: {
// name:"wenhua",
// resolve: {
// alias: {
// '@': resolve('src'),
// 'views': resolve('src/views')
// }
// }
// },
chainWebpack: config => {
// ......
config.module
.rule('svg')
.exclude.add(resolve('../src/assets/icons/svg'))
.end();
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('../src/assets/icons/svg'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]',
})
.end()
},
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// Various Dev Server settings
host: '0.0.0.0', // can be overwritten by process.env.HOST
//host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-module-eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}

93
src/main.js

@ -1,46 +1,47 @@
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import echarts from "echarts";
//引入svg组件
// import IconSvg from './components/svgIcon'
// //全局注册svg-icon
// Vue.component('svg-icon', IconSvg)
Vue.use(Antd);
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts;
// Vue.prototype.$host = 'http://58.30.231.138:8899'
// Vue.prototype.$host = 'http://10.24.4.156'
// Vue.prototype.$host = 'http://10.14.1.197:9090'
// Vue.prototype.$host = 'http://wenhua.xingtongworld.com/' //兴通测试
// Vue.prototype.$host = 'http://10.24.4.156' //正式服
Vue.prototype.$host = 'http://10.14.1.197:9090' //javatest
// Vue.prototype.$host = 'http://127.0.0.1'
router.beforeEach((to,from,next) => {
// console.log('beforeEach')
document.title = to.meta.title
next()
})
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import echarts from "echarts";
//引入svg组件
// import IconSvg from './components/svgIcon'
// //全局注册svg-icon
// Vue.component('svg-icon', IconSvg)
Vue.use(Antd);
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts;
// Vue.prototype.$host = 'http://58.30.231.138:8899'
// Vue.prototype.$host = 'http://10.24.4.156'
// Vue.prototype.$host = 'http://10.14.1.197:9090'
// Vue.prototype.$host = 'http://wenhua.xingtongworld.com/' //兴通测试
// Vue.prototype.$host = 'http://10.24.4.156' //正式服
// Vue.prototype.$host = 'http://192.168.66.221' //javatest
// Vue.prototype.$host = 'http://10.14.1.197:9090' //javatest
// Vue.prototype.$host = 'http://127.0.0.1'
router.beforeEach((to,from,next) => {
// console.log('beforeEach')
document.title = to.meta.title
next()
})
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})

121
src/utils/request.js

@ -1,60 +1,61 @@
import axios from 'axios';
// axios.defaults.baseURL = '/api'
const service = axios.create({
//process.env.NODE_ENV === 'development', //来判断是否开发环境
// baseURL:process.env.NODE_ENV == 'production' ? 'https://yztapi.xingtongworld.com' : '/api/',
baseURL:process.env.NODE_ENV == 'production' ? '../' : 'http://10.14.1.197:9090',
// baseURL:'http://jiao.api.alpha.xingtongworld.com',
// baseURL:'http://58.30.231.138:8899', //测试服
//baseURL:'http://10.24.4.156', //正式服
//baseURL:'http://10.14.1.197:9090', //新服
// baseURL:'http://192.168.66.254:8080',
// baseURL:'http://10.14.1.197:9090', //java测试
timeout: 5000,
});
service.interceptors.request.use(
config => {
let token = localStorage.getItem('wenhua_token'),
url = localStorage.getItem('wenhua_url')
if(token&&url){
config.headers['token'] = token
config.headers['url'] = url
}
return config;
},
error => {
console.log(error);
return Promise.reject();
}
);
service.interceptors.response.use(
response => {
// if (response.data.code === 302) {
// MessageBox.confirm('登录已超时,请重新登录', '退出', {
// confirmButtonText: '登录',
// cancelButtonText: '取消',
// type: 'warning'
// }).then(() => {
// localStorage.removeItem('ms_username')
// localStorage.removeItem('token')
// // this.$router.push('/login');
// location.reload()
// })
// }
if (response.status === 200) {
return response.data;
} else {
Promise.reject();
}
},
error => {
console.log(error);
return Promise.reject();
}
);
export default service;
import axios from 'axios';
// axios.defaults.baseURL = '/api'
const service = axios.create({
//process.env.NODE_ENV === 'development', //来判断是否开发环境
// baseURL:process.env.NODE_ENV == 'production' ? 'https://yztapi.xingtongworld.com' : '/api/',
//baseURL:process.env.NODE_ENV == 'production' ? '../' : 'http://192.168.66.221:8080',
// baseURL:process.env.NODE_ENV == 'production' ? '../' : 'http://10.14.1.197:9090',
// baseURL:'http://jiao.api.alpha.xingtongworld.com',
// baseURL:'http://58.30.231.138:8899', //测试服
baseURL:'http://10.24.4.156', //正式服
//baseURL:'http://10.14.1.197:9090', //新服
// baseURL:'http://192.168.66.254:8080',
// baseURL:'http://10.14.1.197:9090', //java测试
timeout: 5000,
});
service.interceptors.request.use(
config => {
let token = localStorage.getItem('wenhua_token'),
url = localStorage.getItem('wenhua_url')
if(token&&url){
config.headers['token'] = token
config.headers['url'] = url
}
return config;
},
error => {
console.log(error);
return Promise.reject();
}
);
service.interceptors.response.use(
response => {
// if (response.data.code === 302) {
// MessageBox.confirm('登录已超时,请重新登录', '退出', {
// confirmButtonText: '登录',
// cancelButtonText: '取消',
// type: 'warning'
// }).then(() => {
// localStorage.removeItem('ms_username')
// localStorage.removeItem('token')
// // this.$router.push('/login');
// location.reload()
// })
// }
if (response.status === 200) {
return response.data;
} else {
Promise.reject();
}
},
error => {
console.log(error);
return Promise.reject();
}
);
export default service;

Loading…
Cancel
Save