import {fetch} from '@/api/index'
import { getToken } from '@/utils/auth'
const state = {
    projectArr: [],   // 项目
    departmentArr: [],    // 部门
    roleArr: []   // 角色
}

const mutations = {

    SET_PROJECTARR: (state, arr) => {
        state.projectArr = arr
    },
    SET_DEPARTMENTARR: (state, arr) => {
        state.departmentArr = arr
    },
    SET_ROLEARR: (state, arr) => {
        state.roleArr = arr
    },
}

const actions = {
    async setProjectArr({ commit }) {
        if (!getToken()) return
        const data = await fetch('/project/get_list', {}, 'get')
        if (data.code == 200) {
            commit('SET_PROJECTARR', data.data)
        }
    },
    async setDepartmentArr({ commit }) {
        const data = await fetch('/department/get_department_list', {}, 'get')
        if (data.code == 200) {
            commit('SET_DEPARTMENTARR', data.data)
        }
    },
    async setRoleArr({ commit }) {
        const data = await fetch('/role/get_role_list', {}, 'get')
        if (data.code == 200) {
            commit('SET_ROLEARR', data.data)
        }
    }
}

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