3月20号更新

This commit is contained in:
yin 2026-03-20 18:18:53 +08:00
parent 864ca910eb
commit cbced86a1d
19 changed files with 4918 additions and 1539 deletions

View File

@ -30,6 +30,7 @@ export function getWarehouseTree(warehouseId:any) {
} as any)
}
// 获取子区域,未使用
export function getChildren(zoneId:any) {
return request({
url: '/system',
@ -100,6 +101,7 @@ export function detail(id:any) {
} as any)
}
// 切换激活状态,未使用
export function toggleActive(id:any, isActive:any) {
return request({
url: '/system',
@ -114,6 +116,7 @@ export function toggleActive(id:any, isActive:any) {
} as any)
}
// 切换激活状态,未使用
export function getPath(id:any) {
return request({
url: '/system',

View File

@ -45,6 +45,7 @@
import { ref, reactive, watch, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import UpperTable from '@/components/UpperTable/index.vue'
import * as entryApi from '@/api/storage/entry'
import {entrydetail} from '../entry-config'
@ -81,28 +82,49 @@ async function loadEntryDetail() {
loading.value = true
try {
console.log('加载入库单详情, ID:', props.id)
// 模拟数据源
const allMockDetails: Record<number | string, any[]> = {
90: [
{ id: 91, order_id: 90, out_biz_code: '', order_line_no: 1, owner_code: 'khgj2025100901', item_code: '6977520597331', item_id: 0, count: 5000, inventory_type: 'ZP', stock_id: 101845, received_quantity: 5000, confirm_quantity: 5000 }
],
93: [
{ id: 94, order_id: 93, out_biz_code: '', order_line_no: 1, owner_code: 'khgj2025100901', item_code: '6977520597331', item_id: 1000689, count: 1000, inventory_type: 'ZP', stock_id: 101845, received_quantity: 1000, confirm_quantity: 1000 }
],
95: [
{ id: 95, order_id: 95, out_biz_code: '', order_line_no: 2786714391389667366, owner_code: 'wdt02060120001', item_code: '三层钢蒸锅+屉26cm', item_id: 1000690, count: 1000, inventory_type: 'ZP', stock_id: 101874, received_quantity: 1000, confirm_quantity: 1000 }
],
96: [
{ id: 96, order_id: 96, out_biz_code: '', order_line_no: 2786720123363262666, owner_code: 'wdt02060120001', item_code: 'rrxm202502', item_id: 1000691, count: 1000, inventory_type: 'ZP', stock_id: 101875, received_quantity: 1000, confirm_quantity: 1000 }
],
97: [
{ id: 97, order_id: 97, out_biz_code: '', order_line_no: 1, owner_code: 'khgj2025100901', item_code: '20251023-18', item_id: 1000686, count: 1000, inventory_type: 'ZP', stock_id: 101842, received_quantity: 0, confirm_quantity: 0 }
]
let useMock = false
try {
const res = await entryApi.getEntryDetail({
id: props.id,
page: pagination.currentPage,
page_size: pagination.pageSize
})
if (res && res.code === 200 && res.data) {
tableData.value = Array.isArray(res.data) ? res.data : [res.data]
pagination.total = res.total || tableData.value.length
} else {
useMock = true
}
} catch (apiError) {
console.warn('详情API调用失败,改用模拟数据', apiError)
useMock = true
}
const mockDetails = allMockDetails[props.id] || []
tableData.value = mockDetails
pagination.total = mockDetails.length
if (useMock) {
// 模拟数据源
const allMockDetails: Record<number | string, any[]> = {
90: [
{ id: 91, order_id: 90, out_biz_code: '', order_line_no: 1, owner_code: 'khgj2025100901', item_code: '6977520597331', item_id: 0, count: 5000, inventory_type: 'ZP', stock_id: 101845, received_quantity: 5000, confirm_quantity: 5000 }
],
93: [
{ id: 94, order_id: 93, out_biz_code: '', order_line_no: 1, owner_code: 'khgj2025100901', item_code: '6977520597331', item_id: 1000689, count: 1000, inventory_type: 'ZP', stock_id: 101845, received_quantity: 1000, confirm_quantity: 1000 }
],
95: [
{ id: 95, order_id: 95, out_biz_code: '', order_line_no: 2786714391389667366, owner_code: 'wdt02060120001', item_code: '三层钢蒸锅+屉26cm', item_id: 1000690, count: 1000, inventory_type: 'ZP', stock_id: 101874, received_quantity: 1000, confirm_quantity: 1000 }
],
96: [
{ id: 96, order_id: 96, out_biz_code: '', order_line_no: 2786720123363262666, owner_code: 'wdt02060120001', item_code: 'rrxm202502', item_id: 1000691, count: 1000, inventory_type: 'ZP', stock_id: 101875, received_quantity: 1000, confirm_quantity: 1000 }
],
97: [
{ id: 97, order_id: 97, out_biz_code: '', order_line_no: 1, owner_code: 'khgj2025100901', item_code: '20251023-18', item_id: 1000686, count: 1000, inventory_type: 'ZP', stock_id: 101842, received_quantity: 0, confirm_quantity: 0 }
]
}
const mockDetails = allMockDetails[props.id] || []
tableData.value = mockDetails
pagination.total = mockDetails.length
}
} catch (error) {
ElMessage.error('获取明细失败')
} finally {

View File

@ -1,39 +1,24 @@
export const availableFields = [
{ label:'', value: '', type: 'input' },
{ label: '货主', value: 'store_id', type: 'select', options: [] },
{ label: '状态', value: 'status', type: 'select', options: [
{ label: '待入库', value: 'pending' },
{ label: '入库中', value: 'partial' },
{ label: '已完成', value: 'confirmed' },
{ label: '随机入库中',value: ''},
{ label: '随机入库完成',value: ''},
{ label: '',value: ''},
{ label: '',value: ''},
{ label: '已取消', value: 'cancelled' },
{ label: '',value: ''},
{ label: '',value: ''},
{ label: '',value: ''},
{ label: '',value: ''},
{ label: '',value: ''},
{ label: '',value: ''},
{ label: '状态', value: 'order_status', type: 'select', options: [
{ label: '已创建', value: 'CREATED' },
{ label: '待入库', value: 'PENDING' },
{ label: '入库中', value: 'PARTIAL' },
{ label: '已完成', value: 'COMPLETED' },
{ label: '已取消', value: 'CANCELLED' },
]},
{ label: '入库单类型', value: 'type', type: 'select', options: [
{ label: '采购入库单', value: 'purchase' },
{ label: '退货入库单', value: '' },
{ label: '其他入库单', value: 'other' },
{ label: '盘点入库单', value: '' },
{ label: '', value: '' },
{ label: '', value: '' },
{ label: '', value: '' },
{ label: '', value: '' },
{ label: '', value: '' },
{ label: '', value: '' },
{ label: '', value: '' },
{ label: '', value: '' },
{ label: '入库单类型', value: 'order_type', type: 'select', options: [
{ label: '采购入库', value: 'CGRK' },
{ label: '退货入库', value: 'THRK' },
{ label: '其他入库', value: 'QTRK' },
{ label: '盘点入库', value: 'PDRK' },
]},
{ label: '是否同步', value: 'is_synced', type: 'select', options: [
{ label: '是', value: true },
{ label: '否', value: false },
{ label: '同步状态', value: 'sync_status', type: 'select', options: [
{ label: '待推送', value: 'PENDING' },
{ label: '推送中', value: 'SYNCING' },
{ label: '成功', value: 'SUCCESS' },
{ label: '失败', value: 'FAIL' },
]},
{ label: '费用是否记录',value: 'expense_record', type: 'select', options: [
{ label: '是', value: true },

View File

@ -46,9 +46,19 @@
@refresh="loadData"
@selection-change="onSelectionChange"
>
<template #column-status="{ row }">
<el-tag v-if="row.status" size="small">
{{ row.status }}
<template #column-order_status="{ row }">
<el-tag :type="getStatusType(row.order_status)" size="small">
{{ translateField('order_status', row.order_status) }}
</el-tag>
</template>
<template #column-order_type="{ row }">
<span>{{ translateField('order_type', row.order_type) }}</span>
</template>
<template #column-sync_status="{ row }">
<el-tag :type="getSyncStatusType(row.sync_status)" size="small">
{{ translateField('sync_status', row.sync_status) }}
</el-tag>
</template>
@ -142,6 +152,36 @@ const selectedRow = computed(() => {
return list.value.find((i: any) => i.id === selectedEntryId.value) || null
})
function translateField(fieldValue: string, value: any) {
const field = availableFieldsRef.find((f: any) => f.value === fieldValue)
if (field && field.options) {
const option = field.options.find((opt: any) => opt.value === value)
return option ? option.label : value
}
return value
}
function getStatusType(status: string) {
const map: Record<string, string> = {
'CREATED': 'info',
'PENDING': 'warning',
'PARTIAL': 'primary',
'COMPLETED': 'success',
'CANCELLED': 'danger'
}
return map[status] || ''
}
function getSyncStatusType(status: string) {
const map: Record<string, string> = {
'PENDING': 'info',
'SYNCING': 'primary',
'SUCCESS': 'success',
'FAIL': 'danger'
}
return map[status] || ''
}
onMounted(() => {
loadData()
loadFilterData()

View File

@ -0,0 +1,505 @@
<template>
<div class="property-form">
<div class="form-header">
<h3>{{ title }}</h3>
<el-button
v-if="showAddButton"
type="primary"
size="small"
icon="el-icon-plus"
@click="handleAddProperty"
>
添加属性
</el-button>
</div>
<!-- 属性列表 -->
<el-table
v-if="propertyList.length > 0"
:data="propertyList"
style="width: 100%; margin-bottom: 20px;"
border
stripe
size="small"
>
<el-table-column
prop="name"
label="属性名称"
min-width="150"
>
<template #default="{ row }">
<el-input
v-if="row.editing"
v-model="row.name"
size="small"
/>
<span v-else>{{ row.name }}</span>
</template>
</el-table-column>
<el-table-column
prop="type"
label="属性类型"
min-width="120"
>
<template #default="{ row }">
<el-select
v-if="row.editing"
v-model="row.type"
size="small"
style="width: 100%;"
>
<el-option label="文本" value="text" />
<el-option label="数字" value="number" />
<el-option label="日期" value="date" />
<el-option label="选项" value="select" />
<el-option label="布尔" value="boolean" />
</el-select>
<span v-else>{{ getTypeLabel(row.type) }}</span>
</template>
</el-table-column>
<el-table-column
prop="description"
label="描述"
min-width="200"
>
<template #default="{ row }">
<el-input
v-if="row.editing"
v-model="row.description"
type="textarea"
:rows="1"
size="small"
/>
<span v-else>{{ row.description || '--' }}</span>
</template>
</el-table-column>
<el-table-column
prop="required"
label="必填"
min-width="80"
align="center"
>
<template #default="{ row }">
<el-checkbox
v-if="row.editing"
v-model="row.required"
:disabled="row.system"
/>
<span v-else>
<el-tag
v-if="row.required"
type="danger"
size="small"
>是</el-tag>
<el-tag
v-else
type="info"
size="small"
>否</el-tag>
</span>
</template>
</el-table-column>
<el-table-column
prop="system"
label="系统属性"
min-width="100"
align="center"
>
<template #default="{ row }">
<el-tag
v-if="row.system"
type="warning"
size="small"
>是</el-tag>
<span v-else>--</span>
</template>
</el-table-column>
<el-table-column
label="操作"
width="180"
align="center"
fixed="right"
>
<template #default="{ row }">
<template v-if="!row.system">
<el-button
v-if="row.editing"
type="success"
size="mini"
@click="saveProperty(row)"
>保存</el-button>
<el-button
v-else
type="primary"
size="mini"
@click="editProperty(row)"
>编辑</el-button>
<el-button
v-if="!row.editing"
type="danger"
size="mini"
@click="deleteProperty(row)"
>删除</el-button>
<el-button
v-else
type="warning"
size="mini"
@click="cancelEdit(row)"
>取消</el-button>
</template>
<span v-else>--</span>
</template>
</el-table-column>
</el-table>
<!-- 空状态 -->
<el-empty
v-else
:description="emptyText"
:image-size="100"
/>
<!-- 添加属性对话框 -->
<el-dialog
title="添加属性"
v-model:visible="addDialogVisible"
width="500px"
@close="resetAddForm"
>
<el-form
ref="addFormRef"
:model="addForm"
:rules="addFormRules"
label-width="100px"
>
<el-form-item label="属性名称" prop="name">
<el-input
v-model="addForm.name"
placeholder="请输入属性名称"
/>
</el-form-item>
<el-form-item label="属性类型" prop="type">
<el-select
v-model="addForm.type"
placeholder="请选择属性类型"
style="width: 100%;"
>
<el-option label="文本" value="text" />
<el-option label="数字" value="number" />
<el-option label="日期" value="date" />
<el-option label="选项" value="select" />
<el-option label="布尔" value="boolean" />
</el-select>
</el-form-item>
<el-form-item label="描述" prop="description">
<el-input
v-model="addForm.description"
type="textarea"
:rows="3"
placeholder="请输入属性描述"
/>
</el-form-item>
<el-form-item label="是否必填" prop="required">
<el-switch
v-model="addForm.required"
active-text="是"
inactive-text="否"
/>
</el-form-item>
<!-- 如果是选项类型,显示选项设置 -->
<el-form-item
v-if="addForm.type === 'select'"
label="选项值"
prop="options"
>
<div
v-for="(option, index) in addForm.options"
:key="index"
style="display: flex; align-items: center; margin-bottom: 10px;"
>
<el-input
v-model="option.label"
placeholder="选项标签"
style="margin-right: 10px; flex: 1;"
/>
<el-input
v-model="option.value"
placeholder="选项值"
style="flex: 1;"
/>
<el-button
v-if="addForm.options.length > 1"
type="text"
icon="el-icon-delete"
@click="removeOption(Number(index))"
/>
</div>
<el-button
type="text"
icon="el-icon-plus"
@click="addOption"
>
添加选项
</el-button>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="addDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="submitAddForm">确 定</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, computed, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
const props = defineProps({
title: { type: String, default: '属性管理' },
spaceId: { type: [String, Number], default: null },
showAddButton: { type: Boolean, default: true }
})
// 数据
const propertyList = ref<any[]>([
{
id: 1,
name: '名称',
type: 'text',
description: '空间名称',
required: true,
system: true,
editing: false
},
{
id: 2,
name: '编号',
type: 'text',
description: '空间编号',
required: true,
system: true,
editing: false
}
])
const addDialogVisible = ref(false)
const addForm = reactive<any>({
name: '',
type: 'text',
description: '',
required: false,
options: [{ label: '', value: '' }]
})
const addFormRules = reactive({
name: [
{ required: true, message: '请输入属性名称', trigger: 'blur' },
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
],
type: [
{ required: true, message: '请选择属性类型', trigger: 'change' }
]
})
const addFormRef = ref(null)
const emptyText = computed(() => '暂无属性数据,点击"添加属性"按钮创建')
// 监听 spaceId
watch(() => props.spaceId, (newVal) => {
if (newVal) {
loadProperties()
}
}, { immediate: true })
// 方法
async function loadProperties() {
try {
if (props.spaceId) {
propertyList.value.push({
id: Date.now(),
name: '自定义属性',
type: 'text',
description: '用户自定义属性',
required: false,
system: false,
editing: false
})
}
} catch (error) {
ElMessage.error('加载属性数据失败')
console.error('加载属性数据失败:', error)
}
}
function handleAddProperty() {
addDialogVisible.value = true
}
function submitAddForm() {
if (!addFormRef.value) return
;(addFormRef.value as any).validate().then(async () => {
try {
const newProperty = {
id: Date.now(),
name: addForm.name,
type: addForm.type,
description: addForm.description,
required: addForm.required,
system: false,
editing: false,
options: addForm.type === 'select' ? [...addForm.options] : null
}
propertyList.value.push(newProperty)
ElMessage.success('添加属性成功')
addDialogVisible.value = false
} catch (error) {
ElMessage.error('添加属性失败')
console.error('添加属性失败:', error)
}
}).catch(() => {})
}
function editProperty(property: any) {
property.editing = true
property.originalData = { ...property }
}
async function saveProperty(property: any) {
try {
property.editing = false
delete property.originalData
ElMessage.success('保存成功')
} catch (error) {
ElMessage.error('保存失败')
console.error('保存失败:', error)
}
}
function cancelEdit(property: any) {
if (property.originalData) {
Object.assign(property, property.originalData)
delete property.originalData
}
property.editing = false
}
function deleteProperty(property: any) {
ElMessageBox.confirm('确定删除该属性吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
try {
const index = propertyList.value.findIndex(item => item.id === property.id)
if (index > -1) {
propertyList.value.splice(index, 1)
}
ElMessage.success('删除成功')
} catch (error) {
ElMessage.error('删除失败')
console.error('删除失败:', error)
}
}).catch(() => {})
}
function getTypeLabel(type: string) {
const typeMap: any = {
text: '文本',
number: '数字',
date: '日期',
select: '选项',
boolean: '布尔'
}
return typeMap[type] || type
}
function addOption() {
addForm.options.push({ label: '', value: '' })
}
function removeOption(index: number) {
addForm.options.splice(index, 1)
}
function resetAddForm() {
if (addFormRef.value) {
;(addFormRef.value as any).resetFields()
}
addForm.options = [{ label: '', value: '' }]
}
function getProperties() {
return propertyList.value.map(item => ({
id: item.id,
name: item.name,
type: item.type,
description: item.description,
required: item.required,
system: item.system,
options: item.options
}))
}
defineExpose({ getProperties })
</script>
<style scoped lang="scss">
.property-form {
height: 100%;
display: flex;
flex-direction: column;
.form-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 1px solid #ebeef5;
h3 {
margin: 0;
font-size: 16px;
font-weight: 600;
color: #303133;
}
}
.el-table {
flex: 1;
overflow: auto;
::v-deep .el-table__body-wrapper {
overflow: auto;
}
}
.el-empty {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
}
}
// 对话框样式调整
::v-deep .el-dialog__body {
padding: 20px;
max-height: 60vh;
overflow-y: auto;
}
</style>

View File

@ -0,0 +1,519 @@
<template>
<div class="property-form">
<!-- 标题栏 -->
<div class="form-header">
<div class="space-info">
<el-tag type="success" size="small">
仓位编码: {{ formData.space_code }}
</el-tag>
<el-tag :type="getStatusTagType(formData.space_status)" size="small">
{{ getStatusText(formData.space_status) }}
</el-tag>
<el-tag v-if="formData.is_enabled === 0" type="danger" size="small">
已禁用
</el-tag>
</div>
<el-button-group>
<el-button type="primary" size="small" icon="el-icon-edit" @click="handleEdit" :disabled="!props.spaceId || loading">
{{ isEditing ? '保存修改' : '编辑属性' }}
</el-button>
<el-button v-if="isEditing" type="warning" size="small" icon="el-icon-refresh" @click="handleCancel">
取消编辑
</el-button>
</el-button-group>
</div>
<!-- 表单内容 -->
<el-form v-if="props.spaceId" ref="propertyFormRef" :model="formData" :rules="formRules" label-width="100px"
:disabled="!isEditing" size="small" class="property-form-content">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="自定义名称" prop="custom_name">
<el-input v-model="formData.custom_name" placeholder="请输入自定义名称" :maxlength="100" show-word-limit />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="自定义条码" prop="custom_barcode">
<el-input v-model="formData.custom_barcode" placeholder="请输入自定义条码" :maxlength="100" show-word-limit
@blur="handleBarcodeBlur" @input="handleBarcodeInput" clearable />
<div class="form-tip">
<span v-if="barcodeLoading">
<i class="el-icon-loading"></i> 正在检测条码...
</span>
<span v-else-if="barcodeError" class="error">
<i class="el-icon-error"></i> {{ barcodeError }}
</span>
<span v-else-if="barcodeValid" class="success">
<i class="el-icon-success"></i> 条码可用
</span>
<span v-else>可用于扫码识别</span>
</div>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="仓位类型" prop="location_type_id">
<el-select v-model="formData.location_type_id" placeholder="请选择仓位类型" style="width: 100%;"
:loading="typeLoading">
<el-option v-for="type in locationTypes" :key="type.id" :label="type.type_name" :value="type.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="拣货顺序" prop="pick_sequence">
<el-input-number v-model="formData.pick_sequence" placeholder="拣货顺序" :step="1" :min="0" :max="9999"
style="width: 100%;" controls-position="right" />
<div class="form-tip">数值越小越优先</div>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="启用状态" prop="is_enabled">
<el-switch v-model="formData.is_enabled" :active-value="1" :inactive-value="0" active-text="启用"
inactive-text="禁用" :disabled="!isEditing || formData.space_status === 'OCCUPIED'" />
<div v-if="formData.space_status === 'OCCUPIED'" class="form-tip error">
仓位被占用时不可禁用
</div>
</el-form-item>
</el-col>
</el-row>
</el-form>
<!-- 空状态 -->
<div v-if="!loading && !props.spaceId" class="empty-state">
<el-empty description="请先选择仓位" :image-size="100" />
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, watch, onMounted, onBeforeUnmount, getCurrentInstance, } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import * as warehouseApi from '@/api/warehouse'
const props = defineProps({
title: { type: String, default: '仓位属性管理' },
spaceId: { type: [String, Number], default: null }
})
const emit = defineEmits(['spaceSave'])
// 表单相关
function getDefaultFormData() {
return {
id: null,
space_code: '',
custom_name: '',
custom_barcode: '',
location_type_id: null,
pick_sequence: 0,
is_enabled: 1,
space_status: 'AVAILABLE'
}
}
const formData = reactive<any>(getDefaultFormData())
let originalData: any = null
const isEditing = ref(false)
const loading = ref(false)
const saving = ref(false)
// 条码检测
const barcodeLoading = ref(false)
const barcodeValid = ref(false)
const barcodeError = ref('')
let barcodeCheckTimer: any = null
// 下拉
const locationTypes = ref<any[]>([])
const typeLoading = ref(false)
// 表单 ref & rules
const propertyFormRef = ref(null)
const formRules = {
custom_name: [{ max: 100, message: '长度不能超过100个字符', trigger: 'blur' }],
custom_barcode: [
{ max: 100, message: '长度不能超过100个字符', trigger: 'blur' },
{ validator: (rule:any, value:any, callback:any) => validateBarcode(rule, value, callback), trigger: 'blur' }
],
location_type_id: [{ required: true, message: '请选择仓位类型', trigger: 'change' }],
pick_sequence: [{ type: 'number', min: 0, max: 9999, message: '拣货顺序必须在0-9999之间', trigger: 'blur' }]
}
// 监听 props.spaceId
watch(() => props.spaceId, (newId) => {
if (newId) {
loadSpaceData(newId)
} else {
resetForm()
}
}, { immediate: true })
// 监听 is_enabled 和 space_status 的变化
watch(() => formData.is_enabled, (newValue) => {
if (isEditing.value) {
if (newValue === 1) {
formData.space_status = 'AVAILABLE'
} else if (newValue === 0) {
formData.space_status = 'DISABLED'
}
}
})
watch(() => formData.space_status, (newValue) => {
if (isEditing.value && newValue === 'OCCUPIED') {
formData.is_enabled = 1
}
})
onMounted(() => {
loadLocationTypes()
})
onBeforeUnmount(() => {
if (barcodeCheckTimer) clearTimeout(barcodeCheckTimer)
})
// 获取状态标签样式与文字
function getStatusTagType(status: string) {
const map: any = {
'AVAILABLE': 'success',
'OCCUPIED': 'info',
'RESERVED': 'warning',
'MAINTENANCE': 'warning',
'DISABLED': 'danger'
}
return map[status] || 'info'
}
function getStatusText(status: string) {
const map: any = {
'AVAILABLE': '可用',
'OCCUPIED': '占用',
'RESERVED': '预留',
'MAINTENANCE': '维护中',
'DISABLED': '禁用'
}
return map[status] || status
}
// 加载仓位数据
async function loadSpaceData(spaceId: any) {
loading.value = true
isEditing.value = false
resetBarcodeStatus()
try {
const response: any = await warehouseApi.getSpaceInfo(spaceId)
if (response.code == 200) {
const data = response.data
const fd = {
id: data.id,
space_code: data.space_code || '',
custom_name: data.custom_name || '',
custom_barcode: data.custom_barcode || '',
location_type_id: data.location_type_id || null,
pick_sequence: data.pick_sequence || 0,
is_enabled: data.is_enabled === undefined ? 1 : data.is_enabled,
space_status: data.space_status || 'AVAILABLE'
}
if (fd.is_enabled === 0) {
fd.space_status = 'DISABLED'
} else if (fd.space_status === 'DISABLED') {
fd.is_enabled = 0
}
originalData = { ...fd }
Object.assign(formData, fd)
} else {
ElMessage.error(response.message || '加载仓位数据失败')
}
} catch (error) {
console.error('加载仓位数据失败:', error)
ElMessage.error('加载仓位数据失败')
} finally {
loading.value = false
}
}
// 加载仓位类型
async function loadLocationTypes() {
typeLoading.value = true
try {
locationTypes.value = [
{ id: 1, type_name: '普通仓位' },
{ id: 2, type_name: '拣货仓位' },
{ id: 3, type_name: '存储仓位' }
]
} catch (error) {
console.error('加载仓位类型失败:', error)
} finally {
typeLoading.value = false
}
}
// 条码输入/失去焦点/检测
function handleBarcodeInput() {
barcodeValid.value = false
barcodeError.value = ''
if (barcodeCheckTimer) clearTimeout(barcodeCheckTimer)
const barcode = formData.custom_barcode
if (barcode && barcode.length > 0) {
barcodeCheckTimer = setTimeout(() => { checkBarcodeUnique(barcode) }, 500)
}
}
function handleBarcodeBlur() {
const barcode = formData.custom_barcode
if (barcode && barcode.length > 0) {
checkBarcodeUnique(barcode)
}
}
async function checkBarcodeUnique(barcode: string) {
if (originalData && originalData.custom_barcode === barcode) {
barcodeValid.value = true
barcodeError.value = ''
return
}
if (!barcode || barcode.trim() === '') {
resetBarcodeStatus()
return
}
barcodeLoading.value = true
barcodeValid.value = false
barcodeError.value = ''
try {
const response: any = await warehouseApi.checkBarcodeUnique({ id: props.spaceId, barcode: barcode.trim() })
if (response.code == 200) {
const data = response.data
if (data.isUnique) {
barcodeValid.value = true
barcodeError.value = ''
} else {
barcodeValid.value = false
barcodeError.value = data.message || '该条码已被其他仓位使用'
}
} else {
barcodeValid.value = false
barcodeError.value = response.message || '条码检测失败'
}
} catch (error) {
console.error('条码检测失败:', error)
barcodeValid.value = false
barcodeError.value = '条码检测失败,请稍后重试'
} finally {
barcodeLoading.value = false
}
}
function resetBarcodeStatus() {
barcodeLoading.value = false
barcodeValid.value = false
barcodeError.value = ''
}
function validateBarcode(rule: any, value: any, callback: any) {
if (!value || value.trim() === '') { callback(); return }
const pattern = /^[A-Za-z0-9_-]+$/
if (!pattern.test(value)) { callback(new Error('条码只能包含字母、数字、下划线和短横线')); return }
if (value.length > 100) { callback(new Error('条码长度不能超过100个字符')); return }
if (barcodeLoading.value) { callback(new Error('正在检测条码唯一性...')); return }
if (!barcodeValid.value && barcodeError.value) { callback(new Error(barcodeError.value)); return }
callback()
}
// 编辑/保存/取消
function handleEdit() {
if (!isEditing.value) {
isEditing.value = true
originalData = { ...formData }
resetBarcodeStatus()
} else {
handleSave()
}
}
async function handleSave() {
let valid = true
try {
await (propertyFormRef.value as any).validate()
} catch (e) { valid = false }
if (!valid) {
ElMessage.warning('请检查表单填写是否正确')
return
}
const barcode = formData.custom_barcode
if (barcode && barcode.trim() !== '') {
if (originalData && originalData.custom_barcode !== barcode && !barcodeValid.value) {
if (!barcodeError.value) {
await checkBarcodeUnique(barcode)
if (!barcodeValid.value) { ElMessage.warning('请先完成条码检测'); return }
} else { ElMessage.warning(barcodeError.value); return }
}
}
if (formData.space_status === 'OCCUPIED' && formData.is_enabled === 0) {
ElMessage.warning('占用状态的仓位不可禁用')
return
}
saving.value = true
try {
const instance = getCurrentInstance()
const globalStore: any = instance?.appContext.config.globalProperties.$store
const userId = (globalStore && globalStore.state && globalStore.state.user && globalStore.state.user.userId) || 1
const submitData: any = {
id: formData.id,
custom_name: formData.custom_name,
custom_barcode: formData.custom_barcode,
location_type_id: formData.location_type_id,
pick_sequence: formData.pick_sequence,
is_enabled: formData.is_enabled,
space_status: formData.space_status,
updated_by: userId
}
const response: any = await warehouseApi.updateSpaceInfo(submitData)
if (response.code == 200) {
ElMessage.success('仓位属性保存成功')
isEditing.value = false
originalData = { ...formData }
emit('spaceSave', { ...formData })
} else {
ElMessage.error(response.message || '保存失败')
}
} catch (error) {
console.error('保存失败:', error)
ElMessage.error('保存失败')
} finally {
saving.value = false
}
}
function handleCancel() {
if (originalData) {
Object.assign(formData, originalData)
}
isEditing.value = false
resetBarcodeStatus()
ElMessage.info('已取消编辑')
}
function resetForm() {
Object.assign(formData, getDefaultFormData())
originalData = null
isEditing.value = false
resetBarcodeStatus()
if (propertyFormRef.value) (propertyFormRef.value as any).clearValidate()
}
async function refreshData() {
if (props.spaceId) {
await loadSpaceData(props.spaceId)
ElMessage.success('数据已刷新')
}
}
function getFormData() { return { ...formData } }
function reload() { if (props.spaceId) loadSpaceData(props.spaceId) }
function toggleEnabled(enabled: boolean) {
if (formData.space_status === 'OCCUPIED' && !enabled) {
ElMessage.warning('占用状态的仓位不可禁用')
return false
}
formData.is_enabled = enabled ? 1 : 0
formData.space_status = enabled ? 'AVAILABLE' : 'DISABLED'
return true
}
defineExpose({ getFormData, reload, refreshData, toggleEnabled })
</script>
<style scoped lang="scss">
.property-form {
height: 100%;
display: flex;
flex-direction: column;
.form-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding: 15px 0;
border-bottom: 1px solid #ebeef5;
.space-info {
flex: 1;
display: flex;
align-items: center;
gap: 8px;
}
}
.property-form-content {
flex: 1;
.el-form-item {
margin-bottom: 20px;
}
}
.loading-container {
flex: 1;
display: flex;
flex-direction: column;
padding: 20px;
}
.empty-state {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: #909399;
}
.form-tip {
font-size: 12px;
margin-top: 4px;
line-height: 1.4;
display: flex;
align-items: center;
gap: 4px;
&.error {
color: #f56c6c;
}
.error {
color: #f56c6c;
}
.success {
color: #67c23a;
}
.el-icon-loading,
.el-icon-error,
.el-icon-success {
font-size: 14px;
}
}
}
</style>

View File

@ -0,0 +1,280 @@
<template>
<div class="rack-space-management">
<!-- 货架管理部分 -->
<div v-if="props.rack && props.rack.type === 'rack'" class="rack-management">
<!-- 仓位管理部分 -->
<el-card class="space-management-card">
<template #header>
<div class="card-header">
<span>仓位管理(货架{{ props.rack.name }})</span>
<span>
<el-button type="text" size="small" @click="handleAddSpace">
一键排列拣货路径
</el-button>
<el-button type="text" size="small" @click="handleAddSpace">
打印
</el-button>
<el-button type="text" size="small" @click="handleAddSpace">
修复货架
</el-button>
<el-button type="text" size="small" @click="handleAddSpace">
导出
</el-button>
<el-button type="text" size="small" @click="handleAddSpace">
导入批量修改
</el-button>
</span>
</div>
</template>
<!-- 仓位列表 -->
<el-table :data="rackSpaces" height="100%" style="width: 100%" @row-click="handleSpaceClick"
highlight-current-row :row-style="rowStyle" :cell-style="cellStyle">
<el-table-column type="selection"></el-table-column>
<el-table-column sortable prop="space_code" label="仓位编码" width="120" fixed="left"/>
<el-table-column prop="custom_name" label="自定义名称" width="120" />
<el-table-column prop="custom_barcode" label="自定义条码" width="150" />
<el-table-column prop="column_no" label="组" width="80" />
<el-table-column prop="row_no" label="层" width="80" />
<el-table-column prop="level_no" label="格" width="80" />
<el-table-column label="状态">
<template #default="{ row }">
<el-tag :type="spaceStatusStatus(row.space_status)" size="small">
{{ spaceStatusText(row.space_status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column sortable prop="pick_sequence" label="拣货顺序" width="100" fixed="right" />
</el-table>
<div class="info">
<span>货架/实际/可用/禁用:{{ calculateRackTotal() }}/{{ rackSpaces.length }}/{{ canUseSpacecCount }}/{{ canNotUseSpace }}</span>
<span>有存货的仓位数:{{ useSpaceCount }}</span>
</div>
</el-card>
</div>
<div v-else class="empty-rack-container">
<el-empty description="选择货架后查看信息" />
</div>
</div>
</template>
<script setup lang="ts">
import { ref, watch, computed, } from 'vue'
import * as warehouseApi from '@/api/warehouse'
import { ElMessage } from 'element-plus'
const props = defineProps({
rack: { type: Object, default: null },
warehouse: { type: Object, default: null },
zone: { type: Object, default: null }
})
const emit = defineEmits(['edit-warehouse','edit-zone','edit-rack','edit-space','space-click','refresh'])
const rackSpaces = ref<any[]>([])
const loading = ref(false)
const useSpaceCount = ref(0)
const canUseSpacecCount = ref(0)
const canNotUseSpace = ref(0)
watch(() => props.rack, (newVal) => {
console.log('货架信息', newVal)
if (newVal && newVal.type === 'rack') {
loadRackSpaces()
}
}, { immediate: true })
watch(() => props.warehouse, (newVal) => {
console.log('仓库信息', newVal)
}, { immediate: true })
function spaceStatusText(status: string) {
let text = ''
switch (status) {
case 'AVAILABLE': text = '可用'; break
case 'OCCUPIED': text = '可用/存货'; break
case 'DISABLED': text = '禁用'; break
}
return text
}
function spaceStatusStatus(status: string) {
let text = ''
switch (status) {
case 'AVAILABLE':
case 'OCCUPIED': text = 'success'; break
default: text = 'warning'; break
}
return text
}
function rowStyle() {
return { height: '30px' }
}
function cellStyle() {
return { padding: '0', textAlign: 'center' }
}
function calculateRackTotal() {
if (!props.rack) return 0
const { rackColumns = 1, rackRows = 1, rackLevels = 1 } = props.rack.data || {}
return rackColumns * rackRows * rackLevels
}
async function loadRackSpaces() {
if (!props.rack || props.rack.type !== 'rack') return
loading.value = true
try {
const response: any = await warehouseApi.getSpacesByRack(props.rack.id)
if (response.code === 200) {
rackSpaces.value = response.spaces || []
useSpaceCount.value = 0
canUseSpacecCount.value = 0
canNotUseSpace.value = 0
rackSpaces.value.forEach(item => {
switch (item.space_status) {
case 'AVAILABLE':
canUseSpacecCount.value++
break
case 'OCCUPIED':
canUseSpacecCount.value++
useSpaceCount.value++
break
default:
canNotUseSpace.value++
}
})
}
} catch (error) {
console.error('加载仓位失败:', error)
rackSpaces.value = []
} finally {
loading.value = false
}
}
function handleEditWarehouse() { emit('edit-warehouse', props.warehouse) }
function handleEditZone() { emit('edit-zone', props.zone) }
function handleEditRack() { emit('edit-rack', props.rack) }
async function handleAddSpace() {
if (!props.rack || props.rack.type !== 'rack') return
loading.value = true
try {
const response: any = await warehouseApi.createRackWithSpaces(props.rack.id)
if (response.code === 200) {
ElMessage.success('货架生成成功')
await loadRackSpaces()
}
} catch (error) {
console.error('加载仓位失败:', error)
rackSpaces.value = []
} finally {
loading.value = false
}
}
function handleEditSpace(space: any) { emit('edit-space', space) }
function handleSpaceClick(space: any) { emit('space-click', space) }
function refresh() {
if (props.rack && props.rack.type === 'rack') loadRackSpaces()
emit('refresh')
}
defineExpose({ loadRackSpaces, refresh })
</script>
<style scoped>
.rack-space-management {
display: flex;
flex-direction: column;
gap: 16px;
height: 425px;
width: 600px;
overflow: hidden;
.space-management-card {
display: flex;
flex-direction: column;
height: 100%;
:deep(.el-card__body) {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px;
}
}
.el-card__header {
flex-shrink: 0;
height: 40px;
line-height: 40px;
padding: 0 20px;
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
color: #303133;
}
}
.rack-management {
height: 100%;
display: flex;
flex-direction: column;
}
.el-table {
flex: 1;
width: 100%;
::v-deep .el-table__inner-wrapper {
height: 100% !important;
}
::v-deep .el-table__row {
cursor: pointer;
&:hover {
background-color: #f5f7fa;
}
}
}
.el-table td {
padding: 0;
}
.info {
flex-shrink: 0;
width: 100%;
height: 30px;
line-height: 30px;
font-size: 13px;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 10px;
border-top: 1px solid #f0f0f0;
padding-top: 5px;
}
.empty-rack-container {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: #fff;
border-radius: 4px;
border: 1px solid #ebeef5;
}
}
</style>

View File

@ -0,0 +1,171 @@
<template>
<el-dialog
title="编辑仓位"
:visible="props.visible"
width="500px"
@close="handleClose"
>
<el-form
ref="formRef"
:model="formData"
:rules="rules"
label-width="100px"
size="small"
>
<el-form-item label="仓位编码">
<el-input v-model="formData.space_code" disabled />
</el-form-item>
<el-form-item label="位置">
<div class="position-display">
列{{ props.space.column_no }} 层{{ props.space.row_no }} 格{{ props.space.level_no }}
</div>
</el-form-item>
<el-form-item label="尺寸">
<div class="dimension-display">
<div>长: {{ props.space.length || '未设置' }}cm</div>
<div>宽: {{ props.space.width || '未设置' }}cm</div>
<div>高: {{ props.space.height || '未设置' }}cm</div>
</div>
</el-form-item>
<el-form-item label="承重限制" prop="max_weight">
<el-input-number
v-model="formData.max_weight"
:min="0"
:step="0.1"
style="width: 100%"
placeholder="最大承重(kg)"
/>
</el-form-item>
<el-form-item label="仓位状态" prop="space_status">
<el-select
v-model="formData.space_status"
placeholder="请选择状态"
style="width: 100%"
>
<el-option
v-for="item in statusOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="是否启用" prop="is_enabled">
<el-switch
v-model="formData.is_enabled"
:active-value="1"
:inactive-value="0"
/>
</el-form-item>
<el-form-item label="自定义名称">
<el-input
v-model="formData.custom_name"
placeholder="可选"
maxlength="100"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleSubmit" :loading="saving">保存</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import * as spaceApi from '@/api/warehouse'
import { ElMessage } from 'element-plus'
const props = defineProps({
visible: { type: Boolean, default: false },
space: { type: Object, required: true }
})
const emit = defineEmits(['close', 'saved'])
const formRef = ref(null)
const saving = ref(false)
const formData = reactive<any>({
id: null,
space_code: '',
custom_name: '',
custom_barcode: '',
max_weight: null,
space_status: 'AVAILABLE',
is_enabled: 1
})
const rules = {
space_status: [
{ required: true, message: '请选择状态', trigger: 'change' }
]
}
const statusOptions = [
{ value: 'AVAILABLE', label: '可用' },
{ value: 'OCCUPIED', label: '已占用' },
{ value: 'RESERVED', label: '已预留' },
{ value: 'MAINTENANCE', label: '维护中' },
{ value: 'DISABLED', label: '已禁用' }
]
watch(() => props.space, (newSpace) => {
if (newSpace) {
formData.id = newSpace.id
formData.space_code = newSpace.space_code
formData.custom_name = newSpace.custom_name || ''
formData.custom_barcode = newSpace.custom_barcode || ''
formData.max_weight = newSpace.max_weight
formData.space_status = newSpace.space_status
formData.is_enabled = newSpace.is_enabled ? 1 : 0
}
}, { immediate: true })
function handleClose() { emit('close') }
async function handleSubmit() {
try {
const valid = await (formRef.value as any).validate().catch(() => false)
if (!valid) return
saving.value = true
const response: any = await spaceApi.update(formData, formData.id)
if (response.code === 200) {
ElMessage.success('保存成功')
emit('saved')
} else {
ElMessage.error(response.message || '保存失败')
}
} catch (error) {
ElMessage.error('保存失败')
} finally {
saving.value = false
}
}
</script>
<style lang="scss" scoped>
.position-display {
display: flex;
gap: 16px;
font-size: 14px;
color: #606266;
}
.dimension-display {
display: flex;
flex-direction: column;
gap: 4px;
font-size: 14px;
color: #606266;
}
</style>

View File

@ -0,0 +1,286 @@
<template>
<div class="space-list">
<div class="section-header">
<span>仓位格子管理</span>
<div class="header-actions">
<el-button
type="primary"
size="mini"
@click="loadSpaces"
:loading="loading"
>
<i class="el-icon-refresh"></i>
</el-button>
<el-button
type="success"
size="mini"
@click="generateSpaces"
:loading="generating"
v-if="!spaces.length"
>
生成仓位
</el-button>
</div>
</div>
<!-- 仓位列表 -->
<div class="space-grid" v-if="spaces.length > 0">
<div class="grid-header">
<div class="grid-cell">列</div>
<div class="grid-cell">层</div>
<div class="grid-cell">格</div>
<div class="grid-cell">编码</div>
<div class="grid-cell">状态</div>
<div class="grid-cell">操作</div>
</div>
<div class="grid-body">
<div
v-for="space in sortedSpaces"
:key="space.id"
class="space-row"
:class="{
'selected': selectedSpaceId === space.id,
'occupied': space.space_status === 'OCCUPIED'
}"
@click="selectSpace(space)"
>
<div class="grid-cell">{{ space.column_no }}</div>
<div class="grid-cell">{{ space.row_no }}</div>
<div class="grid-cell">{{ space.level_no }}</div>
<div class="grid-cell">{{ space.space_code }}</div>
<div class="grid-cell">
<el-tag
size="mini"
:type="getStatusTag(space.space_status)"
>
{{ getStatusText(space.space_status) }}
</el-tag>
</div>
<div class="grid-cell">
<el-button
type="text"
size="mini"
@click.stop="editSpace(space)"
>
<i class="el-icon-edit"></i>
</el-button>
</div>
</div>
</div>
<!-- 分页 -->
<div class="pagination" v-if="spaces.length > pageSize">
<el-pagination
small
:current-page="currentPage"
:page-size="pageSize"
:total="spaces.length"
layout="prev, pager, next"
@current-change="handlePageChange"
/>
</div>
</div>
<!-- 空状态 -->
<div v-else class="empty-state">
<p>暂无仓位数据</p>
</div>
<!-- 仓位表单 -->
<space-form
v-if="showForm"
:space="currentSpace"
@close="closeForm"
@saved="handleSpaceSaved"
/>
</div>
</template>
<script setup lang="ts">
import { ref, computed, watch, onMounted } from 'vue'
import * as warehouseApi from '@/api/warehouse'
import SpaceForm from './SpaceForm.vue'
import { ElMessage } from 'element-plus'
const props = defineProps({ rackId: { type: [Number, String], required: true } })
const emit = defineEmits(['refresh'])
const spaces = ref<any[]>([])
const loading = ref(false)
const generating = ref(false)
const currentPage = ref(1)
const pageSize = ref(10)
const selectedSpaceId = ref<any>(null)
const showForm = ref(false)
const currentSpace = ref<any>(null)
const statusMap: any = {
'AVAILABLE': { tag: 'success', text: '可用' },
'OCCUPIED': { tag: 'warning', text: '占用' },
'RESERVED': { tag: 'info', text: '预留' },
'MAINTENANCE': { tag: 'danger', text: '维护' },
'DISABLED': { tag: 'info', text: '禁用' }
}
const sortedSpaces = computed(() => {
return [...spaces.value].sort((a, b) => {
const colA = parseInt(a.column_no) || 0
const colB = parseInt(b.column_no) || 0
if (colA !== colB) return colA - colB
const rowA = parseInt(a.row_no) || 0
const rowB = parseInt(b.row_no) || 0
if (rowA !== rowB) return rowA - rowB
const levelA = parseInt(a.level_no) || 0
const levelB = parseInt(b.level_no) || 0
return levelA - levelB
})
})
const paginatedSpaces = computed(() => {
const start = (currentPage.value - 1) * pageSize.value
const end = start + pageSize.value
return sortedSpaces.value.slice(start, end)
})
async function loadSpaces() {
loading.value = true
try {
const response: any = await warehouseApi.getSpacesByRack(props.rackId)
if (response.code === 200) {
spaces.value = response.spaces || []
ElMessage.success(`加载了 ${spaces.value.length} 个仓位`)
}
} catch (error) {
ElMessage.error('加载仓位失败')
} finally {
loading.value = false
}
}
async function generateSpaces() {
generating.value = true
try {
const response: any = await warehouseApi.createRackWithSpaces(props.rackId)
if (response.code === 200) {
ElMessage.success('仓位生成成功')
await loadSpaces()
}
} catch (error) {
ElMessage.error('生成仓位失败')
} finally {
generating.value = false
}
}
function selectSpace(space: any) { selectedSpaceId.value = space.id }
function editSpace(space: any) {
currentSpace.value = space
showForm.value = true
}
function closeForm() {
showForm.value = false
currentSpace.value = null
}
function handleSpaceSaved() {
closeForm()
loadSpaces()
emit('refresh')
}
function getStatusTag(status: string) { return statusMap[status]?.tag || 'info' }
function getStatusText(status: string) { return statusMap[status]?.text || status }
function handlePageChange(page: number) { currentPage.value = page }
onMounted(() => { loadSpaces() })
</script>
<style lang="scss" scoped>
.space-list {
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid #ebeef5;
span {
font-weight: 500;
color: #303133;
}
}
.space-grid {
.grid-header {
display: grid;
grid-template-columns: 1fr 1fr 1fr 2fr 2fr 1fr;
gap: 8px;
padding: 8px;
background: #f8f9fa;
border-radius: 4px;
margin-bottom: 8px;
.grid-cell {
font-size: 12px;
font-weight: 500;
color: #606266;
text-align: center;
}
}
.grid-body {
max-height: 300px;
overflow-y: auto;
.space-row {
display: grid;
grid-template-columns: 1fr 1fr 1fr 2fr 2fr 1fr;
gap: 8px;
padding: 8px;
border-bottom: 1px solid #ebeef5;
cursor: pointer;
transition: background-color 0.2s;
&:hover {
background-color: #f5f7fa;
}
&.selected {
background-color: #ecf5ff;
}
&.occupied {
opacity: 0.7;
}
.grid-cell {
font-size: 12px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
}
}
.pagination {
margin-top: 12px;
display: flex;
justify-content: center;
}
}
.empty-state {
text-align: center;
padding: 32px;
color: #c0c4cc;
}
}
</style>

View File

@ -0,0 +1,155 @@
<template>
<el-dialog
title="添加仓库"
v-model="internalVisible"
width="600px"
@close="handleClose"
>
<el-form
ref="formRef"
:model="formData"
:rules="rules"
label-width="100px"
>
<el-form-item label="仓库名称" prop="zone_name">
<el-input v-model="formData.zone_name" placeholder="请输入仓库名称" />
</el-form-item>
<el-form-item label="仓库编码" prop="zone_code">
<el-input
v-model="formData.zone_code"
placeholder="请输入仓库编码"
maxlength="5"
/>
</el-form-item>
<el-form-item label="仓库长度" prop="length">
<el-input-number
v-model="formData.length"
:min="1000"
:step="1000"
style="width: 100%"
placeholder="长度(mm)"
/>
</el-form-item>
<el-form-item label="仓库宽度" prop="width">
<el-input-number
v-model="formData.width"
:min="1000"
:step="1000"
style="width: 100%"
placeholder="宽度(mm)"
/>
</el-form-item>
<el-form-item label="仓库高度" prop="height">
<el-input-number
v-model="formData.height"
:min="1000"
:step="1000"
style="width: 100%"
placeholder="高度(mm)"
/>
</el-form-item>
<el-form-item label="显示颜色">
<el-color-picker v-model="formData.color" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleSubmit" :loading="submitting">确定</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import * as warehouseApi from '@/api/warehouse'
import { ElMessage } from 'element-plus'
// import { defineProps, defineEmits } from 'vue'
const props = defineProps({ visible: { type: Boolean, default: false } })
const emit = defineEmits(['close', 'success'])
const internalVisible = ref(props.visible)
watch(() => props.visible, (newVal) => {
internalVisible.value = newVal
})
const formRef = ref(null)
const submitting = ref(false)
const formData = reactive<any>({
zone_type: 'warehouse',
zone_name: '',
zone_code: '',
parent_id: 0,
x: 0,
y: 0,
z: 0,
length: 10000,
width: 10000,
height: 5000,
color: '#96ceb4',
is_active: 1
})
const rules = {
zone_name: [ { required: true, message: '请输入仓库名称', trigger: 'blur' } ],
zone_code: [ { required: true, message: '请输入仓库编码', trigger: 'blur' } ],
length: [ { required: true, message: '请输入长度', trigger: 'blur' } ],
width: [ { required: true, message: '请输入宽度', trigger: 'blur' } ],
height: [ { required: true, message: '请输入高度', trigger: 'blur' } ]
}
function handleClose() { emit('close') }
async function handleSubmit() {
try {
const valid = await (formRef.value as any).validate().catch(() => false)
if (!valid) return
submitting.value = true
if (!formData.zone_code) {
const timestamp = Date.now().toString().slice(-4)
formData.zone_code = `WH${timestamp}`
}
const response: any = await warehouseApi.create(formData)
if (response.code === 200) {
ElMessage.success('仓库添加成功')
emit('success')
resetForm()
} else {
ElMessage.error(response.message || '添加失败')
}
} catch (error) {
ElMessage.error('添加失败')
} finally {
submitting.value = false
}
}
function resetForm() {
formData.zone_type = 'warehouse'
formData.zone_name = ''
formData.zone_code = ''
formData.parent_id = 0
formData.x = 0
formData.y = 0
formData.z = 0
formData.length = 10000
formData.width = 10000
formData.height = 5000
formData.color = '#96ceb4'
formData.is_active = 1
if (formRef.value) (formRef.value as any).resetFields()
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,97 @@
<template>
<el-card class="warehouse-tree-card">
<template #header>
<div class="clearfix">
<span>仓库列表</span>
<el-button type="text" @click="emit('add')">添加仓库</el-button>
</div>
</template>
<div class="tree-container">
<el-tree
ref="treeRef"
:data="props.warehouseList"
node-key="id"
:props="treeProps"
:expand-on-click-node="false"
:highlight-current="true"
@node-click="handleNodeClick"
>
<template #default="{ node, data }">
<span class="tree-node">
<el-icon><office-building /></el-icon>
<span class="node-label">{{ data.label }}</span>
</span>
</template>
</el-tree>
</div>
</el-card>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { OfficeBuilding } from '@element-plus/icons-vue'
const props = defineProps({
warehouseList: { type: Array, default: () => [] }
})
const emit = defineEmits(['add', 'select'])
const treeRef = ref(null)
const treeProps = {
children: 'children',
label: 'name'
}
onMounted(() => {
console.log(props.warehouseList)
})
function handleNodeClick(data: any) {
emit('select', data)
}
</script>
<style scoped>
.warehouse-tree-card {
height: 220px;
display:flex;
flex-direction: column;
.el-card__header {
padding: 0;
height:40px;
line-height: 40px;
padding-left: 20px;
.clearfix{
display:flex;
flex-direction: row;
justify-content: space-between;
}
}
.el-card__body{
flex:1;
height: 10px;
}
.tree-container {
height: 100%;
overflow-y: auto;
.tree-node {
display: flex;
align-items: center;
font-size: 14px;
i {
margin-right: 6px;
color: #409EFF;
}
.node-label {
flex: 1;
}
}
}
}
</style>

View File

@ -0,0 +1,585 @@
<template>
<el-card shadow="never" class="warehouse-plan-card">
<!-- 工具栏 -->
<template #header>
<div class="card-header">
<span class="card-title">{{ props.warehouseData.name }} - 平面图</span>
<div class="toolbar">
<el-button-group>
<el-button size="small" @click="zoomIn">放大</el-button>
<el-button size="small" @click="zoomOut">缩小</el-button>
<el-button size="small" @click="resetZoom">重置</el-button>
<el-button size="small" @click="centerView">居中</el-button>
</el-button-group>
<span class="scale-info ml-3">
缩放: {{ (scale * 100).toFixed(0) }}%
</span>
</div>
</div>
</template>
<!-- 平面图容器 -->
<div class="warehouse-container" ref="containerRef">
<div ref="svgContainerRef" class="svg-container" @wheel="handleWheel" @mousedown="handleMouseDown"
@mousemove="handleMouseMove" @mouseup="handleMouseUp" @mouseleave="handleMouseLeave">
<svg ref="svgRef" :width="svgWidth" :height="svgHeight" :viewBox="viewBox" preserveAspectRatio="xMidYMid meet">
<!-- 仓库边界 -->
<rect :x="0" :y="0" :width="warehouseLength" :height="warehouseWidth" fill="#fafafa" stroke="#000"
stroke-width="20" rx="4" />
<!-- 绘制所有区域 -->
<g v-for="area in (props.warehouseData.children || [])" :key="area.id" v-show="area.type === 'area'" class="area-group">
<!-- 区域背景 -->
<rect :x="area.data.x" :y="area.data.y" :width="area.data.length" :height="area.data.width"
:fill="getAreaColor(area)" :stroke="area.data.isActive ? '#67c23a' : '#909399'" stroke-width="1.5"
:stroke-dasharray:number="area.data.isActive ? null : '4,3'" rx="3" />
<!-- 区域名称 -->
<g>
<rect :x="area.data.x + area.data.length/2 - 40" :y="area.data.y + area.data.width/2 - 15" width="80"
height="30" fill="rgba(255,255,255,0.9)" stroke="#dcdfe6" stroke-width="1" rx="4" />
<text :x="area.data.x + area.data.length/2" :y="area.data.y + area.data.width/2" text-anchor="middle"
dominant-baseline="middle" fill="#303133" font-size="84" font-weight="bold">
{{ area.name }}
</text>
</g>
<!-- 区域内的货架 -->
<g v-for="rack in (area.children || [])" :key="rack.id">
<!-- U型货架 -->
<g v-if="rack.type === 'rack'">
<!-- 货架背景 -->
<rect :x="getRackX(rack, area)" :y="getRackY(rack, area)" :width="getRackDisplayWidth(rack)"
:height="getRackDisplayHeight(rack)" fill="url(#rackPattern)" stroke="#409EFF" stroke-width="1"
:stroke-dasharray:numbers="rack.data.isActive ? null : '3,2'" class="rack-background" />
<!-- U型槽位 -->
<g v-for="col in rack.data.rackColumns" :key="col">
<!-- 单个U型槽 -->
<path :d="getUSlotPath(rack, area, col)" :fill="getSlotColor(col)" stroke="#333" stroke-width="0.5"
:filter="isHoveredSlot(rack.id, col) ? 'url(#highlight)' : ''" @mouseenter="() => hoverSlot(rack.id, col)"
@mouseleave="clearHover" class="u-slot" />
<!-- 槽位编号 -->
<text :x="getSlotTextX(rack, area, col)" :y="getSlotTextY(rack, area, col)" text-anchor="middle"
dominant-baseline="middle" fill="#303133" font-size="50" font-weight="bold">
{{ col }}
</text>
</g>
<!-- 货架名称标签 -->
<g v-if="rack.code">
<rect :x="getRackLabelX(rack, area)" :y="getRackLabelY(rack, area)" width="120" height="64"
fill="rgba(255,255,255,0.9)" stroke="#409EFF" stroke-width="1" rx="3" />
<text :x="getRackLabelX(rack, area) + 60" :y="getRackLabelY(rack, area) + 32" text-anchor="middle"
dominant-baseline="middle" fill="#409EFF" font-size="42" font-weight="500">
{{ rack.code }}
</text>
</g>
</g>
<!-- 拣货起点 -->
<g v-else-if="rack.type === 'pick_start'">
<circle :cx="getPickStartX(rack, area)" :cy="getPickStartY(rack, area)"
:r="Math.max(rack.data.length, rack.data.width) / 2" fill="#67c23a" stroke="#5daf34" stroke-width="2"
class="pick-start" />
<text :x="getPickStartX(rack, area)" :y="getPickStartY(rack, area)" text-anchor="middle"
dominant-baseline="middle" fill="white" font-size="10" font-weight="bold">
起点
</text>
</g>
</g>
</g>
<!-- 图案定义 -->
<defs>
<!-- 货架背景图案 -->
<pattern id="rackPattern" patternUnits="userSpaceOnUse" width="20" height="20">
<rect width="20" height="20" fill="#f0f9ff" />
<path d="M0,0 L20,20 M20,0 L0,20" stroke="#e6f7ff" stroke-width="1" />
</pattern>
<!-- 高亮效果 -->
<filter id="highlight" x="-20%" y="-20%" width="140%" height="140%">
<feGaussianBlur in="SourceAlpha" stdDeviation="2" result="blur" />
<feOffset in="blur" dx="0" dy="0" result="offsetBlur" />
<feFlood flood-color="#409EFF" flood-opacity="0.2" result="offsetColor" />
<feComposite in="offsetColor" in2="offsetBlur" operator="in" result="offsetBlur" />
<feMerge>
<feMergeNode in="offsetBlur" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
<!-- 朝向指示箭头 -->
<marker id="directionArrow" markerWidth="6" markerHeight="4" refX="5" refY="2" orient="auto">
<polygon points="0,0 6,2 0,4" fill="#e6a23c" />
</marker>
</defs>
</svg>
</div>
</div>
</el-card>
</template>
<script setup lang="ts">
import { ref, reactive, computed, onMounted, watch } from 'vue'
const props = defineProps({ warehouseData: { type: Object, required: true } })
const containerRef = ref<HTMLElement | null>(null)
const svgContainerRef = ref<HTMLElement | null>(null)
const svgRef = ref<SVGElement | null>(null)
const state = reactive({
scale: 0.1,
minScale: 0.01,
maxScale: 1,
svgWidth: 1200,
svgHeight: 800,
viewBoxX: 0,
viewBoxY: 0,
isDragging: false,
dragStart: { x: 0, y: 0, viewBoxX: 0, viewBoxY: 0 },
hoveredElement: null as any,
hoveredSlot: null as any
})
const scale = computed({ get: () => state.scale, set: (v: number) => (state.scale = v) })
const minScale = computed(() => state.minScale)
const maxScale = computed(() => state.maxScale)
const svgWidth = computed({ get: () => state.svgWidth, set: (v: number) => (state.svgWidth = v) })
const svgHeight = computed({ get: () => state.svgHeight, set: (v: number) => (state.svgHeight = v) })
const viewBox = computed(() => {
const width = svgWidth.value / state.scale
const height = svgHeight.value / state.scale
return `${state.viewBoxX} ${state.viewBoxY} ${width} ${height}`
})
const warehouseLength = computed(() => props.warehouseData.data.length)
const warehouseWidth = computed(() => props.warehouseData.data.width)
onMounted(() => {
updateSvgSize()
centerView()
if (svgContainerRef.value) svgContainerRef.value.style.cursor = 'grab'
})
watch(() => props.warehouseData, () => {
updateSvgSize()
centerView()
})
function updateSvgSize() {
if (!containerRef.value) return
const containerRect = containerRef.value.getBoundingClientRect()
const containerWidth = containerRect.width
const containerHeight = containerRect.height
svgWidth.value = Math.max(containerWidth, 100)
svgHeight.value = Math.max(containerHeight, 100)
const size = svgWidth.value / warehouseLength.value > svgHeight.value / warehouseWidth.value ?
parseInt(((svgHeight.value / warehouseWidth.value) * 100).toString()) : parseInt(((svgWidth.value / warehouseLength.value) * 100).toString())
state.scale = size / 100
state.minScale = size / 100
}
function getAreaColor(area: any) {
if (area.data.color && area.data.color !== '#3B82F6') return area.data.color
const colors = [
'rgba(64, 158, 255, 0.1)',
'rgba(103, 194, 58, 0.1)',
'rgba(230, 162, 60, 0.1)',
'rgba(245, 108, 108, 0.1)',
'rgba(144, 147, 153, 0.1)'
]
const index = (area.id % colors.length)
return colors[index]
}
function getSlotColor(column: number) {
return column % 2 === 0 ? '#a5d8ff' : '#74c0fc'
}
function getRackDisplayWidth(rack: any) {
const direction = rack.data.direction
if (direction === 'east' || direction === 'west') return rack.data.width
return rack.data.length
}
function getRackDisplayHeight(rack: any) {
const direction = rack.data.direction
if (direction === 'east' || direction === 'west') return rack.data.length
return rack.data.width
}
function getRackX(rack: any, area: any) {
const baseX = area.data.x + (rack.data.x || 0)
return baseX
}
function getRackY(rack: any, area: any) {
const baseY = area.data.y + (rack.data.y || 0)
return baseY
}
function getUSlotPath(rack: any, area: any, column: number) {
const direction = rack.data.direction
const rackX = getRackX(rack, area)
const rackY = getRackY(rack, area)
const displayWidth = getRackDisplayWidth(rack)
const displayHeight = getRackDisplayHeight(rack)
const columnCount = rack.data.rackColumns
let slotWidth: number, slotHeight: number, slotX: number, slotY: number
if (direction === 'east' || direction === 'west') {
slotWidth = displayWidth
slotHeight = displayHeight / columnCount
slotX = rackX
slotY = rackY + (column - 1) * slotHeight
} else {
slotWidth = displayWidth / columnCount
slotHeight = displayHeight
slotX = rackX + (column - 1) * slotWidth
slotY = rackY
}
const uDepth = (direction === 'east' || direction === 'west') ? slotWidth * 0.6 : slotHeight * 0.6
const uWidth = (direction === 'east' || direction === 'west') ? slotHeight * 0.8 : slotWidth * 0.8
switch (direction) {
case 'north':
return `M ${slotX + slotWidth/2 - uWidth/2},${slotY} L ${slotX + slotWidth/2 - uWidth/2},${slotY + slotHeight - uDepth} Q ${slotX + slotWidth/2 - uWidth/2},${slotY + slotHeight} ${slotX + slotWidth/2},${slotY + slotHeight} Q ${slotX + slotWidth/2 + uWidth/2},${slotY + slotHeight} ${slotX + slotWidth/2 + uWidth/2},${slotY + slotHeight - uDepth} L ${slotX + slotWidth/2 + uWidth/2},${slotY} Z`
case 'south':
return `M ${slotX + slotWidth/2 - uWidth/2},${slotY + slotHeight} L ${slotX + slotWidth/2 - uWidth/2},${slotY + uDepth} Q ${slotX + slotWidth/2 - uWidth/2},${slotY} ${slotX + slotWidth/2},${slotY} Q ${slotX + slotWidth/2 + uWidth/2},${slotY} ${slotX + slotWidth/2 + uWidth/2},${slotY + uDepth} L ${slotX + slotWidth/2 + uWidth/2},${slotY + slotHeight} Z`
case 'west':
return `M ${slotX},${slotY + slotHeight/2 - uWidth/2} L ${slotX + slotWidth - uDepth},${slotY + slotHeight/2 - uWidth/2} Q ${slotX + slotWidth},${slotY + slotHeight/2 - uWidth/2} ${slotX + slotWidth},${slotY + slotHeight/2} Q ${slotX + slotWidth},${slotY + slotHeight/2 + uWidth/2} ${slotX + slotWidth - uDepth},${slotY + slotHeight/2 + uWidth/2} L ${slotX},${slotY + slotHeight/2 + uWidth/2} Z`
case 'east':
return `M ${slotX + slotWidth},${slotY + slotHeight/2 - uWidth/2} L ${slotX + uDepth},${slotY + slotHeight/2 - uWidth/2} Q ${slotX},${slotY + slotHeight/2 - uWidth/2} ${slotX},${slotY + slotHeight/2} Q ${slotX},${slotY + slotHeight/2 + uWidth/2} ${slotX + uDepth},${slotY + slotHeight/2 + uWidth/2} L ${slotX + slotWidth},${slotY + slotHeight/2 + uWidth/2} Z`
default:
return ''
}
}
function getSlotTextX(rack: any, area: any, column: number) {
const direction = rack.data.direction
const rackX = getRackX(rack, area)
const displayWidth = getRackDisplayWidth(rack)
const columnCount = rack.data.rackColumns
if (direction === 'east' || direction === 'west') {
const slotWidth = displayWidth
return rackX + slotWidth / 2
} else {
const slotWidth = displayWidth / columnCount
return rackX + (column - 0.5) * slotWidth
}
}
function getSlotTextY(rack: any, area: any, column: number) {
const direction = rack.data.direction
const rackY = getRackY(rack, area)
const displayHeight = getRackDisplayHeight(rack)
const columnCount = rack.data.rackColumns
if (direction === 'east' || direction === 'west') {
const slotHeight = displayHeight / columnCount
return rackY + (column - 0.5) * slotHeight
} else {
const slotHeight = displayHeight
return rackY + slotHeight / 2
}
}
function getRackLabelX(rack: any, area: any) {
const direction = rack.data.direction
const rackX = getRackX(rack, area)
const displayWidth = getRackDisplayWidth(rack)
if (direction === 'east' || direction === 'west') return rackX + displayWidth + 5
return rackX + displayWidth / 2 - 40
}
function getRackLabelY(rack: any, area: any) {
const direction = rack.data.direction
const rackY = getRackY(rack, area)
const displayHeight = getRackDisplayHeight(rack)
if (direction === 'north') return rackY - 30
if (direction === 'south') return rackY + displayHeight + 5
return rackY + displayHeight / 2 - 12
}
function getPickStartX(pickStart: any, area: any) {
return area.data.x + (pickStart.data.x || 0) + (pickStart.data.length || 0) / 2
}
function getPickStartY(pickStart: any, area: any) {
return area.data.y + (pickStart.data.y || 0) + (pickStart.data.width || 0) / 2
}
function hoverSlot(rackId: number, column: number) {
const rack = findRackById(rackId)
if (rack) {
state.hoveredElement = rack
state.hoveredSlot = { rackId, column }
}
}
function isHoveredSlot(rackId: number, column: number) {
return state.hoveredSlot && state.hoveredSlot.rackId === rackId && state.hoveredSlot.column === column
}
function clearHover() { state.hoveredSlot = null }
function findRackById(rackId: number) {
for (const area of (props.warehouseData.children || [])) {
for (const child of (area.children || [])) {
if (child.id === rackId) return child
}
}
return null
}
function getDirectionText(direction: string) {
const map: any = { north: '北', south: '南', east: '东', west: '西' }
return map[direction] || direction
}
function getElementTypeText(type: string) {
const map: any = { warehouse: '仓库', area: '区域', rack: '货架', pick_start: '拣货点' }
return map[type] || type
}
function getElementTagType(element: any) {
const map: any = { warehouse: 'primary', area: 'success', rack: 'warning', pick_start: 'info' }
return map[element.type] || 'info'
}
function zoomIn() {
if (state.scale < state.maxScale) state.scale = Math.min(state.maxScale, state.scale * 1.2)
centerView()
}
function zoomOut() {
if (state.scale > state.minScale) state.scale = Math.max(state.minScale, state.scale / 1.2)
centerView()
}
function resetZoom() { updateSvgSize(); centerView() }
function centerView() {
const width = svgWidth.value / state.scale
const height = svgHeight.value / state.scale
state.viewBoxX = -(width - warehouseLength.value) / 2
state.viewBoxY = -(height - warehouseWidth.value) / 2
}
function handleWheel(event: WheelEvent) {
event.preventDefault()
const delta = event.deltaY > 0 ? -1 : 1
if (event.ctrlKey || (event as any).metaKey) {
const zoomFactor = 1.1
const newScale = delta > 0 ? state.scale * zoomFactor : state.scale / zoomFactor
state.scale = Math.max(state.minScale, Math.min(state.maxScale, newScale))
}
}
function handleMouseDown(event: MouseEvent) {
if (event.button !== 0) return
state.isDragging = true
state.dragStart = { x: event.clientX, y: event.clientY, viewBoxX: state.viewBoxX, viewBoxY: state.viewBoxY }
if (svgContainerRef.value) svgContainerRef.value.style.cursor = 'grabbing'
}
function handleMouseMove(event: MouseEvent) {
if (!state.isDragging) return
const dx = event.clientX - state.dragStart.x
const dy = event.clientY - state.dragStart.y
state.viewBoxX = state.dragStart.viewBoxX - dx / state.scale
state.viewBoxY = state.dragStart.viewBoxY - dy / state.scale
}
function handleMouseUp() {
state.isDragging = false
if (svgContainerRef.value) svgContainerRef.value.style.cursor = 'grab'
}
function handleMouseLeave() { state.isDragging = false }
defineExpose({ updateSvgSize, centerView })
</script>
<style scoped>
.warehouse-plan-card {
height: 100%;
display: flex;
flex-direction: column;
.el-card__body {
flex: 1;
height: 100px;
}
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.card-title {
font-size: 16px;
font-weight: 600;
color: var(--el-text-color-primary);
}
.toolbar {
display: flex;
align-items: center;
}
.scale-info {
color: var(--el-text-color-secondary);
font-size: 14px;
margin-left: 16px;
}
.warehouse-container {
flex: 1;
display: flex;
position: relative;
min-height: 600px;
height: 100%;
background: var(--el-fill-color-light);
border-radius: var(--el-border-radius-base);
overflow: hidden;
}
.svg-container {
flex: 1;
overflow: hidden;
position: relative;
}
svg {
display: block;
background: white;
}
.u-slot {
cursor: pointer;
transition: filter 0.2s;
}
.u-slot:hover {
filter: url(#highlight);
}
.rack-background {
pointer-events: none;
}
.pick-start {
cursor: pointer;
transition: transform 0.2s;
}
.pick-start:hover {
transform: scale(1.1);
}
.info-panel {
position: absolute;
top: 16px;
right: 16px;
width: 280px;
background: white;
border-radius: var(--el-border-radius-base);
box-shadow: var(--el-box-shadow-light);
border: 1px solid var(--el-border-color-lighter);
z-index: 10;
}
.info-header {
padding: 16px;
border-bottom: 1px solid var(--el-border-color-lighter);
display: flex;
justify-content: space-between;
align-items: center;
}
.info-header h4 {
margin: 0;
font-size: 14px;
font-weight: 600;
color: var(--el-text-color-primary);
}
.info-content {
padding: 16px;
}
.info-section {
margin-bottom: 16px;
}
.info-section:last-child {
margin-bottom: 0;
}
.info-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
font-size: 13px;
}
.info-row:last-child {
margin-bottom: 0;
}
.info-row .label {
color: var(--el-text-color-secondary);
}
.info-row .value {
color: var(--el-text-color-primary);
font-weight: 500;
text-align: right;
}
.grid-layer text {
user-select: none;
pointer-events: none;
}
/* 响应式调整 */
@media (max-width: 992px) {
.warehouse-container {
flex-direction: column;
}
.info-panel {
position: static;
width: 100%;
margin-top: 16px;
}
.svg-container {
min-height: 500px;
}
}
@media (max-width: 768px) {
.card-header {
flex-direction: column;
align-items: flex-start;
gap: 12px;
}
.toolbar {
flex-wrap: wrap;
gap: 8px;
}
.scale-info {
margin-left: 0;
flex-basis: 100%;
}
}
</style>

View File

@ -0,0 +1,522 @@
<template>
<el-dialog :title="dialogTitle" v-model="props.visible" width="900px" :before-close="handleClose" :close-on-click-modal="false">
<el-form ref="zoneFormRef" :model="formData" :rules="formRules" label-width="100px" label-position="left">
<!-- 分区类型改为下拉选择 -->
<el-form-item label="分区类型" prop="zone_type">
<el-select v-model="formData.zone_type" placeholder="请选择分区类型" style="width: 100%" @change="handleTypeChange"
:disabled="mode === 'edit' || submitting">
<el-option v-for="type in availableZoneTypes" :key="type.value" :label="type.label" :value="type.value" />
</el-select>
</el-form-item>
<el-form-item label="分区编码" prop="zone_code">
<el-input v-model="formData.zone_code" placeholder="请输入分区编码" maxlength="5" show-word-limit />
</el-form-item>
<el-form-item label="分区名称" prop="zone_name">
<el-input v-model="formData.zone_name" placeholder="请输入分区名称" maxlength="100" show-word-limit />
</el-form-item>
<!-- 父分区信息显示 -->
<el-form-item v-if="showParentInfo" label="父分区">
<el-input v-model="parentDisplayName" :disabled="true" style="width: 100%" />
</el-form-item>
<!-- 尺寸信息 - 所有类型都显示 -->
<el-card class="size-card">
<template #header>
<span>尺寸信息</span>
<el-tooltip v-if="formData.zone_type === 'area'" content="区域通常用于规划仓库内的功能区划分" placement="top">
<i class="el-icon-info" style="margin-left: 8px; color: #909399;"></i>
</el-tooltip>
<el-tooltip v-if="formData.zone_type === 'warehouse'" content="仓库的整体尺寸" placement="top">
<i class="el-icon-info" style="margin-left: 8px; color: #909399;"></i>
</el-tooltip>
</template>
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="总长度" prop="length">
<el-input-number v-if="formData.direction=='north'||formData.direction=='south'" v-model="formData.length" placeholder="长度" :min="10" :step="10" style="width: 100%" />
<el-input-number v-else v-model="formData.width" placeholder="长度" :min="10" :step="10" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="总宽度" prop="width">
<el-input-number v-if="formData.direction=='west'||formData.direction=='east'" v-model="formData.length" placeholder="宽度" :min="10" :step="10" style="width: 100%" />
<el-input-number v-else v-model="formData.width" placeholder="宽度" :min="10" :step="10" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="高度" prop="height">
<el-input-number v-model="formData.height" placeholder="高度" :min="10" :step="10" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
</el-row>
<!-- 面积/体积信息显示 -->
<div class="calculation-info">
<span v-if="formData.zone_type === 'area'">面积:{{ calculateArea() }} m²</span>
<span v-if="formData.zone_type === 'rack'">体积:{{ calculateVolume() }} m³</span>
<span v-if="formData.zone_type === 'warehouse'">面积:{{ calculateArea() }} m²</span>
<span v-if="formData.zone_type === 'pick_start'">面积:{{ calculateArea() }} m²</span>
</div>
</el-card>
<!-- 坐标信息 - 用于定位 -->
<el-card class="coordinate-card" v-if="formData.zone_type !== 'warehouse'">
<template #header>
<span>坐标信息</span>
<el-tooltip content="设置分区在三维空间中的位置坐标" placement="top">
<i class="el-icon-info" style="margin-left: 8px; color: #909399;"></i>
</el-tooltip>
</template>
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="X坐标" prop="x">
<el-input-number v-model="formData.x" placeholder="X坐标" :min="0" :step="10" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="Y坐标" prop="y">
<el-input-number v-model="formData.y" placeholder="Y坐标" :min="0" :step="10" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="Z坐标" prop="z">
<el-input-number v-model="formData.z" placeholder="Z坐标" :min="0" :step="10" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
</el-row>
<!-- 坐标说明 -->
<div class="coordinate-note">
<small>说明:X(左右), Y(前后), Z(上下),用于三维空间定位</small>
</div>
</el-card>
<!-- 货架配置 -->
<el-card class="rack-card" v-if="formData.zone_type === 'rack'">
<template #header>
<span>货架配置</span>
<el-tooltip content="货架尺寸指单个货架的尺寸,用于计算仓位布局" placement="top">
<i class="el-icon-info" style="margin-left: 8px; color: #909399;"></i>
</el-tooltip>
</template>
<!-- 货架单元格尺寸 -->
<div class="rack-grid-size">
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="货架长度" prop="cell_length">
<el-input-number v-model="formData.cell_length" placeholder="货架长度" :min="10" :step="5" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="货架深度" prop="cell_width">
<el-input-number v-model="formData.cell_width" placeholder="货架深度" :min="10" :step="5" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="货架高度" prop="cell_height">
<el-input-number v-model="formData.cell_height" placeholder="货架高度" :min="10" :step="5" style="width: 100%" />
<span class="unit-hint">cm</span>
</el-form-item>
</el-col>
</el-row>
</div>
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="列数" prop="rack_columns">
<el-input-number v-model="formData.rack_columns" placeholder="列数" :min="1" :max="255" style="width: 100%" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="层数" prop="rack_rows">
<el-input-number v-model="formData.rack_rows" placeholder="层数" :min="1" :max="255" style="width: 100%" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="分格数" prop="rack_levels">
<el-input-number v-model="formData.rack_levels" placeholder="分格数" :min="1" :max="255" style="width: 100%" />
</el-form-item>
</el-col>
</el-row>
<el-form-item label="朝向" prop="direction">
<el-radio-group v-model="formData.direction">
<el-radio label="north">北</el-radio>
<el-radio label="south">南</el-radio>
<el-radio label="east">东</el-radio>
<el-radio label="west">西</el-radio>
</el-radio-group>
</el-form-item>
<el-row :gutter="20">
<el-col :span="24">
<el-form-item label="自定义通道" prop="z">
<el-input v-model="aislesInput" placeholder="通道所在的列数,多个使用英文,分割,不能超出总列数" style="width: 100%" />
<span class="unit-hint">通道所在的列数,多个使用英文逗号分割</span>
</el-form-item>
</el-col>
</el-row>
<!-- 货架仓位总数 -->
<div class="rack-total-info">
<span>仓位总数:{{ calculateRackTotal() }}</span>
</div>
</el-card>
<!-- 显示颜色和启用状态 -->
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="是否启用" prop="is_active">
<el-switch v-model="formData.is_active" :active-value="1" :inactive-value="0" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleSubmit" :loading="submitting">确定</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, reactive, watch, computed } from 'vue'
import * as warehouseApi from '@/api/warehouse'
import { ElMessage, ElMessageBox } from 'element-plus'
const props = defineProps({
visible: { type: Boolean, required: true },
mode: { type: String, default: 'add' },
zoneData: { type: Object, default: null },
parentId: { type: [Number, String], default: null },
parentType: { type: String, default: null },
parentInfo: { type: Object, default: null },
warehouseId: { type: [Number, String], default: null }
})
const emit = defineEmits(['close', 'success'])
const zoneFormRef = ref<any>(null)
const aislesInput = ref('')
const submitting = ref(false)
type ZoneForm = {
zone_type: string
zone_code: string
zone_name: string
parent_id: string | number | null
warehouse_id: string | number | null
x: number
y: number
z: number
length: number
width: number
height: number
rack_columns: number | null
rack_rows: number | null
rack_levels: number | null
cell_length: number | null
cell_width: number | null
cell_height: number | null
direction: string | null
color: string
is_active: number
aisles: (string | number)[]
}
const formData = reactive<ZoneForm>(getDefaultFormData())
function getDefaultFormData(): ZoneForm {
return {
zone_type: 'area',
zone_code: '',
zone_name: '',
parent_id: null,
warehouse_id: null,
x: 0,
y: 0,
z: 0,
length: 500,
width: 500,
height: 300,
rack_columns: 5,
rack_rows: 5,
rack_levels: 2,
cell_length: 220,
cell_width: 100,
cell_height: 500,
direction: 'north',
color: '#3B82F6',
is_active: 1,
aisles: []
}
}
const allZoneTypes = [ { value: 'area', label: '库区' }, { value: 'rack', label: '货架' }, { value: 'pick_start', label: '拣货点' } ]
const predefineColors = [ '#3B82F6','#10B981','#F59E0B','#EF4444','#8B5CF6','#EC4899','#6B7280','#14B8A6','#F97316','#84CC16' ]
const formRules = reactive({
zone_type: [ { required: true, message: '请选择分区类型', trigger: 'change' } ],
zone_code: [ { required: true, message: '请输入分区编码', trigger: 'blur' }, { pattern: /^[A-Z0-9]{1,5}$/, message: '编码只能是1-5位字母或数字', trigger: 'blur' } ],
zone_name: [ { required: true, message: '请输入分区名称', trigger: 'blur' }, { max: 100, message: '名称最多100个字符', trigger: 'blur' } ],
length: [ { required: true, message: '请输入长度', trigger: 'blur' } ],
width: [ { required: true, message: '请输入宽度', trigger: 'blur' } ],
height: [ { required: true, message: '请输入高度', trigger: 'blur' } ],
rack_columns: [ { type: 'number', min:1, max:255, message: '列数范围1-255', trigger: 'blur' } ],
rack_rows: [ { type: 'number', min:1, max:10, message: '层数范围1-10', trigger: 'blur' } ],
rack_levels: [ { type: 'number', min:1, max:8, message: '分格数范围1-8', trigger: 'blur' } ],
cell_length: [ { required: true, message: '请输入单元格长度', trigger: 'blur' } ],
cell_width: [ { required: true, message: '请输入单元格宽度', trigger: 'blur' } ],
cell_height: [ { required: true, message: '请输入单元格高度', trigger: 'blur' } ]
})
const availableZoneTypes = computed(() => {
if (props.mode === 'edit') {
const currentType = formData.zone_type
const t = allZoneTypes.find(x => x.value === currentType)
return t ? [t] : []
}
if (props.mode === 'add' && props.parentType) {
if (props.parentType === 'warehouse') return allZoneTypes.filter(t => t.value === 'area')
if (props.parentType === 'area') return allZoneTypes.filter(t => t.value === 'rack' || t.value === 'pick_start')
return []
}
return allZoneTypes
})
const dialogTitle = computed(() => {
const map: any = { 'warehouse': '仓库','area':'库区','rack':'货架','pick_start':'拣货点' }
const typeName = map[formData.zone_type] || '分区'
return props.mode === 'add' ? `添加${typeName}` : `编辑${typeName}`
})
const showParentInfo = computed(() => {
if (props.mode === 'edit' && formData.zone_type !== 'warehouse') return true
if (props.mode === 'add' && props.parentInfo) return true
return false
})
const parentDisplayName = computed(() => {
if (props.mode === 'edit' && formData.zone_type !== 'warehouse') {
if (props.zoneData && (props.zoneData.parentInfo || props.zoneData.parentWarehouseName)) {
const p = props.zoneData.parentInfo || { code: '未知编码', name: '未知名称' }
return `${p.code || '未知编码'} - ${p.name || '未知名称'}`
}
return '未知父分区'
}
if (props.mode === 'add' && props.parentInfo) {
const map: any = { 'warehouse': '仓库','area':'库区','rack':'货架' }
const typeName = map[props.parentInfo.type] || props.parentInfo.type || '未知'
return `${props.parentInfo.code || '未知编码'} - ${props.parentInfo.name || '未知名称'} (${typeName})`
}
return ''
})
watch(() => props.visible, (newVal) => { if (newVal) initFormData(); else resetForm() }, { immediate: true })
watch(() => props.zoneData, () => initFormData(), { deep: true })
watch(() => props.parentType, (nv) => { if (nv && props.mode === 'add') autoSetZoneType(nv) }, { immediate: true })
watch(() => formData.length, () => autoCalculateCellSize())
watch(() => formData.width, () => autoCalculateCellSize())
watch(() => formData.height, () => autoCalculateCellSize())
watch(aislesInput, (newVal) => {
if (!newVal) { formData.aisles = []; return }
formData.aisles = newVal.split(',').map(s => { const t = s.trim(); const n = parseInt(t,10); return isNaN(n)? t: n }).filter(x => x !== '')
})
function initFormData() {
if (props.mode === 'edit' && props.zoneData) {
const d = props.zoneData.data || {}
Object.assign(formData, {
zone_type: props.zoneData.type || props.zoneData.zone_type,
zone_code: props.zoneData.code || props.zoneData.zone_code,
zone_name: props.zoneData.name || props.zoneData.zone_name,
parent_id: props.zoneData.parentId || props.zoneData.parent_id,
warehouse_id: props.warehouseId,
x: props.zoneData.x || 0,
y: props.zoneData.y || 0,
z: props.zoneData.z || 0,
length: props.zoneData.length || getDefaultFormData().length,
width: props.zoneData.width || getDefaultFormData().width,
height: props.zoneData.height || getDefaultFormData().height,
rack_columns: props.zoneData.rackColumns || props.zoneData.rack_columns || 5,
rack_rows: props.zoneData.rackRows || props.zoneData.rack_rows || 5,
rack_levels: props.zoneData.rackLevels || props.zoneData.rack_levels || 2,
cell_length: props.zoneData.cellLength || props.zoneData.cell_length || 220,
cell_width: props.zoneData.cellWidth || props.zoneData.cell_width || 100,
cell_height: props.zoneData.cellHeight || props.zoneData.cell_height || 500,
direction: props.zoneData.direction || 'north',
color: props.zoneData.color || '#3B82F6',
is_active: props.zoneData.isActive !== undefined ? props.zoneData.isActive : 1,
aisles: props.zoneData.aisles || []
})
aislesInput.value = (formData.aisles || []).map((it:any)=>String(it)).join(',')
} else {
Object.assign(formData, getDefaultFormData())
formData.warehouse_id = props.warehouseId
formData.parent_id = props.parentId
generateZoneCode()
setDefaultSizeByType()
}
}
function autoSetZoneType(parentTypeVal:any) {
if (props.mode === 'add' && parentTypeVal) {
if (parentTypeVal === 'warehouse') formData.zone_type = 'area'
else if (parentTypeVal === 'area') formData.zone_type = 'rack'
else { ElMessage.warning('当前位置不能添加子分区'); handleClose() }
}
}
function handleTypeChange(value:any) {
if (!formData.zone_code) generateZoneCode()
if (value !== 'rack') { formData.rack_columns = null; formData.rack_rows = null; formData.rack_levels = null; formData.cell_length = null; formData.cell_width = null; formData.cell_height = null; formData.direction = null }
setDefaultSizeByType()
}
function getDefaultSizeByType(type:any) {
const defs:any = { warehouse:{ length:3000,width:2000,height:800 }, area:{ length:500,width:500,height:300 }, rack:{ length:200,width:100,height:200 }, pick_start:{ length:100,width:100,height:100 } }
return defs[type] || defs.area
}
function setDefaultSizeByType() { Object.assign(formData, getDefaultSizeByType(formData.zone_type)) }
function generateZoneCode() {
if (!formData.zone_code) {
const prefixMap:any = { warehouse:'WH', area:'A', rack:'R', pick_start:'PS' }
const prefix = prefixMap[formData.zone_type] || 'Z'
const timestamp = Date.now().toString().slice(-4)
const random = Math.floor(Math.random()*90+10)
formData.zone_code = `${prefix}${random}${timestamp.slice(0,2)}`
}
}
function autoCalculateCellSize() {
if (formData.zone_type === 'rack') {
const { length=200, width=100, height=200, rack_columns=5, rack_rows=5 } = formData as any
const suggestedLength = Math.floor((length - 20) / rack_columns)
const suggestedWidth = Math.floor((width - 20) / 1)
const suggestedHeight = Math.floor((height - 20) / rack_rows)
if (!formData.cell_length || formData.cell_length <= 0) formData.cell_length = suggestedLength > 10 ? suggestedLength : 50
if (!formData.cell_width || formData.cell_width <= 0) formData.cell_width = suggestedWidth > 10 ? suggestedWidth : 50
if (!formData.cell_height || formData.cell_height <= 0) formData.cell_height = suggestedHeight > 10 ? suggestedHeight : 50
}
}
function calculateArea() { const { length=0, width=0 } = formData as any; return ((length*width)/10000).toFixed(2) }
function calculateVolume() { const { length=0,width=0,height=0 } = formData as any; return ((length*width*height)/1000000).toFixed(2) }
function calculateRackTotal() { const { rack_columns=1,rack_rows=1,rack_levels=1 } = formData as any; return rack_columns * rack_rows * rack_levels }
function resetForm() { if (zoneFormRef.value && zoneFormRef.value.resetFields) zoneFormRef.value.resetFields(); Object.assign(formData, getDefaultFormData()); submitting.value = false }
function handleClose() { if (!submitting.value) emit('close') }
async function handleSubmit() {
try {
if (zoneFormRef.value && zoneFormRef.value.validate) await zoneFormRef.value.validate()
submitting.value = true
const submitData = { ...formData, warehouse_id: props.warehouseId }
if (!validateHierarchy()) { submitting.value = false; return }
if (!validateSize()) { submitting.value = false; return }
let response:any
if (props.mode === 'add') response = await warehouseApi.create(submitData)
else response = await warehouseApi.update(submitData, props.zoneData?.id)
if (response && (response.code == 200 || (response.data && response.data.success))) {
ElMessage.success(props.mode === 'add' ? '添加成功' : '更新成功')
emit('success')
handleClose()
} else {
throw new Error(response.message || '操作失败')
}
} catch (error:any) {
console.error('提交失败:', error)
ElMessage.error(error.message || '操作失败')
} finally { submitting.value = false }
}
function validateHierarchy() {
if (props.mode === 'add') {
if (props.parentType === 'warehouse' && formData.zone_type !== 'area') { ElMessage.error('仓库下只能添加库区'); return false }
if (props.parentType === 'area' && !['rack','pick_start'].includes(formData.zone_type)) { ElMessage.error('库区下只能添加货架或拣货点'); return false }
if (props.parentType === 'rack') { ElMessage.error('货架下不能添加子分区'); return false }
}
return true
}
function validateSize() {
const { length=0,width=0,height=0 } = formData as any
if (length <=0 || width<=0 || height<=0) { ElMessage.error('长度、宽度、高度必须大于0'); return false }
if (formData.zone_type === 'rack') {
const { cell_length=0, cell_width=0, cell_height=0, rack_columns=1, rack_rows=1 } = formData as any
if (cell_length<=0 || cell_width<=0 || cell_height<=0) { ElMessage.error('货架单元格尺寸必须大于0'); return false }
if (cell_length * rack_columns > length) ElMessage.warning('货架单元格总长度超过货架总长度')
if (cell_height * rack_rows > height) ElMessage.warning('货架单元格总高度超过货架总高度')
}
return true
}
</script>
<style lang="scss" scoped>
.size-card,
.coordinate-card,
.rack-card {
margin-bottom: 20px;
.el-card__header {
padding: 12px 20px;
background: #f8f9fa;
display: flex;
align-items: center;
}
.unit-hint {
margin-left: 8px;
color: #909399;
font-size: 12px;
}
.calculation-info,
.rack-total-info {
margin-top: 16px;
padding: 8px 12px;
background: #f0f9ff;
border-radius: 4px;
color: #0369a1;
font-size: 14px;
font-weight: 500;
}
.rack-grid-size {
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #ebeef5;
}
}
.dialog-footer { text-align: right; }
.el-form-item { margin-bottom: 20px; &:last-child { margin-bottom: 0; } }
.el-input-number, .el-input { width: 100%; }
.el-color-picker { vertical-align: middle; margin-right: 8px; }
.color-preview { display: inline-block; width: 20px; height: 20px; border-radius: 4px; border: 1px solid #dcdfe6; vertical-align: middle; margin-left: 8px; }
.el-tag { font-size: 14px; padding: 0 10px; height: 32px; line-height: 32px; }
</style>

View File

@ -0,0 +1,146 @@
<template>
<el-card class="zone-management-card">
<template #header>仓库结构</template>
<div class="zone-tree-container">
<el-tree
v-if="treeData.length > 0"
ref="zoneTreeRef"
:data="treeData"
node-key="id"
:props="treeProps"
:expand-on-click-node="false"
:highlight-current="true"
@node-click="handleNodeClick"
>
<template v-slot="{ node, data }">
<span class="tree-node">
<span class="node-content">
<el-tag size="mini" :type="getZoneTypeTag(data.type)">
{{ getZoneTypeText(data.type) }}
</el-tag>
<span class="node-label">{{ data.name }}</span>
</span>
<span class="node-actions">
<el-button v-if="canAddChild(data.type)" type="primary" link @click.stop="handleAdd(data)">
<el-icon><Plus /></el-icon>
</el-button>
<el-button type="primary" link @click.stop="handleEdit(data)">
<el-icon><Edit /></el-icon>
</el-button>
<el-button type="danger" link @click.stop="handleDelete(data)">
<el-icon><Delete /></el-icon>
</el-button>
</span>
</span>
</template>
</el-tree>
</div>
</el-card>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { Plus, Edit, Delete } from '@element-plus/icons-vue'
const props = defineProps({
warehouseId: { type: [Number, String], required: true },
warehouseData: { type: Object, default: null }
})
const emit = defineEmits(['select', 'add', 'edit', 'delete'])
const treeData = ref<any[]>([])
const treeProps = { children: 'children', label: 'name' }
const zoneTypeMap: Record<string, { tag: string; text: string }> = {
warehouse: { tag: 'primary', text: '仓库' },
area: { tag: 'success', text: '库区' },
rack: { tag: 'warning', text: '货架' },
pick_start: { tag: 'info', text: '拣货点' }
}
const allowedParents: any = {
warehouse: ['area'],
area: ['rack', 'pick_start'],
rack: [],
pick_start: []
}
watch(() => props.warehouseData, (newData) => {
if (newData) treeData.value = [newData]
else treeData.value = []
}, { immediate: true })
function handleNodeClick(data: any) { emit('select', data) }
function handleAdd(data: any) { emit('add', data) }
function handleEdit(data: any) { emit('edit', data) }
function handleDelete(data: any) { emit('delete', data) }
function canAddChild(zoneType: string) { return (allowedParents[zoneType] || []).length > 0 }
function getZoneTypeTag(type: string) { return zoneTypeMap[type]?.tag || 'info' }
function getZoneTypeText(type: string) { return zoneTypeMap[type]?.text || type }
</script>
<style scoped>
.zone-management-card {
flex: 1;
display: flex;
flex-direction: column;
.el-card__header {
padding:0;
height:40px;
line-height:40px;
padding-left: 20px;
}
.el-card__body{
height: 100px;
flex:1;
}
.zone-tree-container {
height: 100%;
overflow-y: auto;
.tree-node {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
font-size: 14px;
.node-content {
display: flex;
align-items: center;
gap: 8px;
.node-label {
max-width: 150px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.node-actions {
opacity: 0;
transition: opacity 0.3s;
display: flex;
align-items: center;
.el-button {
padding: 0 4px;
margin-left: 0;
}
.el-icon {
font-size: 16px;
}
}
&:hover .node-actions {
opacity: 1;
}
}
}
}
</style>

View File

@ -1,8 +1,356 @@
<template>
<div class="warehouse-container">
<h1>仓库管理</h1>
<div class="warehouse-management-container">
<div class="main-layout">
<!-- 左侧边栏 -->
<div class="sidebar left-sidebar">
<warehouse-tree
:warehouse-list="warehouseList"
@select="handleWarehouseSelect"
@add="showAddWarehouseDialog"
/>
<zone-management
v-if="selectedWarehouse.id"
:warehouse-id="selectedWarehouse.id"
:warehouse-data="warehouseData"
@select="handleZoneSelect"
@add="handleAddZone"
@edit="handleEditZone"
@delete="handleDeleteZone"
/>
<zone-info
v-if="selectedWarehouse.id"
:rack="selectedRack"
:warehouse="selectedWarehouse"
:zone="selectedZone"
/>
</div>
<!-- 右侧边栏 -->
<div class="sidebar right-sidebar">
<!-- 修改这里,传入更多信息 -->
<rack-space-management
:rack="selectedRack"
ref="rackSpaceManagement"
@refresh="refreshRackSpaces"
@space-click="spaceClick"
/>
<space-card
v-if="selectedRack"
:spaceId="currentSpaceId"
@spaceSave="handleSpaceSave"
/>
</div>
<!-- 中间主内容区 -->
<div class="main-content">
<warehouse-viewer
v-if="warehouseData"
ref="warehouseViewer"
:warehouse-data="zoneData"
:scale="scale"
@shelf-click="onShelfClick"
/>
<div v-else class="empty-viewer">
<el-icon><OfficeBuilding /></el-icon>
<p>请选择一个仓库</p>
</div>
</div>
</div>
<!-- 弹窗组件 -->
<zone-dialog
:visible="zoneDialogVisible"
:mode="zoneDialogMode"
:zone-data="currentZone"
:parent-id="currentParentId"
:parent-type="currentParentType"
:parent-info="currentParentInfo"
:warehouse-id="selectedWarehouse.id"
@close="handleZoneDialogClose"
@success="handleZoneDialogSuccess"
/>
<warehouse-dialog
:visible="warehouseDialogVisible"
@close="handleWarehouseDialogClose"
@success="handleWarehouseDialogSuccess"
/>
</div>
</template>
<script setup lang="ts">
</script>
import { ref, onMounted, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { OfficeBuilding } from '@element-plus/icons-vue'
import WarehouseTree from './WarehouseTree.vue'
import ZoneManagement from './ZoneManagement.vue'
import WarehouseViewer from './WarehouseViewer.vue'
import RackSpaceManagement from './RackSpaceManagement.vue'
import ZoneDialog from './ZoneDialog.vue'
import WarehouseDialog from './WarehouseDialog.vue'
import zoneInfo from './zoneInfo.vue'
import spaceCard from './spaceCard.vue'
import * as warehouseApi from '@/api/warehouse'
// 仓库数据
const warehouseList = ref<any[]>([])
const selectedWarehouse = ref<any>({ id: null })
const selectedZone = ref<any>({})
const warehouseData = ref<any>(null)
const zoneData = ref<any>(null)
// 货架数据
const selectedRack = ref<any>(null)
// 缩放控制
const scale = ref(1)
// 弹窗控制
const zoneDialogVisible = ref(false)
const zoneDialogMode = ref<'add' | 'edit'>('add')
const currentZone = ref<any>(null)
const currentParentId = ref<any>(null)
const currentParentType = ref<any>(null)
const currentParentInfo = ref<any>(null)
const currentSpaceId = ref<any>(null)
const warehouseDialogVisible = ref(false)
// 组件引用
const rackSpaceManagement = ref<any>(null)
const warehouseViewer = ref<any>(null)
const spaceClick = async (data: any) => {
console.log("仓位行点击", data)
currentSpaceId.value = data.id
console.log(data.id, currentSpaceId.value)
}
// 加载仓库列表
const loadWarehouseList = async () => {
try {
const response: any = await warehouseApi.getWarehouseZones({})
if (response.code === 200) {
warehouseList.value = response.zones || []
}
} catch (error) {
ElMessage.error('加载仓库列表失败')
console.error(error)
}
}
const handleSpaceSave = async () => {
if (rackSpaceManagement.value) {
await rackSpaceManagement.value.loadRackSpaces()
}
}
// 选择仓库
const handleWarehouseSelect = async (warehouse: any) => {
selectedWarehouse.value = warehouse
selectedRack.value = null
try {
const response: any = await warehouseApi.getWarehouseTree(warehouse.id)
if (response.code === 200) {
zoneData.value = warehouseData.value = response.warehouseRoot
}
} catch (error) {
ElMessage.error('加载仓库数据失败')
console.error(error)
}
}
// 选择仓库元素
const handleZoneSelect = (zone: any) => {
if (zone.type === 'rack') {
selectedRack.value = zone
} else {
selectedRack.value = null // 更新平面图显示
if (zone.type !== 'pick_start') {
zoneData.value = zone
}
}
currentSpaceId.value = null
nextTick(() => {
if (warehouseViewer.value) {
warehouseViewer.value.updateSvgSize()
warehouseViewer.value.centerView()
}
})
}
// 添加元素
const handleAddZone = (parentData: any) => {
zoneDialogMode.value = 'add'
currentZone.value = null
currentParentId.value = parentData.id
currentParentType.value = parentData.type
currentParentInfo.value = {
code: parentData.code,
name: parentData.name
}
zoneDialogVisible.value = true
}
// 编辑元素
const handleEditZone = async (zoneDataObj: any) => {
try {
const response: any = await warehouseApi.detail(zoneDataObj.id)
if (response.code === 200) {
zoneDialogMode.value = 'edit'
currentZone.value = response.zone
zoneDialogVisible.value = true
}
} catch (error) {
ElMessage.error('加载元素详情失败')
}
}
// 删除元素
const handleDeleteZone = async (zoneDataObj: any) => {
ElMessageBox.confirm('确定删除该元素吗?此操作不可恢复。', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
try {
const response: any = await warehouseApi.deleteZone(zoneDataObj.id)
if (response.code === 200) {
ElMessage.success('删除成功')
await refreshCurrentWarehouse()
} else {
ElMessage.error(response.message || '删除失败')
}
} catch (error: any) {
ElMessage.error(error.message || '删除失败')
}
}).catch(() => {})
}
// 刷新当前仓库数据
const refreshCurrentWarehouse = async () => {
if (selectedWarehouse.value.id) {
await handleWarehouseSelect(selectedWarehouse.value)
}
}
// 刷新货架格子数据
const refreshRackSpaces = async () => {
if (selectedRack.value && rackSpaceManagement.value) {
await rackSpaceManagement.value.loadSpaces()
}
}
// 货架点击事件
const onShelfClick = (shelfData: any) => {
selectedRack.value = shelfData
}
// 弹窗关闭
const handleZoneDialogClose = () => {
zoneDialogVisible.value = false
}
// 弹窗成功
const handleZoneDialogSuccess = async () => {
zoneDialogVisible.value = false
await refreshCurrentWarehouse()
}
// 显示添加仓库弹窗
const showAddWarehouseDialog = () => {
warehouseDialogVisible.value = true
}
// 仓库弹窗关闭
const handleWarehouseDialogClose = () => {
warehouseDialogVisible.value = false
}
// 仓库弹窗成功
const handleWarehouseDialogSuccess = async () => {
warehouseDialogVisible.value = false
await loadWarehouseList()
}
onMounted(() => {
loadWarehouseList()
})
</script>
<style lang="scss" scoped>
.warehouse-management-container {
width: 100%;
height: 100%;
overflow: hidden;
.main-layout {
display: flex;
height: 100%;
padding: 16px;
gap: 16px;
.sidebar {
width: 300px;
display: flex;
flex-direction: column;
gap: 16px;
&.left-sidebar {
flex-shrink: 0;
}
&.right-sidebar {
flex-shrink: 0;
width: 600px;
}
}
.main-content {
flex: 1;
min-width: 0;
.empty-viewer {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #fff;
border-radius: 4px;
color: #c0c4cc;
i {
font-size: 48px;
margin-bottom: 16px;
}
p {
font-size: 14px;
}
}
}
.empty-rack {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #c0c4cc;
i {
font-size: 48px;
margin-bottom: 16px;
}
p {
font-size: 14px;
}
}
}
}
</style>

View File

@ -0,0 +1,125 @@
<template>
<div class="space-card">
<el-card class="space-management-card">
<el-tabs v-model="activeTab" class="space-tabs">
<el-tab-pane label="属性" name="property">
<property-form
ref="propertyFormRef"
:title="'属性管理'"
:space-id="currentSpaceId"
:key="propertyFormKey"
@spaceSave="handleSpaceSave"
class="tab-content"
/>
</el-tab-pane>
<el-tab-pane label="库存" name="inventory">
<inventory-form
ref="inventoryFormRef"
:title="'库存管理'"
:space-id="currentSpaceId"
:key="inventoryFormKey"
class="tab-content"
/>
</el-tab-pane>
</el-tabs>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref, watch, nextTick,} from 'vue'
import PropertyForm from './PropertyForm.vue'
import InventoryForm from './InventoryForm.vue'
const props = defineProps({ spaceId: { type: [String, Number], default: null } })
const emit = defineEmits(['spaceSave'])
const activeTab = ref('property')
const currentSpaceId = ref(props.spaceId)
const propertyFormKey = ref(0)
const inventoryFormKey = ref(0)
const propertyFormRef = ref<any>(null)
const inventoryFormRef = ref<any>(null)
watch(() => props.spaceId, (newId) => {
console.log('空间ID变化:', newId)
currentSpaceId.value = newId
propertyFormKey.value += 1
inventoryFormKey.value += 1
nextTick(() => {
if (activeTab.value === 'property' && propertyFormRef.value && propertyFormRef.value.loadProperties) {
propertyFormRef.value.loadProperties()
} else if (activeTab.value === 'inventory' && inventoryFormRef.value && inventoryFormRef.value.loadInventory) {
inventoryFormRef.value.loadInventory()
}
})
}, { immediate: true })
function updateSpaceId(spaceId: any) { currentSpaceId.value = spaceId }
function handleSpaceSave() {
emit('spaceSave')
console.log('修改仓位')
}
function reloadCurrentTab() {
if (activeTab.value === 'property') {
if (propertyFormRef.value && propertyFormRef.value.loadProperties) propertyFormRef.value.loadProperties()
} else if (activeTab.value === 'inventory') {
if (inventoryFormRef.value && inventoryFormRef.value.loadInventory) inventoryFormRef.value.loadInventory()
}
}
function getFormData() {
const data: any = { spaceId: currentSpaceId.value, properties: null, inventory: null }
if (propertyFormRef.value) {
if (propertyFormRef.value.getProperties) data.properties = propertyFormRef.value.getProperties()
else if (propertyFormRef.value.getFormData) data.properties = propertyFormRef.value.getFormData()
}
if (inventoryFormRef.value) {
if (inventoryFormRef.value.getInventory) data.inventory = inventoryFormRef.value.getInventory()
else if (inventoryFormRef.value.getProperties) data.inventory = inventoryFormRef.value.getProperties()
else if (inventoryFormRef.value.getFormData) data.inventory = inventoryFormRef.value.getFormData()
}
return data
}
defineExpose({ updateSpaceId, getFormData, reloadCurrentTab })
</script>
<style>
.space-card{
flex:1;
.space-management-card{
height:100%;
display:flex;
.el-card__body{
flex:1;
.space-tabs{
display:flex;
flex-direction: column;
height: 100%;
overflow-y: auto;
.el-tabs__header{
padding:0;
margin:0;
}
.el-tabs__content{
flex:1;
.el-tab-pane{
height: 100%;
overflow-y: auto;
overflow-x: hidden;
}
}
}
}
}
}
</style>

View File

@ -0,0 +1,768 @@
<template>
<div class="zone-management">
<!-- 左侧边栏 -->
<div class="sidebar">
<!-- 仓库列表卡片 -->
<el-card class="warehouse-card">
<template #header>
<span>仓库列表</span>
<el-button style="float: right; padding: 3px 0" type="text" @click="showAddWarehouseDialog">
添加仓库
</el-button>
</template>
<div class="warehouse-list">
<el-tree ref="warehouseTreeRef" :data="warehouseList" node-key="id" :props="warehouseTreeProps"
:expand-on-click-node="false" :highlight-current="true" @node-click="handleWarehouseSelect">
<template v-slot="{ node, data }">
<span class="custom-tree-node">
<span>
<span>{{ data.name }}</span>
</span>
</span>
</template>
</el-tree>
</div>
</el-card>
<!-- 仓库元素树状图 -->
<el-card class="zone-card">
<template #header>
<span>仓库元素</span>
</template>
<div class="zone-tree">
<el-tree v-if="selectedWarehouse.id" ref="zoneTreeRef" :data="zoneTreeData" node-key="id" :props="zoneTreeProps"
:expand-on-click-node="false" :highlight-current="true" @node-click="handleZoneSelect">
<template v-slot="{ node, data }">
<span class="custom-tree-node">
<span class="tree-node-content">
<span>{{ data.name }}</span>
</span>
<span class="tree-node-actions">
<el-button type="text" size="mini" @click.stop="addChildElement(data)">添加</el-button>
<el-button type="text" size="mini" @click.stop="editElement(data)">编辑</el-button>
<el-button type="text" size="mini" @click.stop="deleteElement(data)">删除</el-button>
</span>
</span>
</template>
</el-tree>
<div v-else class="empty-state">
<i class="el-icon-office-building" style="font-size: 48px; color: #c0c4cc;"></i>
<p>请先选择一个仓库</p>
</div>
</div>
</el-card>
</div>
<!-- 主内容区 - 仓库平面图 -->
<el-card class="main-content" :body-style="'flex:1'">
<template #header>
<span>仓库平面图</span>
<div class="view-controls">
<el-button-group>
<el-button size="mini" @click="zoomOut" :disabled="scale <= minScale">
<i class="el-icon-zoom-out"></i>
</el-button>
<el-button size="mini" @click="zoomIn" :disabled="scale >= maxScale">
<i class="el-icon-zoom-in"></i>
</el-button>
<el-button size="mini" @click="resetView">
<i class="el-icon-refresh"></i> 重置
</el-button>
</el-button-group>
<span class="scale-display">
缩放: {{ (scale * 100).toFixed(0) }}%
</span>
</div>
</template>
<div class="viewer-container">
<WarehouseViewer v-if="warehouseData" ref="warehouseViewerRef" :warehouse-data="warehouseData" :scale="scale"
@shelf-cell-click="onShelfCellClick" @area-click="onAreaClick" @mode-change="onModeChange" />
</div>
</el-card>
<!-- 右侧边栏 - 连通性检测 -->
<div class="sidebar">
<el-card class="connectivity-card">
<template #header>
<span>连通性检测</span>
</template>
<div class="connectivity-content">
<div class="zone-selectors">
<div class="zone-selector">
<label>起点位置:</label>
<el-select v-model="startZone" placeholder="请选择起点" @change="onZoneSelect('start')">
<el-option v-for="z in allZones" :key="z.id" :label="z.label" :value="z.id" />
</el-select>
</div>
<div class="zone-selector">
<label>终点位置:</label>
<el-select v-model="endZone" placeholder="请选择终点" @change="onZoneSelect('end')">
<el-option v-for="z in allZones" :key="z.id" :label="z.label" :value="z.id" />
</el-select>
</div>
</div>
<div class="selected-zones">
<div v-if="selectedStartZone" class="selected-zone">
<div class="zone-info">
<strong>{{ selectedStartZone.name }}</strong>
</div>
</div>
<div v-if="selectedEndZone" class="selected-zone">
<div class="zone-info">
<strong>{{ selectedEndZone.name }}</strong>
</div>
</div>
</div>
<div class="detection-actions">
<el-button type="primary" size="small" @click="checkConnectivity" :disabled="!selectedStartZone || !selectedEndZone">
<i class="el-icon-connection"></i> 检测连通性
</el-button>
<el-button type="info" size="small" @click="clearSelection">
清空选择
</el-button>
</div>
<div v-if="connectivityResult !== null" class="result-container">
<div :class="['result-card', connectivityResult.success ? 'success' : 'error']">
<div class="result-header">
<strong>{{ connectivityResult.success ? '连通' : '不连通' }}</strong>
</div>
<div class="result-content">
<div v-if="connectivityResult.success">距离: {{ connectivityResult.distance }}</div>
<div v-else>原因: {{ connectivityResult.reason }}</div>
</div>
<div v-if="connectivityResult.success" class="result-actions">
<el-button size="mini" @click="visualizePath">可视化路径</el-button>
<el-button size="mini" @click="showPathDetails">查看详情</el-button>
</div>
</div>
</div>
<div v-if="detectionHistory.length > 0" class="history-container">
<div class="history-header">
<span>检测历史</span>
<el-button type="text" size="mini" @click="clearHistory">清空</el-button>
</div>
<div class="history-list">
<div v-for="record in detectionHistory" :key="record.id" class="history-item" @click="showHistoryRecord(record)">
<div>{{ record.time }} - {{ record.startName }} → {{ record.endName }} - {{ record.success ? '成功' : '失败' }}</div>
</div>
</div>
</div>
</div>
</el-card>
</div>
<!-- 添加/编辑元素弹窗 -->
<ZoneDialog :visible="dialogVisible" :mode="dialogMode" :zone-data="currentZone" :parent-id:string="selectedParentId" :parentType="parentType"
:warehouse-id:string="selectedWarehouse.id" @close="() => dialogVisible = false" @success="handleDialogSuccess" />
<!-- 添加仓库弹窗 -->
<el-dialog title="添加仓库" :visible.sync="warehouseDialogVisible" width="800px" :before-close="handleWarehouseDialogClose">
<el-form ref="warehouseFormRef" :model="warehouseForm" :rules="warehouseRules" label-width="100px">
<el-form-item label="仓库名称" prop="zone_name">
<el-input v-model="warehouseForm.zone_name" placeholder="请输入仓库名称" />
</el-form-item>
<el-form-item label="仓库编码" prop="zone_code">
<el-input v-model="warehouseForm.zone_code" placeholder="请输入仓库编码" maxlength="5" show-word-limit />
</el-form-item>
<el-card class="coordinate-section">
<template #header>
<span>仓库尺寸(单位:毫米)</span>
</template>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="长度" prop="length">
<el-input-number v-model="warehouseForm.length" :min="1000" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="宽度" prop="width">
<el-input-number v-model="warehouseForm.width" :min="1000" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="高度" prop="height">
<el-input-number v-model="warehouseForm.height" :min="1000" />
</el-form-item>
</el-col>
</el-row>
</el-card>
<el-form-item label="显示颜色" prop="color">
<el-color-picker v-model="warehouseForm.color" />
</el-form-item>
<el-form-item label="是否启用" prop="is_active">
<el-switch v-model="warehouseForm.is_active" :active-value="1" :inactive-value="0" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="warehouseDialogVisible = false">取消</el-button>
<el-button type="primary" @click="submitWarehouse" :loading="submittingWarehouse">确定</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, onBeforeUnmount, watch, nextTick } from 'vue'
import WarehouseViewer from './WarehouseViewer.vue'
import ZoneDialog from './ZoneDialog.vue'
import * as warehouseApi from '@/api/warehouse'
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
const warehouseTreeRef = ref(null)
const zoneTreeRef = ref(null)
const warehouseViewerRef = ref<any>(null)
const warehouseFormRef = ref<any>(null)
const warehouseList = ref<any[]>([])
const selectedWarehouse = reactive({ id: null })
const zoneTreeData = ref<any[]>([])
const zoneTreeProps = { children: 'children', label: 'label' }
const warehouseTreeProps = { children: 'children', label: 'name' }
const warehouseData = ref<any>(null)
const scale = ref(1)
const minScale = ref(0.5)
const maxScale = ref(3)
const allZones = ref<any[]>([])
const startZone = ref<number | null>(null)
const endZone = ref<number | null>(null)
const selectedStartZone = ref<any>(null)
const selectedEndZone = ref<any>(null)
const connectivityResult = ref<any | null>(null)
const detectionHistory = ref<any[]>([])
const currentDetectionId = ref<number | null>(null)
const dialogVisible = ref(false)
const dialogMode = ref<'add' | 'edit'>('add')
const currentZone = ref<any>(null)
const parentType = ref<any>(null)
const selectedParentId = ref<number | null>(null)
const warehouseDialogVisible = ref(false)
const warehouseForm = reactive({
zone_type: 'warehouse',
zone_name: '',
zone_code: '',
parent_id: 0,
x: 0,
y: 0,
z: 0,
length: 10000,
width: 10000,
height: 5000,
color: '#96ceb4',
is_active: 1
})
const warehouseRules = reactive({
zone_name: [ { required: true, message: '请输入仓库名称', trigger: 'blur' }, { min:1, max:100, message: '长度在 1 到 100 个字符', trigger: 'blur' } ],
zone_code: [ { required: true, message: '请输入仓库编码', trigger: 'blur' }, { pattern: /^[A-Z0-9]{1,5}$/, message: '编码必须是1-5位大写字母或数字', trigger: 'blur' } ],
length: [ { required: true, message: '请输入长度', trigger: 'blur' }, { type: 'number', min: 1000, message: '长度不能小于1000mm', trigger: 'blur' } ],
width: [ { required: true, message: '请输入宽度', trigger: 'blur' }, { type: 'number', min: 1000, message: '宽度不能小于1000mm', trigger: 'blur' } ],
height: [ { required: true, message: '请输入高度', trigger: 'blur' }, { type: 'number', min: 1000, message: '高度不能小于1000mm', trigger: 'blur' } ]
})
let handleWheelListener: any = null
onMounted(() => {
initWarehouse()
initEventListeners()
})
onBeforeUnmount(() => {
removeEventListeners()
})
watch(zoneTreeData, (newVal) => {
if (newVal && newVal.length > 0) {
extractAllZones(newVal[0])
}
}, { deep: true })
async function initWarehouse() {
try {
const response: any = await warehouseApi.getWarehouseZones({})
if (response.code == 200) {
warehouseList.value = formatWarehouseList(response.zones || [])
}
} catch (error) {
ElMessage.error('加载仓库列表失败')
console.error(error)
}
}
function formatWarehouseList(data: any[]) {
return data.map(warehouse => ({
id: warehouse.id,
name: warehouse.label || warehouse.zone_name,
code: warehouse.code || warehouse.zone_code,
type: warehouse.type || 'warehouse',
children: warehouse.children || [],
data: warehouse.data || {}
}))
}
async function handleWarehouseSelect(data: any) {
selectedWarehouse.id = data.id
try {
const treeResponse: any = await warehouseApi.getWarehouseTree(data.id)
if (treeResponse.code == 200) {
zoneTreeData.value = [treeResponse.warehouseRoot]
calculateInitialScale(treeResponse.warehouseRoot)
warehouseData.value = treeResponse.warehouseRoot
}
} catch (error) {
ElMessage.error('加载仓库数据失败')
console.error(error)
}
}
function handleZoneSelect(data: any) {
warehouseData.value = data
}
function extractAllZones(node: any, result: any[] = []) {
if (!node) return result
if (node.type !== 'warehouse_root' && node.id) {
result.push({ id: node.id, label: `${node.code || ''} - ${node.name}`, type: node.type, name: node.name, code: node.code, data: node.data || {} })
}
if (node.children && node.children.length > 0) node.children.forEach((child: any) => extractAllZones(child, result))
allZones.value = result
}
function calculateInitialScale(warehouseRoot: any) {
if (!warehouseRoot || !warehouseRoot.children || warehouseRoot.children.length === 0) {
scale.value = 1
return
}
let maxX = 0, maxY = 0
const traverse = (node: any) => {
if (node.data) {
const x = (node.data.x || 0) + (node.data.length || 0)
const y = (node.data.y || 0) + (node.data.width || 0)
maxX = Math.max(maxX, x)
maxY = Math.max(maxY, y)
}
if (node.children) node.children.forEach((c: any) => traverse(c))
}
traverse(warehouseRoot)
nextTick(() => {
const containerWidth = warehouseViewerRef.value && warehouseViewerRef.value.$el ? warehouseViewerRef.value.$el.offsetWidth : 800
const containerHeight = warehouseViewerRef.value && warehouseViewerRef.value.$el ? warehouseViewerRef.value.$el.offsetHeight : 600
const scaleX = containerWidth / (maxX + 100)
const scaleY = containerHeight / (maxY + 100)
const targetScale = Math.min(scaleX, scaleY, 1)
scale.value = targetScale || 1
})
}
function canAddChild(zoneType: string) {
const allowedParents: any = { warehouse: ['area'], area: ['aisle'], aisle: ['rack'], rack: [], obstacle: [], gate: [], pick_start: [] }
return allowedParents[zoneType] && allowedParents[zoneType].length > 0
}
function getAddableChildTypes(parentTypeVal: string) {
const typeMap: any = { warehouse: ['area'], area: ['aisle'], aisle: ['rack', 'obstacle', 'gate', 'pick_start'] }
return typeMap[parentTypeVal] || []
}
function addRootElement() {
if (!selectedWarehouse.id) { ElMessage.warning('请先选择仓库'); return }
dialogMode.value = 'add'
currentZone.value = null
selectedParentId.value = selectedWarehouse.id
dialogVisible.value = true
}
function addChildElement(parentData: any) {
dialogMode.value = 'add'
currentZone.value = null
parentType.value = parentData.type
selectedParentId.value = parentData.id
dialogVisible.value = true
}
async function editElement(zoneData: any) {
try {
const response: any = await warehouseApi.detail(zoneData.id)
if (response.code == 200) {
dialogMode.value = 'edit'
currentZone.value = response.zone
selectedParentId.value = null
dialogVisible.value = true
}
} catch (error) {
ElMessage.error('加载元素详情失败')
console.error(error)
}
}
function deleteElement(zoneData: any) {
ElMessageBox.confirm('确定删除该元素吗?此操作不可恢复。', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
.then(async () => {
try {
const response: any = await warehouseApi.deleteZone(zoneData.id)
if (response.data && response.data.success) {
ElMessage.success('删除成功')
refreshZoneTree()
}
} catch (error) { ElMessage.error('删除失败'); console.error(error) }
}).catch(() => {})
}
async function handleDialogSuccess() { dialogVisible.value = false; await refreshZoneTree() }
async function refreshZoneTree() {
if (!selectedWarehouse.id) return
try {
const response: any = await warehouseApi.getWarehouseTree(selectedWarehouse.id)
if (response.data && response.data.success) {
zoneTreeData.value = [response.data.data]
warehouseData.value = response.data.data
}
} catch (error) { console.error('刷新树状图失败:', error) }
}
function showAddWarehouseDialog() {
warehouseForm.zone_type = 'warehouse'
warehouseForm.zone_name = ''
warehouseForm.zone_code = ''
warehouseForm.parent_id = 0
warehouseForm.x = 0
warehouseForm.y = 0
warehouseForm.z = 0
warehouseForm.length = 10000
warehouseForm.width = 10000
warehouseForm.height = 5000
warehouseForm.color = '#96ceb4'
warehouseForm.is_active = 1
if (warehouseFormRef.value && warehouseFormRef.value.clearValidate) warehouseFormRef.value.clearValidate()
warehouseDialogVisible.value = true
}
async function submitWarehouse() {
try {
if (warehouseFormRef.value && warehouseFormRef.value.validate) await warehouseFormRef.value.validate()
warehouseDialogVisible.value = false
submittingWarehouse.value = false
const response: any = await warehouseApi.create(warehouseForm)
if (response.data && response.data.success) { ElMessage.success('仓库添加成功'); initWarehouse() }
} catch (err: unknown) {
let msg = '添加仓库失败'
if (err instanceof Error) msg = err.message
else if (typeof err === 'string') msg = err
ElMessage.error(msg)
console.error(err)
}
}
function handleWarehouseDialogClose(done: any) {
if (submittingWarehouse.value) { ElMessage.warning('正在提交,请稍候'); return }
done()
}
function onZoneSelect(type: 'start' | 'end') {
const zoneId = type === 'start' ? startZone.value : endZone.value
const zone = allZones.value.find(z => z.id === zoneId)
if (zone) { if (type === 'start') selectedStartZone.value = zone; else selectedEndZone.value = zone }
}
async function checkConnectivity() {
if (!selectedStartZone.value || !selectedEndZone.value) { ElMessage.warning('请选择起点和终点'); return }
if (selectedStartZone.value.id === selectedEndZone.value.id) { ElMessage.warning('起点和终点不能相同'); return }
try {
const response: any = await warehouseApi.checkConnectivity({ startZoneId: selectedStartZone.value.id, endZoneId: selectedEndZone.value.id, warehouseId: selectedWarehouse.id })
if (response.data && response.data.success) {
connectivityResult.value = response.data.data
addToHistory(connectivityResult.value)
ElMessage.success('连通性检测完成')
}
} catch (error) {
const result = simulateConnectivity()
connectivityResult.value = result
addToHistory(result)
if (result.success) ElMessage.success('路径可达')
else ElMessage.warning('路径不可达')
}
}
function simulateConnectivity() {
const start = selectedStartZone.value; const end = selectedEndZone.value
const obstacles = allZones.value.filter((z: any) => z.type === 'obstacle' || (z.type === 'rack' && !canPassThroughRack(z)))
if (obstacles.some((obs: any) => obs.id === start.id || obs.id === end.id)) return { success: false, reason: '起点或终点是障碍物', distance:0, path: [] }
const distance = calculateDistance(start, end)
const path = [start, end]
const isConnected = Math.random() > 0.3
return isConnected ? { success: true, distance, path, reason: '' } : { success: false, distance:0, path: [], reason: '路径被障碍物阻挡' }
}
function calculateDistance(zone1: any, zone2: any) {
const center1 = { x: zone1.data.x + zone1.data.length / 2, y: zone1.data.y + zone1.data.width / 2, z: zone1.data.z + zone1.data.height / 2 }
const center2 = { x: zone2.data.x + zone2.data.length / 2, y: zone2.data.y + zone2.data.width / 2, z: zone2.data.z + zone2.data.height / 2 }
const dx = center1.x - center2.x, dy = center1.y - center2.y, dz = center1.z - center2.z
return Math.sqrt(dx*dx + dy*dy + dz*dz)
}
function canPassThroughRack(rackZone: any) { return rackZone.data.direction !== 'north' }
function addToHistory(result: any) {
const record = { id: Date.now(), startZoneId: selectedStartZone.value.id, startName: selectedStartZone.value.name, endZoneId: selectedEndZone.value.id, endName: selectedEndZone.value.name, success: result.success, distance: result.distance, time: new Date().toLocaleTimeString(), data: result }
detectionHistory.value.unshift(record)
currentDetectionId.value = record.id
if (detectionHistory.value.length > 10) detectionHistory.value = detectionHistory.value.slice(0,10)
}
function showHistoryRecord(record: any) {
startZone.value = record.startZoneId
endZone.value = record.endZoneId
selectedStartZone.value = allZones.value.find(z => z.id === record.startZoneId)
selectedEndZone.value = allZones.value.find(z => z.id === record.endZoneId)
connectivityResult.value = record.data
currentDetectionId.value = record.id
}
function clearSelection() { startZone.value = null; endZone.value = null; selectedStartZone.value = null; selectedEndZone.value = null; connectivityResult.value = null; currentDetectionId.value = null }
function clearHistory() { detectionHistory.value = []; currentDetectionId.value = null }
function showPathDetails() {
if (!connectivityResult.value || !connectivityResult.value.success) return
const pathDetails = connectivityResult.value.path.map((zone: any, index: number) => `${index+1}. ${zone.name} (${zone.type})`).join('\n')
ElMessageBox.alert(pathDetails, '路径详情', { confirmButtonText: '确定', customClass: 'path-details-dialog' })
}
function visualizePath() { if (warehouseViewerRef.value && warehouseViewerRef.value.showPath) warehouseViewerRef.value.showPath(connectivityResult.value.path) }
function zoomIn() { if (scale.value < maxScale.value) scale.value = Math.min(scale.value + 0.1, maxScale.value) }
function zoomOut() { if (scale.value > minScale.value) scale.value = Math.max(scale.value - 0.1, minScale.value) }
function resetView() { calculateInitialScale(warehouseData.value) }
function initEventListeners() {
handleWheelListener = (event: WheelEvent) => {
if (event.ctrlKey) { event.preventDefault(); const delta = event.deltaY > 0 ? -0.1 : 0.1; scale.value = Math.max(minScale.value, Math.min(maxScale.value, scale.value + delta)) }
}
window.addEventListener('wheel', handleWheelListener, { passive: false })
}
function removeEventListeners() { if (handleWheelListener) window.removeEventListener('wheel', handleWheelListener) }
function onShelfCellClick(data: any) { console.log('货架单元格点击:', data) }
function onAreaClick(data: any) { console.log('区域点击:', data) }
function onModeChange(mode: any) { console.log('模式变更:', mode) }
const submittingWarehouse = ref(false)
</script>
<style lang="scss" scoped>
.zone-management {
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
flex-direction: row;
padding: 16px;
box-sizing: border-box;
background: #f5f7fa;
.el-card__header {
height: 40px;
line-height: 40px;
padding: 0 20px;
}
.sidebar {
width: 320px;
height: 100%;
display: flex;
flex-direction: column;
.warehouse-card {
height: 300px;
margin-bottom: 16px;
display: flex;
flex-direction: column;
.warehouse-list {
flex: 1;
overflow: auto;
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
}
}
.zone-card {
flex: 1;
display: flex;
flex-direction: column;
.zone-tree {
flex: 1;
overflow: auto;
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
.tree-node-content {}
.tree-node-actions {}
&:hover .tree-node-actions {}
}
.empty-state {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #909399;
p {}
}
}
}
.connectivity-card {
flex: 1;
display: flex;
flex-direction: column;
.connectivity-content {
flex: 1;
display: flex;
flex-direction: column;
gap: 16px;
.zone-selectors {
display: flex;
flex-direction: column;
gap: 12px;
.zone-selector {}
}
.selected-zones {
display: flex;
flex-direction: column;
gap: 12px;
.selected-zone {}
}
.detection-actions {
display: flex;
gap: 8px;
justify-content: center;
}
.result-container {
.result-card {}
}
.history-container {
.history-header {}
.history-list {}
}
}
}
}
.main-content {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
margin: 0 16px;
.el-card__header {
display: flex;
justify-content: space-between;
align-items: center;
.view-controls {
display: flex;
align-items: center;
gap: 16px;
.scale-display {
font-size: 14px;
color: #666;
}
}
}
.el-card__body{
flex:1;
.viewer-container {
height:100%;
flex: 1;
min-height: 0;
position: relative;
background: #fff;
border-radius: 4px;
overflow: hidden;
}
}
}
}
.el-tree {
.el-tree-node__content {
height: 36px;
&:hover {
background-color: #f5f7fa;
}
}
.el-tree-node.is-current>.el-tree-node__content {
background-color: #ecf5ff;
.el-tree-node__label {
color: #409eff;
font-weight: 500;
}
}
}
.el-card {
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
border: 1px solid #ebeef5;
&:hover {
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}
}
.coordinate-section { margin-bottom: 20px; .el-card__header { padding: 12px 20px; background: #f8f9fa; } }
.path-details-dialog { .el-message-box__content { max-height: 400px; overflow-y: auto; white-space: pre-line; } }
</style>

View File

@ -0,0 +1,304 @@
<template>
<div class="rack-space-management">
<!-- 货架管理部分 -->
<div v-if="props.rack && props.rack.type === 'rack'" class="rack-management">
<el-card class="rack-info-card">
<template #header>
<span>货架信息</span>
</template>
<div class="rack-info-content">
<div class="info-item">
<span class="label">编码:</span>
<span class="value">{{ props.rack.code || props.rack.zone_code }}</span>
</div>
<div class="info-item">
<span class="label">名称:</span>
<span class="value">{{ props.rack.name || props.rack.zone_name }}</span>
</div>
<div class="info-item">
<span class="label">尺寸:</span>
<span class="value">{{ props.rack.data.length || 0 }} × {{ props.rack.data.width || 0 }} × {{ props.rack.data.height || 0 }} cm</span>
</div>
<div class="info-item">
<span class="label">仓位数量:</span>
<span class="value">{{ calculateRackTotal() }}</span>
</div>
</div>
</el-card>
</div>
<!-- 仓库/库区信息卡片 -->
<div v-else-if="props.warehouse || props.zone" class="info-display">
<!-- 仓库信息卡片 -->
<el-card v-if="props.warehouse && props.warehouse.id" class="warehouse-info-card">
<template #header>
<span>仓库信息</span>
<el-button type="text" size="small" @click="handleEditWarehouse" v-if="props.warehouse.editable">编辑</el-button>
</template>
<div class="warehouse-info-content">
<div class="info-item">
<span class="label">仓库编码:</span>
<span class="value">{{ props.warehouse.code || props.warehouse.zone_code }}</span>
</div>
<div class="info-item">
<span class="label">仓库名称:</span>
<span class="value">{{ props.warehouse.label }}</span>
</div>
<div class="info-item">
<span class="label">仓库尺寸:</span>
<span class="value">{{ props.warehouse.length || 0 }} × {{ props.warehouse.width || 0 }} × {{ props.warehouse.height || 0 }} cm</span>
</div>
<div class="info-item">
<span class="label">总面积:</span>
<span class="value">{{ calculateArea(props.warehouse) }} m²</span>
</div>
<!-- 仓库统计信息 -->
<div class="statistics-section">
<h4>统计信息</h4>
<el-row :gutter="20">
<el-col :span="12">
<div class="stat-item">
<div class="stat-label">库区数量</div>
<div class="stat-value">{{ props.warehouse.areaCount || 0 }}</div>
</div>
</el-col>
<el-col :span="12">
<div class="stat-item">
<div class="stat-label">货架数量</div>
<div class="stat-value">{{ props.warehouse.rackCount || 0 }}</div>
</div>
</el-col>
<el-col :span="12">
<div class="stat-item">
<div class="stat-label">总仓位</div>
<div class="stat-value">{{ props.warehouse.totalSpaces || 0 }}</div>
</div>
</el-col>
</el-row>
</div>
</div>
</el-card>
<!-- 库区信息卡片 -->
<el-card v-else-if="props.zone && props.zone.type === 'area'" class="zone-info-card">
<template #header>
<span>库区信息</span>
<el-button type="text" size="small" @click="handleEditZone" v-if="props.zone.editable">编辑</el-button>
</template>
<div class="zone-info-content">
<div class="info-item">
<span class="label">库区编码:</span>
<span class="value">{{ props.zone.code || props.zone.zone_code }}</span>
</div>
<div class="info-item">
<span class="label">库区名称:</span>
<span class="value">{{ props.zone.name || props.zone.zone_name }}</span>
</div>
<div class="info-item">
<span class="label">所属仓库:</span>
<span class="value">{{ props.zone.warehouseName || '未知' }}</span>
</div>
<div class="info-item">
<span class="label">库区尺寸:</span>
<span class="value">{{ props.zone.length || 0 }} × {{ props.zone.width || 0 }} × {{ props.zone.height || 0 }} cm</span>
</div>
<div class="info-item">
<span class="label">占地面积:</span>
<span class="value">{{ calculateArea(props.zone) }} m²</span>
</div>
<div class="info-item">
<span class="label">显示颜色:</span>
<span class="value color-preview" :style="{ backgroundColor: props.zone.color || '#3B82F6' }"></span>
</div>
<div class="info-item">
<span class="label">状态:</span>
<span class="value">
<el-tag :type="props.zone.is_active === 1 ? 'success' : 'info'" size="small">{{ props.zone.is_active === 1 ? '启用' : '停用' }}</el-tag>
</span>
</div>
<!-- 库区统计信息 -->
<div class="statistics-section">
<h4>库区统计</h4>
<el-row :gutter="20">
<el-col :span="12">
<div class="stat-item">
<div class="stat-label">货架数量</div>
<div class="stat-value">{{ props.zone.rackCount || 0 }}</div>
</div>
</el-col>
<el-col :span="12">
<div class="stat-item">
<div class="stat-label">拣货点数量</div>
<div class="stat-value">{{ props.zone.pickPointCount || 0 }}</div>
</div>
</el-col>
<el-col :span="24">
<div class="stat-item">
<div class="stat-label">总仓位数量</div>
<div class="stat-value">{{ props.zone.totalSpaces || 0 }}</div>
</div>
</el-col>
</el-row>
</div>
</div>
</el-card>
</div>
<!-- 空状态 -->
<div v-else class="empty-info">
<div class="empty-content">
<i class="el-icon-s-grid"></i>
<p>请选择仓库、库区或货架</p>
<p class="empty-hint">在左侧选择项目查看详细信息</p>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import * as warehouseApi from '@/api/warehouse'
const props = defineProps({
rack: { type: Object, default: null },
warehouse: { type: Object, default: null },
zone: { type: Object, default: null }
})
const emit = defineEmits([ 'edit-warehouse', 'edit-zone', 'edit-rack', 'edit-space', 'space-click', 'refresh' ])
const rackSpaces = ref<any[]>([])
const loading = ref(false)
watch(() => props.rack, (newVal) => {
if (newVal && newVal.type === 'rack') {
loadRackSpaces()
}
}, { immediate: true })
watch(() => props.warehouse, (newVal) => {
// 保持原行为
}, { immediate: true })
function rowStyle() { return { height: '40px' } }
function calculateRackTotal() {
if (!props.rack) return 0
const { rackColumns = 1, rackRows = 1, rackLevels = 1 } = props.rack.data || {}
return rackColumns * rackRows * rackLevels
}
function calculateVolume(item: any) {
const { length = 0, width = 0, height = 0 } = item || {}
const volume = (length * width * height) / 1000000
return volume.toFixed(2)
}
function calculateArea(item: any) {
const { length = 0, width = 0 } = item || {}
const area = (length * width) / 10000
return area.toFixed(2)
}
async function loadRackSpaces() {
if (!props.rack || props.rack.type !== 'rack') return
loading.value = true
try {
const response: any = await warehouseApi.getSpacesByRack(props.rack.id)
if (response.code === 200) {
rackSpaces.value = response.spaces || []
}
} catch (error) {
console.error('加载仓位失败:', error)
rackSpaces.value = []
} finally {
loading.value = false
}
}
function handleEditWarehouse() { emit('edit-warehouse', props.warehouse) }
function handleEditZone() { emit('edit-zone', props.zone) }
function handleEditRack() { emit('edit-rack', props.rack) }
async function handleAddSpace() {
if (!props.rack || props.rack.type !== 'rack') return
loading.value = true
try {
const response: any = await warehouseApi.createRackWithSpaces(props.rack.id)
if (response.code === 200) {
await loadRackSpaces()
}
} catch (error) {
console.error('创建仓位失败:', error)
} finally {
loading.value = false
}
}
function handleEditSpace(space: any) { emit('edit-space', space) }
function handleSpaceClick(space: any) { emit('space-click', space) }
function refresh() {
if (props.rack && props.rack.type === 'rack') loadRackSpaces()
emit('refresh')
}
</script>
<style scoped>
.rack-space-management {
display: flex;
flex-direction: column;
gap: 16px;
overflow-y: auto;
.el-card__header {
padding: 0;
height: 40px;
line-height: 40px;
padding-left: 20px;
font-weight: 400;
}
.el-card__body{
font-size: 14px;
}
.rack-management,
.info-display {
flex: 1;
display: flex;
flex-direction: column;
gap: 16px;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
color: #303133;
}
.zone-image-placeholder {
margin-top: 20px;
padding: 40px 20px;
text-align: center;
border: 1px dashed #dcdfe6;
border-radius: 4px;
background: #f5f7fa;
i {
font-size: 40px;
color: #c0c4cc;
margin-bottom: 12px;
}
p {
margin: 0;
color: #909399;
font-size: 14px;
}
}
}
</style>

File diff suppressed because it is too large Load Diff