🎨 style(mes/wm): 对齐注释风格、修复 TODO、重构冗余代码

- 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 <noreply@anthropic.com>
pull/871/MERGE
YunaiV 2026-02-18 09:07:29 +08:00
parent 47fd8b6018
commit 5289b8b3bd
7 changed files with 216 additions and 130 deletions

View File

@ -43,7 +43,63 @@
<el-input v-model="formData.address" placeholder="请输入工作站地点" />
</el-form-item>
</el-col>
<!-- TODO @芋艿所属工序等工序模块完成后对接 -->
<el-col :span="8">
<el-form-item label="线边库" prop="warehouseId">
<el-select
v-model="formData.warehouseId"
placeholder="请选择线边库"
clearable
class="!w-1/1"
@change="handleWarehouseChange"
>
<el-option
v-for="warehouse in warehouseList"
:key="warehouse.id"
:label="warehouse.name"
:value="warehouse.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="库区" prop="locationId">
<el-select
v-model="formData.locationId"
placeholder="请选择库区"
clearable
class="!w-1/1"
:disabled="!formData.warehouseId"
@change="handleLocationChange"
>
<el-option
v-for="location in locationList"
:key="location.id"
:label="location.name"
:value="location.id"
/>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item label="库位" prop="areaId">
<el-select
v-model="formData.areaId"
placeholder="请选择库位"
clearable
class="!w-1/1"
:disabled="!formData.locationId"
>
<el-option
v-for="area in areaList"
:key="area.id"
:label="area.name"
:value="area.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
@ -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<MdWorkshopVO[]>([]) //
const warehouseList = ref<WmWarehouseVO[]>([]) //
const locationList = ref<WmWarehouseLocationVO[]>([]) //
const areaList = ref<WmWarehouseAreaVO[]>([]) //
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()
}
</script>

View File

@ -9,7 +9,6 @@
>
<el-row>
<el-col :span="8">
<!-- DONE @AI字段布局按 WM 表单统一为三列 -->
<el-form-item label="仓库编码" prop="code">
<el-input v-model="formData.code" placeholder="请输入仓库编码" />
</el-form-item>
@ -71,7 +70,6 @@
</el-row>
</el-form>
<template #footer>
<!-- DONE @AI本版不接入条码预览保留简化弹窗操作区 -->
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
@ -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<UserApi.UserVO[]>([])
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const userList = ref<UserApi.UserVO[]>([]) //
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

View File

@ -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<number | undefined>(undefined)
const warehouseList = ref<WmWarehouseVO[]>([])
const locationList = ref<WmWarehouseLocationVO[]>([])
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const selectedWarehouseId = ref<number | undefined>(undefined) // ID
const warehouseList = ref<WmWarehouseVO[]>([]) //
const locationList = ref<WmWarehouseLocationVO[]>([]) //
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,

View File

