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

View File

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

View File

@ -127,7 +127,7 @@
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
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 { 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 物料/产品标识枚举 */
export const MesItemOrProductEnum = {
ITEM: {