feat(mes): 优化工作站模块,新增获取车间列表和车间 Map 方法,重构表单弹窗逻辑

pull/871/MERGE
YunaiV 2026-02-16 15:47:05 +08:00
parent 435496bdbd
commit b0548b329d
6 changed files with 144 additions and 106 deletions

View File

@ -1,7 +1,5 @@
import request from '@/config/axios'
// DONE @AI【遵守我说的】是不是每个 VO 独立文件;例如说 tool/ 、worker/、machine/ 等等
// MES 工作站 VO
export interface MdWorkstationVO {
id: number // 工作站编号

View File

@ -90,9 +90,9 @@ import { MdWorkstationApi, MdWorkstationVO } from '@/api/mes/md/workstation'
import { MdWorkshopApi, MdWorkshopVO } from '@/api/mes/md/workstation/workshop'
import { CommonStatusEnum } from '@/utils/constants'
import { generateRandomStr } from '@/utils'
import WorkstationMachinePanel from './components/WorkstationMachinePanel.vue'
import WorkstationToolPanel from './components/WorkstationToolPanel.vue'
import WorkstationWorkerPanel from './components/WorkstationWorkerPanel.vue'
import WorkstationMachinePanel from './WorkstationMachinePanel.vue'
import WorkstationToolPanel from './WorkstationToolPanel.vue'
import WorkstationWorkerPanel from './WorkstationWorkerPanel.vue'
defineOptions({ name: 'WorkstationForm' })

View File

@ -1,6 +1,6 @@
<template>
<div>
<el-button type="primary" plain size="small" @click="openAddForm" class="mb-10px">
<el-button type="primary" plain size="small" @click="openForm('create')" class="mb-10px">
<Icon icon="ep:plus" class="mr-5px" /> 添加设备
</el-button>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" border>
@ -16,8 +16,8 @@
</el-table>
<!-- 添加设备弹窗 -->
<Dialog title="添加设备" v-model="dialogVisible" width="500px">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px">
<Dialog :title="dialogTitle" v-model="dialogVisible" width="500px">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px" v-loading="formLoading">
<el-form-item label="设备" prop="machineryId">
<!-- TODO @芋艿对接设备下拉列表 DV 设备模块完成后对接 -->
<el-input-number
@ -39,7 +39,7 @@
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary"> </el-button>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
@ -53,7 +53,9 @@ const props = defineProps<{
workstationId: number //
}>()
const { t } = useI18n() //
const message = useMessage() //
const loading = ref(false) //
const list = ref<MdWorkstationMachineVO[]>([]) //
@ -69,8 +71,12 @@ const getList = async () => {
// ==================== ====================
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formType = ref('') // create - update -
const formLoading = ref(false) //
const formRef = ref() // Ref
const formData = ref({
id: undefined as number | undefined,
workstationId: undefined as number | undefined,
machineryId: undefined as number | undefined,
quantity: 1,
@ -81,10 +87,38 @@ const formRules = reactive({
quantity: [{ required: true, message: '数量不能为空', trigger: 'blur' }]
}) //
/** 打开添加弹窗 */
const openAddForm = () => {
/** 打开表单弹窗 */
const openForm = (type: string) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
}
/** 提交表单 */
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as unknown as MdWorkstationMachineVO
await MdWorkstationMachineApi.createWorkstationMachine(data)
message.success(t('common.createSuccess'))
dialogVisible.value = false
//
await getList()
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
workstationId: props.workstationId,
machineryId: undefined,
quantity: 1,
@ -93,17 +127,6 @@ const openAddForm = () => {
formRef.value?.resetFields()
}
/** 提交表单 */
const submitForm = async () => {
await formRef.value.validate()
await MdWorkstationMachineApi.createWorkstationMachine(
formData.value as unknown as MdWorkstationMachineVO
)
message.success('添加成功')
dialogVisible.value = false
await getList()
}
/** 删除 */
const handleDelete = async (id: number) => {
try {
@ -114,7 +137,6 @@ const handleDelete = async (id: number) => {
} catch {}
}
/** 监听 workstationId 变化 */
watch(
() => props.workstationId,
(val) => {

View File

@ -1,6 +1,6 @@
<template>
<div>
<el-button type="primary" plain size="small" @click="openAddForm" class="mb-10px">
<el-button type="primary" plain size="small" @click="openForm('create')" class="mb-10px">
<Icon icon="ep:plus" class="mr-5px" /> 添加工具
</el-button>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" border>
@ -10,7 +10,7 @@
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" width="120">
<template #default="scope">
<el-button link type="primary" @click="openEditForm(scope.row)"></el-button>
<el-button link type="primary" @click="openForm('update', scope.row)">编辑</el-button>
<el-button link type="danger" @click="handleDelete(scope.row.id)"></el-button>
</template>
</el-table-column>
@ -18,7 +18,13 @@
<!-- 添加/编辑弹窗 -->
<Dialog :title="dialogTitle" v-model="dialogVisible" width="500px">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="80px"
v-loading="formLoading"
>
<el-form-item label="工具类型" prop="toolTypeId">
<!-- TODO @芋艿对接工具类型下拉列表 TM 工具模块完成后对接 -->
<el-input-number
@ -41,7 +47,7 @@
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary"> </el-button>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
@ -55,7 +61,9 @@ const props = defineProps<{
workstationId: number //
}>()
const { t } = useI18n() //
const message = useMessage() //
const loading = ref(false) //
const list = ref<MdWorkstationToolVO[]>([]) //
@ -73,6 +81,7 @@ const getList = async () => {
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formType = ref('') // create - update -
const formLoading = ref(false) //
const formRef = ref() // Ref
const formData = ref({
id: undefined as number | undefined,
@ -86,12 +95,45 @@ const formRules = reactive({
quantity: [{ required: true, message: '数量不能为空', trigger: 'blur' }]
}) //
/** 打开添加弹窗 */
// TODO @AI openFormresetForm formType
const openAddForm = () => {
/** 打开表单弹窗 */
const openForm = (type: string, row?: MdWorkstationToolVO) => {
dialogVisible.value = true
dialogTitle.value = '添加工具'
formType.value = 'create'
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (type === 'update' && row) {
formData.value = { ...row }
}
}
/** 提交表单 */
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as unknown as MdWorkstationToolVO
if (formType.value === 'create') {
await MdWorkstationToolApi.createWorkstationTool(data)
message.success(t('common.updateSuccess'))
} else {
await MdWorkstationToolApi.updateWorkstationTool(data)
message.success(t('common.createSuccess'))
}
dialogVisible.value = false
//
await getList()
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
workstationId: props.workstationId,
@ -102,33 +144,6 @@ const openAddForm = () => {
formRef.value?.resetFields()
}
/** 打开编辑弹窗 */
const openEditForm = (row: MdWorkstationToolVO) => {
dialogVisible.value = true
dialogTitle.value = '编辑工具'
formType.value = 'update'
formData.value = { ...row }
}
/** 提交表单 */
const submitForm = async () => {
// TODO @AI loading
await formRef.value.validate()
if (formType.value === 'update') {
await MdWorkstationToolApi.updateWorkstationTool(
formData.value as unknown as MdWorkstationToolVO
)
message.success('编辑成功')
} else {
await MdWorkstationToolApi.createWorkstationTool(
formData.value as unknown as MdWorkstationToolVO
)
message.success('添加成功')
}
dialogVisible.value = false
await getList()
}
/** 删除 */
const handleDelete = async (id: number) => {
try {

View File

@ -1,6 +1,6 @@
<template>
<div>
<el-button type="primary" plain size="small" @click="openAddForm" class="mb-10px">
<el-button type="primary" plain size="small" @click="openForm('create')" class="mb-10px">
<Icon icon="ep:plus" class="mr-5px" /> 添加人员
</el-button>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" border>
@ -10,7 +10,7 @@
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" width="120">
<template #default="scope">
<el-button link type="primary" @click="openEditForm(scope.row)"></el-button>
<el-button link type="primary" @click="openForm('update', scope.row)">编辑</el-button>
<el-button link type="danger" @click="handleDelete(scope.row.id)"></el-button>
</template>
</el-table-column>
@ -18,13 +18,12 @@
<!-- 添加/编辑弹窗 -->
<Dialog :title="dialogTitle" v-model="dialogVisible" width="500px">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px" v-loading="formLoading">
<el-form-item label="岗位" prop="postId">
<el-select
v-model="formData.postId"
placeholder="请选择岗位"
class="!w-1/1"
:disabled="formType === 'update'"
>
<el-option
v-for="post in postList"
@ -47,7 +46,7 @@
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary"> </el-button>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
@ -62,7 +61,9 @@ const props = defineProps<{
workstationId: number //
}>()
const { t } = useI18n() //
const message = useMessage() //
const loading = ref(false) //
const list = ref<MdWorkstationWorkerVO[]>([]) //
const postList = ref<PostApi.PostVO[]>([]) //
@ -81,6 +82,7 @@ const getList = async () => {
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formType = ref('') // create - update -
const formLoading = ref(false) //
const formRef = ref() // Ref
const formData = ref({
id: undefined as number | undefined,
@ -94,15 +96,47 @@ const formRules = reactive({
quantity: [{ required: true, message: '数量不能为空', trigger: 'blur' }]
}) //
// TODO @AI openFormresetForm formType
/** 打开添加弹窗 */
const openAddForm = async () => {
/** 打开表单弹窗 */
const openForm = async (type: string, row?: MdWorkstationWorkerVO) => {
dialogVisible.value = true
dialogTitle.value = '添加人员'
formType.value = 'create'
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
postList.value = await PostApi.getSimplePostList()
//
if (type === 'update' && row) {
formData.value = { ...row }
}
}
/** 提交表单 */
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as unknown as MdWorkstationWorkerVO
if (formType.value === 'create') {
await MdWorkstationWorkerApi.createWorkstationWorker(data)
message.success(t('common.createSuccess'))
} else {
await MdWorkstationWorkerApi.updateWorkstationWorker(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
await getList()
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
workstationId: props.workstationId,
@ -113,35 +147,6 @@ const openAddForm = async () => {
formRef.value?.resetFields()
}
/** 打开编辑弹窗 */
const openEditForm = async (row: MdWorkstationWorkerVO) => {
dialogVisible.value = true
dialogTitle.value = '编辑人员'
formType.value = 'update'
//
postList.value = await PostApi.getSimplePostList()
formData.value = { ...row }
}
/** 提交表单 */
const submitForm = async () => {
// TODO @AI loading
await formRef.value.validate()
if (formType.value === 'update') {
await MdWorkstationWorkerApi.updateWorkstationWorker(
formData.value as unknown as MdWorkstationWorkerVO
)
message.success('编辑成功')
} else {
await MdWorkstationWorkerApi.createWorkstationWorker(
formData.value as unknown as MdWorkstationWorkerVO
)
message.success('添加成功')
}
dialogVisible.value = false
await getList()
}
/** 删除 */
const handleDelete = async (id: number) => {
try {

View File

@ -77,15 +77,13 @@
<!-- 列表 -->
<ContentWrap>
<!-- @AI宽度的设置有问题参考下别的模块已对齐列宽 -->
<!-- @AI我指的是你这么写宽度占不满屏幕 -->
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="工作站编码" align="center" prop="code" width="120" />
<el-table-column label="工作站名称" align="center" prop="name" width="150" />
<el-table-column label="工作站地点" align="center" prop="address" width="150" />
<el-table-column label="所在车间" align="center" prop="workshopName" width="120" />
<el-table-column label="工作站编码" align="center" prop="code" min-width="120" />
<el-table-column label="工作站名称" align="center" prop="name" min-width="150" />
<el-table-column label="工作站地点" align="center" prop="address" min-width="150" />
<el-table-column label="所在车间" align="center" prop="workshopName" min-width="120" />
<!-- TODO @芋艿所属工序等工序模块完成后对接 -->
<el-table-column label="状态" align="center" prop="status" width="100">
<el-table-column label="状态" align="center" prop="status" min-width="100">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>