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 () {
  const res = await request.get('/captcha');
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


// 生成编码
export async function getCode (code) {
  const res = await request.get(`/main/codemanage/getCode/` + code, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 获取当前登陆用户数据权限部门数据
 * @param
 */
export async function getCurrentUserAuthorityDeptAPI () {
  const res = await request.post('/main/user/getCurrentUserAuthorityDepts');
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
