优化
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import '@/styles/adminDensity.css'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { MapPin, Plus, Save } from '@lucide/vue'
|
||||
import { MapPin, Plus, Printer, Save } from '@lucide/vue'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useUnsavedWorkRegistration } from '@/core/unsaved-work/useUnsavedWorkRegistration'
|
||||
import { getApiErrorDetails, type ApiErrorDetails } from '@/shared/api/http'
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
type SavePlatformLocationRequest,
|
||||
} from '../api/platformLocations'
|
||||
import { listAllPlatformWarehouses, type PlatformWarehouseResource } from '../../../warehouses/api/platformWarehouses'
|
||||
import { printLocationLabels, type LocationLabelPrintItem } from '../utils/locationLabelPrint'
|
||||
|
||||
type EditorMode = 'create' | 'edit'
|
||||
type LocationFilters = QueryModel & {
|
||||
@@ -51,6 +52,7 @@ const warehouseError = ref<ApiErrorDetails | null>(null)
|
||||
const loading = ref(false)
|
||||
const loadError = ref<ApiErrorDetails | null>(null)
|
||||
const rows = ref<PlatformLocationResource[]>([])
|
||||
const selectedRows = ref<PlatformLocationResource[]>([])
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const total = ref(0)
|
||||
@@ -170,7 +172,8 @@ const typeLabels: Record<PlatformLocationType, string> = {
|
||||
}
|
||||
|
||||
const columns: DataTableColumn[] = [
|
||||
{ key: 'actions', label: '操作', width: 240, fixed: 'left', slotName: 'actions' },
|
||||
{ key: 'actions', label: '操作', width: 300, fixed: 'left', slotName: 'actions' },
|
||||
{ key: 'selection', type: 'selection', width: 48, fixed: 'left' },
|
||||
{ key: 'location', label: '库位编码', minWidth: 190, slotName: 'location' },
|
||||
{ key: 'warehouse', label: '所属仓库', minWidth: 210, slotName: 'warehouse' },
|
||||
{ key: 'zone', label: '库区', minWidth: 150, slotName: 'zone' },
|
||||
@@ -239,6 +242,32 @@ function recordScope(row: PlatformLocationResource) {
|
||||
return { warehouseId: apiId(String(row.warehouseId)) }
|
||||
}
|
||||
|
||||
function printItem(row: PlatformLocationResource): LocationLabelPrintItem {
|
||||
const warehouse = warehouses.value.find((item) => String(item.id) === String(row.warehouseId))
|
||||
return {
|
||||
locationCode: row.locationCode,
|
||||
locationName: row.locationName,
|
||||
warehouseCode: row.warehouseCode || warehouse?.warehouseCode,
|
||||
warehouseName: row.warehouseName || warehouse?.warehouseName,
|
||||
zoneCode: row.zoneCode,
|
||||
zoneName: row.zoneName,
|
||||
}
|
||||
}
|
||||
|
||||
function printRows(targets: readonly PlatformLocationResource[]) {
|
||||
if (!targets.length) {
|
||||
ElMessage.warning('请先勾选需要打印的库位')
|
||||
return
|
||||
}
|
||||
if (!printLocationLabels(targets.map(printItem))) {
|
||||
ElMessage.warning('打印窗口被浏览器拦截,请允许弹出窗口后重试')
|
||||
}
|
||||
}
|
||||
|
||||
function onSelectionChange(selection: object[]) {
|
||||
selectedRows.value = selection as PlatformLocationResource[]
|
||||
}
|
||||
|
||||
async function loadWarehouses() {
|
||||
const sequence = ++warehouseLoadSequence
|
||||
warehouseLoading.value = true
|
||||
@@ -275,10 +304,12 @@ async function loadLocations() {
|
||||
const result = await listPlatformLocations(query)
|
||||
if (sequence !== locationLoadSequence) return
|
||||
rows.value = result.records
|
||||
selectedRows.value = []
|
||||
total.value = result.total
|
||||
} catch (error) {
|
||||
if (sequence !== locationLoadSequence) return
|
||||
rows.value = []
|
||||
selectedRows.value = []
|
||||
total.value = 0
|
||||
loadError.value = getApiErrorDetails(error, '库位列表加载失败,请稍后重试')
|
||||
} finally {
|
||||
@@ -527,10 +558,20 @@ onMounted(() => {
|
||||
row-key="id"
|
||||
aria-label="库位列表"
|
||||
:empty-text="emptyDescription"
|
||||
@selection-change="onSelectionChange"
|
||||
>
|
||||
<template #toolbar-actions><el-button v-if="access.can('platform:location:create')" type="primary" @click="openCreate"><Plus :size="16" />新增库位</el-button></template>
|
||||
<template #toolbar-actions>
|
||||
<el-button :disabled="loading || !selectedRows.length" @click="printRows(selectedRows)"><Printer :size="16" />打印所选<span v-if="selectedRows.length">({{ selectedRows.length }})</span></el-button>
|
||||
<el-button v-if="access.can('platform:location:create')" type="primary" @click="openCreate"><Plus :size="16" />新增库位</el-button>
|
||||
</template>
|
||||
<template #actions="{ row }">
|
||||
<div class="location-actions density-actions">
|
||||
<el-button
|
||||
size="small"
|
||||
class="density-action"
|
||||
:disabled="loading"
|
||||
@click="printRows([row as PlatformLocationResource])"
|
||||
>打印</el-button>
|
||||
<el-button
|
||||
v-if="canEdit(row as PlatformLocationResource)"
|
||||
size="small"
|
||||
|
||||
Reference in New Issue
Block a user