添加注册登录功能
This commit is contained in:
@@ -74,7 +74,9 @@
|
||||
data-subcategory="{{ template.sub_category }}">
|
||||
<input type="radio" name="template_id" id="template_{{ template.id }}"
|
||||
value="{{ template.id }}"
|
||||
{% if template.is_default %}checked{% endif %}>
|
||||
{% if selected_template_id and selected_template_id|int == template.id %}checked
|
||||
{% elif not selected_template_id and template.is_default %}checked
|
||||
{% elif not selected_template_id and loop.first %}checked{% endif %}>
|
||||
<label for="template_{{ template.id }}" class="template-content">
|
||||
<div class="template-actions">
|
||||
<button type="button" class="btn-delete"
|
||||
@@ -138,6 +140,10 @@
|
||||
<i class="fas fa-copy"></i>
|
||||
复制提示词
|
||||
</button>
|
||||
<button class="btn btn-favorite" onclick="addToFavorites()">
|
||||
<i class="fas fa-heart"></i>
|
||||
收藏
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="result-content">
|
||||
@@ -1024,6 +1030,33 @@ style.textContent = `
|
||||
.btn-copy i {
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.btn-favorite {
|
||||
padding: 8px 16px;
|
||||
background: #ff6b6b;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.btn-favorite:hover {
|
||||
background: #ff5252;
|
||||
}
|
||||
|
||||
.btn-favorite.btn-success {
|
||||
background: #4CAF50;
|
||||
}
|
||||
|
||||
.btn-favorite.btn-success:hover {
|
||||
background: #45a049;
|
||||
}
|
||||
|
||||
.btn-favorite i {
|
||||
margin-right: 6px;
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
|
||||
@@ -1231,5 +1264,84 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 页面加载时自动选择第一个模板(如果没有选中的模板)
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const selectedTemplate = document.querySelector('input[name="template_id"]:checked');
|
||||
if (!selectedTemplate) {
|
||||
const firstTemplate = document.querySelector('input[name="template_id"]');
|
||||
if (firstTemplate) {
|
||||
firstTemplate.checked = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 收藏功能
|
||||
function addToFavorites() {
|
||||
console.log('开始收藏流程...');
|
||||
|
||||
// 获取当前选中的模板ID
|
||||
const selectedTemplate = document.querySelector('input[name="template_id"]:checked');
|
||||
console.log('选中的模板:', selectedTemplate);
|
||||
if (!selectedTemplate) {
|
||||
alert('请先选择一个模板');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取用户输入的文本
|
||||
const userInput = document.querySelector('textarea[name="input_text"]');
|
||||
console.log('用户输入框:', userInput);
|
||||
console.log('用户输入内容:', userInput ? userInput.value : 'null');
|
||||
if (!userInput || !userInput.value.trim()) {
|
||||
alert('请先输入文本内容');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取生成的提示词
|
||||
const generatedText = document.querySelector('.text-content');
|
||||
console.log('生成的提示词元素:', generatedText);
|
||||
console.log('生成的提示词内容:', generatedText ? generatedText.textContent.substring(0, 100) + '...' : 'null');
|
||||
if (!generatedText || !generatedText.textContent.trim()) {
|
||||
alert('请先生成提示词');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取模板信息
|
||||
const templateCard = selectedTemplate.closest('.template-card');
|
||||
const category = templateCard.dataset.category;
|
||||
|
||||
const favoriteData = {
|
||||
template_id: parseInt(selectedTemplate.value),
|
||||
original_text: userInput.value.trim(),
|
||||
generated_prompt: generatedText.textContent.trim(),
|
||||
category: category
|
||||
};
|
||||
|
||||
// 发送收藏请求
|
||||
fetch('/api/favorites/quick-add', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(favoriteData)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert('收藏成功!');
|
||||
// 可以在这里更新按钮状态
|
||||
const favoriteBtn = document.querySelector('.btn-favorite');
|
||||
favoriteBtn.innerHTML = '<i class="fas fa-heart"></i> 已收藏';
|
||||
favoriteBtn.classList.add('btn-success');
|
||||
favoriteBtn.disabled = true;
|
||||
} else {
|
||||
alert(data.message || '收藏失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('收藏失败:', error);
|
||||
alert('收藏失败,请稍后重试');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user