feat(receiver): 持久化接收机发现端点并支持位置备注信息
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// The reference markup uses data attributes for both static and generated controls.
|
||||
// Only these named actions are callable. Arguments are data, never JavaScript.
|
||||
const actions = Object.freeze(Object.fromEntries(`
|
||||
cancelDrawZone clearAllTrackLayers clearCurrentAlerts copyDroneRid deleteZone deleteCenterAlarm finishDrawZone
|
||||
fitAll focusAlertOnMap focusStationByKey focusZoneByKey logout
|
||||
mapSetViewWgs84 markAlarmHandled openModule renameZone setBaseMap
|
||||
shareDroneLocation shareStationLocation startDrawZone testAlarm
|
||||
toggleMapLabels toggleSidePanel toggleZone trackDrone unlockDroneTracking
|
||||
`.trim().split(/\s+/).map(name => [name, window[name]])));
|
||||
|
||||
function argument(element, value) {
|
||||
if (value === '@value') return element.value;
|
||||
if (value === '@checked') return element.checked;
|
||||
if (value === '@number') return Number(element.value);
|
||||
if (value === '@true') return true;
|
||||
if (value.startsWith('@n:')) return Number(value.slice(3));
|
||||
return value;
|
||||
}
|
||||
|
||||
function run(event, element, kind) {
|
||||
const name = element.getAttribute(`data-rid-${kind}`);
|
||||
const args = [];
|
||||
for (let index = 0; index < 3; index++) {
|
||||
const value = element.getAttribute(`data-rid-arg${index}`);
|
||||
if (value !== null) args.push(argument(element, value));
|
||||
}
|
||||
if (name === 'stop') {
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
if (Object.hasOwn(actions, name)) return actions[name](...args);
|
||||
}
|
||||
|
||||
for (const kind of ['click', 'change', 'input']) {
|
||||
document.addEventListener(kind, event => {
|
||||
const control = event.target.closest?.(`[data-rid-${kind}]`);
|
||||
if (control) Promise.resolve().then(() => run(event, control, kind)).catch(error => {
|
||||
const feedback = document.getElementById('rid-workbench-status');
|
||||
feedback.textContent = error.message || '操作失败,请重试';
|
||||
feedback.hidden = false;
|
||||
clearTimeout(feedback.hideTimer);
|
||||
feedback.hideTimer = setTimeout(() => { feedback.hidden = true; }, 4500);
|
||||
});
|
||||
});
|
||||
}
|
||||
for (const control of document.querySelectorAll('.tool[data-rid-click]')) {
|
||||
control.setAttribute('role', 'button');
|
||||
control.tabIndex = 0;
|
||||
}
|
||||
document.addEventListener('keydown', event => {
|
||||
const control = event.target.closest?.('div[role="button"][data-rid-click]');
|
||||
if (control && (event.key === ' ' || event.key === 'Enter')) {
|
||||
event.preventDefault();
|
||||
control.click();
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user