import Vue from 'vue'
import { axios } from '@/utils/request'
import signMd5Utils from '@/utils/encryption/signMd5Utils'
import Axios from 'axios'

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

export default api

Axios.defaults.timeout=4*60*1000
//post
export function postAction (url, parameter) {
  let sign = signMd5Utils.getSign(url, parameter)
  //将签名和时间戳，添加在请求接口 Header
  let signHeader = { "X-Sign": sign, "X-TIMESTAMP": signMd5Utils.getDateTimeToString() }

  return axios({
    url: url,
    method: 'post',
    data: parameter,
    timeout: 4*60*1000 ,// request timeout (ms)
    headers: signHeader
  })
}

//post method= {post | put}
export function httpAction (url, parameter, method) {
  let sign = signMd5Utils.getSign(url, parameter)
  //将签名和时间戳，添加在请求接口 Header
  let signHeader = { "X-Sign": sign, "X-TIMESTAMP": signMd5Utils.getDateTimeToString() }

  return axios({
    url: url,
    method: method,
    data: parameter,
    headers: signHeader
  })
}

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

//get
export function getAction (url, parameter) {

  let sign = signMd5Utils.getSign(url, parameter)
  //将签名和时间戳，添加在请求接口 Header
  let signHeader = { "X-Sign": sign, "X-TIMESTAMP": signMd5Utils.getDateTimeToString() }

  return axios({
    url: url,
    method: 'get',
    params: parameter,
    headers: signHeader,
    timeout: 59000
  })
}

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

