部分重型模块的原子化拆解

This commit is contained in:
2026-07-23 20:46:16 +08:00
parent 2afff129b9
commit 5fa1b99c5d
12 changed files with 1688 additions and 875 deletions
+26
View File
@@ -0,0 +1,26 @@
// modules/api.js
const API_BASE = '/api';
export function getToken() {
return localStorage.getItem('frpc_token') || '';
}
export function getHeaders() {
return {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + getToken(),
};
}
export async function apiFetch(endpoint, options = {}) {
const url = API_BASE + endpoint;
const headers = options.body instanceof FormData
? { 'Authorization': 'Bearer ' + getToken() }
: getHeaders();
const res = await fetch(url, {
...options,
headers: { ...headers, ...(options.headers || {}) },
});
return res.json();
}