
import http from "@/utils/request"
import common from "@/utils/common"
import { ElNotification } from 'element-plus';

export default {
    post: async function (method, params, success, baseUrl) {
        var res = await http.post({
            "jsonrpc": "2.0",
            "id": common.guid(),
            "method": method,
            "params": [params || {}]
        }, "/", { baseURL: baseUrl || "/api" });
        if (res.code != null) {
            ElNotification.error({
                title: '请求错误',
                message: res.message
            });
        }
        else {
            success && success();
        }
        return res;
    },
    list: async function (method, params) {
        if (!params.PageIndex) {
            params.PageIndex = params.page;
        }
        var res = await this.post(method, params);
        var formatterData = {
            total: res.TotalCount,
            rows: res.PageData,
            page: res.PageIndex,
            pageSize: res.PageSize
        };
        return formatterData;
    }
}
