|
|
|
@ -1,27 +1,35 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
import { Space,Badge, Button, Divider, Switch } from 'ant-design-vue' |
|
|
|
import { onMounted, ref, reactive } from 'vue' |
|
|
|
import {Space, Tag,Badge, Button, Divider, Switch} from 'ant-design-vue' |
|
|
|
import {onMounted, ref, reactive} from 'vue' |
|
|
|
import moment from 'moment' |
|
|
|
import HistoryModal from '../../exa/config/HistoryModal.vue' |
|
|
|
import { calcFormSchemas, columns, searchFormSchema } from './calc.data' |
|
|
|
import {calcFormSchemas, columns, searchFormSchema} from './calc.data' |
|
|
|
|
|
|
|
import { BasicTable, TableAction, useTable } from '@/components/Table' |
|
|
|
import { BasicForm, useForm } from '@/components/Form' |
|
|
|
import {BasicTable, TableAction, useTable} from '@/components/Table' |
|
|
|
import {BasicForm, useForm} from '@/components/Form' |
|
|
|
|
|
|
|
import {calcInstant, getInstantCount, getInstantPage, updateInstant} from '@/api/alert/run/instant' |
|
|
|
import { getExaNow } from '@/api/alert/exa' |
|
|
|
import { useI18n } from '@/hooks/web/useI18n' |
|
|
|
import { router } from '@/router' |
|
|
|
import { useMessage } from '@/hooks/web/useMessage' |
|
|
|
import { IconEnum } from '@/enums/appEnum' |
|
|
|
import { useModal } from '@/components/Modal' |
|
|
|
|
|
|
|
defineOptions({ name: 'InstantCalc' }) |
|
|
|
const { createMessage } = useMessage() |
|
|
|
const { t } = useI18n() |
|
|
|
import {getExaNow} from '@/api/alert/exa' |
|
|
|
import {useI18n} from '@/hooks/web/useI18n' |
|
|
|
import {router} from '@/router' |
|
|
|
import {useMessage} from '@/hooks/web/useMessage' |
|
|
|
import {IconEnum} from '@/enums/appEnum' |
|
|
|
import {useModal} from '@/components/Modal' |
|
|
|
|
|
|
|
defineOptions({name: 'InstantCalc'}) |
|
|
|
const {createMessage} = useMessage() |
|
|
|
const {t} = useI18n() |
|
|
|
// 添加状态映射表 |
|
|
|
const statusMap = { |
|
|
|
0: { label: '待计算', color: 'default' }, |
|
|
|
1: { label: '计算中', color: 'processing' }, |
|
|
|
2: { label: '计算成功', color: 'success' }, |
|
|
|
3: { label: '计算失败', color: 'error' }, |
|
|
|
} |
|
|
|
|
|
|
|
// 添加多选框相关状态 |
|
|
|
const selectedRowss = ref<any[]>([]) |
|
|
|
const [registerTable, { getForm, reload, getDataSource, updateTableDataRecord }] = useTable({ |
|
|
|
const [registerTable, {getForm, reload, getDataSource, updateTableDataRecord}] = useTable({ |
|
|
|
title: '实例列表', |
|
|
|
api: getInstantPage, |
|
|
|
rowKey: 'mpId', |
|
|
|
@ -34,7 +42,7 @@ const [registerTable, { getForm, reload, getDataSource, updateTableDataRecord }] |
|
|
|
actionColOptions: { |
|
|
|
span: 2, |
|
|
|
style: { |
|
|
|
textAlign: 'left' , |
|
|
|
textAlign: 'left', |
|
|
|
marginLeft: '10px', |
|
|
|
}, |
|
|
|
}, |
|
|
|
@ -57,13 +65,27 @@ const [registerTable, { getForm, reload, getDataSource, updateTableDataRecord }] |
|
|
|
console.log(24) |
|
|
|
selectedRowss.value = selectedRows |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
//这段非常重要 |
|
|
|
// 你要的是:表格每一行、每一个字段都有默认值(即使接口没返回)。 |
|
|
|
// 👉 正确、优雅、一次性解决方案:用 afterFetch 统一补默认值 |
|
|
|
afterFetch: (data) => |
|
|
|
data.map(item => ({ |
|
|
|
...item, |
|
|
|
CoveredPercent: '-', |
|
|
|
AlarmNumber: '-', |
|
|
|
AlarmToatlMinutes: '-', |
|
|
|
CalcSeconds: '-', |
|
|
|
Dimension:'-', |
|
|
|
calcStatus: 0, |
|
|
|
})), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
/** |
|
|
|
* BasicForm绑定注册; |
|
|
|
*/ |
|
|
|
const [registerForm,{getFieldsValue,validate,validateFields}] = useForm({ |
|
|
|
const [registerForm, {getFieldsValue, validate, validateFields}] = useForm({ |
|
|
|
// 注册表单列 |
|
|
|
schemas: calcFormSchemas, |
|
|
|
// 是否显示展开收起按钮,默认false |
|
|
|
@ -73,13 +95,13 @@ const [registerForm,{getFieldsValue,validate,validateFields}] = useForm({ |
|
|
|
// // // 折叠时默认显示行数,默认1行 |
|
|
|
// alwaysShowLines: 1, |
|
|
|
layout: 'horizontal', |
|
|
|
model: { time: [moment().subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')] }, |
|
|
|
model: {time: [moment().subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')]}, |
|
|
|
fieldMapToTime: [ |
|
|
|
// data为时间组件在表单内的字段,startTime,endTime为转化后的开始时间于结束时间 |
|
|
|
['time', ['st', 'et'], 'YYYY-MM-DD HH:mm:ss'] |
|
|
|
], |
|
|
|
|
|
|
|
actionColOptions: { span: 5,style: { textAlign: 'left' ,marginLeft: '10px',} }, |
|
|
|
actionColOptions: {span: 5, style: {textAlign: 'left', marginLeft: '10px',}}, |
|
|
|
showSubmitButton: false, |
|
|
|
showResetButton: false, |
|
|
|
}) |
|
|
|
@ -97,21 +119,18 @@ function handleExport(values: any) { |
|
|
|
console.log('导出按钮数据::::', values) |
|
|
|
} |
|
|
|
|
|
|
|
async function handlebeforeCalc(rowMpId?: string) { |
|
|
|
console.log('点击回算按钮数据::::', rowMpId) |
|
|
|
let targetMpIds: string[] = [] |
|
|
|
async function handlebeforeCalc(record?: Recordable) { |
|
|
|
let targetRows: Recordable[] = [] |
|
|
|
|
|
|
|
// 1. 行内按钮点击:直接使用当前行的mpId |
|
|
|
if (rowMpId) { |
|
|
|
alert("行内回算") |
|
|
|
targetMpIds = [rowMpId] |
|
|
|
if (record) { |
|
|
|
targetRows = [record] |
|
|
|
} |
|
|
|
// 2. 顶部按钮点击:使用选中的实例 |
|
|
|
else { |
|
|
|
alert("表单回算") |
|
|
|
targetRows = selectedRowss.value |
|
|
|
|
|
|
|
targetMpIds = selectedRowss.value.map(row => row.mpId) |
|
|
|
if (targetMpIds.length === 0) { |
|
|
|
if (targetRows.length === 0) { |
|
|
|
createMessage.error('请选择要回算的实例') |
|
|
|
return |
|
|
|
} |
|
|
|
@ -119,79 +138,94 @@ async function handlebeforeCalc(rowMpId?: string) { |
|
|
|
|
|
|
|
// 校验表单数据 |
|
|
|
const formData = await validate() |
|
|
|
// 给函数传递需要回算的实例id数组 |
|
|
|
formData.mpIds = targetMpIds; |
|
|
|
handleCalc(formData) |
|
|
|
// 给函数传递需要回算的实例id数组 |
|
|
|
formData.records = targetRows; |
|
|
|
handleCalc(formData) |
|
|
|
} |
|
|
|
|
|
|
|
// 回算 |
|
|
|
async function handleCalc(formData: any) { |
|
|
|
calcLoading.value = true |
|
|
|
console.log('点击回算按钮数据::::', formData) |
|
|
|
// 循环调用后端的回算接口 |
|
|
|
for (const mpId of formData.mpIds) { |
|
|
|
rowCalcLoading[mpId] = true |
|
|
|
console.log('行内回算loading状态:', mpId, rowCalcLoading[mpId]) |
|
|
|
try { |
|
|
|
// 调用后端的回算接口 - 行内回算 |
|
|
|
formData.mpId=mpId |
|
|
|
// 调用后端的回算接口 - 行内回算 |
|
|
|
console.log(formData) |
|
|
|
const res = await calcInstant(formData) |
|
|
|
console.log('回算结果:', res) |
|
|
|
// 更新实例列表 |
|
|
|
// updateTableDataRecord(res) |
|
|
|
createMessage.success(t('common.success')) |
|
|
|
} catch (error) { |
|
|
|
createMessage.error(t('common.fail')) |
|
|
|
} finally { |
|
|
|
rowCalcLoading[mpId] = false |
|
|
|
} |
|
|
|
async function handleCalc(formData: any) { |
|
|
|
calcLoading.value = true |
|
|
|
console.log('点击回算按钮数据::::', formData) |
|
|
|
// 循环调用后端的回算接口 |
|
|
|
for (const record of formData.records) { |
|
|
|
updateTableDataRecord(record.mpId, {calcStatus:1}) |
|
|
|
|
|
|
|
rowCalcLoading[record.mpId] = true |
|
|
|
console.log('行内回算loading状态:', record.mpId, rowCalcLoading[record.mpId]) |
|
|
|
try { |
|
|
|
// 调用后端的回算接口 - 行内回算 |
|
|
|
formData.mpId = record.mpId |
|
|
|
// 调用后端的回算接口 - 行内回算 |
|
|
|
console.log(formData) |
|
|
|
const res = await calcInstant(formData) |
|
|
|
console.log('回算结果:', res) |
|
|
|
console.log(record) |
|
|
|
res.calcStatus = 2 |
|
|
|
// 更新实例列表 |
|
|
|
updateTableDataRecord(record.mpId, res) |
|
|
|
createMessage.success(t('common.successText')) |
|
|
|
} catch (error) { |
|
|
|
updateTableDataRecord(record.mpId, {calcStatus:3}) |
|
|
|
createMessage.error(t('common.failText')) |
|
|
|
} finally { |
|
|
|
rowCalcLoading[record.mpId] = false |
|
|
|
} |
|
|
|
calcLoading.value = false |
|
|
|
} |
|
|
|
calcLoading.value = false |
|
|
|
} |
|
|
|
onMounted(async () => { |
|
|
|
const { setFieldsValue } = getForm() |
|
|
|
await setFieldsValue({ system: null }) |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|
<template> |
|
|
|
<div> |
|
|
|
<BasicTable @register="registerTable"> |
|
|
|
<template #form-formFooter> |
|
|
|
<!-- <a-button v-auth="['run:instant:create']" type="primary" :pre-icon="IconEnum.ADD" @click="handleCreate"> |
|
|
|
{{ t('action.create') }} |
|
|
|
</a-button> --> |
|
|
|
<Divider orientation="left"> |
|
|
|
回算 |
|
|
|
</Divider> |
|
|
|
<!-- <Divider orientation="left">--> |
|
|
|
<!-- 回算--> |
|
|
|
<!-- </Divider>--> |
|
|
|
<!-- 自定义表单 --> |
|
|
|
<BasicForm @register="registerForm"> |
|
|
|
<template #advanceBefore> |
|
|
|
<Space> |
|
|
|
<a-button type="primary" :loading="calcLoading" :pre-icon="IconEnum.BACK_CALC" @click="handlebeforeCalc()"> |
|
|
|
{{ t('action.backCalc') }} |
|
|
|
</a-button> |
|
|
|
<a-button type="primary" :pre-icon="IconEnum.EXPORT" @click="handleExport"> |
|
|
|
{{ t('action.export') }} |
|
|
|
</a-button> |
|
|
|
<a-button type="primary" :loading="calcLoading" :pre-icon="IconEnum.BACK_CALC" |
|
|
|
@click="handlebeforeCalc()"> |
|
|
|
{{ t('action.backCalc') }} |
|
|
|
</a-button> |
|
|
|
<a-button type="primary" :pre-icon="IconEnum.EXPORT" @click="handleExport"> |
|
|
|
{{ t('action.export') }} |
|
|
|
</a-button> |
|
|
|
</Space> |
|
|
|
</template> |
|
|
|
</BasicForm> |
|
|
|
</template> |
|
|
|
<template #bodyCell="{ column, record }"> |
|
|
|
<template v-if="column.key === 'action'"> |
|
|
|
<!-- <TableAction--> |
|
|
|
<!-- :actions="[--> |
|
|
|
<!-- { icon: IconEnum.BACK_CALC,label: rowCalcLoading[record.mpId] ? t('action.calcIng') : t('action.backCalc'), onClick: handleCalc.bind(null, record) },--> |
|
|
|
<!-- ]"--> |
|
|
|
<!-- />--> |
|
|
|
<!-- <TableAction--> |
|
|
|
<!-- :actions="[--> |
|
|
|
<!-- { icon: IconEnum.BACK_CALC,label: rowCalcLoading[record.mpId] ? t('action.calcIng') : t('action.backCalc'), onClick: handleCalc.bind(null, record) },--> |
|
|
|
<!-- ]"--> |
|
|
|
<!-- />--> |
|
|
|
<TableAction |
|
|
|
:actions="[ |
|
|
|
{ icon: IconEnum.BACK_CALC,label: rowCalcLoading[record.mpId] ? t('action.calcIng') : t('action.backCalc'), |
|
|
|
onClick: () => handlebeforeCalc(record.mpId), |
|
|
|
onClick: () => handlebeforeCalc(record), |
|
|
|
disabled: rowCalcLoading[record.mpId]}, |
|
|
|
]" |
|
|
|
@click.stop |
|
|
|
/> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
<!-- 修改calcStatus列的渲染 --> |
|
|
|
<template #calcStatus="{ record }"> |
|
|
|
<Tag :color="statusMap[record.calcStatus].color"> |
|
|
|
{{ statusMap[record.calcStatus].label }} |
|
|
|
</Tag> |
|
|
|
</template> |
|
|
|
</BasicTable> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
|