Browse Source

fix: 统一代码风格,修复部分格式问题

pull/79/head^2
chenjiale 1 month ago
parent
commit
d59c93790b
  1. 640
      src/views/model/train/index.vue

640
src/views/model/train/index.vue

@ -1,10 +1,10 @@
<script lang="ts"> <script lang="ts">
import type { ComponentPublicInstance } from 'vue' import type { ComponentPublicInstance } from "vue";
import type { Dayjs } from 'dayjs' import type { Dayjs } from "dayjs";
import { debounce } from 'lodash-es' import { debounce } from "lodash-es";
import dayjs from 'dayjs' import dayjs from "dayjs";
import { computed, defineComponent, onMounted, ref, toRaw, watch } from 'vue' import { computed, defineComponent, onMounted, ref, toRaw, watch } from "vue";
import { useRoute } from 'vue-router' import { useRoute } from "vue-router";
import { import {
Button, Button,
Card, Card,
@ -23,22 +23,22 @@ import {
Steps, Steps,
Tabs, Tabs,
Transfer, Transfer,
} from 'ant-design-vue' } from "ant-design-vue";
import VueECharts from 'vue-echarts' import VueECharts from "vue-echarts";
import { pointTableSchema, sampleInfoTableSchema } from './data' import { pointTableSchema, sampleInfoTableSchema } from "./data";
import { BasicTable, useTable } from '@/components/Table' import { BasicTable, useTable } from "@/components/Table";
import { PageWrapper } from '@/components/Page' import { PageWrapper } from "@/components/Page";
import { import {
bottomModelApi, bottomModelApi,
modelInfoApi, modelInfoApi,
testModelApi, testModelApi,
trainModelApi, trainModelApi,
updateModelInfo, updateModelInfo,
} from '@/api/alert/model/models' } from "@/api/alert/model/models";
import { getExaHistorys } from '@/api/alert/exa/index' import { getExaHistorys } from "@/api/alert/exa/index";
import { useECharts } from '@/hooks/web/useECharts' import { useECharts } from "@/hooks/web/useECharts";
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from "@/hooks/web/useMessage";
import { pointListApi } from '@/api/alert/model/select' import { pointListApi } from "@/api/alert/model/select";
export default defineComponent({ export default defineComponent({
components: { components: {
@ -67,152 +67,151 @@ export default defineComponent({
ACol: Col, ACol: Col,
}, },
setup() { setup() {
const { createMessage } = useMessage() const { createMessage } = useMessage();
const route = useRoute() const route = useRoute();
const id = route.params.id const id = route.params.id;
const model = ref(null) const model = ref(null);
const brushActivated = ref<Set<number>>(new Set()) const brushActivated = ref<Set<number>>(new Set());
const spinning = ref(false) const spinning = ref(false);
let trainTimeCopy = '' let trainTimeCopy = "";
const fetchModelInfo = async () => { const fetchModelInfo = async () => {
const modelInfo = await modelInfoApi(id) const modelInfo = await modelInfoApi(id);
model.value = modelInfo model.value = modelInfo;
trainTimeCopy = JSON.stringify(model.value.trainTime) trainTimeCopy = JSON.stringify(model.value.trainTime);
getHistory() getHistory();
} };
const pointData = computed(() => model.value?.pointInfo || []) const pointData = computed(() => model.value?.pointInfo || []);
const [pointTable] = useTable({ const [pointTable] = useTable({
columns: pointTableSchema, columns: pointTableSchema,
pagination: true, pagination: true,
dataSource: pointData, dataSource: pointData,
scroll: { y: 300 }, scroll: { y: 300 },
}) });
const trainTime = computed(() => model.value?.trainTime || []) const trainTime = computed(() => model.value?.trainTime || []);
const [trainTimeTable] = useTable({ const [trainTimeTable] = useTable({
columns: sampleInfoTableSchema, columns: sampleInfoTableSchema,
dataSource: trainTime, dataSource: trainTime,
scroll: { y: 300 }, scroll: { y: 300 },
}) });
const activeKey = ref('1') const activeKey = ref("1");
type RangeValue = [Dayjs, Dayjs] type RangeValue = [Dayjs, Dayjs];
const currentDate: Dayjs = dayjs() // const currentDate: Dayjs = dayjs()
const lastMonthDate: Dayjs = currentDate.subtract(1, 'day') // const lastMonthDate: Dayjs = currentDate.subtract(1, 'day')
const rangeValue: RangeValue = [ const currentDate: Dayjs = dayjs("2023-10-29 00:00:00");
lastMonthDate, const lastMonthDate: Dayjs = dayjs("2023-10-28 16:00:00");
currentDate, const rangeValue: RangeValue = [lastMonthDate, currentDate];
] const historyTime = ref<RangeValue>(rangeValue);
const historyTime = ref<RangeValue>(rangeValue) const historyList = ref<any[]>([]);
const historyList = ref<any[]>([]) const echartsRefs = ref<any[]>([]);
const echartsRefs = ref<any[]>([])
async function getHistory() { async function getHistory() {
if (!historyTime.value) if (!historyTime.value) return;
return spinning.value = true;
spinning.value = true
if (model.value.para) { if (model.value.para) {
getTestData() getTestData();
} } else {
else {
const params = { const params = {
startTime: historyTime.value[0].format('YYYY-MM-DD HH:mm:ss'), startTime: historyTime.value[0].format("YYYY-MM-DD HH:mm:ss"),
endTime: historyTime.value[1].format('YYYY-MM-DD HH:mm:ss'), endTime: historyTime.value[1].format("YYYY-MM-DD HH:mm:ss"),
itemName: model.value?.pointInfo itemName: model.value?.pointInfo
.map(item => item.pointId) .map((item) => item.pointId)
.join(','), .join(","),
interval: model.value.sampling, interval: model.value.sampling,
} };
const history = await getExaHistorys(params) const history = await getExaHistorys(params);
historyList.value = history.map((item, index) => { historyList.value = history.map((item, index) => {
const point = model.value?.pointInfo[index] const point = model.value?.pointInfo[index];
return { return {
data: [item], data: [item],
name: `${index + 1}.${point?.description}(${point?.pointId})`, name: `${index + 1}.${point?.description}(${point?.pointId})`,
} };
}) });
echartsRefs.value = Array.from({ length: historyList.value.length }) echartsRefs.value = Array.from({ length: historyList.value.length });
brushActivated.value = new Set() brushActivated.value = new Set();
} }
spinning.value = false spinning.value = false;
} }
async function getTestData() { async function getTestData() {
const params = { const params = {
Model_id: 530, Model_id: 530,
version: model.value?.Cur_Version ? model.value?.Cur_Version : 'v-test', version: model.value?.Cur_Version ? model.value?.Cur_Version : "v-test",
Test_Data: { Test_Data: {
time: historyTime.value time: historyTime.value
.map(t => dayjs(t).format('YYYY-MM-DD HH:mm:ss')) .map((t) => dayjs(t).format("YYYY-MM-DD HH:mm:ss"))
.join(','), .join(","),
points: model.value.pointInfo.map(t => t.pointId).join(','), points: model.value.pointInfo.map((t) => t.pointId).join(","),
interval: model.value.sampling * 1000, interval: model.value.sampling * 1000,
}, },
} };
const result = await testModelApi(params) const result = await testModelApi(params);
const sampleData = result.sampleData const sampleData = result.sampleData;
const reconData = result.reconData const reconData = result.reconData;
const xData = generateTimeList( const xData = generateTimeList(
historyTime.value, historyTime.value,
model.value.sampling * 1000, model.value.sampling * 1000
) );
historyList.value = sampleData.map((item, index) => { historyList.value = sampleData.map((item, index) => {
const point = model.value?.pointInfo[index] const point = model.value?.pointInfo[index];
return { return {
data: [ data: [
item.map((t, i) => { item.map((t, i) => {
return [xData[i], t] return [xData[i], t];
}), }),
reconData[index].map((t, i) => { reconData[index].map((t, i) => {
return [xData[i], t] return [xData[i], t];
}), }),
], ],
name: `${index + 1}.${point?.description}(${point?.pointId})`, name: `${index + 1}.${point?.description}(${point?.pointId})`,
} };
}) });
brushActivated.value = new Set() brushActivated.value = new Set();
} }
function generateTimeList(time: RangeValue, intervalMs: number) { function generateTimeList(time: RangeValue, intervalMs: number) {
const [t1, t2] = time const [t1, t2] = time;
const count = Math.floor(t2.diff(t1, 'millisecond') / intervalMs) + 1 const count = Math.floor(t2.diff(t1, "millisecond") / intervalMs) + 1;
return Array.from({ length: count }, (_, i) => t1.add(i * intervalMs, 'millisecond').valueOf()) return Array.from({ length: count }, (_, i) =>
t1.add(i * intervalMs, "millisecond").valueOf()
);
} }
function getOption(item: any) { function getOption(item: any) {
const name = ['测量值', '模型值', ''] const name = ["测量值", "模型值", ""];
const color = ['blue', '#ff6f00', 'red'] const color = ["blue", "#ff6f00", "red"];
const yIndex = [0, 0, 1] const yIndex = [0, 0, 1];
const option = { const option = {
xAxis: { xAxis: {
type: 'time', type: "time",
axisLabel: { axisLabel: {
formatter(value) { formatter(value) {
const date = new Date(value) const date = new Date(value);
return date.toLocaleString() return date.toLocaleString();
}, },
}, },
}, },
yAxis: [{ type: 'value' }, { type: 'value', max: 10, show: false }], yAxis: [{ type: "value" }, { type: "value", max: 10, show: false }],
series: item.data.map((item, index) => { series: item.data.map((item, index) => {
return { return {
data: item, data: item,
type: 'line', type: "line",
smooth: true, smooth: true,
symbol: 'none', symbol: "none",
name: name[index], name: name[index],
color: color[index], color: color[index],
yAxisIndex: yIndex[index], yAxisIndex: yIndex[index],
} };
}), }),
legend: {}, legend: {},
dataZoom: [{}], dataZoom: [{}],
brush: { brush: {
toolbox: ['lineX'], toolbox: ["lineX"],
xAxisIndex: 0, xAxisIndex: 0,
brushType: 'lineX', brushType: "lineX",
}, },
grid: [ grid: [
{ {
@ -222,242 +221,234 @@ export default defineComponent({
top: 30, top: 30,
}, },
], ],
} };
return option return option;
} }
function setChartRef( function setChartRef(
el: Element | ComponentPublicInstance | null, el: Element | ComponentPublicInstance | null,
index: number, index: number
) { ) {
let dom: HTMLElement | null = null let dom: HTMLElement | null = null;
if (el) { if (el) {
if ('$el' in el && (el as any).$el instanceof HTMLElement) if ("$el" in el && (el as any).$el instanceof HTMLElement)
dom = (el as any).$el dom = (el as any).$el;
else if (el instanceof HTMLElement) else if (el instanceof HTMLElement) dom = el;
dom = el
} }
if (dom) if (dom) useECharts(ref(dom as HTMLDivElement));
useECharts(ref(dom as HTMLDivElement))
} }
function setEchartsRef(el: any, index: number) { function setEchartsRef(el: any, index: number) {
if (el) if (el) echartsRefs.value[index] = el;
echartsRefs.value[index] = el
} }
const isInitBrush = ref(true) const isInitBrush = ref(true);
function onChartFinished(index: number) { function onChartFinished(index: number) {
if (brushActivated.value.has(index)) if (brushActivated.value.has(index)) return;
return const chart = echartsRefs.value[index];
const chart = echartsRefs.value[index] if (!chart) return;
if (!chart)
return
chart.dispatchAction({ chart.dispatchAction({
type: 'takeGlobalCursor', type: "takeGlobalCursor",
key: 'brush', key: "brush",
brushOption: { brushOption: {
brushType: 'lineX', brushType: "lineX",
brushMode: 'multiple', brushMode: "multiple",
}, },
}) });
const areas = (model.value?.trainTime || []).map(row => ({ const areas = (model.value?.trainTime || []).map((row) => ({
brushType: 'lineX', brushType: "lineX",
xAxisIndex: 0, xAxisIndex: 0,
coordRange: [ coordRange: [
dayjs(row.st).format('YYYY-MM-DD HH:mm:ss'), dayjs(row.st).format("YYYY-MM-DD HH:mm:ss"),
dayjs(row.et).format('YYYY-MM-DD HH:mm:ss'), dayjs(row.et).format("YYYY-MM-DD HH:mm:ss"),
], ],
})) }));
chart.dispatchAction({ chart.dispatchAction({
type: 'brush', type: "brush",
areas, areas,
}) });
brushActivated.value.add(index) brushActivated.value.add(index);
isInitBrush.value = true isInitBrush.value = true;
} }
onMounted(async () => { onMounted(async () => {
await fetchModelInfo() await fetchModelInfo();
}) });
const onBrushSelected = debounce((params) => { const onBrushSelected = debounce((params) => {
if (isInitBrush.value) { if (isInitBrush.value) {
isInitBrush.value = false isInitBrush.value = false;
return return;
} }
const selected = params.batch[0].selected if (!isInitBrush.value && model?.Cur_Version != "v-test") {
return;
}
const selected = params.batch[0].selected;
if (selected.length > 0) { if (selected.length > 0) {
const areas = mergeAreas(params.batch[0].areas).map(area => ({ const areas = mergeAreas(params.batch[0].areas).map((area) => ({
brushType: area.brushType, brushType: area.brushType,
xAxisIndex: 0, xAxisIndex: 0,
coordRange: area.coordRange, coordRange: area.coordRange,
})) }));
const trainTime = areas.map((area) => { const trainTime = areas.map((area) => {
const [stRaw, etRaw] = area.coordRange const [stRaw, etRaw] = area.coordRange;
const st = typeof stRaw === 'string' ? dayjs(stRaw).valueOf() : stRaw const st = typeof stRaw === "string" ? dayjs(stRaw).valueOf() : stRaw;
const et = typeof etRaw === 'string' ? dayjs(etRaw).valueOf() : etRaw const et = typeof etRaw === "string" ? dayjs(etRaw).valueOf() : etRaw;
console.log('Selected area:', { st, et }, area) console.log("Selected area:", { st, et }, area);
return { return {
st: dayjs(st).format('YYYY-MM-DD HH:mm:ss'), st: dayjs(st).format("YYYY-MM-DD HH:mm:ss"),
et: dayjs(et).format('YYYY-MM-DD HH:mm:ss'), et: dayjs(et).format("YYYY-MM-DD HH:mm:ss"),
duration: Math.round((et - st) / 1000), duration: Math.round((et - st) / 1000),
number: '', // number: "", //
filter: '', // filter: "", //
mode: '', // mode: "", //
} };
}) });
console.log('Selected train time:', trainTime) console.log("Selected train time:", trainTime);
if (trainTimeCopy === JSON.stringify(trainTime)) if (trainTimeCopy === JSON.stringify(trainTime)) return;
return model.value.trainTime = trainTime;
model.value.trainTime = trainTime trainTimeCopy = JSON.stringify(trainTime);
trainTimeCopy = JSON.stringify(trainTime)
echartsRefs.value.forEach((chart, index) => { echartsRefs.value.forEach((chart, index) => {
if (chart) { if (chart) {
chart.dispatchAction({ chart.dispatchAction({
type: 'brush', type: "brush",
areas, areas,
}) });
isInitBrush.value = true isInitBrush.value = true;
} }
}) });
updateModelInfoDebounced() updateModelInfoDebounced();
} }
}, 300) }, 300);
function mergeAreas(areas: any[]) { function mergeAreas(areas: any[]) {
if (!areas.length) if (!areas.length) return [];
return []
// brushType xAxisIndex // brushType xAxisIndex
const sorted = [...areas].sort( const sorted = [...areas].sort(
(a, b) => a.coordRange[0] - b.coordRange[0], (a, b) => a.coordRange[0] - b.coordRange[0]
) );
const merged: any[] = [] const merged: any[] = [];
for (const area of sorted) { for (const area of sorted) {
if ( if (
merged.length merged.length &&
&& merged[merged.length - 1].brushType === area.brushType merged[merged.length - 1].brushType === area.brushType &&
&& merged[merged.length - 1].xAxisIndex === area.xAxisIndex merged[merged.length - 1].xAxisIndex === area.xAxisIndex &&
&& merged[merged.length - 1].coordRange[1] >= area.coordRange[0] merged[merged.length - 1].coordRange[1] >= area.coordRange[0]
) { ) {
// //
merged[merged.length - 1].coordRange[1] = Math.max( merged[merged.length - 1].coordRange[1] = Math.max(
merged[merged.length - 1].coordRange[1], merged[merged.length - 1].coordRange[1],
area.coordRange[1], area.coordRange[1]
) );
} } else {
else {
// //
merged.push({ merged.push({
brushType: area.brushType, brushType: area.brushType,
xAxisIndex: area.xAxisIndex, xAxisIndex: area.xAxisIndex,
coordRange: [...area.coordRange], coordRange: [...area.coordRange],
}) });
} }
} }
return merged return merged;
} }
// //
const updateModelInfoDebounced = debounce(() => { const updateModelInfoDebounced = debounce(() => {
const val = toRaw(model.value) const val = toRaw(model.value);
if (val && val.id) if (val && val.id) updateModelInfo(val);
updateModelInfo(val) }, 500);
}, 500)
function handleDeleteTrainTime(index: number) { function handleDeleteTrainTime(index: number) {
if (!model.value?.trainTime) if (!model.value?.trainTime) return;
return
// //
model.value.trainTime = [ model.value.trainTime = [
...model.value.trainTime.slice(0, index), ...model.value.trainTime.slice(0, index),
...model.value.trainTime.slice(index + 1), ...model.value.trainTime.slice(index + 1),
] ];
// brush // brush
const areas = (model.value.trainTime || []).map(row => ({ const areas = (model.value.trainTime || []).map((row) => ({
brushType: 'lineX', brushType: "lineX",
xAxisIndex: 0, xAxisIndex: 0,
coordRange: [dayjs(row.st).valueOf(), dayjs(row.et).valueOf()], coordRange: [dayjs(row.st).valueOf(), dayjs(row.et).valueOf()],
})) }));
echartsRefs.value.forEach((chart) => { echartsRefs.value.forEach((chart) => {
if (chart) { if (chart) {
chart.dispatchAction({ chart.dispatchAction({
type: 'brush', type: "brush",
areas, areas,
}) });
isInitBrush.value = true isInitBrush.value = true;
} }
}) });
updateModelInfoDebounced() updateModelInfoDebounced();
} }
async function clearModel() { async function clearModel() {
model.value.para = null model.value.para = null;
updateModelInfoDebounced() updateModelInfoDebounced();
await getHistory() await getHistory();
} }
async function trainModel() { async function trainModel() {
const modelInfo = model.value const modelInfo = model.value;
if (!modelInfo || !modelInfo.id) { if (!modelInfo || !modelInfo.id) {
console.error('模型信息不完整,无法训练') console.error("模型信息不完整,无法训练");
return return;
} }
const pointInfo = modelInfo.pointInfo || [] const pointInfo = modelInfo.pointInfo || [];
if (pointInfo.length === 0) { if (pointInfo.length === 0) {
console.error('模型参数点信息为空,无法训练') console.error("模型参数点信息为空,无法训练");
return return;
} }
const params = { const params = {
conditon: modelInfo.alarmmodelset?.alarmcondition || '1==1', conditon: modelInfo.alarmmodelset?.alarmcondition || "1==1",
Hyper_para: { Hyper_para: {
percent: modelInfo.rate, percent: modelInfo.rate,
}, },
Train_Data: { Train_Data: {
points: pointInfo.map(item => item.pointId).join(','), points: pointInfo.map((item) => item.pointId).join(","),
dead: pointInfo.map(item => (item.dead ? '1' : '0')).join(','), dead: pointInfo.map((item) => (item.dead ? "1" : "0")).join(","),
limit: pointInfo.map(item => (item.limit ? '1' : '0')).join(','), limit: pointInfo.map((item) => (item.limit ? "1" : "0")).join(","),
uplow: pointInfo uplow: pointInfo
.map( .map(
item => (item) =>
`${item.Upper ? item.Upper : null},${ `${item.Upper ? item.Upper : null},${
item.Lower ? item.Lower : null item.Lower ? item.Lower : null
}`, }`
) )
.join(';'), .join(";"),
interval: modelInfo.sampling * 1000, interval: modelInfo.sampling * 1000,
time: modelInfo.trainTime time: modelInfo.trainTime
.map(item => `${item.st},${item.et}`) .map((item) => `${item.st},${item.et}`)
.join(';'), .join(";"),
}, },
type: 'PCA', type: "PCA",
smote_config: [], smote_config: [],
smote: true, smote: true,
} };
spinning.value = true spinning.value = true;
try { try {
const response = await trainModelApi(params) const response = await trainModelApi(params);
model.value.para = response model.value.para = response;
model.value.principal = response.Model_info.K model.value.principal = response.Model_info.K;
updateModelInfoDebounced() updateModelInfoDebounced();
getTestData() getTestData();
createMessage.success('模型训练成功') createMessage.success("模型训练成功");
} } catch (error) {
catch (error) { console.error("模型训练失败:", error);
console.error('模型训练失败:', error) createMessage.error("模型训练失败");
createMessage.error('模型训练失败')
} }
spinning.value = false spinning.value = false;
} }
const editForm = ref({ const editForm = ref({
index: -1, index: -1,
Upper: '', Upper: "",
Lower: '', Lower: "",
lowerBound: '', lowerBound: "",
upperBound: '', upperBound: "",
dead: true, dead: true,
limit: false, limit: false,
}) });
const openEditPointModal = ref<boolean>(false) const openEditPointModal = ref<boolean>(false);
let pointEditRecord = null let pointEditRecord = null;
function editPoint() { function editPoint() {
// //
model.value.pointInfo[editForm.value.index] = { model.value.pointInfo[editForm.value.index] = {
@ -468,123 +459,130 @@ export default defineComponent({
upperBound: editForm.value.upperBound, upperBound: editForm.value.upperBound,
dead: editForm.value.dead, dead: editForm.value.dead,
limit: editForm.value.limit, limit: editForm.value.limit,
} };
updateModelInfoDebounced() updateModelInfoDebounced();
pointEditRecord.Upper = editForm.value.Upper pointEditRecord.Upper = editForm.value.Upper;
pointEditRecord.Lower = editForm.value.Lower pointEditRecord.Lower = editForm.value.Lower;
pointEditRecord.lowerBound = editForm.value.lowerBound pointEditRecord.lowerBound = editForm.value.lowerBound;
pointEditRecord.upperBound = editForm.value.upperBound pointEditRecord.upperBound = editForm.value.upperBound;
pointEditRecord.dead = editForm.value.dead pointEditRecord.dead = editForm.value.dead;
pointEditRecord.limit = editForm.value.limit pointEditRecord.limit = editForm.value.limit;
openEditPointModal.value = false openEditPointModal.value = false;
} }
function openPointModal(index, record) { function openPointModal(index, record) {
// index // index
const pageIndex = index const pageIndex = index;
// index // index
const globalIndex = model.value.pointInfo.findIndex( const globalIndex = model.value.pointInfo.findIndex(
item => item.pointId === record.pointId, (item) => item.pointId === record.pointId
) );
openEditPointModal.value = true openEditPointModal.value = true;
pointEditRecord = record pointEditRecord = record;
editForm.value = { editForm.value = {
index: globalIndex, index: globalIndex,
Upper: record?.Upper ?? '', Upper: record?.Upper ?? "",
Lower: record?.Lower ?? '', Lower: record?.Lower ?? "",
lowerBound: record?.lowerBound ?? '', lowerBound: record?.lowerBound ?? "",
upperBound: record?.upperBound ?? '', upperBound: record?.upperBound ?? "",
dead: !!record?.dead, dead: !!record?.dead,
limit: !!record?.limit, limit: !!record?.limit,
} };
} }
const mode = ref({ const mode = ref({
alarmcondition: '1==1', alarmcondition: "1==1",
alarmname: '全工况运行', alarmname: "全工况运行",
}) });
const openEditModeModal = ref<boolean>(false) const openEditModeModal = ref<boolean>(false);
function openEditMode() { function openEditMode() {
openEditModeModal.value = true openEditModeModal.value = true;
mode.value = { mode.value = {
alarmcondition: model.value?.alarmmodelset?.alarmcondition || '1==1', alarmcondition: model.value?.alarmmodelset?.alarmcondition || "1==1",
alarmname: model.value?.alarmmodelset?.alarmname || '全工况运行', alarmname: model.value?.alarmmodelset?.alarmname || "全工况运行",
} };
} }
function closeEditMode() { function closeEditMode() {
openEditModeModal.value = false openEditModeModal.value = false;
} }
function handleEditMode() { function handleEditMode() {
// //
model.value.alarmmodelset = mode.value model.value.alarmmodelset = mode.value;
updateModelInfoDebounced() updateModelInfoDebounced();
closeEditMode() closeEditMode();
} }
const openEditModelModal = ref(false) const openEditModelModal = ref(false);
const editModelForm = ref({ const editModelForm = ref({
sampling: 0, sampling: 0,
rate: 0, rate: 0,
selectedKeys: [], selectedKeys: [],
}) });
// 穿 // 穿
const transferData = ref([]) // 穿 const transferData = ref([]); // 穿
// //
async function fetchAllPoints(keyword = '') { async function fetchAllPoints(keyword = "") {
// keyword // keyword
// const res = await fetchPointsApi({ keyword }) // const res = await fetchPointsApi({ keyword })
// //
const data = await pointListApi({ keyword }) const data = await pointListApi({ keyword });
console.log('Fetched points:', data) console.log("Fetched points:", data);
transferData.value = transferData.value.filter(item => editModelForm.value.selectedKeys.includes(item.key)) transferData.value = transferData.value
.concat(data.map(item => ({ .filter((item) => editModelForm.value.selectedKeys.includes(item.key))
.concat(
data.map((item) => ({
key: item.id, key: item.id,
title: item.name, title: item.name,
}))) }))
console.log('Transfer data:', transferData.value) );
console.log("Transfer data:", transferData.value);
} }
onMounted(() => { onMounted(() => {
fetchAllPoints() fetchAllPoints();
}) });
function handleTransferSearch(dir, value) { function handleTransferSearch(dir, value) {
if (dir === 'left') { if (dir === "left") {
// //
fetchAllPoints(value) fetchAllPoints(value);
} } else {
else {
// //
transferData.value = (model.value?.pointInfo || []) transferData.value = (model.value?.pointInfo || [])
.filter(item => .filter(
editModelForm.value.selectedKeys.includes(`${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`) (item) =>
&& (`${item.description || ''}(${item.pointId})`).includes(value), editModelForm.value.selectedKeys.includes(
`${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`
) && `${item.description || ""}(${item.pointId})`.includes(value)
) )
.map(item => ({ .map((item) => ({
key: `${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`, key: `${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`,
title: `${item.description || ''} (${item.pointId})`, title: `${item.description || ""} (${item.pointId})`,
})) }));
} }
} }
function openEditModel() { function openEditModel() {
editModelForm.value.sampling = model.value?.sampling || 0 editModelForm.value.sampling = model.value?.sampling || 0;
editModelForm.value.rate = model.value?.rate || 0 editModelForm.value.rate = model.value?.rate || 0;
editModelForm.value.selectedKeys = (model.value?.pointInfo || []).map(item => `${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`) editModelForm.value.selectedKeys = (model.value?.pointInfo || []).map(
transferData.value = (model.value?.pointInfo || []).map(item => ({ (item) =>
`${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`
);
transferData.value = (model.value?.pointInfo || []).map((item) => ({
key: `${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`, key: `${item.description}|${item.pointId}|${item.unit}|${item.Lower}|${item.Upper}`,
title: `${item.description || ''} (${item.pointId})`, title: `${item.description || ""} (${item.pointId})`,
})) }));
console.log('transferData:', transferData.value) console.log("transferData:", transferData.value);
openEditModelModal.value = true openEditModelModal.value = true;
} }
function handleEditModelOk() { function handleEditModelOk() {
model.value.sampling = editModelForm.value.sampling model.value.sampling = editModelForm.value.sampling;
model.value.rate = editModelForm.value.rate model.value.rate = editModelForm.value.rate;
model.value.pointInfo = editModelForm.value.selectedKeys.map((key) => { model.value.pointInfo = editModelForm.value.selectedKeys.map((key) => {
const [description, pointId, unit, Lower, Upper] = key.split('|') const [description, pointId, unit, Lower, Upper] = key.split("|");
return { return {
description, description,
pointId, pointId,
@ -593,28 +591,27 @@ export default defineComponent({
Upper, Upper,
dead: true, dead: true,
limit: false, limit: false,
} };
}) });
clearModel() clearModel();
openEditModelModal.value = false openEditModelModal.value = false;
} }
function handleEditModelCancel() { function handleEditModelCancel() {
openEditModelModal.value = false openEditModelModal.value = false;
} }
async function bottomModel() { async function bottomModel() {
if (!model.value.para) { if (!model.value.para) {
createMessage.error('模型未训练,无法下装') createMessage.error("模型未训练,无法下装");
return return;
} }
try { try {
const response = await bottomModelApi(model.value.id) const response = await bottomModelApi(model.value.id);
model.value = response model.value = response;
createMessage.success('模型下装成功') createMessage.success("模型下装成功");
} } catch (error) {
catch (error) { console.error("底层模型获取失败:", error);
console.error('底层模型获取失败:', error) createMessage.error("底层模型获取失败");
createMessage.error('底层模型获取失败')
} }
} }
@ -653,9 +650,9 @@ export default defineComponent({
handleEditModelOk, handleEditModelOk,
handleEditModelCancel, handleEditModelCancel,
bottomModel, bottomModel,
} };
}, },
}) });
</script> </script>
<template> <template>
@ -672,9 +669,7 @@ export default defineComponent({
<a-descriptions-item label="版本"> <a-descriptions-item label="版本">
{{ model?.Cur_Version || "v-test" }} {{ model?.Cur_Version || "v-test" }}
</a-descriptions-item> </a-descriptions-item>
<a-descriptions-item label="评估报告"> <a-descriptions-item label="评估报告"> 暂无 </a-descriptions-item>
暂无
</a-descriptions-item>
<a-descriptions-item label="创建人"> <a-descriptions-item label="创建人">
{{ model?.founder }} {{ model?.founder }}
</a-descriptions-item> </a-descriptions-item>
@ -713,7 +708,7 @@ export default defineComponent({
( (
model?.trainTime.reduce( model?.trainTime.reduce(
(total, item) => total + item.duration, (total, item) => total + item.duration,
0, 0
) / 3600 ) / 3600
).toFixed(2) || "暂无" ).toFixed(2) || "暂无"
}} }}
@ -785,14 +780,14 @@ export default defineComponent({
> >
清除训练结果 清除训练结果
</a-button> </a-button>
<a-button type="primary" style="margin-left: 6px" @click="openEditModel">
修改模型
</a-button>
<a-button <a-button
danger type="primary"
style="margin-left: 10px" style="margin-left: 6px"
@click="bottomModel" @click="openEditModel"
> >
修改模型
</a-button>
<a-button danger style="margin-left: 10px" @click="bottomModel">
下装 下装
</a-button> </a-button>
</div> </div>
@ -856,12 +851,8 @@ export default defineComponent({
/> />
</a-form-item> </a-form-item>
<a-form-item label="清洗方式" style="margin-top: 16px"> <a-form-item label="清洗方式" style="margin-top: 16px">
<a-checkbox v-model:checked="editForm.dead"> <a-checkbox v-model:checked="editForm.dead"> 死区清洗 </a-checkbox>
死区清洗 <a-checkbox v-model:checked="editForm.limit"> 限值清洗 </a-checkbox>
</a-checkbox>
<a-checkbox v-model:checked="editForm.limit">
限值清洗
</a-checkbox>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-modal> </a-modal>
@ -922,11 +913,18 @@ export default defineComponent({
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-row> </a-row>
<div style="display: flex; justify-content: center; margin-top: 24px;margin-bottom: 10px;"> <div
style="
display: flex;
justify-content: center;
margin-top: 24px;
margin-bottom: 10px;
"
>
<a-transfer <a-transfer
v-model:target-keys="editModelForm.selectedKeys" v-model:target-keys="editModelForm.selectedKeys"
:data-source="transferData" :data-source="transferData"
:render="item => item.title" :render="(item) => item.title"
:row-key="(item) => item.key" :row-key="(item) => item.key"
:pagination="false" :pagination="false"
:show-search="true" :show-search="true"

Loading…
Cancel
Save