feat: 编辑收藏时支持更改类型,动态显示对应字段
This commit is contained in:
@@ -432,7 +432,12 @@ INDEX_TEMPLATE = '''
|
||||
<input type="hidden" id="editId">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">类型</label>
|
||||
<input type="text" id="editType" class="form-control" readonly>
|
||||
<select id="editType" class="form-select">
|
||||
<option value="text">📝 文本</option>
|
||||
<option value="link">🔗 链接</option>
|
||||
<option value="column">📰 专栏</option>
|
||||
<option value="todo">✅ 待办</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">标题</label>
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user