import service from '@/utils/request'
// @Summary 用户登录 获取动态路由
// @Produce  application/json
// @Param 可以什么都不填 调一下即可
// @Router /menu/getMenu [post]
export const logList = (data) => {
  return service({
    url: '/loging/getLogList',
    method: 'post',
    data
  })
}

export const logStatistics = (data) => {
  return service({
    url: '/loging/getStatisticsLogList',
    method: 'post',
    data
  })
}

export const logNodeStatistics = (data) => {
  return service({
    url: '/loging/getNodeStatisticsLogList',
    method: 'post',
    data
  })
}

export const logComputerList = (data) => {
  return service({
    url: '/loging/getComputerStatistics',
    method: 'post',
    data
  })
}

export const logGameIdList = (data) => {
  return service({
    url: '/loging/getGameIdStatistics',
    method: 'post',
    data
  })
}


export const logComputerNum = (data) => {
  return service({
    url: '/loging/getComputerNum',
    method: 'post',
    data
  })
}

export const computerUseLog = (data) => {
  return service({
    url: '/loging/getOnlineComputer',
    method: 'post',
    data
  })
}

export const updateComputerUseRemarks = (data) => {
  return service({
    url: '/loging/updatePcRemarks',
    method: 'post',
    data
  })
}

export const getLogScanningList = (data) => {
  return service({
    url: '/loging/getLogScanningList',
    method: 'post',
    data
  })
}


export const computerSevenRate = (data) => {
  return service({
    url: '/loging/computerSevenRate',
    method: 'post',
    data
  })
}

const handleFileError = (res, fileName) => {
  if (typeof (res.data) !== 'undefined') {
    if (res.data.type === 'application/json') {
      const reader = new FileReader()
      reader.onload = function() {
        const message = JSON.parse(reader.result).msg
        ElMessage({
          showClose: true,
          message: message,
          type: 'error'
        })
      }
      reader.readAsText(new Blob([res.data]))
    }
  } else {
    var downloadUrl = window.URL.createObjectURL(new Blob([res]))
    var a = document.createElement('a')
    a.style.display = 'none'
    a.href = downloadUrl
    a.download = fileName
    var event = new MouseEvent('click')
    a.dispatchEvent(event)
  }
}

// @Tags excel
// @Summary 导出Excel
// @Security ApiKeyAuth
// @accept application/json
// @Produce  application/octet-stream
// @Param data body model.ExcelInfo true "导出Excel文件信息"
// @Success 200
// @Router /loging/exportExcel [post]
export const exportExcel = (tableData, fileName) => {
  service({
    url: '/loging/exportExcel',
    method: 'post',
    data: {
      fileName: fileName,
      infoList: tableData
    },
    responseType: 'blob'
  }).then((res) => {
    handleFileError(res, fileName)
  })
}


export const computerRateExport = (tableData, fileName) => {
  service({
    url: '/loging/computerRateExport',
    method: 'post',
    data: {
      fileName: fileName,
      infoList: tableData
    },
    responseType: 'blob'
  }).then((res) => {
    handleFileError(res, fileName)
  })
}
