save code

This commit is contained in:
xsl
2025-10-04 17:14:04 +08:00
parent 1fbb91eadb
commit 71ec26c7de
2 changed files with 51 additions and 16 deletions
+40 -8
View File
@@ -96,17 +96,25 @@
<input type="file" id="clothInput" accept="image/*">
<img id="clothPreview" class="image-preview" alt="衣服图片预览">
</div>
<br>
<div class="image-upload-box">
<h3>裤子图片</h3>
<input type="file" id="kuziInput" accept="image/*">
<img id="kuziPreview" class="image-preview" alt="裤子图片预览">
</div>
<br>
<div class="option-box">
<label>
<input type="checkbox" id="no2Checkbox"> 设置 no2 不要两步(一步完成)
</label>
<br>
<label>
<input type="checkbox" id="tuodiCheckbox"> 设置 tuodi(拖地)
</label>
<label>
<br>
<!-- <label>
<input type="checkbox" id="kuziCheckbox"> 设置 kuzi(裤子)
</label>
</label> -->
</div>
</div>
@@ -146,14 +154,28 @@
reader.readAsDataURL(file);
}
});
document.getElementById('kuziInput').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
const img = document.getElementById('kuziPreview');
img.src = event.target.result;
img.style.display = 'block';
};
reader.readAsDataURL(file);
}
});
// 提交处理
document.getElementById('submitBtn').addEventListener('click', function() {
const humanFile = document.getElementById('humanInput').files[0];
const clothFile = document.getElementById('clothInput').files[0];
const kuziFile = document.getElementById('kuziInput').files[0];
const no2 = document.getElementById("no2Checkbox").checked;
const tuodi = document.getElementById("tuodiCheckbox").checked;
const kuzi = document.getElementById("kuziCheckbox").checked;
if (!humanFile || !clothFile) {
alert('请同时选择人体图片和衣服图片!');
@@ -167,17 +189,25 @@
// 读取图片并转换为Base64(包含完整前缀)
Promise.all([
readFileAsDataURL(humanFile),
readFileAsDataURL(clothFile)
]).then(([humanDataURL, clothDataURL]) => {
readFileAsDataURL(clothFile),
kuziFile ? readFileAsDataURL(kuziFile) : Promise.resolve(null)
]).then(([humanDataURL, clothDataURL, kuziDataURL]) => {
// 准备请求数据
const data = {
human_img: humanDataURL, // 包含完整前缀的Base64
cloth_img: clothDataURL, // 包含完整前缀的Base64
output_format: "url",
no2: no2,
tuodi:tuodi,
kuzi:kuzi
tuodi:tuodi
};
if(kuziDataURL)
{
data.kuzi_img = kuziDataURL;
}
console.log("准备发送的数据:", data); // 调试用
@@ -209,6 +239,8 @@
<p><img src="${data.url}" style="max-width: 100%; margin-top: 10px;"></p>
<a href="${data.first_url}" target="_blank">${data.url}</a>
<p><img src="${data.first_url}" style="max-width: 100%; margin-top: 10px;"></p>
<a href="${data.second_url}" target="_blank">${data.url}</a>
<p><img src="${data.second_url}" style="max-width: 100%; margin-top: 10px;"></p>
`;
} else {
resultDiv.innerHTML = `