fix(base): AutoForm checkbox/radio/switch 样式修复,HTTP 新增 keepHeaders 跨请求保留机制(by AI)

Co-Authored-By: deepseek-v4-pro[1m] <deepseek-ai@claude-code-best.win>
This commit is contained in:
AI Engineer 2026-06-22 19:23:51 +08:00
parent 70d61f3744
commit 1207c26aef
8 changed files with 53 additions and 5214 deletions

26
dist/base.js vendored
View File

@ -30,11 +30,24 @@
} }
options.body = data; options.body = data;
} }
for (const name of HTTP.keepHeaders) {
if (HTTP._keepHeadersCache[name] && !headers[name]) headers[name] = HTTP._keepHeadersCache[name];
}
if (Object.keys(headers).length) options.headers = headers; if (Object.keys(headers).length) options.headers = headers;
const response = { error: null, ok: null, status: 0, headers: {}, responseType: "", result: null }; const response = { error: null, ok: null, status: 0, headers: {}, responseType: "", result: null };
try { try {
const resp = await fetch(url, options); const resp = await fetch(url, options);
Object.assign(response, { ok: resp.ok, status: resp.status, headers: Object.fromEntries(resp.headers.entries()) }); Object.assign(response, { ok: resp.ok, status: resp.status, headers: Object.fromEntries(resp.headers.entries()) });
for (const name of HTTP.keepHeaders) {
const val = resp.headers.get(name);
if (val) {
HTTP._keepHeadersCache[name] = val;
try {
localStorage.setItem("_http_keep_" + name, val);
} catch (e) {
}
}
}
if (!responseType) { if (!responseType) {
const contentType = resp.headers.get("Content-Type") || ""; const contentType = resp.headers.get("Content-Type") || "";
if (contentType.includes("application/json")) responseType = "json"; if (contentType.includes("application/json")) responseType = "json";
@ -51,6 +64,15 @@
return response; return response;
} }
}; };
HTTP.keepHeaders = ["Session-Id", "Device-Id"];
HTTP._keepHeadersCache = {};
for (const name of HTTP.keepHeaders) {
try {
const val = localStorage.getItem("_http_keep_" + name);
if (val !== null) HTTP._keepHeadersCache[name] = val;
} catch (e) {
}
}
globalThis.HTTP = HTTP; globalThis.HTTP = HTTP;
const UI = {}; const UI = {};
globalThis.Component.register("Toast", (container) => { globalThis.Component.register("Toast", (container) => {
@ -127,14 +149,14 @@
<option $each="item.options" as="opt" $value="opt.value !== undefined ? opt.value : opt" $text="opt.label || opt"></option> <option $each="item.options" as="opt" $value="opt.value !== undefined ? opt.value : opt" $text="opt.label || opt"></option>
</select> </select>
<div $if="['checkbox', 'radio'].includes(item.type)" class="d-flex align-items-center flex-wrap gap-3 h-100"> <div $if="['checkbox', 'radio'].includes(item.type)" class="d-flex align-items-center flex-wrap gap-3 h-100" style="padding: 0 0.75rem; min-height: calc(2.25rem + 2px);">
<label $each="item.options || [item.text||item.label||item.name]" as="opt" class="form-check mb-0 d-flex align-items-center" style="padding-left:0; cursor:pointer;"> <label $each="item.options || [item.text||item.label||item.name]" as="opt" class="form-check mb-0 d-flex align-items-center" style="padding-left:0; cursor:pointer;">
<input $name="item.name" class="form-check-input m-0 me-2" style="float:none;" $type="item.type" $.="item.setting || {}" $value="item.options ? (opt.value !== undefined ? opt.value : opt) : 'on'" $bind="this.data[item.name]"> <input $name="item.name" class="form-check-input m-0 me-2" style="float:none;" $type="item.type" $.="item.setting || {}" $value="item.options ? (opt.value !== undefined ? opt.value : opt) : 'on'" $bind="this.data[item.name]">
<span $if="!this.inline || (item.options && item.options.length > 0)" $text="opt.label || opt" class="form-check-label"></span> <span $if="!this.inline || (item.options && item.options.length > 0)" $text="opt.label || opt" class="form-check-label"></span>
</label> </label>
</div> </div>
<div $if="item.type === 'switch'" class="form-check form-switch fs-5 d-flex align-items-center m-0" style="padding-left:0; min-height:0; display:flex !important;"> <div $if="item.type === 'switch'" class="form-check form-switch fs-5 d-flex align-items-center m-0" style="padding: 0 0.75rem; min-height: calc(2.25rem + 2px); display:flex !important;">
<input $name="item.name" class="form-check-input m-0" style="float:none; cursor:pointer" type="checkbox" $bind="this.data[item.name]"> <input $name="item.name" class="form-check-input m-0" style="float:none; cursor:pointer" type="checkbox" $bind="this.data[item.name]">
</div> </div>

2
dist/base.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,15 +1,8 @@
{ {
"hash": "945ec9e8", "hash": "5696baa5",
"configHash": "6c629749", "configHash": "6c629749",
"lockfileHash": "463a0a64", "lockfileHash": "e54d6ef0",
"browserHash": "38e755dd", "browserHash": "d0b634f4",
"optimized": { "optimized": {},
"bootstrap": {
"src": "../../../../bootstrap/node_modules/bootstrap/dist/js/bootstrap.esm.js",
"file": "bootstrap.js",
"fileHash": "b9d6a4a2",
"needsInterop": false
}
},
"chunks": {} "chunks": {}
} }

5188
node_modules/.vite/deps/bootstrap.js generated vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -17,14 +17,14 @@ const AUTOFORM_BLUEPRINT = globalThis.Util.makeDom(/*html*/`
<option $each="item.options" as="opt" $value="opt.value !== undefined ? opt.value : opt" $text="opt.label || opt"></option> <option $each="item.options" as="opt" $value="opt.value !== undefined ? opt.value : opt" $text="opt.label || opt"></option>
</select> </select>
<div $if="['checkbox', 'radio'].includes(item.type)" class="d-flex align-items-center flex-wrap gap-3 h-100"> <div $if="['checkbox', 'radio'].includes(item.type)" class="d-flex align-items-center flex-wrap gap-3 h-100" style="padding: 0 0.75rem; min-height: calc(2.25rem + 2px);">
<label $each="item.options || [item.text||item.label||item.name]" as="opt" class="form-check mb-0 d-flex align-items-center" style="padding-left:0; cursor:pointer;"> <label $each="item.options || [item.text||item.label||item.name]" as="opt" class="form-check mb-0 d-flex align-items-center" style="padding-left:0; cursor:pointer;">
<input $name="item.name" class="form-check-input m-0 me-2" style="float:none;" $type="item.type" $.="item.setting || {}" $value="item.options ? (opt.value !== undefined ? opt.value : opt) : 'on'" $bind="this.data[item.name]"> <input $name="item.name" class="form-check-input m-0 me-2" style="float:none;" $type="item.type" $.="item.setting || {}" $value="item.options ? (opt.value !== undefined ? opt.value : opt) : 'on'" $bind="this.data[item.name]">
<span $if="!this.inline || (item.options && item.options.length > 0)" $text="opt.label || opt" class="form-check-label"></span> <span $if="!this.inline || (item.options && item.options.length > 0)" $text="opt.label || opt" class="form-check-label"></span>
</label> </label>
</div> </div>
<div $if="item.type === 'switch'" class="form-check form-switch fs-5 d-flex align-items-center m-0" style="padding-left:0; min-height:0; display:flex !important;"> <div $if="item.type === 'switch'" class="form-check form-switch fs-5 d-flex align-items-center m-0" style="padding: 0 0.75rem; min-height: calc(2.25rem + 2px); display:flex !important;">
<input $name="item.name" class="form-check-input m-0" style="float:none; cursor:pointer" type="checkbox" $bind="this.data[item.name]"> <input $name="item.name" class="form-check-input m-0" style="float:none; cursor:pointer" type="checkbox" $bind="this.data[item.name]">
</div> </div>

View File

@ -28,11 +28,21 @@ const HTTP = {
} }
options.body = data options.body = data
} }
for (const name of HTTP.keepHeaders) {
if (HTTP._keepHeadersCache[name] && !headers[name]) headers[name] = HTTP._keepHeadersCache[name]
}
if (Object.keys(headers).length) options.headers = headers if (Object.keys(headers).length) options.headers = headers
const response = { error: null, ok: null, status: 0, headers: {}, responseType: '', result: null } const response = { error: null, ok: null, status: 0, headers: {}, responseType: '', result: null }
try { try {
const resp = await fetch(url, options) const resp = await fetch(url, options)
Object.assign(response, { ok: resp.ok, status: resp.status, headers: Object.fromEntries(resp.headers.entries()) }) Object.assign(response, { ok: resp.ok, status: resp.status, headers: Object.fromEntries(resp.headers.entries()) })
for (const name of HTTP.keepHeaders) {
const val = resp.headers.get(name)
if (val) {
HTTP._keepHeadersCache[name] = val
try { localStorage.setItem('_http_keep_' + name, val); } catch (e) {}
}
}
if (!responseType) { if (!responseType) {
const contentType = resp.headers.get('Content-Type') || '' const contentType = resp.headers.get('Content-Type') || ''
if (contentType.includes('application/json')) responseType = 'json' if (contentType.includes('application/json')) responseType = 'json'
@ -50,5 +60,14 @@ const HTTP = {
} }
} }
HTTP.keepHeaders = ['Session-Id', 'Device-Id'];
HTTP._keepHeadersCache = {};
for (const name of HTTP.keepHeaders) {
try {
const val = localStorage.getItem('_http_keep_' + name);
if (val !== null) HTTP._keepHeadersCache[name] = val;
} catch (e) {}
}
globalThis.HTTP = HTTP; globalThis.HTTP = HTTP;
export { HTTP }; export { HTTP };

View File

@ -4,7 +4,7 @@
"use strict"; "use strict";
var _a, _b; var _a, _b;
const Util = { const Util = {
clone: globalThis.structuredClone || ((obj) => JSON.parse(JSON.stringify(obj))), clone: (obj) => JSON.parse(JSON.stringify(obj)),
base64: (str) => btoa(String.fromCharCode(...new TextEncoder().encode(str))), base64: (str) => btoa(String.fromCharCode(...new TextEncoder().encode(str))),
unbase64: (str) => new TextDecoder().decode(Uint8Array.from(atob(str), (c) => c.charCodeAt(0))), unbase64: (str) => new TextDecoder().decode(Uint8Array.from(atob(str), (c) => c.charCodeAt(0))),
urlbase64: (str) => Util.base64(str).replace(/[+/=]/g, (m) => ({ "+": "-", "/": "", "=": "" })[m]), urlbase64: (str) => Util.base64(str).replace(/[+/=]/g, (m) => ({ "+": "-", "/": "", "=": "" })[m]),