Ver Fonte

Merge branch 'master' of http://git.cc-lotus.info/free-lab/lab-mobile

guhongwei há 3 anos atrás
pai
commit
4e83890920
7 ficheiros alterados com 38 adições e 6 exclusões
  1. 8 0
      .env.development
  2. 5 0
      .env.production
  3. 1 1
      src/plugins/axios.js
  4. 2 0
      src/store/index.js
  5. 2 1
      src/util/axios-wrapper.js
  6. 15 2
      src/views/index.vue
  7. 5 2
      vue.config.js

+ 8 - 0
.env.development

@@ -0,0 +1,8 @@
+# 开发环境配置
+ENV = 'development'
+
+# 若依管理系统/开发环境
+VUE_APP_BASE_API = '/dev-api'
+
+# 路由懒加载
+VUE_CLI_BABEL_TRANSPILE_MODULES = true

+ 5 - 0
.env.production

@@ -0,0 +1,5 @@
+# 生产环境配置
+ENV = 'production'
+
+# 若依管理系统/生产环境
+VUE_APP_BASE_API = '/prod-api'

+ 1 - 1
src/plugins/axios.js

@@ -16,4 +16,4 @@ const Plugin = {
   },
 };
 
-Vue.use(Plugin, { baseUrl: process.env.VUE_APP_AXIOS_BASE_URL });
+Vue.use(Plugin, { baseUrl: process.env.VUE_APP_BASE_API });

+ 2 - 0
src/store/index.js

@@ -3,6 +3,7 @@ import Vuex from 'vuex';
 import * as ustate from '@common/src/store/user/state';
 import * as umutations from '@common/src/store/user/mutations';
 import test from '@common/src/store/test';
+import login from '@common/src/store/login';
 
 Vue.use(Vuex);
 
@@ -12,5 +13,6 @@ export default new Vuex.Store({
   actions: {},
   modules: {
     test,
+    login,
   },
 });

+ 2 - 1
src/util/axios-wrapper.js

@@ -70,7 +70,8 @@ export default class AxiosWrapper {
       const axios = Axios.create({
         baseURL: this.baseUrl,
       });
-      axios.defaults.headers.common.Authorization = util.token;
+      if (util.token) axios.defaults.headers.common.Authorization = `Bearer ${util.token}`;
+      // axios.defaults.headers.isToken = false;
       let res = await axios.request({
         method: isNullOrUndefined(data) ? 'get' : 'post',
         url,

+ 15 - 2
src/views/index.vue

@@ -13,6 +13,7 @@
 <script>
 import adminFrame from '@common/src/components/mobile-frame/mobile-main.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('login');
 export default {
   name: 'index',
   props: {},
@@ -79,8 +80,20 @@ export default {
       ],
     };
   },
-  async created() {},
-  methods: {},
+  async created() {
+    this.toLogin();
+  },
+  methods: {
+    ...mapActions(['login']),
+    async toLogin() {
+      const obj = { username: 'wxyk', password: 'wxyk' };
+      const res = await this.login(obj);
+      if (res.code === 200) {
+        const token = res.token;
+        sessionStorage.setItem('token', token);
+      }
+    },
+  },
   computed: {
     ...mapState(['user']),
   },

+ 5 - 2
vue.config.js

@@ -22,10 +22,13 @@ module.exports = {
       '/files': {
         target: 'http://broadcast.waityou24.cn',
       },
-      '/api': {
-        target: 'http://127.0.0.1:9001',
+      [process.env.VUE_APP_BASE_API]: {
+        target: 'http://127.0.0.1:8112',
         changeOrigin: true,
         ws: false,
+        pathRewrite: {
+          ['^' + process.env.VUE_APP_BASE_API]: '',
+        },
       },
     },
   },