59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
const aliases = {
|
|
lineNumber: ['lineNumber', 'line_number', '序号', '行号'],
|
|
name: ['name', '设备名称', '摄像头名称'],
|
|
location: ['location', '安装位置', '位置'],
|
|
address: ['address', '设备地址', 'ONVIF地址', 'onvif_address']
|
|
}
|
|
|
|
function readAlias(row, names) {
|
|
const key = names.find(name => Object.prototype.hasOwnProperty.call(row, name))
|
|
return key ? row[key] : ''
|
|
}
|
|
|
|
export function normalizeImportRows(rows) {
|
|
return rows.map((row, index) => ({
|
|
lineNumber: Number(readAlias(row, aliases.lineNumber)) || index + 1,
|
|
name: String(readAlias(row, aliases.name) || '').trim(),
|
|
location: String(readAlias(row, aliases.location) || '').trim(),
|
|
address: String(readAlias(row, aliases.address) || '').trim()
|
|
}))
|
|
}
|
|
|
|
export function createBatchPayload(rows, idempotencyKey) {
|
|
return {
|
|
idempotencyKey: String(idempotencyKey || '').trim(),
|
|
rows: normalizeImportRows(rows).map(row => ({
|
|
lineNumber: row.lineNumber,
|
|
name: row.name,
|
|
location: row.location,
|
|
address: row.address
|
|
}))
|
|
}
|
|
}
|
|
|
|
export function credentialPayload(items, credentialByItem) {
|
|
return {
|
|
credentials: items.map(item => {
|
|
const value = credentialByItem[item.id] || {}
|
|
const same = value.rtspSameAsOnvif !== false
|
|
return {
|
|
itemId: item.id,
|
|
onvifUsername: String(value.onvifUsername || ''),
|
|
onvifPassword: String(value.onvifPassword || ''),
|
|
rtspSameAsOnvif: same,
|
|
rtspUsername: same ? '' : String(value.rtspUsername || ''),
|
|
rtspPassword: same ? '' : String(value.rtspPassword || '')
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
export function clearCredentialMap(credentialByItem) {
|
|
Object.keys(credentialByItem).forEach(key => {
|
|
credentialByItem[key].onvifUsername = ''
|
|
credentialByItem[key].onvifPassword = ''
|
|
credentialByItem[key].rtspUsername = ''
|
|
credentialByItem[key].rtspPassword = ''
|
|
})
|
|
}
|