add TabSplitView

This commit is contained in:
Timi
2026-11-03 17:01:29 +08:00
parent 1a0cdd2181
commit a5fa855031
12 changed files with 1157 additions and 963 deletions
+2
View File
@@ -144,4 +144,6 @@ components.d.ts
# ---> 本地调试产物(CDP 截图、登录态、一次性脚本)
/.debug-tmp/
/.debug-*/
/.debug-*.png
+4 -328
View File
@@ -9,7 +9,7 @@
<template #right>
<t-button
aria-label="刷新"
@click="reload"
@click="panelRef?.reload()"
theme="default"
variant="text"
size="small"
@@ -18,339 +18,15 @@
</t-button>
</template>
</t-navbar>
<div v-can="permissionCodes.stat.read" class="gao-chart-page order-data-charts">
<section class="hero">
<div class="eyebrow" v-text="'订单经营分析'" />
<h1 v-text="'客户经营看板'" />
<p v-text="`${currentStoreStore.currentStoreName} · 订单、收款与客户贡献 · 近 1 个月`" />
</section>
<div v-if="!storeId" class="no-store">
<t-empty description="暂无可统计的门店" />
</div>
<template v-else>
<section class="summary">
<div v-for="item in summaryList" :key="item.label" class="summary-item">
<span v-text="item.label" />
<strong v-text="item.value" />
</div>
</section>
<div class="chart-list">
<order-daily-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="dailyList"
:loading="isLoading"
/>
<div class="two-columns">
<order-type-chart
v-entrance-transition
:list="typeList"
:loading="isLoading"
/>
<order-payment-chart
v-entrance-transition
:list="paymentList"
:loading="isLoading"
/>
</div>
<div class="two-columns">
<order-status-chart
v-entrance-transition
:list="statusList"
:loading="isLoading"
/>
<customer-order-rank-chart
v-entrance-transition
:list="customerRankList"
:loading="isLoading"
/>
</div>
<order-receivable-card
v-entrance-transition
:receivable="receivable"
/>
</div>
</template>
</div>
<order-charts-panel ref="panelRef" />
</template>
<script setup lang="ts">
import GaoSalesOrderChartAPI from "@/api/GaoSalesOrderChartAPI";
import CustomerOrderRankChart from "@/pages/product/component/CustomerOrderRankChart.vue";
import OrderDailyChart from "@/pages/product/component/OrderDailyChart.vue";
import OrderPaymentChart from "@/pages/product/component/OrderPaymentChart.vue";
import OrderReceivableCard from "@/pages/product/component/OrderReceivableCard.vue";
import OrderStatusChart from "@/pages/product/component/OrderStatusChart.vue";
import OrderTypeChart from "@/pages/product/component/OrderTypeChart.vue";
import type {
GaoCustomerOrderRankView,
GaoSalesOrderDailyStatView,
GaoSalesOrderPaymentStatView,
GaoSalesOrderReceivableStatView,
GaoSalesOrderStatusStatView,
GaoSalesOrderTypeStatView
} from "@/types/GaoChart";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { clearStoreChartCache } from "@/utils/storeChartCache";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { buildDateTextList, formatMoney, formatQuantity, toUnixRange } from "@/pages/product/component/chartUtils";
import { getCurrentStoreId } from "@/utils/store";
interface SummaryItem {
label: string;
value: string;
}
import OrderChartsPanel from "@/pages/product/component/OrderChartsPanel.vue";
defineOptions({
name: "OrderDataCharts"
});
const currentStoreStore = useCurrentStoreStore();
const dateRange = buildDefaultDateRange();
const dateTextList = buildDateTextList(dateRange[0], dateRange[1]);
const dailyList = ref<GaoSalesOrderDailyStatView[]>([]);
const typeList = ref<GaoSalesOrderTypeStatView[]>([]);
const paymentList = ref<GaoSalesOrderPaymentStatView[]>([]);
const statusList = ref<GaoSalesOrderStatusStatView[]>([]);
const customerRankList = ref<GaoCustomerOrderRankView[]>([]);
const receivable = ref<GaoSalesOrderReceivableStatView>({});
const isLoading = ref(false);
let requestId = 0;
const storeId = computed(() => currentStoreStore.currentStoreId || getCurrentStoreId());
const summaryList = computed<SummaryItem[]>(() => [
{
label: "订单数",
value: `${formatQuantity(receivable.value.orderCount)} 单`
},
{
label: "成交金额",
value: formatMoney(receivable.value.saleAmount)
},
{
label: "有效收款",
value: formatMoney(receivable.value.paidAmount)
},
{
label: "未收金额",
value: formatMoney(receivable.value.unpaidAmount)
},
{
label: "净收款",
value: formatMoney(receivable.value.netPaidAmount)
}
]);
watch(storeId, async () => {
await loadCharts();
}, { immediate: true });
onMounted(async () => {
if (!currentStoreStore.currentStoreId) {
await currentStoreStore.loadLoginStore();
}
});
async function reload(): Promise<void> {
clearStoreChartCache();
await loadCharts();
}
async function loadCharts(): Promise<void> {
if (!storeId.value) {
clearData();
return;
}
const currentRequestId = ++requestId;
isLoading.value = true;
try {
const range = toUnixRange(dateRange);
const request = { storeId: storeId.value, ...range, topN: 10 };
const [daily, type, payment, status, receivableData, customerRank] = await Promise.all([
GaoSalesOrderChartAPI.daily(request),
GaoSalesOrderChartAPI.type(request),
GaoSalesOrderChartAPI.payment(request),
GaoSalesOrderChartAPI.status(request),
GaoSalesOrderChartAPI.receivable(request),
GaoSalesOrderChartAPI.customerRank(request)
]);
if (currentRequestId !== requestId) {
return;
}
dailyList.value = daily || [];
typeList.value = type || [];
paymentList.value = payment || [];
statusList.value = status || [];
receivable.value = receivableData || {};
customerRankList.value = customerRank || [];
} catch (error) {
if (currentRequestId === requestId) {
Message.error(getErrorMessage(error, "订单图表加载失败"));
}
} finally {
if (currentRequestId === requestId) {
isLoading.value = false;
}
}
}
function clearData(): void {
isLoading.value = false;
dailyList.value = [];
typeList.value = [];
paymentList.value = [];
statusList.value = [];
receivable.value = {};
customerRankList.value = [];
}
function buildDefaultDateRange(): [string, string] {
const end = getDateEnd(new Date());
const today = getDateStart(end);
const beginMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1, 0, 0, 0, 0);
const lastDayOfBeginMonth = new Date(beginMonth.getFullYear(), beginMonth.getMonth() + 1, 0).getDate();
const begin = new Date(beginMonth);
begin.setDate(Math.min(today.getDate(), lastDayOfBeginMonth));
return [formatDateTime(begin), formatDateTime(end)];
}
function getDateStart(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
}
function getDateEnd(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
}
function formatDateTime(date: Date): string {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
function pad(value: number): string {
return String(value).padStart(2, "0");
}
const panelRef = ref<InstanceType<typeof OrderChartsPanel>>();
</script>
<style scoped lang="less">
.gao-chart-page {
gap: 1rem;
padding: calc(var(--tui-nav-height) + 1rem) 1rem 1rem;
display: flex;
flex-direction: column;
.hero {
padding: .25rem .25rem 0;
.eyebrow {
color: var(--td-brand-color);
font-size: .6875rem;
font-weight: 700;
letter-spacing: .12em;
}
h1 {
color: #0f172a;
margin: .25rem 0 0;
font-size: 1.5rem;
line-height: 1.3;
}
p {
color: #7b889d;
margin: .375rem 0 0;
font-size: .8125rem;
}
}
.summary {
gap: .625rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.summary-item {
padding: .75rem .625rem;
background: rgba(255, 255, 255, .92);
box-shadow: var(--td-shadow-1);
border-radius: 1rem;
span {
color: #52607a;
display: block;
font-size: .75rem;
}
strong {
color: #0f172a;
margin-top: .25rem;
display: block;
font-size: 1rem;
font-weight: 700;
}
}
.chart-list {
gap: 1rem;
display: flex;
flex-direction: column;
}
.two-columns {
gap: 1rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.no-store {
padding: 1.5rem 0;
display: flex;
align-items: center;
justify-content: center;
}
}
:global(html.theme-dark) {
.gao-chart-page {
.hero {
h1 {
color: #e2e8f0;
}
p {
color: #94a3b8;
}
}
.summary-item {
background: rgba(15, 23, 42, .88);
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
span {
color: #94a3b8;
}
strong {
color: #e2e8f0;
}
}
}
}
@media (max-width: 42rem) {
.gao-chart-page {
.two-columns {
grid-template-columns: 1fr;
}
}
}
</style>
+4 -346
View File
@@ -9,7 +9,7 @@
<template #right>
<t-button
aria-label="刷新"
@click="reload"
@click="panelRef?.reload()"
theme="default"
variant="text"
size="small"
@@ -18,357 +18,15 @@
</t-button>
</template>
</t-navbar>
<div v-can="permissionCodes.stat.read" class="gao-chart-page product-data-charts">
<section class="hero">
<div class="eyebrow" v-text="'产品经营分析'" />
<h1 v-text="'产品经营看板'" />
<p v-text="`${currentStoreStore.currentStoreName} · 销售、履约与库存 · 近 1 个月`" />
</section>
<div v-if="!storeId" class="no-store">
<t-empty description="暂无可统计的门店" />
</div>
<template v-else>
<section class="summary">
<div v-for="item in summaryList" :key="item.label" class="summary-item">
<span v-text="item.label" />
<strong v-text="item.value" />
</div>
</section>
<div class="chart-list">
<product-sales-trend-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="salesDailyList"
:loading="isLoading"
/>
<div class="two-columns">
<product-sales-rank-chart
v-entrance-transition
:list="salesRankList"
:loading="isLoading"
/>
<product-fulfillment-rank-chart
v-entrance-transition
:list="fulfillmentRankList"
:loading="isLoading"
/>
</div>
<product-fulfillment-trend-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="fulfillmentDailyList"
:loading="isLoading"
/>
<product-stock-movement-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="stockMovementList"
:loading="isLoading"
/>
<product-stock-health-table
v-entrance-transition
:list="stockHealthList"
:sku-health-list="skuHealthList"
:loading="isLoading"
/>
</div>
</template>
</div>
<product-charts-panel ref="panelRef" />
</template>
<script setup lang="ts">
import GaoProductChartAPI from "@/api/GaoProductChartAPI";
import GaoProductSkuChartAPI from "@/api/GaoProductSkuChartAPI";
import ProductFulfillmentRankChart from "@/pages/product/component/ProductFulfillmentRankChart.vue";
import ProductFulfillmentTrendChart from "@/pages/product/component/ProductFulfillmentTrendChart.vue";
import ProductSalesRankChart from "@/pages/product/component/ProductSalesRankChart.vue";
import ProductSalesTrendChart from "@/pages/product/component/ProductSalesTrendChart.vue";
import ProductStockHealthTable from "@/pages/product/component/ProductStockHealthTable.vue";
import ProductStockMovementChart from "@/pages/product/component/ProductStockMovementChart.vue";
import type {
GaoProductFulfillmentDailyStatView,
GaoProductFulfillmentRankView,
GaoProductSalesDailyStatView,
GaoProductSalesRankView,
GaoProductStockHealthView,
GaoProductStockMovementDailyStatView,
GaoProductSkuStockHealthView
} from "@/types/GaoChart";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { clearStoreChartCache } from "@/utils/storeChartCache";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { buildDateTextList, formatMoney, formatQuantity, sumNumber, toUnixRange } from "@/pages/product/component/chartUtils";
import { getCurrentStoreId } from "@/utils/store";
interface SummaryItem {
label: string;
value: string;
}
import ProductChartsPanel from "@/pages/product/component/ProductChartsPanel.vue";
defineOptions({
name: "ProductDataCharts"
});
const currentStoreStore = useCurrentStoreStore();
const dateRange = buildDefaultDateRange();
const dateTextList = buildDateTextList(dateRange[0], dateRange[1]);
const salesDailyList = ref<GaoProductSalesDailyStatView[]>([]);
const salesRankList = ref<GaoProductSalesRankView[]>([]);
const fulfillmentDailyList = ref<GaoProductFulfillmentDailyStatView[]>([]);
const fulfillmentRankList = ref<GaoProductFulfillmentRankView[]>([]);
const stockMovementList = ref<GaoProductStockMovementDailyStatView[]>([]);
const stockHealthList = ref<GaoProductStockHealthView[]>([]);
const skuHealthList = ref<GaoProductSkuStockHealthView[]>([]);
const isLoading = ref(false);
let requestId = 0;
const storeId = computed(() => currentStoreStore.currentStoreId || getCurrentStoreId());
const summaryList = computed<SummaryItem[]>(() => [
{
label: "订单数",
value: `${formatQuantity(sumNumber(salesDailyList.value, item => item.orderCount))} 单`
},
{
label: "直接销量",
value: formatQuantity(sumNumber(salesDailyList.value, item => item.directBaseQuantity))
},
{
label: "套餐权益",
value: formatQuantity(sumNumber(salesDailyList.value, item => item.packageBaseQuantity))
},
{
label: "直接销售额",
value: formatMoney(sumNumber(salesDailyList.value, item => item.directSaleAmount))
},
{
label: "低库存产品",
value: `${stockHealthList.value.filter(item => 0 < (item.lowStockSkuCount || 0)).length} 个`
}
]);
watch(storeId, async () => {
await loadCharts();
}, { immediate: true });
onMounted(async () => {
if (!currentStoreStore.currentStoreId) {
await currentStoreStore.loadLoginStore();
}
});
async function reload(): Promise<void> {
clearStoreChartCache();
await loadCharts();
}
async function loadCharts(): Promise<void> {
if (!storeId.value) {
clearData();
return;
}
const currentRequestId = ++requestId;
isLoading.value = true;
try {
const range = toUnixRange(dateRange);
const rangeRequest = { storeId: storeId.value, ...range, topN: 10 };
const snapshotRequest = { storeId: storeId.value };
const [salesDaily, salesRank, fulfillmentDaily, fulfillmentRank, stockMovement, stockHealth] = await Promise.all([
GaoProductChartAPI.salesDaily(rangeRequest),
GaoProductChartAPI.salesRank(rangeRequest),
GaoProductChartAPI.fulfillmentDaily(rangeRequest),
GaoProductChartAPI.fulfillmentRank(rangeRequest),
GaoProductChartAPI.stockMovementDaily(rangeRequest),
GaoProductChartAPI.stockHealth(snapshotRequest)
]);
if (currentRequestId !== requestId) {
return;
}
salesDailyList.value = salesDaily || [];
salesRankList.value = salesRank || [];
fulfillmentDailyList.value = fulfillmentDaily || [];
fulfillmentRankList.value = fulfillmentRank || [];
stockMovementList.value = stockMovement || [];
stockHealthList.value = stockHealth || [];
skuHealthList.value = [];
if (stockHealthList.value.some(item => 0 < (item.lowStockSkuCount || 0))) {
try {
const skuHealth = await GaoProductSkuChartAPI.stockHealth({ storeId: storeId.value });
if (currentRequestId === requestId) {
skuHealthList.value = (skuHealth || []).filter(item => item.lowStock === 1);
}
} catch (error) {
Message.warning(getErrorMessage(error, "低库存规格明细加载失败"));
}
}
} catch (error) {
if (currentRequestId === requestId) {
Message.error(getErrorMessage(error, "产品图表加载失败"));
}
} finally {
if (currentRequestId === requestId) {
isLoading.value = false;
}
}
}
function clearData(): void {
isLoading.value = false;
salesDailyList.value = [];
salesRankList.value = [];
fulfillmentDailyList.value = [];
fulfillmentRankList.value = [];
stockMovementList.value = [];
stockHealthList.value = [];
skuHealthList.value = [];
}
function buildDefaultDateRange(): [string, string] {
const end = getDateEnd(new Date());
const today = getDateStart(end);
const beginMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1, 0, 0, 0, 0);
const lastDayOfBeginMonth = new Date(beginMonth.getFullYear(), beginMonth.getMonth() + 1, 0).getDate();
const begin = new Date(beginMonth);
begin.setDate(Math.min(today.getDate(), lastDayOfBeginMonth));
return [formatDateTime(begin), formatDateTime(end)];
}
function getDateStart(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
}
function getDateEnd(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
}
function formatDateTime(date: Date): string {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
function pad(value: number): string {
return String(value).padStart(2, "0");
}
const panelRef = ref<InstanceType<typeof ProductChartsPanel>>();
</script>
<style scoped lang="less">
.gao-chart-page {
gap: 1rem;
padding: calc(var(--tui-nav-height) + 1rem) 1rem 1rem;
display: flex;
flex-direction: column;
.hero {
padding: .25rem .25rem 0;
.eyebrow {
color: var(--td-brand-color);
font-size: .6875rem;
font-weight: 700;
letter-spacing: .12em;
}
h1 {
color: #0f172a;
margin: .25rem 0 0;
font-size: 1.5rem;
line-height: 1.3;
}
p {
color: #7b889d;
margin: .375rem 0 0;
font-size: .8125rem;
}
}
.summary {
gap: .625rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.summary-item {
padding: .75rem .625rem;
background: rgba(255, 255, 255, .92);
box-shadow: var(--td-shadow-1);
border-radius: 1rem;
span {
color: #52607a;
display: block;
font-size: .75rem;
}
strong {
color: #0f172a;
margin-top: .25rem;
display: block;
font-size: 1rem;
font-weight: 700;
}
}
.chart-list {
gap: 1rem;
display: flex;
flex-direction: column;
}
.two-columns {
gap: 1rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.no-store {
padding: 1.5rem 0;
display: flex;
align-items: center;
justify-content: center;
}
}
:global(html.theme-dark) {
.gao-chart-page {
.hero {
h1 {
color: #e2e8f0;
}
p {
color: #94a3b8;
}
}
.summary-item {
background: rgba(15, 23, 42, .88);
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
span {
color: #94a3b8;
}
strong {
color: #e2e8f0;
}
}
}
}
@media (max-width: 42rem) {
.gao-chart-page {
.two-columns {
grid-template-columns: 1fr;
}
}
}
</style>
@@ -0,0 +1,345 @@
<template>
<div
v-can="permissionCodes.stat.read"
class="gao-chart-page"
:class="{ embedded, compact }"
>
<section class="hero" v-entrance-transition>
<div class="eyebrow" v-text="'订单经营分析'" />
<h1 v-text="'客户经营看板'" />
<p v-text="`${currentStoreStore.currentStoreName} · 订单、收款与客户贡献 · 近 1 个月`" />
</section>
<div v-if="!storeId" class="no-store" v-entrance-transition>
<t-empty description="暂无可统计的门店" />
</div>
<template v-else>
<section class="summary">
<div
v-for="item in summaryList"
:key="item.label"
class="summary-item"
v-entrance-transition="{ step: 30 }"
>
<span v-text="item.label" />
<strong v-text="item.value" />
</div>
</section>
<div class="chart-list">
<order-daily-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="dailyList"
:loading="isLoading"
/>
<div class="two-columns">
<order-type-chart
v-entrance-transition
:list="typeList"
:loading="isLoading"
/>
<order-payment-chart
v-entrance-transition
:list="paymentList"
:loading="isLoading"
/>
</div>
<div class="two-columns">
<order-status-chart
v-entrance-transition
:list="statusList"
:loading="isLoading"
/>
<customer-order-rank-chart
v-entrance-transition
:list="customerRankList"
:loading="isLoading"
/>
</div>
<order-receivable-card
v-entrance-transition
:receivable="receivable"
/>
</div>
</template>
</div>
</template>
<script setup lang="ts">
import GaoSalesOrderChartAPI from "@/api/GaoSalesOrderChartAPI";
import CustomerOrderRankChart from "@/pages/product/component/CustomerOrderRankChart.vue";
import OrderDailyChart from "@/pages/product/component/OrderDailyChart.vue";
import OrderPaymentChart from "@/pages/product/component/OrderPaymentChart.vue";
import OrderReceivableCard from "@/pages/product/component/OrderReceivableCard.vue";
import OrderStatusChart from "@/pages/product/component/OrderStatusChart.vue";
import OrderTypeChart from "@/pages/product/component/OrderTypeChart.vue";
import type {
GaoCustomerOrderRankView,
GaoSalesOrderDailyStatView,
GaoSalesOrderPaymentStatView,
GaoSalesOrderReceivableStatView,
GaoSalesOrderStatusStatView,
GaoSalesOrderTypeStatView
} from "@/types/GaoChart";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { clearStoreChartCache } from "@/utils/storeChartCache";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { buildDateTextList, formatMoney, formatQuantity, toUnixRange } from "@/pages/product/component/chartUtils";
import { getCurrentStoreId } from "@/utils/store";
interface SummaryItem {
label: string;
value: string;
}
withDefaults(defineProps<{
/** 嵌在分栏里:顶部内边距交给栏内导航,不再自己让出导航高度 */
embedded?: boolean;
/** 窄栏里图表一律单列 */
compact?: boolean;
}>(), {
embedded: false,
compact: false
});
defineOptions({
name: "OrderChartsPanel"
});
const currentStoreStore = useCurrentStoreStore();
const dateRange = buildDefaultDateRange();
const dateTextList = buildDateTextList(dateRange[0], dateRange[1]);
const dailyList = ref<GaoSalesOrderDailyStatView[]>([]);
const typeList = ref<GaoSalesOrderTypeStatView[]>([]);
const paymentList = ref<GaoSalesOrderPaymentStatView[]>([]);
const statusList = ref<GaoSalesOrderStatusStatView[]>([]);
const customerRankList = ref<GaoCustomerOrderRankView[]>([]);
const receivable = ref<GaoSalesOrderReceivableStatView>({});
const isLoading = ref(false);
let requestId = 0;
const storeId = computed(() => currentStoreStore.currentStoreId || getCurrentStoreId());
const summaryList = computed<SummaryItem[]>(() => [
{
label: "订单数",
value: `${formatQuantity(receivable.value.orderCount)} 单`
},
{
label: "成交金额",
value: formatMoney(receivable.value.saleAmount)
},
{
label: "有效收款",
value: formatMoney(receivable.value.paidAmount)
},
{
label: "未收金额",
value: formatMoney(receivable.value.unpaidAmount)
},
{
label: "净收款",
value: formatMoney(receivable.value.netPaidAmount)
}
]);
watch(storeId, async () => {
await loadCharts();
}, { immediate: true });
onMounted(async () => {
if (!currentStoreStore.currentStoreId) {
await currentStoreStore.loadLoginStore();
}
});
async function reload(): Promise<void> {
clearStoreChartCache();
await loadCharts();
}
async function loadCharts(): Promise<void> {
if (!storeId.value) {
clearData();
return;
}
const currentRequestId = ++requestId;
isLoading.value = true;
try {
const range = toUnixRange(dateRange);
const request = { storeId: storeId.value, ...range, topN: 10 };
const [daily, type, payment, status, receivableData, customerRank] = await Promise.all([
GaoSalesOrderChartAPI.daily(request),
GaoSalesOrderChartAPI.type(request),
GaoSalesOrderChartAPI.payment(request),
GaoSalesOrderChartAPI.status(request),
GaoSalesOrderChartAPI.receivable(request),
GaoSalesOrderChartAPI.customerRank(request)
]);
if (currentRequestId !== requestId) {
return;
}
dailyList.value = daily || [];
typeList.value = type || [];
paymentList.value = payment || [];
statusList.value = status || [];
receivable.value = receivableData || {};
customerRankList.value = customerRank || [];
} catch (error) {
if (currentRequestId === requestId) {
Message.error(getErrorMessage(error, "订单图表加载失败"));
}
} finally {
if (currentRequestId === requestId) {
isLoading.value = false;
}
}
}
function clearData(): void {
isLoading.value = false;
dailyList.value = [];
typeList.value = [];
paymentList.value = [];
statusList.value = [];
receivable.value = {};
customerRankList.value = [];
}
function buildDefaultDateRange(): [string, string] {
const end = getDateEnd(new Date());
const today = getDateStart(end);
const beginMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1, 0, 0, 0, 0);
const lastDayOfBeginMonth = new Date(beginMonth.getFullYear(), beginMonth.getMonth() + 1, 0).getDate();
const begin = new Date(beginMonth);
begin.setDate(Math.min(today.getDate(), lastDayOfBeginMonth));
return [formatDateTime(begin), formatDateTime(end)];
}
function getDateStart(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
}
function getDateEnd(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
}
function formatDateTime(date: Date): string {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
function pad(value: number): string {
return String(value).padStart(2, "0");
}
defineExpose({
reload
});
</script>
<style scoped lang="less">
.gao-chart-page {
// 卡片配色走变量,深色模式只改 .gao-chart-page 上的变量值
--chart-bg: rgba(255, 255, 255, .92);
--chart-shadow: var(--td-shadow-1);
--chart-title: #0f172a;
--chart-text: #7b889d;
--chart-label: #52607a;
gap: 1rem;
padding: calc(var(--tui-nav-height) + 1rem) 1rem 1rem;
display: flex;
flex-direction: column;
// 分栏里顶部内边距由栏内导航负责
&.embedded {
padding: 0 1rem 1rem;
}
.hero {
padding: .25rem .25rem 0;
.eyebrow {
color: var(--td-brand-color);
font-size: .6875rem;
font-weight: 700;
letter-spacing: .12em;
}
h1 {
color: var(--chart-title);
margin: .25rem 0 0;
font-size: 1.5rem;
line-height: 1.3;
}
p {
color: var(--chart-text);
margin: .375rem 0 0;
font-size: .8125rem;
}
}
.summary {
gap: .625rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.summary-item {
padding: .75rem .625rem;
background: var(--chart-bg);
box-shadow: var(--chart-shadow);
border-radius: 1rem;
span {
color: var(--chart-label);
display: block;
font-size: .75rem;
}
strong {
color: var(--chart-title);
margin-top: .25rem;
display: block;
font-size: 1rem;
font-weight: 700;
}
}
.chart-list {
gap: 1rem;
display: flex;
flex-direction: column;
}
.two-columns {
gap: 1rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
// 分栏窄容器:双列图表一律改单列
&.compact {
.two-columns {
grid-template-columns: minmax(0, 1fr);
}
}
.no-store {
padding: 1.5rem 0;
display: flex;
align-items: center;
justify-content: center;
}
}
:global(html.theme-dark .gao-chart-page) {
--chart-bg: rgba(15, 23, 42, .88);
--chart-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
--chart-title: #e2e8f0;
--chart-text: #94a3b8;
--chart-label: #94a3b8;
}
</style>
@@ -0,0 +1,363 @@
<template>
<div
v-can="permissionCodes.stat.read"
class="gao-chart-page"
:class="{ embedded, compact }"
>
<section class="hero" v-entrance-transition>
<div class="eyebrow" v-text="'产品经营分析'" />
<h1 v-text="'产品经营看板'" />
<p v-text="`${currentStoreStore.currentStoreName} · 销售、履约与库存 · 近 1 个月`" />
</section>
<div v-if="!storeId" class="no-store" v-entrance-transition>
<t-empty description="暂无可统计的门店" />
</div>
<template v-else>
<section class="summary">
<div
v-for="item in summaryList"
:key="item.label"
class="summary-item"
v-entrance-transition="{ step: 30 }"
>
<span v-text="item.label" />
<strong v-text="item.value" />
</div>
</section>
<div class="chart-list">
<product-sales-trend-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="salesDailyList"
:loading="isLoading"
/>
<div class="two-columns">
<product-sales-rank-chart
v-entrance-transition
:list="salesRankList"
:loading="isLoading"
/>
<product-fulfillment-rank-chart
v-entrance-transition
:list="fulfillmentRankList"
:loading="isLoading"
/>
</div>
<product-fulfillment-trend-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="fulfillmentDailyList"
:loading="isLoading"
/>
<product-stock-movement-chart
v-entrance-transition
:date-text-list="dateTextList"
:list="stockMovementList"
:loading="isLoading"
/>
<product-stock-health-table
v-entrance-transition
:list="stockHealthList"
:sku-health-list="skuHealthList"
:loading="isLoading"
/>
</div>
</template>
</div>
</template>
<script setup lang="ts">
import GaoProductChartAPI from "@/api/GaoProductChartAPI";
import GaoProductSkuChartAPI from "@/api/GaoProductSkuChartAPI";
import ProductFulfillmentRankChart from "@/pages/product/component/ProductFulfillmentRankChart.vue";
import ProductFulfillmentTrendChart from "@/pages/product/component/ProductFulfillmentTrendChart.vue";
import ProductSalesRankChart from "@/pages/product/component/ProductSalesRankChart.vue";
import ProductSalesTrendChart from "@/pages/product/component/ProductSalesTrendChart.vue";
import ProductStockHealthTable from "@/pages/product/component/ProductStockHealthTable.vue";
import ProductStockMovementChart from "@/pages/product/component/ProductStockMovementChart.vue";
import type {
GaoProductFulfillmentDailyStatView,
GaoProductFulfillmentRankView,
GaoProductSalesDailyStatView,
GaoProductSalesRankView,
GaoProductStockHealthView,
GaoProductStockMovementDailyStatView,
GaoProductSkuStockHealthView
} from "@/types/GaoChart";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { clearStoreChartCache } from "@/utils/storeChartCache";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { buildDateTextList, formatMoney, formatQuantity, sumNumber, toUnixRange } from "@/pages/product/component/chartUtils";
import { getCurrentStoreId } from "@/utils/store";
interface SummaryItem {
label: string;
value: string;
}
withDefaults(defineProps<{
/** 嵌在分栏里:顶部内边距交给栏内导航,不再自己让出导航高度 */
embedded?: boolean;
/** 窄栏里图表一律单列 */
compact?: boolean;
}>(), {
embedded: false,
compact: false
});
defineOptions({
name: "ProductChartsPanel"
});
const currentStoreStore = useCurrentStoreStore();
const dateRange = buildDefaultDateRange();
const dateTextList = buildDateTextList(dateRange[0], dateRange[1]);
const salesDailyList = ref<GaoProductSalesDailyStatView[]>([]);
const salesRankList = ref<GaoProductSalesRankView[]>([]);
const fulfillmentDailyList = ref<GaoProductFulfillmentDailyStatView[]>([]);
const fulfillmentRankList = ref<GaoProductFulfillmentRankView[]>([]);
const stockMovementList = ref<GaoProductStockMovementDailyStatView[]>([]);
const stockHealthList = ref<GaoProductStockHealthView[]>([]);
const skuHealthList = ref<GaoProductSkuStockHealthView[]>([]);
const isLoading = ref(false);
let requestId = 0;
const storeId = computed(() => currentStoreStore.currentStoreId || getCurrentStoreId());
const summaryList = computed<SummaryItem[]>(() => [
{
label: "订单数",
value: `${formatQuantity(sumNumber(salesDailyList.value, item => item.orderCount))} 单`
},
{
label: "直接销量",
value: formatQuantity(sumNumber(salesDailyList.value, item => item.directBaseQuantity))
},
{
label: "套餐权益",
value: formatQuantity(sumNumber(salesDailyList.value, item => item.packageBaseQuantity))
},
{
label: "直接销售额",
value: formatMoney(sumNumber(salesDailyList.value, item => item.directSaleAmount))
},
{
label: "低库存产品",
value: `${stockHealthList.value.filter(item => 0 < (item.lowStockSkuCount || 0)).length} 个`
}
]);
watch(storeId, async () => {
await loadCharts();
}, { immediate: true });
onMounted(async () => {
if (!currentStoreStore.currentStoreId) {
await currentStoreStore.loadLoginStore();
}
});
async function reload(): Promise<void> {
clearStoreChartCache();
await loadCharts();
}
async function loadCharts(): Promise<void> {
if (!storeId.value) {
clearData();
return;
}
const currentRequestId = ++requestId;
isLoading.value = true;
try {
const range = toUnixRange(dateRange);
const rangeRequest = { storeId: storeId.value, ...range, topN: 10 };
const snapshotRequest = { storeId: storeId.value };
const [salesDaily, salesRank, fulfillmentDaily, fulfillmentRank, stockMovement, stockHealth] = await Promise.all([
GaoProductChartAPI.salesDaily(rangeRequest),
GaoProductChartAPI.salesRank(rangeRequest),
GaoProductChartAPI.fulfillmentDaily(rangeRequest),
GaoProductChartAPI.fulfillmentRank(rangeRequest),
GaoProductChartAPI.stockMovementDaily(rangeRequest),
GaoProductChartAPI.stockHealth(snapshotRequest)
]);
if (currentRequestId !== requestId) {
return;
}
salesDailyList.value = salesDaily || [];
salesRankList.value = salesRank || [];
fulfillmentDailyList.value = fulfillmentDaily || [];
fulfillmentRankList.value = fulfillmentRank || [];
stockMovementList.value = stockMovement || [];
stockHealthList.value = stockHealth || [];
skuHealthList.value = [];
if (stockHealthList.value.some(item => 0 < (item.lowStockSkuCount || 0))) {
try {
const skuHealth = await GaoProductSkuChartAPI.stockHealth({ storeId: storeId.value });
if (currentRequestId === requestId) {
skuHealthList.value = (skuHealth || []).filter(item => item.lowStock === 1);
}
} catch (error) {
Message.warning(getErrorMessage(error, "低库存规格明细加载失败"));
}
}
} catch (error) {
if (currentRequestId === requestId) {
Message.error(getErrorMessage(error, "产品图表加载失败"));
}
} finally {
if (currentRequestId === requestId) {
isLoading.value = false;
}
}
}
function clearData(): void {
isLoading.value = false;
salesDailyList.value = [];
salesRankList.value = [];
fulfillmentDailyList.value = [];
fulfillmentRankList.value = [];
stockMovementList.value = [];
stockHealthList.value = [];
skuHealthList.value = [];
}
function buildDefaultDateRange(): [string, string] {
const end = getDateEnd(new Date());
const today = getDateStart(end);
const beginMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1, 0, 0, 0, 0);
const lastDayOfBeginMonth = new Date(beginMonth.getFullYear(), beginMonth.getMonth() + 1, 0).getDate();
const begin = new Date(beginMonth);
begin.setDate(Math.min(today.getDate(), lastDayOfBeginMonth));
return [formatDateTime(begin), formatDateTime(end)];
}
function getDateStart(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
}
function getDateEnd(date: Date): Date {
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
}
function formatDateTime(date: Date): string {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
}
function pad(value: number): string {
return String(value).padStart(2, "0");
}
defineExpose({
reload
});
</script>
<style scoped lang="less">
.gao-chart-page {
// 卡片配色走变量,深色模式只改 .gao-chart-page 上的变量值
--chart-bg: rgba(255, 255, 255, .92);
--chart-shadow: var(--td-shadow-1);
--chart-title: #0f172a;
--chart-text: #7b889d;
--chart-label: #52607a;
gap: 1rem;
padding: calc(var(--tui-nav-height) + 1rem) 1rem 1rem;
display: flex;
flex-direction: column;
// 分栏里顶部内边距由栏内导航负责
&.embedded {
padding: 0 1rem 1rem;
}
.hero {
padding: .25rem .25rem 0;
.eyebrow {
color: var(--td-brand-color);
font-size: .6875rem;
font-weight: 700;
letter-spacing: .12em;
}
h1 {
color: var(--chart-title);
margin: .25rem 0 0;
font-size: 1.5rem;
line-height: 1.3;
}
p {
color: var(--chart-text);
margin: .375rem 0 0;
font-size: .8125rem;
}
}
.summary {
gap: .625rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.summary-item {
padding: .75rem .625rem;
background: var(--chart-bg);
box-shadow: var(--chart-shadow);
border-radius: 1rem;
span {
color: var(--chart-label);
display: block;
font-size: .75rem;
}
strong {
color: var(--chart-title);
margin-top: .25rem;
display: block;
font-size: 1rem;
font-weight: 700;
}
}
.chart-list {
gap: 1rem;
display: flex;
flex-direction: column;
}
.two-columns {
gap: 1rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
// 分栏窄容器:双列图表一律改单列
&.compact {
.two-columns {
grid-template-columns: minmax(0, 1fr);
}
}
.no-store {
padding: 1.5rem 0;
display: flex;
align-items: center;
justify-content: center;
}
}
:global(html.theme-dark .gao-chart-page) {
--chart-bg: rgba(15, 23, 42, .88);
--chart-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
--chart-title: #e2e8f0;
--chart-text: #94a3b8;
--chart-label: #94a3b8;
}
</style>
+33 -96
View File
@@ -10,45 +10,39 @@
<navbar-notify-button />
</template>
</t-navbar>
<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>
</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>
<!-- 平板横屏:门店与客户合并成一页,两栏各自保留导航栏 -->
<tab-split-view
v-if="mergedLayout"
left-title="门店"
right-title="客户"
>
<template #left-actions>
<t-button
aria-label="刷新"
@click="storeOverviewRef?.refresh()"
theme="default"
variant="text"
size="small"
>
<t-icon name="refresh" size="1.25rem" />
</t-button>
</template>
<template #left>
<store-overview ref="storeOverviewRef" compact />
</template>
<template #right-actions>
<navbar-notify-button />
</template>
<template #right>
<pending-notice-bar />
<customer-entry-panel />
</template>
</tab-split-view>
<main v-else class="tui-page-content scroll column">
<div class="tab-body">
<pending-notice-bar />
<customer-entry-panel />
</div>
</main>
</div>
</template>
@@ -60,6 +54,7 @@ import PendingNoticeBar from "./component/PendingNoticeBar.vue";
import CustomerEntryPanel from "./component/CustomerEntryPanel.vue";
import NavbarNotifyButton from "./component/NavbarNotifyButton.vue";
import StoreOverview from "./component/StoreOverview.vue";
import TabSplitView from "./component/TabSplitView.vue";
import { permissionCodes } from "@/utils/permission";
defineOptions({
@@ -74,61 +69,3 @@ 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 {
.wide-split {
overflow: hidden;
padding-top: 0;
padding-bottom: 0;
}
.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);
}
// 栏内导航栏贴在栏顶,内容从它下方滚过,和整页的毛玻璃效果一致
.t-navbar {
top: 0;
left: 0;
right: 0;
position: absolute;
// navbar 默认 fixed:内容层原本贴着视口,这里收回栏内;
// 占位块是给 fixed 模式撑高度用的,栏内不需要
:deep(.t-navbar__content) {
left: 0;
right: 0;
position: relative;
}
:deep(.t-navbar__placeholder) {
display: none;
}
}
.pane-body {
flex: 1;
min-height: 0;
overflow: auto;
padding-top: calc(var(--tui-nav-height, 48px) + 1rem);
padding-bottom: 1rem;
}
}
}
</style>
+88 -185
View File
@@ -1,214 +1,117 @@
<template>
<t-navbar fixed :z-index="20" title="产品" />
<main class="tui-page-content scroll column product-tab">
<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
>
<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="tui-page-layout tui-navbar product-tab">
<t-navbar
v-if="!mergedLayout"
fixed
:z-index="20"
title="产品"
/>
<!-- 平板横屏:经营图表与产品入口合并成一页,两栏各自保留导航栏 -->
<tab-split-view
v-if="mergedLayout"
left-title="经营图表"
right-title="产品"
>
<template #left-actions>
<t-button
aria-label="刷新"
@click="panelRef?.reload()"
theme="default"
variant="text"
size="small"
>
<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>
<t-icon name="refresh" size="1.25rem" />
</t-button>
</template>
<template #left>
<div class="left">
<div class="chart-switch glass-header">
<t-segmented
v-model="chartMode"
class="switch"
block
:options="chartModeOptions"
/>
</div>
<product-charts-panel
v-if="chartMode === 'product'"
ref="panelRef"
embedded
compact
/>
<order-charts-panel
v-else
ref="panelRef"
embedded
compact
/>
</div>
</template>
<template #right>
<product-entry-panel compact hide-analysis />
</template>
</tab-split-view>
<main v-else class="tui-page-content scroll column product-tab-body">
<div class="tab-body">
<product-entry-panel />
</div>
</main>
</div>
</template>
<script setup lang="ts">
import { useUserStore } from "timi-web-api";
import { useLayout } from "timi-tdesign-mobile";
import ProductEntryPanel from "./component/ProductEntryPanel.vue";
import TabSplitView from "./component/TabSplitView.vue";
import { permissionCodes } from "@/utils/permission";
type MenuItem = {
icon: string;
path: string;
title: string;
visible: boolean;
};
type ChartMode = "product" | "order";
type MenuGroup = {
items: MenuItem[];
title: string;
};
// 图表带 echarts 全家桶,只有横屏分栏才会用到,异步加载避免拖累手机端的首屏
const ProductChartsPanel = defineAsyncComponent(() => import("@/pages/product/component/ProductChartsPanel.vue"));
const OrderChartsPanel = defineAsyncComponent(() => import("@/pages/product/component/OrderChartsPanel.vue"));
defineOptions({
name: "ProductTab"
});
const router = useRouter();
const userStore = useUserStore();
const menuGroupList = computed<MenuGroup[]>(() => [
{
title: "产品管理",
items: [
{
icon: "catalog",
path: "/management/product-categories",
title: "产品分类",
visible: userStore.hasPermissions(permissionCodes.productCategory.read)
},
{
icon: "control-platform",
path: "/management/products",
title: "产品库",
visible: userStore.hasPermissions(permissionCodes.product.read)
},
{
icon: "wallet",
path: "/management/product-stocks",
title: "库存",
visible: userStore.hasPermissions(permissionCodes.productStock.read)
},
{
icon: "history",
path: "/management/product-stock-records",
title: "库存流水",
visible: userStore.hasPermissions(permissionCodes.productStock.read)
}
]
},
{
title: "交易管理",
items: [
{
icon: "task",
path: "/management/sales-orders",
title: "销售订单",
visible: userStore.hasPermissions(permissionCodes.salesOrder.read)
},
{
icon: "wallet",
path: "/management/fund-records",
title: "资金流水",
visible: userStore.hasPermissions(permissionCodes.fundRecord.read)
},
{
icon: "undertake-delivery",
path: "/management/order-fulfillments",
title: "履约记录",
visible: userStore.hasPermissions(permissionCodes.orderFulfillment.read)
},
{
icon: "money",
path: "/management/consumption-records",
title: "消费记录",
visible: userStore.hasPermissions(permissionCodes.salesOrder.read)
}
]
},
{
title: "套餐管理",
items: [
{
icon: "layers",
path: "/management/package-configs",
title: "套餐配置",
visible: userStore.hasPermissions(permissionCodes.packageConfig.read)
},
{
icon: "task",
path: "/management/package-orders",
title: "套餐订单",
visible: userStore.hasPermissions(permissionCodes.packageConfig.read)
&& userStore.hasPermissions(permissionCodes.salesOrder.read)
}
]
},
{
title: "积分兑换",
items: [
{
icon: "cart",
path: "/management/points/redeem-skus",
title: "兑换商品",
visible: userStore.hasPermissions(permissionCodes.pointRedeemSku.manage)
},
{
icon: "gift",
path: "/management/points/redemptions",
title: "积分兑换",
visible: userStore.hasPermissions(permissionCodes.pointRedemption.create)
}
]
},
{
title: "经营分析",
items: [
{
icon: "chart-analytics",
path: "/management/product-data-charts",
title: "产品经营图表",
visible: userStore.hasPermissions(permissionCodes.stat.read)
},
{
icon: "chart-combo",
path: "/management/order-data-charts",
title: "客户经营图表",
visible: userStore.hasPermissions(permissionCodes.stat.read)
}
]
}
]);
// 横屏平板(出现左侧导航栏)才合并经营图表与产品入口;
// 没有统计权限的账号本来就没有图表入口,这里同样不显示左侧分栏
const { isWide } = useLayout({ tablet: true });
const mergedLayout = computed(() => isWide.value && userStore.hasPermissions(permissionCodes.stat.read));
const panelRef = ref<{ reload: () => Promise<void> }>();
const visibleMenuGroupList = computed<MenuGroup[]>(() => menuGroupList.value
.map(group => ({
...group,
items: group.items.filter(item => item.visible)
}))
.filter(group => group.items.length));
// ---------- 图表切换 ----------
async function go(path: string): Promise<void> {
await router.push(path);
}
const chartMode = ref<ChartMode>("product");
const chartModeOptions = [
{ value: "product" as ChartMode, label: "产品经营" },
{ value: "order" as ChartMode, label: "客户经营" }
];
</script>
<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));
}
}
/**
* 图表切换吸在栏内导航下方,滚动图表时不用回顶部。
*
* sticky 的偏移是相对滚动容器的内容盒算的,而 .pane-body 顶部有
* calc(导航高 + .5rem) 的内边距,所以这里要减去那 .5rem 才能贴住导航底边。
*/
.chart-switch {
top: -1rem;
z-index: 5;
padding: 1rem;
margin-top: -1rem;
position: sticky;
}
</style>
+2 -2
View File
@@ -2,7 +2,7 @@
<t-navbar fixed :z-index="20" title="管理" />
<main class="tui-page-content scroll column management-tab">
<div class="tab-body">
<div class="menu-grid">
<div class="menus">
<t-cell-group class="user-card" theme="card" v-entrance-transition>
<t-cell
v-if="currentUser"
@@ -347,7 +347,7 @@ onBeforeRouteLeave(() => {
* 和分组卡片并排会在下面留下一大块空白。
* 手机上仍是单列,间距保持 .5rem。
*/
.menu-grid {
.menus {
gap: .5rem;
display: grid;
padding: 0 1rem;
@@ -162,11 +162,7 @@ async function openAiChat(): Promise<void> {
.entry-panel {
.entry-group {
margin: 0 1rem;
& + & {
margin-top: 1.5rem;
}
margin: 1rem;
> h2 {
color: #52607a;
@@ -255,4 +251,4 @@ async function openAiChat(): Promise<void> {
--entry-background: rgba(15, 23, 42, .88);
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
}
</style>
</style>
@@ -0,0 +1,191 @@
<template>
<div class="menus" :class="{ compact }">
<t-cell-group
v-for="(group, index) in visibleMenuGroupList"
:key="index"
class="menu-group"
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)"
>
<template #leftIcon>
<t-icon :name="item.icon" size="1.35rem" />
</template>
</t-cell>
</t-cell-group>
</div>
<center-tips v-if="!visibleMenuGroupList.length" :content="'当前账号暂无产品管理权限'" />
</template>
<script setup lang="ts">
import { useUserStore } from "timi-web-api";
import { permissionCodes } from "@/utils/permission";
type MenuItem = {
icon: string;
path: string;
title: string;
visible: boolean;
};
type MenuGroup = {
items: MenuItem[];
/** 分组的稳定标识,用于按场景隐藏整组 */
key?: "analysis";
};
const props = withDefaults(defineProps<{
/** 分栏窄栏里固定单列 */
compact?: boolean;
/** 横屏分栏左侧已经展示图表,右侧不再重复「经营分析」入口 */
hideAnalysis?: boolean;
}>(), {
compact: false,
hideAnalysis: false
});
defineOptions({
name: "ProductEntryPanel"
});
const router = useRouter();
const userStore = useUserStore();
const menuGroupList = computed<MenuGroup[]>(() => [
{
items: [
{
icon: "catalog",
path: "/management/product-categories",
title: "产品分类",
visible: userStore.hasPermissions(permissionCodes.productCategory.read)
},
{
icon: "control-platform",
path: "/management/products",
title: "产品库",
visible: userStore.hasPermissions(permissionCodes.product.read)
},
{
icon: "wallet",
path: "/management/product-stocks",
title: "库存",
visible: userStore.hasPermissions(permissionCodes.productStock.read)
},
{
icon: "history",
path: "/management/product-stock-records",
title: "库存流水",
visible: userStore.hasPermissions(permissionCodes.productStock.read)
}
]
},
{
items: [
{
icon: "task",
path: "/management/sales-orders",
title: "销售订单",
visible: userStore.hasPermissions(permissionCodes.salesOrder.read)
},
{
icon: "wallet",
path: "/management/fund-records",
title: "资金流水",
visible: userStore.hasPermissions(permissionCodes.fundRecord.read)
},
{
icon: "undertake-delivery",
path: "/management/order-fulfillments",
title: "履约记录",
visible: userStore.hasPermissions(permissionCodes.orderFulfillment.read)
},
{
icon: "money",
path: "/management/consumption-records",
title: "消费记录",
visible: userStore.hasPermissions(permissionCodes.salesOrder.read)
}
]
},
{
items: [
{
icon: "layers",
path: "/management/package-configs",
title: "套餐配置",
visible: userStore.hasPermissions(permissionCodes.packageConfig.read)
},
{
icon: "task",
path: "/management/package-orders",
title: "套餐订单",
visible: userStore.hasPermissions(permissionCodes.packageConfig.read)
&& userStore.hasPermissions(permissionCodes.salesOrder.read)
}
]
},
{
items: [
{
icon: "cart",
path: "/management/points/redeem-skus",
title: "兑换商品",
visible: userStore.hasPermissions(permissionCodes.pointRedeemSku.manage)
},
{
icon: "gift",
path: "/management/points/redemptions",
title: "积分兑换",
visible: userStore.hasPermissions(permissionCodes.pointRedemption.create)
}
]
},
{
key: "analysis",
items: [
{
icon: "chart-analytics",
path: "/management/product-data-charts",
title: "产品经营图表",
visible: userStore.hasPermissions(permissionCodes.stat.read)
},
{
icon: "chart-combo",
path: "/management/order-data-charts",
title: "客户经营图表",
visible: userStore.hasPermissions(permissionCodes.stat.read)
}
]
}
]);
const visibleMenuGroupList = computed<MenuGroup[]>(() => menuGroupList.value
.filter(group => !props.hideAnalysis || group.key !== "analysis")
.map(group => ({
...group,
items: group.items.filter(item => item.visible)
}))
.filter(group => group.items.length));
async function go(path: string): Promise<void> {
await router.push(path);
}
</script>
<style scoped lang="less">
.menus {
gap: 2rem;
display: flex;
margin-top: 1rem;
flex-direction: column;
}
</style>
+110
View File
@@ -0,0 +1,110 @@
<template>
<main class="tui-page-content wide-split">
<div class="split">
<section class="pane">
<t-navbar :z-index="20" :title="leftTitle">
<template #right>
<slot name="left-actions"/>
</template>
</t-navbar>
<div class="pane-body">
<slot name="left"/>
</div>
</section>
<section class="pane">
<t-navbar :z-index="20" :title="rightTitle">
<template #right>
<slot name="right-actions"/>
</template>
</t-navbar>
<div class="pane-body">
<slot name="right"/>
</div>
</section>
</div>
</main>
</template>
<script setup lang="ts">
defineOptions({
name: "TabSplitView"
});
defineProps<{
/** 左栏导航栏标题 */
leftTitle: string;
/** 右栏导航栏标题 */
rightTitle: string;
}>();
</script>
<style scoped lang="less">
/**
* 平板横屏的两栏骨架:每栏一条自己的导航栏,内容从导航下方滚过。
*
* 页面只需提供两栏内容,栏宽、栏内导航定位、滚动容器都在这里统一。
*/
/**
* 必须写成 `.tui-page-content.wide-split` 复合选择器:
* 库里 `.tui-page-layout .tui-page-content` 是两个类,我们单写 `.wide-split`(1 类 + 1 作用域属性)
* 权重打平且库样式在后,padding-top 会被 48px+1rem 盖回来,两条导航栏整体被顶下去。
*/
.tui-page-content.wide-split {
overflow: hidden;
padding-top: 0;
padding-bottom: 0;
}
.split {
flex: 1;
display: grid;
min-height: 0;
grid-template-columns: minmax(0, 1fr) clamp(24rem, 28vw, 28rem);
}
.pane {
display: flex;
position: relative;
overflow: hidden;
min-height: 0;
flex-direction: column;
&:first-child {
border-right: 1px solid var(--td-component-border);
}
// 栏内导航栏贴在栏顶,内容从它下方滚过,和整页的毛玻璃效果一致
.t-navbar {
top: 0;
left: 0;
right: 0;
position: absolute;
}
/**
* navbar 默认 fixed:内容层原本贴着视口,这里收回栏内。
*
* 选择器必须同时带 .t-navbar 和 .t-navbar--fixed(同一个元素上的两个类),
* 权重才压得住库里的
* `.tui-app-shell.is-rail .t-navbar--fixed .t-navbar__content { left: var(--tui-fixed-left) }`,
* 否则横屏下整条导航会右移一个左侧导航栏的宽度。
*/
:deep(.t-navbar.t-navbar--fixed .t-navbar__content) {
left: 0;
right: 0;
position: relative;
}
:deep(.t-navbar__placeholder) {
display: none;
}
.pane-body {
flex: 1;
min-height: 0;
overflow: auto;
padding-top: calc(var(--tui-nav-height, 48px) + 1rem);
padding-bottom: 1rem;
}
}
</style>
+13
View File
@@ -127,6 +127,19 @@ export default defineConfig(({ mode }) => {
allowedHosts: [
"gao.imyeyu.com"
],
/**
* 调试产物(截图、CDP 脚本、Chrome 的 user-data-dir)不能被监听:
* Chrome 运行时锁着里面的 SQLite,chokidar 一 watch 就 EBUSY 把 dev server 打挂。
* 默认的 .git / node_modules 需要显式保留,因为这里的 ignored 会覆盖默认值。
*/
watch: {
ignored: [
"**/.git/**",
"**/node_modules/**",
"**/.debug-*",
"**/.debug-*/**"
]
},
fs: {
allow: [
projectRoot,