// 单点登录（自研）
import { baseUrl, sso } from '@/api/scan/config'
import http from '@/api/httputils'

/**
 * 根据用户ID获取用户信息：基本信息、菜单、项目
 * nh 2021.10.25
 */
export async function getUserInfoByUserId(param) {
    try {
        var _obj = await http.getUserInfoByUserId({
            puser: {
                userId: param.userId,
                loginDevice: "PC",
                pd: param.pd
            }
        });
        return _obj;
    } catch (error) {
        console.error('getUserInfoByUserId异常：', error);
        return {
            result:'failure'
        };
    }
}

/**
 * 根据token获取用户信息、菜单信息和项目信息
 */
export async function getUserInfo(param) {
    let url = `${baseUrl}${sso}/users/info`
    return await http.getJson(url, param)
}

/**
 * 退出登录
 */
export async function logout(param) {
    let url = `${baseUrl}${sso}/users/logout`
    return await http.postJson(url, param)
}

/**
 * 用户创建
 */
export async function createUsers(param) {
    let url = `${baseUrl}${sso}/users/create`
    return await http.postJson(url, param)
}

/**
 * 用户删除
 */
export async function deleteUsers(param) {
    let url = `${baseUrl}${sso}/users/delete`
    return await http.postJson(url, param)
}

/**
 * 用户修改
 */
export async function updateUsers(param) {
    let url = `${baseUrl}${sso}/users/update`
    return await http.postJson(url, param)
}

/**
 * 用户密码修改
 */
export async function updateUsersPass(param) {
    let url = `${baseUrl}${sso}/users/update/password`
    return await http.postJson(url, param)
}

/**
 * 用户查询
 */
export async function queryUsers(param) {
    let url = `${baseUrl}${sso}/users/query`
    return await http.postJson(url, param)
}

/**
 * 角色创建
 */
export async function createRole(param) {
    let url = `${baseUrl}${sso}/role/create`
    return await http.postJson(url, param)
}

/**
 * 角色删除
 */
export async function deleteRole(param) {
    let url = `${baseUrl}${sso}/role/delete`
    return await http.postJson(url, param)
}

/**
 * 角色修改
 */
export async function updateRole(param) {
    let url = `${baseUrl}${sso}/role/update`
    return await http.postJson(url, param)
}

/**
 * 角色查询
 */
export async function queryRole(param) {
    let url = `${baseUrl}${sso}/role/query`
    return await http.postJson(url, param)
}

/**
 * 角色修改-带菜单配置
 */
export async function updateRoleMenu(param) {
    let url = `${baseUrl}${sso}/role/update/menu`
    return await http.postJson(url, param)
}

/**
 * 角色创建-带菜单配置
 */
export async function createRoleMenu(param) {
    let url = `${baseUrl}${sso}/role/create/menu`
    return await http.postJson(url, param)
}

/**
 * 获取全部菜单
 */
export async function queryMenu(param) {
    let url = `${baseUrl}${sso}/menu/query`
    return await http.getJson(url, param)
}
