

import axios from 'axios'
 const url = 'http://1.193.162.246:18402/ydspcore/api';//服务器地址
//  const url = 'http://192.168.31.17:5000/api';//测试地址

class API{
    constructor(controller){
        //UserController
        let name = controller.substring(0,controller.indexOf('Controller'));
        this.api = `${url}/${name}`;
    }
    //显示，调用次方法
    All(action){
        return axios.get(this.formatAPI(action));
    }
    //查询，可调用此方法
    Get(action,filter){
        return axios.get(`${this.formatAPI(action)}/${filter}`);
    }
    //添加，调用此方法
    Post(action,modal){
        return axios.post(this.formatAPI(action),modal);
    }
    //修改，可调用此方法
    //  id修改编号 ,   modal 修改对象
    Put(action,id,modal){
        return axios.put(`${this.formatAPI(action)}/${id}`,modal);
    }
    //删除，调用此方法
    Delete(action,id){
        return axios.delete(`${this.formatAPI(action)}/${id}`);
    }

    formatAPI(action){
        return (action!=undefined && action !=null)? `${this.api}/${action}`: this.api;
    }

    
}
export default API;