refactor(mes-tm): 工具管理前端枚举优化

1. 新增 MesToolStatusEnum、MesMaintenTypeEnum 到 mes/utils/constants.ts
2. ToolForm、ToolTypeForm、index 页面使用枚举常量替代魔法值
3. 移除 as unknown as 类型断言,移除 TODO @AI 注释
pull/871/MERGE
YunaiV 2026-02-16 22:30:15 +08:00
parent b15cd9021e
commit d6a4857f6f
5 changed files with 50 additions and 51 deletions

View File

@ -64,7 +64,7 @@
<el-form-item <el-form-item
label="下次保养日期" label="下次保养日期"
prop="nextMaintenDate" prop="nextMaintenDate"
v-if="formData.maintenType === 1" v-if="formData.maintenType === MesMaintenTypeEnum.REGULAR"
> >
<el-date-picker <el-date-picker
v-model="formData.nextMaintenDate" v-model="formData.nextMaintenDate"
@ -77,7 +77,7 @@
<el-form-item <el-form-item
label="下次保养周期" label="下次保养周期"
prop="nextMaintenPeriod" prop="nextMaintenPeriod"
v-if="formData.maintenType === 2" v-if="formData.maintenType === MesMaintenTypeEnum.USAGE"
> >
<el-input-number <el-input-number
v-model="formData.nextMaintenPeriod" v-model="formData.nextMaintenPeriod"
@ -109,7 +109,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict' import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool' import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool'
import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tooltype' import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tool/type'
import { MesToolStatusEnum, MesMaintenTypeEnum } from '@/views/mes/utils/constants'
defineOptions({ name: 'ToolForm' }) defineOptions({ name: 'ToolForm' })
@ -121,19 +122,19 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formType = ref('') // create - update - const formType = ref('') // create - update -
const formData = ref({ const formData = ref({
id: undefined as unknown as number, id: undefined,
code: undefined as unknown as string, code: undefined,
name: undefined as unknown as string, name: undefined,
brand: undefined as unknown as string, brand: undefined,
spec: undefined as unknown as string, spec: undefined,
toolTypeId: undefined as unknown as number, toolTypeId: undefined,
quantity: 1 as number, quantity: 1,
quantityAvailable: 1 as number, quantityAvailable: 1,
maintenType: undefined as unknown as number, maintenType: undefined,
nextMaintenPeriod: undefined as unknown as number, nextMaintenPeriod: undefined,
nextMaintenDate: undefined as unknown as string, nextMaintenDate: undefined,
status: 1 as number, status: MesToolStatusEnum.STORE,
remark: undefined as unknown as string remark: undefined
}) })
const formRules = reactive({ const formRules = reactive({
name: [{ required: true, message: '工具名称不能为空', trigger: 'blur' }], name: [{ required: true, message: '工具名称不能为空', trigger: 'blur' }],
@ -184,20 +185,10 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成
const submitForm = async () => { const submitForm = async () => {
// //
await formRef.value.validate() await formRef.value.validate()
//
// TODO @AI
if (formData.value.maintenType === 1) {
formData.value.nextMaintenPeriod = undefined as unknown as number
} else if (formData.value.maintenType === 2) {
formData.value.nextMaintenDate = undefined as unknown as string
} else {
formData.value.nextMaintenPeriod = undefined as unknown as number
formData.value.nextMaintenDate = undefined as unknown as string
}
// //
formLoading.value = true formLoading.value = true
try { try {
const data = formData.value as unknown as TmToolVO const data = formData.value as unknown as TmToolVO //
if (formType.value === 'create') { if (formType.value === 'create') {
await TmToolApi.createTool(data) await TmToolApi.createTool(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
@ -215,7 +206,6 @@ const submitForm = async () => {
/** 重置表单 */ /** 重置表单 */
const resetForm = () => { const resetForm = () => {
// TODO @AIlinter
formData.value = { formData.value = {
id: undefined, id: undefined,
code: undefined, code: undefined,
@ -228,7 +218,7 @@ const resetForm = () => {
maintenType: undefined, maintenType: undefined,
nextMaintenPeriod: undefined, nextMaintenPeriod: undefined,
nextMaintenDate: undefined, nextMaintenDate: undefined,
status: 1, // TODO @AI status: MesToolStatusEnum.STORE,
remark: undefined remark: undefined
} }
selectedToolType.value = undefined selectedToolType.value = undefined

View File

@ -102,7 +102,7 @@
<el-table-column label="品牌" align="center" prop="brand" /> <el-table-column label="品牌" align="center" prop="brand" />
<el-table-column label="型号规格" align="center" prop="spec" /> <el-table-column label="型号规格" align="center" prop="spec" />
<el-table-column label="工具类型" align="center" prop="toolTypeName" /> <el-table-column label="工具类型" align="center" prop="toolTypeName" />
<el-table-column label="数量" align="center" prop="quantity" /> <el-table-column label="库存数量" align="center" prop="quantity" />
<el-table-column label="可用数量" align="center" prop="quantityAvailable" /> <el-table-column label="可用数量" align="center" prop="quantityAvailable" />
<el-table-column label="保养维护类型" align="center" prop="maintenType"> <el-table-column label="保养维护类型" align="center" prop="maintenType">
<template #default="scope"> <template #default="scope">
@ -111,10 +111,10 @@
</el-table-column> </el-table-column>
<el-table-column label="下次保养" align="center" width="150"> <el-table-column label="下次保养" align="center" width="150">
<template #default="scope"> <template #default="scope">
<span v-if="scope.row.maintenType === 1"> <span v-if="scope.row.maintenType === MesMaintenTypeEnum.REGULAR">
{{ scope.row.nextMaintenDate ? formatDate(scope.row.nextMaintenDate) : '-' }} {{ scope.row.nextMaintenDate ? formatDate(scope.row.nextMaintenDate) : '-' }}
</span> </span>
<span v-else-if="scope.row.maintenType === 2"> <span v-else-if="scope.row.maintenType === MesMaintenTypeEnum.USAGE">
{{ scope.row.nextMaintenPeriod != null ? scope.row.nextMaintenPeriod + ' 次' : '-' }} {{ scope.row.nextMaintenPeriod != null ? scope.row.nextMaintenPeriod + ' 次' : '-' }}
</span> </span>
<span v-else>-</span> <span v-else>-</span>
@ -170,9 +170,10 @@
import { dateFormatter, formatDate } from '@/utils/formatTime' import { dateFormatter, formatDate } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool' import { TmToolApi, TmToolVO } from '@/api/mes/tm/tool'
import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tooltype' import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tool/type'
import ToolForm from './ToolForm.vue' import ToolForm from './ToolForm.vue'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { MesMaintenTypeEnum } from '@/views/mes/utils/constants'
defineOptions({ name: 'MesTmTool' }) defineOptions({ name: 'MesTmTool' })

View File

@ -15,11 +15,10 @@
<el-input v-model="formData.name" placeholder="请输入类型名称" /> <el-input v-model="formData.name" placeholder="请输入类型名称" />
</el-form-item> </el-form-item>
<el-form-item label="是否编码管理" prop="codeFlag"> <el-form-item label="是否编码管理" prop="codeFlag">
<!-- TODO @AI: linter -->
<el-radio-group v-model="formData.codeFlag"> <el-radio-group v-model="formData.codeFlag">
<el-radio <el-radio
v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)" v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
:key="dict.value" :key="dict.value + ''"
:value="dict.value" :value="dict.value"
> >
{{ dict.label }} {{ dict.label }}
@ -44,7 +43,7 @@
<el-form-item <el-form-item
label="保养周期" label="保养周期"
prop="maintenPeriod" prop="maintenPeriod"
v-if="formData.maintenType === 1" v-if="formData.maintenType === MesMaintenTypeEnum.REGULAR"
> >
<el-input-number <el-input-number
v-model="formData.maintenPeriod" v-model="formData.maintenPeriod"
@ -65,7 +64,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { getBoolDictOptions, getIntDictOptions, DICT_TYPE } from '@/utils/dict' import { getBoolDictOptions, getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tooltype' import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tool/type'
import { MesMaintenTypeEnum } from '@/views/mes/utils/constants'
defineOptions({ name: 'ToolTypeForm' }) defineOptions({ name: 'ToolTypeForm' })
@ -77,13 +77,13 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formType = ref('') // create - update - const formType = ref('') // create - update -
const formData = ref({ const formData = ref({
id: undefined as unknown as number, id: undefined,
code: undefined as unknown as string, code: undefined,
name: undefined as unknown as string, name: undefined,
codeFlag: true as boolean, codeFlag: true,
maintenType: undefined as unknown as number, maintenType: undefined,
maintenPeriod: undefined as unknown as number, maintenPeriod: undefined,
remark: undefined as unknown as string remark: undefined
}) })
const formRules = reactive({ const formRules = reactive({
code: [{ required: true, message: '类型编码不能为空', trigger: 'blur' }], code: [{ required: true, message: '类型编码不能为空', trigger: 'blur' }],
@ -115,11 +115,6 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成
const submitForm = async () => { const submitForm = async () => {
// //
await formRef.value.validate() await formRef.value.validate()
//
// TODO @AI
if (formData.value.maintenType !== 1) {
formData.value.maintenPeriod = undefined as unknown as number
}
// //
formLoading.value = true formLoading.value = true
try { try {
@ -140,7 +135,6 @@ const submitForm = async () => {
} }
/** 重置表单 */ /** 重置表单 */
// TODO @AIlinter
const resetForm = () => { const resetForm = () => {
formData.value = { formData.value = {
id: undefined, id: undefined,

View File

@ -127,7 +127,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tooltype' import { TmToolTypeApi, TmToolTypeVO } from '@/api/mes/tm/tool/type'
import ToolTypeForm from './ToolTypeForm.vue' import ToolTypeForm from './ToolTypeForm.vue'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'

View File

@ -1,3 +1,17 @@
/** MES 工具状态枚举 */
export const MesToolStatusEnum = {
STORE: 1, // 在库
ISSUE: 2, // 领用中
REPAIR: 3, // 维修中
SCRAP: 4 // 报废
}
/** MES 保养维护类型枚举 */
export const MesMaintenTypeEnum = {
REGULAR: 1, // 定期维护
USAGE: 2 // 按使用次数维护
}
/** MES 物料/产品标识枚举 */ /** MES 物料/产品标识枚举 */
export const MesItemOrProductEnum = { export const MesItemOrProductEnum = {
ITEM: { ITEM: {