lrf402788946 4 年之前
父節點
當前提交
6369d604a6
共有 2 個文件被更改,包括 68 次插入2 次删除
  1. 64 0
      store/logs.js
  2. 4 2
      utils/axios-wrapper.js

+ 64 - 0
store/logs.js

@@ -0,0 +1,64 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+import axios from 'axios';
+Vue.use(Vuex);
+const api = {
+  leaveInfo: `/api/train/logs`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.leaveInfo}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.leaveInfo}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.leaveInfo}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.leaveInfo}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.leaveInfo}/${payload}`);
+    return res;
+  },
+  async mergeRequest({ commit, dispatch }, { method, data }) {
+    let toRequest = () => {
+      let res = [];
+      for (const i of data) {
+        res.push(dispatch(method, i));
+      }
+      return res;
+    };
+    let result = await axios.all(toRequest());
+    let newFilter = data => {
+      let res = data.map(i => {
+        let type = _.isArray(i);
+        if (!type) {
+          //fetch的多个请求 是object 将errcode为0的data取出来
+          return _.get(i, `data`, i);
+        } else {
+          //query的多个请求 array 将此数据再次走这个方法
+          return newFilter(i);
+        }
+      });
+      return res;
+    };
+    let returns = _.flattenDeep(newFilter(result));
+    return returns;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 4 - 2
utils/axios-wrapper.js

@@ -74,8 +74,10 @@ export default class AxiosWrapper {
       const axios = Axios.create({
         baseURL: this.baseUrl,
       });
-      if (UserUtil.token) {
-        axios.defaults.headers.common.Authorization = UserUtil.token;
+      const user = localStorage.getItem('user');
+      console.log(user);
+      if (user) {
+        axios.defaults.headers.common.Authorization = encodeURI(user);
       }
       let res = await axios.request({
         method: isNullOrUndefined(data) ? 'get' : 'post',