merge store overview and home for wide mode

This commit is contained in:
Timi
2026-11-03 15:42:49 +08:00
parent d3879c9c77
commit 1a0cdd2181
17 changed files with 991 additions and 625 deletions
+91 -273
View File
@@ -1,316 +1,134 @@
<template>
<div class="tui-page-layout tui-navbar home-tab">
<t-navbar
v-if="!mergedLayout"
fixed
:z-index="20"
title="客户"
>
<template #right>
<t-badge
v-if="canReadNotify"
class="notification-badge"
:count="unreadNotifyCount"
:offset="[-6, 6]"
:max-count="99"
:show-zero="false"
>
<t-button
aria-label="通知"
@click="router.push('/notify')"
theme="default"
shape="square"
variant="text"
size="small"
>
<t-icon name="notification" size="1.25rem" />
</t-button>
</t-badge>
<navbar-notify-button />
</template>
</t-navbar>
<main class="tui-page-content scroll column">
<pending-notice-bar />
<section
v-for="group in visibleEntryGroupList"
:key="group.title"
class="entry-group"
>
<h2 v-text="group.title"/>
<div class="items" :class="group.layout">
<div
v-for="item in group.entryList"
:key="item.path"
class="item-wrap"
v-entrance-transition="{ step: 30 }"
>
<t-button
class="item"
:class="{ quick: item.path === '/customer/quick-sign-in' || item.path === '/management/order-fulfillments/quick' }"
variant="text"
@click="router.push(item.path)"
>
<div class="body">
<t-icon :name="item.icon" size="1.75rem"/>
<h2 v-text="item.title"/>
</div>
</t-button>
<main class="tui-page-content" :class="mergedLayout ? 'wide-split' : 'scroll column'">
<!-- 平板横屏:门店与客户合并成一页,两栏各自保留导航栏 -->
<div v-if="mergedLayout" class="split">
<section class="pane store-pane">
<t-navbar :z-index="20" title="门店">
<template #right>
<t-button
aria-label="刷新"
@click="storeOverviewRef?.refresh()"
theme="default"
variant="text"
size="small"
>
<t-icon name="refresh" size="1.25rem" />
</t-button>
</template>
</t-navbar>
<div class="pane-body">
<store-overview ref="storeOverviewRef" compact />
</div>
</div>
</section>
<div class="help-wrap" v-entrance-transition>
<t-button
class="help"
theme="primary"
variant="text"
content="使用帮助"
@click="router.push('/management/help')"
>
<template #icon>
<t-icon name="help-circle"/>
</template>
</t-button>
<t-button
v-if="canUseAi"
class="ai"
theme="primary"
variant="text"
content="AI 小糕"
@click="openAiChat"
>
<template #icon>
<t-icon name="robot-2" />
</template>
</t-button>
</section>
<section class="pane entry-pane">
<t-navbar :z-index="20" title="客户">
<template #right>
<navbar-notify-button />
</template>
</t-navbar>
<div class="pane-body">
<pending-notice-bar />
<customer-entry-panel />
</div>
</section>
</div>
<template v-else>
<div class="tab-body">
<pending-notice-bar />
<customer-entry-panel />
</div>
</template>
</main>
</div>
</template>
<script setup lang="ts">
import { NotifyAPI, useUserStore } from "timi-web-api";
import { useUserStore } from "timi-web-api";
import { useLayout } from "timi-tdesign-mobile";
import PendingNoticeBar from "./component/PendingNoticeBar.vue";
import { corePermissionCodes, gaoRoleCodes, permissionCodes } from "@/utils/permission";
import CustomerEntryPanel from "./component/CustomerEntryPanel.vue";
import NavbarNotifyButton from "./component/NavbarNotifyButton.vue";
import StoreOverview from "./component/StoreOverview.vue";
import { permissionCodes } from "@/utils/permission";
defineOptions({
name: "HomeTab"
});
const router = useRouter();
const userStore = useUserStore();
const unreadNotifyCount = ref(0);
interface HomeEntry {
path: string;
permission: string;
icon: string;
title: string;
}
interface HomeEntryGroup {
title: string;
layout?: "customer";
entryList: HomeEntry[];
}
const entryGroupList: HomeEntryGroup[] = [
{
title: "客户管理",
layout: "customer",
entryList: [
{
path: "/management/customers/create?redirect=/customers",
permission: permissionCodes.customer.create,
icon: "user-add",
title: "录入"
},
{
path: "/customer/registration",
permission: permissionCodes.eventRecord.create,
icon: "task-checked",
title: "登记"
},
{
path: "/customer/quick-sign-in",
permission: permissionCodes.eventRecord.create,
icon: "scan",
title: "快速扫码登记"
}
]
},
{
title: "订单管理",
entryList: [
{
path: "/management/sales-orders/create",
permission: permissionCodes.salesOrder.create,
icon: "task-add",
title: "创建产品订单"
},
{
path: "/management/customer-packages/create",
permission: permissionCodes.customerPackage.create,
icon: "layers",
title: "创建套餐订单"
},
{
path: "/management/order-fulfillments/quick",
permission: permissionCodes.orderFulfillment.create,
icon: "undertake-delivery",
title: "快速履约"
},
{
path: "/management/sales-orders",
permission: permissionCodes.salesOrder.read,
icon: "task",
title: "销售订单"
},
{
path: "/management/points/redemptions",
permission: permissionCodes.pointRedemption.create,
icon: "gift",
title: "积分兑换"
}
]
}
];
const visibleEntryGroupList = computed(() => entryGroupList
.map(group => ({
...group,
entryList: group.entryList.filter(item => userStore.hasPermissions(item.permission))
}))
.filter(group => group.entryList.length));
const canReadNotify = computed(() => userStore.hasPermissions(corePermissionCodes.notify.read));
const canUseAi = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager));
async function openAiChat(): Promise<void> {
await router.push("/ai/chat");
}
async function loadUnreadNotifyCount(): Promise<void> {
try {
unreadNotifyCount.value = Math.max(0, await NotifyAPI.countUnreadInternal());
} catch (error) {
unreadNotifyCount.value = 0;
console.warn("未读通知数量加载失败", error);
}
}
onMounted(async () => {
if (canReadNotify.value) {
await loadUnreadNotifyCount();
}
});
// 横屏平板(出现左侧导航栏)才合并门店与客户入口;
// 没有统计权限的账号本来就没有门店 tab,这里同样不显示左侧分栏
const { isWide } = useLayout({ tablet: true });
const mergedLayout = computed(() => isWide.value && userStore.hasPermissions(permissionCodes.stat.read));
const storeOverviewRef = ref<InstanceType<typeof StoreOverview>>();
</script>
<style scoped lang="less">
.home-tab {
.entry-group {
margin: 0 1rem;
.wide-split {
overflow: hidden;
padding-top: 0;
padding-bottom: 0;
}
& + & {
margin-top: 1.5rem;
.split {
flex: 1;
display: grid;
min-height: 0;
grid-template-columns: minmax(0, 1fr) clamp(24rem, 28vw, 28rem);
}
.pane {
display: flex;
position: relative;
min-height: 0;
overflow: hidden;
flex-direction: column;
&:first-child {
border-right: 1px solid var(--td-component-border);
}
> h2 {
color: #52607a;
margin: 0 0 .75rem 0;
font-size: .875rem;
font-weight: 700;
}
// 栏内导航栏贴在栏顶,内容从它下方滚过,和整页的毛玻璃效果一致
.t-navbar {
top: 0;
left: 0;
right: 0;
position: absolute;
.items {
--td-button-border-radius: 1.75rem;
gap: .875rem;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
.item {
--entry-color: #0f766e;
--entry-color-active: #0a5d56;
--entry-background: rgba(255, 255, 255, .92);
color: var(--entry-color);
width: 100%;
height: auto;
margin: 0;
padding: 1rem;
display: flex;
// navbar 默认 fixed:内容层原本贴着视口,这里收回栏内;
// 占位块是给 fixed 模式撑高度用的,栏内不需要
:deep(.t-navbar__content) {
left: 0;
right: 0;
position: relative;
text-align: center;
background: var(--entry-background);
box-shadow: 0 .75rem 2rem rgba(15, 23, 42, .08);
align-items: center;
aspect-ratio: 1;
flex-direction: column;
justify-content: center;
}
&.quick {
--td-button-default-text-active-bg-color: var(--entry-color-active);
color: var(--entry-background);
background: var(--entry-color);
}
.body {
inset: 1rem;
display: flex;
gap: .5rem;
position: absolute;
align-items: center;
flex-direction: column;
justify-content: center;
h2 {
margin: 0;
font-size: .75rem;
line-height: 1.5;
}
}
:deep(.t-navbar__placeholder) {
display: none;
}
}
}
.help-wrap {
--td-button-border-radius: 1rem;
gap: 1rem;
width: fit-content;
margin: 1rem auto 0 auto;
display: flex;
align-items: center;
.help,
.ai {
width: 8rem;
background: white;
box-shadow: var(--td-shadow-3);
.pane-body {
flex: 1;
min-height: 0;
overflow: auto;
padding-top: calc(var(--tui-nav-height, 48px) + 1rem);
padding-bottom: 1rem;
}
}
}
:global(html.theme-dark) {
.entry-page {
.entry-group > h2 {
color: #94a3b8;
}
.item {
--entry-background: rgba(15, 23, 42, .88);
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
}
}
}
.notification-badge {
:deep(.t-badge__content) {
display: flex;
align-items: center;
}
}
</style>