You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

784 lines
18 KiB

import moment from 'moment'
import { left } from 'inquirer/lib/utils/readline'
import { ref } from 'vue'
import type { BasicColumn, FormSchema } from '@/components/Table'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { getModelVersionList } from '@/api/alert/run/model/index'
import { optionListApi, subSystemListApi } from '@/api/alert/model/select'
import type { systemSelectParams } from '@/api/alert/model/model/optionsModel'
import {setObjToUrlParams} from "@/utils";
import {getInstantList} from "@/api/alert/run/instant";
export const columns: BasicColumn[] = [
{
title: '编号',
dataIndex: 'mpId',
width: 80,
fixed: 'left',
},
{
title: '实例状态',
dataIndex: 'status1',
width: 100,
slots: { customRender: 'runStatus' },
fixed: 'left',
},
{
title: '实例名称',
dataIndex: 'mpName',
width: 250,
className: 'instant',
slots: { customRender: 'detail' },
fixed: 'left',
},
{
title: '专业',
dataIndex: 'systemName',
width: 200,
},
{
title: '算法',
dataIndex: 'algorithmName',
width: 200,
},
{
title: '模式',
dataIndex: 'conditionName',
width: 200,
},
{
title: '原模型名称',
dataIndex: 'modelName',
width: 200,
},
{
title: '版本',
dataIndex: 'modelVersion',
width: 200,
},
{
title: '运行日志',
dataIndex: 'runningLog',
width: 200,
},
{
title: '计算组',
dataIndex: 'groupName',
width: 200,
},
{
title: '统计量',
dataIndex: 'pointSte',
width: 120,
slots: { customRender: 'history' },
fixed: 'left',
},
{
title: '投切',
dataIndex: 'instantStatus',
width: 100,
slots: { customRender: 'status' },
fixed: 'right',
},
// {
// title: '实时值',
// dataIndex: 'value',
// width: 90,
// className: 'value',
// slots: { customRender: 'value' },
// }
]
// /**
// * 获取搜索表单 schema
// * @param showAlgorithm 是否显示算法字段
// */
// export async function getSearchFormSchema(showAlgorithm = true,showAll=true): FormSchema[] {
// const optionList = await optionListApi()
// const systemOptions = ref<any>([])
// if(!showAll){
// const param: systemSelectParams = { unitId: optionList.units[0].id, typeId: optionList.types[0].id }
// systemOptions.value = await subSystemListApi(param)
// }
// return [
// {
// label: '机组',
// field: 'unit',
// component: 'Select',
// defaultValue: showAll ? null: optionList.units[0].id,
// colProps: { span: 4 },
// componentProps: ({ formModel }) => ({
// placeholder: '全部机组',
// style: { 'color': 'green', fontSize: '14px' },
// options: optionList.units.map(unit => ({ value: unit.id, label: unit.name })),
// onChange: async (e: any) => {
// const param: systemSelectParams = { unitId: e, typeId: formModel.type }
// if (!param.typeId || !param.unitId) {
// systemOptions.value = []
// return
// }
// systemOptions.value = await subSystemListApi(param)
// },
// }),
// },
// {
// label: '系统',
// field: 'type',
// component: 'Select',
// defaultValue: showAll ? null: optionList.types[0].id,
// colProps: { span: 4 },
// componentProps: ({ formModel }) => ({
// placeholder: '全部系统',
// options: optionList.types.map(type => ({ value: type.id, label: type.name })),
// onChange: async (e: any) => {
// const param: systemSelectParams = { unitId: formModel.unit, typeId: e }
// if (!param.typeId || !param.unitId) {
// systemOptions.value = []
// return
// }
// systemOptions.value = await subSystemListApi(param)
// },
// }),
// },
// {
// label: '子系统',
// field: 'system',
// component: 'Select',
// defaultValue: showAll ? null: systemOptions[0].id,
// colProps: { span: 4 },
// componentProps: () => ({
// placeholder: '全部子系统',
// options: systemOptions.value.map(system => ({ value: system.id, label: system.name })),
// }),
// },
// {
// label: '模型实例名称',
// field: 'mpName',
// component: 'Input',
// labelWidth: 120,
// defaultValue: '',
// colProps: { span: 5 },
// },
// {
// label: '算法',
// field: 'algorithmId',
// component: 'Select',
// labelWidth: 50,
// componentProps: {
// placeholder: '全部算法',
// options: [
// { value: 1, label: '主成分分析(PCA)' },
// { value: 2, label: '神经网络(ANN)' },
// ],
// },
// defaultValue: null,
// colProps: { span: 3 },
// show: showAlgorithm, // 根据参数决定是否显示
// },
// {
// label: '状态1',
// field: 'running',
// component: 'Input',
// show: false,
// },
// {
// label: '状态2',
// field: 'runningLog',
// component: 'Input',
// show: false,
// },
// {
// label: '状态3',
// field: 'isUpdate',
// component: 'Input',
// show: false,
// },
// ]
// }
/**
* schemavben
*/
export interface selectParams {
unitId: number | null;
typeId: number | null;
systemId: number | null;
}
export async function getSearchFormSchema(
showAlgorithm = true,
showAll = true,
showName=true,
isModal=false,
haveMpId = true,
haveWarn = true,
): Promise<FormSchema[]> {
const optionList = await optionListApi()
const mpList = ref<any[]>([])
// 子系统 options 用普通变量维护(不是 ref)
const systemOptions = ref<any[]>([])
if (!showAll && optionList.units?.length && optionList.types?.length) {
const param: systemSelectParams = {
unitId: optionList.units[0].id,
typeId: optionList.types[0].id,
}
systemOptions.value = await subSystemListApi(param);
//拿到该机组、该系统、该子系统的模型实例
const param1: selectParams = {
unit: optionList.units[0].id,
type: optionList.types[0].id,
system: systemOptions.value[1].id,
}
mpList.value = await getInstantList(param1)
}
console.log(systemOptions.value)
return [
{
label: '机组',
field: 'unit',
component: 'Select',
defaultValue: showAll ? null : optionList.units?.[0]?.id,
colProps: { span: isModal?8:4 },
componentProps: ({ formModel, formActionType }) => ({
placeholder: '全部机组',
options: optionList.units?.map(unit => ({
value: unit.id,
label: unit.name,
})) || [],
onChange: async (unitId: number) => {
if (!unitId || !formModel.type) {
systemOptions.value = []
return
}
systemOptions.value = await subSystemListApi({
unitId,
typeId: formModel.type,
})
// ✅ 给子系统赋默认值(第一个)
if (systemOptions.value.length) {
formActionType.setFieldsValue({system: systemOptions.value[1].id})
}
else{
formActionType.setFieldsValue({system: null})
}
// //拿到该机组、该系统、该子系统的模型实例
// mpList.value = await getInstantList({
// unit: unitId,
// type: formModel.type,
// system: formModel.system,
// })
// if (mpList.value.length) {
// formActionType.setFieldsValue({mpId: mpList.value[0].mpId})
// }
// else{
// formActionType.setFieldsValue({mpId: null})
// }
},
}),
},
{
label: '系统',
field: 'type',
component: 'Select',
defaultValue: showAll ? null : optionList.types?.[0]?.id,
colProps: { span: isModal?8:4 },
componentProps: ({ formModel, formActionType }) => ({
placeholder: '全部系统',
options: optionList.types?.map(type => ({
value: type.id,
label: type.name,
})) || [],
onChange: async (typeId: number) => {
if (!typeId || !formModel.unit) {
systemOptions.value = []
return
}
systemOptions.value = await subSystemListApi({
unitId: formModel.unit,
typeId,
})
if (!showAll&&systemOptions.value.length) {
formActionType.setFieldsValue({system: systemOptions.value[1].id})
}
else{
formActionType.setFieldsValue({system: null})
}
// //拿到该机组、该系统、该子系统的模型实例
// mpList.value = await getInstantList({
// unit: formModel.unit,
// type: typeId,
// system: formModel.system,
// })
// if (mpList.value.length) {
// formActionType.setFieldsValue({mpId: mpList.value[0].mpId})
// }
// else{
// formActionType.setFieldsValue({mpId: null})
// }
},
}),
},
{
label: '子系统',
field: 'system',
component: 'Select',
defaultValue: showAll? null:systemOptions.value[1].id, // ⚠️ 子系统永远不要给默认值
colProps: { span: isModal?8:4 },
componentProps: ({ formModel, formActionType }) => ({
placeholder: '全部子系统',
options: systemOptions.value?.map(system => ({
value: system.id,
label: system.name,
})) || [],
onChange: async (system: number) => {
if (!system || !formModel.unit) {
mpList.value = []
return
}
mpList.value = await getInstantList({
unit: formModel.unit,
type: formModel.type,
system: system,
})
if (mpList.value.length) {
formModel.mpId=mpList.value[0].mpId
} else {
formModel.mpId=null
}
},
})
},
{
label: '模型实例名称',
field: 'mpName',
component: 'Input',
defaultValue: '',
colProps: { span: 5 },
labelWidth: 120,
show: showName,
},
{
label: '算法',
field: 'algorithmId',
component: 'Select',
defaultValue: undefined,
colProps: { span: 3 },
show: showAlgorithm,
componentProps: {
placeholder: '全部算法',
options: [
{ value: 1, label: '主成分分析(PCA)' },
{ value: 2, label: '神经网络(ANN)' },
],
},
},
{
label: '模型实例',
field: 'mpId',
component: 'Select',
defaultValue: mpList.value.length!=0?mpList.value[0].mpId:null,
colProps: { span: isModal?8:4 },
show:haveMpId,
componentProps: () => ({
placeholder: '全部实例',
options: mpList.value.map(instant => ({
value: instant.mpId,
label: instant.mpName,
})),
})},
// 隐藏字段(用于后端透传)
{ label: '状态1', field: 'running', component: 'Input', show: false },
{ label: '状态2', field: 'runningLog', component: 'Input', show: false },
{ label: '状态3', field: 'isUpdate', component: 'Input', show: false },
]
}
export const formSchema: FormSchema[] = [
{
label: '测点编码',
field: 'ItemName',
required: true,
component: 'Input',
},
{
label: '测点描述',
field: 'Descriptor',
required: true,
component: 'Input',
},
{
label: '单位',
field: 'EngUnits',
required: true,
component: 'Input',
},
{
label: '组名',
field: 'GroupName',
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.COMMON_STATUS),
},
required: true,
},
{
label: '类型',
field: 'ItemType',
component: 'Select',
componentProps: {
options: [{ value: 1, label: 1 }, { value: 2, label: 2 }, { value: 3, label: 3 }, { value: 4, label: 4 }, { value: 5, label: 5 }],
},
required: true,
},
{
label: '自动保存',
field: 'AutoSave',
component: 'Select',
componentProps: {
options: [{ value: 1, label: '是' }, { value: 2, label: '否' }],
},
required: true,
},
{
label: '数据来源',
field: 'Source',
component: 'Input',
},
]
export const instantForm: FormSchema[] = [
{
label: '时间范围',
field: 'time',
show: true,
component: 'RangePicker',
defaultValue: [moment().subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')],
componentProps: {
placeholder: ['开始时间', '结束时间'],
valueFormat: 'YYYY-MM-DD HH:mm:ss',
showTime: {
defaultValue: [moment().subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')],
},
onChange: (e: any) => {
console.log(e)
},
colProps: {
span: 8,
},
},
},
{
label: '时间间隔',
field: 'interval',
component: 'Select',
defaultValue: 300,
labelWidth:100,
componentProps: {
options: [{ value: 1, label: '1秒' }, { value: 10, label: '10秒' }, { value: 100, label: '100秒' }, { value: 300, label: '300秒' }],
},
required: true,
colProps: {
span: 3,
},
},
{
label: '复盘',
field: 'fp',
labelWidth:100,
component: 'RadioGroup',
defaultValue: 0,
colProps: {
span: 5,
},
componentProps: {
options: [
{
label: '是',
value: 1,
},
{
label: '否',
value: 0,
},
],
},
required: true,
},
{
label: '',
field: 'faultConfig',
component: 'Input',
slot: 'configButton',
colProps: {
span: 2,
}
}
]
export const searchFormSchemaModel: FormSchema[] = [
{
label: '模型实例名称',
field: 'mpName',
component: 'Input',
defaultValue: '',
required: true,
colProps: { span: 8 },
},
]
export const createInstantForm: FormSchema[] = [
{
label: '所用模型的id',
field: 'modelId',
component: 'Input',
required: true,
show: false,
colProps: {
span: 12,
},
},
{
label: '算法id',
field: 'algorithmId',
component: 'Input',
required: true,
show: false,
colProps: {
span: 12,
},
},
{
label: '实例名称',
field: 'mpName',
component: 'Input',
required: true,
colProps: {
span: 12,
},
componentProps: {
placeholder: '请选择下方模型以生成实例',
},
rules: [{ required: true, message: '请选择下方模型以生成实例' }],
},
{
label: '运行周期',
field: 'intervalTime',
component: 'Input',
required: true,
defaultValue: 30,
colProps: {
span: 6,
},
},
{
label: '计算组',
field: 'group',
component: 'Select',
componentProps: {
options: [],
},
colProps: {
span: 6,
},
required: true,
},
{
label: '版本号',
field: 'modelVersionId',
component: 'Select',
componentProps: {
// api: getModelVersionList,
// labelField: 'version',
// valueField: 'id',
// params: {},
options: [],
},
colProps: {
span: 12,
},
required: true,
},
{
label: '是否存储',
field: 'isStore',
component: 'RadioGroup',
defaultValue: '1',
componentProps: {
options: [
{
label: '是',
value: '1',
},
{
label: '否',
value: '0',
},
],
},
colProps: {
span: 12,
},
required: true,
},
]
export const updateInstantForm: FormSchema[] = [
{
label: '编号',
field: 'mpId',
component: 'Input',
required: true,
show: false,
},
{
label: '实例名称',
field: 'mpName',
component: 'Input',
required: true,
componentProps: {
placeholder: '请输入实例名称',
},
rules: [{ required: true, message: '请输入实例名称' }],
},
{
label: '计算组',
field: 'calcGroup',
component: 'Select',
componentProps: {
options: [],
},
required: true,
},
{
label: '版本号',
field: 'modelVersionId',
component: 'Select',
componentProps: {
options: [],
},
required: true,
},
]
export const InstantBasicInfo: any[] = [
{
label: '实例名称',
field: 'mpName',
},
{
label: '创建人',
field: 'creator',
},
{
label: '创建时间',
field: 'createTime',
},
{
label: '最近修改人',
field: 'updater',
},
{
label: '最近修改时间',
field: 'updateTime',
},
{
label: '算法',
field: 'algorithm_shortname',
},
// modelInfo中的字段
{
label: '训练采样间隔',
field: 'sampling',
},
{
label: '参数个数',
field: 'pointInfo',
},
{
label: '最小主元贡献率',
field: 'rate',
},
{
label: '主元个数',
field: 'principal',
},
{
label: '模型精度',
field: 'rate',
},
]
export const detailColumns: BasicColumn[] = [
{
title: '编号',
dataIndex: 'id',
width: 80,
fixed: 'left',
},
{
title: '测点编码',
dataIndex: 'inputInfo',
width: 150,
fixed: 'left',
},
{
title: '测点名称',
dataIndex: 'inputName',
width: 200,
fixed: 'left',
},
{
title: '单位',
dataIndex: 'unit',
width: 50,
fixed: 'left',
},
{
title: '重构值测点',
dataIndex: 'outPointInfo',
width: 200,
},
{
title: '偏差值测点',
dataIndex: 'biasPointInfo',
width: 200,
},
{
title: '错误状态测点',
dataIndex: 'faultVariablePointInfo',
width: 200,
},
]