From 5289b8b3bdc3cd06325a06ca7b2ef8becc274db8 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 18 Feb 2026 09:07:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20style(mes/wm):=20=E5=AF=B9?= =?UTF-8?q?=E9=BD=90=E6=B3=A8=E9=87=8A=E9=A3=8E=E6=A0=BC=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20TODO=E3=80=81=E9=87=8D=E6=9E=84=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - warehouse/index.vue:补充变量行内注释;将 chargeUserId 展示内联到模板 - WarehouseForm.vue:删除非标准 DONE @AI 注释;补充变量注释、defineExpose/defineEmits 注释、submitForm 步骤注释 - location/index.vue:补充变量行内注释;修复 warehouseId 类型;使用具名路由跳转 - location/LocationForm.vue:补充注释;修复 warehouseId 类型;补充新增时默认值注释 - area/index.vue:合并 parseQueryId 到 loadLocationContext;将 4 个散 ref 合并为 currentLocation 对象;补充变量行内注释 - area/AreaForm.vue:修复 locationId 类型;简化 open 方法中逐字段赋值为直接赋值;补充注释 - md/workstation/WorkstationForm.vue:补充 JSDoc 注释、变量注释、submitForm 步骤注释 Co-Authored-By: Claude Sonnet 4.6 --- .../mes/md/workstation/WorkstationForm.vue | 112 +++++++++++++++++- src/views/mes/wm/warehouse/WarehouseForm.vue | 31 ++--- src/views/mes/wm/warehouse/area/AreaForm.vue | 52 ++++---- src/views/mes/wm/warehouse/area/index.vue | 59 ++++----- src/views/mes/wm/warehouse/index.vue | 35 +++--- .../wm/warehouse/location/LocationForm.vue | 33 +++--- src/views/mes/wm/warehouse/location/index.vue | 24 ++-- 7 files changed, 216 insertions(+), 130 deletions(-) diff --git a/src/views/mes/md/workstation/WorkstationForm.vue b/src/views/mes/md/workstation/WorkstationForm.vue index ef07b3682..b90443bd7 100644 --- a/src/views/mes/md/workstation/WorkstationForm.vue +++ b/src/views/mes/md/workstation/WorkstationForm.vue @@ -43,7 +43,63 @@ - + + + + + + + + + + + + + + + + + + + + + + + @@ -88,6 +144,9 @@ import { getIntDictOptions, DICT_TYPE } from '@/utils/dict' import { MdWorkstationApi, MdWorkstationVO } from '@/api/mes/md/workstation' import { MdWorkshopApi, MdWorkshopVO } from '@/api/mes/md/workstation/workshop' +import { WmWarehouseApi, WmWarehouseVO } from '@/api/mes/wm/warehouse' +import { WmWarehouseLocationApi, WmWarehouseLocationVO } from '@/api/mes/wm/warehouse/location' +import { WmWarehouseAreaApi, WmWarehouseAreaVO } from '@/api/mes/wm/warehouse/area' import { CommonStatusEnum } from '@/utils/constants' import { generateRandomStr } from '@/utils' import WorkstationMachinePanel from './WorkstationMachinePanel.vue' @@ -105,6 +164,9 @@ const formLoading = ref(false) // 表单的加载中:1)修改时的数据加 const formType = ref('') // 表单的类型:create - 新增;update - 修改 const activeTab = ref('machine') // 当前激活的资源 Tab const workshopList = ref([]) // 车间下拉列表 +const warehouseList = ref([]) // 仓库下拉列表 +const locationList = ref([]) // 库区下拉列表 +const areaList = ref([]) // 库位下拉列表 const formData = ref({ id: undefined, code: undefined, @@ -124,13 +186,45 @@ const formRules = reactive({ workshopId: [{ required: true, message: '所在车间不能为空', trigger: 'change' }], status: [{ required: true, message: '状态不能为空', trigger: 'blur' }] }) // 表单校验规则 -const formRef = ref() +const formRef = ref() // 表单 Ref /** 生成工作站编码 */ const generateCode = () => { formData.value.code = 'WS' + generateRandomStr(12) } +/** 加载库区列表 */ +const loadLocationList = async (warehouseId?: number) => { + if (!warehouseId) { + locationList.value = [] + return + } + locationList.value = await WmWarehouseLocationApi.getWarehouseLocationSimpleList(warehouseId) +} + +/** 加载库位列表 */ +const loadAreaList = async (locationId?: number) => { + if (!locationId) { + areaList.value = [] + return + } + areaList.value = await WmWarehouseAreaApi.getWarehouseAreaSimpleList(locationId) +} + +/** 仓库改变时,重置库区和库位 */ +const handleWarehouseChange = async (warehouseId?: number) => { + formData.value.locationId = undefined + formData.value.areaId = undefined + areaList.value = [] + await loadLocationList(warehouseId) +} + +/** 库区改变时,重置库位 */ +const handleLocationChange = async (locationId?: number) => { + formData.value.areaId = undefined + await loadAreaList(locationId) +} + /** 打开弹窗 */ const open = async (type: string, id?: number) => { dialogVisible.value = true @@ -139,22 +233,29 @@ const open = async (type: string, id?: number) => { resetForm() // 加载车间列表 workshopList.value = await MdWorkshopApi.getWorkshopSimpleList() + // 加载仓库列表 + warehouseList.value = await WmWarehouseApi.getWarehouseSimpleList() // 修改时,设置数据 if (id) { formLoading.value = true try { formData.value = await MdWorkstationApi.getWorkstation(id) + // 加载库区和库位列表(因为修改时会回显仓库和库区,所以需要加载对应的列表) + await loadLocationList(formData.value.warehouseId) + await loadAreaList(formData.value.locationId) } finally { formLoading.value = false } } } -defineExpose({ open }) +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 /** 提交表单 */ -const emit = defineEmits(['success']) +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 const submitForm = async () => { + // 校验表单 await formRef.value.validate() + // 提交请求 formLoading.value = true try { const data = formData.value as unknown as MdWorkstationVO @@ -166,6 +267,7 @@ const submitForm = async () => { message.success(t('common.updateSuccess')) } dialogVisible.value = false + // 发送操作成功的事件 emit('success') } finally { formLoading.value = false @@ -187,6 +289,8 @@ const resetForm = () => { status: CommonStatusEnum.ENABLE, remark: undefined } + locationList.value = [] + areaList.value = [] formRef.value?.resetFields() } diff --git a/src/views/mes/wm/warehouse/WarehouseForm.vue b/src/views/mes/wm/warehouse/WarehouseForm.vue index 498cacce8..ffdfccd4d 100644 --- a/src/views/mes/wm/warehouse/WarehouseForm.vue +++ b/src/views/mes/wm/warehouse/WarehouseForm.vue @@ -9,7 +9,6 @@ > - @@ -71,7 +70,6 @@ @@ -84,14 +82,14 @@ import * as UserApi from '@/api/system/user' defineOptions({ name: 'WarehouseForm' }) -const { t } = useI18n() -const message = useMessage() +const { t } = useI18n() // 国际化 +const message = useMessage() // 消息弹窗 -const dialogVisible = ref(false) -const dialogTitle = ref('') -const formLoading = ref(false) -const formType = ref('') -const userList = ref([]) +const dialogVisible = ref(false) // 弹窗的是否展示 +const dialogTitle = ref('') // 弹窗的标题 +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 +const formType = ref('') // 表单的类型:create - 新增;update - 修改 +const userList = ref([]) // 用户列表 const formData = ref({ id: undefined, code: undefined, @@ -101,13 +99,13 @@ const formData = ref({ chargeUserId: undefined, frozen: false, remark: undefined -}) +}) // 表单数据 const formRules = reactive({ code: [{ required: true, message: '仓库编码不能为空', trigger: 'blur' }], name: [{ required: true, message: '仓库名称不能为空', trigger: 'blur' }], frozen: [{ required: true, message: '是否冻结不能为空', trigger: 'change' }] -}) -const formRef = ref() +}) // 表单校验规则 +const formRef = ref() // 表单 Ref /** 打开弹窗 */ const open = async (type: string, id?: number) => { @@ -115,7 +113,9 @@ const open = async (type: string, id?: number) => { dialogTitle.value = t('action.' + type) formType.value = type resetForm() + // 加载用户列表 userList.value = await UserApi.getSimpleUserList() + // 修改时,设置数据 if (id) { formLoading.value = true try { @@ -125,12 +125,14 @@ const open = async (type: string, id?: number) => { } } } -defineExpose({ open }) +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 /** 提交表单 */ -const emit = defineEmits(['success']) +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 const submitForm = async () => { + // 校验表单 await formRef.value.validate() + // 提交请求 formLoading.value = true try { const data = formData.value as unknown as WmWarehouseVO @@ -142,6 +144,7 @@ const submitForm = async () => { message.success(t('common.updateSuccess')) } dialogVisible.value = false + // 发送操作成功的事件 emit('success') } finally { formLoading.value = false diff --git a/src/views/mes/wm/warehouse/area/AreaForm.vue b/src/views/mes/wm/warehouse/area/AreaForm.vue index 960b695aa..fdcf54d10 100644 --- a/src/views/mes/wm/warehouse/area/AreaForm.vue +++ b/src/views/mes/wm/warehouse/area/AreaForm.vue @@ -156,21 +156,21 @@ import { WmWarehouseAreaApi, WmWarehouseAreaVO } from '@/api/mes/wm/warehouse/ar defineOptions({ name: 'AreaForm' }) -const { t } = useI18n() -const message = useMessage() +const { t } = useI18n() // 国际化 +const message = useMessage() // 消息弹窗 -const dialogVisible = ref(false) -const dialogTitle = ref('') -const formLoading = ref(false) -const formType = ref('') -const selectedWarehouseId = ref(undefined) -const warehouseList = ref([]) -const locationList = ref([]) +const dialogVisible = ref(false) // 弹窗的是否展示 +const dialogTitle = ref('') // 弹窗的标题 +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 +const formType = ref('') // 表单的类型:create - 新增;update - 修改 +const selectedWarehouseId = ref(undefined) // 当前选中的仓库 ID +const warehouseList = ref([]) // 仓库列表 +const locationList = ref([]) // 库区列表 const formData = ref({ id: undefined, code: undefined, name: undefined, - locationId: undefined, + locationId: undefined as number | undefined, area: undefined, maxLoad: undefined, positionX: undefined, @@ -191,7 +191,7 @@ const formRules = reactive({ allowItemMixing: [{ required: true, message: '物料混放开关不能为空', trigger: 'change' }], allowBatchMixing: [{ required: true, message: '批次混放开关不能为空', trigger: 'change' }] }) -const formRef = ref() +const formRef = ref() // 表单 Ref /** 加载库区列表 */ const loadLocationList = async (warehouseId?: number) => { @@ -215,39 +215,25 @@ const open = async ( defaultLocationId?: number, defaultWarehouseId?: number ) => { - // TODO @AI:注释的风格,参考下别的模块的 form; dialogVisible.value = true dialogTitle.value = t('action.' + type) formType.value = type resetForm() warehouseList.value = await WmWarehouseApi.getWarehouseSimpleList() + // 修改时,设置数据 if (id) { formLoading.value = true try { const data = await WmWarehouseAreaApi.getWarehouseArea(id) selectedWarehouseId.value = data.warehouseId await loadLocationList(selectedWarehouseId.value) - formData.value = { - id: data.id, - code: data.code, - name: data.name, - locationId: data.locationId, - area: data.area, - maxLoad: data.maxLoad, - positionX: data.positionX, - positionY: data.positionY, - positionZ: data.positionZ, - enabled: data.enabled, - frozen: data.frozen, - allowItemMixing: data.allowItemMixing, - allowBatchMixing: data.allowBatchMixing, - remark: data.remark - } + formData.value = data } finally { formLoading.value = false } return } + // 新增时,设置默认仓库和库区(从列表页跳转过来时传入) if (defaultWarehouseId) { selectedWarehouseId.value = defaultWarehouseId await loadLocationList(defaultWarehouseId) @@ -258,16 +244,17 @@ const open = async ( selectedWarehouseId.value = location.warehouseId await loadLocationList(selectedWarehouseId.value) } - // TODO @linter:修复 formData.value.locationId = defaultLocationId } } -defineExpose({ open }) +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 /** 提交表单 */ -const emit = defineEmits(['success']) +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 const submitForm = async () => { + // 校验表单 await formRef.value.validate() + // 提交请求 formLoading.value = true try { const data = formData.value as unknown as WmWarehouseAreaVO @@ -279,6 +266,7 @@ const submitForm = async () => { message.success(t('common.updateSuccess')) } dialogVisible.value = false + // 发送操作成功的事件 emit('success') } finally { formLoading.value = false @@ -293,7 +281,7 @@ const resetForm = () => { id: undefined, code: undefined, name: undefined, - locationId: undefined, + locationId: undefined as number | undefined, area: undefined, maxLoad: undefined, positionX: undefined, diff --git a/src/views/mes/wm/warehouse/area/index.vue b/src/views/mes/wm/warehouse/area/index.vue index 97f2e41f6..c9bc4bd8e 100644 --- a/src/views/mes/wm/warehouse/area/index.vue +++ b/src/views/mes/wm/warehouse/area/index.vue @@ -1,8 +1,8 @@