All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m41s
对齐登录、工作台、H5、官网与充值页的轻压 inset;监控改胶囊 Tab 减闪;充值页去步骤条并收窄布局。 Co-authored-by: Cursor <cursoragent@cursor.com>
648 lines
16 KiB
Vue
648 lines
16 KiB
Vue
<template>
|
||
<div class="h5-login-page" :class="{ 'is-oauth-busy': oauthBusy }">
|
||
<!-- OAuth 回跳:全屏过渡,避免先闪登录表单再进系统 -->
|
||
<main v-if="oauthBusy" class="h5-login-oauth-screen">
|
||
<div class="h5-login-oauth-screen__card">
|
||
<div class="h5-login-oauth-screen__brand">
|
||
<img :src="logoImg" alt="" class="h5-login-card__logo" />
|
||
<span>{{ t('h5.login.brandName') }}</span>
|
||
</div>
|
||
<a-spin :size="28" />
|
||
<p class="h5-login-oauth-screen__text">{{ t('h5.login.oauthLoggingIn') }}</p>
|
||
</div>
|
||
</main>
|
||
|
||
<template v-else>
|
||
<header class="h5-login-nav">
|
||
<button type="button" class="h5-login-back" @click="goBack">
|
||
<icon-left />
|
||
</button>
|
||
<h1 class="h5-login-nav__title">{{ t('h5.login.title') }}</h1>
|
||
<LoginLangToggle />
|
||
</header>
|
||
|
||
<main class="h5-login-main">
|
||
<section class="h5-login-card">
|
||
<header class="h5-login-card__brand">
|
||
<div class="h5-login-card__brand-row">
|
||
<img :src="logoImg" alt="" class="h5-login-card__logo" />
|
||
<h2 class="h5-login-card__title">{{ t('h5.login.brandName') }}</h2>
|
||
</div>
|
||
<p class="h5-login-card__hint">{{ t('h5.login.brandHint') }}</p>
|
||
</header>
|
||
|
||
<form class="h5-login-form" @submit.prevent="handleSubmit">
|
||
<a-input
|
||
v-model="form.account"
|
||
size="large"
|
||
allow-clear
|
||
class="h5-login-input"
|
||
:placeholder="t('h5.login.accountPlaceholder')"
|
||
autocomplete="username"
|
||
/>
|
||
<a-input-password
|
||
v-model="form.password"
|
||
size="large"
|
||
allow-clear
|
||
class="h5-login-input"
|
||
:placeholder="t('h5.login.passwordPlaceholder')"
|
||
autocomplete="current-password"
|
||
/>
|
||
|
||
<p v-if="errorBox" class="h5-login-error">{{ errorBox }}</p>
|
||
|
||
<a-button
|
||
type="primary"
|
||
html-type="submit"
|
||
long
|
||
size="large"
|
||
class="h5-login-submit"
|
||
:loading="loading"
|
||
>
|
||
{{ loading ? t('h5.login.submitting') : t('h5.login.submit') }}
|
||
</a-button>
|
||
|
||
<a-checkbox v-model="agreementChecked" class="h5-login-agree">
|
||
<span>
|
||
{{ t('h5.login.agreePrefix') }}
|
||
<a class="h5-login-link" @click.prevent="openAgreement('privacy')">
|
||
{{ t('h5.login.privacy') }}
|
||
</a>
|
||
{{ t('h5.login.and') }}
|
||
<a class="h5-login-link" @click.prevent="openAgreement('terms')">
|
||
{{ t('h5.login.terms') }}
|
||
</a>
|
||
</span>
|
||
</a-checkbox>
|
||
</form>
|
||
|
||
<div class="h5-login-oauth">
|
||
<WechatOAuthLoginButton
|
||
:after-login-path="resolveRedirectPath()"
|
||
:disabled="loading"
|
||
/>
|
||
</div>
|
||
</section>
|
||
|
||
<div class="h5-login-extra">
|
||
<p class="h5-login-extra__hint">
|
||
{{ t('h5.login.newUserHint') }}
|
||
<button type="button" class="h5-login-extra__link" @click="goRegister">
|
||
{{ t('h5.login.goRegister') }}
|
||
</button>
|
||
</p>
|
||
</div>
|
||
</main>
|
||
|
||
<H5LoginPortalSwitch target="admin" />
|
||
</template>
|
||
|
||
<a-modal
|
||
v-model:visible="agreementVisible"
|
||
:title="agreementTitle"
|
||
:footer="false"
|
||
unmount-on-close
|
||
width="auto"
|
||
modal-class="h5-login-modal"
|
||
>
|
||
<div class="h5-login-agreement">{{ agreementContent }}</div>
|
||
</a-modal>
|
||
</div>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { nextTick, onMounted, reactive, ref } from 'vue';
|
||
import { useRoute, useRouter } from 'vue-router';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { Message } from '@arco-design/web-vue';
|
||
import { IconLeft } from '@arco-design/web-vue/es/icon';
|
||
import { OmsLoginType } from '@/api/rbac';
|
||
import { isLogin, setToken } from '@/utils/auth';
|
||
import { applyRbacUserToUserStore } from '@/utils/enter-system';
|
||
import { ensureFullLocaleMessages } from '@/locale';
|
||
import { isWeChatBrowser } from '@/utils/device';
|
||
import { useRbacUserStore } from '@/store/modules/rbac-user';
|
||
import logoImg from '@/assets/logo2.png';
|
||
import LoginLangToggle from '@/views/login/components/LoginLangToggle.vue';
|
||
import H5LoginPortalSwitch from '@/views/h5/components/H5LoginPortalSwitch.vue';
|
||
import WechatOAuthLoginButton from '../components/WechatOAuthLoginButton.vue';
|
||
import { wxOAuthLogin } from '@/api/wechat';
|
||
import {
|
||
parseAfterLoginPathFromOAuthState,
|
||
redirectToWeChatOAuth,
|
||
} from '@/utils/wechatOAuth';
|
||
|
||
defineOptions({ name: 'H5Login' });
|
||
|
||
const { t } = useI18n();
|
||
const route = useRoute();
|
||
const router = useRouter();
|
||
const rbacUserStore = useRbacUserStore();
|
||
|
||
const form = reactive({ account: '', password: '' });
|
||
const agreementChecked = ref(false);
|
||
const loading = ref(false);
|
||
const errorBox = ref('');
|
||
const agreementVisible = ref(false);
|
||
const agreementTitle = ref('');
|
||
const agreementContent = ref('');
|
||
|
||
function readOAuthCodeFromRoute() {
|
||
const code = route.query.code;
|
||
return typeof code === 'string' ? code.trim() : '';
|
||
}
|
||
|
||
/** 有 OAuth code 时首帧即全屏过渡,避免先画出登录表单 */
|
||
const oauthBusy = ref(!!readOAuthCodeFromRoute());
|
||
let oauthConsuming = false;
|
||
|
||
const privacyText = `一、隐私保护告知
|
||
我们重视您的个人信息保护。登录与使用客户中心时,将按业务需要处理账号、订单与联系信息,仅用于履约、客服与安全风控,不会向无关第三方出售。
|
||
二、您的权利
|
||
您可查阅、更正账号资料,也可联系客服申请账号相关协助。`;
|
||
|
||
const termsText = `一、使用须知
|
||
请妥善保管账号与密码,勿向他人泄露。您应对账号下的查价、下单、支付等操作负责。
|
||
二、服务说明
|
||
系统展示的运费、时效为估算或报价结果,最终以订单确认与仓库计费为准。异常订单请及时联系客服或使用 AI 顾问。`;
|
||
|
||
function goBack() {
|
||
if (window.history.length > 1) {
|
||
router.back();
|
||
return;
|
||
}
|
||
router.replace('/h5/orders');
|
||
}
|
||
|
||
function goRegister() {
|
||
if (!isWeChatBrowser()) {
|
||
Message.warning(t('h5.login.openInWechat'));
|
||
return;
|
||
}
|
||
void redirectToWeChatOAuth('register').catch((e: any) => {
|
||
Message.error(e?.message || t('h5.login.oauthFailed'));
|
||
});
|
||
}
|
||
|
||
function openAgreement(type: 'privacy' | 'terms') {
|
||
if (type === 'privacy') {
|
||
agreementTitle.value = t('h5.login.privacy');
|
||
agreementContent.value = privacyText;
|
||
} else {
|
||
agreementTitle.value = t('h5.login.terms');
|
||
agreementContent.value = termsText;
|
||
}
|
||
agreementVisible.value = true;
|
||
}
|
||
|
||
function resolveRedirectPath() {
|
||
const fromState = parseAfterLoginPathFromOAuthState(route.query.state);
|
||
if (fromState) return fromState;
|
||
const redirect = route.query.redirect;
|
||
if (typeof redirect === 'string' && redirect.startsWith('/h5')) {
|
||
return redirect;
|
||
}
|
||
return '/h5/orders';
|
||
}
|
||
|
||
function stripOAuthQuery() {
|
||
const { code: _c, state: _s, ...rest } = route.query;
|
||
return rest;
|
||
}
|
||
|
||
async function finishLogin() {
|
||
if (!rbacUserStore.userInfo) return;
|
||
if (rbacUserStore.token) {
|
||
setToken(rbacUserStore.token);
|
||
}
|
||
applyRbacUserToUserStore(rbacUserStore.userInfo, form.account.trim());
|
||
// 不阻塞跳转:H5 bootstrap 已含业务文案;全量语言包后台补
|
||
void ensureFullLocaleMessages();
|
||
await nextTick();
|
||
const target = resolveRedirectPath();
|
||
try {
|
||
await router.replace({ path: target, query: {} });
|
||
} catch (navErr) {
|
||
console.error('H5 登录跳转失败', navErr);
|
||
await router.replace('/h5/orders').catch(() => undefined);
|
||
}
|
||
}
|
||
|
||
async function consumeOAuthCode(code: string) {
|
||
if (oauthConsuming) return;
|
||
oauthConsuming = true;
|
||
oauthBusy.value = true;
|
||
errorBox.value = '';
|
||
try {
|
||
const result = await wxOAuthLogin(code);
|
||
const ok = await rbacUserStore.loginByWxResult(result);
|
||
if (!ok) {
|
||
Message.error(t('h5.login.failed'));
|
||
oauthBusy.value = false;
|
||
await router.replace({ path: route.path, query: stripOAuthQuery() });
|
||
return;
|
||
}
|
||
// 成功后保持全屏过渡直到离开本页,勿 toast / 勿先露出登录表单
|
||
await finishLogin();
|
||
} catch (e: any) {
|
||
const msg = e?.message || t('h5.login.oauthFailed');
|
||
Message.error(msg);
|
||
errorBox.value = msg;
|
||
oauthBusy.value = false;
|
||
await router.replace({ path: route.path, query: stripOAuthQuery() });
|
||
} finally {
|
||
oauthConsuming = false;
|
||
}
|
||
}
|
||
|
||
async function handleSubmit() {
|
||
if (loading.value || oauthBusy.value) return;
|
||
errorBox.value = '';
|
||
|
||
if (!agreementChecked.value) {
|
||
Message.warning(t('h5.login.needAgree'));
|
||
return;
|
||
}
|
||
if (!form.account.trim()) {
|
||
errorBox.value = t('h5.login.accountRequired');
|
||
return;
|
||
}
|
||
if (!form.password) {
|
||
errorBox.value = t('h5.login.passwordRequired');
|
||
return;
|
||
}
|
||
|
||
loading.value = true;
|
||
try {
|
||
const success = await rbacUserStore.login(
|
||
form.account.trim(),
|
||
form.password,
|
||
OmsLoginType.Customer,
|
||
);
|
||
|
||
if (!success || !rbacUserStore.userInfo) {
|
||
errorBox.value = t('h5.login.failed');
|
||
Message.error(t('h5.login.failed'));
|
||
return;
|
||
}
|
||
|
||
Message.success(t('h5.login.success'));
|
||
await finishLogin();
|
||
} catch (e: any) {
|
||
errorBox.value = e?.message || t('h5.login.failed');
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
onMounted(async () => {
|
||
if (isLogin()) {
|
||
router.replace(resolveRedirectPath());
|
||
return;
|
||
}
|
||
|
||
const code = readOAuthCodeFromRoute();
|
||
if (code) {
|
||
await consumeOAuthCode(code);
|
||
return;
|
||
}
|
||
|
||
if (isWeChatBrowser() && route.query.auto === '1') {
|
||
oauthBusy.value = true;
|
||
try {
|
||
await redirectToWeChatOAuth('login', null, { afterLoginPath: resolveRedirectPath() });
|
||
} catch (e: any) {
|
||
oauthBusy.value = false;
|
||
Message.error(e?.message || t('h5.login.oauthFailed'));
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
|
||
<style lang="less" scoped>
|
||
.h5-login-page {
|
||
--login-ease: cubic-bezier(0.22, 1, 0.36, 1);
|
||
box-sizing: border-box;
|
||
min-height: 100vh;
|
||
min-height: 100dvh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
background: var(--app-page-bg, #f0f3f4);
|
||
overflow-x: hidden;
|
||
-webkit-overflow-scrolling: touch;
|
||
|
||
&.is-oauth-busy {
|
||
justify-content: center;
|
||
}
|
||
}
|
||
|
||
.h5-login-oauth-screen {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px));
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.h5-login-oauth-screen__card {
|
||
width: min(320px, 100%);
|
||
padding: 36px 24px;
|
||
border-radius: 20px;
|
||
background: var(--app-acrylic-bg);
|
||
border: 1px solid var(--app-acrylic-border);
|
||
box-shadow: none;
|
||
backdrop-filter: var(--app-acrylic-blur);
|
||
-webkit-backdrop-filter: var(--app-acrylic-blur);
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 16px;
|
||
text-align: center;
|
||
}
|
||
|
||
.h5-login-oauth-screen__brand {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
margin-bottom: 4px;
|
||
font-size: 20px;
|
||
font-weight: 700;
|
||
color: #1d2129;
|
||
letter-spacing: 0.04em;
|
||
}
|
||
|
||
.h5-login-oauth-screen__text {
|
||
margin: 0;
|
||
font-size: 14px;
|
||
line-height: 1.45;
|
||
color: #86909c;
|
||
}
|
||
|
||
.h5-login-nav {
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 20;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
height: 48px;
|
||
padding: 0 8px 0 4px;
|
||
background: transparent;
|
||
border-bottom: none;
|
||
color: #4e5969;
|
||
}
|
||
|
||
/* 无障碍保留页面标题,视觉上隐藏(避免与卡内「客户中心」重复) */
|
||
.h5-login-nav__title {
|
||
position: absolute;
|
||
width: 1px;
|
||
height: 1px;
|
||
padding: 0;
|
||
margin: -1px;
|
||
overflow: hidden;
|
||
clip: rect(0, 0, 0, 0);
|
||
white-space: nowrap;
|
||
border: 0;
|
||
}
|
||
|
||
.h5-login-back {
|
||
width: 40px;
|
||
height: 40px;
|
||
border: none;
|
||
background: transparent;
|
||
font-size: 20px;
|
||
color: #1d2129;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
cursor: pointer;
|
||
border-radius: 10px;
|
||
transition: background 0.2s var(--login-ease), transform 0.2s var(--login-ease);
|
||
|
||
&:active {
|
||
background: rgba(0, 0, 0, 0.04);
|
||
transform: scale(0.96);
|
||
}
|
||
}
|
||
|
||
.h5-login-main {
|
||
flex: 1;
|
||
width: 100%;
|
||
max-width: 420px;
|
||
margin: 0 auto;
|
||
padding: 20px 16px calc(28px + env(safe-area-inset-bottom, 0px));
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
}
|
||
|
||
.h5-login-card {
|
||
/* 对齐官网/PC 登录 pressed:白底 + inset 凹陷 */
|
||
background: #ffffff;
|
||
border: none;
|
||
border-radius: 20px;
|
||
padding: 28px 20px 22px;
|
||
box-shadow:
|
||
inset 0 2px 8px rgba(15, 23, 42, 0.07),
|
||
inset 0 1px 1px rgba(15, 23, 42, 0.04);
|
||
backdrop-filter: none;
|
||
-webkit-backdrop-filter: none;
|
||
}
|
||
|
||
/* 品牌放进卡片:一个完整登录单元(Clerk / Vercel 鉴权卡常见) */
|
||
.h5-login-card__brand {
|
||
text-align: center;
|
||
margin: 0 0 22px;
|
||
}
|
||
|
||
.h5-login-card__brand-row {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.h5-login-card__logo {
|
||
display: block;
|
||
width: 36px;
|
||
height: 36px;
|
||
object-fit: contain;
|
||
border: none;
|
||
border-radius: 0;
|
||
background: transparent;
|
||
-webkit-touch-callout: none;
|
||
-webkit-user-select: none;
|
||
user-select: none;
|
||
-webkit-user-drag: none;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.h5-login-card__title {
|
||
margin: 0;
|
||
font-size: 22px;
|
||
font-weight: 700;
|
||
color: #1d2129;
|
||
letter-spacing: 0.04em;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.h5-login-card__hint {
|
||
margin: 10px 0 0;
|
||
font-size: 13px;
|
||
line-height: 1.45;
|
||
color: #86909c;
|
||
}
|
||
|
||
.h5-login-form {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.h5-login-input {
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.h5-login-form :deep(.arco-input-wrapper),
|
||
.h5-login-form :deep(.arco-input-password) {
|
||
border-radius: 12px;
|
||
background: #f0f3f4;
|
||
border: none;
|
||
min-height: 48px;
|
||
backdrop-filter: none;
|
||
-webkit-backdrop-filter: none;
|
||
box-shadow: inset 0 2px 8px rgba(15, 23, 42, 0.08);
|
||
transition: box-shadow 0.2s var(--login-ease), background 0.2s var(--login-ease);
|
||
|
||
&:hover {
|
||
background: #f0f3f4;
|
||
box-shadow: inset 0 3px 10px rgba(15, 23, 42, 0.1);
|
||
}
|
||
|
||
&.arco-input-wrapper-focus,
|
||
&.arco-input-focus {
|
||
background: #f0f3f4;
|
||
border: none;
|
||
box-shadow:
|
||
inset 0 3px 10px rgba(15, 23, 42, 0.1),
|
||
0 0 0 3px color-mix(in srgb, var(--app-primary-color) 12%, transparent);
|
||
}
|
||
}
|
||
|
||
.h5-login-error {
|
||
margin: 0 0 8px;
|
||
padding: 10px 12px;
|
||
border-radius: 12px;
|
||
background: color-mix(in srgb, #ffece8 72%, var(--app-acrylic-bg));
|
||
border: 1px solid color-mix(in srgb, #ffb4a8 65%, var(--app-acrylic-border));
|
||
color: #f53f3f;
|
||
font-size: 13px;
|
||
line-height: 1.4;
|
||
backdrop-filter: var(--app-acrylic-blur);
|
||
-webkit-backdrop-filter: var(--app-acrylic-blur);
|
||
animation: h5-login-rise 0.28s var(--login-ease) both;
|
||
}
|
||
|
||
.h5-login-agree {
|
||
margin: 12px 0 0;
|
||
width: 100%;
|
||
font-size: 12px;
|
||
color: #86909c;
|
||
line-height: 18px;
|
||
|
||
:deep(.arco-checkbox) {
|
||
align-items: flex-start;
|
||
max-width: 100%;
|
||
}
|
||
|
||
/* 勾选框约 14px,首行行高 18px,上移 2px 与「我已阅读」光学对齐 */
|
||
:deep(.arco-checkbox-icon-hover) {
|
||
margin-top: 2px;
|
||
}
|
||
|
||
:deep(.arco-checkbox-label) {
|
||
flex: 1;
|
||
min-width: 0;
|
||
line-height: 18px;
|
||
color: #86909c;
|
||
}
|
||
}
|
||
|
||
.h5-login-link {
|
||
color: var(--app-primary-color);
|
||
cursor: pointer;
|
||
}
|
||
|
||
.h5-login-submit {
|
||
margin-top: 8px;
|
||
height: 48px !important;
|
||
border-radius: 10px !important;
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
/* 主按钮靠实色对比突出,避免过重光晕 */
|
||
box-shadow: none;
|
||
transition: filter 0.2s var(--login-ease), transform 0.2s var(--login-ease) !important;
|
||
|
||
&:active {
|
||
transform: scale(0.985);
|
||
}
|
||
}
|
||
|
||
.h5-login-oauth {
|
||
margin-top: 18px;
|
||
}
|
||
|
||
.h5-login-extra {
|
||
margin-top: 18px;
|
||
text-align: center;
|
||
}
|
||
|
||
.h5-login-extra__hint {
|
||
margin: 0;
|
||
font-size: 13px;
|
||
color: #86909c;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.h5-login-extra__link {
|
||
margin: 0;
|
||
padding: 0;
|
||
border: none;
|
||
background: transparent;
|
||
color: var(--app-primary-color);
|
||
font-size: inherit;
|
||
font-weight: 600;
|
||
line-height: inherit;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.h5-login-agreement {
|
||
white-space: pre-wrap;
|
||
font-size: 13px;
|
||
line-height: 1.7;
|
||
color: #4e5969;
|
||
max-height: 60vh;
|
||
overflow: auto;
|
||
}
|
||
|
||
@keyframes h5-login-rise {
|
||
from {
|
||
opacity: 0;
|
||
transform: translate3d(0, 12px, 0);
|
||
}
|
||
to {
|
||
opacity: 1;
|
||
transform: translate3d(0, 0, 0);
|
||
}
|
||
}
|
||
|
||
@media (prefers-reduced-motion: reduce) {
|
||
.h5-login-error,
|
||
.h5-login-submit {
|
||
animation: none !important;
|
||
transition: none !important;
|
||
}
|
||
}
|
||
</style>
|