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 @@
([])
-const total = ref(0)
-const currentWarehouseId = ref(undefined)
-const currentWarehouseName = ref('')
-const currentLocationId = ref(undefined)
-const currentLocationName = ref('')
+const loading = ref(true) // 列表的加载中
+const list = ref([]) // 列表的数据
+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 @AI:linter 报错
+ 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)
}
/** 删除按钮操作 */
diff --git a/src/views/mes/wm/warehouse/index.vue b/src/views/mes/wm/warehouse/index.vue
index 17aab71d9..4a43dd641 100644
--- a/src/views/mes/wm/warehouse/index.vue
+++ b/src/views/mes/wm/warehouse/index.vue
@@ -54,7 +54,11 @@
- {{ getChargeUserName(scope.row.chargeUserId) }}
+ {{
+ scope.row.chargeUserId
+ ? userList.find((user) => user.id === scope.row.chargeUserId)?.nickname || '-'
+ : '-'
+ }}
@@ -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([])
-const userList = ref([])
-const total = ref(0)
+const loading = ref(true) // 列表的加载中
+const list = ref([]) // 列表的数据
+const userList = ref([]) // 用户列表
+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 @AI:直接在上面的模块,渲染;html 里;
-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) }
})
}
diff --git a/src/views/mes/wm/warehouse/location/LocationForm.vue b/src/views/mes/wm/warehouse/location/LocationForm.vue
index 94931e8ee..e3964b16b 100644
--- a/src/views/mes/wm/warehouse/location/LocationForm.vue
+++ b/src/views/mes/wm/warehouse/location/LocationForm.vue
@@ -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([])
+const dialogVisible = ref(false) // 弹窗的是否展示
+const dialogTitle = ref('') // 弹窗的标题
+const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
+const formType = ref('') // 表单的类型:create - 新增;update - 修改
+const warehouseList = ref([]) // 仓库列表
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,
diff --git a/src/views/mes/wm/warehouse/location/index.vue b/src/views/mes/wm/warehouse/location/index.vue
index d1ca2d6b6..2c54552fb 100644
--- a/src/views/mes/wm/warehouse/location/index.vue
+++ b/src/views/mes/wm/warehouse/location/index.vue
@@ -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([])
-const total = ref(0)
+const loading = ref(true) // 列表的加载中
+const list = ref([]) // 列表的数据
+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)
}