import request from '@/utils/request'
import { AxiosPromise } from 'axios'

// apiUrl 菜单管理
const api = {
	page: '/sys/resource/page',
	listTree: '/sys/resource/list-tree',
	listApi: '/sys/resource/list-api',
	create: '/sys/resource/create',
	update: '/sys/resource/update',
	delete: '/sys/resource/delete'
}
/**
 * 菜单管理 - 列表
 */
function resourcePageApi(data: any): AxiosPromise {
	return request({
		url: api.page,
		method: 'get',
		data
	})
}

function resourceListTreeApi(data: any): AxiosPromise {
	return request({
		url: api.listTree,
		method: 'get',
		data
	})
}

function resourceListApi(params: any): AxiosPromise {
	return request({
		url: api.listApi,
		method: 'get',
		params
	})
}

/**
 * 菜单管理 - 新增编辑保存
 */
function resourceAddOrEditSaveApi(data: any): AxiosPromise {
	return request({
		url: data.id ? api.update : api.create,
		method: 'post',
		data
	})
}

/**
 * 菜单管理 - 删除
 */
function resourceDeleteApi(data: any): AxiosPromise {
	return request({
		url: api.delete,
		method: 'post',
		data
	})
}
export default {
	resourcePageApi,
	resourceListTreeApi,
	resourceListApi,
	resourceAddOrEditSaveApi,
	resourceDeleteApi
}
