SubnetAPI.js 1.6 KB
import Axios from 'axios'

import {
  SUBNET_ADMQ, REQUEST_CONFIG, SUBNET_CONDITION_QUERY, SUBNET_UPLOAD,
  SUBNET_DOWNLOAD, SUBNET_DELETE
} from '../../utils/RequestUrls'

var staticMethods = {
  // 获取所有子网
  getSubnetCollection: function () {
    return Axios.get(SUBNET_ADMQ)
  },

  // 添加子网
  postAddSubnet: function (subnet) {
    return Axios.post(SUBNET_ADMQ, subnet, REQUEST_CONFIG)
  },

  // 删除子网
  deleteDeleteSubnet: function (subnetKeyList) {
    return Axios.delete(SUBNET_ADMQ, {
      data: subnetKeyList,
      headers: {'Content-Type': 'application/json', 'Encoding': 'utf-8'}
    })
  },

  // 修改子网
  putModifySubnet: function (subnet) {
    return Axios.put(SUBNET_ADMQ, subnet, REQUEST_CONFIG)
  },

  // 条件查询子网
  putConditionQuerySubnet: function (conditionSet) {
    return Axios.put(SUBNET_CONDITION_QUERY, conditionSet, REQUEST_CONFIG)
  },

  // 子网文件下载
  putDownloadSubnet: function (conditionSet) {
    return Axios.put(SUBNET_DOWNLOAD, conditionSet, {
      headers: {
        'Content-Type': 'application/json'
      },
      responseType: 'arraybuffer'
    })
  },

  // 子网文件上传
  postUploadSubnet: function (fileFormData) {
    return Axios.post(SUBNET_UPLOAD + '/1', fileFormData, {headers: {
      'Content-Type': 'multipart/form-data',
      'Accept': 'application/json'
    }})
  }

}

function SubnetAPI (websocketService = null) {
  return Object.freeze(Object.assign(
    {
      // object methods comes here
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(SubnetAPI, staticMethods)
export default SubnetAPI