2026-09-01 19:26:55 +08:00

412 lines
11 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" :style="{ height: containerHeight }">
<!-- 多标签模式 -->
<template v-if="!singlePage">
<!-- 顶部多标签页区域(对齐 order/orderManagement 的 tab-section) -->
<div class="tab-section">
<!-- 标签排序入口(tab 区域左侧,对齐 order/orderManagement) -->
<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">操作按钮</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 }}</span>
</template>
</el-tab-pane>
</el-tabs>
</div>
<!-- 主内容区容器(对齐 order/orderManagement 的 main-container) -->
<div class="main-container">
<transition name="tab-fade" mode="out-in">
<keep-alive v-if="tabCacheEnabled" :max="tabCacheMax">
<component
:is="activeComponent"
:key="activeTab"
v-bind="activeTabProps"
/>
</keep-alive>
<component
v-else
:is="activeComponent"
:key="activeTab"
v-bind="activeTabProps"
/>
</transition>
</div>
</template>
<!-- 单页模式:直接渲染默认页签组件,复用 .tab-container 样式结构 -->
<div v-else class="tab-container single-page-container">
<keep-alive>
<component
:is="defaultTab.component"
:key="defaultTab.name"
v-bind="defaultTab.props || {}"
/>
</keep-alive>
</div>
<SortSettingDialog
v-model:visible="sortDialogVisible"
:tabs="DEFAULT_TAB_OPTIONS"
scope="order.wave.tabs.order"
@saved="handleSortSaved"
/>
</div>
</template>
<script setup lang="ts">
import { ref, watch, computed, markRaw, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { useSettingsStore } from '@/stores/modules/settings'
import { useExperimentalStore } from '@/stores/modules/experimental'
import { Sort } from '@element-plus/icons-vue'
import SortSettingDialog from '@/components/SortSettingDialog.vue'
import { useUserPreferenceStore } from '@/stores/modules/userPreference'
import GroupWaveBatchListPanel from './GroupWaveBatchListPanel.vue'
import SandanWaveBatchListPanel from './SandanWaveBatchListPanel.vue'
import FallbackOrderListPanel from './FallbackOrderListPanel.vue'
import WaveStrategyListPanel from './WaveStrategyListPanel.vue'
import WavePickTaskListPanel from './WavePickTaskListPanel.vue'
import { safeInvoke } from '@/utils/safe-invoke'
import { WAVE_PAGE_CONFIG } from './config/wave-config'
const route = useRoute()
const settingsStore = useSettingsStore()
const experimentalStore = useExperimentalStore()
/** tab 缓存开关(实验性设置,默认开) */
const tabCacheEnabled = computed(() => experimentalStore.tabCacheEnabled)
/** tab 缓存最大数量(实验性设置,默认 2,超出 LRU 淘汰最久未用) */
const tabCacheMax = computed(() => experimentalStore.tabCacheMax)
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
const singlePage = WAVE_PAGE_CONFIG.singlePage
const containerHeight = computed(() => {
const baseH = shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
return baseH
})
/** 单页模式下使用的默认标签(始终为 tabs 第一项) */
const defaultTab = computed(() => tabs.value[0]!)
const activeTab = ref('groupWave')
/** 当前激活页签对应的组件(渲染在主内容区 main-container 中,对齐 order/orderManagement) */
const activeComponent = computed(() => {
const tab = tabs.value.find((t) => t.name === activeTab.value)
return tab?.component
})
/** 当前激活页签对应的 props(对齐 order/orderManagement) */
const activeTabProps = computed(() => {
const tab = tabs.value.find((t) => t.name === activeTab.value)
return tab?.props || {}
})
type WaveTabItem = {
name: string
label: string
component: any
props?: Record<string, unknown>
}
const tabs = ref<WaveTabItem[]>([
{
name: 'groupWave',
label: '团购波次',
component: markRaw(GroupWaveBatchListPanel),
props: { scanBoxCacheKey: 'wave-order-group-wave' }
},
{
name: 'sandanWave',
label: '散单波次',
component: markRaw(SandanWaveBatchListPanel),
props: { scanBoxCacheKey: 'wave-order-sandan-wave' }
},
{
name: 'sandanFallbackOrders',
label: '不符合波次策略订单列表',
component: markRaw(FallbackOrderListPanel),
props: { scanBoxCacheKey: 'wave-order-sandan-fallback-orders' }
},
{
name: 'sandanWaveStrategy',
label: '波次策略',
component: markRaw(WaveStrategyListPanel),
props: { scanBoxCacheKey: 'wave-order-sandan-wave-strategy' }
},
{
name: 'pickTaskWave',
label: '拣货中任务',
component: markRaw(WavePickTaskListPanel),
props: { scanBoxCacheKey: 'wave-order-pick-task' }
}
])
// ============================================================
// 标签排序(浏览器本地保存,scope=order.wave.tabs.order)
// ============================================================
/** 默认 tab 顺序(弹窗选项 / 恢复默认用) */
const DEFAULT_TAB_OPTIONS = tabs.value.map(({ name, label }) => ({ name, label }))
const sortDialogVisible = ref(false)
const preferenceStore = useUserPreferenceStore()
const TAB_ORDER_SCOPE = 'order.wave.tabs.order'
function openSortDialog() {
sortDialogVisible.value = true
}
/** 保存标签顺序:按新顺序重排 tabs 数组(组件对象原样复用,缺失项留在末尾) */
function handleSortSaved(order: string[]) {
applyTabOrder(order)
}
/** 读取本账号保存的标签顺序并应用;无配置时保持默认顺序 */
function applySavedTabOrder() {
const saved = preferenceStore.get(TAB_ORDER_SCOPE)
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: WaveTabItem[] = []
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
}
/**
* 首屏 / 外部导航时从地址栏恢复 tab。
* 方案B:页签切换改为纯本地状态(handleTabChange 不写回路由),
* 因为布局层 AppMain 使用 route.fullPath 作为 router-view 的 key,
* 任何 URL 变化(含 ?tab=)都会触发整页销毁重建,导致切换卡顿、重复请求与显示闪烁。
* 此处仅:① 首屏按 URL 初始化;② 浏览器前进/后退等外部导航时同步本地 tab。
* 非法 / 缺失 tab 时纯本地归位到团购波次,绝不写回路由。
*/
watch(
() => route.query.tab,
(newTab) => {
const validTabs = tabs.value.map((t) => t.name)
const raw = newTab === undefined || newTab === null ? '' : String(newTab).trim()
if (raw && validTabs.includes(raw)) {
activeTab.value = raw
return
}
activeTab.value = 'groupWave'
},
{ immediate: true }
)
const handleTabChange = (tabName: string | number) => {
safeInvoke(() => {
const name = String(tabName)
// 方案B:纯本地切换,不写回路由(避免改变 fullPath 触发 AppMain 整页销毁重建)
if (activeTab.value === name) {
return
}
activeTab.value = name
})
}
onMounted(() => {
applySavedTabOrder()
})
</script>
<style lang="scss" scoped>
.order-management-wrapper {
position: relative;
width: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ===== 顶部多标签页区域(对齐 order/orderManagement 的 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 区域左侧,样式对齐 order/orderManagement) */
.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;
}
/* 隐藏内容区,仅展示标签头(对齐 order/orderManagement) */
:deep(.el-tabs__content) {
display: none;
}
}
.custom-tab-label {
display: inline-flex;
align-items: center;
gap: 6px;
}
/* ===== 主内容区容器(对齐 order/orderManagement 的 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>