commit remaining frontend updates

This commit is contained in:
lizhilun
2026-07-01 16:15:23 +08:00
parent e69930799c
commit 77cd66a854
6 changed files with 82 additions and 10 deletions
+34
View File
@@ -20,6 +20,40 @@ async function doLogin() {
}
}
async function doRegister() {
const user = document.getElementById('registerUser').value.trim();
const pass = document.getElementById('registerPass').value.trim();
const passConfirm = document.getElementById('registerPassConfirm').value.trim();
if (!user || !pass) { document.getElementById('registerError').textContent = '请输入用户名和密码'; return; }
if (pass !== passConfirm) { document.getElementById('registerError').textContent = '两次密码输入不一致'; return; }
try {
const res = await fetch(API + '/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: user, password: pass })
});
const data = await res.json();
if (!res.ok) { document.getElementById('registerError').textContent = data.error; return; }
showToast('注册成功,请登录');
showLoginPage();
} catch (e) {
document.getElementById('registerError').textContent = '网络错误';
}
}
function showRegisterPage() {
document.getElementById('registerError').textContent = '';
document.getElementById('registerUser').value = '';
document.getElementById('registerPass').value = '';
document.getElementById('registerPassConfirm').value = '';
showPage('registerPage');
}
function showLoginPage() {
document.getElementById('loginError').textContent = '';
showPage('loginPage');
}
function doLogout() {
token = null;
username = null;
+2 -3
View File
@@ -135,9 +135,8 @@ async function saveEditRecord() {
if (time) body.created_at = new Date(time).toISOString();
try {
const res = await fetch(API + '/api/records/' + id, {
const res = await apiFetch(API + '/api/records/' + id, {
method: 'PUT',
headers: headers(),
body: JSON.stringify(body)
});
if (!res.ok) { showToast('保存失败'); return; }
@@ -152,7 +151,7 @@ async function deleteEditRecord() {
const id = document.getElementById('editId').value;
if (!confirm('确定删除这条记录?')) return;
try {
const res = await fetch(API + '/api/records/' + id, { method: 'DELETE', headers: headers() });
const res = await apiFetch(API + '/api/records/' + id, { method: 'DELETE' });
if (!res.ok) { showToast('删除失败'); return; }
showToast('已删除');
closeEditModal();
+3 -3
View File
@@ -11,7 +11,7 @@ async function doExport(format) {
closeExportModal();
showToast('正在导出...');
try {
const res = await fetch(API + '/api/export?format=' + format, { headers: headers() });
const res = await apiFetch(API + '/api/export?format=' + format);
if (!res.ok) {
const err = await res.json();
showToast(err.error || '导出失败');
@@ -88,9 +88,9 @@ async function confirmImport() {
if (!pendingImportContent) return;
showToast('正在导入...');
try {
const res = await fetch(API + '/api/import', {
const res = await apiFetch(API + '/api/import', {
method: 'POST',
headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Authorization': 'Bearer ' + token },
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
body: pendingImportContent
});
const data = await res.json();
+1 -2
View File
@@ -159,9 +159,8 @@ async function submitRecord() {
}
try {
const res = await fetch(API + '/api/records', {
const res = await apiFetch(API + '/api/records', {
method: 'POST',
headers: headers(),
body: JSON.stringify(body)
});
if (!res.ok) { showToast('保存失败'); return; }