WEB/src/views/warehouse/PathManagement.vue
2026-04-15 21:01:12 +08:00

448 lines
13 KiB
Vue

<template>
<div class="path-management">
<el-card class="box-card">
<template #header>
<div class="card-header">
<span>路径管理</span>
<div class="header-buttons">
<el-button
type="primary"
size="small"
@click="recalculatePath"
:loading="recalculatingPath"
:disabled="!selectedWarehouse?.id"
>
重新计算路径
</el-button>
<el-button
type="success"
size="small"
@click="updateNeighbors"
:loading="updatingNeighbors"
:disabled="!selectedWarehouse?.id"
>
更新邻居关系
</el-button>
</div>
</div>
</template>
<div class="path-content">
<!-- 路径参数设置 -->
<el-form
:model="pathParams"
label-width="120px"
size="small"
@submit.prevent
>
<el-row :gutter="16">
<el-col :span="12">
<el-form-item label="包含空间信息">
<el-switch v-model="pathParams.includeSpaces" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="结果限制">
<el-input-number
v-model="pathParams.limit"
:min="1"
:max="1000"
controls-position="right"
/>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="16">
<el-col :span="12">
<el-form-item label="排序方式">
<el-select v-model="pathParams.sortBy" placeholder="请选择排序方式">
<el-option label="距离优先" value="distance" />
<el-option label="序号优先" value="sequence" />
<el-option label="效率优先" value="efficiency" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item>
<el-button
type="primary"
@click="getPickPath"
:loading="loadingPath"
:disabled="!selectedWarehouse?.id"
>
获取拣货路径
</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
<!-- 路径信息展示 -->
<div class="path-info" v-if="pickPath">
<el-divider content-position="left">拣货路径信息</el-divider>
<div class="path-stats">
<el-row :gutter="16">
<el-col :span="6">
<el-statistic title="总路径长度" :value="pathStats.totalDistance" suffix="米" />
</el-col>
<el-col :span="6">
<el-statistic title="路径节点数" :value="pathStats.nodeCount" suffix="个" />
</el-col>
<el-col :span="6">
<el-statistic title="预计用时" :value="pathStats.estimatedTime" suffix="分钟" />
</el-col>
<el-col :span="6">
<el-statistic title="效率评分" :value="pathStats.efficiencyScore" suffix="分" />
</el-col>
</el-row>
</div>
<!-- 路径详细信息 -->
<el-table
:data="pickPath"
style="margin-top: 16px"
size="small"
max-height="300"
>
<el-table-column prop="sequence" label="序号" width="60" />
<el-table-column prop="nodeType" label="节点类型" width="100">
<template #default="{ row }">
<el-tag :type="getNodeTypeColor(row.nodeType)">
{{ getNodeTypeName(row.nodeType) }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="nodeName" label="节点名称" />
<el-table-column prop="distance" label="距离(米)" width="80" />
<el-table-column prop="estimatedTime" label="用时(秒)" width="80" />
<el-table-column label="操作" width="100">
<template #default="{ row }">
<el-button
type="primary"
link
size="small"
@click="highlightNode(row)"
>
定位
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 路径可视化选项 -->
<div class="path-visualization" v-if="pickPath">
<el-divider content-position="left">路径可视化</el-divider>
<el-row :gutter="16">
<el-col :span="12">
<el-button
type="success"
@click="showPathOnMap"
:disabled="!pickPath"
>
在地图上显示路径
</el-button>
</el-col>
<el-col :span="12">
<el-button
type="info"
@click="exportPath"
:disabled="!pickPath"
>
导出路径数据
</el-button>
</el-col>
</el-row>
</div>
<!-- 空状态 -->
<div v-if="!pickPath && !loadingPath" class="empty-state">
<el-empty
description="暂无路径数据"
:image-size="100"
>
<el-button
type="primary"
@click="getPickPath"
:disabled="!selectedWarehouse?.id"
>
获取拣货路径
</el-button>
</el-empty>
</div>
</div>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, computed, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import * as warehouseApi from '@/api/warehouse/warehouse'
interface PathNode {
sequence: number
nodeType: string
nodeName: string
distance: number
estimatedTime: number
location?: {
x: number
y: number
z?: number
}
}
const props = defineProps<{
selectedWarehouse?: any
}>()
const emit = defineEmits<{
pathHighlight: [nodeData: any]
pathShow: [pathData: any[]]
}>()
// 响应式数据
const pickPath = ref<PathNode[]>([])
const loadingPath = ref(false)
const recalculatingPath = ref(false)
const updatingNeighbors = ref(false)
// 路径参数
const pathParams = reactive({
includeSpaces: true,
limit: 100,
sortBy: 'efficiency'
})
// 路径统计信息
const pathStats = computed(() => {
if (!pickPath.value?.length) {
return {
totalDistance: 0,
nodeCount: 0,
estimatedTime: 0,
efficiencyScore: 0
}
}
const totalDistance = pickPath.value.reduce((sum, node) => sum + (node.distance || 0), 0)
const totalTime = pickPath.value.reduce((sum, node) => sum + (node.estimatedTime || 0), 0)
const nodeCount = pickPath.value.length
const efficiencyScore = nodeCount > 0 ? Math.round((totalDistance / nodeCount) * 10) / 10 : 0
return {
totalDistance: Math.round(totalDistance * 100) / 100,
nodeCount,
estimatedTime: Math.round(totalTime / 60 * 100) / 100,
efficiencyScore
}
})
// 获取拣货路径
const getPickPath = async () => {
if (!props.selectedWarehouse?.id) {
ElMessage.warning('请先选择一个仓库')
return
}
loadingPath.value = true
try {
const params = {
warehouse_id: props.selectedWarehouse.id,
include_spaces: pathParams.includeSpaces ? 'true' : 'false',
limit: pathParams.limit,
sort_by: pathParams.sortBy
}
const response: any = await warehouseApi.getPickPath(params)
if (response.code === 200) {
// 模拟路径数据结构(根据实际返回调整)
pickPath.value = response.path || generateMockPath()
ElMessage.success('路径获取成功')
} else {
ElMessage.error(response.message || '获取路径失败')
}
} catch (error: any) {
ElMessage.error(error.message || '获取路径失败')
console.error(error)
} finally {
loadingPath.value = false
}
}
// 重新计算拣货路径
const recalculatePath = async () => {
if (!props.selectedWarehouse?.id) {
ElMessage.warning('请先选择一个仓库')
return
}
ElMessageBox.confirm('重新计算路径将花费一些时间,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
recalculatingPath.value = true
try {
const response: any = await warehouseApi.recalculatePickPath(props.selectedWarehouse.id)
if (response.code === 200) {
ElMessage.success('路径重新计算成功')
// 重新获取路径数据
await getPickPath()
} else {
ElMessage.error(response.message || '重新计算失败')
}
} catch (error: any) {
ElMessage.error(error.message || '重新计算失败')
console.error(error)
} finally {
recalculatingPath.value = false
}
}).catch(() => {})
}
// 更新邻居关系
const updateNeighbors = async () => {
if (!props.selectedWarehouse?.id) {
ElMessage.warning('请先选择一个仓库')
return
}
updatingNeighbors.value = true
try {
const response: any = await warehouseApi.updateNeighbors(props.selectedWarehouse.id)
if (response.code === 200) {
ElMessage.success('邻居关系更新成功')
} else {
ElMessage.error(response.message || '更新邻居关系失败')
}
} catch (error: any) {
ElMessage.error(error.message || '更新邻居关系失败')
console.error(error)
} finally {
updatingNeighbors.value = false
}
}
// 节点类型颜色
const getNodeTypeColor = (type: string) => {
const colors: Record<string, string> = {
'start': 'success',
'rack': 'primary',
'junction': 'info',
'end': 'danger'
}
return colors[type] || ''
}
// 节点类型名称
const getNodeTypeName = (type: string) => {
const names: Record<string, string> = {
'start': '起点',
'rack': '货架',
'junction': '路口',
'end': '终点'
}
return names[type] || type
}
// 高亮节点
const highlightNode = (node: PathNode) => {
emit('pathHighlight', node)
ElMessage.info(`已定位到: ${node.nodeName}`)
}
// 在地图上显示路径
const showPathOnMap = () => {
emit('pathShow', pickPath.value)
ElMessage.success('路径已在地图上显示')
}
// 导出路径数据
const exportPath = () => {
if (!pickPath.value?.length) return
const data = {
warehouse_id: props.selectedWarehouse?.id,
path_params: pathParams,
path_stats: pathStats.value,
path_nodes: pickPath.value,
export_time: new Date().toLocaleString()
}
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `pick_path_${props.selectedWarehouse?.code || 'warehouse'}_${Date.now()}.json`
link.click()
URL.revokeObjectURL(url)
ElMessage.success('路径数据已导出')
}
// 生成模拟路径数据(用于测试)
const generateMockPath = (): PathNode[] => {
return [
{ sequence: 1, nodeType: 'start', nodeName: '拣货起点', distance: 0, estimatedTime: 0 },
{ sequence: 2, nodeType: 'rack', nodeName: 'A区-货架01', distance: 15.5, estimatedTime: 30 },
{ sequence: 3, nodeType: 'rack', nodeName: 'A区-货架03', distance: 8.2, estimatedTime: 45 },
{ sequence: 4, nodeType: 'junction', nodeName: '路口J01', distance: 12.0, estimatedTime: 20 },
{ sequence: 5, nodeType: 'rack', nodeName: 'B区-货架05', distance: 22.3, estimatedTime: 60 },
{ sequence: 6, nodeType: 'end', nodeName: '拣货终点', distance: 18.7, estimatedTime: 25 }
]
}
// 监听仓库变化
watch(() => props.selectedWarehouse?.id, () => {
pickPath.value = []
})
</script>
<style lang="scss" scoped>
.path-management {
.box-card {
height: 100%;
:deep(.el-card__body) {
padding: 16px;
height: calc(100% - 60px);
overflow-y: auto;
}
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
.header-buttons {
display: flex;
gap: 8px;
}
}
.path-content {
.path-stats {
margin: 16px 0;
padding: 16px;
background: #f5f7fa;
border-radius: 4px;
}
.path-visualization {
margin-top: 16px;
}
.empty-state {
padding: 40px 0;
text-align: center;
}
}
}
</style>