style:配方库-添加采集时间/录入时间字段

main
黄伟杰 5 days ago
parent 3e7aa4a57d
commit bb096c0c6b

@ -14,6 +14,11 @@ export interface RecipePlanDetailVO {
isEnable?: string | number | boolean isEnable?: string | number | boolean
} }
export interface CollectLatestTimeResult {
timeAbnormal?: boolean
latestTime?: string | number
}
export const RecipePlanDetailApi = { export const RecipePlanDetailApi = {
getRecipePlanDetailPage: async (params: any) => { getRecipePlanDetailPage: async (params: any) => {
return await request.get({ url: `/iot/recipe-plan-detail/page`, params }) return await request.get({ url: `/iot/recipe-plan-detail/page`, params })
@ -39,5 +44,8 @@ export const RecipePlanDetailApi = {
return await request.post({ url: `/iot/recipe-plan-detail/batch-create?id=` + id }) return await request.post({ url: `/iot/recipe-plan-detail/batch-create?id=` + id })
}, },
getCollectLatestTime: async (params: { id?: number | string; recipeId?: number | string }) => {
return await request.get({ url: `/iot/recipe-plan-detail/getCollectLatestTime`, params })
}
} }

@ -32,6 +32,11 @@
prop="value" prop="value"
min-width="180" min-width="180"
/> />
<el-table-column label="采集时间" align="center" prop="collectionTime" min-width="180">
<template #default="scope">
{{ formatTime(scope.row?.collectionTime) }}
</template>
</el-table-column>
</el-table> </el-table>
<Pagination <Pagination
:total="to" :total="to"
@ -129,6 +134,11 @@
prop="remark" prop="remark"
min-width="180" min-width="180"
/> />
<el-table-column label="录入时间" align="center" prop="updateTime" min-width="180">
<template #default="scope">
{{ formatTime(scope.row?.updateTime) }}
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="120"> <el-table-column align="center" fixed="right" label="操作" width="120">
<template #default="scope"> <template #default="scope">
<el-button link type="primary" @click="openReferDialog(scope.row)"></el-button> <el-button link type="primary" @click="openReferDialog(scope.row)"></el-button>
@ -172,6 +182,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs'
import { RecipePointRecordApi } from '@/api/iot/recipepointrecord' import { RecipePointRecordApi } from '@/api/iot/recipepointrecord'
import { RecipeDeviceRecordApi } from '@/api/iot/recipeDeviceRecord' import { RecipeDeviceRecordApi } from '@/api/iot/recipeDeviceRecord'
import { RecipePointVO } from '@/api/iot/recipePoint' import { RecipePointVO } from '@/api/iot/recipePoint'
@ -212,6 +223,24 @@ const getUnitLabel = (dataUnit: unknown) => {
return unit?.name ?? id return unit?.name ?? id
} }
const formatTime = (value: unknown) => {
if (value === undefined || value === null || value === '') return '-'
if (typeof value === 'number') {
if (!Number.isFinite(value)) return '-'
const ms = value < 1e12 ? value * 1000 : value
return dayjs(ms).isValid() ? dayjs(ms).format('YYYY-MM-DD HH:mm:ss') : '-'
}
const raw = String(value).trim()
if (!raw) return '-'
if (/^\d+$/.test(raw)) {
const num = Number(raw)
if (!Number.isFinite(num)) return '-'
const ms = num < 1e12 ? num * 1000 : num
return dayjs(ms).isValid() ? dayjs(ms).format('YYYY-MM-DD HH:mm:ss') : raw
}
return dayjs(raw).isValid() ? dayjs(raw).format('YYYY-MM-DD HH:mm:ss') : raw
}
const queryFormRef = ref() const queryFormRef = ref()
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,

@ -370,10 +370,31 @@ const checkRecipeRecords = async (recipeId: string | number) => {
} }
} }
const ensureCollectTimeNormalOrConfirmed = async (row: RecipePlanDetailVO) => {
try {
const res = await RecipePlanDetailApi.getCollectLatestTime({
id: row?.id,
recipeId: row?.recipeId
})
const timeAbnormal = !!(res as any)?.timeAbnormal
if (!timeAbnormal) return true
try {
await message.confirm('设备最新数据晚于当前系统时间2分钟确认是否继续读取。')
return true
} catch {
return false
}
} catch {
return true
}
}
const handleRead = async (row: RecipePlanDetailVO) => { const handleRead = async (row: RecipePlanDetailVO) => {
const recipeId = row?.recipeId const recipeId = row?.recipeId
const id = row?.id const id = row?.id
if (!recipeId) return if (!recipeId) return
const ok = await ensureCollectTimeNormalOrConfirmed(row)
if (!ok) return
handleRowClick(row) handleRowClick(row)
const recipeName = row?.recipeName const recipeName = row?.recipeName
const { hasDeviceRecords, hasManualRecords } = await checkRecipeRecords(recipeId) const { hasDeviceRecords, hasManualRecords } = await checkRecipeRecords(recipeId)

Loading…
Cancel
Save