模型上传管理和绑定构件,构建树形

This commit is contained in:
cjh
2026-06-10 17:02:45 +08:00
parent 3ac2fe48dd
commit 965bb309db
27 changed files with 2476 additions and 94 deletions

View File

@@ -5,13 +5,62 @@ const MOCK_DELAY = 300;
const mock = (data, delay = MOCK_DELAY) =>
new Promise((resolve) => setTimeout(() => resolve(data), delay));
function parseJsonPreserveLongIds(text) {
if (!text) return null;
let result = "";
let inString = false;
let escaped = false;
for (let i = 0; i < text.length; i += 1) {
const char = text[i];
if (inString) {
result += char;
if (escaped) {
escaped = false;
} else if (char === "\\") {
escaped = true;
} else if (char === "\"") {
inString = false;
}
continue;
}
if (char === "\"") {
inString = true;
result += char;
continue;
}
const startsNumber = char === "-" || (char >= "0" && char <= "9");
if (!startsNumber) {
result += char;
continue;
}
const start = i;
if (char === "-") i += 1;
while (i < text.length && text[i] >= "0" && text[i] <= "9") i += 1;
const numberText = text.slice(start, i);
const nextChar = text[i];
const isInteger = nextChar !== "." && nextChar !== "e" && nextChar !== "E";
const digitCount = numberText.startsWith("-") ? numberText.length - 1 : numberText.length;
result += isInteger && digitCount >= 16 ? `"${numberText}"` : numberText;
i -= 1;
}
return JSON.parse(result);
}
export const fetchApi = async (url, options = {}) => {
const fullUrl = url.startsWith("http") ? url : BASE_URL + url;
const token = localStorage.getItem("token");
const isFormData = options.body instanceof FormData;
const config = {
headers: {
"Content-Type": "application/json",
...(isFormData ? {} : { "Content-Type": "application/json" }),
...(token ? { Authorization: `Bearer ${token}` } : {}),
...options.headers,
},
@@ -20,7 +69,8 @@ export const fetchApi = async (url, options = {}) => {
try {
const res = await fetch(fullUrl, config);
const data = await res.json();
const raw = await res.text();
const data = parseJsonPreserveLongIds(raw);
if (!res.ok) {
throw new Error(data.message || `请求失败: ${res.status}`);
}
@@ -45,6 +95,13 @@ export const post = (url, data, options = {}) =>
body: JSON.stringify(data),
});
export const postForm = (url, formData, options = {}) =>
fetchApi(url, {
...options,
method: "POST",
body: formData,
});
export const put = (url, data, options = {}) =>
fetchApi(url, {
...options,
@@ -58,4 +115,4 @@ export const del = (url, data, options = {}) => {
return fetchApi(url, config);
};
export { mock };
export { mock };