0.1.10 • Published 1 month ago

@vanwei-wcs/device-utils v0.1.10

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

wcs-device-utils

🚀 wcs device的一些方法 🌈.

安装

npm i @vanwei-wcs/device-utils

使用

import { CountDeviceNumber } from ' @vanwei-wcs/device-utils'
const count = CountDeviceNumber(data.statistics)
console.log(count)

名词解释

虚拟目录

是wcs虚拟出来的类型,下面代码中的label表示名称、type表示基础类型、abilities表示该类型具有的能力集合

export const VirtualGroups = [
	{ label: '下级域', type: 'port', abilities: []},
	{ label: '区域', type: 'district', abilities: []},
	{ label: '链接', type: 'link', abilities: []}
]

真实设备

能够接入真实的设备类型,下面代码中的label表示名称,type表示基础类型,abilities表示该类型具有的能力集合

export const RealDevices: device[] =  [
	{ label: '网关', type: 'vbox', abilities: ['transcode']},
	{ label: '网络录像机', type: 'NVR', abilities: ['record']},
	{ label: '摄像头', type: 'IPC', abilities: ['video', 'transcode']},
	{ label: '硬盘录像机', type: 'DVR', abilities: ['record']},
	{ label: '门禁', type: 'AccessController', abilities: ['door']},
	{ label: '人证机', type: 'IDCardReader', abilities: ['face']},
	{ label: '一键报警设备', type: 'EmergencyAlarmer', abilities: ['alarm']},
	{ label: '消防网关', type: 'FireGateway', abilities: []},
	{ label: '物联网网关', type: 'IOTBox', abilities: []},
	{ label: '混合硬盘录像机', type: 'HVR', abilities: []},
	{ label: '视频服务器', type: 'DVS', abilities: []},
	{ label: 'NVS设备', type: 'NVS', abilities: []},
	{ label: '智能dvr', type: 'IVR', abilities: []},
	{ label: '车载dvr', type: 'MVR', abilities: []},

	{ label: '云台摄像头', type: 'IPC/IPDome', abilities: ['video', 'ptz']},
	{ label: '红外摄像头', type: 'IPC/TII', abilities: ['video', 'thermal']},
	{ label: '云台红外摄像头', type: 'IPC/TII/IPDome', abilities: ['video', 'ptz', 'thermal']},
	{ label: '智能交通摄像机', type: 'IPC/ITC', abilities: ['video', 'door', 'car']},
	{ label: '智能人脸相机', type: 'IPC/Face', abilities: ['video', 'face']},

	// 兼容性要求,后续版本可能会删除
	{ label: '道闸(弃用)', type: 'ITC', abilities: ['door']},
	{ label: '红外摄像头(弃用)', type: 'TII/IPC', abilities: ['thermal']}
]

设备类型

指设备树中设备的device_type的值,是由下面的DeviceTypePrefix的字段(除了masterText)和设备的基础类型组合而成(用/连接),另外有以下几点需要了解

  • 虚拟目录只能和group组合,其他无限制,
  • 含有group的都称为目录,类似于文件夹
  • 含有device/master的都称为主设备,是表示接入的设备本身,例如group/vbox表示网关目录,它的子级有device/master/vbox和一些其他的目录,这个device/master/vbox就表示网关本身,可以用来执行重启网关等操作
  • 含有device的都成为设备,目前一般情况下只有device/IPC开头的设备(表示摄像头的通道,一般用来播放视频)
// 举例
// group
// group/port
// group/IPC/ITC
// group/AccessController
// device/IPC
// device/IPC/IPDome
// device/master/vbox
// device/master/IPC/Face

组件api

常量 Const

字段说明类型
DeviceTypePrefixwcs设备类型前缀Object{group: 'group',device: 'device',masterText: 'master',master: 'device/master'}
AllBaseTypes全部类型数组Array打印以查看具体值
VirtualGroups虚拟目录Array
RealDevices真实设备Array
GroupTypes虚拟目录和group组合之后的设备类型集合Array
DeviceTypes真实设备和device组合之后的设备类型集合Array
GroupDeviceTypesGroupTypes和DeviceTypes的合集Array
MasterDeviceTypes真实设备和device/master组合之后的设备类型集合Array
RealDeviceTypes等于DeviceTypesArray
RealMasterDeviceTypes等于MasterDeviceTypesArray
RealGroupDeviceTypes真实设备和group组合之后的设备类型集合Array
VirtualGroupTypes等于GroupTypesArray

