公众号前级页面逻辑完成
This commit is contained in:
281
index.html
281
index.html
@@ -620,6 +620,13 @@
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.userinfo-wrapper img {
|
||||
max-width: 20px;
|
||||
max-height: 20px;
|
||||
margin-right: 4px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.chat-container .content {
|
||||
overflow-y: auto;
|
||||
scrollbar-width: none;
|
||||
@@ -627,7 +634,7 @@
|
||||
|
||||
/* 按钮样式 */
|
||||
.userinfo-toggle {
|
||||
padding: 7px 2px;
|
||||
padding: 4px 2px;
|
||||
border-radius: 9px;
|
||||
border: none;
|
||||
background: #0057ff;
|
||||
@@ -1169,7 +1176,11 @@
|
||||
|
||||
<!-- 左侧侧边栏 -->
|
||||
<div class="sidebar" id="sidebar">
|
||||
<button class="toggle-btn" id="toggleBtn" onclick="toggleSidebar()">☰</button>
|
||||
<button class="toggle-btn" id="toggleBtn" onclick="toggleSidebar()"><svg t="1764295127411" class="icon"
|
||||
viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="19121" width="32" height="32">
|
||||
<path d="M118.279 336.402h754.531v68.618h-754.531v-68.618z" p-id="19122"></path>
|
||||
<path d="M118.279 647.52h754.531v68.618h-754.531v-68.618z" p-id="19123"></path>
|
||||
</svg></button>
|
||||
<div class="sidebar-header"><img src="./img/logo.png">会话列表</div>
|
||||
<div class="sidebar-actions">
|
||||
<button onclick="newChat()">+ 新建会话</button>
|
||||
@@ -1220,17 +1231,17 @@
|
||||
</div>
|
||||
<div class="userinfo">
|
||||
<span class="username"></span>
|
||||
<span class="logout" onClick="logout()">退出</span>
|
||||
<span class="logout " onClick="logout()">退出</span>
|
||||
<a class="logout price" href="./modal.html">服务价格</a>
|
||||
</div>
|
||||
<div class="userinfo-wrapper">
|
||||
<img src="" alt="">
|
||||
<!-- 初始按钮 -->
|
||||
<button class="userinfo-toggle username" onclick="toggleUserInfo()">用户</button>
|
||||
|
||||
<!-- 折叠面板 -->
|
||||
<div class="userinfo-panel">
|
||||
<!-- <span class="username">用户名</span> -->
|
||||
<span class="logout" onclick="logout()">退出</span>
|
||||
<span class="logout logout1" onclick="logout()">退出</span>
|
||||
<a class="logout price" href="./modal.html">服务价格</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1408,59 +1419,33 @@
|
||||
let sessId;
|
||||
let activeChatId = '';
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
console.log(params.get("userId"), 644);
|
||||
console.log(params.get("userId"), 644, params.get("nickname"), params.get("headingimg"));
|
||||
|
||||
const encodedUserId = params.get("userId");
|
||||
const from = params.get("from");
|
||||
const code = params.get("code");
|
||||
|
||||
|
||||
|
||||
function handleCode(code) {
|
||||
if (code) {
|
||||
console.log(code, "code");
|
||||
retryFetch(`https://servicestream.satabot.com/api/wechat/access_token?code=${code}`)
|
||||
|
||||
.then(res => {
|
||||
console.log(res.nickname)
|
||||
document.querySelectorAll('.username').forEach((e) => {
|
||||
e.textContent = res.nickname;
|
||||
})
|
||||
openId = res.openid;
|
||||
userId = res.openid;
|
||||
getUserByOpenId(userId)
|
||||
|
||||
});
|
||||
} else {
|
||||
return; // ✅ 没问题,直接退出函数
|
||||
}
|
||||
}
|
||||
const appid = "wx364b8ebf17fe45fe";
|
||||
// 回调地址(必须和公众号后台配置的网页授权域名一致)
|
||||
const redirect_uri = encodeURIComponent("http://ai.satabot.com");
|
||||
// 授权方式:snsapi_base(静默) 或 snsapi_userinfo(需要用户确认)
|
||||
const scope = "snsapi_userinfo";
|
||||
// 自定义参数,授权后会原样返回
|
||||
const state = "12399";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ✅ 先 URL 解码,再 Base64 解码,再 UTF-8 解码
|
||||
let userId;
|
||||
if (from == "weixin") {
|
||||
userId = encodedUserId;
|
||||
openId = encodedUserId;
|
||||
setCookie('openId', openId)
|
||||
document.querySelectorAll('.logout').forEach(el => {
|
||||
if (params.get("nickname")) {
|
||||
console.log(1)
|
||||
|
||||
document.querySelectorAll('.logout1').forEach(el => {
|
||||
el.style.display = 'none';
|
||||
});
|
||||
console.log(3)
|
||||
document.querySelectorAll('.username').forEach((e) => {
|
||||
e.textContent = params.get("nickname");
|
||||
})
|
||||
|
||||
document.querySelector(".userinfo-wrapper img").src = params.get("headingimg");
|
||||
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
||||
console.log(4)
|
||||
|
||||
} else {
|
||||
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
||||
}
|
||||
// 微信授权的码
|
||||
handleCode(code);
|
||||
if (userId && userId != "NaN") {
|
||||
setCookie("userId", userId);
|
||||
}
|
||||
@@ -1477,7 +1462,6 @@
|
||||
if (isMobile()) {
|
||||
toggleSidebar();
|
||||
}
|
||||
console.log(isWeChat(), 999, code)
|
||||
// if (isWeChat()) {
|
||||
// if (code) {
|
||||
// // gotoWeiXin();
|
||||
@@ -1496,29 +1480,8 @@
|
||||
// }
|
||||
|
||||
// } else {
|
||||
if (getCookie("userId") && getCookie("userId") != "NaN" && !code) {
|
||||
getSessionList();
|
||||
|
||||
if (from == "weixin") {
|
||||
getUserByOpenId(userId)
|
||||
} else {
|
||||
getSessionList();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// deleteCookie('userId');
|
||||
|
||||
if (from == "weixin") {
|
||||
|
||||
} else {
|
||||
// getUserName(userId);
|
||||
getSessionList();
|
||||
// window.location.href = 'http://ri.satabot.com/index.html#/login?goRemote=1&clear=1';
|
||||
|
||||
// window.location.href = 'http://ri.satabot.com/#/login?goRemote=1&clear=1';
|
||||
}
|
||||
|
||||
}
|
||||
function handleLogin(data) {
|
||||
console.log("开始登录")
|
||||
const loginParams = data;
|
||||
@@ -1695,143 +1658,42 @@
|
||||
throw lastError;
|
||||
}
|
||||
|
||||
function getUserByOpenId(id) {
|
||||
if (document.querySelector(".weixin-loading").classList.contains("none")) {
|
||||
document.querySelector(".weixin-loading").classList.remove("none");
|
||||
}
|
||||
const data = {
|
||||
sourceType: 5,
|
||||
openId: id,
|
||||
|
||||
phonenumber: '',
|
||||
smsCode: '',
|
||||
}
|
||||
retryFetch("https://serviceri.satabot.com/login", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(res => {
|
||||
if (res.code == 300) {
|
||||
showpop(); // 弹出验证码
|
||||
} else if (res.code == 200) {
|
||||
setCookie('token', res.token);
|
||||
userId = res.userId;
|
||||
getSessionList();
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("登录请求失败(重试10次后):", err);
|
||||
showToast("网络异常,请稍后再试");
|
||||
})
|
||||
.finally(() => {
|
||||
if (!document.querySelector(".weixin-loading").classList.contains("none")) {
|
||||
document.querySelector(".weixin-loading").classList.add("none");
|
||||
}
|
||||
console.log("登录请求结束");
|
||||
});
|
||||
// fetch("https://ai.satabot.com/api/remote/login", {
|
||||
// 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 == 300) {
|
||||
// showpop();//出现验证码弹窗
|
||||
// } else if (res.code == 200) {
|
||||
// setCookie('token', res.token);
|
||||
// userId = res.userId;
|
||||
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// console.error("请求失败:", err);
|
||||
// showToast("网络异常,请稍后再试" + err);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// console.log("登录请求结束");
|
||||
// });
|
||||
// try {
|
||||
// handleLogin(data).then(res => {
|
||||
// if (res.code == 300) {
|
||||
// showpop();//出现验证码弹窗
|
||||
// } else if (res.code == 200) {
|
||||
// setCookie('token', res.token);
|
||||
// userId = res.userId;
|
||||
|
||||
// }
|
||||
// })
|
||||
// retryFetch("https://serviceai.satabot.com/getuserByopenid", {
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// "Content-Type": "application/json"
|
||||
// },
|
||||
// body: JSON.stringify({
|
||||
// userId: id,
|
||||
|
||||
// })
|
||||
// }).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");
|
||||
// 获取到用户名称
|
||||
function getUserName(userId) {
|
||||
if (code) return;
|
||||
if (from == "weixin") {
|
||||
document.querySelectorAll('.username').forEach((e) => {
|
||||
e.textContent = userId;
|
||||
})
|
||||
} else {
|
||||
try {
|
||||
fetch("https://serviceai.satabot.com/user", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
userId,
|
||||
if (params.get("nickname")) return;
|
||||
try {
|
||||
fetch("https://serviceai.satabot.com/user", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
userId,
|
||||
|
||||
})
|
||||
}).then(res => res.json()).then(data => {
|
||||
if (data.code === 0) {
|
||||
document.querySelectorAll('.username').forEach((e) => {
|
||||
e.textContent = data.userName;
|
||||
})
|
||||
|
||||
console.log("成功找到该用户:", data.userName, data.userId);
|
||||
|
||||
} else {
|
||||
window.location.href = data.error;
|
||||
return;
|
||||
console.error("未找到该用户:",);
|
||||
}
|
||||
})
|
||||
}).then(res => res.json()).then(data => {
|
||||
if (data.code === 0) {
|
||||
document.querySelectorAll('.username').forEach((e) => {
|
||||
e.textContent = data.userName;
|
||||
})
|
||||
|
||||
console.log("成功找到该用户:", data.userName, data.userId);
|
||||
|
||||
} else {
|
||||
window.location.href = data.error;
|
||||
return;
|
||||
console.error("未找到该用户:",);
|
||||
}
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
console.error("请求异常:", err);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("请求异常:", err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
questions.forEach(q => {
|
||||
|
||||
q.addEventListener("click", () => {
|
||||
@@ -2296,11 +2158,8 @@
|
||||
sessId = sendParam.sessionId;
|
||||
sendParam.imageBase64 = img;
|
||||
// sendParam.userId= encodedUserId;
|
||||
if (from != "weixin" && !code) {
|
||||
sendParam.userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
||||
} else {
|
||||
sendParam.userId = userId;
|
||||
}
|
||||
sendParam.userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
||||
|
||||
|
||||
// ✅ 创建 AbortController
|
||||
controller = new AbortController();
|
||||
@@ -2390,6 +2249,32 @@
|
||||
sendBtnImg.classList.remove('none');
|
||||
stopBtn.classList.add('none');
|
||||
msgDiv.innerHTML = marked.parse(aiMsg.content);
|
||||
const shareSpan = document.createElement("span");
|
||||
shareSpan.style.display = "inline-flex";
|
||||
shareSpan.style.alignItems = "center";
|
||||
shareSpan.style.cursor = "pointer";
|
||||
shareSpan.style.marginTop = "8px";
|
||||
shareSpan.style.opacity = "0.75";
|
||||
shareSpan.style.transition = "opacity .2s";
|
||||
shareSpan.title = "分享";
|
||||
|
||||
shareSpan.onmouseenter = () => shareSpan.style.opacity = "1";
|
||||
shareSpan.onmouseleave = () => shareSpan.style.opacity = "0.75";
|
||||
|
||||
shareSpan.innerHTML = `
|
||||
<svg t="1764059839985" class="icon" viewBox="0 0 1236 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5667" width="20" height="20"><path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z" p-id="5668"></path></svg>
|
||||
`;
|
||||
|
||||
shareSpan.onclick = () => {
|
||||
generatePoster(aiMsg.content);
|
||||
};
|
||||
setTimeout(() => {
|
||||
msgDiv.appendChild(shareSpan);
|
||||
}, 1000)
|
||||
|
||||
|
||||
console.log("shareSpan appended?", msgDiv.contains(shareSpan));
|
||||
|
||||
|
||||
|
||||
setTimeout(scrollToBottom, 0); // chatMessages.scrollTop = chatMessages.scrollHeight;
|
||||
|
||||
Reference in New Issue
Block a user