diff --git a/index.html b/index.html index b2a0439..35bceb3 100755 --- a/index.html +++ b/index.html @@ -1886,6 +1886,18 @@ let token = params.get("token");//app的token let localtoken = params.get("localtoken");//公众号的localtoken + function clearOldRootDomainCookies() { + const names = ['Admin-Token', 'token', 'userId', 'username', 'nickname', 'headimgurl', 'headingimg']; + const parts = location.hostname.split('.'); + const rootDomain = parts.length >= 2 ? '.' + parts.slice(-2).join('.') : ''; + if (!rootDomain || rootDomain === '.') return; + names.forEach(name => { + document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=' + rootDomain + ';'; + }); + console.log('[cookie] 已清除旧 root-domain cookie:', rootDomain); + } + clearOldRootDomainCookies(); + // app会得到token; // 手机端会验证token @@ -2133,6 +2145,7 @@ console.error("请求异常:", err); } } + questions.forEach(q => { @@ -2214,6 +2227,8 @@ function logout() { deleteCookie('userId'); deleteCookie('token'); + deleteCookie('nickname'); + deleteCookie('headimgurl'); deleteCookie("sharetoken", "ai.satabot.com") // 清空历史记录(黑科技) history.pushState(null, null, location.href); diff --git a/login.html b/login.html index 4425b76..074dd2d 100644 --- a/login.html +++ b/login.html @@ -1,639 +1,633 @@ - - - - - - - 新能源智能体 - - - + @media (max-width: 1200px) { + .main { + transform: scale(0.92); + } + .switch { + width: 42%; + } + .container { + width: 58%; + } + } + @media (max-width: 1000px) { + .main { + transform: scale(0.85); + } + } + @media (max-width: 800px) { + body { + padding: 0; + } + .main { + transform: scale(1); + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + width: 100%; + border-radius:0; + box-shadow: none; + } + .a-container { + position: absolute; + z-index: 100; + left: 50%; + transform: translateX(-50%); + width:100%; + } + .switch { + display: none; + } + .tab { + width: 100%; + } + } + @media (max-width: 600px) { + .main { + transform: scale(1); + width:100%; + height:100vh; + border-radius:0; + } + .a-container { + width: 100%; + left: 50%; + transform: translateX(-50%); + } + .form-panel{ + width:90%; + } + #weixin_container{ + width:260px; + height:260px; + } + .switch { + display: none; + } + } + - -
-
-
-
-
密码登录
-
微信登录
-
+ +
+ + - - - + if (!agree) { + showToast('请阅读并同意用户协议!'); + return; + } + const username = document.getElementById('username').value.trim(); + const password = document.getElementById('password').value; + const rememberMe = document.getElementById('rememberMe').checked; + const btn = document.getElementById('loginBtn'); + if (!username) { showToast('请输入账号'); return; } + if (!password) { showToast('请输入密码'); return; } + if (rememberMe) { + setCookie('username', username, 30); + setCookie('password', password, 30); + setCookie('rememberMe', true, 30); + } else { + removeCookie('username'); + removeCookie('password'); + removeCookie('rememberMe'); + } + btn.disabled = true; + btn.innerText = '登录中...'; + fetch('https://serviceri.satabot.com/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username, password, sourceType: 1 }) + }) + .then(r => r.json()) + .then(data => { + + if (data && data.code === 200 && data.userId) { + const rawUserId = String(data.userId); + const encodedUserId = btoa(unescape(encodeURIComponent(rawUserId))); + setCookie('token', data.token || ('t_' + Date.now()), 7); + setCookie('userId', rawUserId, 7); + //if (data.username) setCookie('nickname', data.username, 7); + setTimeout(() => { + window.location.href = './index.html?userId=' + encodedUserId; + }, 100); + } else { + showToast((data && data.msg) || '账号或密码错误'); + btn.disabled = false; + btn.innerText = '登录'; + } + }) + .catch(() => { + showToast('登录请求失败,请稍后重试'); + btn.disabled = false; + btn.innerText = '登录'; + }); + } + let wxInited = false; + function initWxLogin() { + if (wxInited) return; + if (typeof window.WxLogin !== 'function') { + setTimeout(initWxLogin, 100); + return; + } + try { + new window.WxLogin({ + id: 'weixin_container', + appid: WECHAT_APPID, + scope: 'snsapi_login', + redirect_uri: WECHAT_REDIRECT_URI, + state: 'ai' + }); + wxInited = true; + } catch (e) { + console.error('WxLogin init error:', e); + } + } + history.pushState(null, null, location.href); + window.addEventListener('popstate', () => { + history.pushState(null, null, location.href); + }); + if (getCookie('token') && getCookie('userId')) { + const rawUserId = getCookie('userId'); + const encodedUserId = btoa(unescape(encodeURIComponent(rawUserId))); + window.location.href = './index.html?userId=' + encodedUserId; + } + - diff --git a/server2.js b/server2.js index 6f85cf1..af1b890 100755 --- a/server2.js +++ b/server2.js @@ -765,7 +765,7 @@ app.post("/user", async (req, res) => { if (rows.length === 0) { res.json({ code: 300, - error: "http://ri.satabot.com/#/login?goRemote=1", + error: "https://ai.satabot.com/login.html", msg: "未找到该用户" }); return;