Merge branch 'master' of https://git.code.tencent.com/xian-ncc-da/xian-ncc-da-client
This commit is contained in:
commit
9ca21665cf
@ -7,6 +7,7 @@ interface Item {
|
||||
id: number;
|
||||
name: string;
|
||||
proto: string;
|
||||
type: string;
|
||||
createdAt: string;
|
||||
updateAt: string;
|
||||
creatorId?: number;
|
||||
@ -76,6 +77,10 @@ export function saveDraft(
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
export function saveAsDraft(id: number, data: { name: string }) {
|
||||
return api.post(`${DraftUriBase}/${id}/saveAs`, data);
|
||||
export async function saveAsDraft(
|
||||
id: number,
|
||||
data: { name: string; proto: string }
|
||||
): Promise<Item> {
|
||||
const response = await api.post(`${DraftUriBase}/${id}/saveAs`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { fromUint8Array, toUint8Array } from 'js-base64';
|
||||
import { IPointData, Point } from 'pixi.js';
|
||||
import { IscsFan } from 'src/graphics/iscs-fan/IscsFan';
|
||||
import { IscsFanDraw } from 'src/graphics/iscs-fan/IscsFanDrawAssistant';
|
||||
import { Link } from 'src/graphics/link/Link';
|
||||
import { LinkDraw } from 'src/graphics/link/LinkDrawAssistant';
|
||||
import { Rect } from 'src/graphics/rect/Rect';
|
||||
@ -107,8 +106,16 @@ export function destroyDrawApp(): void {
|
||||
export function initDrawApp(dom: HTMLElement): JlDrawApp {
|
||||
drawApp = new JlDrawApp(dom);
|
||||
const app = drawApp;
|
||||
app.setOptions({
|
||||
drawAssistants: [
|
||||
//根据草稿图类型加载绘图工具
|
||||
const draftType = useDrawStore().$state.draftType;
|
||||
let drawAssistants: (
|
||||
| PlatformDraw
|
||||
| StationDraw
|
||||
| SignalDraw
|
||||
| TurnoutDraw
|
||||
)[] = [];
|
||||
if (draftType === 'Line') {
|
||||
drawAssistants = [
|
||||
new PlatformDraw(app, () => {
|
||||
return new PlatformData();
|
||||
}),
|
||||
@ -124,7 +131,52 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
|
||||
// new TrainDraw(app, () => {
|
||||
// return new TrainData();
|
||||
// }),
|
||||
],
|
||||
];
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyP',
|
||||
onPress: () => {
|
||||
app.interactionPlugin(Platform.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyT',
|
||||
onPress: () => {
|
||||
console.log(app.interactionPlugin(Turnout.Type));
|
||||
app.interactionPlugin(Turnout.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyO',
|
||||
onPress: () => {
|
||||
app.interactionPlugin(Station.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyH',
|
||||
onPress: () => {
|
||||
app.interactionPlugin(Signal.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
// app.addKeyboardListener(
|
||||
// new KeyListener({
|
||||
// value: 'KeyR',
|
||||
// onPress: () => {
|
||||
// app.interactionPlugin(Train.Type).resume();
|
||||
// },
|
||||
// })
|
||||
// );
|
||||
}
|
||||
|
||||
app.setOptions({
|
||||
drawAssistants: drawAssistants,
|
||||
});
|
||||
|
||||
// 画布右键菜单
|
||||
@ -144,61 +196,35 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
|
||||
};
|
||||
DefaultCanvasMenu.open(e.global);
|
||||
});
|
||||
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyP',
|
||||
onPress: () => {
|
||||
app.interactionPlugin(Platform.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyT',
|
||||
onPress: () => {
|
||||
console.log(app.interactionPlugin(Turnout.Type));
|
||||
app.interactionPlugin(Turnout.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyO',
|
||||
onPress: () => {
|
||||
app.interactionPlugin(Station.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyH',
|
||||
onPress: () => {
|
||||
app.interactionPlugin(Signal.Type).resume();
|
||||
},
|
||||
})
|
||||
);
|
||||
// app.addKeyboardListener(
|
||||
// new KeyListener({
|
||||
// value: 'KeyR',
|
||||
// onPress: () => {
|
||||
// app.interactionPlugin(Train.Type).resume();
|
||||
// },
|
||||
// })
|
||||
// );
|
||||
app.addKeyboardListener(
|
||||
new KeyListener({
|
||||
value: 'KeyS',
|
||||
global: true,
|
||||
combinations: [CombinationKey.Ctrl],
|
||||
onPress: () => {
|
||||
saveDrawDatas(app);
|
||||
saveDrawToServer(app);
|
||||
},
|
||||
})
|
||||
);
|
||||
return drawApp;
|
||||
}
|
||||
|
||||
export function saveDrawToServer(app: JlDrawApp) {
|
||||
const base64 = saveDrawDatas(app);
|
||||
const drawStore = useDrawStore();
|
||||
const id = drawStore.draftId;
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
saveDraft(id as number, { proto: base64 })
|
||||
.then(() => {
|
||||
successNotify('保存数据成功!');
|
||||
})
|
||||
.catch((err) => {
|
||||
errorNotify(err.message, err);
|
||||
});
|
||||
}
|
||||
|
||||
// const StorageKey = 'graphic-storage';
|
||||
export function saveDrawDatas(app: JlDrawApp) {
|
||||
const storage = new graphicData.RtssGraphicStorage();
|
||||
@ -238,18 +264,7 @@ export function saveDrawDatas(app: JlDrawApp) {
|
||||
const base64 = fromUint8Array(storage.serialize());
|
||||
console.log('保存数据', storage);
|
||||
// localStorage.setItem(StorageKey, base64);
|
||||
const drawStore = useDrawStore();
|
||||
const id = drawStore.draftId;
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
saveDraft(id as number, { proto: base64 })
|
||||
.then(() => {
|
||||
successNotify('保存数据成功!');
|
||||
})
|
||||
.catch((err) => {
|
||||
errorNotify('保存数据失败!', err.message);
|
||||
});
|
||||
return base64;
|
||||
}
|
||||
|
||||
export async function loadDrawDatas(app: GraphicApp) {
|
||||
|
@ -7,11 +7,11 @@
|
||||
<q-menu>
|
||||
<q-list style="min-width: 100px">
|
||||
<q-item clickable v-close-popup @click="saveAllDrawDatas">
|
||||
<q-item-section>保存并校验</q-item-section>
|
||||
<q-item-section>保存</q-item-section>
|
||||
</q-item>
|
||||
<!-- <q-item clickable v-close-popup @click="saveAsDialog = true">
|
||||
<q-item clickable v-close-popup @click="saveAsDialog = true">
|
||||
<q-item-section>另存为</q-item-section>
|
||||
</q-item> -->
|
||||
</q-item>
|
||||
<q-item clickable v-close-popup>
|
||||
<q-item-section>一键关联</q-item-section>
|
||||
</q-item>
|
||||
@ -161,13 +161,19 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import DrawProperties from 'src/components/draw-app/DrawProperties.vue';
|
||||
import { getDrawApp, loadDrawDatas, saveDrawDatas } from 'src/drawApp';
|
||||
import {
|
||||
getDrawApp,
|
||||
loadDrawDatas,
|
||||
saveDrawDatas,
|
||||
saveDrawToServer,
|
||||
} from 'src/drawApp';
|
||||
import { JlDrawApp } from 'src/jl-graphic';
|
||||
import { useDrawStore } from 'src/stores/draw-store';
|
||||
import { onMounted, onUnmounted, reactive, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { errorNotify, successNotify } from 'src/utils/CommonNotify';
|
||||
import { saveAsDraft } from 'src/api/DraftApi';
|
||||
import { ApiError } from 'src/boot/axios';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@ -273,7 +279,7 @@ function onResize() {
|
||||
}
|
||||
function saveAllDrawDatas() {
|
||||
const drawApp = getDrawApp();
|
||||
saveDrawDatas(drawApp as JlDrawApp);
|
||||
saveDrawToServer(drawApp as JlDrawApp);
|
||||
}
|
||||
|
||||
function backConfirm() {
|
||||
@ -285,15 +291,20 @@ const saveAsName = ref('');
|
||||
|
||||
async function saveAs(name: string) {
|
||||
try {
|
||||
const record = await saveAsDraft(+route.params.id as number, { name });
|
||||
console.log('🚀 ~ file: DrawLayout.vue:288 ~ saveAs ~ record:', record);
|
||||
// if (record) {
|
||||
// router.replace(`/painting/${record.id}`);
|
||||
// }
|
||||
const drawApp = getDrawApp();
|
||||
const base64 = saveDrawDatas(drawApp as JlDrawApp);
|
||||
const record = await saveAsDraft(+route.params.id as number, {
|
||||
name,
|
||||
proto: base64,
|
||||
});
|
||||
if (record) {
|
||||
router.replace(`/painting/${record.id}/${record.type}`);
|
||||
}
|
||||
successNotify('另存为成功');
|
||||
saveAsDialog.value = false;
|
||||
} catch (e) {
|
||||
errorNotify('另存为异常', e);
|
||||
const error = e as ApiError;
|
||||
errorNotify(error.title, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user