增加高压空闲调节

This commit is contained in:
2026-06-10 11:23:24 +08:00
parent ee45729b5b
commit d44140d999
123 changed files with 22413 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
/**
* Minified by jsDelivr using Terser v5.15.1.
* Original file: /npm/js-base64@3.7.5/base64.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
!function(t,n){var r,e;"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r=t.Base64,(e=n()).noConflict=function(){return t.Base64=r,e},t.Meteor&&(Base64=e),t.Base64=e)}("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:this,(function(){"use strict";var t,n="3.7.5",r="function"==typeof atob,e="function"==typeof btoa,o="function"==typeof Buffer,u="function"==typeof TextDecoder?new TextDecoder:void 0,i="function"==typeof TextEncoder?new TextEncoder:void 0,f=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),c=(t={},f.forEach((function(n,r){return t[n]=r})),t),a=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,d=String.fromCharCode.bind(String),s="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):function(t){return new Uint8Array(Array.prototype.slice.call(t,0))},l=function(t){return t.replace(/=/g,"").replace(/[+\/]/g,(function(t){return"+"==t?"-":"_"}))},h=function(t){return t.replace(/[^A-Za-z0-9\+\/]/g,"")},p=function(t){for(var n,r,e,o,u="",i=t.length%3,c=0;c<t.length;){if((r=t.charCodeAt(c++))>255||(e=t.charCodeAt(c++))>255||(o=t.charCodeAt(c++))>255)throw new TypeError("invalid character found");u+=f[(n=r<<16|e<<8|o)>>18&63]+f[n>>12&63]+f[n>>6&63]+f[63&n]}return i?u.slice(0,i-3)+"===".substring(i):u},y=e?function(t){return btoa(t)}:o?function(t){return Buffer.from(t,"binary").toString("base64")}:p,A=o?function(t){return Buffer.from(t).toString("base64")}:function(t){for(var n=[],r=0,e=t.length;r<e;r+=4096)n.push(d.apply(null,t.subarray(r,r+4096)));return y(n.join(""))},b=function(t,n){return void 0===n&&(n=!1),n?l(A(t)):A(t)},g=function(t){if(t.length<2)return(n=t.charCodeAt(0))<128?t:n<2048?d(192|n>>>6)+d(128|63&n):d(224|n>>>12&15)+d(128|n>>>6&63)+d(128|63&n);var n=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320);return d(240|n>>>18&7)+d(128|n>>>12&63)+d(128|n>>>6&63)+d(128|63&n)},B=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,x=function(t){return t.replace(B,g)},C=o?function(t){return Buffer.from(t,"utf8").toString("base64")}:i?function(t){return A(i.encode(t))}:function(t){return y(x(t))},m=function(t,n){return void 0===n&&(n=!1),n?l(C(t)):C(t)},v=function(t){return m(t,!0)},U=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,F=function(t){switch(t.length){case 4:var n=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return d(55296+(n>>>10))+d(56320+(1023&n));case 3:return d((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return d((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},w=function(t){return t.replace(U,F)},S=function(t){if(t=t.replace(/\s+/g,""),!a.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(3&t.length));for(var n,r,e,o="",u=0;u<t.length;)n=c[t.charAt(u++)]<<18|c[t.charAt(u++)]<<12|(r=c[t.charAt(u++)])<<6|(e=c[t.charAt(u++)]),o+=64===r?d(n>>16&255):64===e?d(n>>16&255,n>>8&255):d(n>>16&255,n>>8&255,255&n);return o},E=r?function(t){return atob(h(t))}:o?function(t){return Buffer.from(t,"base64").toString("binary")}:S,D=o?function(t){return s(Buffer.from(t,"base64"))}:function(t){return s(E(t).split("").map((function(t){return t.charCodeAt(0)})))},R=function(t){return D(T(t))},z=o?function(t){return Buffer.from(t,"base64").toString("utf8")}:u?function(t){return u.decode(D(t))}:function(t){return w(E(t))},T=function(t){return h(t.replace(/[-_]/g,(function(t){return"-"==t?"+":"/"})))},Z=function(t){return z(T(t))},j=function(t){return{value:t,enumerable:!1,writable:!0,configurable:!0}},I=function(){var t=function(t,n){return Object.defineProperty(String.prototype,t,j(n))};t("fromBase64",(function(){return Z(this)})),t("toBase64",(function(t){return m(this,t)})),t("toBase64URI",(function(){return m(this,!0)})),t("toBase64URL",(function(){return m(this,!0)})),t("toUint8Array",(function(){return R(this)}))},O=function(){var t=function(t,n){return Object.defineProperty(Uint8Array.prototype,t,j(n))};t("toBase64",(function(t){return b(this,t)})),t("toBase64URI",(function(){return b(this,!0)})),t("toBase64URL",(function(){return b(this,!0)}))},P={version:n,VERSION:"3.7.5",atob:E,atobPolyfill:S,btoa:y,btoaPolyfill:p,fromBase64:Z,toBase64:m,encode:m,encodeURI:v,encodeURL:v,utob:x,btou:w,decode:Z,isValid:function(t){if("string"!=typeof t)return!1;var n=t.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(n)||!/[^\s0-9a-zA-Z\-_]/.test(n)},fromUint8Array:b,toUint8Array:R,extendString:I,extendUint8Array:O,extendBuiltins:function(){I(),O()},Base64:{}};return Object.keys(P).forEach((function(t){return P.Base64[t]=P[t]})),P}));
//# sourceMappingURL=/sm/555281732ed54ee1693a772f485329378d8ea5052ffa4370e9c2e9947eb42d22.map
+392
View File
@@ -0,0 +1,392 @@
$(document).ready(function() {
const topic_control = '/dev/control/hsv/1';
const topic_status = '/dev/status/hsv/1';
const topic_response = '/dev/response/hsv/1';
// ================== 控制面板相关 ==================
// MQTT客户端配置
const client = mqtt.connect('ws://123.57.81.127:8085/mqtt', {
username: 'mqtt',
password: '123456',
clientId: 'web_client_' + Math.random().toString(16).substr(2, 8)
});
// Toast初始化
const toastEl = document.getElementById('toast');
const toast = new bootstrap.Toast(toastEl, {
autohide: true,
delay: 3000
});
function showToast(message) {
$('.toast-body').text(message);
toast.show();
}
client.on('connect', function() {
showToast('已连接到MQTT服务器');
client.subscribe(topic_status, function(err) {
if (!err) {
showToast('已订阅 主题'+ topic_status);
}
});
client.subscribe(topic_response, function(err) {
if (!err) {
showToast('已订阅 ' + topic_response + ' 主题');
}
});
});
client.on('message', function(topic, message) {
if (topic.startsWith(topic_status)) {
try {
const data = JSON.parse(message.toString());
var iin = parseFloat(data.value.Iin);
if (iin > 65) {
iin = 0;
}
var vinState = parseFloat(data.value.Vin).toFixed(1) + 'V ' + parseFloat(iin).toFixed(2) + 'A';
$('#vinState').text(vinState)
$('#hvState').text(data.value.hv == 'on' ? '高压已打开' : '高压已关闭');
$('#rayState').text(data.value.xray == 'on' ? '射线已打开' : '射线已关闭');
$('#feedbackVoltage').text(parseFloat(data.value.kV).toFixed(2));
$('#feedbackCurrent').text(parseFloat(data.value.mA).toFixed(2));
$('#filamentVoltage').text(parseFloat(data.value.fV).toFixed(3));
$('#filamentCurrent').text(parseFloat(data.value.fI).toFixed(3));
} catch (e) {
showToast('解析消息失败: ' + e.message);
}
} else if (topic.startsWith(topic_response)) {
try {
const data = JSON.parse(message.toString());
console.log(data)
if (data.command == 'get_params') {
$('#setVoltage').val(parseFloat(data.value.kV).toFixed(2));
$('#setCurrent').val(parseFloat(data.value.mA).toFixed(2));
$('#filaPreheatCurrent').val(parseFloat(data.value.filament.preheat / 1000).toFixed(2));
$('#filaLimitCurrent').val(parseFloat(data.value.filament.limit / 1000).toFixed(2));
showToast('参数已更新');
} else {
showToast('请求已发送');
}
} catch (e) {
showToast('解析消息失败: ' + e.message);
}
}
});
$('#setParams').click(function() {
const setVoltage = parseFloat($('#setVoltage').val());
const setCurrent = parseFloat($('#setCurrent').val());
const filaPreheatCurrent = parseFloat($('#filaPreheatCurrent').val()) * 1000;
const filaLimitCurrent = parseFloat($('#filaLimitCurrent').val()) * 1000;
var msg = {
device_id: '2',
device_code: '2#HVS',
command: 'set_params',
value: {
kV: setVoltage,
mA: setCurrent,
filament : {
preheat: filaPreheatCurrent,
limit: filaLimitCurrent
}
}
}
client.publish(topic_control, JSON.stringify(msg));
showToast('请求已发送!');
});
$('#getParams').click(function() {
var msg = {
device_id: '1',
device_code: '2#HVS',
command: 'get_params'
}
client.publish(topic_control, JSON.stringify(msg));
showToast('请求已发送!');
});
$('#hvEnable').click(function() {
var msg = {
device_id: '1',
device_code: '1#HVS',
command: 'hv_control',
value: 'on'
}
client.publish(topic_control, JSON.stringify(msg));
showToast('请求已发送!');
});
$('#hvDisable').click(function() {
var msg = {
device_id: '1',
device_code: '1#HVS',
command: 'hv_control',
value: 'off'
}
client.publish(topic_control, JSON.stringify(msg));
showToast('请求已发送!');
});
$('#rayEnable').click(function() {
var msg = {
device_id: '1',
device_code: '1#HVS',
command: 'ray_control',
value: 'on'
}
client.publish(topic_control, JSON.stringify(msg));
showToast('请求已发送!');
});
$('#rayDisable').click(function() {
var msg = {
device_id: '1',
device_code: '1#HVS',
command: 'ray_control',
value: 'off'
}
client.publish(topic_control, JSON.stringify(msg));
showToast('请求已发送!');
});
$('#reboot').click(function() {
$.ajax({
url: '/api/device/reboot',
type: 'GET',
success: function(response) {
if (response.success) {
showToast('请求已发送');
} else {
showToast('请求失败:' + response.message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
showToast('请求失败:服务器错误');
}
});
});
$('#hv_service_start').click(function() {
$.ajax({
url: '/api/hv_service/start',
type: 'GET',
success: function(response) {
if (response.success) {
showToast('请求已发送');
} else {
showToast('请求失败:' + response.message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
showToast('请求失败:服务器错误');
}
});
});
$('#hv_service_stop').click(function() {
$.ajax({
url: '/api/hv_service/stop',
type: 'GET',
success: function(response) {
if (response.success) {
showToast('请求已发送');
} else {
showToast('请求失败:' + response.message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
showToast('请求失败:服务器错误');
}
});
});
$(window).on('beforeunload', function() {
client.end();
});
// ================== 脚本编辑器相关 ==================
let scriptTabInited = false;
let editor = null;
$('button[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
console.log('tab shown', e);
const target = $(e.target).attr('data-bs-target');
if (target === '#script' && !scriptTabInited) {
// 初始化CodeMirror
editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
mode: 'text/x-python',
theme: 'monokai',
lineNumbers: true,
indentUnit: 4,
lineWrapping: true,
matchBrackets: true,
autoCloseBrackets: true
});
editor.setValue("请选择一个文件");
// 初始化文件树
$('#fileTree').jstree({
'core': {
'data': {
'url': function(node) {
const url = node.id === '#' ? '/api/script/list' : '/api/script/list?path=' + node.id;
return url;
},
'data': function(node) {
return { 'id': node.id };
},
'dataFilter': function(data) {
var json = {};
try {
json = JSON.parse(data);
} catch (e) {
return "[]";
}
if (json.success && Array.isArray(json.data)) {
return JSON.stringify(json.data);
}
return "[]";
},
'error': function(jqXHR, textStatus, errorThrown) {
showToast('加载文件列表失败:' + textStatus);
}
},
'themes': {
'name': 'default',
'responsive': true
},
'check_callback': true,
'multiple': false
},
'types': {
'default': {
'icon': 'bi bi-file-text'
},
'folder': {
'icon': 'bi bi-folder'
},
'python': {
'icon': 'bi bi-filetype-py'
},
'json': {
'icon': 'bi bi-filetype-json'
},
'shell': {
'icon': 'bi bi-filetype-sh'
}
},
'plugins': ['types']
}).on('ready.jstree', function() {
// 文件树初始化完成
});
// 文件树节点点击事件
$('#fileTree').on('select_node.jstree', function(e, data) {
const node = data.node;
if (node.original.type != 'folder') {
loadFile(node.id);
}
});
// 加载文件内容
function loadFile(path) {
$.get('/api/script/read?path=' + encodeURIComponent(path), function(response) {
if (response.success) {
// 使用js-base64库解码
const content = Base64.decode(response.data);
const ext = path.split('.').pop().toLowerCase();
switch(ext) {
case 'py':
editor.setOption('mode', 'text/x-python');
break;
case 'json':
editor.setOption('mode', 'application/json');
break;
case 'sh':
editor.setOption('mode', 'text/x-sh');
break;
case 'html':
editor.setOption('mode', 'text/html');
break;
case 'js':
editor.setOption('mode', 'javascript');
break;
case 'css':
editor.setOption('mode', 'css');
break;
default:
editor.setOption('mode', 'text/plain');
}
editor.setValue(content);
$('#currentFile').text(path);
$('#saveFile, #deleteFile').prop('disabled', false);
} else {
showToast('加载文件失败:' + response.message);
}
}).fail(function(jqXHR, textStatus, errorThrown) {
showToast('加载文件失败:服务器错误');
});
}
// 保存文件
$('#saveFile').click(function() {
const path = $('#currentFile').text();
// 使用js-base64库编码
const content = Base64.encode(editor.getValue());
$.ajax({
url: '/api/script/write',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
path: path,
content: content
}),
success: function(response) {
if (response.success) {
showToast('文件保存成功');
} else {
showToast('保存文件失败:' + response.message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
showToast('保存文件失败:服务器错误');
}
});
});
// 删除文件
$('#deleteFile').click(function() {
if (confirm('确定要删除这个文件吗?')) {
const path = $('#currentFile').text();
$.ajax({
url: '/api/script/delete',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
path: path
}),
success: function(response) {
if (response.success) {
showToast('文件删除成功');
$('#currentFile').text('未选择文件');
editor.setValue('');
$('#saveFile, #deleteFile').prop('disabled', true);
$('#fileTree').jstree('refresh');
} else {
showToast('删除文件失败:' + response.message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
showToast('删除文件失败:服务器错误');
}
});
}
});
// 刷新文件树
$('#refreshTree').click(function() {
console.log('刷新文件树');
$('#fileTree').jstree('refresh');
});
scriptTabInited = true;
}
});
});