feat:添加配方类型页面
parent
5ca63c5a85
commit
b9607a5d03
@ -0,0 +1,34 @@
|
|||||||
|
import request from '@/config/axios'
|
||||||
|
|
||||||
|
export interface RecipeVO {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
recipeType: string
|
||||||
|
recipeDesc: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RecipeApi = {
|
||||||
|
getRecipePage: async (params: any) => {
|
||||||
|
return await request.get({ url: `/iot/recipe/page`, params })
|
||||||
|
},
|
||||||
|
|
||||||
|
getRecipe: async (id: number) => {
|
||||||
|
return await request.get({ url: `/iot/recipe/get?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
createRecipe: async (data: Partial<RecipeVO>) => {
|
||||||
|
return await request.post({ url: `/iot/recipe/create`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
updateRecipe: async (data: Partial<RecipeVO>) => {
|
||||||
|
return await request.put({ url: `/iot/recipe/update`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteRecipe: async (id: number) => {
|
||||||
|
return await request.delete({ url: `/iot/recipe/delete?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
exportRecipe: async (params) => {
|
||||||
|
return await request.download({ url: `/iot/recipe/export-excel`, params })
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,293 @@
|
|||||||
|
<template>
|
||||||
|
<ContentWrap>
|
||||||
|
<el-form
|
||||||
|
class="-mb-15px"
|
||||||
|
:model="queryParams"
|
||||||
|
ref="queryFormRef"
|
||||||
|
:inline="true"
|
||||||
|
label-width="68px"
|
||||||
|
>
|
||||||
|
<el-form-item label="名称" prop="name">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.name"
|
||||||
|
placeholder="请输入名称"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="工序" prop="recipeType">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.recipeType"
|
||||||
|
placeholder="请选择工序"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
@change="handleQuery"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="option in processOptions"
|
||||||
|
:key="option.value"
|
||||||
|
:label="option.label"
|
||||||
|
:value="option.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 查询</el-button>
|
||||||
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||||
|
<el-button type="primary" plain @click="openDialog('create')">
|
||||||
|
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||||
|
</el-button>
|
||||||
|
<el-button type="success" plain @click="handleExport" :loading="exportLoading">
|
||||||
|
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||||
|
</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<ContentWrap>
|
||||||
|
<el-table
|
||||||
|
ref="tableRef"
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
row-key="id"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
|
>
|
||||||
|
<el-table-column type="selection" width="55" reserve-selection />
|
||||||
|
<el-table-column label="名称" align="center" prop="name" />
|
||||||
|
<el-table-column label="工序" align="center" prop="recipeType">
|
||||||
|
<template #default="scope">
|
||||||
|
{{ getProcessLabel(scope.row.recipeType) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="备注" align="center" prop="recipeDesc" />
|
||||||
|
<el-table-column label="操作" align="center" width="160px" fixed="right">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button link type="primary" @click="openDialog('update', scope.row)">编辑</el-button>
|
||||||
|
<el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="handlePagination"
|
||||||
|
/>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||||
|
<el-form
|
||||||
|
ref="dialogFormRef"
|
||||||
|
:model="dialogForm"
|
||||||
|
:rules="dialogRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="dialogLoading"
|
||||||
|
>
|
||||||
|
<el-form-item label="名称" prop="name">
|
||||||
|
<el-input v-model="dialogForm.name" placeholder="请输入名称" clearable />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="工序" prop="recipeType">
|
||||||
|
<el-select v-model="dialogForm.recipeType" placeholder="请选择工序" clearable class="!w-full">
|
||||||
|
<el-option
|
||||||
|
v-for="option in processOptions"
|
||||||
|
:key="option.value"
|
||||||
|
:label="option.label"
|
||||||
|
:value="option.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="recipeDesc">
|
||||||
|
<el-input v-model="dialogForm.recipeDesc" placeholder="请输入备注" clearable type="textarea" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
<el-button type="primary" @click="submitDialog" :disabled="dialogLoading">保 存</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
|
||||||
|
import download from '@/utils/download'
|
||||||
|
import { RecipeApi, RecipeVO } from '@/api/iot/recipe'
|
||||||
|
|
||||||
|
type ProcessOption = { label: string; value: string }
|
||||||
|
|
||||||
|
/** 配方类型 列表 */
|
||||||
|
defineOptions({ name: 'FormulaType' })
|
||||||
|
|
||||||
|
const message = useMessage()
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const processOptions = computed<ProcessOption[]>(() => {
|
||||||
|
return getStrDictOptions(DICT_TYPE.MES_PROGRESS_TYPE).map((dict) => ({
|
||||||
|
label: dict.label,
|
||||||
|
value: dict.value
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
const processLabelMap = computed<Record<string, string>>(() => {
|
||||||
|
return processOptions.value.reduce((acc, cur) => {
|
||||||
|
acc[cur.value] = cur.label
|
||||||
|
return acc
|
||||||
|
}, {} as Record<string, string>)
|
||||||
|
})
|
||||||
|
|
||||||
|
const getProcessLabel = (value: string) => {
|
||||||
|
return processLabelMap.value[value] ?? value
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const tableRef = ref()
|
||||||
|
const queryFormRef = ref()
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: '',
|
||||||
|
recipeType: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
const exportLoading = ref(false)
|
||||||
|
|
||||||
|
const selectedIds = ref<number[]>([])
|
||||||
|
const handleSelectionChange = (rows: any[]) => {
|
||||||
|
selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = ref<RecipeVO[]>([])
|
||||||
|
const total = ref(0)
|
||||||
|
|
||||||
|
const buildQueryParams = () => {
|
||||||
|
const name = queryParams.name?.trim()
|
||||||
|
return {
|
||||||
|
pageNo: queryParams.pageNo,
|
||||||
|
pageSize: queryParams.pageSize,
|
||||||
|
name: name ? name : undefined,
|
||||||
|
recipeType: queryParams.recipeType ? queryParams.recipeType : undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const data = await RecipeApi.getRecipePage(buildQueryParams())
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value?.resetFields?.()
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePagination = () => {
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleExport = async () => {
|
||||||
|
if (!selectedIds.value.length) {
|
||||||
|
message.error('请选择需要导出的数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await message.exportConfirm()
|
||||||
|
exportLoading.value = true
|
||||||
|
const data = await RecipeApi.exportRecipe({ ids: selectedIds.value.join(',') })
|
||||||
|
download.excel(data, '配方类型.xls')
|
||||||
|
} catch {
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type DialogMode = 'create' | 'update'
|
||||||
|
|
||||||
|
const dialogVisible = ref(false)
|
||||||
|
const dialogMode = ref<DialogMode>('create')
|
||||||
|
const dialogTitle = computed(() => (dialogMode.value === 'create' ? '新增配方类型' : '编辑配方类型'))
|
||||||
|
const dialogFormRef = ref()
|
||||||
|
const dialogLoading = ref(false)
|
||||||
|
const dialogForm = reactive({
|
||||||
|
id: undefined as number | undefined,
|
||||||
|
name: '',
|
||||||
|
recipeType: '',
|
||||||
|
recipeDesc: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
const dialogRules = reactive({
|
||||||
|
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
|
||||||
|
recipeType: [{ required: true, message: '工序不能为空', trigger: 'change' }]
|
||||||
|
})
|
||||||
|
|
||||||
|
const openDialog = (mode: DialogMode, row?: RecipeVO) => {
|
||||||
|
dialogMode.value = mode
|
||||||
|
dialogVisible.value = true
|
||||||
|
nextTick(() => {
|
||||||
|
dialogFormRef.value?.clearValidate?.()
|
||||||
|
})
|
||||||
|
|
||||||
|
if (mode === 'create') {
|
||||||
|
dialogForm.id = undefined
|
||||||
|
dialogForm.name = ''
|
||||||
|
dialogForm.recipeType = ''
|
||||||
|
dialogForm.recipeDesc = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogForm.id = row?.id
|
||||||
|
dialogForm.name = row?.name ?? ''
|
||||||
|
dialogForm.recipeType = row?.recipeType ?? ''
|
||||||
|
dialogForm.recipeDesc = row?.recipeDesc ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitDialog = async () => {
|
||||||
|
if (!dialogFormRef.value) return
|
||||||
|
await dialogFormRef.value.validate()
|
||||||
|
dialogLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
id: dialogForm.id,
|
||||||
|
name: dialogForm.name,
|
||||||
|
recipeType: dialogForm.recipeType,
|
||||||
|
recipeDesc: dialogForm.recipeDesc
|
||||||
|
}
|
||||||
|
if (dialogMode.value === 'create') {
|
||||||
|
await RecipeApi.createRecipe(data)
|
||||||
|
message.success(t('common.createSuccess'))
|
||||||
|
} else {
|
||||||
|
await RecipeApi.updateRecipe(data)
|
||||||
|
message.success(t('common.updateSuccess'))
|
||||||
|
}
|
||||||
|
dialogVisible.value = false
|
||||||
|
await getList()
|
||||||
|
} finally {
|
||||||
|
dialogLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDelete = async (row: RecipeVO) => {
|
||||||
|
try {
|
||||||
|
await message.delConfirm()
|
||||||
|
await RecipeApi.deleteRecipe(row.id)
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
await getList()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue