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' 'use strict'
// Template version: 1.3.1 // Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation. // see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path') const path = require('path')
module.exports = { module.exports = {
// configureWebpack: { // configureWebpack: {
// name:"wenhua", // name:"wenhua",
// resolve: { // resolve: {
// alias: { // alias: {
// '@': resolve('src'), // '@': resolve('src'),
// 'views': resolve('src/views') // 'views': resolve('src/views')
// } // }
// } // }
// }, // },
chainWebpack: config => { chainWebpack: config => {
// ...... // ......
config.module config.module
.rule('svg') .rule('svg')
.exclude.add(resolve('../src/assets/icons/svg')) .exclude.add(resolve('../src/assets/icons/svg'))
.end(); .end();
config.module config.module
.rule('icons') .rule('icons')
.test(/\.svg$/) .test(/\.svg$/)
.include.add(resolve('../src/assets/icons/svg')) .include.add(resolve('../src/assets/icons/svg'))
.end() .end()
.use('svg-sprite-loader') .use('svg-sprite-loader')
.loader('svg-sprite-loader') .loader('svg-sprite-loader')
.options({ .options({
symbolId: 'icon-[name]', symbolId: 'icon-[name]',
}) })
.end() .end()
}, },
dev: { dev: {
// Paths // Paths
assetsSubDirectory: 'static', assetsSubDirectory: 'static',
assetsPublicPath: '/', assetsPublicPath: '/',
proxyTable: {}, proxyTable: {},
// Various Dev Server settings // Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST host: '0.0.0.0', // 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 //host: 'localhost', // can be overwritten by process.env.HOST
autoOpenBrowser: false, port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
errorOverlay: true, autoOpenBrowser: false,
notifyOnErrors: true, errorOverlay: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps /**
*/ * Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-module-eval-source-map', // 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 // If you have problems debugging vue-files in devtools,
// https://vue-loader.vuejs.org/en/options.html#cachebusting // set this to false - it *may* help
cacheBusting: true, // https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
}, cssSourceMap: true
},
build: {
// Template for index.html build: {
index: path.resolve(__dirname, '../dist/index.html'), // Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'), // Paths
assetsSubDirectory: 'static', assetsRoot: path.resolve(__dirname, '../dist'),
assetsPublicPath: './', assetsSubDirectory: 'static',
assetsPublicPath: './',
/**
* Source Maps /**
*/ * Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production productionSourceMap: true,
devtool: '#source-map', // 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. // Gzip off by default as many popular static hosts such as
// Before setting to `true`, make sure to: // Surge or Netlify already gzip all static assets for you.
// npm install --save-dev compression-webpack-plugin // Before setting to `true`, make sure to:
productionGzip: false, // npm install --save-dev compression-webpack-plugin
productionGzipExtensions: ['js', 'css'], productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes: // Run the build command with an extra argument to
// `npm run build --report` // View the bundle analyzer report after build finishes:
// Set to `true` or `false` to always turn it on or off // `npm run build --report`
bundleAnalyzerReport: process.env.npm_config_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 // The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue' import Vue from 'vue'
import App from './App' import App from './App'
import router from './router' import router from './router'
import Antd from 'ant-design-vue'; import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css'; import 'ant-design-vue/dist/antd.css';
import echarts from "echarts"; import echarts from "echarts";
//引入svg组件 //引入svg组件
// import IconSvg from './components/svgIcon' // import IconSvg from './components/svgIcon'
// //全局注册svg-icon // //全局注册svg-icon
// Vue.component('svg-icon', IconSvg) // Vue.component('svg-icon', IconSvg)
Vue.use(Antd); Vue.use(Antd);
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$echarts = echarts; Vue.prototype.$echarts = echarts;
// Vue.prototype.$host = 'http://58.30.231.138:8899' // Vue.prototype.$host = 'http://58.30.231.138:8899'
// Vue.prototype.$host = 'http://10.24.4.156' // Vue.prototype.$host = 'http://10.24.4.156'
// Vue.prototype.$host = 'http://10.14.1.197:9090' // Vue.prototype.$host = 'http://10.14.1.197:9090'
// Vue.prototype.$host = 'http://wenhua.xingtongworld.com/' //兴通测试 // Vue.prototype.$host = 'http://wenhua.xingtongworld.com/' //兴通测试
// Vue.prototype.$host = 'http://10.24.4.156' //正式服 // Vue.prototype.$host = 'http://10.24.4.156' //正式服
Vue.prototype.$host = 'http://10.14.1.197:9090' //javatest // 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'
// Vue.prototype.$host = 'http://127.0.0.1'
router.beforeEach((to,from,next) => {
// console.log('beforeEach') router.beforeEach((to,from,next) => {
document.title = to.meta.title // console.log('beforeEach')
next() document.title = to.meta.title
}) next()
/* eslint-disable no-new */ })
new Vue({ /* eslint-disable no-new */
el: '#app', new Vue({
router, el: '#app',
components: { App }, router,
template: '<App/>' components: { App },
}) template: '<App/>'
})

121
src/utils/request.js

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

Loading…
Cancel
Save