From ffe7adcad2f26df643e84b63b452d964d485c806 Mon Sep 17 00:00:00 2001
From: hubian <908234780@qq.com>
Date: Mon, 13 Apr 2026 16:45:48 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=96=E8=BE=91=E6=94=B6=E8=97=8F?=
=?UTF-8?q?=E6=97=B6=E6=94=AF=E6=8C=81=E6=9B=B4=E6=94=B9=E7=B1=BB=E5=9E=8B?=
=?UTF-8?q?=EF=BC=8C=E5=8A=A8=E6=80=81=E6=98=BE=E7=A4=BA=E5=AF=B9=E5=BA=94?=
=?UTF-8?q?=E5=AD=97=E6=AE=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
xian_favor/api.py | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/xian_favor/api.py b/xian_favor/api.py
index facaf55..536e3a7 100644
--- a/xian_favor/api.py
+++ b/xian_favor/api.py
@@ -432,7 +432,12 @@ INDEX_TEMPLATE = '''
-
+
@@ -555,6 +560,11 @@ document.addEventListener('DOMContentLoaded', async () => {
document.getElementById('todoFields').style.display = type === 'todo' ? 'block' : 'none';
});
+ // 编辑时类型切换
+ document.getElementById('editType').addEventListener('change', (e) => {
+ updateEditFieldsByType(e.target.value);
+ });
+
// 搜索
document.getElementById('searchInput').addEventListener('input', debounce(loadItems, 300));
@@ -815,14 +825,11 @@ async function openEditModal(id) {
const type = item.type;
document.getElementById('editId').value = id;
- document.getElementById('editType').value = getTypeLabel(type);
+ document.getElementById('editType').value = type;
document.getElementById('editTitle').value = item.title || '';
// 根据类型显示/隐藏字段
- document.getElementById('editContentGroup').style.display = type === 'text' ? 'block' : 'none';
- document.getElementById('editUrlGroup').style.display = ['link', 'column'].includes(type) ? 'block' : 'none';
- document.getElementById('editSourceGroup').style.display = type === 'column' ? 'block' : 'none';
- document.getElementById('editTodoFields').style.display = type === 'todo' ? 'block' : 'none';
+ updateEditFieldsByType(type);
document.getElementById('editContent').value = item.content || '';
document.getElementById('editUrl').value = item.url || '';
@@ -839,16 +846,21 @@ async function openEditModal(id) {
new bootstrap.Modal(document.getElementById('editModal')).show();
}
+// 根据类型更新编辑表单字段显示
+function updateEditFieldsByType(type) {
+ document.getElementById('editContentGroup').style.display = type === 'text' ? 'block' : 'none';
+ document.getElementById('editUrlGroup').style.display = ['link', 'column'].includes(type) ? 'block' : 'none';
+ document.getElementById('editSourceGroup').style.display = type === 'column' ? 'block' : 'none';
+ document.getElementById('editTodoFields').style.display = type === 'todo' ? 'block' : 'none';
+}
+
// 保存编辑
async function saveEdit() {
const id = document.getElementById('editId').value;
-
- // 获取当前条目的类型
- const detailRes = await fetch(`${API_BASE}/items/${currentDetailId}`);
- const detailData = await detailRes.json();
- const type = detailData.data.type;
+ const type = document.getElementById('editType').value; // 从下拉框获取新类型
const data = {
+ type: type, // 包含类型变更
title: document.getElementById('editTitle').value,
content: type === 'text' ? document.getElementById('editContent').value : null,
url: ['link', 'column'].includes(type) ? document.getElementById('editUrl').value : null,