公众号优化菜单链接

This commit is contained in:
2025-11-19 16:53:57 +08:00
parent a95652b458
commit ad35173301

View File

@@ -10,7 +10,8 @@
<title>新能源智能体</title> <title>新能源智能体</title>
<link rel="icon" href="./img/logo.png" type="image/x-icon"> <link rel="icon" href="./img/logo.png" type="image/x-icon">
<!-- <script src=" https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxopensdk.js"> --> <!-- <script src=" https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxopensdk.js"> -->
</script> <!-- </script> -->
<script src="./marked.min.js"></script>
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script> <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
@@ -987,6 +988,10 @@
} }
#sms-button {
padding: 12px;
}
.popbgc .loading-box { .popbgc .loading-box {
position: absolute; position: absolute;
top: 0px; top: 0px;
@@ -1347,7 +1352,7 @@
</div> </div>
<script src="./marked.min.js"></script>
<script> <script>
// 开启 vConsole 调试面板 // 开启 vConsole 调试面板
var vConsole = new VConsole(); var vConsole = new VConsole();
@@ -1360,6 +1365,7 @@
<script> <script>
window.addEventListener('load', () => {
const sidebar = document.getElementById("sidebar"); const sidebar = document.getElementById("sidebar");
const chatMessages = document.getElementById("chatMessages"); const chatMessages = document.getElementById("chatMessages");
const chatInput = document.getElementById("chatInput"); const chatInput = document.getElementById("chatInput");
@@ -1390,6 +1396,7 @@
// ✅ 先 URL 解码,再 Base64 解码,再 UTF-8 解码 // ✅ 先 URL 解码,再 Base64 解码,再 UTF-8 解码
let userId; let userId;
if (from == "weixin") { if (from == "weixin") {
@@ -1513,9 +1520,7 @@
}); });
}); });
} }
// }
function bindToLogin() { function bindToLogin() {
debugger;
document.querySelector('.popbox .loading-box').classList.remove('none'); document.querySelector('.popbox .loading-box').classList.remove('none');
const data = { const data = {
sourceType: 5, sourceType: 5,
@@ -1523,18 +1528,32 @@
phonenumber: document.getElementById('sys-phone').value, phonenumber: document.getElementById('sys-phone').value,
smsCode: document.getElementById('code').value smsCode: document.getElementById('code').value
} }
try { fetch("/api/remote/login", {
handleLogin(data).then(res => { method: "POST", // 必选:指定请求方法为 POST
headers: {
"Content-Type": "application/json", // 声明请求体是 JSON 格式
// 可选:如果接口需要 Token 前置验证,可添加 Authorization 头
// "Authorization": "Bearer 你的前置 Token"
},
// 必选:请求体,将参数对象转为 JSON 字符串(不能直接传对象)
body: JSON.stringify(data)
}).then(res => res.json()).then(res => {
if (res.code == 200) { if (res.code == 200) {
document.querySelector('.popbox .loading-box').classList.add('none') if (document.querySelector('.popbox .loading-box')) {
document.querySelector('.popbox .loading-box').classList.add('none');
}
userId = res.userId; userId = res.userId;
setCookie('token', res.token); setCookie('token', res.token);
unshowpop(); unshowpop();
getSessionList(); getSessionList();
} else { } else {
showToast(res.msg); showToast(res.msg + "denglucuowu");
document.querySelector('.popbox .loading-box').classList.remove('none'); setTimeout(() => {
window.location.reload();
}, 2000);
return;
} }
}).catch(err => { }).catch(err => {
@@ -1544,12 +1563,64 @@
}) })
.finally(() => { .finally(() => {
unshowpop(); unshowpop();
if (document.querySelector('.popbox .loading-box')) {
document.querySelector('.popbox .loading-box').classList.add('none'); document.querySelector('.popbox .loading-box').classList.add('none');
});
} catch (err) {
console.error("请求异常:", err);
} }
});
// try {
// handleLogin(data).then(res => {
// if (res.code == 200) {
// if (document.querySelector('.popbox .loading-box')) {
// document.querySelector('.popbox .loading-box').classList.add('none');
// }
// userId = res.userId;
// setCookie('token', res.token);
// unshowpop();
// getSessionList();
// } else {
// showToast(res.msg + "denglucuowu");
// window.location.reload();
// return;
// }
// }).catch(err => {
// // 捕获异步异常(如网络错误、接口报错、代码报错)
// console.error("请求异常:", err);
// showToast("登录失败,请重试" + err); // 给用户友好提示
// })
// .finally(() => {
// unshowpop();
// if (document.querySelector('.popbox .loading-box')) {
// document.querySelector('.popbox .loading-box').classList.add('none');
// }
// });
// } catch (err) {
// console.error("请求异常:", err);
// }
}
async function retryFetch(url, options, maxRetry = 10) {
let lastError;
for (let i = 0; i < maxRetry; i++) {
try {
console.log(`登录请求第 ${i + 1} 次尝试...`);
const response = await fetch(url, options);
return await response.json();
} catch (err) {
lastError = err;
console.warn(`第 ${i + 1} 次尝试失败:`, err);
// 最后一次重试失败 → 抛出错误
if (i === maxRetry - 1) throw err;
// 重试前延迟 300ms
await new Promise(res => setTimeout(res, 300));
}
}
throw lastError;
} }
function getUserByOpenId(id) { function getUserByOpenId(id) {
@@ -1560,38 +1631,84 @@
phonenumber: '', phonenumber: '',
smsCode: '', smsCode: '',
} }
try { retryFetch("https://ai.satabot.com/api/remote/login", {
handleLogin(data).then(res => { method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(res => {
if (res.code == 300) { if (res.code == 300) {
showpop();//出现验证码弹窗 showpop(); // 弹出验证码
} else if (res.code == 200) { } else if (res.code == 200) {
setCookie('token', res.token); setCookie('token', res.token);
userId = res.userId; userId = res.userId;
} }
}) })
// fetch("/api/getuserByopenid", { .catch(err => {
// method: "POST", console.error("登录请求失败(重试三次后):", err);
showToast("网络异常,请稍后再试");
})
.finally(() => {
console.log("登录请求结束");
});
// fetch("https://ai.satabot.com/api/remote/login", {
// method: "POST", // 必选:指定请求方法为 POST
// headers: { // headers: {
// "Content-Type": "application/json" // "Content-Type": "application/json", // 声明请求体是 JSON 格式
// // 可选:如果接口需要 Token 前置验证,可添加 Authorization 头
// // "Authorization": "Bearer 你的前置 Token"
// }, // },
// body: JSON.stringify({ // // 必选:请求体,将参数对象转为 JSON 字符串(不能直接传对象)
// userId: id, // body: JSON.stringify(data)
// }).then(res => res.json()).then(res => {
// if (res.code == 300) {
// showpop();//出现验证码弹窗
// } else if (res.code == 200) {
// setCookie('token', res.token);
// userId = res.userId;
// }
// }).catch(err => {
// console.error("请求失败:", err);
// showToast("网络异常,请稍后再试" + err);
// }) // })
// }).then(res => res.json()).then(data => { // .finally(() => {
// if (data.code == 0) { // console.log("登录请求结束");
// });
// try {
// handleLogin(data).then(res => {
// if (res.code == 300) {
// showpop();//出现验证码弹窗
// } else if (res.code == 200) {
// setCookie('token', res.token);
// userId = res.userId;
// userId = data.userId;
// sendParam.userId = userId;
// getSessionList();
// } else {
// console.error("未找到该用户:",);
// } // }
// }) // })
} catch (err) { // // fetch("/api/getuserByopenid", {
console.error("请求异常:", err); // // method: "POST",
} // // headers: {
// // "Content-Type": "application/json"
// // },
// // body: JSON.stringify({
// // userId: id,
// // })
// // }).then(res => res.json()).then(data => {
// // if (data.code == 0) {
// // userId = data.userId;
// // sendParam.userId = userId;
// // getSessionList();
// // } else {
// // console.error("未找到该用户:",);
// // }
// // })
// } catch (err) {
// console.error("请求异常:", err);
// }
} }
const questions = document.querySelectorAll(".question"); const questions = document.querySelectorAll(".question");
// 获取到用户名称 // 获取到用户名称
@@ -2129,43 +2246,72 @@
renderMessages([chat[0].messages], true); renderMessages([chat[0].messages], true);
renderChatList('new'); renderChatList('new');
} }
let countTimer;
function getSms() { function getSms() {
document.getElementById('send-code').textContent = "60s";
let remainSeconds = 60; let remainSeconds = 60;
let countTimer = setInterval(() => {
countTimer = setInterval(() => {
if (remainSeconds > 0) { if (remainSeconds > 0) {
remainSeconds--; remainSeconds--;
document.getElementById('send-code').textContent = `${remainSeconds}s`; document.getElementById('send-code').textContent = `${remainSeconds}s`;
document.getElementById('send-code').disabled = true; document.getElementById('send-code').disabled = true;
} else { } else {
clearInterval(countTimer); clearInterval(countTimer);
countTimer = null;
document.getElementById('send-code').textContent = "获取验证码"; document.getElementById('send-code').textContent = "获取验证码";
document.getElementById('send-code').disabled = false; document.getElementById('send-code').disabled = false;
} }
}, 1000) }, 1000)
const phonenumber = document.getElementById('sys-phone').value; const phonenumber = document.getElementById('sys-phone').value;
handleBind(phonenumber).then(res => { const bindParams = {
phoneNumbers: num,
}
fetch("/api/remote/external/sms/sendAliSmsCode", {
method: "POST", // 必选:指定请求方法为 POST
headers: {
"Content-Type": "application/json", // 声明请求体是 JSON 格式
// 可选:如果接口需要 Token 前置验证,可添加 Authorization 头
// "Authorization": "Bearer 你的前置 Token"
},
// 必选:请求体,将参数对象转为 JSON 字符串(不能直接传对象)
body: JSON.stringify(bindParams)
}).then(res => res.json()).then(res => {
if (res.code == 200) { if (res.code == 200) {
} else { } else {
showToast(res.msg); showToast(res.msg + "yanzssahnegma");
clearInterval(countTimer); clearInterval(countTimer);
countTimer = null;
document.getElementById('send-code').textContent = "获取验证码"; document.getElementById('send-code').textContent = "获取验证码";
document.getElementById('send-code').disabled = false; document.getElementById('send-code').disabled = false;
return; return;
} }
console.log(res); console.log(res);
}).catch(err => { }).catch(err => {
showToast(err); showToast(err + "yanzhnegma");
clearInterval(countTimer); clearInterval(countTimer);
countTimer = null;
document.getElementById('send-code').textContent = "获取验证码"; document.getElementById('send-code').textContent = "获取验证码";
document.getElementById('send-code').disabled = false; document.getElementById('send-code').disabled = false;
return; return;
}) })
// handleBind(phonenumber).then(res => {
// }).catch(err => {
// showToast(err + "yanzhnegma");
// clearInterval(countTimer);
// countTimer = null;
// document.getElementById('send-code').textContent = "获取验证码";
// document.getElementById('send-code').disabled = false;
// return;
// })
} }
function unshowpop() { function unshowpop() {
if (countTimer) {
clearInterval(countTimer); clearInterval(countTimer);
}
const popbox = document.querySelector('.popbox'); const popbox = document.querySelector('.popbox');
if (popbox) { if (popbox) {
popbox.remove(); popbox.remove();
@@ -2446,6 +2592,10 @@
} }
} }
}); });
});
</script> </script>
<script> <script>