adminsStore.js 766 Bytes
Newer Older
姜雷 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
import { fetchAdminList } from '@/api/base/index';

const GET_ADMINS_LIST = 'GET_ADMINS_LIST';
const FETCH_STATE = 'FETCH_STATE';

const state = () => ({
  list: [],
  fetching: false,
});

const getters = {
  AdminList: state => state.list,
};

const actions = {
  fetchAdminList({ state, commit }) {
    if (state.fetching) return;
    commit(FETCH_STATE, true);
    return fetchAdminList().then(res => {
      const list = res.data;
      commit(GET_ADMINS_LIST, list);
      commit(FETCH_STATE, false);
    });
  },
};

const mutations = {
  [GET_ADMINS_LIST](state, list) {
    state.list = list;
  },
  [FETCH_STATE](state, fetching) {
    state.fetching = fetching;
  },
};

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations,
};