import Vue from 'vue'; import Vuex from 'vuex'; import _ from 'lodash'; Vue.use(Vuex); const api = { loginInfo: `/api/jh/v1/login`, }; const state = () => ({}); const mutations = {}; const actions = { async query({ commit }, { skip = 0, limit, ...info } = {}) { const res = await this.$axios.$get(`${api.loginInfo}`, { skip, limit, ...info, }); return res; }, async login({ commit }, { user }) { const res = await this.$axios.$post(`${api.loginInfo}`, user); if (res.errcode === 0) { localStorage.setItem('user', JSON.stringify(res.data)); commit('setUser', res.data, { root: true }); } return res; }, async fetch({ commit }, payload) { const res = await this.$axios.$get(`${api.loginInfo}/${payload}`); return res; }, async update({ commit }, { id, ...data }) { const res = await this.$axios.$post(`${api.loginInfo}/${id}`, data); return res; }, async delete({ commit }, payload) { const res = await this.$axios.$delete(`${api.loginInfo}/${payload}`); return res; }, }; export default { namespaced: true, state, mutations, actions, };