修复提示上传图片的逻辑
This commit is contained in:
56
index.html
56
index.html
@@ -5,7 +5,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>新能源智能体</title>
|
||||
<link rel="icon" href="./img/logo.png" type="image/x-icon">
|
||||
<link rel="icon" href="./img/logo.png" type="image/x-icon">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
@@ -17,6 +17,25 @@
|
||||
|
||||
}
|
||||
|
||||
.toast {
|
||||
position: fixed;
|
||||
top: 20%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
color: #fff;
|
||||
padding: 10px 18px;
|
||||
border-radius: 8px;
|
||||
font-size: 15px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* 侧边栏 */
|
||||
.sidebar {
|
||||
width: 240px;
|
||||
@@ -728,6 +747,7 @@
|
||||
const chatList = document.getElementById("chatList");
|
||||
let sessIdList = [];
|
||||
let isUpload = {};
|
||||
let hasImage = false;
|
||||
let isPre = false;//是否点击了预设问题
|
||||
// let sessIdList = JSON.parse(localStorage.getItem("sessId")) || [];
|
||||
let sessId;
|
||||
@@ -761,11 +781,15 @@
|
||||
isPre = true;
|
||||
console.log(isUpload, 88)
|
||||
if (!sendParam.imageBase64 && !fileInput.files.length) {
|
||||
if (!isUpload[activeChatId]) {
|
||||
alert("请先上传图片");
|
||||
// if (!isUpload[activeChatId]) {
|
||||
if (!hasImage) {
|
||||
showToast("请先上传图片");
|
||||
// alert("请先上传图片");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
const value = q.getAttribute("data-value");
|
||||
const preValue = q.getAttribute("data-pre-value");
|
||||
@@ -824,6 +848,24 @@
|
||||
console.error("请求异常:", err);
|
||||
}
|
||||
}
|
||||
function showToast(message) {
|
||||
// 创建元素
|
||||
const toast = document.createElement("div");
|
||||
toast.className = "toast";
|
||||
toast.innerText = message;
|
||||
document.body.appendChild(toast);
|
||||
|
||||
// 显示
|
||||
setTimeout(() => {
|
||||
toast.classList.add("show");
|
||||
}, 10);
|
||||
|
||||
// 2 秒后自动消失
|
||||
setTimeout(() => {
|
||||
toast.classList.remove("show");
|
||||
setTimeout(() => toast.remove(), 300); // 动画结束后移除
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
|
||||
function toggleSidebar() {
|
||||
@@ -879,7 +921,10 @@
|
||||
return;
|
||||
}
|
||||
data.forEach(msg => {
|
||||
addMessage(msg.content, msg.role, msg.image_base64, msg.created_at);
|
||||
if (msg.image_base64) {
|
||||
hasImage = true; // 只要有一个不为空,就置为 true
|
||||
}
|
||||
addMessage(msg.content, msg.role, msg.image_base64);
|
||||
});
|
||||
}
|
||||
// 内容 角色 图片 创造时间
|
||||
@@ -935,6 +980,7 @@
|
||||
let imgUrl = '';
|
||||
if (sendParam.imageBase64) {
|
||||
imgUrl = sendParam.imageBase64;
|
||||
hasImage = true;
|
||||
if (fileInput.files[0]) {
|
||||
const file = fileInput.files[0];
|
||||
const url = URL.createObjectURL(file);
|
||||
@@ -1033,7 +1079,7 @@
|
||||
const chat = [{
|
||||
id,
|
||||
title: "新对话 " + (sessIdList.length),
|
||||
messages: { role: "assistant", content: "👋 新会话已创建,请输入问题。", }
|
||||
messages: { role: "assistant", content: "👋 新会话已创建,请输入问题。", image_base64: '' }
|
||||
}];
|
||||
activeChatId = id;
|
||||
ifSessionId = true;
|
||||
|
||||
Reference in New Issue
Block a user