liufumingren b4a458abd3 1
2026-11-16 09:55:27 +08:00

447 lines
14 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="order-management-wrapper">
<!-- 多标签模式 -->
<template v-if="!singlePage">
<!-- 顶部多标签页区域(统一组件:视觉/排序/默认页签均由 TabArea 负责) -->
<div class="tab-section">
<TabArea
:tabs="tabs"
:default-active="activeTab"
page-key="order.management"
@tab-change="handleTabChange"
>
<template #header-action>
<!-- <el-button size="small" @click="workbenchDialogVisible = true">统一查询</el-button> -->
<!-- <el-button size="small" @click="bindByWaybillDialogVisible = true">按运单绑定包材</el-button> -->
<el-button size="small" :loading="badgeLoading" @click="refreshBadgeCounts">刷新角标</el-button>
</template>
<template #label="{ tab }">
{{ tab.label }}
<el-badge
:value="tab.count"
:max="99"
:hidden="tab.count === 0"
class="tab-badge"
/>
</template>
</TabArea>
</div>
<!-- 主内容区容器(对齐 stock/stockManagement 的 main-container) -->
<div class="main-container">
<transition name="tab-fade" mode="out-in">
<!--
tab 缓存策略由「更多设置」控制(tabCacheEnabled / tabCacheMax):
启用时用 KeepAlive 缓存各 tab 组件(超出 max 按 LRU 淘汰最久未用),
关闭时不缓存、每次切换重新挂载。
-->
<KeepAlive v-if="tabCacheEnabled" :max="tabCacheMax">
<component :is="activeComponent" />
</KeepAlive>
<component v-else :is="activeComponent" />
</transition>
</div>
</template>
<!-- 单页模式:直接渲染默认页签组件 -->
<div v-else class="tab-container single-page-container">
<component :is="defaultTab.component" />
</div>
<order-workbench-list-dialog
v-if="workbenchDialogVisible"
v-model="workbenchDialogVisible"
/>
<BindPackageMaterialByWaybillDialog
v-if="bindByWaybillDialogVisible"
v-model="bindByWaybillDialogVisible"
/>
</div>
</template>
<script setup lang="ts">
import { ref, watch, onMounted, computed, markRaw, defineAsyncComponent } from 'vue'
import { useRoute } from 'vue-router'
import { useSettingsStore } from '@/stores/modules/settings'
import { useExperimentalStore } from '@/stores/modules/experimental'
import { orderBadgeCount } from '@/api/order.index/orderindex'
// 默认页签(待处理订单)保持同步加载,避免首屏多一次 chunk 等待;其余页签按需加载
import PendingOrder from './pendingOrder.vue'
const ReviewOrder = defineAsyncComponent(() => import('./reviewOrder.vue'))
const OutboundOrder = defineAsyncComponent(() => import('./outboundOrder.vue'))
const ExceptionOrder = defineAsyncComponent(() => import('./exceptionOrder.vue'))
const DeliveryOrder = defineAsyncComponent(() => import('./deliveryOrder.vue'))
const PendingOrder2b = defineAsyncComponent(() => import('./pendingOrder2b.vue'))
const DeliveryOrder2b = defineAsyncComponent(() => import('./deliveryOrder2b.vue'))
const EntrustWarehouse = defineAsyncComponent(() => import('./entrustWarehouse.vue'))
const DeliveryException = defineAsyncComponent(() => import('./deliveryException.vue'))
const ArchiveOrder = defineAsyncComponent(() => import('./archiveOrder.vue'))
const OrderWorkbenchListDialog = defineAsyncComponent(() => import('./component/OrderWorkbenchListDialog.vue'))
const BindPackageMaterialByWaybillDialog = defineAsyncComponent(() => import('./component/BindPackageMaterialByWaybillDialog.vue'))
import TabArea from '@/components/TabArea/index.vue'
import { useTabOrder } from '@/composables/useTabOrder'
import { safeInvoke } from '@/utils/safe-invoke'
import { ORDER_PAGE_CONFIG } from './config/order-common-config'
const route = useRoute()
const settingsStore = useSettingsStore()
const experimentalStore = useExperimentalStore()
/** tab 缓存开关(实验性设置,默认开) */
const tabCacheEnabled = computed(() => experimentalStore.tabCacheEnabled)
/** tab 缓存最大数量:优先本页配置(8 个页签全量缓存),回退全局实验性设置 */
const tabCacheMax = computed(() => ORDER_PAGE_CONFIG.tabCacheMax ?? experimentalStore.tabCacheMax)
const singlePage = ORDER_PAGE_CONFIG.singlePage
const badgeLoading = ref(false)
const workbenchDialogVisible = ref(false)
const bindByWaybillDialogVisible = ref(false)
type OrderTabItem = {
name: string
label: string
count: number | string
component: any
}
/** 当前激活页签对应的组件(渲染在主内容区 main-container 中,对齐 stock/stockManagement) */
const activeComponent = computed(() => {
const tab = tabs.value.find((t) => t.name === activeTab.value)
return tab?.component
})
const tabs = ref<OrderTabItem[]>([
{
name: 'reviewOrder',
label: '待审核订单',
count: 5,
component: markRaw(ReviewOrder)
},
{
name: 'pendingOrder',
label: '待处理订单',
count: 10,
component: markRaw(PendingOrder)
},
{
name: 'pendingOrder2b',
label: '待处理B2B订单',
count: 0,
component: markRaw(PendingOrder2b)
},
{
name: 'exceptionOrder',
label: '待处理异常订单',
count: 3,
component: markRaw(ExceptionOrder)
},
{
name: 'outboundOrder',
label: '待出库订单',
count: 0,
component: markRaw(OutboundOrder)
},
{
name: 'entrustWarehouse',
label: '委托外仓订单',
count: 0,
component: markRaw(EntrustWarehouse)
},
{
name: 'deliveryOrder',
label: '配送订单',
count: 0,
component: markRaw(DeliveryOrder)
},
{
name: 'deliveryOrder2b',
label: '配送B2B订单',
count: 0,
component: markRaw(DeliveryOrder2b)
},
{
name: 'deliveryException',
label: '配送异常订单',
count: 0,
component: markRaw(DeliveryException)
},
{
name: 'archiveOrder',
label: '归档订单',
count: 0,
component: markRaw(ArchiveOrder)
}
])
// ============================================================
// 标签排序 / 默认页签(统一由 useTabOrder 负责,配置按账号保存)
// ============================================================
const { defaultTabName, resolveInitialTab } = useTabOrder('order.management', () => tabs.value, {
legacyScopes: ['order.tabs.order'],
// 页面默认打开「待处理订单」
fallbackTabName: 'pendingOrder'
})
/** 单页模式下使用的默认标签(跟随用户设置的默认页签,未设置时回退第一项) */
const defaultTab = computed(
() => tabs.value.find((tab) => tab.name === defaultTabName.value) ?? tabs.value[0]!
)
const activeTab = ref(resolveInitialTab(route.query.tab as string | undefined))
const badgeToTabMap: Record<string, string> = {
reviewOrder: 'reviewOrder',
pendingOrder: 'pendingOrder',
outboundOrder: 'outboundOrder',
expectionOrder: 'exceptionOrder',
entrustOrder: 'entrustWarehouse',
deliveryOrder: 'deliveryOrder',
deliveryExpectionOrder: 'deliveryException',
archiveOrder: 'archiveOrder'
}
/** tab.name → 角标接口字段(反查表;避免每次刷新都对 badgeToTabMap 做 Object.keys+find) */
const tabNameToBadgeKey: Record<string, string> = Object.fromEntries(
Object.entries(badgeToTabMap).map(([badgeKey, tabName]) => [tabName, badgeKey])
)
/** 角标刷新最小间隔:切页签时做节流,避免连续切换重复打角标聚合查询(手动刷新不受限) */
const BADGE_REFRESH_MIN_INTERVAL = 3000
let lastBadgeSyncAt = 0
async function loadBadgeCounts(options: { force?: boolean } = {}) {
if (badgeLoading.value) return
if (!options.force && Date.now() - lastBadgeSyncAt < BADGE_REFRESH_MIN_INTERVAL) return
badgeLoading.value = true
try {
const res: any = await orderBadgeCount()
if (!res || ![1, 200].includes(res.code) || !res.data) return
const data = res.data as Record<string, number | string>
// 就地更新 count,避免整表替换导致 el-tabs 子项反复重建、事件重入
for (const tab of tabs.value) {
const badgeKey = tabNameToBadgeKey[tab.name]
if (!badgeKey) continue
tab.count = data[badgeKey] ?? 0
}
lastBadgeSyncAt = Date.now()
} catch (error) {
console.error('order.badgeCount error:', error)
} finally {
badgeLoading.value = false
}
}
function refreshBadgeCounts() {
safeInvoke(() => loadBadgeCounts({ force: true }))
}
/**
* 首屏 / 外部导航时从地址栏恢复 tab。
* 方案B:页签切换改为纯本地状态(handleTabChange 不写回路由),
* 因为布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
* 任何 URL 变化(含 ?tab=)都会触发整页销毁重建,导致切换卡顿、重复请求与显示闪烁。
* 此处仅:① 首屏按 URL 初始化;② 浏览器前进/后退等外部导航时同步本地 tab。
* 非法 / 缺失 tab 时纯本地归位到「待处理订单」,绝不写回路由。
*/
watch(
() => route.query.tab,
(newTab) => {
activeTab.value = resolveInitialTab(newTab === undefined || newTab === null ? '' : String(newTab))
},
{ immediate: true }
)
onMounted(() => {
loadBadgeCounts()
})
// 切换标签(使用 tab-change:在 v-model 更新之后触发,避免与 tab-click 重入)
const handleTabChange = (tabName: string | number) => {
safeInvoke(() => {
const name = String(tabName)
// 方案B:纯本地切换,不写回路由(避免改变 fullPath 触发 AppMain 整页销毁重建)
if (activeTab.value === name) {
return
}
activeTab.value = name
return loadBadgeCounts()
})
}
</script>
<style lang="scss" scoped>
.order-management-wrapper {
position: relative;
width: 100%;
/* 高度由布局层的 .app-router-page(flex:1) 提供,页面不再自己算 100vh */
height: 100%;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ===== 顶部多标签页区域(对齐 stock/stockManagement 的 tab-section) ===== */
.tab-section {
flex-shrink: 0;
position: relative;
background: #fff;
border: 1px solid #e8eef7;
border-bottom: none;
border-radius: 6px 6px 0 0;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
overflow: hidden;
}
.tab-container {
display: flex;
flex-direction: column;
/* border-card 自带外壳的清除统一由 src/styles/tab-area.scss 负责
(scoped 下写成 :deep(.el-tabs--border-card) 会变成后代选择器,永远匹配不到自身) */
:deep(.el-tabs__header) {
margin-bottom: 0;
flex-shrink: 0;
}
:deep(.el-tabs__header.is-top) {
padding: 8px 12px 0 46px;
background: linear-gradient(180deg, #f7fafd 0%, #eef4fb 100%);
border-bottom: 1px solid #e8eef7;
margin: 0;
}
:deep(.el-tabs__nav-wrap::after) {
display: none;
}
:deep(.el-tabs__item.is-top) {
height: 34px;
line-height: 34px;
padding: 0 16px;
border-radius: 8px 8px 0 0;
color: #606266;
font-size: 13px;
font-weight: 500;
transition: all 0.25s cubic-bezier(0.645, 0.045, 0.355, 1);
border: 1px solid #e6edf8;
border-bottom: none;
background: #edf3fb;
margin-right: 6px;
box-shadow: inset 0 -1px 0 rgba(15, 23, 42, 0.03);
}
:deep(.el-tabs__item.is-top:hover) {
color: #409eff;
background-color: rgba(64, 158, 255, 0.06);
border-color: rgba(64, 158, 255, 0.12);
}
:deep(.el-tabs__item.is-top.is-active) {
color: #2f80ed;
font-weight: 600;
background: #ffffff;
border-color: #e8eef7;
/*
第二层阴影向下 1px 纯白,盖住 header 底部的 1px 分隔线,
让激活标签与下方内容区连通(box-shadow 不受标签 overflow:hidden 裁剪)。
*/
box-shadow: 0 -1px 8px rgba(47, 128, 237, 0.08), 0 1px 0 0 #ffffff;
z-index: 1;
position: relative;
&::before {
content: "";
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background: #2f80ed;
margin-right: 6px;
vertical-align: middle;
flex-shrink: 0;
}
}
:deep(.el-tabs__active-bar) {
display: none;
}
/* 隐藏内容区,仅展示标签头(对齐 stock/stockManagement) */
:deep(.el-tabs__content) {
display: none;
}
}
.custom-tab-label {
display: inline-flex;
align-items: center;
gap: 6px;
}
.tab-badge {
:deep(.el-badge__content) {
font-size: 12px;
height: 18px;
line-height: 18px;
padding: 0 6px;
&.is-fixed {
top: -2px;
right: -8px;
}
}
}
// 当数量很大时显示为红色
:deep(.el-badge__content) {
&.is-danger {
background-color: #f56c6c;
}
}
/* ===== 主内容区容器(对齐 stock/stockManagement 的 main-container) ===== */
.main-container {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
background: #fff;
border: 1px solid #e8eef7;
border-top: none;
border-radius: 0 0 6px 6px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
overflow: hidden;
}
/* ========== 单页模式 ========== */
.single-page-container {
flex: 1;
min-height: 0;
background: #fff;
border: 1px solid #e8eef7;
border-radius: 6px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
overflow: hidden;
:deep(> *) {
flex: 1;
overflow: auto;
min-height: 0;
}
}
/* ===== 页签切换淡入淡出(对齐 storage/generalreport 的 tab-fade) ===== */
.tab-fade-enter-active,
.tab-fade-leave-active {
/* 页签切换是高频操作:0.2s 在 out-in 下叠加成 ~0.4s 的"等一下",缩到 0.12s */
transition: opacity 0.12s ease;
opacity: 1;
}
.tab-fade-enter-from,
.tab-fade-leave-to {
opacity: 0;
}
</style>