添加数据校验

This commit is contained in:
fan 2023-07-19 10:42:35 +08:00
parent 9a74810fac
commit b7302e3cfe
3 changed files with 47 additions and 2 deletions

View File

@ -37,7 +37,9 @@ export async function addTrain(data: {
return response.data;
}
/**
*
*
* @param simulationId 仿id
* @param trainId
*/
export async function removeTrain(data: {
simulationId: string;
@ -46,3 +48,7 @@ export async function removeTrain(data: {
const response = await api.post(`${UriBase}/train/remove`, data);
return response.data;
}
export function checkMapData(data: { mapProto: string }) {
return api.post(`${UriBase}/check/data`, data);
}

View File

@ -74,7 +74,8 @@ import {
LogicSectionTemplate,
} from 'src/graphics/logicSection/LogicSection';
import { LogicSectionData } from './graphics/LogicSectionInteraction';
import { Notify } from 'quasar';
import { Notify, Dialog } from 'quasar';
import { checkMapData } from 'src/api/Simulation';
// export function fromStoragePoint(p: graphicData.Point): Point {
// return new Point(p.x, p.y);
@ -320,6 +321,35 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
return drawApp;
}
export function checkDataToServer(app: JlDrawApp) {
const base64 = saveDrawDatas(app);
checkMapData({ mapProto: base64 })
.then((res) => {
if (res.data.success) {
successNotify('校验数据成功!');
} else {
// console.log(res.data.errors);
// const errors = res.data.error.splic
let message = '';
res.data.errors.forEach((err: string) => {
message += `<div>${err};<div>`;
});
Dialog.create({
title: '校验失败',
message: message,
html: true,
persistent: true,
ok: {
ali: 'center',
},
});
}
})
.catch((err) => {
errorNotify(err.message, err);
});
}
export function saveDrawToServer(app: JlDrawApp) {
const base64 = saveDrawDatas(app);
const drawStore = useDrawStore();

View File

@ -12,6 +12,9 @@
<q-item clickable v-close-popup @click="saveAsDialog = true">
<q-item-section>另存为</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="handleCheckData">
<q-item-section>数据校验</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="buildRelations">
<q-item-section>一键关联</q-item-section>
</q-item>
@ -191,6 +194,7 @@ import {
loadDrawDatas,
saveDrawDatas,
saveDrawToServer,
checkDataToServer,
} from 'src/drawApp';
import { JlDrawApp } from 'src/jl-graphic';
import { useDrawStore } from 'src/stores/draw-store';
@ -329,6 +333,11 @@ function saveAllDrawDatas() {
saveDrawToServer(drawApp as JlDrawApp);
}
function handleCheckData() {
const drawApp = getDrawApp();
checkDataToServer(drawApp as JlDrawApp);
}
function buildRelations() {
const app = getDrawApp();
app?.detectRelations();