2026-07-25 18:14:50 +08:00

219 lines
5.3 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="stock-management-wrapper" :style="{ height: containerHeight }">
<!-- ===== 顶部多标签页区域(对齐 setting/encoding / waveOrder2 的 TabArea) ===== -->
<div class="tab-section">
<el-tabs
v-model="activeTab"
tab-position="top"
type="border-card"
class="tab-container"
@tab-change="handleTabChange"
>
<el-tab-pane
v-for="tab in tabs"
:key="tab.name"
:name="tab.name"
:label="tab.label"
:lazy="false"
/>
</el-tabs>
</div>
<!-- ===== 主内容区容器(对齐 setting/encoding / waveOrder2 的 main-container) ===== -->
<div class="main-container">
<component :is="tabs.find(t => t.name === activeTab)?.component" :key="activeTab" />
</div>
</div>
</template>
<script setup lang="ts">
import { computed, markRaw, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useSettingsStore } from '@/stores/modules/settings'
import { safeInvoke } from '@/utils/safe-invoke'
import StockDetail from '../stock/index.vue'
import ComboStock from '../combo_stock/index.vue'
const route = useRoute()
const router = useRouter()
const settingsStore = useSettingsStore()
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
const containerHeight = computed(() =>
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
)
type StockTabItem = {
name: string
label: string
component: any
}
const tabs = ref<StockTabItem[]>([
{
name: 'stockDetail',
label: '商品明细',
component: markRaw(StockDetail)
},
{
name: 'comboStock',
label: '组合商品',
component: markRaw(ComboStock)
}
])
const activeTab = ref('stockDetail')
function resolveDefaultTab(): string {
const path = String(route.path || '').toLowerCase()
if (path.includes('combo')) {
return 'comboStock'
}
return 'stockDetail'
}
watch(
() => [route.query.tab, route.path] as const,
([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 = resolveDefaultTab()
if (raw && !validTabs.includes(raw)) {
router.replace({
query: {
...route.query,
tab: resolveDefaultTab()
}
})
}
},
{ immediate: true }
)
const handleTabChange = (tabName: string | number) => {
safeInvoke(() => {
const name = String(tabName)
if (String(route.query.tab ?? '') === name) {
return
}
router.replace({
query: {
...route.query,
tab: name
}
})
})
}
</script>
<style lang="scss" scoped>
/* ================================================================
整体布局容器(对齐 setting/encoding / waveOrder2 的 wrapper)
================================================================ */
.stock-management-wrapper {
position: relative;
width: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* ================================================================
1. 顶部多标签页区域(对齐 setting/encoding / waveOrder2 的 tab-section)
================================================================ */
.tab-section {
flex-shrink: 0;
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;
:deep(.el-tabs__header) {
margin-bottom: 0;
flex-shrink: 0;
}
:deep(.el-tabs__header.is-top) {
padding: 4px 12px 0;
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;
}
/* 隐藏内容区,仅展示标签头(对齐 setting/encoding / waveOrder2 的 TabArea) */
:deep(.el-tabs__content) {
display: none;
}
}
/* ================================================================
2. 主内容区容器(对齐 setting/encoding / waveOrder2 的 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;
}
</style>