Update app/statics/admin/config.html
Browse files- app/statics/admin/config.html +85 -102
app/statics/admin/config.html
CHANGED
|
@@ -8,25 +8,26 @@
|
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
| 9 |
<link href="/static/css/app.css?v={{APP_VERSION}}" rel="stylesheet">
|
| 10 |
<style>
|
| 11 |
-
/*
|
| 12 |
-
body { background: #
|
| 13 |
|
| 14 |
/* Page header */
|
| 15 |
.page-hd { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:20px }
|
| 16 |
-
.page-title{ font-size:22px; font-weight:700; line-height:1.2 }
|
| 17 |
-
.page-sub { font-size:13px; color:
|
| 18 |
.page-actions { display:flex; gap:8px; align-items:center; flex-shrink:0 }
|
| 19 |
|
|
|
|
| 20 |
.page-action-btn {
|
| 21 |
height:32px; padding:0 14px; border-radius:999px;
|
| 22 |
display:inline-flex; align-items:center; justify-content:center; gap:6px;
|
| 23 |
font-size:13px; font-weight:600;
|
| 24 |
-
border:1px solid #
|
| 25 |
}
|
| 26 |
-
.page-action-btn:hover { background:#
|
| 27 |
-
.page-action-btn-primary { background:#
|
| 28 |
-
.page-action-btn-primary:hover { background:#
|
| 29 |
-
.page-action-btn:disabled { opacity:.
|
| 30 |
|
| 31 |
/* Section nav tabs */
|
| 32 |
.cfg-nav {
|
|
@@ -43,15 +44,16 @@
|
|
| 43 |
border-radius:999px;
|
| 44 |
font-size:12px;
|
| 45 |
font-weight:500;
|
| 46 |
-
color:#
|
| 47 |
-
background:#
|
| 48 |
transition:color .15s, background .15s;
|
| 49 |
cursor:pointer;
|
|
|
|
| 50 |
}
|
| 51 |
-
.cfg-tab:hover { color:#
|
| 52 |
.cfg-tab.active {
|
| 53 |
-
background:#
|
| 54 |
-
color:#
|
| 55 |
font-weight:600;
|
| 56 |
}
|
| 57 |
.cfg-tab .dot {
|
|
@@ -62,7 +64,7 @@
|
|
| 62 |
background:currentColor;
|
| 63 |
margin-left:5px;
|
| 64 |
vertical-align:middle;
|
| 65 |
-
opacity:.
|
| 66 |
}
|
| 67 |
.cfg-tab.dirty .dot { display:inline-block }
|
| 68 |
|
|
@@ -70,10 +72,10 @@
|
|
| 70 |
.cfg-panel { display:none }
|
| 71 |
.cfg-panel.active { display:block }
|
| 72 |
|
| 73 |
-
/* Field rows */
|
| 74 |
.cfg-group {
|
| 75 |
-
background:#
|
| 76 |
-
border:
|
| 77 |
border-radius:12px;
|
| 78 |
overflow:hidden;
|
| 79 |
margin-bottom:12px;
|
|
@@ -81,11 +83,11 @@
|
|
| 81 |
.cfg-group-title {
|
| 82 |
font-size:11px;
|
| 83 |
font-weight:700;
|
| 84 |
-
color:#
|
| 85 |
text-transform:uppercase;
|
| 86 |
letter-spacing:.08em;
|
| 87 |
padding:12px 16px 6px;
|
| 88 |
-
background:#
|
| 89 |
border-bottom:none;
|
| 90 |
}
|
| 91 |
.cfg-row {
|
|
@@ -94,13 +96,14 @@
|
|
| 94 |
gap:18px;
|
| 95 |
align-items:center;
|
| 96 |
padding:11px 16px;
|
| 97 |
-
border-bottom:1px solid #
|
| 98 |
transition:background .15s;
|
| 99 |
}
|
| 100 |
.cfg-row:last-child { border-bottom:none }
|
| 101 |
-
.cfg-row:hover { background:#
|
| 102 |
-
|
| 103 |
-
.cfg-row.modified
|
|
|
|
| 104 |
.cfg-label-col { min-width:0; display:grid; gap:3px; align-content:start }
|
| 105 |
.cfg-label {
|
| 106 |
display:inline-flex;
|
|
@@ -108,10 +111,10 @@
|
|
| 108 |
gap:6px;
|
| 109 |
font-size:12px;
|
| 110 |
font-weight:600;
|
| 111 |
-
color:#
|
| 112 |
line-height:1.35;
|
| 113 |
}
|
| 114 |
-
.cfg-desc { max-width:520px; font-size:11px; color:#
|
| 115 |
.cfg-help {
|
| 116 |
position:relative;
|
| 117 |
width:16px;
|
|
@@ -121,9 +124,9 @@
|
|
| 121 |
justify-content:center;
|
| 122 |
padding:0;
|
| 123 |
border-radius:50%;
|
| 124 |
-
border:1px solid #
|
| 125 |
-
background:#
|
| 126 |
-
color:#
|
| 127 |
font-size:11px;
|
| 128 |
line-height:1;
|
| 129 |
font-weight:700;
|
|
@@ -132,9 +135,9 @@
|
|
| 132 |
}
|
| 133 |
.cfg-help:hover,
|
| 134 |
.cfg-help:focus-visible {
|
| 135 |
-
color:#
|
| 136 |
-
border-color:#
|
| 137 |
-
background:#
|
| 138 |
outline:none;
|
| 139 |
}
|
| 140 |
.cfg-help-tip {
|
|
@@ -143,7 +146,8 @@
|
|
| 143 |
max-width:min(320px, calc(100vw - 24px));
|
| 144 |
padding:9px 10px;
|
| 145 |
border-radius:8px;
|
| 146 |
-
background:#
|
|
|
|
| 147 |
color:#fff;
|
| 148 |
font-size:12px;
|
| 149 |
font-weight:500;
|
|
@@ -151,7 +155,7 @@
|
|
| 151 |
text-align:left;
|
| 152 |
white-space:pre-line;
|
| 153 |
overflow-wrap:anywhere;
|
| 154 |
-
box-shadow:0 8px 24px rgba(0,0,0,.
|
| 155 |
opacity:0;
|
| 156 |
pointer-events:none;
|
| 157 |
transform:translateY(3px);
|
|
@@ -168,11 +172,13 @@
|
|
| 168 |
left:var(--arrow-left, 50%);
|
| 169 |
width:8px;
|
| 170 |
height:8px;
|
| 171 |
-
background:#
|
|
|
|
|
|
|
| 172 |
transform:translateX(-50%) rotate(45deg);
|
| 173 |
}
|
| 174 |
-
.cfg-help-tip[data-placement="top"]::before { bottom:-
|
| 175 |
-
.cfg-help-tip[data-placement="bottom"]::before { top:-
|
| 176 |
.cfg-input-col { min-width:0; display:flex; align-items:center; justify-content:flex-start; gap:8px }
|
| 177 |
.cfg-input-col.is-bool { justify-content:flex-end }
|
| 178 |
.cfg-inline-action {
|
|
@@ -182,14 +188,14 @@
|
|
| 182 |
align-items:center;
|
| 183 |
justify-content:center;
|
| 184 |
padding:0;
|
| 185 |
-
color:#
|
| 186 |
border:0;
|
| 187 |
background:transparent;
|
| 188 |
cursor:pointer;
|
| 189 |
flex-shrink:0;
|
| 190 |
transition:color .15s, opacity .15s, transform .15s;
|
| 191 |
}
|
| 192 |
-
.cfg-inline-action:hover { color:#
|
| 193 |
.cfg-inline-action:disabled {
|
| 194 |
opacity:.32;
|
| 195 |
cursor:not-allowed;
|
|
@@ -197,7 +203,7 @@
|
|
| 197 |
}
|
| 198 |
.cfg-inline-action svg { width:14px; height:14px; display:block }
|
| 199 |
|
| 200 |
-
/* Inputs */
|
| 201 |
.cfg-text {
|
| 202 |
width:100%;
|
| 203 |
max-width:none;
|
|
@@ -205,12 +211,13 @@
|
|
| 205 |
padding:0 10px;
|
| 206 |
font-size:13px;
|
| 207 |
border-radius:8px;
|
| 208 |
-
border:1px solid #
|
| 209 |
-
background:#
|
|
|
|
| 210 |
transition:border-color .15s, background .15s;
|
| 211 |
font-family: inherit; text-align:right;
|
| 212 |
}
|
| 213 |
-
.cfg-text:focus { border-color:#
|
| 214 |
.cfg-text.wide { max-width:none }
|
| 215 |
.cfg-textarea {
|
| 216 |
width:100%;
|
|
@@ -219,13 +226,14 @@
|
|
| 219 |
padding:8px 10px;
|
| 220 |
font-size:12px;
|
| 221 |
border-radius:10px;
|
| 222 |
-
border:1px solid #
|
| 223 |
-
background:#
|
|
|
|
| 224 |
resize:vertical;
|
| 225 |
transition:border-color .15s, background .15s;
|
| 226 |
font-family: 'Geist Mono', 'Courier New', monospace; line-height:1.5; text-align:right;
|
| 227 |
}
|
| 228 |
-
.cfg-textarea:focus { border-color:#
|
| 229 |
.cfg-number {
|
| 230 |
width:100%;
|
| 231 |
max-width:none;
|
|
@@ -233,24 +241,30 @@
|
|
| 233 |
padding:0 10px;
|
| 234 |
font-size:13px;
|
| 235 |
border-radius:8px;
|
| 236 |
-
border:1px solid #
|
| 237 |
-
background:#
|
|
|
|
| 238 |
text-align:right;
|
| 239 |
}
|
| 240 |
-
.cfg-number:focus { border-color:#
|
| 241 |
.cfg-select {
|
| 242 |
width:100%;
|
| 243 |
height:32px;
|
| 244 |
padding:0 28px 0 10px;
|
| 245 |
font-size:13px;
|
| 246 |
border-radius:8px;
|
| 247 |
-
border:1px solid #
|
| 248 |
-
background:#
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
| 250 |
background-repeat:no-repeat; background-position:right 8px center;
|
| 251 |
cursor:pointer; text-align:right;
|
| 252 |
}
|
| 253 |
-
.cfg-select:focus { border-color:#
|
|
|
|
|
|
|
| 254 |
|
| 255 |
/* Toggle switch */
|
| 256 |
.toggle {
|
|
@@ -259,15 +273,15 @@
|
|
| 259 |
.toggle input { opacity:0; width:0; height:0 }
|
| 260 |
.toggle-track {
|
| 261 |
position:absolute; cursor:pointer; inset:0;
|
| 262 |
-
background:#
|
| 263 |
}
|
| 264 |
.toggle-track::before {
|
| 265 |
content:''; position:absolute; width:14px; height:14px;
|
| 266 |
left:3px; bottom:3px; background:#fff; border-radius:50%;
|
| 267 |
-
transition:transform .2s; box-shadow:0 1px 2px rgba(0,0,0,.
|
| 268 |
}
|
| 269 |
-
.toggle input:checked + .toggle-track { background:#
|
| 270 |
-
.toggle input:checked + .toggle-track::before { transform:translateX(16px) }
|
| 271 |
|
| 272 |
/* Modified badge */
|
| 273 |
.cfg-modified-dot {
|
|
@@ -281,12 +295,12 @@
|
|
| 281 |
.cfg-rand-btn {
|
| 282 |
width:30px; height:30px; border-radius:999px;
|
| 283 |
display:inline-flex; align-items:center; justify-content:center;
|
| 284 |
-
color:#
|
| 285 |
cursor:pointer; flex-shrink:0; transition:background .15s, border-color .15s;
|
| 286 |
}
|
| 287 |
-
.cfg-rand-btn:hover { background:#
|
| 288 |
|
| 289 |
-
/* Save bar */
|
| 290 |
.save-bar {
|
| 291 |
position:fixed;
|
| 292 |
left:50%;
|
|
@@ -294,8 +308,8 @@
|
|
| 294 |
z-index:50;
|
| 295 |
width:min(calc(100% - 56px), 1280px);
|
| 296 |
transform:translate(-50%, calc(100% + 20px));
|
| 297 |
-
background:rgba(
|
| 298 |
-
border:1px solid #
|
| 299 |
border-radius:16px;
|
| 300 |
padding:12px 16px;
|
| 301 |
display:flex;
|
|
@@ -303,9 +317,10 @@
|
|
| 303 |
justify-content:space-between;
|
| 304 |
gap:12px;
|
| 305 |
transition:transform .25s ease;
|
|
|
|
| 306 |
}
|
| 307 |
.save-bar.visible { transform:translate(-50%, 0) }
|
| 308 |
-
.save-bar-msg { font-size:13px; color:
|
| 309 |
.save-bar-actions { display:flex; gap:8px }
|
| 310 |
.save-bar-btn {
|
| 311 |
height:32px;
|
|
@@ -316,10 +331,10 @@
|
|
| 316 |
border:1px solid transparent;
|
| 317 |
cursor:pointer;
|
| 318 |
}
|
| 319 |
-
.save-bar-btn-cancel { border-color:#
|
| 320 |
-
.save-bar-btn-cancel:hover { background:#
|
| 321 |
-
.save-bar-btn-save { background:#
|
| 322 |
-
.save-bar-btn-save:hover { background:#
|
| 323 |
|
| 324 |
@media (max-width:640px) {
|
| 325 |
.cfg-row { grid-template-columns:1fr; gap:8px; align-items:flex-start }
|
|
@@ -384,10 +399,6 @@
|
|
| 384 |
<script src="/static/js/toast.js?v={{APP_VERSION}}"></script>
|
| 385 |
<script src="/static/js/footer.js?v={{APP_VERSION}}"></script>
|
| 386 |
<script>
|
| 387 |
-
// ── Config schema ──────────────────────────────────────────────────────────
|
| 388 |
-
// Each group has a `section` (full dotted TOML path, e.g. "proxy.egress").
|
| 389 |
-
// Each field has a `key` (leaf key within that section).
|
| 390 |
-
// Full config path = section + '.' + key.
|
| 391 |
const SCHEMA_DEF = [
|
| 392 |
{
|
| 393 |
id: 'system', label: '系统配置', labelKey: 'config.schema.tabs.system',
|
|
@@ -418,7 +429,7 @@ const SCHEMA_DEF = [
|
|
| 418 |
{ value: 'WARNING', label: 'WARNING' },
|
| 419 |
{ value: 'ERROR', label: 'ERROR' },
|
| 420 |
],
|
| 421 |
-
desc: '日志
|
| 422 |
descKey: 'config.schema.fields.fileLogLevel.desc',
|
| 423 |
},
|
| 424 |
{
|
|
@@ -733,10 +744,9 @@ const SCHEMA_DEF = [
|
|
| 733 |
},
|
| 734 |
];
|
| 735 |
|
| 736 |
-
// ── State ──────────────────────────────────────────────────────────────────
|
| 737 |
let SCHEMA = [];
|
| 738 |
-
let _cfg = {};
|
| 739 |
-
let _dirty = {};
|
| 740 |
let _activeTab = SCHEMA_DEF[0].id;
|
| 741 |
let _configLoaded = false;
|
| 742 |
let _rowRefs = new Map();
|
|
@@ -852,7 +862,6 @@ function applyConfigI18n() {
|
|
| 852 |
_refreshDirtyState({ autoNormalizeSelects: false });
|
| 853 |
}
|
| 854 |
|
| 855 |
-
// ── API ────────────────────────────────────────────────────���───────────────
|
| 856 |
async function _api(method, path, body) {
|
| 857 |
const key = await adminKey.get();
|
| 858 |
const r = await fetch(ADMIN_API + path, {
|
|
@@ -864,15 +873,11 @@ async function _api(method, path, body) {
|
|
| 864 |
return r.json();
|
| 865 |
}
|
| 866 |
|
| 867 |
-
// ── Schema helpers ─────────────────────────────────────────────────────────
|
| 868 |
-
|
| 869 |
-
// Navigate a nested object by dotted path. Returns undefined if any segment is missing.
|
| 870 |
function _getByPath(obj, dottedPath) {
|
| 871 |
return dottedPath.split('.').reduce((node, k) =>
|
| 872 |
(node != null && typeof node === 'object') ? node[k] : undefined, obj);
|
| 873 |
}
|
| 874 |
|
| 875 |
-
// Set a value at a dotted path, creating intermediate objects as needed.
|
| 876 |
function _setByPath(obj, dottedPath, value) {
|
| 877 |
const keys = dottedPath.split('.');
|
| 878 |
let cur = obj;
|
|
@@ -883,8 +888,6 @@ function _setByPath(obj, dottedPath, value) {
|
|
| 883 |
cur[keys[keys.length - 1]] = value;
|
| 884 |
}
|
| 885 |
|
| 886 |
-
// Evaluate a disabledWhen condition on a select option.
|
| 887 |
-
// Currently supported: 'no_app_url' — true when app.app_url is empty.
|
| 888 |
function _evalDisabledWhen(condition) {
|
| 889 |
if (condition === 'no_app_url') {
|
| 890 |
const v = 'app.app_url' in _dirty ? _dirty['app.app_url'] : _getByPath(_cfg, 'app.app_url');
|
|
@@ -893,9 +896,6 @@ function _evalDisabledWhen(condition) {
|
|
| 893 |
return false;
|
| 894 |
}
|
| 895 |
|
| 896 |
-
// Evaluate a showIf condition.
|
| 897 |
-
// String form: truthy check on config path. "app.webui_enabled"
|
| 898 |
-
// Object form: value-in-list check. { path: "proxy.egress.mode", values: ["single_proxy"] }
|
| 899 |
function _evalShowIf(showIf) {
|
| 900 |
if (!showIf) return true;
|
| 901 |
const path = typeof showIf === 'string' ? showIf : showIf.path;
|
|
@@ -904,10 +904,8 @@ function _evalShowIf(showIf) {
|
|
| 904 |
return showIf.values.includes(cur);
|
| 905 |
}
|
| 906 |
|
| 907 |
-
// Full dotted config path for a field: "proxy.egress.mode"
|
| 908 |
function _fullPath(section, key) { return `${section}.${key}`; }
|
| 909 |
|
| 910 |
-
// Get the current value of a field from loaded config.
|
| 911 |
function _getValue(section, key, field) {
|
| 912 |
const value = _getByPath(_cfg, _fullPath(section, key));
|
| 913 |
return value === undefined && field && Object.prototype.hasOwnProperty.call(field, 'default')
|
|
@@ -920,7 +918,6 @@ function _getCurrentValue(section, key, field) {
|
|
| 920 |
return fp in _dirty ? _dirty[fp] : _getValue(section, key, field);
|
| 921 |
}
|
| 922 |
|
| 923 |
-
// ── Render ──────────────────────────────────────────────────────────────────
|
| 924 |
function _el(tag, attrs, ...children) {
|
| 925 |
const el = document.createElement(tag);
|
| 926 |
Object.entries(attrs || {}).forEach(([k, v]) => {
|
|
@@ -1072,7 +1069,6 @@ function renderInput(field, section, value) {
|
|
| 1072 |
const inp = _el('input', attrs);
|
| 1073 |
inp.addEventListener('input', () => {
|
| 1074 |
let n = inp.value === '' ? '' : Number(inp.value);
|
| 1075 |
-
// 强制限制在 min/max 范围内
|
| 1076 |
if (typeof n === 'number' && !isNaN(n)) {
|
| 1077 |
if (field.min != null && n < field.min) n = field.min;
|
| 1078 |
if (field.max != null && n > field.max) n = field.max;
|
|
@@ -1083,7 +1079,6 @@ function renderInput(field, section, value) {
|
|
| 1083 |
return inp;
|
| 1084 |
}
|
| 1085 |
|
| 1086 |
-
// text / password
|
| 1087 |
const inp = _el('input', {
|
| 1088 |
class: `cfg-text${field.wide ? ' wide' : ''}`,
|
| 1089 |
type: field.type === 'password' ? 'password' : 'text',
|
|
@@ -1168,7 +1163,6 @@ function renderRow(field, section, tabId) {
|
|
| 1168 |
_tabFieldIndex.set(fp, tabId);
|
| 1169 |
if (isDirty) _tabDirtyCounts.set(tabId, (_tabDirtyCounts.get(tabId) || 0) + 1);
|
| 1170 |
|
| 1171 |
-
// Conditional visibility
|
| 1172 |
if (field.showIf) {
|
| 1173 |
row._showIfSpec = field.showIf;
|
| 1174 |
row.style.display = _evalShowIf(field.showIf) ? '' : 'none';
|
|
@@ -1201,7 +1195,6 @@ function renderAll() {
|
|
| 1201 |
nav.innerHTML = ''; panels.innerHTML = '';
|
| 1202 |
|
| 1203 |
SCHEMA.forEach(tab => {
|
| 1204 |
-
// Tab button
|
| 1205 |
const btn = _el('button', {
|
| 1206 |
class: `cfg-tab${tab.id === _activeTab ? ' active' : ''}`,
|
| 1207 |
onclick: () => switchTab(tab.id),
|
|
@@ -1210,7 +1203,6 @@ function renderAll() {
|
|
| 1210 |
_tabButtons.set(tab.id, btn);
|
| 1211 |
nav.appendChild(btn);
|
| 1212 |
|
| 1213 |
-
// Panel
|
| 1214 |
panels.appendChild(renderPanel(tab));
|
| 1215 |
});
|
| 1216 |
_tabButtons.forEach((_, tabId) => _syncTabDirtyState(tabId));
|
|
@@ -1224,7 +1216,6 @@ function switchTab(id) {
|
|
| 1224 |
p.classList.toggle('active', p.id === `panel-${id}`));
|
| 1225 |
}
|
| 1226 |
|
| 1227 |
-
// ── Dirty state helpers ────────────────────────────────────────────────────
|
| 1228 |
function _refreshRow(section, key) {
|
| 1229 |
const row = _rowRefs.get(_fullPath(section, key));
|
| 1230 |
if (row) row.classList.toggle('modified', _fullPath(section, key) in _dirty);
|
|
@@ -1284,7 +1275,6 @@ function _refreshDirtyState({ autoNormalizeSelects = true, changedPaths = null }
|
|
| 1284 |
if (!changedPaths) _tabButtons.forEach((_, tabId) => _syncTabDirtyState(tabId));
|
| 1285 |
}
|
| 1286 |
|
| 1287 |
-
// ── Load config ──────────────────────────────────────────────────────────���─
|
| 1288 |
async function load() {
|
| 1289 |
try {
|
| 1290 |
_cfg = await _api('GET', '/config');
|
|
@@ -1298,22 +1288,17 @@ async function load() {
|
|
| 1298 |
}
|
| 1299 |
}
|
| 1300 |
|
| 1301 |
-
// ── Save ──────────────────────────────────────────────────────────────────
|
| 1302 |
async function doSave() {
|
| 1303 |
if (!Object.keys(_dirty).length) return;
|
| 1304 |
|
| 1305 |
-
// Build a properly nested patch from full dotted paths.
|
| 1306 |
-
// "proxy.egress.mode" → {proxy:{egress:{mode:v}}}
|
| 1307 |
const patch = {};
|
| 1308 |
Object.entries(_dirty).forEach(([fp, v]) => _setByPath(patch, fp, v));
|
| 1309 |
|
| 1310 |
try {
|
| 1311 |
showToast(tr('config.saving', null, '正在保存更改…'), 'info');
|
| 1312 |
await _api('POST', '/config', patch);
|
| 1313 |
-
// Merge into local _cfg so re-render shows correct values.
|
| 1314 |
Object.entries(_dirty).forEach(([fp, v]) => _setByPath(_cfg, fp, v));
|
| 1315 |
_dirty = {};
|
| 1316 |
-
// Re-render to clear modified state
|
| 1317 |
renderAll();
|
| 1318 |
_refreshDirtyState({ autoNormalizeSelects: false });
|
| 1319 |
showToast(tr('config.saveSuccess', null, '更改已保存'), 'success');
|
|
@@ -1322,7 +1307,6 @@ async function doSave() {
|
|
| 1322 |
}
|
| 1323 |
}
|
| 1324 |
|
| 1325 |
-
// ── Reset ─────────────────────────────────────────────────────────────────
|
| 1326 |
function doReset() {
|
| 1327 |
if (!Object.keys(_dirty).length) return;
|
| 1328 |
_dirty = {};
|
|
@@ -1331,7 +1315,6 @@ function doReset() {
|
|
| 1331 |
showToast(tr('config.resetSuccess', null, '未保存的更改已撤销'), 'info');
|
| 1332 |
}
|
| 1333 |
|
| 1334 |
-
// ── Boot ──────────────────────────────────────────────────────────────────
|
| 1335 |
(async () => {
|
| 1336 |
try {
|
| 1337 |
SCHEMA = buildSchema();
|
|
|
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
| 9 |
<link href="/static/css/app.css?v={{APP_VERSION}}" rel="stylesheet">
|
| 10 |
<style>
|
| 11 |
+
/* 全局基础深灰色调 */
|
| 12 |
+
body { background: #18181b; color: #e4e4e7; }
|
| 13 |
|
| 14 |
/* Page header */
|
| 15 |
.page-hd { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:20px }
|
| 16 |
+
.page-title{ font-size:22px; font-weight:700; line-height:1.2; color: #ffffff; }
|
| 17 |
+
.page-sub { font-size:13px; color:#a1a1aa; margin-top:5px }
|
| 18 |
.page-actions { display:flex; gap:8px; align-items:center; flex-shrink:0 }
|
| 19 |
|
| 20 |
+
/* 按钮深色适配 */
|
| 21 |
.page-action-btn {
|
| 22 |
height:32px; padding:0 14px; border-radius:999px;
|
| 23 |
display:inline-flex; align-items:center; justify-content:center; gap:6px;
|
| 24 |
font-size:13px; font-weight:600;
|
| 25 |
+
border:1px solid #3f3f46; background:#27272a; color:#e4e4e7;
|
| 26 |
}
|
| 27 |
+
.page-action-btn:hover { background:#3f3f46; border-color:#52525b; color:#fff }
|
| 28 |
+
.page-action-btn-primary { background:#fafafa; border-color:#fafafa; color:#111 }
|
| 29 |
+
.page-action-btn-primary:hover { background:#e4e4e7; border-color:#e4e4e7 }
|
| 30 |
+
.page-action-btn:disabled { opacity:.3; pointer-events:none }
|
| 31 |
|
| 32 |
/* Section nav tabs */
|
| 33 |
.cfg-nav {
|
|
|
|
| 44 |
border-radius:999px;
|
| 45 |
font-size:12px;
|
| 46 |
font-weight:500;
|
| 47 |
+
color:#a1a1aa;
|
| 48 |
+
background:#27272a;
|
| 49 |
transition:color .15s, background .15s;
|
| 50 |
cursor:pointer;
|
| 51 |
+
border:none;
|
| 52 |
}
|
| 53 |
+
.cfg-tab:hover { color:#fff; background:#3f3f46 }
|
| 54 |
.cfg-tab.active {
|
| 55 |
+
background:#fafafa;
|
| 56 |
+
color:#111;
|
| 57 |
font-weight:600;
|
| 58 |
}
|
| 59 |
.cfg-tab .dot {
|
|
|
|
| 64 |
background:currentColor;
|
| 65 |
margin-left:5px;
|
| 66 |
vertical-align:middle;
|
| 67 |
+
opacity:.7;
|
| 68 |
}
|
| 69 |
.cfg-tab.dirty .dot { display:inline-block }
|
| 70 |
|
|
|
|
| 72 |
.cfg-panel { display:none }
|
| 73 |
.cfg-panel.active { display:block }
|
| 74 |
|
| 75 |
+
/* Field rows - 容器与行卡片适配 */
|
| 76 |
.cfg-group {
|
| 77 |
+
background:#27272a;
|
| 78 |
+
border:1px solid #3f3f46;
|
| 79 |
border-radius:12px;
|
| 80 |
overflow:hidden;
|
| 81 |
margin-bottom:12px;
|
|
|
|
| 83 |
.cfg-group-title {
|
| 84 |
font-size:11px;
|
| 85 |
font-weight:700;
|
| 86 |
+
color:#a1a1aa;
|
| 87 |
text-transform:uppercase;
|
| 88 |
letter-spacing:.08em;
|
| 89 |
padding:12px 16px 6px;
|
| 90 |
+
background:#27272a;
|
| 91 |
border-bottom:none;
|
| 92 |
}
|
| 93 |
.cfg-row {
|
|
|
|
| 96 |
gap:18px;
|
| 97 |
align-items:center;
|
| 98 |
padding:11px 16px;
|
| 99 |
+
border-bottom:1px solid #3f3f46;
|
| 100 |
transition:background .15s;
|
| 101 |
}
|
| 102 |
.cfg-row:last-child { border-bottom:none }
|
| 103 |
+
.cfg-row:hover { background:#2f2f33 }
|
| 104 |
+
/* 暗色模式下修改状态使用暗琥珀色背景 */
|
| 105 |
+
.cfg-row.modified { background:#2c1d05 }
|
| 106 |
+
.cfg-row.modified:hover { background:#382607 }
|
| 107 |
.cfg-label-col { min-width:0; display:grid; gap:3px; align-content:start }
|
| 108 |
.cfg-label {
|
| 109 |
display:inline-flex;
|
|
|
|
| 111 |
gap:6px;
|
| 112 |
font-size:12px;
|
| 113 |
font-weight:600;
|
| 114 |
+
color:#f4f4f5;
|
| 115 |
line-height:1.35;
|
| 116 |
}
|
| 117 |
+
.cfg-desc { max-width:520px; font-size:11px; color:#a1a1aa; line-height:1.45 }
|
| 118 |
.cfg-help {
|
| 119 |
position:relative;
|
| 120 |
width:16px;
|
|
|
|
| 124 |
justify-content:center;
|
| 125 |
padding:0;
|
| 126 |
border-radius:50%;
|
| 127 |
+
border:1px solid #3f3f46;
|
| 128 |
+
background:#27272a;
|
| 129 |
+
color:#a1a1aa;
|
| 130 |
font-size:11px;
|
| 131 |
line-height:1;
|
| 132 |
font-weight:700;
|
|
|
|
| 135 |
}
|
| 136 |
.cfg-help:hover,
|
| 137 |
.cfg-help:focus-visible {
|
| 138 |
+
color:#fff;
|
| 139 |
+
border-color:#52525b;
|
| 140 |
+
background:#3f3f46;
|
| 141 |
outline:none;
|
| 142 |
}
|
| 143 |
.cfg-help-tip {
|
|
|
|
| 146 |
max-width:min(320px, calc(100vw - 24px));
|
| 147 |
padding:9px 10px;
|
| 148 |
border-radius:8px;
|
| 149 |
+
background:#27272a;
|
| 150 |
+
border:1px solid #3f3f46;
|
| 151 |
color:#fff;
|
| 152 |
font-size:12px;
|
| 153 |
font-weight:500;
|
|
|
|
| 155 |
text-align:left;
|
| 156 |
white-space:pre-line;
|
| 157 |
overflow-wrap:anywhere;
|
| 158 |
+
box-shadow:0 8px 24px rgba(0,0,0,.4);
|
| 159 |
opacity:0;
|
| 160 |
pointer-events:none;
|
| 161 |
transform:translateY(3px);
|
|
|
|
| 172 |
left:var(--arrow-left, 50%);
|
| 173 |
width:8px;
|
| 174 |
height:8px;
|
| 175 |
+
background:#27272a;
|
| 176 |
+
border-left:1px solid #3f3f46;
|
| 177 |
+
border-top:1px solid #3f3f46;
|
| 178 |
transform:translateX(-50%) rotate(45deg);
|
| 179 |
}
|
| 180 |
+
.cfg-help-tip[data-placement="top"]::before { bottom:-5px; transform:translateX(-50%) rotate(225deg); }
|
| 181 |
+
.cfg-help-tip[data-placement="bottom"]::before { top:-5px; transform:translateX(-50%) rotate(45deg); }
|
| 182 |
.cfg-input-col { min-width:0; display:flex; align-items:center; justify-content:flex-start; gap:8px }
|
| 183 |
.cfg-input-col.is-bool { justify-content:flex-end }
|
| 184 |
.cfg-inline-action {
|
|
|
|
| 188 |
align-items:center;
|
| 189 |
justify-content:center;
|
| 190 |
padding:0;
|
| 191 |
+
color:#a1a1aa;
|
| 192 |
border:0;
|
| 193 |
background:transparent;
|
| 194 |
cursor:pointer;
|
| 195 |
flex-shrink:0;
|
| 196 |
transition:color .15s, opacity .15s, transform .15s;
|
| 197 |
}
|
| 198 |
+
.cfg-inline-action:hover { color:#fff; transform:translateY(-.5px) }
|
| 199 |
.cfg-inline-action:disabled {
|
| 200 |
opacity:.32;
|
| 201 |
cursor:not-allowed;
|
|
|
|
| 203 |
}
|
| 204 |
.cfg-inline-action svg { width:14px; height:14px; display:block }
|
| 205 |
|
| 206 |
+
/* Inputs - 输入框元素全局深色化与边框调校 */
|
| 207 |
.cfg-text {
|
| 208 |
width:100%;
|
| 209 |
max-width:none;
|
|
|
|
| 211 |
padding:0 10px;
|
| 212 |
font-size:13px;
|
| 213 |
border-radius:8px;
|
| 214 |
+
border:1px solid #3f3f46;
|
| 215 |
+
background:#1f1f23;
|
| 216 |
+
color:#e4e4e7;
|
| 217 |
transition:border-color .15s, background .15s;
|
| 218 |
font-family: inherit; text-align:right;
|
| 219 |
}
|
| 220 |
+
.cfg-text:focus { border-color:#71717a; background:#27272a; outline:none; box-shadow:none; color:#fff; }
|
| 221 |
.cfg-text.wide { max-width:none }
|
| 222 |
.cfg-textarea {
|
| 223 |
width:100%;
|
|
|
|
| 226 |
padding:8px 10px;
|
| 227 |
font-size:12px;
|
| 228 |
border-radius:10px;
|
| 229 |
+
border:1px solid #3f3f46;
|
| 230 |
+
background:#1f1f23;
|
| 231 |
+
color:#e4e4e7;
|
| 232 |
resize:vertical;
|
| 233 |
transition:border-color .15s, background .15s;
|
| 234 |
font-family: 'Geist Mono', 'Courier New', monospace; line-height:1.5; text-align:right;
|
| 235 |
}
|
| 236 |
+
.cfg-textarea:focus { border-color:#71717a; background:#27272a; outline:none; color:#fff; }
|
| 237 |
.cfg-number {
|
| 238 |
width:100%;
|
| 239 |
max-width:none;
|
|
|
|
| 241 |
padding:0 10px;
|
| 242 |
font-size:13px;
|
| 243 |
border-radius:8px;
|
| 244 |
+
border:1px solid #3f3f46;
|
| 245 |
+
background:#1f1f23;
|
| 246 |
+
color:#e4e4e7;
|
| 247 |
text-align:right;
|
| 248 |
}
|
| 249 |
+
.cfg-number:focus { border-color:#71717a; background:#27272a; outline:none; color:#fff; }
|
| 250 |
.cfg-select {
|
| 251 |
width:100%;
|
| 252 |
height:32px;
|
| 253 |
padding:0 28px 0 10px;
|
| 254 |
font-size:13px;
|
| 255 |
border-radius:8px;
|
| 256 |
+
border:1px solid #3f3f46;
|
| 257 |
+
background:#1f1f23;
|
| 258 |
+
color:#e4e4e7;
|
| 259 |
+
appearance:none;
|
| 260 |
+
/* 调整 SVG 图标为浅灰色以防暗色下看不见 */
|
| 261 |
+
background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%23aaa' stroke-width='2' fill='none'/%3E%3C/svg%3E");
|
| 262 |
background-repeat:no-repeat; background-position:right 8px center;
|
| 263 |
cursor:pointer; text-align:right;
|
| 264 |
}
|
| 265 |
+
.cfg-select:focus { border-color:#71717a; background:#27272a; outline:none }
|
| 266 |
+
.cfg-select option { background:#27272a; color:#e4e4e7 }
|
| 267 |
+
.cfg-select option:disabled { color:#71717a }
|
| 268 |
|
| 269 |
/* Toggle switch */
|
| 270 |
.toggle {
|
|
|
|
| 273 |
.toggle input { opacity:0; width:0; height:0 }
|
| 274 |
.toggle-track {
|
| 275 |
position:absolute; cursor:pointer; inset:0;
|
| 276 |
+
background:#3f3f46; border-radius:20px; transition:background .2s;
|
| 277 |
}
|
| 278 |
.toggle-track::before {
|
| 279 |
content:''; position:absolute; width:14px; height:14px;
|
| 280 |
left:3px; bottom:3px; background:#fff; border-radius:50%;
|
| 281 |
+
transition:transform .2s; box-shadow:0 1px 2px rgba(0,0,0,.3);
|
| 282 |
}
|
| 283 |
+
.toggle input:checked + .toggle-track { background:#fafafa }
|
| 284 |
+
.toggle input:checked + .toggle-track::before { transform:translateX(16px); background:#111; }
|
| 285 |
|
| 286 |
/* Modified badge */
|
| 287 |
.cfg-modified-dot {
|
|
|
|
| 295 |
.cfg-rand-btn {
|
| 296 |
width:30px; height:30px; border-radius:999px;
|
| 297 |
display:inline-flex; align-items:center; justify-content:center;
|
| 298 |
+
color:#a1a1aa; border:1px solid #3f3f46; background:#27272a;
|
| 299 |
cursor:pointer; flex-shrink:0; transition:background .15s, border-color .15s;
|
| 300 |
}
|
| 301 |
+
.cfg-rand-btn:hover { background:#3f3f46; border-color:#52525b; color:#fff }
|
| 302 |
|
| 303 |
+
/* Save bar - 底部保存栏半透明磨砂质感 */
|
| 304 |
.save-bar {
|
| 305 |
position:fixed;
|
| 306 |
left:50%;
|
|
|
|
| 308 |
z-index:50;
|
| 309 |
width:min(calc(100% - 56px), 1280px);
|
| 310 |
transform:translate(-50%, calc(100% + 20px));
|
| 311 |
+
background:rgba(39,39,42,.96);
|
| 312 |
+
border:1px solid #3f3f46;
|
| 313 |
border-radius:16px;
|
| 314 |
padding:12px 16px;
|
| 315 |
display:flex;
|
|
|
|
| 317 |
justify-content:space-between;
|
| 318 |
gap:12px;
|
| 319 |
transition:transform .25s ease;
|
| 320 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
|
| 321 |
}
|
| 322 |
.save-bar.visible { transform:translate(-50%, 0) }
|
| 323 |
+
.save-bar-msg { font-size:13px; color:#a1a1aa }
|
| 324 |
.save-bar-actions { display:flex; gap:8px }
|
| 325 |
.save-bar-btn {
|
| 326 |
height:32px;
|
|
|
|
| 331 |
border:1px solid transparent;
|
| 332 |
cursor:pointer;
|
| 333 |
}
|
| 334 |
+
.save-bar-btn-cancel { border-color:#3f3f46; background:#27272a; color:#e4e4e7; }
|
| 335 |
+
.save-bar-btn-cancel:hover { background:#3f3f46; border-color:#52525b; color:#fff; }
|
| 336 |
+
.save-bar-btn-save { background:#fafafa; color:#111 }
|
| 337 |
+
.save-bar-btn-save:hover { background:#e4e4e7Prefix }
|
| 338 |
|
| 339 |
@media (max-width:640px) {
|
| 340 |
.cfg-row { grid-template-columns:1fr; gap:8px; align-items:flex-start }
|
|
|
|
| 399 |
<script src="/static/js/toast.js?v={{APP_VERSION}}"></script>
|
| 400 |
<script src="/static/js/footer.js?v={{APP_VERSION}}"></script>
|
| 401 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
const SCHEMA_DEF = [
|
| 403 |
{
|
| 404 |
id: 'system', label: '系统配置', labelKey: 'config.schema.tabs.system',
|
|
|
|
| 429 |
{ value: 'WARNING', label: 'WARNING' },
|
| 430 |
{ value: 'ERROR', label: 'ERROR' },
|
| 431 |
],
|
| 432 |
+
desc: '日志 file 写入最低等级,可独立于控制台配置。默认 INFO。',
|
| 433 |
descKey: 'config.schema.fields.fileLogLevel.desc',
|
| 434 |
},
|
| 435 |
{
|
|
|
|
| 744 |
},
|
| 745 |
];
|
| 746 |
|
|
|
|
| 747 |
let SCHEMA = [];
|
| 748 |
+
let _cfg = {};
|
| 749 |
+
let _dirty = {};
|
| 750 |
let _activeTab = SCHEMA_DEF[0].id;
|
| 751 |
let _configLoaded = false;
|
| 752 |
let _rowRefs = new Map();
|
|
|
|
| 862 |
_refreshDirtyState({ autoNormalizeSelects: false });
|
| 863 |
}
|
| 864 |
|
|
|
|
| 865 |
async function _api(method, path, body) {
|
| 866 |
const key = await adminKey.get();
|
| 867 |
const r = await fetch(ADMIN_API + path, {
|
|
|
|
| 873 |
return r.json();
|
| 874 |
}
|
| 875 |
|
|
|
|
|
|
|
|
|
|
| 876 |
function _getByPath(obj, dottedPath) {
|
| 877 |
return dottedPath.split('.').reduce((node, k) =>
|
| 878 |
(node != null && typeof node === 'object') ? node[k] : undefined, obj);
|
| 879 |
}
|
| 880 |
|
|
|
|
| 881 |
function _setByPath(obj, dottedPath, value) {
|
| 882 |
const keys = dottedPath.split('.');
|
| 883 |
let cur = obj;
|
|
|
|
| 888 |
cur[keys[keys.length - 1]] = value;
|
| 889 |
}
|
| 890 |
|
|
|
|
|
|
|
| 891 |
function _evalDisabledWhen(condition) {
|
| 892 |
if (condition === 'no_app_url') {
|
| 893 |
const v = 'app.app_url' in _dirty ? _dirty['app.app_url'] : _getByPath(_cfg, 'app.app_url');
|
|
|
|
| 896 |
return false;
|
| 897 |
}
|
| 898 |
|
|
|
|
|
|
|
|
|
|
| 899 |
function _evalShowIf(showIf) {
|
| 900 |
if (!showIf) return true;
|
| 901 |
const path = typeof showIf === 'string' ? showIf : showIf.path;
|
|
|
|
| 904 |
return showIf.values.includes(cur);
|
| 905 |
}
|
| 906 |
|
|
|
|
| 907 |
function _fullPath(section, key) { return `${section}.${key}`; }
|
| 908 |
|
|
|
|
| 909 |
function _getValue(section, key, field) {
|
| 910 |
const value = _getByPath(_cfg, _fullPath(section, key));
|
| 911 |
return value === undefined && field && Object.prototype.hasOwnProperty.call(field, 'default')
|
|
|
|
| 918 |
return fp in _dirty ? _dirty[fp] : _getValue(section, key, field);
|
| 919 |
}
|
| 920 |
|
|
|
|
| 921 |
function _el(tag, attrs, ...children) {
|
| 922 |
const el = document.createElement(tag);
|
| 923 |
Object.entries(attrs || {}).forEach(([k, v]) => {
|
|
|
|
| 1069 |
const inp = _el('input', attrs);
|
| 1070 |
inp.addEventListener('input', () => {
|
| 1071 |
let n = inp.value === '' ? '' : Number(inp.value);
|
|
|
|
| 1072 |
if (typeof n === 'number' && !isNaN(n)) {
|
| 1073 |
if (field.min != null && n < field.min) n = field.min;
|
| 1074 |
if (field.max != null && n > field.max) n = field.max;
|
|
|
|
| 1079 |
return inp;
|
| 1080 |
}
|
| 1081 |
|
|
|
|
| 1082 |
const inp = _el('input', {
|
| 1083 |
class: `cfg-text${field.wide ? ' wide' : ''}`,
|
| 1084 |
type: field.type === 'password' ? 'password' : 'text',
|
|
|
|
| 1163 |
_tabFieldIndex.set(fp, tabId);
|
| 1164 |
if (isDirty) _tabDirtyCounts.set(tabId, (_tabDirtyCounts.get(tabId) || 0) + 1);
|
| 1165 |
|
|
|
|
| 1166 |
if (field.showIf) {
|
| 1167 |
row._showIfSpec = field.showIf;
|
| 1168 |
row.style.display = _evalShowIf(field.showIf) ? '' : 'none';
|
|
|
|
| 1195 |
nav.innerHTML = ''; panels.innerHTML = '';
|
| 1196 |
|
| 1197 |
SCHEMA.forEach(tab => {
|
|
|
|
| 1198 |
const btn = _el('button', {
|
| 1199 |
class: `cfg-tab${tab.id === _activeTab ? ' active' : ''}`,
|
| 1200 |
onclick: () => switchTab(tab.id),
|
|
|
|
| 1203 |
_tabButtons.set(tab.id, btn);
|
| 1204 |
nav.appendChild(btn);
|
| 1205 |
|
|
|
|
| 1206 |
panels.appendChild(renderPanel(tab));
|
| 1207 |
});
|
| 1208 |
_tabButtons.forEach((_, tabId) => _syncTabDirtyState(tabId));
|
|
|
|
| 1216 |
p.classList.toggle('active', p.id === `panel-${id}`));
|
| 1217 |
}
|
| 1218 |
|
|
|
|
| 1219 |
function _refreshRow(section, key) {
|
| 1220 |
const row = _rowRefs.get(_fullPath(section, key));
|
| 1221 |
if (row) row.classList.toggle('modified', _fullPath(section, key) in _dirty);
|
|
|
|
| 1275 |
if (!changedPaths) _tabButtons.forEach((_, tabId) => _syncTabDirtyState(tabId));
|
| 1276 |
}
|
| 1277 |
|
|
|
|
| 1278 |
async function load() {
|
| 1279 |
try {
|
| 1280 |
_cfg = await _api('GET', '/config');
|
|
|
|
| 1288 |
}
|
| 1289 |
}
|
| 1290 |
|
|
|
|
| 1291 |
async function doSave() {
|
| 1292 |
if (!Object.keys(_dirty).length) return;
|
| 1293 |
|
|
|
|
|
|
|
| 1294 |
const patch = {};
|
| 1295 |
Object.entries(_dirty).forEach(([fp, v]) => _setByPath(patch, fp, v));
|
| 1296 |
|
| 1297 |
try {
|
| 1298 |
showToast(tr('config.saving', null, '正在保存更改…'), 'info');
|
| 1299 |
await _api('POST', '/config', patch);
|
|
|
|
| 1300 |
Object.entries(_dirty).forEach(([fp, v]) => _setByPath(_cfg, fp, v));
|
| 1301 |
_dirty = {};
|
|
|
|
| 1302 |
renderAll();
|
| 1303 |
_refreshDirtyState({ autoNormalizeSelects: false });
|
| 1304 |
showToast(tr('config.saveSuccess', null, '更改已保存'), 'success');
|
|
|
|
| 1307 |
}
|
| 1308 |
}
|
| 1309 |
|
|
|
|
| 1310 |
function doReset() {
|
| 1311 |
if (!Object.keys(_dirty).length) return;
|
| 1312 |
_dirty = {};
|
|
|
|
| 1315 |
showToast(tr('config.resetSuccess', null, '未保存的更改已撤销'), 'info');
|
| 1316 |
}
|
| 1317 |
|
|
|
|
| 1318 |
(async () => {
|
| 1319 |
try {
|
| 1320 |
SCHEMA = buildSchema();
|