diff --git a/index.html b/index.html index 7b3dc86..b2a0439 100755 --- a/index.html +++ b/index.html @@ -2,1610 +2,1611 @@ - - - - - - - - + + + + + + + + - 飒沓光伏智能体 - - - - + 飒沓光伏智能体 + + + + - - - + + 100% { + background-color: #ccc; + } + } + -
-
+
+
-
-
+
+
- - + - + - -
-
- +
+
+ -
- 新能源智能体satabot -
+ 新能源智能体satabot +
-
-
-
+
+
+
-
+
-
-
-
分析这个场站
-
详细的割草计划
-
详细的清洗计划
-
详细的巡检计划
+
+
+
分析这个场站
+
详细的割草计划
+
+ 详细的清洗计划
+
详细的巡检计划
-
-
-
-
- - - - - - -
+
+
+
+
+ + + + + + +
-
+
- -
+ +
-
- + - - - - - - -
-
- - - - - -
- - - -
+ + + + + + +
+
+ + + + + +
+ + + +
-
-
+
+
-
-
-
-
-
分析这个场站
-
详细的割草计划
+
+
+
+
+
分析这个场站
+
详细的割草计划
-
详细的清洗计划
-
详细的巡检计划
+
+ 详细的清洗计划
+
详细的巡检计划
-
-
-
-
- - - - - - -
+
+
+
+
+ + + + + + +
-
-
- -
+
+
+ +
-
- + - - - - - - + + + + + + -
-
- - - - - +
+
+ + + + + -
- - - -
+
+ + + +
-
-
-
+
+
+
-
-
-
-
+
+ + +
- + + +
+ - + - - + - - - + document.body.insertAdjacentHTML('beforeend', html); + } + + function switchChat(id) { + activeChatId = id; + sendParam.sessionId = id; + const items = document.querySelectorAll(".chat-item"); + items.forEach(item => { + if (item.dataset.sessionid === id) { + item.classList.add("active"); + } else { + item.classList.remove("active"); + } + }); + + getHistory(); + // renderChatList(); + + } + const deleteSession = (sessionId, userId) => { + if (activeChatId == sessionId) { + if (controller) { + controller.abort(); + controller = null; + if (sendBtnImg.classList.contains('none')) { + sendBtnImg.classList.remove('none'); + stopBtn.forEach(e => { + e.classList.add('none') + + }) + } + } + } + try { + fetch(`https://serviceai.satabot.com/session?sessionId=${sessionId}&userId=${userId}`, { + method: "DELETE" + }).then(res => res.json()).then(data => { + if (data.code === 0) { + getSessionList(); + renderChatList(); + + console.log("删除成功:", data.message); + } else { + console.error("删除失败:", data.error); + } + }) + + + } catch (err) { + console.error("请求异常:", err); + } + } + + + function deleteChat(id) { + // sessIdList = sessIdList.filter(item => item !== id); + // localStorage.setItem("sessId", JSON.stringify(sessIdList)); + deleteSession(id, sendParam.userId) + + } + + + function handleSendFile() { + console.log("选择文件"); + // 触发隐藏的 input 点击 + if (isMobile()) { + document.getElementById("fileInput1").click(); + } else { + document.getElementById("fileInput").click(); + + } + + } + + // 监听文件选择 + document.getElementById("fileInput").addEventListener("change", function (e) { + const file = e.target.files[0]; + if (file) { + console.log("选择的文件:", file.name); + // 这里可以直接上传 + uploadFile(file); + } + }); + document.getElementById("fileInput1").addEventListener("change", function (e) { + const file = e.target.files[0]; + if (file) { + console.log("选择的文件:", file.name); + // 这里可以直接上传 + uploadFile(file); + } + }); + + // 示例上传函数(fetch 到后端接口) + function uploadFile(file) { + + if (file) { + + const reader = new FileReader(); + reader.readAsDataURL(file); + + reader.onload = async function () { + + sendParam.imageBase64 = reader.result; + document.querySelectorAll(".img-row").forEach(e => { + e.classList.remove("none"); + }) + const imgs = document.querySelectorAll(".img-row img"); + imgs.forEach(img => { + img.src = sendParam.imageBase64; + }); + isUpload[activeChatId] = true; + if (document.querySelector('.mobilesendbtn').classList.contains('none')) { + document.querySelector('.mobilesendbtn').classList.remove('none') + } + + } + // document.getElementById("rawImg").src = URL.createObjectURL(file); + } + } + function deleteImg() { + document.querySelectorAll(".img-row").forEach(e => { + e.classList.add("none"); + }) + sendParam.imageBase64 = ''; + const imgs = document.querySelectorAll(".img-row img"); + imgs.forEach(img => { + img.src = ''; + }); + } + + chatInput.addEventListener("keydown", function (e) { + if (e.key === "Enter" && !e.shiftKey) { // 按下回车且未按Shift + e.preventDefault(); // 阻止换行 + sendMessage(); // 调用发送函数 + } + }); + chatInput.addEventListener("input", function () { + if (chatInput.value.trim() !== "") { + document.querySelector(".mobilesendbtn").classList.remove('none') + } else { + document.querySelector(".mobilesendbtn").classList.add('none') + + } + }); + document.querySelector(".sendMsgImg").addEventListener("click", function () { + sendMessage(); + }); + document.querySelector(".sendMsgImg1").addEventListener("click", function () { + sendMessage(); + }); + + + document.querySelectorAll(".sendfileimg").forEach(el => { + el.addEventListener("click", function () { + handleSendFile(); + }); + }); + // getHistory(); + // renderChatList("new"); + + // sendParam.sessionId = "7906661519458367"; + // 调用获取历史记录的接口 + function getHistory() { + // sendParam.userId = encodedUserId; + fetch(`https://serviceai.satabot.com/history?sessionId=${sendParam.sessionId}`, { + // fetch(`http://1.95.137.212:30008/history?sessionId=${sendParam.sessionId}`, { + method: "GET", + // headers: { "Content-Type": "application/json" }, + // credentials: 'include', // 发送 cookie + // body: JSON.stringify(sendParam), + }).then(res => res.json()).then(data => { + if (!weixinloading.classList.contains("none")) { + weixinloading.classList.add("none"); + } + // chats = data.messages; + // renderChatList(); + if (controller) return; + renderMessages(data.messages) + + }) + } + // sessIdList + + + function isWeChat() { + return /MicroMessenger/i.test(navigator.userAgent); + } + // function getCookie(name) { + // const value = `; ${document.cookie}`; + // const parts = value.split(`; ${name}=`); + // if (parts.length === 2) return parts.pop().split(';').shift(); + // return null; + // } + // gotoWeiXin(); + function gotoWeiXin() { + console.log(isWeChat(), 8888, navigator.userAgent); + + const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`; + // 拼接完整的授权链接 + // const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`; + // 跳转到微信授权 + console.log("跳转链接:", authUrl); + window.location.href = authUrl; + + } + // loginWithWeChat(); + // function loginWithWeChat() { + // const appId = "wx364b8ebf17fe45fe"; + // const appSecret = "9b7476020991a2c71f1416da7f011d31"; + // const redirectUri = encodeURIComponent("https://www.example.com/wechat/callback"); + // const state = "login_state"; + // const scope = "snsapi_userinfo"; + + // const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&secret=${appSecret}&redirect_uri=${redirectUri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`; + + // window.location.href = url; // 跳转到微信授权页面 + // } + // simulateWechatLogin() + + + // 触发登录时执行:跳转微信授权页 + function simulateWechatLogin() { + const APP_ID = 'wx0eeb7556d60121db'; + const REDIRECT_URI = encodeURIComponent("https://www.satabot.com"); + const STATE = Math.random().toString(36).substring(2, 12); + const SCOPE = 'snsapi_base'; + // const authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx807d86fb6b3d4fd2&redirect_uri=http%3A%2F%2Fdevelopers.weixin.qq.com&response_type=code&scope=snsapi_userinfo&state=STATE&forcePopup=true#wechat_redirect"; + const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=${SCOPE}&state=${STATE}&forcePopup=true#wechat_redirect`; + // window.location.href = authUrl; // 跳转后页面刷新,后续代码不执行 + } + + // if(from=="weixin"){ + // gotoWeiXin(); + // }else{ + + // } + // if (!isWeChat()) { + + + // } else { + // gotoWeiXin(); + // } + + // let isSuccess = false; + // function getSessionList() { + // console.log(userId, "huoqu") + + // sendParam.userId = userId; + // fetch(`/api/sessions?userId=${sendParam.userId}`, { + // // fetch(`http://1.95.137.212:30008/history?sessionId=${sendParam.sessionId}`, { + // method: "GET", + // // headers: { "Content-Type": "application/json" }, + // // credentials: 'include', // 发送 cookie + // // body: JSON.stringify(sendParam), + // }).then(res => res.json()).then(data => { + // debugger; + // console.log(data, 8777, data.code) + + // if (data.code == 300) { + // if (!isSuccess) { + // window.location.href = data.error; + // isSuccess = true; + // } else { + // window.location.href = "https://ai.satabot.com/404.html"; + // return; + // } + // // window.location.href='http://localhost/#/login?goRemote=1 ' + + // return; + // } else { + // sessIdList = data.sessions; + // renderChatList(); + // console.log(data, 8777) + // } + + // // chats = data.messages; + // // renderChatList(); + // // renderMessages(data.messages) + + // }) + // } + + function getSessionList() { + + + sendParam.userId = userId; + fetch(`https://serviceai.satabot.com/sessions?userId=${sendParam.userId}`, { + method: "GET", + // 确保 credentials 正确设置,以便传递 Cookie + // credentials: 'include', + }) + .then(res => { + // debugger; + // 首先检查 HTTP 响应状态码 + if (res.status === 401) { + // 401 表示未授权,用户需要登录 + // 从后端响应头中获取登录页地址(后端需设置 Location 头) + const loginUrl = res.headers.get('Location') || '/login'; // 降级默认地址 + window.location.href = loginUrl; // 跳转到后端指定的登录页 + return Promise.reject('用户未授权'); + } + else if (!res.ok) { + // 处理其他 HTTP 错误,如 404, 500 等 + console.error('请求失败,状态码:', res.status); + // 可以在这里统一跳转到 404 页面 + // window.location.href = "https://ai.satabot.com/404.html"; + return Promise.reject(`HTTP error! status: ${res.status}`); + } + + // 如果状态码是 200 OK,则继续解析 JSON + return res.json(); + }) + .then(data => { + // 请求成功,渲染页面 + console.log('获取会话列表成功'); + sessIdList = data.sessions; + + renderChatList(); + }) + .catch(error => { + // 捕获网络错误或我们手动抛出的错误 + console.error('获取会话列表时发生错误:', error); + // 这里可以不做任何事,因为特定的错误已经被处理了 + }); + } + + function toggleSidebar() { + sidebar.classList.toggle("collapsed"); + + const toggleBtn = document.getElementById("toggleBtn"); + + if (sidebar.classList.contains("collapsed")) { + toggleBtn.style.left = "10px"; // 收起后 + } else { + toggleBtn.style.left = "10px"; // 收起后 + } + } + document.getElementById("stopBtn").addEventListener("click", () => { + document.querySelectorAll('.thinking-loading').forEach(el => el.classList.add('no-after')); + console.log(controller, '暂停消息'); + + isStopped = true; + + if (reader) { + reader.cancel("stop"); + reader = null; + } + + if (controller) { + controller.abort(); + controller = null; + } + + + if (sendBtnImg.classList.contains('none')) { + sendBtnImg.classList.remove('none'); + stopBtn.forEach(e => { + e.classList.add('none') + + }) + } + + fetch("https://serviceai.satabot.com/stop", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(sendParam), + + }); + + }); + document.getElementById("stopBtn1").addEventListener("click", () => { + document.querySelectorAll('.thinking-loading').forEach(el => el.classList.add('no-after')); + + console.log(controller, '暂停消息'); + isStopped = true; + + if (reader) { + reader.cancel("stop"); + reader = null; + } + + if (controller) { + controller.abort(); + controller = null; + } + + if (sendBtnImg.classList.contains('none')) { + sendBtnImg.classList.remove('none'); + stopBtn.forEach(e => { + e.classList.add('none') + + }) + } + fetch("https://serviceai.satabot.com/stop", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(sendParam), + + }); + }); + // DOM 加载完成后执行 + console.log('DOM Ready'); + // }); + + + + + + diff --git a/login.html b/login.html new file mode 100644 index 0000000..4ed8241 --- /dev/null +++ b/login.html @@ -0,0 +1,638 @@ + + + + + + + + + + 新能源智能体 + + + + + + +
+
+
+
+
密码登录
+
微信登录
+
+ +
+
+
账号
+
+ + + + + +
+
+ +
+
密码
+
+ + + + + + + + + +
+
+ + + + + +
+ + 我已阅读并同意 + 《用户服务协议》、 + 《隐私政策》 +
+
+ +
+
+

请使用微信扫描二维码登录

+
+
+ +
+
+
+
+ logo +
+
新能源智能体
+
sataBotAgent
+
+
+
+
+
+
+ +
+ + + + + diff --git a/logintest.vue b/logintest.vue new file mode 100644 index 0000000..b1cfe0c --- /dev/null +++ b/logintest.vue @@ -0,0 +1,1807 @@ + + + + +