This commit is contained in:
2025-08-21 09:34:51 +08:00
parent ddd01f813b
commit 7b97fda4be
6 changed files with 555 additions and 7 deletions

View File

@@ -144,6 +144,188 @@
margin-bottom: 10px;
}
</style>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
body {
background-color: #f5f7fa;
color: #333;
line-height: 1.6;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 30px;
}
h1 {
text-align: center;
margin-bottom: 20px;
color: #2c3e50;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #555;
}
input[type="text"], textarea {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 16px;
transition: border 0.3s;
}
input[type="text"]:focus, textarea:focus {
border-color: #3498db;
outline: none;
}
.required::after {
content: ' *';
color: red;
}
.tag-container {
display: flex;
flex-wrap: wrap;
margin-top: 10px;
padding: 10px;
border: 1px dashed #ccc;
border-radius: 6px;
min-height: 50px;
}
.tag {
background-color: #3498db;
color: white;
padding: 5px 10px;
border-radius: 20px;
margin-right: 10px;
margin-bottom: 10px;
display: flex;
align-items: center;
}
.tag span {
margin-right: 5px;
}
.tag button {
background: none;
border: none;
color: white;
cursor: pointer;
font-size: 14px;
}
.add-tag {
display: flex;
margin-top: 10px;
}
.add-tag input {
flex: 1;
margin-right: 10px;
}
.btn {
padding: 12px 20px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
transition: background 0.3s;
}
.btn-primary {
background-color: #3498db;
color: white;
}
.btn-primary:hover {
background-color: #2980b9;
}
.btn-secondary {
background-color: #95a5a6;
color: white;
margin-left: 10px;
}
.btn-secondary:hover {
background-color: #7f8c8d;
}
.btn-group {
display: flex;
justify-content: center;
margin-top: 30px;
}
.placeholder {
color: #999;
font-style: italic;
}
.example-tip {
background-color: #f8f9fa;
padding: 15px;
border-radius: 6px;
margin-top: 5px;
font-size: 14px;
color: #666;
}
.sample-container {
margin-top: 10px;
padding: 15px;
background-color: #f8f9fa;
border-radius: 6px;
border-left: 4px solid #3498db;
}
.sample-title {
font-weight: bold;
margin-bottom: 10px;
}
/* 添加遮罩动画样式 */
.mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s, visibility 0.3s;
}
.mask.active {
opacity: 1;
visibility: visible;
}
.loader {
width: 50px;
height: 50px;
border: 5px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: #3498db;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.mask-text {
color: white;
margin-top: 20px;
text-align: center;
font-size: 18px;
}
.mask-content {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
</head>
<body>
<div class="container">
@@ -191,7 +373,7 @@
<div class="form-group">
<label for="atmosphere" class="required">氛围-情绪</label>
<input type="text" id="atmosphere" placeholder="例如:温" required>
<input type="text" id="atmosphere" placeholder="例如:温" required>
<div class="example-tip">请描述画面想要传达的整体氛围或情绪</div>
</div>
@@ -369,7 +551,6 @@
const creationMethod = document.querySelector('input[name="creationMethod"]:checked').value;
if (creationMethod === 'prompt') {
// 原有的提示词生成逻辑
// 收集表单数据
const formData = {
timeWeatherLight: document.getElementById('timeWeatherLight').value,
@@ -391,11 +572,10 @@
}
prompt += `,氛围${formData.atmosphere}`;
// 在实际应用中,这里应该发送数据到后端
console.log('生成的提示词:', prompt);
alert('提示词已生成:\n' + prompt + '\n\n下一步将生成首帧图片');
// 调用 API 生成图片
generateImage(prompt);
} else {
// 新增的图片上传逻辑
// 图片上传逻辑
if (imageUpload.files.length === 0) {
alert('请先选择要上传的图片');
return;
@@ -403,10 +583,55 @@
const file = imageUpload.files[0];
console.log('上传的图片:', file.name);
alert('图片上传\n' + file.name + '\n\n下一步将使用此图片作为首帧');
// 这里应该实现图片上传逻辑
alert('图片上传功能尚未实现');
}
});
// 新增函数:调用 API 生成图片
function generateImage(prompt) {
// 显示遮罩动画
mask.classList.add('active');
maskText.textContent = '正在生成图片,请稍候...';
console.log('生成的提示词:', prompt);
// 发送请求到后端 API
fetch('/api/jimeng/prompt_input', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ prompt: prompt })
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应异常');
}
return response.json();
})
.then(data => {
// 隐藏遮罩动画
mask.classList.remove('active');
if (data.code === 200) {
// 保存图片 URL 和提示词并跳转到预览页面
sessionStorage.setItem('generatedImageUrl', data.data.image_url);
sessionStorage.setItem('lastPrompt', prompt);
window.location.href = 'image_preview.html';
} else {
alert('图片生成失败: ' + data.message);
}
})
.catch(error => {
// 隐藏遮罩动画
mask.classList.remove('active');
console.error('生成图片时出错:', error);
alert('生成图片时出错: ' + error.message);
});
}
// 表单重置事件
promptForm.addEventListener('reset', function() {
// 清空标签
@@ -423,4 +648,81 @@
});
</script>
</body>
</html>
<!-- 添加遮罩层 -->
<div class="mask" id="mask">
<div class="mask-content">
<div class="loader"></div>
<div class="mask-text" id="maskText">正在生成图片,请稍候...</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// ... existing code ...
const mask = document.getElementById('mask');
const maskText = document.getElementById('maskText');
// ... existing code ...
// 新增函数:调用 API 生成图片
function generateImage(prompt) {
// 显示遮罩动画
mask.classList.add('active');
maskText.textContent = '正在生成图片,请稍候...';
console.log('生成的提示词:', prompt);
// 发送请求到后端 API
fetch('/api/jimeng/prompt_input', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ prompt: prompt })
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应异常');
}
return response.json();
})
.then(data => {
// 隐藏遮罩动画
mask.classList.remove('active');
if (data.code === 200) {
// 保存图片 URL 并跳转到预览页面
sessionStorage.setItem('generatedImageUrl', data.data.image_url);
window.location.href = 'image_preview.html';
} else {
alert('图片生成失败: ' + data.message);
}
})
.catch(error => {
// 恢复按钮状态
submitBtn.disabled = false;
submitBtn.textContent = '确认并继续';
console.error('生成图片时出错:', error);
alert('生成图片时出错: ' + error.message);
});
}
// 表单重置事件
promptForm.addEventListener('reset', function() {
// 清空标签
while (tagContainer.firstChild) {
tagContainer.removeChild(tagContainer.firstChild);
}
tagContainer.appendChild(placeholder);
checkTagContainer();
sampleContainer.style.display = 'none';
});
// 初始化检查
checkTagContainer();
});
</script>
</body>
</html>