<template>
|
<div class="device-bind-page art-full-height">
|
<ArtSearchBar
|
v-model="searchForm"
|
:items="searchItems"
|
:showExpand="true"
|
@search="handleSearch"
|
@reset="handleReset"
|
/>
|
|
<ElCard class="art-table-card">
|
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
<template #left>
|
<ElSpace wrap>
|
<ElButton v-auth="'add'" @click="showDialog('add')" v-ripple>新增绑定</ElButton>
|
<ElButton
|
v-auth="'delete'"
|
type="danger"
|
:disabled="selectedRows.length === 0"
|
@click="handleBatchDelete"
|
v-ripple
|
>
|
批量删除
|
</ElButton>
|
<ListExportPrint
|
class="inline-flex"
|
:preview-visible="previewVisible"
|
@update:previewVisible="handlePreviewVisibleChange"
|
:report-title="reportTitle"
|
:selected-rows="selectedRows"
|
:query-params="reportQueryParams"
|
:columns="columns"
|
:preview-rows="previewRows"
|
:preview-meta="resolvedPreviewMeta"
|
:total="pagination.total"
|
:disabled="loading"
|
@export="handleExport"
|
@print="handlePrint"
|
/>
|
</ElSpace>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@selection-change="handleSelectionChange"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
|
<DeviceBindDialog
|
v-model:visible="dialogVisible"
|
:dialog-type="dialogType"
|
:device-bind-data="currentDeviceBindData"
|
:type-options="typeOptions"
|
@submit="handleDialogSubmit"
|
/>
|
|
<DeviceBindDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail="detailData"
|
/>
|
</ElCard>
|
</div>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from 'vue'
|
import { ElMessage } from 'element-plus'
|
import { useUserStore } from '@/store/modules/user'
|
import { useAuth } from '@/hooks/core/useAuth'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useCrudPage } from '@/views/system/common/useCrudPage'
|
import { usePrintExportPage } from '@/views/system/common/usePrintExportPage'
|
import ListExportPrint from '@/components/biz/list-export-print/index.vue'
|
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import { fetchWarehouseAreasList } from '@/api/warehouse-areas'
|
import {
|
fetchDeleteDeviceBind,
|
fetchDeviceBindPage,
|
fetchExportDeviceBindReport,
|
fetchGetDeviceBindDetail,
|
fetchGetDeviceBindMany,
|
fetchSaveDeviceBind,
|
fetchUpdateDeviceBind
|
} from '@/api/device-bind'
|
import DeviceBindDialog from './modules/device-bind-dialog.vue'
|
import DeviceBindDetailDrawer from './modules/device-bind-detail-drawer.vue'
|
import { createDeviceBindTableColumns } from './deviceBindTable.columns'
|
import {
|
buildDeviceBindDialogModel,
|
buildDeviceBindPageQueryParams,
|
buildDeviceBindPrintRows,
|
buildDeviceBindReportMeta,
|
buildDeviceBindSavePayload,
|
buildDeviceBindSearchParams,
|
createDeviceBindSearchState,
|
getDeviceBindPaginationKey,
|
normalizeDeviceBindListRow,
|
resolveDeviceBindTypeOptions,
|
DEVICE_BIND_REPORT_STYLE,
|
DEVICE_BIND_REPORT_TITLE
|
} from './deviceBindPage.helpers'
|
|
defineOptions({ name: 'DeviceBind' })
|
|
const { hasAuth } = useAuth()
|
const userStore = useUserStore()
|
|
const searchForm = ref(createDeviceBindSearchState())
|
const typeOptions = ref([])
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
let handleDeleteAction = null
|
|
const reportTitle = DEVICE_BIND_REPORT_TITLE
|
const reportQueryParams = computed(() => buildDeviceBindSearchParams(searchForm.value))
|
const typeLabelMap = computed(
|
() =>
|
new Map(
|
typeOptions.value
|
.map((item) => [String(item.value), item.label])
|
.filter(([value, label]) => value && label)
|
)
|
)
|
|
function resolveTypeLabel(id) {
|
return typeLabelMap.value.get(String(id)) || ''
|
}
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入排号/设备号/站点列表/备注'
|
}
|
},
|
{
|
label: '当前排号',
|
key: 'currentRow',
|
type: 'number',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入当前排号'
|
}
|
},
|
{
|
label: '起始排号',
|
key: 'startRow',
|
type: 'number',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入起始排号'
|
}
|
},
|
{
|
label: '终止排号',
|
key: 'endRow',
|
type: 'number',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入终止排号'
|
}
|
},
|
{
|
label: '设备数量',
|
key: 'deviceQty',
|
type: 'number',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入设备数量'
|
}
|
},
|
{
|
label: '起始设备号',
|
key: 'startDeviceNo',
|
type: 'number',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入起始设备号'
|
}
|
},
|
{
|
label: '终止设备号',
|
key: 'endDeviceNo',
|
type: 'number',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入终止设备号'
|
}
|
},
|
{
|
label: '库区类型',
|
key: 'typeId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
options: typeOptions.value
|
}
|
},
|
{
|
label: '站点列表',
|
key: 'staList',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入站点列表'
|
}
|
},
|
{
|
label: '物料相似',
|
key: 'beSimilar',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '是', value: '1' },
|
{ label: '否', value: '0' }
|
]
|
}
|
},
|
{
|
label: '空板靠近',
|
key: 'emptySimilar',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '是', value: '1' },
|
{ label: '否', value: '0' }
|
]
|
}
|
},
|
{
|
label: '备注',
|
key: 'memo',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入备注'
|
}
|
},
|
{
|
label: '开始时间',
|
key: 'timeStart',
|
type: 'date',
|
props: {
|
clearable: true,
|
type: 'date',
|
valueFormat: 'YYYY-MM-DD',
|
placeholder: '请选择开始时间'
|
}
|
},
|
{
|
label: '结束时间',
|
key: 'timeEnd',
|
type: 'date',
|
props: {
|
clearable: true,
|
type: 'date',
|
valueFormat: 'YYYY-MM-DD',
|
placeholder: '请选择结束时间'
|
}
|
}
|
])
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchGetDeviceBindDetail(row.id), {}, {
|
timeoutMessage: '设备绑定详情加载超时,已停止等待'
|
})
|
detailData.value = normalizeDeviceBindListRow(detail, resolveTypeLabel)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取设备绑定详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
const detail = await guardRequestWithMessage(fetchGetDeviceBindDetail(row.id), {}, {
|
timeoutMessage: '设备绑定详情加载超时,已停止等待'
|
})
|
showDialog('edit', detail)
|
} catch (error) {
|
ElMessage.error(error?.message || '获取设备绑定详情失败')
|
}
|
}
|
|
const { columns, columnChecks, data, loading, pagination, getData, replaceSearchParams, resetSearchParams, handleSizeChange, handleCurrentChange, refreshData, refreshCreate, refreshUpdate, refreshRemove } =
|
useTable({
|
core: {
|
apiFn: fetchDeviceBindPage,
|
apiParams: buildDeviceBindPageQueryParams(searchForm.value),
|
paginationKey: getDeviceBindPaginationKey(),
|
columnsFactory: () =>
|
createDeviceBindTableColumns({
|
handleView: openDetail,
|
handleEdit: hasAuth('update') ? openEditDialog : null,
|
handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null,
|
resolveTypeLabel,
|
canEdit: hasAuth('update'),
|
canDelete: hasAuth('delete')
|
})
|
},
|
transform: {
|
dataTransformer: (records) => {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((item) => normalizeDeviceBindListRow(item, resolveTypeLabel))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentDeviceBindData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildDeviceBindDialogModel(),
|
buildEditModel: (record) => buildDeviceBindDialogModel(record),
|
buildSavePayload: (formData) => buildDeviceBindSavePayload(formData),
|
saveRequest: fetchSaveDeviceBind,
|
updateRequest: fetchUpdateDeviceBind,
|
deleteRequest: fetchDeleteDeviceBind,
|
entityName: '设备绑定',
|
resolveRecordLabel: (record) => record?.currentRow ?? record?.id,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
})
|
handleDeleteAction = handleDelete
|
|
const buildPreviewMeta = (rows) => {
|
const now = new Date()
|
return {
|
reportDate: now.toLocaleDateString('zh-CN'),
|
printedAt: now.toLocaleString('zh-CN', { hour12: false }),
|
operator: userStore.getUserInfo?.name || userStore.getUserInfo?.username || '',
|
count: rows.length,
|
reportStyle: { ...DEVICE_BIND_REPORT_STYLE }
|
}
|
}
|
|
const resolvePrintRecords = async (payload) => {
|
if (Array.isArray(payload?.ids) && payload.ids.length > 0) {
|
return defaultResponseAdapter(await fetchGetDeviceBindMany(payload.ids)).records
|
}
|
return defaultResponseAdapter(
|
await fetchDeviceBindPage({
|
...reportQueryParams.value,
|
current: 1,
|
pageSize: Number(pagination.total) > 0 ? Number(pagination.total) : Number(payload?.pageSize) || 20
|
})
|
).records
|
}
|
|
const { previewVisible, previewRows, previewMeta, handlePreviewVisibleChange, handleExport, handlePrint } =
|
usePrintExportPage({
|
downloadFileName: 'device-bind.xlsx',
|
requestExport: (payload) =>
|
fetchExportDeviceBindReport(payload, {
|
headers: {
|
Authorization: userStore.accessToken || ''
|
}
|
}),
|
resolvePrintRecords,
|
buildPreviewRows: (records) => buildDeviceBindPrintRows(records, resolveTypeLabel),
|
buildPreviewMeta
|
})
|
|
const resolvedPreviewMeta = computed(() =>
|
buildDeviceBindReportMeta({
|
previewMeta: previewMeta.value,
|
count: previewRows.value.length,
|
orientation: previewMeta.value?.reportStyle?.orientation || DEVICE_BIND_REPORT_STYLE.orientation
|
})
|
)
|
|
function handleSearch(params) {
|
replaceSearchParams(buildDeviceBindSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createDeviceBindSearchState())
|
resetSearchParams()
|
}
|
|
async function loadTypeOptions() {
|
const records = await guardRequestWithMessage(fetchWarehouseAreasList(), [], {
|
timeoutMessage: '库区类型加载超时,已停止等待'
|
})
|
typeOptions.value = resolveDeviceBindTypeOptions(defaultResponseAdapter(records).records)
|
}
|
|
onMounted(async () => {
|
await Promise.all([loadTypeOptions(), getData()])
|
})
|
</script>
|