fix: 仪表盘动画改为模块方法 _animateNumber (避免全局作用域问题)
This commit is contained in:
@@ -306,5 +306,27 @@
|
|||||||
"framework.command.execute"
|
"framework.command.execute"
|
||||||
],
|
],
|
||||||
"timestamp": 27941.297902882
|
"timestamp": 27941.297902882
|
||||||
|
},
|
||||||
|
"bf0ab570": {
|
||||||
|
"plugin_name": "example_plugin",
|
||||||
|
"permissions": [
|
||||||
|
"plugin.example.read",
|
||||||
|
"plugin.example.write",
|
||||||
|
"plugin.example.execute",
|
||||||
|
"framework.event.subscribe",
|
||||||
|
"framework.command.execute"
|
||||||
|
],
|
||||||
|
"timestamp": 28040.658771958
|
||||||
|
},
|
||||||
|
"2d3bd47f": {
|
||||||
|
"plugin_name": "sentinel",
|
||||||
|
"permissions": [
|
||||||
|
"plugin.sentinel.read",
|
||||||
|
"plugin.sentinel.write",
|
||||||
|
"plugin.network.access",
|
||||||
|
"framework.event.subscribe",
|
||||||
|
"framework.command.execute"
|
||||||
|
],
|
||||||
|
"timestamp": 28040.668302635
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ commands:
|
|||||||
permissions:
|
permissions:
|
||||||
- framework.command.test
|
- framework.command.test
|
||||||
source: internal
|
source: internal
|
||||||
last_updated: 27941.282839757
|
last_updated: 28040.621524771
|
||||||
plugin_commands:
|
plugin_commands:
|
||||||
example_plugin:
|
example_plugin:
|
||||||
echo: *id001
|
echo: *id001
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
http_port: 4200
|
http_port: 4200
|
||||||
last_updated: 27941.295580277
|
last_updated: 28040.661568417
|
||||||
plugin_routes:
|
plugin_routes:
|
||||||
example_plugin:
|
example_plugin:
|
||||||
- methods:
|
- methods:
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
/* ── 数字跳动动画 ── */
|
|
||||||
function animateNumber(el, newVal, decimals, suffix) {
|
|
||||||
var oldVal = parseFloat(el.getAttribute('data-val') || newVal);
|
|
||||||
if (oldVal === newVal) { el.textContent = newVal.toFixed(decimals) + suffix; return; }
|
|
||||||
el.setAttribute('data-val', newVal);
|
|
||||||
var start = performance.now();
|
|
||||||
var duration = 900;
|
|
||||||
function step(ts) {
|
|
||||||
var p = Math.min((ts - start) / duration, 1);
|
|
||||||
var eased = 1 - Math.pow(1 - p, 3); // ease-out
|
|
||||||
el.textContent = (oldVal + (newVal - oldVal) * eased).toFixed(decimals) + suffix;
|
|
||||||
if (p < 1) requestAnimationFrame(step);
|
|
||||||
}
|
|
||||||
requestAnimationFrame(step);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.DashboardModule = {
|
window.DashboardModule = {
|
||||||
ws: null,
|
ws: null,
|
||||||
reconnectTimer: null,
|
reconnectTimer: null,
|
||||||
reconnectDelay: 1000,
|
reconnectDelay: 1000,
|
||||||
charts: {},
|
charts: {},
|
||||||
|
|
||||||
|
_animateNumber: function(el, newVal, decimals, suffix) {
|
||||||
|
var self = this;
|
||||||
|
var oldVal = parseFloat(el.getAttribute('data-val') || newVal);
|
||||||
|
if (Math.abs(oldVal - newVal) < 0.05) { el.textContent = newVal.toFixed(decimals) + suffix; return; }
|
||||||
|
el.setAttribute('data-val', newVal);
|
||||||
|
var start = performance.now();
|
||||||
|
var duration = 900;
|
||||||
|
function step(ts) {
|
||||||
|
var p = Math.min((ts - start) / duration, 1);
|
||||||
|
var eased = 1 - Math.pow(1 - p, 3);
|
||||||
|
el.textContent = (oldVal + (newVal - oldVal) * eased).toFixed(decimals) + suffix;
|
||||||
|
if (p < 1) requestAnimationFrame(step);
|
||||||
|
}
|
||||||
|
requestAnimationFrame(step);
|
||||||
|
},
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ window.DashboardModule = {
|
|||||||
// ── 内存 ──
|
// ── 内存 ──
|
||||||
if (sys.memory) {
|
if (sys.memory) {
|
||||||
var m = sys.memory.percent || 0;
|
var m = sys.memory.percent || 0;
|
||||||
var el = document.getElementById('d-mem'); if (el) animateNumber(el, m, 1, '%');
|
var el = document.getElementById('d-mem'); if (el) self._animateNumber(el, m, 1, '%');
|
||||||
el = document.getElementById('d-mem-detail');
|
el = document.getElementById('d-mem-detail');
|
||||||
if (el) el.textContent = (sys.memory.used_gb || 0).toFixed(1) + ' / ' + (sys.memory.total_gb || 0).toFixed(1) + ' GB';
|
if (el) el.textContent = (sys.memory.used_gb || 0).toFixed(1) + ' / ' + (sys.memory.total_gb || 0).toFixed(1) + ' GB';
|
||||||
self.charts.mem.update(m);
|
self.charts.mem.update(m);
|
||||||
@@ -102,7 +102,7 @@ window.DashboardModule = {
|
|||||||
var load = (sys.cpu.load_avg && sys.cpu.load_avg[0]) ? sys.cpu.load_avg[0] : 0;
|
var load = (sys.cpu.load_avg && sys.cpu.load_avg[0]) ? sys.cpu.load_avg[0] : 0;
|
||||||
cpuVal = Math.min(100, (load / (sys.cpu.cores || 1)) * 100);
|
cpuVal = Math.min(100, (load / (sys.cpu.cores || 1)) * 100);
|
||||||
}
|
}
|
||||||
var el = document.getElementById('d-cpu'); if (el) animateNumber(el, cpuVal, 0, '%');
|
var el = document.getElementById('d-cpu'); if (el) self._animateNumber(el, cpuVal, 0, '%');
|
||||||
self.charts.cpu.update(cpuVal);
|
self.charts.cpu.update(cpuVal);
|
||||||
|
|
||||||
if (sys.cpu.load_avg) {
|
if (sys.cpu.load_avg) {
|
||||||
@@ -133,7 +133,7 @@ window.DashboardModule = {
|
|||||||
// ── 进程内存 ──
|
// ── 进程内存 ──
|
||||||
if (sys.process && sys.process.memory_mb !== undefined) {
|
if (sys.process && sys.process.memory_mb !== undefined) {
|
||||||
var pm = sys.process.memory_mb || 0;
|
var pm = sys.process.memory_mb || 0;
|
||||||
var el = document.getElementById('d-proc-mem'); if (el) animateNumber(el, pm, 1, ' MB');
|
var el = document.getElementById('d-proc-mem'); if (el) self._animateNumber(el, pm, 1, ' MB');
|
||||||
self.charts.proc_mem.update(pm);
|
self.charts.proc_mem.update(pm);
|
||||||
}
|
}
|
||||||
if (sys.process && sys.process.pid !== undefined) {
|
if (sys.process && sys.process.pid !== undefined) {
|
||||||
|
|||||||
Reference in New Issue
Block a user