import apiFormImport from "../api/apiForm";
let apiForm = apiFormImport.apis;
let axios = null;

export default {
    name: "FORM_RES_GLOBAL",

    OBJ_RES: {}, // 资源缓存

    install(Vue,opts){
        axios = opts.spcpFormAxios;
    },

    /**
     * 根据ID获取资源信息
     * @param id
     * @returns {*}
     */
    getById(id) {
        return new Promise(resolve => {
            if(!this.OBJ_RES[id]){
                axios.post(apiForm.plFormResource.getById, {id: id}).then(res => {
                    if(res.data){
                        this.OBJ_RES[id] = res.data|| {};
                        resolve(this.OBJ_RES[id]);
                    }else{
                        resolve(null);
                    }
                });
            }else{
                resolve(this.OBJ_RES[id]);
            }
        });
    }
}
