Bläddra i källkod

```
feat(config): 更新开发环境代理配置及API基础路径

将开发环境中的代理目标地址更新为本地IP地址,并调整相关注释说明。
同时修改了静态资源配置文件中的 baseUrl 地址以匹配新的后端服务部署位置。
```

zhangtao 3 dagar sedan
förälder
incheckning
f9900f071b
3 ändrade filer med 119 tillägg och 116 borttagningar
  1. 77 77
      config/index.js
  2. 34 31
      src/utils/httpRequest.js
  3. 8 8
      static/config/index.js

+ 77 - 77
config/index.js

@@ -6,95 +6,95 @@ const path = require('path')
 const devEnv = require('./dev.env')
 
 module.exports = {
-  dev: {
+	dev: {
 
-    // Paths
-    assetsSubDirectory: 'static',
-    assetsPublicPath: '/',
-    // 代理列表, 是否开启代理通过[./dev.env.js]配置
-    proxyTable: {
-      // proxyTable: devEnv.OPEN_PROXY === false ? {} : {
-      '/proxyApi': {
-			// target: 'http://smam.qd-xiaomage.com:9210/sqx_fast/',
-			target: 'https://master.dstapp.cn/sqx_fast/',
-			changeOrigin: true,
-			pathRewrite: {
-				'^/proxyApi': ''
-			}
+		// Paths
+		assetsSubDirectory: 'static',
+		assetsPublicPath: '/',
+		// 代理列表, 是否开启代理通过[./dev.env.js]配置
+		proxyTable: {
+			// proxyTable: devEnv.OPEN_PROXY === false ? {} : {
+			'/proxyApi': {
+				// target: 'http://smam.qd-xiaomage.com:9210/sqx_fast/',
+				target: 'http://192.168.1.166:8188/sqx_fast',
+				changeOrigin: true,
+				pathRewrite: {
+					'^/proxyApi': ''
+				}
+			},
+			'/api': {
+				target: 'http://v2.api.haodanku.com/',
+				changeOrigin: true,
+				pathRewrite: {
+					'^/api': ''
+				}
+			},
 		},
-		'/api': {
-			target: 'http://v2.api.haodanku.com/',
-			changeOrigin: true,
-			pathRewrite: {
-				'^/api': ''
-			}
-		},
-    },
 
-    // Various Dev Server settings
-    host: '127.0.0.1', // can be overwritten by process.env.HOST
-    port: 8001, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
-    autoOpenBrowser: true,
-    errorOverlay: true,
-    notifyOnErrors: true,
-    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
+		// Various Dev Server settings
+		host: '127.0.0.1', // can be overwritten by process.env.HOST
+		port: 8001, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
+		autoOpenBrowser: true,
+		errorOverlay: true,
+		notifyOnErrors: true,
+		poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
 
-    // Use Eslint Loader?
-    // If true, your code will be linted during bundling and
-    // linting errors and warnings will be shown in the console.
-    useEslint: true,
-    // If true, eslint errors and warnings will also be shown in the error overlay
-    // in the browser.
-    showEslintErrorsInOverlay: false,
+		// Use Eslint Loader?
+		// If true, your code will be linted during bundling and
+		// linting errors and warnings will be shown in the console.
+		useEslint: true,
+		// If true, eslint errors and warnings will also be shown in the error overlay
+		// in the browser.
+		showEslintErrorsInOverlay: false,
 
-    /**
-     * Source Maps
-     */
+		/**
+		 * Source Maps
+		 */
 
-    // https://webpack.js.org/configuration/devtool/#development
-    devtool: 'eval-source-map',
+		// https://webpack.js.org/configuration/devtool/#development
+		devtool: '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,
+		// 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,
 
-    // CSS Sourcemaps off by default because relative paths are "buggy"
-    // with this option, according to the CSS-Loader README
-    // (https://github.com/webpack/css-loader#sourcemaps)
-    // In our experience, they generally work as expected,
-    // just be aware of this issue when enabling this option.
-    cssSourceMap: false,
-  },
+		// CSS Sourcemaps off by default because relative paths are "buggy"
+		// with this option, according to the CSS-Loader README
+		// (https://github.com/webpack/css-loader#sourcemaps)
+		// In our experience, they generally work as expected,
+		// just be aware of this issue when enabling this option.
+		cssSourceMap: false,
+	},
 
-  build: {
-    // Template for index.html
-    index: path.resolve(__dirname, '../dist/index.html'),
+	build: {
+		// Template for index.html
+		index: path.resolve(__dirname, '../dist/index.html'),
 
-    // Paths
-    assetsRoot: path.resolve(__dirname, '../dist'),
-    assetsSubDirectory: 'static',
-    assetsPublicPath: './',
+		// Paths
+		assetsRoot: path.resolve(__dirname, '../dist'),
+		assetsSubDirectory: 'static',
+		assetsPublicPath: './',
 
-    /**
-     * Source Maps
-     */
+		/**
+		 * Source Maps
+		 */
 
-    productionSourceMap: false,
-    // https://webpack.js.org/configuration/devtool/#production
-    devtool: '#source-map',
+		productionSourceMap: false,
+		// 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'],
+		// 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
-  }
+		// 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
+	}
 }

+ 34 - 31
src/utils/httpRequest.js

@@ -6,34 +6,34 @@ import merge from 'lodash/merge'
 import { clearLoginInfo } from '@/utils'
 
 const http = axios.create({
-  timeout: 1000 * 30,
-  // withCredentials: true,
-  headers: {
-    'Content-Type': 'application/json; charset=utf-8'
-  }
+	timeout: 1000 * 30,
+	// withCredentials: true,
+	headers: {
+		'Content-Type': 'application/json; charset=utf-8'
+	}
 })
 
 /**
  * 请求拦截
  */
 http.interceptors.request.use(config => {
-  config.headers['token'] = Vue.cookie.get('token') // 请求头带上token
-  return config
+	config.headers['token'] = Vue.cookie.get('token') // 请求头带上token
+	return config
 }, error => {
-  return Promise.reject(error)
+	return Promise.reject(error)
 })
 
 /**
  * 响应拦截
  */
 http.interceptors.response.use(response => {
-  if (response.data && response.data.code === 401) { // 401, token失效
-    clearLoginInfo()
-    router.push({ name: 'login' })
-  }
-  return response
+	if (response.data && response.data.code === 401) { // 401, token失效
+		clearLoginInfo()
+		router.push({ name: 'login' })
+	}
+	return response
 }, error => {
-  return Promise.reject(error)
+	return Promise.reject(error)
 })
 
 /**
@@ -41,22 +41,25 @@ http.interceptors.response.use(response => {
  * @param {*} actionName action方法名称
  */
 http.adornUrl = (actionName) => {
-  // 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
-  // return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl) + actionName
+	// 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
+
+	return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl) + actionName
 	// return 'http://smam.qd-xiaomage.com:9210/sqx_fast/' + actionName
-	return 'https://master.dstapp.cn/sqx_fast/' + actionName
+	// return 'https://master.dstapp.cn/sqx_fast/' + actionName
+	// return 'http://192.168.1.166:8188/sqx_fast' + actionName
 }
 
 http.adornWss = (actionName) => {
-  // 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
-  // return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl) + actionName
-	return 'ws://smam.qd-xiaomage.com:9210/wss' + actionName
+	// 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
+	return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl) + actionName
+	// return 'ws://smam.qd-xiaomage.com:9210/wss' + actionName
 }
 
 
 http.adornUrl2 = (actionName) => {
-  // 非生产环境 && 开启代理, 接口前缀统一使用[/sqx_fast/]前缀做代理拦截!
-  // return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/sqx_fast/' : window.SITE_CONFIG.baseUrl) + actionName
+
+	// 非生产环境 && 开启代理, 接口前缀统一使用[/sqx_fast/]前缀做代理拦截!
+	// return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/sqx_fast/' : window.SITE_CONFIG.baseUrl) + actionName
 	return '/api' + actionName
 }
 /**
@@ -65,10 +68,10 @@ http.adornUrl2 = (actionName) => {
  * @param {*} openDefultParams 是否开启默认参数?
  */
 http.adornParams = (params = {}, openDefultParams = false) => {
-  var defaults = {
-    't': new Date().getTime()
-  }
-  return openDefultParams ? merge(defaults, params) : params
+	var defaults = {
+		't': new Date().getTime()
+	}
+	return openDefultParams ? merge(defaults, params) : params
 }
 
 /**
@@ -80,11 +83,11 @@ http.adornParams = (params = {}, openDefultParams = false) => {
  *  form: 'application/x-www-form-urlencoded; charset=utf-8'
  */
 http.adornData = (data = {}, openDefultdata = false, contentType = 'json') => {
-  var defaults = {
-    't': new Date().getTime()
-  }
-  data = openDefultdata ? merge(defaults, data) : data
-  return contentType === 'json' ? JSON.stringify(data) : qs.stringify(data)
+	var defaults = {
+		't': new Date().getTime()
+	}
+	data = openDefultdata ? merge(defaults, data) : data
+	return contentType === 'json' ? JSON.stringify(data) : qs.stringify(data)
 }
 
 export default http

+ 8 - 8
static/config/index.js

@@ -1,14 +1,14 @@
 /**
  * 开发环境
  */
-;(function () {
-  window.SITE_CONFIG = {};
+; (function () {
+	window.SITE_CONFIG = {};
 
-  // api接口请求地址
-    window.SITE_CONFIG['baseUrl'] = 'http://localhost:8080/sz-fast';
+	// api接口请求地址
+	window.SITE_CONFIG['baseUrl'] = 'http://192.168.1.166:8188/sqx_fast';
 
-  // cdn地址 = 域名 + 版本号
-  window.SITE_CONFIG['domain']  = './'; // 域名
-  window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)
-  window.SITE_CONFIG['cdnUrl']  = window.SITE_CONFIG.domain + window.SITE_CONFIG.version;
+	// cdn地址 = 域名 + 版本号
+	window.SITE_CONFIG['domain'] = './'; // 域名
+	window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)
+	window.SITE_CONFIG['cdnUrl'] = window.SITE_CONFIG.domain + window.SITE_CONFIG.version;
 })();