方法 Methods

方法说明参数返回值
GetBaseTypeByDeviceType获取设备类型的基础类型,例如 device/IPC -> IPCdeviceType:stringstring
GetLabelByType根据设备基础类型获取设备label,例如 IPC -> 摄像头type:stringstring
GetLabelByDeviceType获取设备类型的label, 例如 device/master/IPC -> 摄像头deviceType:stringstring
GetLabelByMasterDeviceType获取设备类型的label,含有主设备标识 "(主)", 例如 device/master/IPC -> 摄像头(主)deviceType:stringstring
IsGroupType判断是否是目录deviceType:stringboolean
IsDeviceType判断是真实设备类型,含有device前缀deviceType:stringboolean
IsMasterDeviceType判断是主设备类型,含有device/master前缀deviceType:stringboolean
IsIPCDevice判断是摄像头类型,含有device/IPCdeviceType:stringboolean
GetDeviceTypesByAbility获取含有指定能力的真实设备类型集合(含设备类型前缀),参数ability表示能力,prefix表示返回时组合此前缀,默认为deviceability:string,prefix:stringArray
GetDeviceTypesByAbilities获取一种或多种能力的真实设备类型集合(含设备类型前缀),参数abilities表示能力字符数组,prefix表示返回时组合此前缀,默认为deviceabilities:Array,prefix:stringArray
GetBaseTypesByAbility获取含有指定能力的真实设备基础类型集合,参数ability表示能力ability:stringArray
GetBaseTypesByAbilities获取一种或多种能力的真实设备基础类型集合,参数abilities表示能力字符数组abilities:ArrayArray
CountDeviceNumber统计设备的子设备在线和总数,参数statistics为设备详情中的statistics字段statistics{online,total}
GetDeviceIcon获取设备类型的icon字符,参数deviceType为设备类型,status为设备详情中的status字段,具体请参考文末的icon解释deviceType:string,status:stringstring
HasChildGroup判断此设备类型的设备是否含有目录类型的子级deviceType:stringboolean
GetPathChain获取一个设备路径path的父级链路数组path:stringstring[]
GetPathsChain获取多个设备路径path的父级链路数组path:string[]string[]
IsValidPath获取多个设备路径path的父级链路数组path:string[]string[]
GetParentPath判断设备路径是否符合规则path:stringboolean

导出定义

export default {
	DeviceTypePrefix,

	AllBaseTypes,

	GroupTypes,
	DeviceTypes,
	MasterDeviceTypes,
	GroupDeviceTypes,

	RealDevices,
	RealDeviceTypes,
	RealMasterDeviceTypes,
	RealGroupDeviceTypes,

	VirtualGroups,
	VirtualGroupTypes,

	GetBaseTypeByDeviceType,
	GetLabelByType,
	GetLabelByDeviceType,
	GetLabelByMasterDeviceType,

	IsGroupType,
	IsDeviceType,
	IsMasterDeviceType,
	IsIPCDevice,

	GetDeviceTypesByAbility,
	GetDeviceTypesByAbilities,
	GetBaseTypesByAbility,
	GetBaseTypesByAbilities,

	CountDeviceNumber,
	GetDeviceIcon,
	HasChildGroup,
	
	IsValidPath,
	GetPathChain,
	GetPathsChain,
	GetParentPath
}

icon解释

通过设备类型和状态来获取一个值,此值可以用来设置这个设备的图片或者图标

/**
 * icon字符列表
 *
 * group	目录
 * device_online	在线设备
 * device_offline	离线设备
 * box_online	在线网关
 * box_offline	离线网关
 * ipc_online	在线摄像头
 * ipc_offline	离线摄像头
 * ball_ipc_online	在线球机
 * ball_ipc_offline	离线球机
 * nvr_online	在线nvr
 * nvr_offline	离线nvr
 * device_master_online	在线主设备
 * device_master_offline	离线主设备
 * link	连接
 * delete	已删除
 *
 */
const icon =  GetDeviceIcon('device/IPC')
const img_url = '/static/device_images/'+ icon + '.png'
// 对应参考图片在device_images文件夹里面,也可以自定义图片
0.1.10

1 month ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago