import customPageApi from '../../../../api/customPage';

/**
 * 缓存信息
 * */
export default {
    namespaced: true,
    state: {
        // 自定义页面
        pages: {}
    },
    getters: {
        get: (state, getters) => code => {
            return state.pages[code];
        }
    },
    actions: {
        /**
         * @description 加载数据视图
         * @param {Object} state vuex state
         * @param {*} code 代码
         */
        async load({ state }, code) {
            if (!(code in state.pages)) {
                let res = await customPageApi.getByCode(code);
                state.pages[code] = res;

                return res;
            } else {
                return state.pages[code];
            }
        }
    }
};
