nicecode-v2/packages/func/es/camera/index.js
2024-01-10 15:15:12 +08:00

142 lines
5.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { get, has, isString } from 'lodash-es';
import { loop } from "../utils";
import { DevicemanagerCameraType, DeviceType } from "./constants";
export var isFaceCamera = function isFaceCamera(type) {
return [DevicemanagerCameraType.DEVICEMANAGER_CAMERA_TYPE_1400, DevicemanagerCameraType.DEVICEMANAGER_CAMERA_TYPE_HKGRABBER, DevicemanagerCameraType.DEVICEMANAGER_CAMERA_TYPE_DHGRABBER].includes(type);
};
/**
*
* @param value 传入的数据 可以是 itemcamera/vms/dirs/ deviceID
* @param isId
*/
export function getDeviceType(value) {
var type;
var isDeviceKey = isString(value);
if (isDeviceKey) {
type = value.split('_')[0];
} else {
if (has(value, 'longitude')) {
type = DeviceType['CAMERA'];
}
if (has(value, 'ip')) {
type = DeviceType['VMS'];
}
if (!type) {
type = DeviceType['DIR'];
}
}
return type;
}
/**
* 后端设备id/vmsid/dirid是三张表 合并在一起不保证唯一 前端生成唯一key
* @param id 设备id
* @param type 设备类型
*/
export function deviceIDToDeviceKey(id, type, vmsId) {
if (type == DeviceType['DIR']) {
return "".concat(type, "_").concat(id, "_").concat(vmsId);
} else {
return "".concat(type, "_").concat(id);
}
}
/**
* 后端设备id/vmsid/dirid是三张表 合并在一起不保证唯一 前端生成唯一key
* @param item camera/vms/dirs
*/
export function deviceToDeviceKey(item) {
var deviceKey = '';
var type = getDeviceType(item);
if (!type) {
console.error('device type is null!');
}
switch (type) {
case DeviceType['DIR']:
{
var dirId = item['dirid'] || item['dirId'];
if (!dirId && dirId !== 0) {
console.error('dirId type is null!');
}
var vmsId = get(item, 'extendInfo.vmsPlatformId');
if (!vmsId && vmsId !== 0) {
console.error('vmsId type is null!');
}
deviceKey = "".concat(type, "_").concat(dirId, "_").concat(vmsId);
}
break;
case DeviceType['VMS']:
deviceKey = "".concat(type, "_").concat(item['id']);
break;
case DeviceType['CAMERA']:
{
var _vmsId = get(item, 'extendInfo.vmsPlatformId');
if (!_vmsId && _vmsId !== 0) {
console.error('vmsId type is null!');
}
deviceKey = "".concat(type, "_").concat(item.id);
}
break;
}
return deviceKey;
}
/**
* 设备树key 转 后端设备原始id dirid是string/vms&camera 是number 和后端保持一致
* @param deviceKey 设备树的id
*/
export function deviceKeyToDeviceId(deviceKey) {
var _deviceKey$split = deviceKey.split('_'),
_deviceKey$split2 = _slicedToArray(_deviceKey$split, 2),
type = _deviceKey$split2[0],
id = _deviceKey$split2[1];
return type === DeviceType['DIR'] ? id : Number(id);
}
export var getVmsIdByDeviceId = function getVmsIdByDeviceId(key) {
var type = getDeviceType(key);
var vmsId = '';
switch (type) {
case DeviceType['CAMERA']:
case DeviceType['DIR']:
vmsId = key.split('_')[2];
break;
case DeviceType['VMS']:
vmsId = key.split('_')[1];
break;
}
if (!vmsId) {
console.error('vmsid is null!');
}
return vmsId;
};
/**
* 通过设备id或设备key在树里面找摄像头
* @param ids cameraId
* @param deviceTree 树
* @param type "id" | "key"
*/
export var findCamerasByInDeviceTree = function findCamerasByInDeviceTree() {
var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var deviceTree = arguments.length > 1 ? arguments[1] : undefined;
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'id';
var cameraInfoList = [];
var _ids = ids.map(function (v) {
return String(v);
}); //都转string在做判断 保证格式一致
loop(deviceTree, function (item) {
var isCamera = getDeviceType(get(item, 'key', '')) === DeviceType['CAMERA'];
var isMatch = type === 'key' ? _ids.includes(get(item, 'key')) : _ids.includes("".concat(get(item, 'origin.id')));
if (isCamera && isMatch) {
cameraInfoList.push(item);
}
});
return cameraInfoList;
};