import request from '@/utils/request'
/**
 * 获取菜单树的数据 - 异步获取
 * @param {} pid
 * @returns
 */
export function getMenusTree(data) {
  return request({
    url: 'system/menu/getMenusTree',
    method: 'post',
    data
  })
}
/**
 * 获取菜单列表数据-异步获取
 * @param {*} params
 * @returns
 */
export function getMenus(data) {
  return request({
    url: 'system/menu/getMenus',
    method: 'post',
    data
  })
}
/**
 * 获取菜单树数据-编辑时
 * @param {*} ids
 * @returns
 */
export function getSupMenus(data) {
  // const data = Array.isArray(ids) || ids.length === 0 ? ids : Array.of(ids)
  return request({
    url: 'system/menu/getSupMenus',
    method: 'post',
    data
  })
}

export function getChild(data) {
  return request({
    url: 'system/menu/getChild',
    method: 'post',
    data
  })
}

export function add(data) {
  return request({
    url: 'system/menu/saveFormJson',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'system/menu/deleteFormJson',
    method: 'post',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'system/menu/saveFormJson',
    method: 'post',
    data
  })
}

export default {
  add,
  edit,
  del,
  getMenusTree,
  getSupMenus,
  getMenus,
  getChild
}
