Browse Source

添加生成环境和测试环境不同配置

sunjh 5 years ago
parent
commit
cc3046b414
7 changed files with 228 additions and 238 deletions
  1. 3 1
      config/dev.env.js
  2. 3 11
      config/index.js
  3. 3 1
      config/prod.env.js
  4. 9 0
      config/proxyConfig.js
  5. 196 196
      package-lock.json
  6. 8 7
      src/components/commons/Header.vue
  7. 6 22
      src/js/http.js

+ 3 - 1
config/dev.env.js

@@ -3,5 +3,7 @@ const merge = require('webpack-merge')
 const prodEnv = require('./prod.env')
 
 module.exports = merge(prodEnv, {
-  NODE_ENV: '"development"'
+  NODE_ENV: '"development"',
+  API_ROOT: '"//crowd.mooctest.net"',
+  LOGIN_URL: '"http://user.mooctest.net:8081/page/login?redirect=http%3a%2f%2fcrowd.mooctest.net%2f%23%2fmine"'
 })

+ 3 - 11
config/index.js

@@ -3,22 +3,14 @@
 // see http://vuejs-templates.github.io/webpack for documentation.
 
 const path = require('path')
-
+const proxyTable = require('./proxyConfig')
 module.exports = {
   dev: {
 
     // Paths
     assetsSubDirectory: 'static',
     assetsPublicPath: '/',
-    proxyTable: {// config/index.js  文件
-      '/api': {
-        target: 'http://localhost:8080/', // 设置你调用的接口域名和端口号
-        changeOrigin: true,     // 跨域
-        pathRewrite: {
-          '^/api': '/'
-        }
-      },
-    },
+    proxyTable: proxyTable,
 
     // Various Dev Server settings
     host: 'localhost', // can be overwritten by process.env.HOST
@@ -58,7 +50,7 @@ module.exports = {
     // Paths
     assetsRoot: path.resolve(__dirname, '../dist'),
     assetsSubDirectory: 'static',
-    assetsPublicPath: '/',
+    assetsPublicPath: './',
 
     /**
      * Source Maps

+ 3 - 1
config/prod.env.js

@@ -1,4 +1,6 @@
 'use strict'
 module.exports = {
-  NODE_ENV: '"production"'
+  NODE_ENV: '"production"',
+  API_ROOT: '"//crowd.mooctest.net"',
+  LOGIN_URL:'"http://user.mooctest.net:8081/page/login?redirect=http%3a%2f%2fcrowd.dev.mooctest.net%2f%23%2fmine"'
 }

+ 9 - 0
config/proxyConfig.js

@@ -0,0 +1,9 @@
+module.exports = {
+  '/api': {
+    target: 'http://localhost:8080/', // 设置你调用的接口域名和端口号
+    changeOrigin: true,     // 跨域
+    pathRewrite: {
+      '^/api': '/'
+    }
+  },
+}

File diff suppressed because it is too large
+ 196 - 196
package-lock.json


+ 8 - 7
src/components/commons/Header.vue

@@ -72,7 +72,7 @@
               </a>
             </router-link>
             <a v-if="!isLogin" class="dropdown-toggle nav-link" data-toggle="dropdown"
-               href="http://user.mooctest.net:8081/page/login?redirect=http%3a%2f%2fcrowd.mooctest.net%2f%23%2fmine">
+               :href="loginUrl">
               <img class="icon" src="@/assets/img/mine_icon.svg">
               <span>登录</span>
             </a>
@@ -337,6 +337,7 @@ export default {
     return {
       user: {},
       fullScreenLoading: true,
+      loginUrl: process.env.LOGIN_URL,
       authInfo: {},
       isShowAuthCheckingDialog: false,
       isShowAuthRejectDialog: false,
@@ -354,13 +355,13 @@ export default {
 
     })
   },
-  watch:{
-    'user.authStatus'(val){
+  watch: {
+    'user.authStatus' (val) {
       this.user.authStatus = val
       console.log('changed')
       console.log(this.user.authStatus)
     },
-    deep:true
+    deep: true
   },
   methods: {
     openNavBarFunc () {
@@ -403,7 +404,7 @@ export default {
           'isSystemAdministrator': false
         })
         console.log('本地没有用户信息,开始加载用户信息')
-        getCurrentUser().then((res)=>{
+        getCurrentUser().then((res) => {
           console.log(res)
           storageSave('user', res)
           this.user = res
@@ -412,7 +413,7 @@ export default {
           console.log('用户信息加载成功')
           this.isLogin = true
           this.fullScreenLoading = false
-        }).catch((error)=>{
+        }).catch((error) => {
           console.log('用户信息加载失败')
           this.fullScreenLoading = false
         })
@@ -608,7 +609,7 @@ export default {
   },
   created () {
     var self = this
-    this.$root.$on('user',function (val) {
+    this.$root.$on('user', function (val) {
       self.user = val
     })
   },

+ 6 - 22
src/js/http.js

@@ -1,24 +1,9 @@
 import axios from 'axios'
 
 const TIME_OUT_MS = 60 * 1000 // 默认请求超时时间
+const BASE_URL = process.env.API_ROOT
 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
 
-// // 请求拦截器
-// axios.interceptors.request.use(function (config) {
-//   console.log('正确拦截')
-//   console.log(config)
-//   return config
-// }, function (error) {
-//   console.log('错误拦截')
-//   return Promise.reject(error)
-// })
-// // 响应拦截器
-// axios.interceptors.response.use(function (response) {
-//   return response
-// }, function (error) {
-//   return Promise.reject(error)
-// })
-
 /*
  * @param response 返回数据列表
  */
@@ -51,8 +36,7 @@ function handleResults (response) {
 }
 
 function handleUrl (url) {
-  //url = 'http://crowd.mooctest.net' + url
-  return url
+  return BASE_URL + url
 }
 
 /*
@@ -66,7 +50,7 @@ function handleParams (data) {
 export default {
   post (url, data) {
     return new Promise((resolve, reject) => {
-      axios.post(url, handleParams(data)).then(
+      axios.post(handleUrl(url), handleParams(data)).then(
         (result) => {
           resolve(result.data)
         }
@@ -91,7 +75,7 @@ export default {
   },
   put (url, data) {
     return new Promise((resolve, reject) => {
-      axios.put(url, JSON.parse(JSON.stringify(data))).then(
+      axios.put(handleUrl(url), JSON.parse(JSON.stringify(data))).then(
         (result) => {
           resolve(result.data)
         }
@@ -104,7 +88,7 @@ export default {
   },
   delete (url, data) {
     return new Promise((resolve, reject) => {
-      axios.delete(url, {data: handleParams(data)}).then(
+      axios.delete(handleUrl(url), {data: handleParams(data)}).then(
         (result) => {
           resolve(result)
         }
@@ -117,7 +101,7 @@ export default {
   },
   upload (url, data, config) {
     return new Promise((resolve, reject) => {
-      axios.post(url, data, config).then(
+      axios.post(handleUrl(url), data, config).then(
         (result) => {
           resolve(result)
         }

Some files were not shown because too many files changed in this diff