From c49e2fed522f689952835e230a6b32dd0b6b9e4b Mon Sep 17 00:00:00 2001 From: hwj Date: Wed, 7 Jan 2026 19:29:19 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E9=85=8D=E6=96=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE-=E5=AF=B9=E6=8E=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/recipeConfig/index.ts | 45 +-- src/api/iot/recipePoint/index.ts | 31 ++ .../components/RecipeDetailList.vue | 332 ++++++++++++++++++ src/views/formula/formulaConfig/index.vue | 109 ++---- 4 files changed, 400 insertions(+), 117 deletions(-) create mode 100644 src/api/iot/recipePoint/index.ts create mode 100644 src/views/formula/formulaConfig/components/RecipeDetailList.vue diff --git a/src/api/iot/recipeConfig/index.ts b/src/api/iot/recipeConfig/index.ts index 46ebb05c..90e6a386 100644 --- a/src/api/iot/recipeConfig/index.ts +++ b/src/api/iot/recipeConfig/index.ts @@ -20,12 +20,14 @@ export interface RecipeConfigVO { export interface RecipePointDetailVO { id: number - recipeId: number + recipeId: string | number attributeId?: number - pointName: string - pointType: string - dataType: string - dataUnit: string + pointName?: string + pointType?: string + dataType?: string + dataUnit?: string + attributeName?: string + attributeType?: string } export interface RecipePointCandidateVO { @@ -172,39 +174,10 @@ export const RecipeConfigApi = { }, getRecipePointDetailPage: async (params: any) => { - ensureMockSeeded() - await sleep(120) - const recipeId = Number(params?.recipeId) - const pageNo = params?.pageNo - const pageSize = params?.pageSize - if (!recipeId) return { list: [], total: 0 } - - const relation = loadFromStorage>(STORAGE_KEYS.recipePointRelation, {}) - const selectedIds = relation[String(recipeId)] ?? [] - const candidates = loadFromStorage( - STORAGE_KEYS.pointCandidates, - buildMockPointCandidates() - ) - const map = candidates.reduce((acc, cur) => { - acc[cur.id] = cur - return acc - }, {} as Record) - const detailAll: RecipePointDetailVO[] = selectedIds - .map((id) => map[id]) - .filter(Boolean) - .map((item) => ({ - id: item.id, - recipeId, - attributeId: item.id, - pointName: item.pointName, - pointType: item.pointType, - dataType: item.dataType, - dataUnit: item.dataUnit - })) - return paginate(detailAll, pageNo, pageSize) + return await request.get({ url: `/iot/recipe-device-attribute/page`, params }) }, - saveRecipePointConfig: async (data: { recipeId: number; attributeIds: number[] }) => { + saveRecipePointConfig: async (data: { recipeId: string | number; attributeIds: number[] }) => { ensureMockSeeded() await sleep(120) const relation = loadFromStorage>(STORAGE_KEYS.recipePointRelation, {}) diff --git a/src/api/iot/recipePoint/index.ts b/src/api/iot/recipePoint/index.ts new file mode 100644 index 00000000..2185218a --- /dev/null +++ b/src/api/iot/recipePoint/index.ts @@ -0,0 +1,31 @@ +import request from '@/config/axios' + +export interface RecipePointVO { + id: number + recipeId: string | number + name?: string + max?: string | number + min?: string | number + dataType?: string + dataUnit?: string + remark?: string + createTime?: string +} + +export const RecipePointApi = { + getRecipePointPage: async (params: any) => { + return await request.get({ url: `/iot/recipe-point/page`, params }) + }, + + createRecipePoint: async (params: Partial) => { + return await request.post({ url: `/iot/recipe-point/create`, data: params }) + }, + + updateRecipePoint: async (params: Partial) => { + return await request.put({ url: `/iot/recipe-point/update`, data: params }) + }, + + deleteRecipePoint: async (id: number) => { + return await request.delete({ url: `/iot/recipe-point/delete`, params: { id } }) + } +} diff --git a/src/views/formula/formulaConfig/components/RecipeDetailList.vue b/src/views/formula/formulaConfig/components/RecipeDetailList.vue new file mode 100644 index 00000000..b3d8fad9 --- /dev/null +++ b/src/views/formula/formulaConfig/components/RecipeDetailList.vue @@ -0,0 +1,332 @@ + + + diff --git a/src/views/formula/formulaConfig/index.vue b/src/views/formula/formulaConfig/index.vue index b4729d31..f63a98fd 100644 --- a/src/views/formula/formulaConfig/index.vue +++ b/src/views/formula/formulaConfig/index.vue @@ -48,7 +48,7 @@ ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-to @@ -59,31 +59,16 @@ ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-to @pagination="handlePagination" /> - - - - - - - - - - - - - - - - - + @@ -142,7 +127,8 @@ import download from '@/utils/download' import { ProductApi } from '@/api/erp/product/product' import { DeviceApi } from '@/api/iot/device' import { RecipeApi } from '@/api/iot/recipe' -import { RecipeConfigApi, RecipeConfigVO, RecipePointDetailVO } from '@/api/iot/recipeConfig' +import { RecipeConfigApi, RecipeConfigVO } from '@/api/iot/recipeConfig' +import RecipeDetailList from './components/RecipeDetailList.vue' type SelectOption = { label: string; value: T } @@ -261,7 +247,7 @@ const getDeviceOptions = async () => { const getRecipeTypeOptions = async () => { recipeTypeLoading.value = true try { - const data = await RecipeApi.getRecipePage() + const data = await RecipeApi.getRecipePage({}) recipeTypeOptions.value = (data?.list ?? []).map((item: any) => ({ label: item.name, value: item.name })) } finally { recipeTypeLoading.value = false @@ -351,53 +337,24 @@ const submitDialog = async () => { } } +const detailRef = ref() const detailVisible = ref(false) -const detailActiveTab = ref('detail') -const detailLoading = ref(false) -const detailList = ref([]) -const detailTotal = ref(0) const detailMeta = reactive({ - recipeId: undefined as string | undefined, + id: undefined as number | undefined, recipeCode: '', name: '' }) -const detailQueryParams = reactive({ - pageNo: 1, - pageSize: 10, - recipeId: undefined as string | undefined -}) - -const getDetailList = async () => { - if (!detailQueryParams.recipeId) return - detailLoading.value = true - try { - const data = await RecipeConfigApi.getRecipePointDetailPage({ - pageNo: detailQueryParams.pageNo, - pageSize: detailQueryParams.pageSize, - recipeId: detailQueryParams.recipeId - }) - detailList.value = (data.list ?? []).map((item: any) => { - return { - ...item, - pointName: item.pointName ?? item.attributeName, - pointType: item.pointType ?? item.attributeType - } - }) - detailTotal.value = data.total - } finally { - detailLoading.value = false - } -} const openDetail = async (row: RecipeConfigVO) => { - detailMeta.recipeId = row.recipeCode + detailMeta.id = row.id detailMeta.recipeCode = row.recipeCode detailMeta.name = row.name ?? row.recipeName ?? '' - detailQueryParams.recipeId = row.recipeCode - detailQueryParams.pageNo = 1 detailVisible.value = true - detailActiveTab.value = 'detail' - await getDetailList() +} + +const handleDetailConfig = () => { + if (!detailMeta.recipeCode) return + openConfigDialog(detailMeta.recipeCode) } const handleRowClick = async (row: RecipeConfigVO, column: any) => { @@ -408,19 +365,9 @@ const handleRowClick = async (row: RecipeConfigVO, column: any) => { const closeDetail = () => { detailVisible.value = false - detailActiveTab.value = 'detail' - detailMeta.recipeId = undefined + detailMeta.id = undefined detailMeta.recipeCode = '' detailMeta.name = '' - detailQueryParams.recipeId = undefined - detailQueryParams.pageNo = 1 - detailQueryParams.pageSize = 10 - detailList.value = [] - detailTotal.value = 0 -} - -const handleDetailPagination = () => { - getDetailList() } type TransferItem = { key: number; label: string; disabled?: boolean } @@ -431,16 +378,16 @@ const configRecipeId = ref(undefined) const configCandidates = ref([]) const configSelectedKeys = ref([]) -const openConfigDialog = async (row: RecipeConfigVO) => { +const openConfigDialog = async (recipeCode: string) => { configVisible.value = true - configRecipeId.value = row.recipeCode + configRecipeId.value = recipeCode configSelectedKeys.value = [] configCandidates.value = [] configLoading.value = true try { const [candidateRes, selectedRes] = await Promise.all([ DeviceApi.getDeviceContactModelPage(), - RecipeConfigApi.getRecipePointDetailPage({ pageNo: 1, pageSize: 1000, recipeId: row.recipeCode }) + RecipeConfigApi.getRecipePointDetailPage({ pageNo: 1, pageSize: 100, recipeId: recipeCode }) ]) const candidateList = Array.isArray(candidateRes) @@ -470,8 +417,8 @@ const submitConfig = async () => { }) message.success(t('common.updateSuccess')) configVisible.value = false - if (detailVisible.value && detailQueryParams.recipeId === configRecipeId.value) { - await getDetailList() + if (detailVisible.value && detailMeta.recipeCode === configRecipeId.value) { + await detailRef.value?.refresh?.() } } finally { configLoading.value = false