import Vue from 'vue'
import Vuex from "vuex";
import app from "./modules/app";
import dataset from "./modules/dataset";
import menudata from "./modules/menudata";
import dicts from './modules/dict'


Vue.use(Vuex);

const store = new Vuex.Store({
    modules: {
        app,
        dataset,
        menudata,
        dicts
    },
    getters: {
        menu: state => state.app.menu,
    },
    mutations: {
        updateDialog(state, {
            show,
            _class,
            modal,
            props,
            title,
            componentName,
            bodyComponent,
            sysmTips,
            refresh,
            top,
            dialogMultiple,
            drag
        }) {
            let data = {
                show,

                _class,
                modal,
                props,
                title,
                componentName,
                bodyComponent,
                dialogMultiple,
                drag,
                sysmTips,
                refresh,
                top
            };
            //如果同时要打开多个弹窗，需要在打开弹窗时设置dialogMultiple为true
            if (dialogMultiple) {
                if (data.show) {
                    state.dialog.push(data);
                } else {

                    state.dialog = state.dialog.filter(item => {
                        if (item.componentName === data.componentName) {
                            item.show = data.show;
                        }
                        if (data.props) {
                            item.props = data.props;
                        }
                        if (data.refresh) {
                            item.refresh = true;
                        }
                        return item;
                        // return item.componentName !== data.componentName
                    })
                    console.log(state.dialog);
                }
            } else {
                state.dialog = [data];
            }
        },
    }
});

export default store;
