import request from '@/utils/request';
import { setToken } from '@/utils/token-util';

/**
 * 登录
 */
export async function login(data) {
    const res = await request.post('/login', data);
    if (res.data.code === 200) {
        setToken('Bearer ' + res.data.token, data.remember);
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取验证码
 */
export async function getCaptcha() {
    const res = await request.get('/captchaImage');
    if (res.data.code === 200) {
        return res.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 发送手机验证码
 */
export async function sendMobileCode(data) {
    const res = await request.post('/sendMobileCode', data);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}
