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

const api = {
  user: '/api/user',
  role: '/api/role',downFilePost,
  service: '/api/service',
  permission: '/api/permission',
  permissionNoPager: '/api/permission/no-pager'
}

export default api
export function getJons(url) {
  return axios({
    url: url,
    method:'get' ,
  })
}
//post
export function postAction(url,parameter) {
  return axios({
    url: url,
    method:'post' ,
    data: parameter
  })
}

/**
 * 专门用于支持一些请求时间很长的
 * @param url
 * @param parameter
 * @returns {*}
 */
export function longTimePostAction(url, parameter) {
  return axios({
    url: url,
    method:'post' ,
    data: parameter,
    timeout: 300000
  })
}

//post_form
export function postFormAction(url,parameter) {
  return axios({
    url: url,
    method:'post' ,
    data: parameter,
    headers:{
      'Content-Type':'application/json'
    }
  })
}

//post method= {post | put}
export function httpAction(url,parameter,method) {
  console.log("url:", url)
  return axios({
    url: url,
    method:method ,
    data: parameter
  })
}

//put
export function putAction(url,parameter) {
  return axios({
    url: url,
    method:'put',
    data: parameter
  })
}

//get
export function getAction(url,parameter) {
  return axios({
    url: url,
    method: 'get',
    params: parameter
  })
}

//deleteAction
export function deleteAction(url,parameter) {
  return axios({
    url: url,
    method: 'delete',
    params: parameter
  })
}

export function getUserList(parameter) {
  return axios({
    url: api.user,
    method: 'get',
    params: parameter
  })
}

export function getRoleList(parameter) {
  return axios({
    url: api.role,
    method: 'get',
    params: parameter
  })
}

export function getServiceList(parameter) {
  return axios({
    url: api.service,
    method: 'get',
    params: parameter
  })
}

export function getPermissions(parameter) {
  return axios({
    url: api.permissionNoPager,
    method: 'get',
    params: parameter
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveService(parameter) {
  return axios({
    url: api.service,
    method: parameter.id == 0 ? 'post' : 'put',
    data: parameter
  })
}

/**
 * 下载文件 用于excel导出
 * @param url
 * @param parameter
 * @returns {*}
 */
export function downFile(url,parameter){
  return axios({
    url: url,
    params: parameter,
    method:'get' ,
    responseType: 'blob'
  })
}

export function downFilePost(url,parameter){
  return axios({
    url: url,
    params: parameter,
    method:'post' ,
    responseType: 'blob'
  })
}

export function playRecording(url, parameter) {
  return axios({
    url: url,
    params: parameter,
    method:'post' ,
    timeout: 300000,
    responseType: 'blob'
  })
}
