diff --git a/src/api/iot/device/index.ts b/src/api/iot/device/index.ts index ca15f6fc..5afaad3b 100644 --- a/src/api/iot/device/index.ts +++ b/src/api/iot/device/index.ts @@ -65,6 +65,15 @@ export interface HistoryRecordParams { collectionEndTime?: string } +export interface DeviceContactModelVO { + id: number + attributeCode?: string + attributeName?: string + attributeType?: string + dataType?: string + dataUnit?: string +} + // 物联设备 API export const DeviceApi = { // 查询物联设备分页 @@ -127,6 +136,10 @@ export const DeviceApi = { getDeviceAttributePage: async (params) => { return await request.get({ url: `/iot/device/device-attribute/page`, params }) }, + + getDeviceContactModelPage: async () => { + return await request.get({ url: `/iot/device-contact-model/page` }) + }, // 新增设备属性 createDeviceAttribute: async (data) => { return await request.post({ url: `/iot/device-contact-model/create`, data }) diff --git a/src/api/iot/recipeConfig/index.ts b/src/api/iot/recipeConfig/index.ts index f043c3e9..46ebb05c 100644 --- a/src/api/iot/recipeConfig/index.ts +++ b/src/api/iot/recipeConfig/index.ts @@ -1,13 +1,21 @@ +import request from '@/config/axios' + export interface RecipeConfigVO { id: number recipeCode: string - recipeName: string + recipeName?: string + name?: string recipeType?: string | number productId?: number productName?: string + machineName?: string deviceId?: number deviceName?: string + recipeDesc?: string remark?: string + isEnable?: string | number + dataUnit?: string + createTime?: string } export interface RecipePointDetailVO { @@ -31,7 +39,6 @@ export interface RecipePointCandidateVO { type PageResult = { list: T[]; total: number } const STORAGE_KEYS = { - recipeList: 'mock:recipeConfig:recipes', pointCandidates: 'mock:recipeConfig:pointCandidates', recipePointRelation: 'mock:recipeConfig:recipePointRelation' } as const @@ -54,23 +61,6 @@ const saveToStorage = (key: string, value: any) => { window.localStorage.setItem(key, JSON.stringify(value)) } -const buildMockRecipes = (): RecipeConfigVO[] => { - return Array.from({ length: 18 }).map((_, idx) => { - const no = String(idx + 1).padStart(3, '0') - return { - id: idx + 1, - recipeCode: `RCP-${no}`, - recipeName: `配方-${no}`, - recipeType: idx % 2 === 0 ? '标准' : '自定义', - productId: undefined, - productName: idx % 3 === 0 ? '产品A' : idx % 3 === 1 ? '产品B' : '产品C', - deviceId: undefined, - deviceName: idx % 2 === 0 ? '设备1' : '设备2', - remark: idx % 4 === 0 ? '示例数据' : '' - } - }) -} - const buildMockPointCandidates = (): RecipePointCandidateVO[] => { const pointTypes = ['模拟量', '开关量', '计算量'] const dataTypes = ['int', 'float', 'string', 'bool'] @@ -88,9 +78,6 @@ const buildMockPointCandidates = (): RecipePointCandidateVO[] => { } const ensureMockSeeded = () => { - const recipeList = loadFromStorage(STORAGE_KEYS.recipeList, []) - if (!recipeList.length) saveToStorage(STORAGE_KEYS.recipeList, buildMockRecipes()) - const pointCandidates = loadFromStorage(STORAGE_KEYS.pointCandidates, []) if (!pointCandidates.length) saveToStorage(STORAGE_KEYS.pointCandidates, buildMockPointCandidates()) @@ -119,103 +106,53 @@ const contains = (value: string | undefined, keyword: string | undefined) => { export const RecipeConfigApi = { getRecipeConfigPage: async (params: any) => { - ensureMockSeeded() - await sleep(120) - const recipeCode = params?.recipeCode - const recipeName = params?.recipeName - const productName = params?.productName - const pageNo = params?.pageNo - const pageSize = params?.pageSize - const list = loadFromStorage(STORAGE_KEYS.recipeList, buildMockRecipes()) - const filtered = list.filter((item) => { - return ( - contains(item.recipeCode, recipeCode) && - contains(item.recipeName, recipeName) && - contains(item.productName, productName) - ) - }) - return paginate(filtered, pageNo, pageSize) + const finalParams = { + ...(params ?? {}), + name: params?.name ?? params?.recipeName + } + return await request.get({ url: `/iot/recipe/page`, params: finalParams }) }, createRecipeConfig: async (data: Partial) => { - ensureMockSeeded() - await sleep(120) - const list = loadFromStorage(STORAGE_KEYS.recipeList, buildMockRecipes()) - const maxId = list.reduce((acc, cur) => Math.max(acc, cur.id), 0) - const nextId = maxId + 1 - const newItem: RecipeConfigVO = { - id: nextId, - recipeCode: data.recipeCode ?? '', - recipeName: data.recipeName ?? '', + const finalData = { + id: data.id, + name: data.name ?? data.recipeName, + recipeCode: data.recipeCode, recipeType: data.recipeType, - productId: data.productId, productName: data.productName, - deviceId: data.deviceId, - deviceName: data.deviceName, - remark: data.remark + machineName: data.machineName ?? data.deviceName, + recipeDesc: data.recipeDesc ?? data.remark, + isEnable: data.isEnable, + dataUnit: data.dataUnit } - saveToStorage(STORAGE_KEYS.recipeList, [newItem, ...list]) - return nextId + return await request.post({ url: `/iot/recipe/create`, data: finalData }) }, updateRecipeConfig: async (data: Partial) => { - ensureMockSeeded() - await sleep(120) - if (!data.id) return true - const list = loadFromStorage(STORAGE_KEYS.recipeList, buildMockRecipes()) - const next = list.map((item) => { - if (item.id !== data.id) return item - return { - ...item, - recipeCode: data.recipeCode ?? item.recipeCode, - recipeName: data.recipeName ?? item.recipeName, - recipeType: data.recipeType ?? item.recipeType, - productId: data.productId ?? item.productId, - productName: data.productName ?? item.productName, - deviceId: data.deviceId ?? item.deviceId, - deviceName: data.deviceName ?? item.deviceName, - remark: data.remark ?? item.remark - } - }) - saveToStorage(STORAGE_KEYS.recipeList, next) - return true + const finalData = { + id: data.id, + name: data.name ?? data.recipeName, + recipeCode: data.recipeCode, + recipeType: data.recipeType, + productName: data.productName, + machineName: data.machineName ?? data.deviceName, + recipeDesc: data.recipeDesc ?? data.remark, + isEnable: data.isEnable, + dataUnit: data.dataUnit + } + return await request.put({ url: `/iot/recipe/update`, data: finalData }) }, deleteRecipeConfig: async (id: number) => { - ensureMockSeeded() - await sleep(120) - const list = loadFromStorage(STORAGE_KEYS.recipeList, buildMockRecipes()) - saveToStorage( - STORAGE_KEYS.recipeList, - list.filter((item) => item.id !== id) - ) - - const relation = loadFromStorage>(STORAGE_KEYS.recipePointRelation, {}) - delete relation[String(id)] - saveToStorage(STORAGE_KEYS.recipePointRelation, relation) - return true + return await request.delete({ url: `/iot/recipe/delete?id=` + id }) }, exportRecipeConfig: async (params: any) => { - ensureMockSeeded() - await sleep(120) - const ids = String(params?.ids ?? '') - .split(',') - .map((v) => Number(v)) - .filter((v) => !Number.isNaN(v)) - const list = loadFromStorage(STORAGE_KEYS.recipeList, buildMockRecipes()) - const exportList = ids.length ? list.filter((item) => ids.includes(item.id)) : list - const header = ['配方编码', '配方名称', '配方类型', '关联产品', '关联设备', '备注'] - const rows = exportList.map((item) => [ - item.recipeCode, - item.recipeName, - item.recipeType ?? '', - item.productName ?? '', - item.deviceName ?? '', - item.remark ?? '' - ]) - const csv = [header, ...rows].map((r) => r.map((v) => `"${String(v).replace(/"/g, '""')}"`).join(',')).join('\n') - return new Blob([csv], { type: 'text/csv;charset=utf-8' }) + const finalParams = { + ...(params ?? {}), + name: params?.name ?? params?.recipeName + } + return await request.download({ url: `/iot/recipe/export-excel`, params: finalParams }) }, getPointCandidatePage: async (params: any): Promise> => { diff --git a/src/views/formula/formulaConfig/index.vue b/src/views/formula/formulaConfig/index.vue index 7d6d54e6..af62405e 100644 --- a/src/views/formula/formulaConfig/index.vue +++ b/src/views/formula/formulaConfig/index.vue @@ -6,9 +6,9 @@ v-model="queryParams.recipeCode" placeholder="请输入配方编码" clearable @keyup.enter="handleQuery" class="!w-240px" /> - + @@ -37,15 +37,15 @@ ref="tableRef" v-loading="loading" :data="list" :stripe="true" :show-overflow-to highlight-current-row @selection-change="handleSelectionChange" @row-click="handleRowClick"> - + - - + +