login.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import _ from 'lodash';
  4. Vue.use(Vuex);
  5. const api = {
  6. loginInfo: `/api/jh/v1/login`,
  7. };
  8. const state = () => ({});
  9. const mutations = {};
  10. const actions = {
  11. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  12. const res = await this.$axios.$get(`${api.loginInfo}`, {
  13. skip,
  14. limit,
  15. ...info,
  16. });
  17. return res;
  18. },
  19. async login({ commit }, { user }) {
  20. const res = await this.$axios.$post(`${api.loginInfo}`, user);
  21. if (res.errcode === 0) {
  22. localStorage.setItem('user', JSON.stringify(res.data));
  23. commit('setUser', res.data, { root: true });
  24. }
  25. return res;
  26. },
  27. async fetch({ commit }, payload) {
  28. const res = await this.$axios.$get(`${api.loginInfo}/${payload}`);
  29. return res;
  30. },
  31. async update({ commit }, { id, ...data }) {
  32. const res = await this.$axios.$post(`${api.loginInfo}/${id}`, data);
  33. return res;
  34. },
  35. async delete({ commit }, payload) {
  36. const res = await this.$axios.$delete(`${api.loginInfo}/${payload}`);
  37. return res;
  38. },
  39. };
  40. export default {
  41. namespaced: true,
  42. state,
  43. mutations,
  44. actions,
  45. };