@ -1,8 +1,8 @@
<template>
<ContentWrap>
<el-alert
v-if="currentLocationId"
:title="`当前仓库/库区:${currentWarehouseName || `#${currentWarehouseId || '-'}`} / ${currentLocationName || `#${currentLocationId}`}`"
v-if="currentLocation.id"
:title="`当前仓库/库区:${currentLocation.warehouseName || `#${currentLocation.warehouseId || '-'}`} / ${currentLocation.name || `#${currentLocation.id}`}`"
type="info"
show-icon
:closable="false"
@ -140,51 +140,44 @@ import AreaForm from './AreaForm.vue'
defineOptions({ name: 'MesWmArea' })
const message = useMessage()
const { t } = useI18n()
const message = useMessage() //
const { t } = useI18n() //
const route = useRoute()
const loading = ref(true)
const list = ref<WmWarehouseAreaVO[]>([])
const total = ref(0)
const currentWarehouseId = ref<number | undefined>(undefined)
const currentWarehouseName = ref('')
const currentLocationId = ref<number | undefined>(undefined)
const currentLocationName = ref('')
const loading = ref(true) //
const list = ref<WmWarehouseAreaVO[]>([]) //
const total = ref(0) //
const currentLocation = ref<{ id: number; name: string; warehouseId: number; warehouseName: string }>({
id: 0,
name: '',
warehouseId: 0,
warehouseName: ''
}) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
code: undefined,
name: undefined,
locationId: undefined,
locationId: undefined as number | undefined,
positionX: undefined,
positionY: undefined,
positionZ: undefined
})
const queryFormRef = ref()
const parseQueryId = (queryValue: string | string[] | null | undefined): number | undefined => {
const value = Array.isArray(queryValue) ? queryValue[0] : queryValue
if (!value) {
return undefined
}
const id = Number(value)
return Number.isInteger(id) && id > 0 ? id : undefined
}
}) //
const queryFormRef = ref() // Ref
/** 加载库区上下文(从 URL query 参数获取 locationId并加载库区和仓库名称 */
const loadLocationContext = async () => {
const locationId = parseQueryId(route.query.locationId as string | string[] | undefined)
if (!locationId) {
const locationId = Number(route.query.locationId)
if (!Number.isInteger(locationId) || locationId <= 0) {
return
}
currentLocationId.value = locationId
// TODO @AIlinter
currentLocation.value.id = locationId
queryParams.locationId = locationId
try {
const location = await WmWarehouseLocationApi.getWarehouseLocation(locationId)
currentLocationName.value = location.name
currentWarehouseId.value = location.warehouseId
currentWarehouseName.value = location.warehouseName
currentLocation.value.name = location.name
currentLocation.value.warehouseId = location.warehouseId
currentLocation.value.warehouseName = location.warehouseName
} catch {
//
}
@ -211,14 +204,14 @@ const handleQuery = () => {
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
queryParams.locationId = currentLocationId.value
queryParams.locationId = currentLocation.value.id || undefined
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const formRef = ref() // Ref
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id, currentLocationId.value, currentWarehouseId.value)
formRef.value.open(type, id, currentLocation.value.id || undefined, currentLocation.value.warehouseId || undefined)
}
/** 删除按钮操作 */

View File

@ -54,7 +54,11 @@
<el-table-column label="面积(㎡)" align="center" prop="area" min-width="100" />
<el-table-column label="负责人" align="center" prop="chargeUserId" min-width="100">
<template #default="scope">
{{ getChargeUserName(scope.row.chargeUserId) }}
{{
scope.row.chargeUserId
? userList.find((user) => user.id === scope.row.chargeUserId)?.nickname || '-'
: '-'
}}
</template>
</el-table-column>
<el-table-column label="冻结" align="center" prop="frozen" min-width="80">
@ -119,36 +123,28 @@ import WarehouseForm from './WarehouseForm.vue'
defineOptions({ name: 'MesWmWarehouse' })
const message = useMessage()
const { t } = useI18n()
const message = useMessage() //
const { t } = useI18n() //
const router = useRouter()
const loading = ref(true)
const list = ref<WmWarehouseVO[]>([])
const userList = ref<UserApi.UserVO[]>([])
const total = ref(0)
const loading = ref(true) //
const list = ref<WmWarehouseVO[]>([]) //
const userList = ref<UserApi.UserVO[]>([]) //
const total = ref(0) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
code: undefined,
name: undefined,
frozen: undefined
})
const queryFormRef = ref()
}) //
const queryFormRef = ref() // Ref
/** 加载用户列表 */
const loadUserList = async () => {
userList.value = await UserApi.getSimpleUserList()
}
// TODO @AIhtml
const getChargeUserName = (userId?: number) => {
if (!userId) {
return '-'
}
return userList.value.find((user) => user.id === userId)?.nickname || '-'
}
/** 查询列表 */
const getList = async () => {
loading.value = true
@ -174,16 +170,15 @@ const resetQuery = () => {
}
/** 添加/修改操作 */
const formRef = ref()
const formRef = ref() // Ref
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 打开库区页面 */
const openLocation = (warehouseId: number) => {
// TODO @AI使 name
router.push({
path: '/mes/wm/warehouse/location',
name: 'MesWmLocation',
query: { warehouseId: String(warehouseId) }
})
}

View File

@ -73,20 +73,19 @@ import { WmWarehouseLocationApi, WmWarehouseLocationVO } from '@/api/mes/wm/ware
defineOptions({ name: 'LocationForm' })
// TODO @AI仿
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 warehouseList = ref<WmWarehouseVO[]>([])
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const warehouseList = ref<WmWarehouseVO[]>([]) //
const formData = ref({
id: undefined,
code: undefined,
name: undefined,
warehouseId: undefined,
warehouseId: undefined as number | undefined,
area: undefined,
areaEnabled: true,
frozen: false,
@ -98,16 +97,16 @@ const formRules = reactive({
warehouseId: [{ required: true, message: '所属仓库不能为空', trigger: 'change' }],
frozen: [{ required: true, message: '是否冻结不能为空', trigger: 'change' }]
})
const formRef = ref()
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: 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 {
@ -117,18 +116,19 @@ const open = async (type: string, id?: number, defaultWarehouseId?: number) => {
}
return
}
// TODO @linter
//
if (defaultWarehouseId) {
formData.value.warehouseId = defaultWarehouseId
}
}
defineExpose({ open })
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success'])
const emit = defineEmits(['success']) // success
const submitForm = async () => {
// TODO @AI form
//
await formRef.value.validate()
//
formLoading.value = true
try {
const data = formData.value as unknown as WmWarehouseLocationVO
@ -140,6 +140,7 @@ const submitForm = async () => {
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
@ -152,7 +153,7 @@ const resetForm = () => {
id: undefined,
code: undefined,
name: undefined,
warehouseId: undefined,
warehouseId: undefined as number | undefined,
area: undefined,
areaEnabled: true,
frozen: false,

View File

@ -115,26 +115,28 @@ import LocationForm from './LocationForm.vue'
defineOptions({ name: 'MesWmLocation' })
const message = useMessage()
const { t } = useI18n()
const message = useMessage() //
const { t } = useI18n() //
const router = useRouter()
const route = useRoute()
const loading = ref(true)
const list = ref<WmWarehouseLocationVO[]>([])
const total = ref(0)
const loading = ref(true) //
const list = ref<WmWarehouseLocationVO[]>([]) //
const total = ref(0) //
const currentWarehouse = ref<{ id: number; name: string }>({
id: 0,
name: ''
})
}) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
code: undefined,
name: undefined,
warehouseId: undefined
})
const queryFormRef = ref()
warehouseId: undefined as number | undefined
}) //
const queryFormRef = ref() // Ref
/** 加载仓库上下文(从 URL query 参数获取 warehouseId并加载仓库名称 */
const loadWarehouseContext = async () => {
const warehouseId = Number(route.query.warehouseId)
if (!Number.isInteger(warehouseId) || warehouseId <= 0) {
@ -178,13 +180,13 @@ const resetQuery = () => {
/** 打开库位页面 */
const openArea = (locationId: number) => {
router.push({
path: '/mes/wm/warehouse/area',
name: 'MesWmArea',
query: { locationId: String(locationId) }
})
}
/** 添加/修改操作 */
const formRef = ref()
const formRef = ref() // Ref
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id, currentWarehouse.value.id || undefined)
}