zs 9 месяцев назад
Родитель
Сommit
1cfec02833
5 измененных файлов с 55 добавлено и 22 удалено
  1. 40 0
      src/store/login.js
  2. 14 1
      src/store/user/mutations.js
  3. 1 1
      src/store/user/state.js
  4. 0 10
      src/store/admin.js
  5. 0 10
      src/store/user.js

+ 40 - 0
src/store/login.js

@@ -0,0 +1,40 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  login: `/login`,
+  logout: `/logout`,
+  pwd: `/pwd`,
+  tokenView: `/tokenView`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  // 重置密码
+  async resetPwd({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.pwd}`, payload);
+    return res;
+  },
+  async login({ commit }, payload) {
+    const type = _.get(payload, 'type');
+    const np = _.omit(payload, 'type');
+    const res = await this.$axios.$post(`${api.login}/${type}`, np);
+    return res;
+  },
+  async logout({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.logout}`, payload);
+    return res;
+  },
+  async tokenView({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.tokenView}`, payload);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 14 - 1
src/store/user/mutations.js

@@ -4,5 +4,18 @@ export const setUser = (state, payload) => {
 
 export const deleteUser = (state, payload) => {
   state.user = {};
-  sessionStorage.removeItem('token');
+  localStorage.removeItem('token');
+};
+
+export const setMenus = (state, payload) => {
+  menus.state = payload;
+};
+
+export const tokenView = async (token) => {
+  const result = await axios.$get(`/token/tokenView`, null, {
+    headers: {
+      token: token,
+    },
+  });
+  return result;
 };

+ 1 - 1
src/store/user/state.js

@@ -1,2 +1,2 @@
 export const user = {};
-export const test = { id: '11' };
+export const menus = [];

+ 0 - 10
src/store/admin.js

@@ -33,16 +33,6 @@ const actions = {
     const res = await this.$axios.$delete(`${api.test}/${payload}`);
     return res;
   },
-  // 重置密码
-  async resetPwd({ commit }, payload) {
-    const id = _.get(payload, 'id', _.get(payload, 'id'));
-    const res = await this.$axios.$post(`${api.test}/resetPwd/${id}`, payload);
-    return res;
-  },
-  async login({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.test}/login`, payload);
-    return res;
-  },
 };
 export default {
   namespaced: true,

+ 0 - 10
src/store/user.js

@@ -33,16 +33,6 @@ const actions = {
     const res = await this.$axios.$delete(`${api.test}/${payload}`);
     return res;
   },
-  // 重置密码
-  async resetPwd({ commit }, payload) {
-    const id = _.get(payload, 'id', _.get(payload, 'id'));
-    const res = await this.$axios.$post(`${api.test}/resetPwd/${id}`, payload);
-    return res;
-  },
-  async login({ commit }, payload) {
-    const res = await this.$axios.$post(`${api.test}/login`, payload);
-    return res;
-  },
 };
 export default {
   namespaced: true,