feat(frontend): 新增导出任务页面与多标签页导航
- 新增 views/ExportTask/Index.vue:发起导出、轮询进度、完成后自动下载、历史列表, 以及 api/exportTask.ts - 新增 store/tabs.ts:顶部多标签页(打开/关闭/固定),BasicLayout 接入;顶栏账号头像 改走 mediaUrl 拼 API origin - 路由新增 /export-tasks,默认落地与已登录访问登录页时跳转改为 /dashboard (动态路由尚未注册时由守卫重新解析当前目标) - 登录页标题改为「天豹 OMS 管理系统」
This commit is contained in:
parent
441659d303
commit
640f39ed2e
83
frontend/src/api/exportTask.ts
Normal file
83
frontend/src/api/exportTask.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { get, post } from '@/utils/request'
|
||||
import request from '@/utils/request'
|
||||
|
||||
/** 导出类型:出入库记录 / 商品 / 订单 */
|
||||
export type ExportType = 'stock_record' | 'product' | 'order'
|
||||
|
||||
/** 导出任务状态:0待处理 1处理中 2已完成 3失败 */
|
||||
export type ExportStatus = 0 | 1 | 2 | 3
|
||||
|
||||
/** 导出类型选项(后端返回) */
|
||||
export interface ExportTypeOption {
|
||||
value: ExportType
|
||||
label: string
|
||||
}
|
||||
|
||||
/** 导出任务项 */
|
||||
export interface ExportTaskItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
type: ExportType
|
||||
type_label?: string
|
||||
status: ExportStatus
|
||||
status_label?: string
|
||||
sql?: string
|
||||
file_name: string | null
|
||||
file_path: string | null
|
||||
total_count: number
|
||||
processed_count: number
|
||||
progress: number
|
||||
error_message: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 导出筛选条件(按类型可选字段) */
|
||||
export interface ExportFilters {
|
||||
product_id?: number | null
|
||||
warehouse_id?: number | null
|
||||
biz_type?: string
|
||||
direction?: number | string
|
||||
bill_type?: number | string
|
||||
item_type?: string
|
||||
bill_no?: string
|
||||
keyword?: string
|
||||
category_name?: string
|
||||
status?: number | string
|
||||
submit_status?: number | string
|
||||
shop_id?: number | null
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/** 导出类型选项 */
|
||||
export function getExportTypes() {
|
||||
return get<ExportTypeOption[]>('/export-tasks/types')
|
||||
}
|
||||
|
||||
/** 提交导出任务:立即返回任务ID */
|
||||
export function submitExport(payload: { type: ExportType; filters?: ExportFilters }) {
|
||||
return post<{ id: number; type: ExportType; status: number }>('/export-tasks', payload)
|
||||
}
|
||||
|
||||
/** 导出任务列表(按主体隔离) */
|
||||
export function getExportTasks(params?: object) {
|
||||
return get<{ list: ExportTaskItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/export-tasks',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 导出任务进度 */
|
||||
export function getExportTask(id: number) {
|
||||
return get<ExportTaskItem>('/export-tasks/' + id)
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载导出文件:以 blob 形式拉取(走鉴权拦截器),由调用方触发浏览器下载
|
||||
* @param id 任务ID
|
||||
* @return Promise<Blob> CSV 文件流
|
||||
*/
|
||||
export function downloadExport(id: number) {
|
||||
return request.get('/export-tasks/' + id + '/download', { responseType: 'blob' }) as unknown as Promise<Blob>
|
||||
}
|
||||
@ -1,17 +1,92 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { RouterView, useRouter } from 'vue-router'
|
||||
import { computed, onMounted, onBeforeUnmount, watch, nextTick, ref } from 'vue'
|
||||
import { RouterView, useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { ArrowDown } from '@element-plus/icons-vue'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { useMenuStore } from '@/store/menu'
|
||||
import { usePrincipalStore } from '@/store/principal'
|
||||
import { useTabsStore } from '@/store/tabs'
|
||||
import SideMenu from '@/components/SideMenu.vue'
|
||||
import { mediaUrl } from '@/utils/media'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const menuStore = useMenuStore()
|
||||
const principalStore = usePrincipalStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const tabs = useTabsStore()
|
||||
|
||||
// 保活标签:恢复历史打开页面,并跟随路由把每个页面记为一个标签,支持快速切换
|
||||
tabs.init(route)
|
||||
watch(
|
||||
() => route.fullPath,
|
||||
() => tabs.addTab(route),
|
||||
)
|
||||
|
||||
function onTabChange(name: string | number) {
|
||||
const tab = tabs.tabs.find((t) => t.key === name)
|
||||
if (tab) router.push(tab.fullPath)
|
||||
}
|
||||
|
||||
function onTabRemove(name: string | number) {
|
||||
tabs.removeTab(String(name))
|
||||
}
|
||||
|
||||
/* ---- 标签溢出折叠:超出宽度的标签隐藏,并入「更多」下拉 ---- */
|
||||
const visibleCount = ref(999)
|
||||
const tabWidths = new Map<string, number>()
|
||||
|
||||
// 实际渲染在标签条上的标签:保证激活项始终可见(必要时替换最后一项)
|
||||
const visibleTabs = computed(() => {
|
||||
const all = tabs.tabs
|
||||
const n = Math.min(visibleCount.value, all.length)
|
||||
if (n <= 0) return all.slice(0, 1)
|
||||
const slice = all.slice(0, n)
|
||||
const activeIdx = all.findIndex((t) => t.key === tabs.active)
|
||||
if (activeIdx >= n) slice[n - 1] = all[activeIdx]
|
||||
return slice
|
||||
})
|
||||
|
||||
function estimateWidth(t: { key: string; title: string; affix: boolean }): number {
|
||||
const cached = tabWidths.get(t.key)
|
||||
if (cached) return cached
|
||||
// 标题宽度估算:字号 13px + 左右内边距 40 + 可关闭时的 x 图标 14
|
||||
return t.title.length * 13 + 40 + (t.affix ? 0 : 14)
|
||||
}
|
||||
|
||||
function recalcTabs() {
|
||||
const scroll = document.querySelector(
|
||||
'.app-tabs__inner .el-tabs__nav-scroll',
|
||||
) as HTMLElement | null
|
||||
if (!scroll) return
|
||||
const avail = scroll.clientWidth
|
||||
// 缓存当前可见标签的真实宽度
|
||||
const items = Array.from(scroll.querySelectorAll('.el-tabs__item')) as HTMLElement[]
|
||||
items.forEach((el, i) => {
|
||||
const key = visibleTabs.value[i]?.key
|
||||
if (key) tabWidths.set(key, el.offsetWidth)
|
||||
})
|
||||
// 按全部标签宽度累加,计算能放下的数量
|
||||
let used = 0
|
||||
let count = 0
|
||||
for (const t of tabs.tabs) {
|
||||
const w = tabWidths.get(t.key) ?? estimateWidth(t)
|
||||
if (used + w <= avail) {
|
||||
used += w
|
||||
count++
|
||||
} else break
|
||||
}
|
||||
visibleCount.value = Math.max(1, count)
|
||||
}
|
||||
|
||||
function gotoTab(tab: { key: string; fullPath: string }) {
|
||||
tabs.active = tab.key
|
||||
router.push(tab.fullPath)
|
||||
}
|
||||
|
||||
let resizeObserver: ResizeObserver | null = null
|
||||
|
||||
|
||||
/**
|
||||
* 当前账号在当前主体下的名称与头像(来自主体账号关联表 principal_users.name / avatar)。
|
||||
@ -22,7 +97,7 @@ const accountProfile = computed(() => {
|
||||
const currentId = principalStore.currentId
|
||||
const relation = (user?.principals || []).find(p => Number(p.id) === Number(currentId))
|
||||
const name = relation?.account_name || user?.nickname || user?.username || ''
|
||||
const avatar = relation?.account_avatar || ''
|
||||
const avatar = mediaUrl(relation?.account_avatar || '')
|
||||
return { name, avatar, initial: name ? Array.from(name.trim())[0] || '' : '' }
|
||||
})
|
||||
|
||||
@ -30,8 +105,28 @@ onMounted(() => {
|
||||
// 当前主体若已不在所属列表内(如切换账号),重置为第一个
|
||||
const ids = (auth.user?.principals || []).map((p) => p.id)
|
||||
principalStore.ensureValid(ids)
|
||||
// 计算标签条可见数量,处理溢出折叠
|
||||
nextTick(recalcTabs)
|
||||
// 布局/字体就绪后再算一次,避免首帧宽度未稳定导致收起数量不准
|
||||
requestAnimationFrame(recalcTabs)
|
||||
if (document.fonts?.ready) document.fonts.ready.then(recalcTabs)
|
||||
resizeObserver = new ResizeObserver(() => recalcTabs())
|
||||
const scroll = document.querySelector('.app-tabs__inner .el-tabs__nav-scroll')
|
||||
if (scroll) resizeObserver.observe(scroll)
|
||||
window.addEventListener('resize', recalcTabs)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
resizeObserver?.disconnect()
|
||||
window.removeEventListener('resize', recalcTabs)
|
||||
})
|
||||
|
||||
// 标签增减 / 激活项变化 / 顺序变化时重新计算可见数量
|
||||
watch(
|
||||
() => [tabs.tabs.length, tabs.active, tabs.tabs.map((t) => t.key).join('|')],
|
||||
() => nextTick(recalcTabs),
|
||||
)
|
||||
|
||||
function logout() {
|
||||
ElMessageBox.confirm('确定要退出登录吗?', '提示', { type: 'warning' })
|
||||
.then(() => {
|
||||
@ -45,6 +140,11 @@ function goLogin() {
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
// 进入导出任务页(全局任务池:提交后后台异步处理,完成后自动下载)
|
||||
function goExport() {
|
||||
router.push('/export-tasks')
|
||||
}
|
||||
|
||||
// 切换当前主体:持久化到 localStorage 并刷新页面以按新主体重新拉取数据
|
||||
function onPrincipalChange(id: number) {
|
||||
principalStore.setCurrentId(id)
|
||||
@ -62,7 +162,42 @@ function onPrincipalChange(id: number) {
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header class="app-header">
|
||||
<div class="app-tabs">
|
||||
<el-tabs
|
||||
v-model="tabs.active"
|
||||
type="card"
|
||||
class="app-tabs__inner"
|
||||
@tab-change="onTabChange"
|
||||
@tab-remove="onTabRemove"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="tab in visibleTabs"
|
||||
:key="tab.key"
|
||||
:name="tab.key"
|
||||
:label="tab.title"
|
||||
:closable="!tab.affix"
|
||||
/>
|
||||
</el-tabs>
|
||||
<el-dropdown trigger="click">
|
||||
<el-button text size="small" :icon="ArrowDown">更多</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
v-for="tab in tabs.tabs"
|
||||
:key="tab.key"
|
||||
@click="gotoTab(tab)"
|
||||
:style="{ color: tab.key === tabs.active ? 'var(--el-color-primary)' : '' }"
|
||||
>
|
||||
{{ tab.title }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided @click="tabs.closeOthers(tabs.active)">关闭其他</el-dropdown-item>
|
||||
<el-dropdown-item @click="tabs.closeAll()">关闭全部</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
<div class="user-area">
|
||||
<el-button text type="primary" @click="goExport">导出任务</el-button>
|
||||
<el-select
|
||||
v-if="auth.user?.principals && auth.user.principals.length"
|
||||
:model-value="principalStore.currentId"
|
||||
@ -96,7 +231,11 @@ function onPrincipalChange(id: number) {
|
||||
</div>
|
||||
</el-header>
|
||||
<el-main class="app-main">
|
||||
<RouterView />
|
||||
<RouterView v-slot="{ Component }">
|
||||
<KeepAlive :max="20">
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</KeepAlive>
|
||||
</RouterView>
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
@ -105,6 +244,8 @@ function onPrincipalChange(id: number) {
|
||||
<style scoped>
|
||||
.app-container {
|
||||
height: 100%;
|
||||
/* 顶栏与侧边栏 logo 高度保持一致 */
|
||||
--app-header-height: 56px;
|
||||
}
|
||||
|
||||
.app-aside {
|
||||
@ -115,7 +256,7 @@ function onPrincipalChange(id: number) {
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 56px;
|
||||
height: var(--app-header-height);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@ -131,12 +272,25 @@ function onPrincipalChange(id: number) {
|
||||
}
|
||||
|
||||
.app-header {
|
||||
height: var(--app-header-height);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
padding: 0 12px;
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid var(--el-border-color);
|
||||
background-color: #f5f7fa;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* 顶栏底线放在最底层,让激活的 tab 能压住它,与下方正文连成一体 */
|
||||
.app-header::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: 1px;
|
||||
background: var(--el-border-color);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.user-area {
|
||||
@ -176,4 +330,90 @@ function onPrincipalChange(id: number) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.app-tabs {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
align-self: flex-end;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.app-tabs__inner {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* 去掉 el-tabs 自带的底部边框与包裹边框,改由顶栏底线统一表现。
|
||||
card 头部默认固定 40px 高(items 仅 30px),会导致激活项够不到底线的间隙,
|
||||
这里改为内容高度并贴底对齐,消除间隙。 */
|
||||
.app-tabs__inner :deep(.el-tabs__header) {
|
||||
margin: 0;
|
||||
border-bottom: none;
|
||||
height: auto;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
/* nav-wrap 裁剪溢出(由「更多」承载多余标签),并贴底以保证激活项压住顶栏底线 */
|
||||
.app-tabs__inner :deep(.el-tabs__nav-wrap) {
|
||||
overflow: hidden;
|
||||
margin-bottom: 0;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
/* 禁用 el-tabs 自带的左右滚动箭头,溢出统一收进「更多」下拉 */
|
||||
.app-tabs__inner :deep(.el-tabs__nav-prev),
|
||||
.app-tabs__inner :deep(.el-tabs__nav-next) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.app-tabs__inner :deep(.el-tabs__nav) {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.app-tabs__inner :deep(.el-tabs__item) {
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
font-size: 13px;
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
color: var(--el-text-color-regular);
|
||||
border-radius: 6px 6px 0 0;
|
||||
transition: background-color .2s, color .2s;
|
||||
}
|
||||
|
||||
/* 非激活 tab 悬停高亮(背景 + 主色文字) */
|
||||
.app-tabs__inner :deep(.el-tabs__item:not(.is-active):hover) {
|
||||
background-color: rgba(0, 0, 0, 0.04);
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
/* 非激活 tab 不显示关闭按钮,避免 hover 时宽度浮动 */
|
||||
.app-tabs__inner :deep(.el-tabs__item:not(.is-active) .is-icon-close) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* 激活 tab 常显关闭按钮,宽度恒定不抖动 */
|
||||
.app-tabs__inner :deep(.el-tabs__item.is-active .is-icon-close) {
|
||||
display: inline-flex;
|
||||
width: 14px;
|
||||
}
|
||||
|
||||
/* 保持 closable tab 悬停时内边距不变,防止宽度抖动 */
|
||||
.app-tabs__inner :deep(.el-tabs__item.is-closable:hover) {
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
/* 激活项:白色块下沉 1px 压住顶栏底线,与下方正文无缝连接并突出当前块 */
|
||||
.app-tabs__inner :deep(.el-tabs__item.is-active) {
|
||||
background-color: #fff;
|
||||
color: var(--el-color-primary);
|
||||
font-weight: 600;
|
||||
margin-bottom: -1px;
|
||||
border-bottom: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -14,10 +14,16 @@ const router = createRouter({
|
||||
path: '/',
|
||||
component: () => import('@/layouts/BasicLayout.vue'),
|
||||
name: 'layout',
|
||||
redirect: { name: 'home' },
|
||||
redirect: { path: '/dashboard' },
|
||||
children: [
|
||||
{ path: '', name: 'home', component: () => import('@/views/Home.vue'), meta: { title: '首页' } },
|
||||
{ path: 'about', name: 'about', component: () => import('@/views/About.vue'), meta: { title: '关于' } },
|
||||
{
|
||||
path: 'export-tasks',
|
||||
name: 'exportTasks',
|
||||
component: () => import('@/views/ExportTask/Index.vue'),
|
||||
meta: { title: '导出任务' },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@ -30,7 +36,7 @@ router.beforeEach(async (to) => {
|
||||
return { name: 'login', query: { redirect: to.fullPath } }
|
||||
}
|
||||
if (to.name === 'login' && token) {
|
||||
return { name: 'home' }
|
||||
return { path: '/dashboard' }
|
||||
}
|
||||
if (token) {
|
||||
const { useAuthStore } = await import('@/store/auth')
|
||||
|
||||
104
frontend/src/store/tabs.ts
Normal file
104
frontend/src/store/tabs.ts
Normal file
@ -0,0 +1,104 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type { RouteLocationNormalized } from 'vue-router'
|
||||
import router from '@/router'
|
||||
|
||||
/** 单个保活标签 */
|
||||
export interface TabItem {
|
||||
/** keep-alive 缓存键:用 route.fullPath,保证同一路径不同查询参数各自缓存 */
|
||||
key: string
|
||||
/** 跳转用完整路径 */
|
||||
fullPath: string
|
||||
/** 标签标题(来自路由 meta.title) */
|
||||
title: string
|
||||
/** 固定标签(首页)不可关闭 */
|
||||
affix: boolean
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'oms-tabs'
|
||||
const MAX_TABS = 20
|
||||
|
||||
/** 从本地恢复上次会话的标签历史 */
|
||||
function loadTabs(): TabItem[] {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
if (raw) return JSON.parse(raw) as TabItem[]
|
||||
} catch {
|
||||
/* 本地数据损坏时忽略,退回空列表 */
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export const useTabsStore = defineStore('tabs', () => {
|
||||
const tabs = ref<TabItem[]>([])
|
||||
const active = ref('')
|
||||
|
||||
function persist() {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(tabs.value))
|
||||
} catch {
|
||||
/* 容量超限等异常忽略 */
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化:固定首页标签 + 恢复本地历史,并把当前页面也纳入标签 */
|
||||
function init(current?: RouteLocationNormalized) {
|
||||
// 仪表盘即首页:固定标签使用「/dashboard」路由,与侧边栏「仪表盘」入口一致,避免重复开标签
|
||||
const home: TabItem = { key: '/dashboard', fullPath: '/dashboard', title: '首页', affix: true }
|
||||
// 过滤掉旧会话遗留的「/」首页标签,防止与仪表盘首页重复
|
||||
const others = loadTabs().filter((t) => t.key !== home.key && t.key !== '/')
|
||||
tabs.value = [home, ...others].slice(0, MAX_TABS)
|
||||
active.value = home.key
|
||||
if (current && current.fullPath !== home.key && current.fullPath !== '/') addTab(current)
|
||||
}
|
||||
|
||||
/** 打开 / 激活一个页面标签 */
|
||||
function addTab(route: RouteLocationNormalized) {
|
||||
const title =
|
||||
(route.meta?.title as string) || (route.name ? String(route.name) : route.path) || '未命名'
|
||||
// 根路径「/」与仪表盘「/dashboard」是同一首页,统一为 /dashboard 复用固定标签
|
||||
const key = route.fullPath === '/' ? '/dashboard' : route.fullPath
|
||||
if (!tabs.value.some((t) => t.key === key)) {
|
||||
// 超出上限时移除最早打开的非固定标签
|
||||
if (tabs.value.length >= MAX_TABS) {
|
||||
const idx = tabs.value.findIndex((t) => !t.affix)
|
||||
if (idx !== -1) tabs.value.splice(idx, 1)
|
||||
}
|
||||
tabs.value.push({ key, fullPath: route.fullPath, title, affix: false })
|
||||
}
|
||||
active.value = key
|
||||
persist()
|
||||
}
|
||||
|
||||
/** 关闭指定标签;若关闭的是当前页,自动跳到相邻标签 */
|
||||
function removeTab(key: string) {
|
||||
const idx = tabs.value.findIndex((t) => t.key === key)
|
||||
if (idx === -1) return
|
||||
if (tabs.value[idx].affix) return
|
||||
tabs.value.splice(idx, 1)
|
||||
if (active.value === key) {
|
||||
const next = tabs.value[idx] || tabs.value[idx - 1]
|
||||
if (next) router.push(next.fullPath)
|
||||
else active.value = ''
|
||||
}
|
||||
persist()
|
||||
}
|
||||
|
||||
/** 关闭除指定标签外的全部(保留固定标签) */
|
||||
function closeOthers(key: string) {
|
||||
tabs.value = tabs.value.filter((t) => t.affix || t.key === key)
|
||||
active.value = key
|
||||
persist()
|
||||
}
|
||||
|
||||
/** 关闭全部(保留固定标签) */
|
||||
function closeAll() {
|
||||
tabs.value = tabs.value.filter((t) => t.affix)
|
||||
const first = tabs.value[0]
|
||||
active.value = first?.key ?? ''
|
||||
if (first) router.push(first.fullPath)
|
||||
persist()
|
||||
}
|
||||
|
||||
return { tabs, active, init, addTab, removeTab, closeOthers, closeAll }
|
||||
})
|
||||
458
frontend/src/views/ExportTask/Index.vue
Normal file
458
frontend/src/views/ExportTask/Index.vue
Normal file
@ -0,0 +1,458 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import {
|
||||
downloadExport,
|
||||
getExportTasks,
|
||||
getExportTypes,
|
||||
submitExport,
|
||||
type ExportFilters,
|
||||
type ExportTaskItem,
|
||||
type ExportType,
|
||||
type ExportTypeOption,
|
||||
} from '@/api/exportTask'
|
||||
|
||||
/**
|
||||
* 导出任务页(全局任务池)
|
||||
* - 提交导出(选类型 + 筛选)→ 立即得到任务ID,定时任务在后台逐个处理并落盘 CSV
|
||||
* - 列表轮询进度;任务「完成」后自动触发浏览器下载(也可手动点「下载」)
|
||||
* - 文件按 年/月/日 分目录存储,记录按当前主体隔离
|
||||
*/
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
type: '' as string,
|
||||
status: '' as string | number,
|
||||
})
|
||||
|
||||
const typeOptions = ref<ExportTypeOption[]>([])
|
||||
|
||||
const STATUS_TAG: Record<number, 'info' | 'success' | 'warning' | 'danger'> = {
|
||||
0: 'info',
|
||||
1: 'warning',
|
||||
2: 'success',
|
||||
3: 'danger',
|
||||
}
|
||||
const STATUS_TEXT: Record<number, string> = { 0: '待处理', 1: '处理中', 2: '已完成', 3: '失败' }
|
||||
const statusOptions = [
|
||||
{ label: '待处理', value: 0 },
|
||||
{ label: '处理中', value: 1 },
|
||||
{ label: '已完成', value: 2 },
|
||||
{ label: '失败', value: 3 },
|
||||
]
|
||||
const orderStatusOptions = [
|
||||
{ label: '待处理', value: 1 },
|
||||
{ label: '处理中', value: 2 },
|
||||
{ label: '已完成', value: 3 },
|
||||
{ label: '已取消', value: 4 },
|
||||
]
|
||||
const submitStatusOptions = [
|
||||
{ label: '未上交', value: 0 },
|
||||
{ label: '上交中', value: 1 },
|
||||
{ label: '已上交', value: 2 },
|
||||
{ label: '上交失败', value: 3 },
|
||||
]
|
||||
const productStatusOptions = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
]
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } =
|
||||
useListPage<ExportTaskItem, typeof query>({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { page: query.page, pageSize: query.pageSize }
|
||||
if (query.type) params.type = query.type
|
||||
if (query.status !== '') params.status = query.status
|
||||
return getExportTasks(params)
|
||||
},
|
||||
})
|
||||
|
||||
async function fetchTypes() {
|
||||
try {
|
||||
typeOptions.value = await getExportTypes()
|
||||
} catch {
|
||||
typeOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 提交导出对话框 ---------- */
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const form = reactive({
|
||||
type: '' as ExportType | '',
|
||||
keyword: '',
|
||||
dateRange: [] as string[],
|
||||
biz_type: '',
|
||||
direction: '' as string | number,
|
||||
bill_type: '' as string | number,
|
||||
item_type: '',
|
||||
bill_no: '',
|
||||
product_id: null as number | null,
|
||||
product_label: '',
|
||||
status: '' as string | number,
|
||||
submit_status: '' as string | number,
|
||||
})
|
||||
|
||||
function openDialog() {
|
||||
form.type = typeOptions.value[0]?.value || 'stock_record'
|
||||
form.keyword = ''
|
||||
form.dateRange = []
|
||||
form.biz_type = ''
|
||||
form.direction = ''
|
||||
form.bill_type = ''
|
||||
form.item_type = ''
|
||||
form.bill_no = ''
|
||||
form.product_id = null
|
||||
form.product_label = ''
|
||||
form.status = ''
|
||||
form.submit_status = ''
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function onProductLock(p: { id: number; item_code?: string; item_name?: string } | null) {
|
||||
if (!p) {
|
||||
onProductClear()
|
||||
return
|
||||
}
|
||||
form.product_id = p.id
|
||||
form.product_label = p.item_code ? `${p.item_code} ${p.item_name}` : p.item_name || ''
|
||||
}
|
||||
function onProductClear() {
|
||||
form.product_id = null
|
||||
form.product_label = ''
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
if (!form.type) {
|
||||
ElMessage.warning('请选择导出类型')
|
||||
return
|
||||
}
|
||||
const filters: ExportFilters = {}
|
||||
if (form.keyword) filters.keyword = form.keyword.trim()
|
||||
if (form.dateRange.length === 2) {
|
||||
filters.start_time = form.dateRange[0]
|
||||
filters.end_time = form.dateRange[1]
|
||||
}
|
||||
if (form.type === 'stock_record') {
|
||||
if (form.product_id != null) filters.product_id = form.product_id
|
||||
if (form.biz_type) filters.biz_type = form.biz_type
|
||||
if (form.direction !== '') filters.direction = form.direction
|
||||
if (form.bill_type !== '') filters.bill_type = form.bill_type
|
||||
if (form.item_type) filters.item_type = form.item_type
|
||||
if (form.bill_no) filters.bill_no = form.bill_no.trim()
|
||||
} else if (form.type === 'product') {
|
||||
if (form.status !== '') filters.status = form.status
|
||||
} else if (form.type === 'order') {
|
||||
if (form.status !== '') filters.status = form.status
|
||||
if (form.submit_status !== '') filters.submit_status = form.submit_status
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const res = await submitExport({ type: form.type as ExportType, filters })
|
||||
ElMessage.success('已提交导出任务,处理完成后将自动下载')
|
||||
autoDownloadIds.value.add(res.id)
|
||||
dialogVisible.value = false
|
||||
await refresh()
|
||||
startPolling()
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 轮询进度 + 完成自动下载 ---------- */
|
||||
const autoDownloadIds = ref<Set<number>>(new Set())
|
||||
const pollingTimer = ref<number | null>(null)
|
||||
|
||||
function hasActive(arr: ExportTaskItem[]) {
|
||||
return arr.some(t => t.status === 0 || t.status === 1)
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
await fetchList()
|
||||
for (const t of list.value) {
|
||||
if (t.status === 2 && autoDownloadIds.value.has(t.id)) {
|
||||
autoDownloadIds.value.delete(t.id)
|
||||
triggerDownload(t.id, t.file_name)
|
||||
}
|
||||
}
|
||||
if (!hasActive(list.value) && autoDownloadIds.value.size === 0) {
|
||||
stopPolling()
|
||||
}
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
if (pollingTimer.value != null) return
|
||||
pollingTimer.value = window.setInterval(() => { refresh().catch(() => {}) }, 2000)
|
||||
}
|
||||
function stopPolling() {
|
||||
if (pollingTimer.value != null) {
|
||||
clearInterval(pollingTimer.value)
|
||||
pollingTimer.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function triggerDownload(id: number, fileName?: string | null) {
|
||||
try {
|
||||
const blob = await downloadExport(id)
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = fileName || `export_${id}.xlsx`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(url)
|
||||
} catch {
|
||||
// 错误已由响应拦截器统一提示
|
||||
}
|
||||
}
|
||||
|
||||
function statusText(v: number) {
|
||||
return STATUS_TEXT[v] || String(v)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchTypes()
|
||||
fetchList()
|
||||
startPolling()
|
||||
})
|
||||
onUnmounted(() => stopPolling())
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card class="export-card">
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>导出任务</span>
|
||||
<span class="hint">提交后后台异步处理,完成后自动下载(XLSX 按 年/月/日 分目录存储)</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form :inline="true" class="search-bar" size="small">
|
||||
<el-form-item label="类型">
|
||||
<el-select v-model="query.type" placeholder="全部" clearable style="width: 150px">
|
||||
<el-option v-for="o in typeOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 120px">
|
||||
<el-option v-for="o in statusOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button type="success" @click="openDialog">新建导出</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="table-wrap">
|
||||
<DataTable :loading="loading" :data="list" class="fill-table">
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column label="类型" width="120">
|
||||
<template #default="{ row }">{{ row.type_label || row.type }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="STATUS_TAG[row.status]">{{ statusText(row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="进度" width="180">
|
||||
<template #default="{ row }">
|
||||
<el-progress
|
||||
:percentage="row.progress || 0"
|
||||
:status="row.status === 3 ? 'exception' : row.status === 2 ? 'success' : undefined"
|
||||
/>
|
||||
<span class="progress-sub">已处理 {{ row.processed_count }}/{{ row.total_count || 0 }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="file_name" label="文件名" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="created_at" label="创建时间" width="165">
|
||||
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="失败原因" min-width="160" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.error_message || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="100" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-if="row.status === 2"
|
||||
type="primary"
|
||||
link
|
||||
@click="triggerDownload(row.id, row.file_name)"
|
||||
>下载</el-button>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<!-- 新建导出对话框 -->
|
||||
<el-dialog v-model="dialogVisible" title="新建导出" width="560px" append-to-body>
|
||||
<el-form label-width="90px" size="small">
|
||||
<el-form-item label="导出类型" required>
|
||||
<el-select v-model="form.type" placeholder="请选择" style="width: 100%">
|
||||
<el-option v-for="o in typeOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="form.keyword"
|
||||
:placeholder="form.type === 'order' ? '订单号 / 备注' : '编码 / 名称'"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="form.type === 'stock_record'">
|
||||
<el-form-item label="商品">
|
||||
<div class="product-filter">
|
||||
<ProductSelect
|
||||
v-model="form.product_id"
|
||||
:model-label="form.product_label"
|
||||
placeholder="搜索商品编码/名称锁定商品"
|
||||
@select="onProductLock"
|
||||
/>
|
||||
<el-button v-if="form.product_id != null" link type="primary" @click="onProductClear">清除</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="业务动作">
|
||||
<el-select v-model="form.biz_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="出库推送锁定" value="outbound_lock" />
|
||||
<el-option label="出库解锁" value="outbound_unlock" />
|
||||
<el-option label="出库确认扣减" value="outbound_deduct" />
|
||||
<el-option label="出库驳回回补" value="outbound_restore" />
|
||||
<el-option label="入库确认增加" value="inbound_increase" />
|
||||
<el-option label="订单审核锁定" value="order_lock" />
|
||||
<el-option label="订单解锁" value="order_unlock" />
|
||||
<el-option label="订单发货确认扣减" value="order_deduct" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="方向">
|
||||
<el-select v-model="form.direction" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="入库" :value="1" />
|
||||
<el-option label="出库" :value="2" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="单据类型">
|
||||
<el-select v-model="form.bill_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="入库单" :value="1" />
|
||||
<el-option label="出库单" :value="2" />
|
||||
<el-option label="发货单" :value="3" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="库存类型">
|
||||
<el-select v-model="form.item_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="正品" value="ZC" />
|
||||
<el-option label="残次品" value="CC" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="单据号">
|
||||
<el-input v-model="form.bill_no" placeholder="如 CK_1" clearable />
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<template v-if="form.type === 'product'">
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="form.status" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option v-for="o in productStatusOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<template v-if="form.type === 'order'">
|
||||
<el-form-item label="订单状态">
|
||||
<el-select v-model="form.status" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option v-for="o in orderStatusOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="上交状态">
|
||||
<el-select v-model="form.submit_status" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option v-for="o in submitStatusOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<el-form-item v-if="form.type === 'stock_record' || form.type === 'order'" label="时间区间">
|
||||
<el-date-picker
|
||||
v-model="form.dateRange"
|
||||
type="daterange"
|
||||
value-format="YYYY-MM-DD"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="onSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.export-card {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.export-card :deep(.el-card__header) {
|
||||
padding: 8px 14px;
|
||||
}
|
||||
.export-card :deep(.el-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
padding: 10px 14px;
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.page-header .hint {
|
||||
font-weight: 400;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.product-filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.progress-sub {
|
||||
font-size: 11px;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-left: 6px;
|
||||
}
|
||||
</style>
|
||||
@ -304,7 +304,7 @@ onUnmounted(() => {
|
||||
<template>
|
||||
<div class="login-page">
|
||||
<el-card class="login-card">
|
||||
<div class="login-title">OMS 管理系统</div>
|
||||
<div class="login-title">天豹 OMS 管理系统</div>
|
||||
<el-tabs v-model="loginTab" stretch>
|
||||
<el-tab-pane label="账号登录" name="account">
|
||||
<el-form
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user