index.ts 4.85 KB
import { defHttp } from '@/utils/external/http/axios'
import { CameraRecord, ConfigurationItemType, DictItem, OrganizationListItem, UploadResponse } from './model'
import { PaginationResult } from '/#/external/axios'
import { isShareMode } from '@/views/share/hook'

enum Api {
  GET_DICT = '/dict_item',
  UPLOAD = '/oss/upload',
  DOWNLOAD = '/oss/download_file/',
  AREALIST = '/area/list',
  PLATFORM = '/platform/get',
  CONFIGURATION = '/configuration/center',
  CONFIGURATION_SHARE = '/configuration/center/share/',
  BASEORIGINATION = '/organization/me/list/',
  VIDEO = '/video/list',
  DEVICE_PROFILE = '/device_profile/me/list',
  DEVICE = '/device',
  VIDEOURL = '/video/url/',
  GEOJSONURL = '/map/geo_json/',
  DEVICE_URL = '/device',
  GET_ATTRBUTELIST = '/device/attributes/',
  GET_DEVICE_LATEST = '/plugins/telemetry/DEVICE/',
  DEVICE_ATTR = '/device/attributes',
  ALARM_LIST = '/alarm',
  BASE_DELETE_URL = '/oss',
  DATA_SQL = '/dbConnect',
}

//sql选择列表
export const getDataViewSqlPage = (params: object) => {
  return defHttp.get<PaginationResult<ConfigurationItemType>>({ url: `${Api.DATA_SQL}`, params })
}
//保存和更新组件SQL查询配置
export const saveDictItemByCode = (params: object) => {
  return defHttp.post<DictItem[]>({
    url: `${Api.DATA_SQL}/saveDataSet`,
    params: params
  })
}
//预览大屏查询组件数据
export const getDataView = (params: object) => {
  return defHttp.post<DictItem[]>({
    url: `${Api.DATA_SQL}/getDataView`,
    params: params
  })
}

export const getDictItemByCode = (value: string) => {
  return defHttp.post<DictItem[]>({
    url: `${Api.GET_DICT}/find`,
    params: {
      dictCode: value
    }
  })
}

export const upload = (file: FormData) => {
  return defHttp.post<UploadResponse>({
    url: Api.UPLOAD,
    params: file
  })
}

export const downloadFile = (fileName: string) => {
  return defHttp.get({ url: `${Api.DOWNLOAD}${fileName}` })
}

//获取区域
export const getAreaList = (data: object) => {
  return defHttp.post<any>({
    url: Api.AREALIST,
    data
  })
}

//获取企业定制
export const getPlatformInfo = () => defHttp.get({ url: Api.PLATFORM })

//获取组态列表
export const getConfigurationList = (params: object) => {
  return defHttp.get<PaginationResult<ConfigurationItemType>>({ url: `${Api.CONFIGURATION}`, params })
}

//组态设置是否公开或私有
export const setConfigurationIsShare = (params: string, isShare: boolean, data: object) => {
  return defHttp.post({
    url: `${Api.CONFIGURATION_SHARE}${params}?isShare=${isShare}`,
    data
  })
}

// 获取设备状态,在线 or 离线时间
export const getDeviceActiveTime = (entityId: string) => {
  return defHttp.get(
    {
      url: `/plugins/telemetry/DEVICE/${entityId}/values/attributes?keys=active`
    },
    {
      joinPrefix: false
    }
  )
}

//获取组织列表
export const getOrganizationList = (params?: OrganizationListItem) =>
  defHttp.get({
    url: Api.BASEORIGINATION,
    params
  })

//获取视频列表
export const getVideoList = (params?: object) =>
  defHttp.get<{ data: CameraRecord[] }>({
    url: Api.VIDEO,
    params
  })

//获取产品列表
export const getProfileList = (params?: object) =>
  defHttp.get({
    url: Api.DEVICE_PROFILE,
    params
  })

//获取设备列表
export const getDeviceList = (params: any, data?: object) =>
  defHttp.post({
    url: Api.DEVICE,
    params,
    data
  })

//获取平台视频流播放地址
export const getVideoUrl = (id: string) =>
  defHttp.get({
    url: `${Api.VIDEOURL}${id}`
  }, {
    withShareToken: true
  })

//获取行政区域
export const getGeoJsonMap = (code: number | string, level: string) => {
  return defHttp.get({
    url: `${Api.GEOJSONURL}${code}/${level}`
  }, { withShareToken: isShareMode() })
}


// 获取设备详情
export const getDeviceDetail = (id: string) =>
  defHttp.get({
    url: Api.DEVICE_URL + `/${id}`
  })

// 获取产品属性
export const getAttribute = (deviceProfileId: string) =>
  defHttp.get({
    url: `${Api.GET_ATTRBUTELIST}${deviceProfileId}`
  })

// 获取设备最新数据
export const getDeviceLatest = (tbDeviceId: string) =>
  defHttp.get({
    url: `${Api.GET_DEVICE_LATEST}${tbDeviceId}/values/timeseries`
  }, {
    joinPrefix: false
  })

//获取产品属性
export const getProfileAttrs = (params: { deviceProfileId: string; dataType?: string }) => {
  const { deviceProfileId, dataType } = params;
  return defHttp.get({
    url: `${Api.DEVICE_ATTR}/${deviceProfileId}`,
    params: { dataType },
  });
};

//获取告警列表
export const getAlarmList = (params?: object) =>
  defHttp.get({
    url: Api.ALARM_LIST,
    params
  },
    {
      withShareToken: true
    })


/**
 * 删除上传的图片
 * @description deleteFilePath图片url
 */
export const deleteFilePath = (deleteFilePath?: string) => {
  return defHttp.delete({
    url: `${Api.BASE_DELETE_URL}?deleteFilePath=${deleteFilePath}`,
  });
};