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>
+53 -21
View File
@@ -1,28 +1,30 @@
<template>
<t-navbar fixed :z-index="20" title="产品" />
<main class="tui-page-content scroll column product-tab">
<t-cell-group
v-for="(group, index) in visibleMenuGroupList"
:key="group.title"
class="menu-group"
:title="group.title"
theme="card"
v-entrance-transition
>
<t-cell
v-for="item in group.items"
:key="item.path"
class="menu-item"
:title="item.title"
arrow
hover
@click="go(item.path)"
<div class="tab-body menu-grid">
<t-cell-group
v-for="(group, index) in visibleMenuGroupList"
:key="group.title"
class="menu-group"
:title="group.title"
theme="card"
v-entrance-transition
>
<template #leftIcon>
<span class="icon-wrap" :class="`tone-${index}`"><t-icon :name="item.icon" size="1.35rem" /></span>
</template>
</t-cell>
</t-cell-group>
<t-cell
v-for="item in group.items"
:key="item.path"
class="menu-item"
:title="item.title"
arrow
hover
@click="go(item.path)"
>
<template #leftIcon>
<span class="icon-wrap" :class="`tone-${index}`"><t-icon :name="item.icon" size="1.35rem" /></span>
</template>
</t-cell>
</t-cell-group>
</div>
<center-tips v-if="!visibleMenuGroupList.length" :content="'当前账号暂无产品管理权限'" />
</main>
</template>
@@ -178,5 +180,35 @@ async function go(path: string): Promise<void> {
<style scoped lang="less">
.product-tab {
gap: .5rem;
.tab-body {
--tab-body-max: 72rem;
}
/**
* 平板起分组卡片并排:同一屏能看到更多分组,
* 行宽也不会被拉到整屏宽(手机形态完全不变)。
*/
.menu-grid {
gap: .5rem;
display: grid;
padding: 0 1rem;
align-items: start;
grid-template-columns: minmax(0, 1fr);
// 卡片自带 16px 外边距,进栅格后间距交给容器的 padding 和 gap
:deep(.t-cell-group--card) {
margin: 0;
}
@media (min-width: 48rem) {
gap: .75rem;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 80rem) {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
}
</style>
+114 -62
View File
@@ -1,69 +1,73 @@
<template>
<t-navbar fixed :z-index="20" title="管理" />
<main class="tui-page-content scroll column management-tab">
<t-cell-group class="user-card" theme="card" v-entrance-transition>
<t-cell
v-if="currentUser"
class="info"
arrow
hover
@click="go('/management/profile')"
>
<template #description>
<div v-if="currentUser?.phoneNo" v-text="currentUser.phoneNo" />
</template>
<template #title>
<div class="header">
<div class="name" v-text="currentUser.nick || currentUser.name" />
<gender-icon :value="currentUser.gender" />
<div class="roles">
<t-tag
v-for="role in currentUserRoleList"
:key="getRoleKey(role)"
size="small"
theme="success"
variant="outline"
:content="getRoleName(role)"
<div class="tab-body">
<div class="menu-grid">
<t-cell-group class="user-card" theme="card" v-entrance-transition>
<t-cell
v-if="currentUser"
class="info"
arrow
hover
@click="go('/management/profile')"
>
<template #description>
<div v-if="currentUser?.phoneNo" v-text="currentUser.phoneNo" />
</template>
<template #title>
<div class="header">
<div class="name" v-text="currentUser.nick || currentUser.name" />
<gender-icon :value="currentUser.gender" />
<div class="roles">
<t-tag
v-for="role in currentUserRoleList"
:key="getRoleKey(role)"
size="small"
theme="success"
variant="outline"
:content="getRoleName(role)"
/>
<span v-if="!currentUserRoleList.length && !isRoleLoading" class="muted" v-text="'未配置角色'" />
</div>
</div>
</template>
<template #leftIcon>
<t-image
class="avatar"
:src="currentUserAvatar"
:alt="currentUser.nick || currentUser.name"
fit="cover"
/>
<span v-if="!currentUserRoleList.length && !isRoleLoading" class="muted" v-text="'未配置角色'" />
</div>
</div>
</template>
<template #leftIcon>
<t-image
class="avatar"
:src="currentUserAvatar"
:alt="currentUser.nick || currentUser.name"
fit="cover"
/>
</template>
</t-cell>
</t-cell-group>
<t-cell-group
v-for="group in visibleMenuGroupList"
:key="group.title"
:title="group.title"
theme="card"
v-entrance-transition="{ step: 30 }"
>
<t-cell
v-for="item in group.items"
:key="item.path"
class="item"
:title="item.title"
arrow
hover
@click="go(item)"
>
<template #leftIcon>
<t-icon :name="item.icon" size="1.75rem" />
</template>
</t-cell>
</t-cell-group>
<footer class="footer">
<p>技术支持:夜雨</p>
<p>Copyright © 2026 imyeyu.com</p>
</footer>
</template>
</t-cell>
</t-cell-group>
<t-cell-group
v-for="group in visibleMenuGroupList"
:key="group.title"
:title="group.title"
theme="card"
v-entrance-transition="{ step: 30 }"
>
<t-cell
v-for="item in group.items"
:key="item.path"
class="item"
:title="item.title"
arrow
hover
@click="go(item)"
>
<template #leftIcon>
<t-icon :name="item.icon" size="1.75rem" />
</template>
</t-cell>
</t-cell-group>
</div>
<footer class="footer">
<p>技术支持:夜雨</p>
<p>Copyright © 2026 imyeyu.com</p>
</footer>
</div>
</main>
</template>
@@ -333,6 +337,54 @@ onBeforeRouteLeave(() => {
.management-tab {
gap: .5rem;
.tab-body {
--tab-body-max: 72rem;
}
/**
* 平板起分组卡片并排,同一行的卡片拉伸等高(默认 stretch),
* 账户卡片独占一行当页头——它只有一条 cell,
* 和分组卡片并排会在下面留下一大块空白。
* 手机上仍是单列,间距保持 .5rem。
*/
.menu-grid {
gap: .5rem;
display: grid;
padding: 0 1rem;
grid-template-columns: minmax(0, 1fr);
// 卡片自带 16px 外边距,进栅格后间距交给容器的 padding 和 gap
:deep(.t-cell-group--card) {
margin: 0;
}
@media (min-width: 48rem) {
gap: .75rem;
grid-template-columns: repeat(2, minmax(0, 1fr));
.user-card {
grid-column: 1 / -1;
}
/**
* cell-group 的白色在 cell 上,根节点被拉伸后下半截是透明的,
* 同行的卡片看起来还是高矮不一;把容器色补到根上才是真正等高。
* 标题自带的灰底在卡片里会变成一条灰带,一并清掉。
*/
:deep(.t-cell-group--card) {
background: var(--td-bg-color-container, #fff);
.t-cell-group__title {
background: transparent;
}
}
}
@media (min-width: 80rem) {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
.user-card {
.info {
+6 -201
View File
@@ -3,7 +3,7 @@
<template #right>
<t-button
aria-label="刷新"
@click="refreshCharts"
@click="storeOverviewRef?.refresh()"
theme="default"
variant="text"
size="small"
@@ -13,213 +13,18 @@
</template>
</t-navbar>
<main class="tui-page-content scroll column store-tab">
<t-cell-group
v-if="canViewStore || canManageStore"
theme="card"
v-entrance-transition
>
<t-cell
v-if="canViewStore"
class="info"
:title="currentStoreStore.currentStoreName"
:description="currentStore?.address"
/>
<t-cell
v-if="canSelectStore"
class="action"
title="切换门店"
note="选择使用门店"
arrow
hover
@click="openStorePicker"
>
<template #leftIcon>
<t-icon name="swap" />
</template>
</t-cell>
<t-cell
v-if="canManageStore"
class="action"
title="门店管理"
note="管理门店资料和营业日"
arrow
hover
@click="goStoreManagement"
>
<template #leftIcon>
<t-icon name="shop-3" />
</template>
</t-cell>
<t-cell
v-if="canManageStoreDiary"
class="action"
title="门店日记"
note="记录门店经营日常"
arrow
hover
@click="goStoreDiaryManagement"
>
<template #leftIcon>
<t-icon name="file" />
</template>
</t-cell>
</t-cell-group>
<store-data-charts :key="`${currentStoreStore.currentStoreId}-${chartRefreshKey}`" />
<t-popup v-model="storePickerVisible" placement="bottom">
<t-picker
v-model="storePickerDraft"
:columns="storePickerColumns"
title="切换门店"
@cancel="storePickerVisible = false"
@confirm="confirmStorePicker"
/>
</t-popup>
<div class="tab-body">
<store-overview ref="storeOverviewRef" />
</div>
</main>
</template>
<script setup lang="ts">
import { Message } from "@/utils/message";
import { useUserStore } from "timi-web-api";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { clearStoreChartCache } from "@/utils/storeChartCache";
import { gaoRoleCodes, gaoStoreScopePermissionCodes, permissionCodes } from "@/utils/permission";
type PickerValue = string | number;
const StoreDataCharts = defineAsyncComponent(() => import("@/pages/store/component/StoreDataCharts.vue"));
import StoreOverview from "@/pages/tabs/component/StoreOverview.vue";
defineOptions({
name: "StoreTab"
});
const router = useRouter();
const userStore = useUserStore();
const currentStoreStore = useCurrentStoreStore();
const chartRefreshKey = ref(0);
const currentStore = computed(() => currentStoreStore.currentStore);
const canSelectStore = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
const canLoadLoginStore = computed(() => userStore.hasPermissions(gaoStoreScopePermissionCodes, "or"));
const canViewStore = computed(() => canSelectStore.value || canLoadLoginStore.value);
const canManageStore = computed(() => userStore.hasRoles([
gaoRoleCodes.globalManager,
gaoRoleCodes.storeManager
], "or") && userStore.hasPermissions(permissionCodes.store.read));
const canManageStoreDiary = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager)
&& userStore.hasPermissions(permissionCodes.storeDiary.create));
// ---------- 门店切换 ----------
const storePickerVisible = ref(false);
const storePickerDraft = ref<PickerValue[]>([]);
const storePickerColumns = computed(() => [
currentStoreStore.storeList.map(item => ({
label: item.name || item.code || "未命名门店",
value: item.id || ""
})).filter(item => item.value)
]);
function openStorePicker(): void {
if (!canSelectStore.value) {
return;
}
if (!currentStoreStore.storeList.length) {
Message.warning("暂无可选门店");
return;
}
storePickerDraft.value = [currentStoreStore.currentStoreId];
storePickerVisible.value = true;
}
function confirmStorePicker(): void {
const storeId = String(storePickerDraft.value[0] || "");
if (!storeId) {
return;
}
currentStoreStore.selectStore(storeId);
storePickerVisible.value = false;
Message.success("当前门店已切换");
}
function refreshCharts(): void {
clearStoreChartCache();
chartRefreshKey.value++;
}
// ---------- 门店管理 ----------
async function goStoreManagement(): Promise<void> {
if (canSelectStore.value) {
await router.push("/management/stores");
return;
}
const store = await currentStoreStore.loadLoginStore();
if (!store?.id) {
Message.warning("未绑定所属门店");
return;
}
await router.push(`/management/stores/${store.id}`);
}
async function goStoreDiaryManagement(): Promise<void> {
if (!canManageStoreDiary.value) {
return;
}
const store = await currentStoreStore.loadLoginStore();
if (!store?.id) {
Message.warning("未绑定所属门店");
return;
}
await router.push({ name: "StoreDiaryList" });
}
onMounted(async () => {
if (canSelectStore.value) {
await currentStoreStore.loadStoreList();
} else if (canLoadLoginStore.value) {
await currentStoreStore.loadLoginStore();
}
});
const storeOverviewRef = ref<InstanceType<typeof StoreOverview>>();
</script>
<style scoped lang="less">
.store-tab {
.store-header {
.store-card {
.info {
:deep(.t-cell__title-text) {
font-size: 1.5rem;
}
}
}
}
}
:global(html.theme-dark) {
.store-tab {
.store-card {
.info {
:deep(.t-cell__description) {
color: #94a3b8;
}
}
}
}
}
</style>
@@ -0,0 +1,258 @@
<template>
<div class="entry-panel">
<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.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>
</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>
</div>
</div>
</template>
<script setup lang="ts">
import { useUserStore } from "timi-web-api";
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
defineOptions({
name: "CustomerEntryPanel"
});
const router = useRouter();
const userStore = useUserStore();
interface HomeEntry {
path: string;
permission: string;
icon: string;
title: string;
/** 高频入口:沿用实心主色卡片 */
quick?: boolean;
}
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: "快速扫码登记",
quick: true
}
]
},
{
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: "快速履约",
quick: true
},
{
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 canUseAi = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager));
async function openAiChat(): Promise<void> {
await router.push("/ai/chat");
}
</script>
<style scoped lang="less">
.entry-panel {
.entry-group {
margin: 0 1rem;
& + & {
margin-top: 1.5rem;
}
> h2 {
color: #52607a;
margin: 0 0 .75rem 0;
font-size: .875rem;
font-weight: 700;
}
.items {
--td-button-border-radius: 1.75rem;
// 按最小宽度铺排:手机刚好吃下 3 列,平板自动加列而不是把卡片放大
gap: .875rem;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(6.5rem, 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;
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;
}
}
}
}
}
.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);
}
}
}
// :global 必须包住整条选择器,只包第一个 compound 时后代选择器会被编译器丢掉
:global(html.theme-dark .entry-panel .entry-group > h2) {
color: #94a3b8;
}
:global(html.theme-dark .entry-panel .entry-group .item) {
--entry-background: rgba(15, 23, 42, .88);
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
}
</style>
@@ -0,0 +1,60 @@
<template>
<t-badge
v-if="canRead"
class="notify-button"
:count="unreadCount"
: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>
</template>
<script setup lang="ts">
import { NotifyAPI, useUserStore } from "timi-web-api";
import { corePermissionCodes } from "@/utils/permission";
defineOptions({
name: "NavbarNotifyButton"
});
const router = useRouter();
const userStore = useUserStore();
const unreadCount = ref(0);
const canRead = computed(() => userStore.hasPermissions(corePermissionCodes.notify.read));
async function loadUnreadCount(): Promise<void> {
try {
unreadCount.value = Math.max(0, await NotifyAPI.countUnreadInternal());
} catch (error) {
unreadCount.value = 0;
console.warn("未读通知数量加载失败", error);
}
}
onMounted(async () => {
if (canRead.value) {
await loadUnreadCount();
}
});
</script>
<style scoped lang="less">
.notify-button {
:deep(.t-badge__content) {
display: flex;
align-items: center;
}
}
</style>
+206
View File
@@ -0,0 +1,206 @@
<template>
<t-cell-group
v-if="canViewStore || canManageStore"
class="store-card"
theme="card"
v-entrance-transition
>
<t-cell
v-if="canViewStore"
class="info"
:title="currentStoreStore.currentStoreName"
:description="currentStore?.address"
/>
<t-cell
v-if="canSelectStore"
class="action"
title="切换门店"
note="选择使用门店"
arrow
hover
@click="openStorePicker"
>
<template #leftIcon>
<t-icon name="swap" />
</template>
</t-cell>
<t-cell
v-if="canManageStore"
class="action"
title="门店管理"
note="管理门店资料和营业日"
arrow
hover
@click="goStoreManagement"
>
<template #leftIcon>
<t-icon name="shop-3" />
</template>
</t-cell>
<t-cell
v-if="canManageStoreDiary"
class="action"
title="门店日记"
note="记录门店经营日常"
arrow
hover
@click="goStoreDiaryManagement"
>
<template #leftIcon>
<t-icon name="file" />
</template>
</t-cell>
</t-cell-group>
<store-data-charts
:key="`${currentStoreStore.currentStoreId}-${chartRefreshKey}`"
:compact="compact"
/>
<t-popup v-model="storePickerVisible" placement="bottom">
<t-picker
v-model="storePickerDraft"
:columns="storePickerColumns"
title="切换门店"
@cancel="storePickerVisible = false"
@confirm="confirmStorePicker"
/>
</t-popup>
</template>
<script setup lang="ts">
import { Message } from "@/utils/message";
import { useUserStore } from "timi-web-api";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { clearStoreChartCache } from "@/utils/storeChartCache";
import { gaoRoleCodes, gaoStoreScopePermissionCodes, permissionCodes } from "@/utils/permission";
type PickerValue = string | number;
const StoreDataCharts = defineAsyncComponent(() => import("@/pages/store/component/StoreDataCharts.vue"));
withDefaults(defineProps<{
/** 窄栏(平板横屏的左侧分栏)里图表改为单列 */
compact?: boolean;
}>(), {
compact: false
});
defineOptions({
name: "StoreOverview"
});
const router = useRouter();
const userStore = useUserStore();
const currentStoreStore = useCurrentStoreStore();
const chartRefreshKey = ref(0);
const currentStore = computed(() => currentStoreStore.currentStore);
const canSelectStore = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
const canLoadLoginStore = computed(() => userStore.hasPermissions(gaoStoreScopePermissionCodes, "or"));
const canViewStore = computed(() => canSelectStore.value || canLoadLoginStore.value);
const canManageStore = computed(() => userStore.hasRoles([
gaoRoleCodes.globalManager,
gaoRoleCodes.storeManager
], "or") && userStore.hasPermissions(permissionCodes.store.read));
const canManageStoreDiary = computed(() => userStore.hasRoles(gaoRoleCodes.storeManager)
&& userStore.hasPermissions(permissionCodes.storeDiary.create));
// ---------- 门店切换 ----------
const storePickerVisible = ref(false);
const storePickerDraft = ref<PickerValue[]>([]);
const storePickerColumns = computed(() => [
currentStoreStore.storeList.map(item => ({
label: item.name || item.code || "未命名门店",
value: item.id || ""
})).filter(item => item.value)
]);
function openStorePicker(): void {
if (!canSelectStore.value) {
return;
}
if (!currentStoreStore.storeList.length) {
Message.warning("暂无可选门店");
return;
}
storePickerDraft.value = [currentStoreStore.currentStoreId];
storePickerVisible.value = true;
}
function confirmStorePicker(): void {
const storeId = String(storePickerDraft.value[0] || "");
if (!storeId) {
return;
}
currentStoreStore.selectStore(storeId);
storePickerVisible.value = false;
Message.success("当前门店已切换");
}
function refresh(): void {
clearStoreChartCache();
chartRefreshKey.value++;
}
// ---------- 门店管理 ----------
async function goStoreManagement(): Promise<void> {
if (canSelectStore.value) {
await router.push("/management/stores");
return;
}
const store = await currentStoreStore.loadLoginStore();
if (!store?.id) {
Message.warning("未绑定所属门店");
return;
}
await router.push(`/management/stores/${store.id}`);
}
async function goStoreDiaryManagement(): Promise<void> {
if (!canManageStoreDiary.value) {
return;
}
const store = await currentStoreStore.loadLoginStore();
if (!store?.id) {
Message.warning("未绑定所属门店");
return;
}
await router.push({ name: "StoreDiaryList" });
}
onMounted(async () => {
if (canSelectStore.value) {
await currentStoreStore.loadStoreList();
} else if (canLoadLoginStore.value) {
await currentStoreStore.loadLoginStore();
}
});
defineExpose({
refresh
});
</script>
<style scoped lang="less">
.store-card {
// 门店资料卡只有几行,平板上限宽居中,避免拉成整屏宽的空卡片
@media (min-width: 48rem) {
max-width: 40rem;
margin: 0 auto;
}
}
// :global 必须包住整条选择器,只包第一个 compound 时后代选择器会被编译器丢掉
:global(html.theme-dark .store-card .info .t-cell__description) {
color: #94a3b8;
}
</style>