| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <title>外发明细登录</title>
- <style>
- * { box-sizing: border-box; }
- html, body { margin: 0; height: 100%; width: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f0f2f5; }
- body { display: flex; flex-direction: column; min-height: 100vh; }
- .login-shell {
- flex: 1 1 auto;
- width: 100%;
- min-height: 0;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 24px 16px 52px;
- box-sizing: border-box;
- }
- .page { width: 100%; max-width: 420px; margin: 0; padding: 0; flex: 0 0 auto; }
- .logo-area { text-align: center; margin-bottom: 18px; }
- .logo-area h1 { font-size: 1.2rem; color: #333; margin: 0; font-weight: 600; }
- .login-tabs {
- display: flex;
- margin-bottom: 14px;
- border-radius: 10px;
- overflow: hidden;
- border: 1px solid #ddd;
- background: #fff;
- }
- .login-tabs button {
- flex: 1;
- padding: 12px 8px;
- border: none;
- background: #f5f5f5;
- color: #666;
- font-size: 15px;
- cursor: pointer;
- }
- .login-tabs button.active {
- background: #3c8dbc;
- color: #fff;
- font-weight: 600;
- }
- .panel { display: none; }
- .panel.active { display: block; }
- .card { background: #fff; border-radius: 12px; padding: 22px 18px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
- .field { margin-bottom: 16px; }
- .field label { display: block; font-size: 0.85rem; color: #555; margin-bottom: 6px; }
- .field input { width: 100%; padding: 12px 14px; border: 1px solid #ddd; border-radius: 8px; font-size: 16px; }
- .field input:focus { outline: none; border-color: #3c8dbc; }
- .row-code { display: flex; gap: 10px; align-items: center; }
- .row-code input { flex: 1; min-width: 0; }
- .row-captcha img {
- flex-shrink: 0;
- width: 110px;
- height: 40px;
- border-radius: 8px;
- border: 1px solid #ddd;
- cursor: pointer;
- display: block;
- background: #f5f5f5;
- }
- .btn-code { flex-shrink: 0; padding: 0 14px; border: 1px solid #3c8dbc; background: #fff; color: #3c8dbc; border-radius: 8px; font-size: 14px; white-space: nowrap; min-width: 108px; height: 44px; }
- .btn-code:disabled { opacity: .55; border-color: #ccc; color: #999; }
- .btn-submit { width: 100%; padding: 14px; border: none; border-radius: 8px; background: #3c8dbc; color: #fff; font-size: 16px; font-weight: 600; margin-top: 8px; }
- .btn-submit:active { opacity: .9; }
- .btn-submit.busy { opacity: .75; cursor: wait; }
- .tip { font-size: 12px; color: #999; margin-top: 12px; line-height: 1.5; }
- .footer { position: fixed; bottom: 0; left: 0; right: 0; text-align: center; padding: 10px; font-size: 12px; color: #999; background: #f0f2f5; }
- /* 页内提示(替代 alert) */
- .login-toast {
- position: fixed;
- left: 50%;
- /* 抬高:避开页脚版权区,大致落在登录按钮下方附近 */
- bottom: calc(max(120px, min(32vh, 240px)) + env(safe-area-inset-bottom, 0px));
- transform: translate3d(-50%, 16px, 0);
- max-width: min(92vw, 360px);
- padding: 12px 18px;
- border-radius: 10px;
- font-size: 14px;
- line-height: 1.5;
- text-align: center;
- box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
- z-index: 10000;
- opacity: 0;
- visibility: hidden;
- pointer-events: none;
- transition: opacity .25s ease, transform .25s ease, visibility .25s;
- }
- .login-toast.show {
- opacity: 1;
- visibility: visible;
- transform: translate3d(-50%, 0, 0);
- }
- .login-toast.err {
- background: #c0392b;
- color: #fff;
- }
- .login-toast.info {
- background: rgba(60, 141, 188, .96);
- color: #fff;
- }
- .login-toast.ok {
- background: #27ae60;
- color: #fff;
- }
- </style>
- </head>
- <body>
- <div class="login-shell">
- <div class="page">
- <div class="logo-area">
- <h1>登录</h1>
- </div>
- <div class="login-tabs" role="tablist">
- <button type="button" class="active" data-tab="account">账号密码</button>
- <button type="button" data-tab="phone">手机号登录</button>
- </div>
- <div class="card">
- <div id="panel-account" class="panel active">
- <div class="field">
- <label for="username">账号</label>
- <input type="text" id="username" name="username" maxlength="11" placeholder="登录账号(手机号)" autocomplete="username">
- </div>
- <div class="field">
- <label for="password">密码</label>
- <input type="password" id="password" name="password" placeholder="密码" autocomplete="current-password">
- </div>
- <button type="button" class="btn-submit" id="btn-login-pwd">登 录</button>
- </div>
- <div id="panel-phone" class="panel">
- <div class="field">
- <label for="phone">手机号</label>
- <input type="tel" id="phone" name="phone" maxlength="11" placeholder="请输入11位手机号" autocomplete="tel">
- </div>
- <div class="field">
- <label for="captcha">图形验证码</label>
- <div class="row-code row-captcha">
- <input type="text" id="captcha" name="captcha" maxlength="6" placeholder="请输入图形验证码" autocomplete="off">
- <img id="img-captcha" src="{$mprocCaptchaUrl|default=''|htmlentities}" width="110" height="40" alt="图形验证码" title="点击刷新">
- </div>
- </div>
- <div class="field">
- <label for="code">短信验证码</label>
- <div class="row-code">
- <input type="text" id="code" name="code" maxlength="6" inputmode="numeric" placeholder="6位验证码" autocomplete="one-time-code">
- <button type="button" class="btn-code" id="btn-send">获取验证码</button>
- </div>
- </div>
- <button type="button" class="btn-submit" id="btn-login">登 录</button>
- </div>
- </div>
- </div>
- </div>
- <div id="login-toast" class="login-toast err" role="status" aria-live="polite" aria-atomic="true" hidden></div>
- <script>
- (function () {
- var sendUrl = "{:url('index/index/sendSms')}";
- var loginUrl = "{:url('index/index/doLogin')}";
- var loginPwdUrl = "{:url('index/index/doLoginPwd')}";
- var indexUrl = "{:url('index/index/index')}";
- var restoreUrl = "{:url('index/index/mprocRestore')}";
- var captchaBaseUrl = {:json_encode(isset($mprocCaptchaUrl) ? $mprocCaptchaUrl : url('index/index/captcha'), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)};
- var loginRedirect = {:json_encode(isset($mprocLoginRedirect) ? $mprocLoginRedirect : '', JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)};
- var $tabs = document.querySelectorAll('.login-tabs button');
- var $panelPhone = document.getElementById('panel-phone');
- var $panelAccount = document.getElementById('panel-account');
- var $phone = document.getElementById('phone');
- var $captcha = document.getElementById('captcha');
- var $imgCaptcha = document.getElementById('img-captcha');
- var $code = document.getElementById('code');
- var $username = document.getElementById('username');
- var $password = document.getElementById('password');
- var $btnSend = document.getElementById('btn-send');
- var $btnLogin = document.getElementById('btn-login');
- var $btnLoginPwd = document.getElementById('btn-login-pwd');
- var cd = 0;
- var timer = null;
- var $toast = document.getElementById('login-toast');
- var toastHideTimer = null;
- /** 页内轻提示,替代 alert */
- function showToast(msg, kind) {
- kind = (kind === 'ok' || kind === 'info') ? kind : 'err';
- if (!$toast) {
- return;
- }
- if (toastHideTimer) {
- clearTimeout(toastHideTimer);
- toastHideTimer = null;
- }
- $toast.textContent = msg || '';
- $toast.className = 'login-toast ' + kind;
- $toast.removeAttribute('hidden');
- requestAnimationFrame(function () {
- $toast.classList.add('show');
- });
- toastHideTimer = setTimeout(function () {
- $toast.classList.remove('show');
- toastHideTimer = setTimeout(function () {
- $toast.setAttribute('hidden', 'hidden');
- $toast.textContent = '';
- }, 280);
- }, 3200);
- }
- function postForm(url, data, timeoutMs) {
- timeoutMs = timeoutMs || 0;
- var body = [];
- for (var k in data) {
- if (Object.prototype.hasOwnProperty.call(data, k)) {
- body.push(encodeURIComponent(k) + '=' + encodeURIComponent(data[k]));
- }
- }
- var opts = {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- 'X-Requested-With': 'XMLHttpRequest'
- },
- body: body.join('&'),
- credentials: 'same-origin'
- };
- var tid = null;
- if (timeoutMs > 0 && typeof AbortController !== 'undefined') {
- var ctrl = new AbortController();
- opts.signal = ctrl.signal;
- tid = setTimeout(function () {
- try { ctrl.abort(); } catch (e1) {}
- }, timeoutMs);
- }
- return fetch(url, opts).then(function (r) {
- if (tid) {
- clearTimeout(tid);
- tid = null;
- }
- return r.json();
- }).catch(function (e) {
- if (tid) {
- clearTimeout(tid);
- tid = null;
- }
- throw e;
- });
- }
- /** 提交中:立刻改文案,避免用户以为没点到 */
- function setSubmitBusy(btn, busy, busyText) {
- if (!btn) return;
- if (!Object.prototype.hasOwnProperty.call(btn.dataset, 'idleText')) {
- btn.dataset.idleText = (btn.textContent || '').trim();
- }
- btn.disabled = !!busy;
- btn.classList.toggle('busy', !!busy);
- btn.textContent = busy ? (busyText || '请稍候…') : btn.dataset.idleText;
- }
- function mprocExtractFocusEidFromRedirect(redir) {
- if (!redir) {
- return 0;
- }
- var fe = 0;
- try {
- var s = String(redir);
- var qIdx = s.indexOf('?');
- if (qIdx >= 0) {
- fe = parseInt(new URLSearchParams(s.substring(qIdx + 1)).get('focus_eid'), 10) || 0;
- }
- if (fe <= 0) {
- var m = s.match(/(?:[?&;]|%26)(?:amp;)*focus_eid=(\d+)/i);
- if (m) {
- fe = parseInt(m[1], 10) || 0;
- }
- }
- } catch (ignoreParse) {
- fe = 0;
- }
- if (fe <= 0) {
- try {
- fe = parseInt(sessionStorage.getItem('mproc_focus_eid'), 10) || 0;
- } catch (ignoreSs) {
- fe = 0;
- }
- }
- return fe;
- }
- function mprocEnsureUrlHasFocusEid(url, redir) {
- if (!url) {
- return url;
- }
- if (/(?:\?|#)(?:mproc_fe=|focus_eid=)\d+/.test(url)) {
- return url;
- }
- var fe = mprocExtractFocusEidFromRedirect(redir);
- if (fe <= 0) {
- return url;
- }
- var base = url.split('#')[0].split('?')[0];
- return base + '?focus_eid=' + encodeURIComponent(String(fe)) + '#mproc_fe=' + fe;
- }
- function goHome(ret) {
- if (ret && (ret.code === 1 || ret.code === '1')) {
- var d = ret.data || {};
- if (d.mproc_token) {
- try {
- var days = parseInt(d.keep_days, 10) || 7;
- localStorage.setItem('mproc_token', d.mproc_token);
- localStorage.setItem('mproc_token_exp', String(Date.now() + days * 86400000));
- } catch (eStore) {}
- }
- var jump = ret.url || indexUrl;
- jump = mprocEnsureUrlHasFocusEid(jump, loginRedirect);
- var feJump = mprocExtractFocusEidFromRedirect(jump) || mprocExtractFocusEidFromRedirect(loginRedirect);
- if (feJump > 0) {
- try {
- sessionStorage.setItem('mproc_focus_eid', String(feJump));
- } catch (ignoreSs) {}
- }
- location.href = jump;
- } else {
- showToast(ret && ret.msg ? ret.msg : '登录失败', 'err');
- }
- }
- function refreshCaptchaImage() {
- if (!$imgCaptcha || !captchaBaseUrl) return;
- $imgCaptcha.src = captchaBaseUrl + (captchaBaseUrl.indexOf('?') >= 0 ? '&' : '?') + 'r=' + Date.now();
- }
- /** 手动换图 / 验证码已被服务端校验消耗后:刷新图片并清空输入 */
- function resetCaptchaField() {
- refreshCaptchaImage();
- if ($captcha) $captcha.value = '';
- }
- if ($imgCaptcha) {
- $imgCaptcha.addEventListener('click', resetCaptchaField);
- }
- $tabs.forEach(function (btn) {
- btn.addEventListener('click', function () {
- var tab = btn.getAttribute('data-tab');
- $tabs.forEach(function (b) { b.classList.toggle('active', b === btn); });
- $panelPhone.classList.toggle('active', tab === 'phone');
- $panelAccount.classList.toggle('active', tab === 'account');
- if (tab === 'phone') resetCaptchaField();
- });
- });
- function tick() {
- if (cd <= 0) {
- clearInterval(timer);
- timer = null;
- $btnSend.disabled = false;
- $btnSend.textContent = '获取验证码';
- return;
- }
- $btnSend.textContent = cd + '秒后重发';
- cd--;
- }
- function sendSmsCode() {
- var phone = ($phone.value || '').trim();
- var captcha = ($captcha && $captcha.value) ? $captcha.value.trim() : '';
- if (!/^1\d{10}$/.test(phone)) {
- showToast('请输入正确的手机号', 'err');
- return;
- }
- if (!captcha) {
- showToast('请输入图形验证码', 'err');
- return;
- }
- if (cd > 0) return;
- $btnSend.disabled = true;
- $btnSend.textContent = '发送中…';
- postForm(sendUrl, { phone: phone, captcha: captcha }, 25000).then(function (ret) {
- if (ret && (ret.code === 1 || ret.code === '1')) {
- cd = 60;
- tick();
- timer = setInterval(tick, 1000);
- showToast('已发送', 'ok');
- } else {
- $btnSend.disabled = false;
- $btnSend.textContent = '获取验证码';
- var errMsg = ret && ret.msg ? ret.msg : '发送失败';
- showToast(errMsg, 'err');
- // 图形码已通过校验(如短信发送失败)时才换图;填错/手机号/频控等保留原输入
- if (/短信发送失败/.test(errMsg)) {
- resetCaptchaField();
- }
- }
- }).catch(function (e) {
- $btnSend.disabled = false;
- $btnSend.textContent = '获取验证码';
- if (e && e.name === 'AbortError') {
- showToast('请求超时,请稍后再试', 'err');
- } else {
- showToast('网络错误', 'err');
- }
- });
- }
- $btnSend.addEventListener('click', function () {
- var active = document.activeElement;
- if (active && active !== $btnSend && typeof active.blur === 'function') {
- active.blur();
- }
- // 移动端:先 blur 再读取输入框,避免点击按钮时图形码尚未写入 value
- setTimeout(sendSmsCode, 0);
- });
- $btnLogin.addEventListener('click', function () {
- var phone = ($phone.value || '').trim();
- var code = ($code.value || '').trim();
- if (!/^1\d{10}$/.test(phone)) {
- showToast('请输入正确的手机号', 'err');
- return;
- }
- if (!/^\d{6}$/.test(code)) {
- showToast('请输入6位验证码', 'err');
- return;
- }
- setSubmitBusy($btnLogin, true, '登录中…');
- postForm(loginUrl, { phone: phone, code: code, redirect: loginRedirect }, 25000).then(function (ret) {
- setSubmitBusy($btnLogin, false);
- goHome(ret);
- }).catch(function (e) {
- setSubmitBusy($btnLogin, false);
- if (e && e.name === 'AbortError') {
- showToast('请求超时,请稍后再试', 'err');
- } else {
- showToast('网络错误', 'err');
- }
- });
- });
- $btnLoginPwd.addEventListener('click', function () {
- var u = ($username.value || '').trim();
- var p = $password.value || '';
- if (!u) {
- showToast('请输入账号', 'err');
- return;
- }
- if (!p) {
- showToast('请输入密码', 'err');
- return;
- }
- setSubmitBusy($btnLoginPwd, true, '登录中…');
- postForm(loginPwdUrl, { username: u, password: p, redirect: loginRedirect }, 25000).then(function (ret) {
- setSubmitBusy($btnLoginPwd, false);
- goHome(ret);
- }).catch(function (e) {
- setSubmitBusy($btnLoginPwd, false);
- if (e && e.name === 'AbortError') {
- showToast('请求超时,请稍后再试', 'err');
- } else {
- showToast('网络错误', 'err');
- }
- });
- });
- /** 微信等移动端 Session/Cookie 易失效:用 localStorage 中的 token 自动恢复 7 天登录并回跳原链接(含 focus_eid) */
- function mprocTryAutoRestoreLogin() {
- var tok = '';
- var exp = 0;
- try {
- tok = localStorage.getItem('mproc_token') || '';
- exp = parseInt(localStorage.getItem('mproc_token_exp'), 10) || 0;
- } catch (eRead) {
- return;
- }
- if (!tok || !exp || Date.now() > exp) {
- if (tok) {
- try {
- localStorage.removeItem('mproc_token');
- localStorage.removeItem('mproc_token_exp');
- } catch (eClr) {}
- }
- return;
- }
- setSubmitBusy($btnLogin, true, '正在恢复登录…');
- if ($btnLoginPwd) {
- $btnLoginPwd.disabled = true;
- }
- var body = 'mproc_token=' + encodeURIComponent(tok);
- if (loginRedirect) {
- body += '&redirect=' + encodeURIComponent(loginRedirect);
- }
- fetch(restoreUrl, {
- method: 'POST',
- credentials: 'same-origin',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- 'X-Requested-With': 'XMLHttpRequest',
- 'X-Mproc-Token': tok
- },
- body: body
- }).then(function (r) {
- return r.json();
- }).then(function (ret) {
- if (ret && (ret.code === 1 || ret.code === '1')) {
- goHome(ret);
- return;
- }
- setSubmitBusy($btnLogin, false);
- if ($btnLoginPwd) {
- $btnLoginPwd.disabled = false;
- }
- var msg = ret && ret.msg ? String(ret.msg) : '';
- if (/过期|重新登录|未登录|请先登录/i.test(msg)) {
- try {
- localStorage.removeItem('mproc_token');
- localStorage.removeItem('mproc_token_exp');
- } catch (eDrop) {}
- }
- }).catch(function () {
- setSubmitBusy($btnLogin, false);
- if ($btnLoginPwd) {
- $btnLoginPwd.disabled = false;
- }
- });
- }
- mprocTryAutoRestoreLogin();
- })();
- </script>
- </body>
- </html>
|