删除全部 Node.js 后端、.mjs 测试、辅助脚本、package*.json、node_modules 和迁移对照工具。 浏览器前端保留并迁入 [Eis.Web/wwwroot](C:/Users/BI/Documents/EIS-dotnet/src/Eis.Web/wwwroot/index.html),统一改为 .js 模块。 修复一个隐藏遗漏:.NET 仍依赖 schema.mjs,且 MySQL 结构解析可能被转义反引号截断。现已改为原生 [SQLite SQL](C:/Users/BI/Documents/EIS-dotnet/src/Eis.Infrastructure/Data/Schema.sqlite.sql) 和 [MySQL SQL](C:/Users/BI/Documents/EIS-dotnet/src/Eis.Infrastructure/Data/Schema.mysql.sql) 资源。 更新了 [DatabaseInitializer.cs](C:/Users/BI/Documents/EIS-dotnet/src/Eis.Infrastructure/Data/DatabaseInitializer.cs)、项目配置、README 和迁移文档。 data 目录和现有数据库未修改;测试仅使用系统临时 SQLite 数据库。
35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
const pendingReads = new Map();
|
|
|
|
async function request(path, options) {
|
|
const binaryBody = options.body instanceof ArrayBuffer || options.body instanceof Blob || options.body instanceof FormData;
|
|
const response = await fetch(path, {
|
|
credentials: 'same-origin',
|
|
headers: { ...(options.body && !binaryBody ? { 'Content-Type': 'application/json' } : {}), ...options.headers },
|
|
...options,
|
|
body: options.body && typeof options.body !== 'string' && !binaryBody ? JSON.stringify(options.body) : options.body
|
|
});
|
|
const type = response.headers.get('content-type') || '';
|
|
const data = type.includes('application/json') ? await response.json() : await response.text();
|
|
if (!response.ok) {
|
|
const error = new Error(data?.message || '操作未完成,请稍后重试');
|
|
error.status = response.status;
|
|
throw error;
|
|
}
|
|
return data;
|
|
}
|
|
|
|
export function api(path, options = {}) {
|
|
const method = String(options.method || 'GET').toUpperCase();
|
|
if (method !== 'GET' || options.body != null || options.signal) return request(path, options);
|
|
|
|
// A quick double click or repeated render must not download and parse the
|
|
// same large JSON response more than once while the first request is active.
|
|
const key = String(path);
|
|
if (pendingReads.has(key)) return pendingReads.get(key);
|
|
const loading = request(path, options).finally(() => {
|
|
if (pendingReads.get(key) === loading) pendingReads.delete(key);
|
|
});
|
|
pendingReads.set(key, loading);
|
|
return loading;
|
|
}
|