mirror of
https://github.com/KingHWJ/WeReadBoard.git
synced 2026-11-03 18:24:58 +08:00
feat(reading-goals): 持久化阅读目标并收紧看板布局
This commit is contained in:
1 parent
61d3951905
commit
094e1aca3d
13 files changed
+834
-39
No files matched your search
+22
-2
@@ -10,12 +10,16 @@
|
||||
|
||||
const BASE = '/api/v2';
|
||||
|
||||
async function request(path, params) {
|
||||
async function request(path, params, method = 'GET', body) {
|
||||
const url = new URL(BASE + path, global.location.origin);
|
||||
Object.entries(params || {}).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') url.searchParams.set(key, value);
|
||||
});
|
||||
const response = await fetch(url.toString(), { headers: { Accept: 'application/json' } });
|
||||
const response = await fetch(url.toString(), {
|
||||
method,
|
||||
headers: { Accept: 'application/json', ...(body ? { 'Content-Type': 'application/json' } : {}) },
|
||||
...(body ? { body: JSON.stringify(body) } : {}),
|
||||
});
|
||||
let payload = null;
|
||||
try {
|
||||
payload = await response.json();
|
||||
@@ -56,6 +60,22 @@
|
||||
return request('/status');
|
||||
},
|
||||
|
||||
goals() {
|
||||
return request('/goals');
|
||||
},
|
||||
|
||||
saveGoal(goal, editing = false) {
|
||||
return request(editing ? `/goals/${encodeURIComponent(goal.id)}` : '/goals', null, editing ? 'PUT' : 'POST', goal);
|
||||
},
|
||||
|
||||
deleteGoal(id) {
|
||||
return request(`/goals/${encodeURIComponent(id)}`, null, 'DELETE');
|
||||
},
|
||||
|
||||
importGoals(goals) {
|
||||
return request('/goals/import', null, 'POST', { goals });
|
||||
},
|
||||
|
||||
/**
|
||||
* 书架数据
|
||||
* @param {string} tab all|reading|done|wish
|
||||
|
||||
Reference in new issue
Block a user