480 lines
13 KiB
Vue
480 lines
13 KiB
Vue
<template>
|
||
<div class="order-management-wrapper" :style="{ height: containerHeight }">
|
||
<!-- 多标签模式 -->
|
||
<template v-if="!singlePage">
|
||
<!-- 顶部多标签页区域(对齐 stock/stockManagement 的 tab-section) -->
|
||
<div class="tab-section">
|
||
<!-- 排序设置入口(tab 区域左侧,样式对齐 scan-box 模式切换按钮) -->
|
||
<div class="tab-sort-entry">
|
||
<el-tooltip content="标签排序" placement="bottom">
|
||
<el-button class="sort-entry-btn" size="small" link @click="openSortDialog">
|
||
<el-icon><Sort /></el-icon>
|
||
</el-button>
|
||
</el-tooltip>
|
||
</div>
|
||
<div class="tabs-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>
|
||
</div>
|
||
<el-tabs
|
||
v-model="activeTab"
|
||
@tab-change="handleTabChange"
|
||
tab-position="top"
|
||
type="border-card"
|
||
class="tab-container"
|
||
>
|
||
<el-tab-pane
|
||
v-for="tab in tabs"
|
||
:key="tab.name"
|
||
:name="tab.name"
|
||
:lazy="false"
|
||
>
|
||
<template #label>
|
||
<span class="custom-tab-label">
|
||
{{ tab.label }}
|
||
<el-badge
|
||
:value="tab.count"
|
||
:max="99"
|
||
:hidden="tab.count === 0"
|
||
class="tab-badge"
|
||
/>
|
||
</span>
|
||
</template>
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
</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-model="workbenchDialogVisible" />
|
||
<BindPackageMaterialByWaybillDialog v-model="bindByWaybillDialogVisible" />
|
||
<SortSettingDialog v-model:visible="sortDialogVisible" :tabs="ORDER_TAB_LIST" scope="order.tabs.order" @saved="handleSortSaved" />
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, watch, onMounted, computed, markRaw } 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'
|
||
import ReviewOrder from './reviewOrder.vue'
|
||
import PendingOrder from './pendingOrder.vue'
|
||
import OutboundOrder from './outboundOrder.vue'
|
||
import ExceptionOrder from './exceptionOrder.vue'
|
||
import DeliveryOrder from './deliveryOrder.vue'
|
||
import EntrustWarehouse from './entrustWarehouse.vue'
|
||
import DeliveryException from './deliveryException.vue'
|
||
import ArchiveOrder from './archiveOrder.vue'
|
||
import OrderWorkbenchListDialog from './component/OrderWorkbenchListDialog.vue'
|
||
import BindPackageMaterialByWaybillDialog from './component/BindPackageMaterialByWaybillDialog.vue'
|
||
import SortSettingDialog from '@/components/SortSettingDialog.vue'
|
||
import { Sort } from '@element-plus/icons-vue'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import { ORDER_PAGE_CONFIG, ORDER_TAB_LIST } from './config/order-common-config'
|
||
import { useUserPreferenceStore } from '@/stores/modules/userPreference'
|
||
|
||
const route = useRoute()
|
||
const settingsStore = useSettingsStore()
|
||
const experimentalStore = useExperimentalStore()
|
||
/** tab 缓存开关(实验性设置,默认开) */
|
||
const tabCacheEnabled = computed(() => experimentalStore.tabCacheEnabled)
|
||
/** tab 缓存最大数量(实验性设置,默认 2,超出 LRU 淘汰最久未用) */
|
||
const tabCacheMax = computed(() => experimentalStore.tabCacheMax)
|
||
const singlePage = ORDER_PAGE_CONFIG.singlePage
|
||
const badgeLoading = ref(false)
|
||
const workbenchDialogVisible = ref(false)
|
||
const bindByWaybillDialogVisible = ref(false)
|
||
|
||
// 标签排序弹窗
|
||
const sortDialogVisible = ref(false)
|
||
const preferenceStore = useUserPreferenceStore()
|
||
|
||
function openSortDialog() {
|
||
sortDialogVisible.value = true
|
||
}
|
||
|
||
/** 保存标签顺序:按新顺序重排 tabs 数组(组件对象原样复用,缺失项留在末尾) */
|
||
function handleSortSaved(order: string[]) {
|
||
applyTabOrder(order)
|
||
}
|
||
|
||
/** 读取本账号保存的标签顺序并应用;无配置时保持默认顺序 */
|
||
function applySavedTabOrder() {
|
||
const saved = preferenceStore.get('order.tabs.order')
|
||
if (!Array.isArray(saved) || !saved.length) return
|
||
applyTabOrder(saved)
|
||
}
|
||
|
||
/** 按给定 tab.name 顺序重排 tabs;非法项剔除,缺失项按当前 tabs 补在末尾 */
|
||
function applyTabOrder(order: string[]) {
|
||
const byName = new Map(tabs.value.map((t) => [t.name, t]))
|
||
const ordered: OrderTabItem[] = []
|
||
for (const name of order) {
|
||
if (byName.has(name)) ordered.push(byName.get(name)!)
|
||
}
|
||
for (const t of tabs.value) {
|
||
if (!ordered.some((x) => x.name === t.name)) ordered.push(t)
|
||
}
|
||
tabs.value = ordered
|
||
}
|
||
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() => shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)')
|
||
|
||
/** 单页模式下使用的默认标签(始终为 tabs 第一项) */
|
||
const defaultTab = computed(() => tabs.value[0]!)
|
||
|
||
const activeTab = ref('pendingOrder')
|
||
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: '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: 'deliveryException',
|
||
label: '配送异常订单',
|
||
count: 0,
|
||
component: markRaw(DeliveryException)
|
||
},
|
||
{
|
||
name: 'archiveOrder',
|
||
label: '归档订单',
|
||
count: 0,
|
||
component: markRaw(ArchiveOrder)
|
||
}
|
||
])
|
||
|
||
const badgeToTabMap: Record<string, string> = {
|
||
reviewOrder: 'reviewOrder',
|
||
pendingOrder: 'pendingOrder',
|
||
outboundOrder: 'outboundOrder',
|
||
expectionOrder: 'exceptionOrder',
|
||
entrustOrder: 'entrustWarehouse',
|
||
deliveryOrder: 'deliveryOrder',
|
||
deliveryExpectionOrder: 'deliveryException',
|
||
archiveOrder: 'archiveOrder'
|
||
}
|
||
|
||
async function loadBadgeCounts() {
|
||
if (badgeLoading.value) 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 = Object.keys(badgeToTabMap).find((key) => badgeToTabMap[key] === tab.name)
|
||
if (!badgeKey) continue
|
||
tab.count = data[badgeKey] ?? 0
|
||
}
|
||
} catch (error) {
|
||
console.error('order.badgeCount error:', error)
|
||
} finally {
|
||
badgeLoading.value = false
|
||
}
|
||
}
|
||
|
||
function refreshBadgeCounts() {
|
||
safeInvoke(() => loadBadgeCounts())
|
||
}
|
||
|
||
/**
|
||
* 首屏 / 外部导航时从地址栏恢复 tab。
|
||
* 方案B:页签切换改为纯本地状态(handleTabChange 不写回路由),
|
||
* 因为布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
|
||
* 任何 URL 变化(含 ?tab=)都会触发整页销毁重建,导致切换卡顿、重复请求与显示闪烁。
|
||
* 此处仅:① 首屏按 URL 初始化;② 浏览器前进/后退等外部导航时同步本地 tab。
|
||
* 非法 / 缺失 tab 时纯本地归位到「待处理订单」,绝不写回路由。
|
||
*/
|
||
watch(
|
||
() => route.query.tab,
|
||
(newTab) => {
|
||
const validTabs = tabs.value.map((tab) => tab.name)
|
||
const raw = newTab === undefined || newTab === null ? '' : String(newTab).trim()
|
||
|
||
if (raw && validTabs.includes(raw)) {
|
||
activeTab.value = raw
|
||
return
|
||
}
|
||
|
||
activeTab.value = 'pendingOrder'
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
|
||
onMounted(() => {
|
||
applySavedTabOrder()
|
||
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%;
|
||
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;
|
||
}
|
||
|
||
.tabs-header-action {
|
||
position: absolute;
|
||
top: 4px;
|
||
right: 16px;
|
||
height: 38px;
|
||
display: flex;
|
||
align-items: center;
|
||
z-index: 2;
|
||
}
|
||
|
||
/* 排序设置入口(tab 区域左侧,样式对齐 scan-box 模式切换按钮) */
|
||
.tab-sort-entry {
|
||
position: absolute;
|
||
top: 4px;
|
||
left: 12px;
|
||
height: 38px;
|
||
display: flex;
|
||
align-items: center;
|
||
z-index: 2;
|
||
|
||
.sort-entry-btn {
|
||
color: #606266;
|
||
font-size: 15px;
|
||
padding: 4px 6px;
|
||
border-radius: 4px;
|
||
transition: all 0.2s;
|
||
|
||
&:hover {
|
||
color: #409eff;
|
||
background-color: rgba(64, 158, 255, 0.08);
|
||
}
|
||
}
|
||
}
|
||
|
||
.tab-container {
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
:deep(.el-tabs__header) {
|
||
margin-bottom: 0;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
:deep(.el-tabs__header.is-top) {
|
||
padding: 4px 12px 0 46px;
|
||
background: #f8fbff;
|
||
border-bottom: 1px solid #e8eef7;
|
||
margin: 0;
|
||
}
|
||
|
||
:deep(.el-tabs__nav-wrap::after) {
|
||
display: none;
|
||
}
|
||
|
||
:deep(.el-tabs__item.is-top) {
|
||
height: 38px;
|
||
line-height: 38px;
|
||
padding: 0 20px;
|
||
border-radius: 6px 6px 0 0;
|
||
color: #606266;
|
||
font-size: 14px;
|
||
font-weight: 500;
|
||
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
||
border: 1px solid transparent;
|
||
border-bottom: none;
|
||
margin-right: 4px;
|
||
}
|
||
|
||
:deep(.el-tabs__item.is-top:hover) {
|
||
color: #409eff;
|
||
background-color: rgba(64, 158, 255, 0.05);
|
||
}
|
||
|
||
:deep(.el-tabs__item.is-top.is-active) {
|
||
color: #409eff;
|
||
font-weight: 600;
|
||
background: #ffffff;
|
||
border-color: #e8eef7;
|
||
border-bottom: 2px solid #ffffff;
|
||
margin-bottom: -1px;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
|
||
:deep(.el-tabs__active-bar) {
|
||
height: 2px;
|
||
border-radius: 2px;
|
||
background-color: #409eff;
|
||
bottom: 0;
|
||
}
|
||
|
||
/* 隐藏内容区,仅展示标签头(对齐 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 {
|
||
transition: opacity 0.2s ease;
|
||
opacity: 1;
|
||
}
|
||
|
||
.tab-fade-enter-from,
|
||
.tab-fade-leave-to {
|
||
opacity: 0;
|
||
}
|
||
</style>
|