fix: 动画改用 setInterval (兼容动态 script 加载) + try-catch 保护

This commit is contained in:
qinglong
2026-06-13 18:29:11 +08:00
parent c4b44e0fd2
commit a2bd6486a0
4 changed files with 39 additions and 15 deletions
+22
View File
@@ -328,5 +328,27 @@
"framework.command.execute"
],
"timestamp": 28040.668302635
},
"2a0ced83": {
"plugin_name": "example_plugin",
"permissions": [
"plugin.example.read",
"plugin.example.write",
"plugin.example.execute",
"framework.event.subscribe",
"framework.command.execute"
],
"timestamp": 28375.085750685
},
"8a812834": {
"plugin_name": "sentinel",
"permissions": [
"plugin.sentinel.read",
"plugin.sentinel.write",
"plugin.network.access",
"framework.event.subscribe",
"framework.command.execute"
],
"timestamp": 28375.089465424
}
}
+1 -1
View File
@@ -101,7 +101,7 @@ commands:
permissions:
- framework.command.test
source: internal
last_updated: 28040.621524771
last_updated: 28375.06993407
plugin_commands:
example_plugin:
echo: *id001
+1 -1
View File
@@ -1,5 +1,5 @@
http_port: 4200
last_updated: 28040.661568417
last_updated: 28375.086802768
plugin_routes:
example_plugin:
- methods:
+12 -10
View File
@@ -5,19 +5,21 @@ window.DashboardModule = {
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; }
try {
var oldVal = parseFloat(el.getAttribute('data-val'));
if (isNaN(oldVal)) oldVal = newVal;
if (Math.abs(oldVal - newVal) < 0.05) { el.textContent = newVal.toFixed(decimals) + suffix; el.setAttribute('data-val', newVal); 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 steps = 20, i = 0;
var stepMs = 50; // 20 steps × 50ms = 1000ms
var timer = setInterval(function(){
i++;
var p = Math.min(i / steps, 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);
if (i >= steps) clearInterval(timer);
}, stepMs);
} catch(e) { el.textContent = newVal.toFixed(decimals) + suffix; }
},
init: function() {