| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525 |
- import request, { tenantRequest } from '@/utils/request'
- import {
- add,
- update,
- del,
- confirm,
- messageSend,
- send,
- confirmAndSend,
- addTenant,
- addTenantOrOrg,
- addUser,
- addOrg
- } from './base'
- import {
- AssetType,
- AlarmStrategies
- } from '@/constant'
- export function getRatiosWithUser () {
- return tenantRequest({
- url: '/device/resolutionRatio',
- method: 'GET',
- params: addTenantOrOrg({})
- }).then(({ data }) => {
- return {
- data: Object.keys(data).map(key => {
- return {
- value: key,
- label: `${key} ${data[key].slice(0, 3).map(device => device.name).join(', ')}`
- }
- })
- }
- })
- }
- export function getRatios () {
- return tenantRequest({
- url: '/device/resolutionRatio',
- method: 'GET',
- params: addTenant({})
- }).then(({ data }) => {
- return {
- data: Object.keys(data).map(key => {
- return {
- value: key,
- label: key
- }
- })
- }
- })
- }
- export function getTimeline (deviceId, options) {
- return request({
- url: `/content/deviceCalender/${deviceId}`,
- method: 'GET',
- ...options
- }).then(({ data }) => JSON.parse(data.eventDetail) || [])
- }
- 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 }) => confirm(
- data.length
- ? `删除主设备后备份设备也将删除`
- : `删除 ${name} ?`,
- data.length
- ? `删除 ${name}`
- : null
- )).then(() => messageSend({
- url: `/device/${id}`,
- method: 'DELETE'
- }, '删除'))
- }
- export function getDevices (query, options) {
- const scope = addTenantOrOrg({})
- if (scope.tenant) {
- return getDevicesByAdmin({
- ...query,
- ...scope
- }, options)
- }
- const { pageNum: pageIndex, pageSize, ...params } = query
- return tenantRequest({
- url: '/device/relation/page',
- method: 'GET',
- params: {
- pageIndex, pageSize,
- ...params,
- ...scope
- },
- ...options
- })
- }
- export function getDevicesByAdmin (query, options) {
- const { pageNum: pageIndex, pageSize, ...params } = query
- return tenantRequest({
- url: params.tenant ? '/device/tenant/page' : '/device/relation/page',
- method: 'GET',
- params: {
- pageIndex, pageSize,
- ...params
- },
- ...options
- })
- }
- export function getBoundDevices (query, options) {
- const { pageNum: pageIndex, pageSize, ...params } = query
- return request({
- url: '/device/allocate/page',
- method: 'GET',
- params: {
- pageIndex, pageSize,
- ...params
- },
- ...options
- })
- }
- export function bindDeviceToObject (deviceId, org) {
- return send({
- url: '/device/allocate/department',
- method: 'POST',
- data: { deviceId, org }
- })
- }
- export function unbindDevice ({ deviceRelationId, name }) {
- return confirmAndSend('移除', name, {
- url: `/device/allocate/${deviceRelationId}`,
- method: 'DELETE'
- })
- }
- export function unbindDevices (params) {
- return request({
- url: '/device/allocate/department',
- method: 'DELETE',
- 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 tenantRequest({
- url: '/productType/list',
- method: 'GET',
- params: addTenant({
- 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 tenantRequest({
- url: '/product/list',
- method: 'GET',
- params: addTenant({
- pageIndex, pageSize,
- ...params
- })
- })
- }
- export function addDeviceGroup (data) {
- return add({
- url: '/deviceGroup',
- method: 'POST',
- data: addOrg(data, false)
- })
- }
- 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 tenantRequest({
- url: '/deviceGroup/list',
- method: 'GET',
- params: addUser({
- pageIndex, pageSize,
- ...params
- })
- })
- }
- export function getDevicesByGroup (id) {
- return tenantRequest({
- url: `/deviceGroup/${id}/device`,
- method: 'GET',
- params: addTenantOrOrg({})
- })
- }
- export function getDeviceTree () {
- return tenantRequest({
- url: '/deviceGroup/deviceTree',
- method: 'GET',
- params: addUser(addTenantOrOrg({}))
- })
- }
- 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 tenantRequest({
- url: '/device/listDeviceTotal',
- method: 'GET',
- params: addTenantOrOrg({ productId })
- })
- }
- export function getDeviceAlarms (query) {
- const { pageNum: pageIndex, pageSize, ...params } = query
- return request({
- url: '/deviceException/list',
- method: 'GET',
- params: {
- pageIndex, pageSize,
- ...params
- }
- }).then(({ data, totalCount }) => {
- return {
- data: data.map(({ id, deviceName, level, pic, picUrl, type, handle, status, happenTime, ...item }) => {
- const alarm = {
- id, deviceName, level, happenTime,
- asset: pic && picUrl
- ? {
- type: AssetType.IMAGE,
- url: picUrl,
- thumbnail: picUrl
- }
- : null,
- type: getType(type),
- handle: ['应用重启', '设备重启', '恢复出厂', '未干预'][handle] || '-',
- status: handle <= 2 && status <= 2
- ? {
- type: ['primary', 'success', 'danger'][status],
- label: ['处理中', '成功', '失败'][status]
- }
- : { label: '-' }
- }
- AlarmStrategies.forEach(({ key }) => {
- alarm[key] = getTag(item[key])
- })
- return alarm
- }),
- totalCount
- }
- })
- }
- const AlarmType = {
- 0: '疑似黑屏',
- 1: '设备离线',
- 2: '屏幕拓扑结构异常',
- 3: '播放非法视频',
- 4: '接收卡离线',
- 5: '发送控制设备离线',
- 6: '浪潮智能网关离线',
- 7: '屏幕监控摄像头离线',
- 8: '人流监测摄像头离线',
- 9: '设备上线',
- 10: '回采疑似',
- 11: '回采不合规',
- 12: '空档期',
- 1000: '分割器异常'
- }
- function getType (type) {
- if (type >= 1101 && type <= 1116) {
- type = 1000
- }
- return AlarmType[type] || '-'
- }
- function getTag (value) {
- switch (value) {
- case 0:
- return {
- type: 'danger',
- label: '否'
- }
- case 1:
- return {
- type: 'success',
- label: '是'
- }
- default:
- return { label: '-' }
- }
- }
- export function getTasks (query) {
- const { pageNum: pageIndex, pageSize, ...params } = query
- return request({
- url: '/device/functionTask',
- method: 'GET',
- params: {
- pageIndex, pageSize,
- ...params
- }
- })
- }
- export function addTask (task) {
- return add({
- url: '/device/functionTask',
- method: 'POST',
- data: task
- })
- }
- export function updateTask (task) {
- return update({
- url: '/device/functionTask',
- method: 'PUT',
- data: task
- })
- }
- export function deleteTask ({ taskId }) {
- return del({
- url: `/device/functionTask/${taskId}`,
- method: 'DELETE'
- })
- }
- export function activateTask ({ taskId }) {
- return confirmAndSend('启用', null, {
- url: '/device/functionTask/resume',
- method: 'PUT',
- data: [taskId]
- })
- }
- export function deactivateTask ({ taskId }) {
- return confirmAndSend('停用', null, {
- url: '/device/functionTask/pause',
- method: 'PUT',
- data: [taskId]
- })
- }
- export function getShadow (deviceId) {
- return request({
- url: `/device/shadow/${deviceId}`,
- method: 'GET'
- })
- }
- export function getRecordConfig (deviceId, config) {
- return request({
- url: '/deviceStream/config',
- method: 'GET',
- params: { deviceId },
- ...config
- })
- }
- export function addRecordConfig (data, config) {
- return request({
- url: '/deviceStream/config',
- method: 'POST',
- data,
- ...config
- })
- }
- export function updateRecordConfig (data, config) {
- return request({
- url: '/deviceStream/config',
- method: 'PUT',
- data,
- ...config
- })
- }
- export function authCode (stream) {
- return request({
- url: `/deviceStream/${stream}/authCode`,
- method: 'GET'
- })
- }
|