import { createAPI } from './instance';

// export const apiUrl = 'http://124.93.101.8:9988/dgbg/';
export const apiUrl = '/';
// mobileLogin.view
// 测试账户：2012012099
// 密码：1

const instance = createAPI(apiUrl);

const loadingCounter = () => {
    let count = 0;
    const startLoading = () => {
        count++;
    }
    const endLoading = () => {
        count--;
    }
    const getCount = () => count;
    return {
        startLoading,
        endLoading,
        getCount
    }
};

let loadingCount = loadingCounter();

async function axiosRequest(option = {}) {
    loadingCount.startLoading();
    const res = await instance({
        method: option.method || 'get',
        url: option.url,
        opts: option.body || null,
    });
    loadingCount.endLoading();
    return res;
}

export let loading = loadingCount.getCount() > 0;

export default axiosRequest;

// export function postRequest(url, params = {}) {
//     return instance({
//         method: 'post',
//         url: url,
//         opts: params,
//     });
// }
