| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- import store from '@/store'
- import request, { tenantRequest } from '@/utils/request'
- import {
- add,
- update,
- del,
- confirm,
- messageSend,
- send,
- confirmAndSend,
- addTenant,
- addTenantOrOrg,
- addUser
- } from './base'
- import {
- AssetType,
- SupportedAlarmStrategies
- } 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 getTimelineByRange (deviceId, startTime, endTime, options) {
- return request({
- url: `/content/deviceCalender/${deviceId}`,
- method: 'GET',
- params: {
- startTime,
- endTime
- },
- ...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
- })
- }
- function deleteDeviceById (id) {
- return messageSend({
- url: `/device/${id}`,
- method: 'DELETE'
- }, '删除')
- }
- export function deleteDevice ({ id, name, masterId }) {
- if (__SUB_DEVICE__) {
- if (masterId) {
- return confirm(`删除备份设备【${name}】?`).then(() => deleteDeviceById(id))
- }
- return send({
- url: `/device/${id}/standbyDevice`,
- method: 'GET',
- params: { pageNum: 1, pageSize: 1 }
- }).then(({ data }) => confirm(
- data.length
- ? `删除主设备【${name}】后备份设备也将删除`
- : `删除设备【${name}】?`
- )).then(() => deleteDeviceById(id))
- }
- return confirm(`删除设备【${name}】?`).then(() => deleteDeviceById(id))
- }
- // isAttentionFlag 是否带关注标识位,开启值为1
- // attentionValue 过滤值,2为不过滤
- export function getDevices (query, options) {
- return getDevicesByQuery(addTenantOrOrg(query), options)
- }
- export function getDevicesByQuery (query, options) {
- const { tenant, org, ...params } = query
- if (tenant || org && org === store.getters.tenant) {
- return getDevicesByTenant(tenant || org, params, options)
- }
- return getDevicesByOrg(org, params, options)
- }
- export function getDevicesByTenant (tenant, query, options) {
- const { pageNum: pageIndex, pageSize, ...params } = query
- return tenantRequest({
- url: '/device/tenant/page',
- method: 'GET',
- params: {
- tenant,
- pageIndex,
- pageSize,
- ...params
- },
- ...options
- })
- }
- export function getDevicesByOrg (org, query, options) {
- const { pageNum: pageIndex, pageSize, ...params } = query
- return tenantRequest({
- url: '/device/relation/page',
- method: 'GET',
- params: {
- org,
- pageIndex,
- pageSize,
- ...params
- },
- ...options
- })
- }
- 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)
- }
- const productMap = {}
- export function getProduct (id) {
- if (productMap[id]) {
- return Promise.resolve({ data: productMap[id] })
- }
- return request({
- url: `/product/${id}`,
- method: 'GET'
- }).then(({ data }) => {
- if (data) {
- productMap[id] = data
- }
- return { data }
- })
- }
- 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
- })
- }
- 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 addDevicesToGroup (id, deviceIds) {
- return add({
- url: `/deviceGroup/${id}/device`,
- method: 'POST',
- data: deviceIds
- })
- }
- export function deleteDeviceFromGroup (id, { id: deviceId, name }) {
- return confirmAndSend('移除', name, {
- url: `/deviceGroup/${id}/device`,
- method: 'DELETE',
- params: { deviceId }
- })
- }
- export function getDeviceStatistics () {
- return getDeviceStatisticsByPath(store.getters.org)
- }
- export function getDeviceStatisticsByPath (path, options) {
- return tenantRequest({
- url: '/device/listDeviceTotal',
- method: 'GET',
- params: path === store.getters.tenant
- ? { tenant: path }
- : { org: path },
- ...options
- })
- }
- const handeEnum = ['应用重启', '设备重启', '恢复出厂', '未干预']
- const typeEnum = ['primary', 'success', 'danger']
- const labelEnum = ['处理中', '成功', '失败']
- 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, messageId, deviceName, level, pic, picUrl, type, handle, status, happenTime, bugMessage, ...item }) => {
- const alarm = {
- id, messageId, deviceName, level, happenTime,
- file: pic && picUrl
- ? {
- type: AssetType.IMAGE,
- url: picUrl,
- origin: true
- }
- : null,
- type: bugMessage || `预警码【${type}】`,
- handle: handeEnum[handle] || '-',
- status: handle <= 2 && status <= 2
- ? {
- type: typeEnum[status],
- label: labelEnum[status]
- }
- : { label: '-' }
- }
- SupportedAlarmStrategies.forEach(({ key }) => {
- alarm[key] = getTag(item[key])
- })
- return alarm
- }),
- totalCount
- }
- })
- }
- function getTag (status) {
- switch (status) {
- case 0:
- return {
- type: 'primary',
- label: '待发送'
- }
- case 1:
- return {
- type: 'success',
- label: '已发送'
- }
- case 2:
- return {
- type: 'warning',
- label: '发送中'
- }
- case 3:
- return {
- type: 'danger',
- label: '失败'
- }
- case 4:
- return {
- type: 'danger',
- label: '无目标'
- }
- case 5:
- return {
- type: 'warning',
- label: '未开启'
- }
- default:
- return null
- }
- }
- export function getUsersByInform ({ messageId }) {
- return send({
- url: '/deviceException/user/list',
- method: 'GET',
- params: { messageId }
- })
- }
- 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, options) {
- return request({
- url: `/deviceStream/${stream}/authCode`,
- method: 'GET',
- ...options
- })
- }
- export function addDeviceAttention (deviceId) {
- return update({
- url: `/device/attention/add/${deviceId}`,
- method: 'POST',
- data: { deviceId }
- }, '关注')
- }
- export function cancelDeviceAttention (deviceId) {
- return update({
- url: `/device/attention/cancel/${deviceId}`,
- method: 'DELETE'
- }, '取关')
- }
- export function getDeviceAttentionList (options) {
- return request({
- url: '/device/user/attention/list',
- method: 'GET',
- ...options
- })
- }
- export function getStatusReport (id, options) {
- return request({
- url: '/device/screenPower/latestStatusReport',
- method: 'POST',
- data: { deviceIds: id },
- ...options
- })
- }
- export function getDevicesWithPower (params) {
- return request({
- url: '/device/bond/multiFunction/list',
- method: 'GET',
- params
- })
- }
- export function getDepartmentDeviceTree (options) {
- return getDepartmentDeviceTreeByGroup(store.getters.org, options)
- }
- export function getDepartmentDeviceTreeByGroup (path, options) {
- const data = addTenant()
- if (path && path !== data.tenant) {
- data.org = path
- }
- return tenantRequest({
- url: '/admin/department/device/list',
- method: 'GET',
- params: data,
- ...options
- })
- }
|