/*
 * @Author: Gui
 * @Date: 2023-03-01 19:20:44
 * @LastEditors: guicheng 1625811865@qq.com
 * @LastEditTime: 2024-04-16 16:41:07
 * @Description: kxs files
 * @filePath:
 */
import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";
import encryptByDES from "@/utils/encryptByDES";
import { getGroupUrl } from "@/utils/getUrl/getUrl.js";
const UrlList = await getGroupUrl();

export type UserResult = {
  status: String;
  data: {
    SysAdminId: string;
    realName: string;
    rightList: any;
    apiToken: string;
    /** 用户名 */
    username: string;
    /** 当前登陆用户的角色 */
    roles: Array<string>;
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

export type RefreshTokenResult = {
  success: boolean;
  status: String;
  data: {
    apiTokenExpiredDate: string | number | Date;
    apiToken: any;
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};
/** 登录 */
export const getLogin = (data?: object) => {
  console.log(data);
  return http.login(
    "http://localhost:5296/v1/kxs/sysServer/oauth2/token",
    data
  );
};
/** 获取当前用户树形菜单 */
export const getUserMenu = () => {
  console.log(UrlList);
  return http.Request({
    url: UrlList.kxsSys.menugetUserMenu.url,
    method: UrlList.kxsSys.menugetUserMenu.method,
    params: {}
  });
};

/** 刷新token */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>("post", "/refreshtoken", {
    data: { value: encryptByDES(JSON.stringify(data)) }
  });
};
