优化
This commit is contained in:
@@ -15,7 +15,7 @@ import ListPageLayout from '@/shared/components/ListPageLayout.vue'
|
||||
import LoadErrorState from '@/shared/components/LoadErrorState.vue'
|
||||
import OperationErrorToast from '@/shared/components/OperationErrorToast.vue'
|
||||
import QueryToolbar, { type QueryField, type QueryModel } from '@/shared/components/QueryToolbar.vue'
|
||||
import { createPallet, getPallet, getPalletSummary, listPallets, listReceivingOverseasWarehouses, updatePallet, type PalletDto, type PalletSummaryDto, type ReceivingOverseasWarehouseDto } from '../api/pallets'
|
||||
import { createPallet, getPallet, getPalletLabelPdf, getPalletSummary, listPallets, listReceivingOverseasWarehouses, updatePallet, type PalletDto, type PalletSummaryDto, type ReceivingOverseasWarehouseDto } from '../api/pallets'
|
||||
import { overseasWarehousePermissions as permission } from '../permissions'
|
||||
import type { PalletListItem } from '../types'
|
||||
|
||||
@@ -27,6 +27,7 @@ const rows = ref<PalletListItem[]>([])
|
||||
const loading = ref(false)
|
||||
const contextLoading = ref(false)
|
||||
const saving = ref(false)
|
||||
const printingId = ref('')
|
||||
const loadError = ref<ApiErrorDetails | null>(null)
|
||||
const mutationError = ref<ApiErrorDetails | null>(null)
|
||||
const loadErrorKind = ref<'context' | 'list'>('context')
|
||||
@@ -120,6 +121,21 @@ async function save() {
|
||||
}
|
||||
|
||||
function search(model: QueryModel) { page.value = 1; void load(model) }
|
||||
async function printPallet(source: object) {
|
||||
if (printingId.value) return
|
||||
const row = source as PalletListItem
|
||||
printingId.value = row.id; mutationError.value = null
|
||||
try {
|
||||
const blob = await getPalletLabelPdf(row.warehouseId, row.id)
|
||||
const url = URL.createObjectURL(blob)
|
||||
try {
|
||||
const link = document.createElement('a')
|
||||
link.href = url; link.download = `${row.code}-托盘码.pdf`; link.click()
|
||||
} finally { window.setTimeout(() => URL.revokeObjectURL(url), 0) }
|
||||
ElMessage.success('已生成 1 张托盘标签 PDF')
|
||||
} catch (error) { mutationError.value = getApiErrorDetails(error, '托盘标签打印失败,请重试') }
|
||||
finally { printingId.value = '' }
|
||||
}
|
||||
function resetSearch(model: QueryModel) { page.value = 1; void load(model) }
|
||||
function openDetail(source: object) { const row = source as PalletListItem; void router.push({ name: 'overseas-pallet-detail', params: { palletId: row.id }, query: { warehouseId: row.warehouseId } }) }
|
||||
async function initialize() { await loadWarehouses(); if (!loadError.value) await load() }
|
||||
@@ -134,7 +150,7 @@ onMounted(initialize)
|
||||
<template v-if="loadError" #state><LoadErrorState title="托盘数据加载失败" :message="loadError.message" :loading="loading || contextLoading" @retry="retryLoad"><template #details><ApiErrorMeta :details="loadError" /></template></LoadErrorState></template>
|
||||
<section v-if="!loadError" class="surface-panel table-panel"><DataTable v-model:page="page" v-model:page-size="pageSize" :data="rows" :columns="columns" :loading="loading" :total="total" preference-key="overseas-pallets" row-key="id" empty-text="暂无托盘" @update:page="load()" @update:page-size="page = 1; load()">
|
||||
<template #toolbar-actions><el-button v-if="access.can(permission.palletCreate)" type="primary" @click="openCreate"><Plus :size="16" />新增托盘</el-button></template>
|
||||
<template #actions="{ row }"><div class="density-actions"><el-button class="density-action" data-tone="neutral" size="small" @click="openDetail(row)">查看</el-button><el-button class="density-action" data-tone="neutral" v-if="access.can(permission.palletEdit)" size="small" @click="openEdit(row)">编辑</el-button></div></template>
|
||||
<template #actions="{ row }"><div class="density-actions"><el-button class="density-action" data-tone="neutral" size="small" @click="openDetail(row)">查看</el-button><el-button v-if="access.can(permission.palletList)" class="density-action" data-tone="neutral" size="small" :loading="printingId === row.id" :disabled="Boolean(printingId) && printingId !== row.id" @click="printPallet(row)">打印</el-button><el-button class="density-action" data-tone="neutral" v-if="access.can(permission.palletEdit)" size="small" @click="openEdit(row)">编辑</el-button></div></template>
|
||||
<template #pagination-left>共 {{ total }} 条托盘</template>
|
||||
</DataTable></section>
|
||||
</ListPageLayout>
|
||||
|
||||
Reference in New Issue
Block a user