front/src/views/h5/customer-center/layout.vue
zzh 8f3a41956e
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m25s
feat: 开票管理与品牌文案统一(PC/H5 短名全称同源)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-21 12:22:57 +08:00

249 lines
6.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="h5-center-layout">
<header v-if="showHeader" class="h5-center-header">
<h1 class="h5-center-header__title">{{ headerTitle }}</h1>
<LoginLangToggle />
</header>
<main
ref="mainRef"
class="h5-center-main"
:class="{
'h5-center-main--no-header': !showHeader,
'h5-center-main--no-tabbar': !showTabBar,
}"
>
<router-view v-slot="{ Component }">
<keep-alive :include="[...H5_CUSTOMER_TAB_KEEP_ALIVE]">
<component :is="Component" />
</keep-alive>
</router-view>
</main>
<AppTabBar
v-if="showTabBar"
:order-badge="orderBadge"
:hide-create="hideCreateFab"
@create-order="openPlaceOrder"
/>
<!-- 仅打开时挂载;首屏后 idle 预取分包 -->
<H5CreateOrderFlow
v-if="createFlowReady"
v-model:visible="placeOrderVisible"
/>
<H5FollowOfficialModal v-if="followModalReady" />
<H5NoticePopup v-if="noticePopupReady" />
<H5LoginGateSheet />
</div>
</template>
<script lang="ts" setup>
import {
computed,
defineAsyncComponent,
nextTick,
onMounted,
onBeforeUnmount,
provide,
ref,
watch,
} from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { isLogin } from '@/utils/auth';
import { getOrderStatusCounts } from '@/api/order';
import { ensureFullLocaleMessages } from '@/locale';
import { hideWeChatBrowserNav } from '@/utils/device';
import { H5_ORDER_GROUPS, sumStatusCounts } from '@/constants/h5OrderStatus';
import LoginLangToggle from '@/views/login/components/LoginLangToggle.vue';
import AppTabBar from './components/AppTabBar.vue';
import H5LoginGateSheet from './components/H5LoginGateSheet.vue';
import { ensureH5Login } from './composables/useH5LoginGate';
import { H5_HIDE_CREATE_FAB_KEY } from './composables/h5TabBarUi';
import {
H5_CUSTOMER_TAB_KEEP_ALIVE,
useH5TabScrollMemory,
} from '@/views/h5/composables/useH5TabEnterOnce';
import { brandCopy } from '@/utils/brandCopy';
defineOptions({ name: 'H5CustomerCenterLayout' });
const H5CreateOrderFlow = defineAsyncComponent(
() => import('./components/H5CreateOrderFlow.vue'),
);
const H5FollowOfficialModal = defineAsyncComponent(
() => import('./components/H5FollowOfficialModal.vue'),
);
const H5NoticePopup = defineAsyncComponent(
() => import('./components/H5NoticePopup.vue'),
);
const { t, locale } = useI18n();
const route = useRoute();
const mainRef = ref<HTMLElement | null>(null);
useH5TabScrollMemory(mainRef, [...H5_CUSTOMER_TAB_KEEP_ALIVE]);
const orderBadge = ref(0);
const placeOrderVisible = ref(false);
const createFlowReady = ref(false);
/** 订单批量/揽收勾选时隐藏凸起加号,避免挡住底部操作条 */
const hideCreateFab = ref(false);
provide(H5_HIDE_CREATE_FAB_KEY, hideCreateFab);
let idlePreloadHandle: number | null = null;
let badgeTimer: ReturnType<typeof setTimeout> | null = null;
async function openPlaceOrder() {
if (
!ensureH5Login({
reasonKey: 'h5.loginGate.reason.placeOrder',
redirect: '/h5/place-order',
})
) {
return;
}
createFlowReady.value = true;
await nextTick();
placeOrderVisible.value = true;
}
const showTabBar = computed(() => route.meta?.h5HideTabBar !== true);
const showHeader = computed(() => route.meta?.h5HideHeader !== true);
const followModalReady = computed(() => isLogin());
const noticePopupReady = computed(() => isLogin());
const headerTitle = computed(() => {
const key = String(route.meta?.locale || 'h5.center.title');
return t(key);
});
function syncDocumentTitle() {
document.title = t('h5.documentTitle', { name: brandCopy.navName });
}
async function refreshOrderBadge() {
if (!isLogin()) {
orderBadge.value = 0;
return;
}
try {
const res = await getOrderStatusCounts();
const action = H5_ORDER_GROUPS.find((g) => g.key === 'actionNeeded');
const issue = H5_ORDER_GROUPS.find((g) => g.key === 'issue');
orderBadge.value =
sumStatusCounts(res.counts, action?.statuses || []) +
sumStatusCounts(res.counts, issue?.statuses || []);
} catch {
orderBadge.value = 0;
}
}
function scheduleBadgeRefresh() {
if (badgeTimer) clearTimeout(badgeTimer);
// 让列表接口先跑,角标稍后补,避免与订单列表抢带宽
badgeTimer = setTimeout(() => {
void refreshOrderBadge();
}, 1200);
}
function preloadCreateFlow() {
if (createFlowReady.value || !isLogin()) return;
void import('./components/H5CreateOrderFlow.vue').catch(() => undefined);
}
onMounted(() => {
hideWeChatBrowserNav();
syncDocumentTitle();
// 访客也可逛顾问等页:空闲补全量语言包(bootstrap 已含 H5 + ediAssistant)
const run = () => {
void ensureFullLocaleMessages(locale.value);
preloadCreateFlow();
};
if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
idlePreloadHandle = window.requestIdleCallback(run, {
timeout: 2500,
}) as unknown as number;
} else {
idlePreloadHandle = window.setTimeout(run, 800) as unknown as number;
}
if (showTabBar.value) {
scheduleBadgeRefresh();
}
});
onBeforeUnmount(() => {
if (badgeTimer) clearTimeout(badgeTimer);
if (idlePreloadHandle != null) {
if (typeof window !== 'undefined' && 'cancelIdleCallback' in window) {
window.cancelIdleCallback(idlePreloadHandle);
} else {
clearTimeout(idlePreloadHandle);
}
}
});
watch(
() => route.path,
() => {
if (route.path.startsWith('/h5/orders') || route.path === '/h5/me') {
scheduleBadgeRefresh();
}
},
);
watch(locale, () => {
syncDocumentTitle();
});
</script>
<style lang="less">
@import './styles/tokens.less';
</style>
<style lang="less" scoped>
.h5-center-layout {
min-height: 100vh;
min-height: 100dvh;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
.h5-center-header {
position: sticky;
top: 0;
z-index: 50;
display: flex;
align-items: center;
justify-content: space-between;
height: 48px;
padding: 0 12px 0 16px;
background: color-mix(in srgb, var(--h5-surface) 92%, transparent);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border-bottom: 1px solid var(--h5-border);
color: var(--h5-text-2);
}
.h5-center-header__title {
margin: 0;
font-size: 17px;
font-weight: 600;
color: var(--h5-text);
}
.h5-center-main {
flex: 1;
min-height: 0;
padding-bottom: var(--h5-dock-offset);
box-sizing: border-box;
overflow: auto;
-webkit-overflow-scrolling: touch;
&--no-tabbar {
padding-bottom: var(--h5-safe-bottom);
}
&--no-header {
/* 「我的」等自带 Hero 顶栏 */
}
}
</style>