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

/**
 * 登录
 */
export async function login (data) {
  const res = await request.post('/main/user/login', data);
  if (res.data.code == 0) {
    setToken(res.data.data.token, data.remember);
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 获取用户信息
 */
export async function getLoginUser (data) {
  const res = await request.get('/system/account/getLoginUser', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 获取验证码
 */
export async function getCaptcha (params) {
  const res = await request.get('/main/user/captcha', {params , responseType:'blob'});
    return res;
}


// 保存 logo 和项目名称
export async function logoSave (data) {
  const res = await request.post('/main/logo/save', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取 logo 和项目名称

export async function logoByCode (code) {
  const res = await request.get(`/main/logo/getByCode/${code}`);
  if (res.data.code == 0) {
    return res.data.data    ;
  }
  return Promise.reject(new Error(res.data.message));
}


