From 630a6a98da137619cc4d5df52b96e897effa942d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A1=E5=8F=A3=E6=B5=AA=E4=BA=BA?= Date: Sun, 27 Sep 2026 21:21:36 +0800 Subject: [PATCH] style: space plugin save actions below settings --- SHA256SUMS | 2 +- web/index.html | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SHA256SUMS b/SHA256SUMS index 29d2244..758ca4d 100644 --- a/SHA256SUMS +++ b/SHA256SUMS @@ -7,5 +7,5 @@ e83c52906953a723fc79208aecf08372a875e0bc2f74b4283329a475744f8984 README.md 3da8b5d94e2206bffc19e1c4fa493b31880c9a90fd6a02546461fe54a7255dbd config/pigway-pi-control.conf 20c584762cae3a50a498df25e11272c3c191a62c9ce823e63f8224d14637b1d4 systemd/pigway-pi-control-api.service 35ec68e1c3040e7affad43961fbb77e9e29f3474b92aed1005502629f9acb549 systemd/pigway-pi-control.service -fe32725efb7edcd54a2e0d037e0abbe3cb8994ee836a3d4b8822171f43cf3f36 web/index.html +cf3e2b813732b231651be3482327a4928d925846116a86b159cbf081c4c405e0 web/index.html 73b7922be93bf57169589755137dc5ec7ec7c8059c85c2bf2ee53a344e534d7e docs/HARDWARE_PLUGIN_API.md diff --git a/web/index.html b/web/index.html index e6871ff..1d20c66 100644 --- a/web/index.html +++ b/web/index.html @@ -5,10 +5,12 @@ PIGWay Pi Control
@@ -69,7 +71,7 @@ async function pluginAction(id,operation){try{await pluginPut('/api/v1/plugins', function capabilityField(section,key,value,spec){const unit=LANG==='zh'?({s:'秒',ms:'毫秒'}[spec.unit]||spec.unit):spec.unit,label=spec.label?.[LANG]||spec.label?.en||key,id=`${section}.${key}`,vis=spec.visible?` data-cap-visible="${esc(JSON.stringify(spec.visible))}"`:'';return ``} function pluginChoice(x){const zh={off:'全灭',solid:'自定义常亮',flash:'自定义闪烁(实验性)',breathe:'内置呼吸',flow:'流水灯',marquee:'跑马灯',rainbow:'彩虹灯',colorful:'炫彩灯',red:'红色',green:'绿色',blue:'蓝色',yellow:'黄色',purple:'紫色',cyan:'青色',white:'白色'};return LANG==='zh'?(zh[x]||x):x} function capabilityFields(section,fields,values){const seen=new Set();return Object.entries(fields).map(([key,spec])=>{if(!spec.color_group)return capabilityField(section,key,values[key],spec);if(seen.has(spec.color_group))return '';seen.add(spec.color_group);const members=Object.entries(fields).filter(([,v])=>v.color_group===spec.color_group),hex='#'+['r','g','b'].map(c=>Number(values[members.find(([,v])=>v.channel===c)[0]]).toString(16).padStart(2,'0')).join('');return `
${members.map(([k,v])=>capabilityField(section,k,values[k],{...v,visible:null})).join('')}
`}).join('')} -async function editPlugin(id){try{pluginSelected=id;pluginDraft=await get('/api/v1/plugin/config?host='+encodeURIComponent(currentConfigHost)+'&id='+encodeURIComponent(id));const data=pluginDraft,editor=$('pluginEditor');editor.innerHTML=`

${esc(id)}

${pluginText('配置由插件保存并立即应用,不重启监控。','Settings are saved and applied by the plugin without restarting monitoring.')}

${(data.notes||[]).map(n=>`

${esc(n[LANG]||n.en||'')}

`).join('')}${Object.entries(data.schema).map(([section,fields])=>`

${({fan:pluginText('风扇','Fan'),oled:pluginText('屏幕','Display'),rgb:pluginText('灯光','Lighting')})[section]||esc(section)}

${capabilityFields(section,fields,data.config[section])}
`).join('')}
`;editor.oninput=e=>{if(e.target.dataset.capColor){const group=e.target.dataset.capColor,hex=e.target.value;['r','g','b'].forEach((c,i)=>{editor.querySelector(`[data-cap-key="${group}_${c}"]`).value=parseInt(hex.slice(1+2*i,3+2*i),16)})}for(const picker of editor.querySelectorAll('[data-cap-color]')){picker.value='#'+['r','g','b'].map(c=>Math.max(0,Math.min(255,Number(editor.querySelector(`[data-cap-key="${picker.dataset.capColor}_${c}"]`).value))).toString(16).padStart(2,'0')).join('')}updatePluginVisibility()};updatePluginVisibility();$('savePlugin').onclick=savePluginConfig}catch(e){$('pluginEditor').textContent=e.message}} +async function editPlugin(id){try{pluginSelected=id;pluginDraft=await get('/api/v1/plugin/config?host='+encodeURIComponent(currentConfigHost)+'&id='+encodeURIComponent(id));const data=pluginDraft,editor=$('pluginEditor');editor.innerHTML=`

${esc(id)}

${pluginText('配置由插件保存并立即应用,不重启监控。','Settings are saved and applied by the plugin without restarting monitoring.')}

${(data.notes||[]).map(n=>`

${esc(n[LANG]||n.en||'')}

`).join('')}${Object.entries(data.schema).map(([section,fields])=>`

${({fan:pluginText('风扇','Fan'),oled:pluginText('屏幕','Display'),rgb:pluginText('灯光','Lighting')})[section]||esc(section)}

${capabilityFields(section,fields,data.config[section])}
`).join('')}
`;editor.oninput=e=>{if(e.target.dataset.capColor){const group=e.target.dataset.capColor,hex=e.target.value;['r','g','b'].forEach((c,i)=>{editor.querySelector(`[data-cap-key="${group}_${c}"]`).value=parseInt(hex.slice(1+2*i,3+2*i),16)})}for(const picker of editor.querySelectorAll('[data-cap-color]')){picker.value='#'+['r','g','b'].map(c=>Math.max(0,Math.min(255,Number(editor.querySelector(`[data-cap-key="${picker.dataset.capColor}_${c}"]`).value))).toString(16).padStart(2,'0')).join('')}updatePluginVisibility()};updatePluginVisibility();$('savePlugin').onclick=savePluginConfig}catch(e){$('pluginEditor').textContent=e.message}} function updatePluginVisibility(){document.querySelectorAll('[data-cap-visible]').forEach(el=>{const rules=JSON.parse(el.dataset.capVisible);el.classList.toggle('hidden',!Object.entries(rules).every(([key,values])=>values.includes(document.querySelector(`[data-cap-key="${key}"]`)?.value)))})} async function savePluginConfig(){const updates={};for(const el of document.querySelectorAll('[data-cap-key]')){if(!el.reportValidity())return;const s=el.dataset.capSection,k=el.dataset.capKey;(updates[s]??={})[k]=el.value}try{await pluginPut('/api/v1/plugin/config',{id:pluginSelected,updates});$('pluginSaveState').textContent=pluginText('保存成功','Saved')}catch(e){$('pluginSaveState').textContent=e.message}} document.addEventListener('click',async e=>{const b=e.target.closest('[data-manage-plugin-host]');if(!b)return;currentConfigHost=b.dataset.managePluginHost;await ensureHosts();$('configHost').value=currentConfigHost;document.querySelector('[data-tab="config"]').click();await loadConfig();document.querySelector('[data-config-section="plugins"]')?.click()});