import request from '@/utils/request' import { add, update, del, confirm, messageSend, send, confirmAndSend } from './base' export function getRatios () { return request({ url: '/device/resolutionRatio', method: 'GET' }).then(({ data }) => { return { data: Object.keys(data).map(key => { return { value: key, label: key, devices: data[key].map(device => device.name).join(', ') } }) } }) } export function addDevice (data) { return add({ url: '/device', method: 'POST', data }) } export function updateDevice (data) { return update({ url: '/device', method: 'put', data }) } export function deleteDevice ({ id, name }) { return send({ url: `/device/${id}/standbyDevice`, method: 'GET', params: { pageNum: 1, pageSize: 1 } }).then(({ data }) => { return confirm(data.length ? `删除主设备 ${name} 后备份设备也将删除,确定删除?` : `确定删除 ${name}?` ).then(() => messageSend({ url: `/device/${id}`, method: 'DELETE' }, '删除')) }) } export function getDevices (query) { const { pageNum: pageIndex, pageSize, ...params } = query return request({ url: '/device/list', method: 'GET', params: { pageIndex, pageSize, ...params } }) } export function activateDevice ({ id, name }) { return confirmAndSend('激活', name, { url: '/device/batch/activate', method: 'put', data: [id] }) } export function deactivateDevice ({ id, name }) { return confirmAndSend('停用', name, { url: '/device/batch/deactivate', method: 'put', data: [id] }) } export function getDevice (id) { return request({ url: `/device/${id}`, method: 'GET' }) } export function getSubDevices (query) { const { id, pageNum: pageIndex, pageSize, ...params } = query return request({ url: `/device/${id}/standbyDevice`, method: 'GET', params: { pageIndex, pageSize, ...params } }) } export function addSubDevice ({ id }, data) { return add({ url: `/device/${id}/addStandby`, method: 'POST', data }) } export function addProductType (data) { return add({ url: '/productType', method: 'POST', data }) } export function updateProductType (data) { return update({ url: '/productType', method: 'put', data }) } export function deleteProductType ({ id, name }) { return del({ url: `/productType/${id}`, method: 'DELETE' }, name) } export function getProductTypes (query) { const { pageNum: pageIndex, pageSize, ...params } = query return request({ url: '/productType/list', method: 'GET', params: { pageIndex, pageSize, ...params } }) } export function addProduct (data) { return add({ url: '/product', method: 'POST', data }) } export function updateProduct (data) { return update({ url: '/product', method: 'put', data }) } export function deleteProduct ({ id, name }) { return del({ url: `/product/${id}`, method: 'DELETE' }, name) } export function getProducts (query) { const { pageNum: pageIndex, pageSize, ...params } = query return request({ url: '/product/list', method: 'GET', params: { pageIndex, pageSize, ...params } }) } export function addDeviceGroup (data) { return add({ url: '/deviceGroup', method: 'POST', data }) } export function updateDeviceGroup (data) { return update({ url: '/deviceGroup', method: 'put', data }) } export function deleteDeviceGroup ({ id, name }) { return del({ url: `/deviceGroup/${id}`, method: 'DELETE' }, name) } export function getDeviceGroups (query) { const { pageNum: pageIndex, pageSize, ...params } = query return request({ url: '/deviceGroup/list', method: 'GET', params: { pageIndex, pageSize, ...params } }) } export function getDevicesByGroup (id) { return request({ url: `/deviceGroup/${id}/device`, method: 'GET' }) } export function getDeviceTree () { return request({ url: '/deviceGroup/deviceTree', method: 'GET' }) } export function addDeviceToGroup (id, deviceId) { return add({ url: `/deviceGroup/${id}/device`, method: 'POST', data: [].concat(deviceId) }) } export function deleteDeviceFromGroup (id, { id: deviceId, name }) { return confirmAndSend('移除', name, { url: `/deviceGroup/${id}/device`, method: 'DELETE', params: { deviceId } }) } export function getDeviceStatistics (productId) { return request({ url: '/device/listDeviceTotal', method: 'GET', params: { productId } }) } export function getDeviceAlarms (query) { const { pageNum: pageIndex, pageSize, ...params } = query return request({ url: '/deviceException/list', method: 'GET', params: { pageIndex, pageSize, ...params } }) }