草稿另存为接口

This commit is contained in:
dong 2023-06-09 17:56:19 +08:00
parent b21af0985a
commit d6515cf693
3 changed files with 47 additions and 26 deletions

View File

@ -7,6 +7,7 @@ interface Item {
id: number; id: number;
name: string; name: string;
proto: string; proto: string;
type: string;
createdAt: string; createdAt: string;
updateAt: string; updateAt: string;
creatorId?: number; creatorId?: number;
@ -76,6 +77,10 @@ export function saveDraft(
* @param data * @param data
* @returns * @returns
*/ */
export function saveAsDraft(id: number, data: { name: string }) { export async function saveAsDraft(
return api.post(`${DraftUriBase}/${id}/saveAs`, data); id: number,
data: { name: string; proto: string }
): Promise<Item> {
const response = await api.post(`${DraftUriBase}/${id}/saveAs`, data);
return response.data;
} }

View File

@ -202,13 +202,29 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
global: true, global: true,
combinations: [CombinationKey.Ctrl], combinations: [CombinationKey.Ctrl],
onPress: () => { onPress: () => {
saveDrawDatas(app); saveDrawToServer(app);
}, },
}) })
); );
return drawApp; 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'; // const StorageKey = 'graphic-storage';
export function saveDrawDatas(app: JlDrawApp) { export function saveDrawDatas(app: JlDrawApp) {
const storage = new graphicData.RtssGraphicStorage(); const storage = new graphicData.RtssGraphicStorage();
@ -248,18 +264,7 @@ export function saveDrawDatas(app: JlDrawApp) {
const base64 = fromUint8Array(storage.serialize()); const base64 = fromUint8Array(storage.serialize());
console.log('保存数据', storage); console.log('保存数据', storage);
// localStorage.setItem(StorageKey, base64); // localStorage.setItem(StorageKey, base64);
const drawStore = useDrawStore(); return base64;
const id = drawStore.draftId;
if (!id) {
return;
}
saveDraft(id as number, { proto: base64 })
.then(() => {
successNotify('保存数据成功!');
})
.catch((err) => {
errorNotify('保存数据失败!', err.message);
});
} }
export async function loadDrawDatas(app: GraphicApp) { export async function loadDrawDatas(app: GraphicApp) {

View File

@ -7,11 +7,11 @@
<q-menu> <q-menu>
<q-list style="min-width: 100px"> <q-list style="min-width: 100px">
<q-item clickable v-close-popup @click="saveAllDrawDatas"> <q-item clickable v-close-popup @click="saveAllDrawDatas">
<q-item-section>保存并校验</q-item-section> <q-item-section>保存</q-item-section>
</q-item> </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-section>另存为</q-item-section>
</q-item> --> </q-item>
<q-item clickable v-close-popup> <q-item clickable v-close-popup>
<q-item-section>一键关联</q-item-section> <q-item-section>一键关联</q-item-section>
</q-item> </q-item>
@ -161,13 +161,19 @@
<script setup lang="ts"> <script setup lang="ts">
import DrawProperties from 'src/components/draw-app/DrawProperties.vue'; 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 { JlDrawApp } from 'src/jl-graphic';
import { useDrawStore } from 'src/stores/draw-store'; import { useDrawStore } from 'src/stores/draw-store';
import { onMounted, onUnmounted, reactive, ref } from 'vue'; import { onMounted, onUnmounted, reactive, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { errorNotify, successNotify } from 'src/utils/CommonNotify'; import { errorNotify, successNotify } from 'src/utils/CommonNotify';
import { saveAsDraft } from 'src/api/DraftApi'; import { saveAsDraft } from 'src/api/DraftApi';
import { ApiError } from 'src/boot/axios';
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
@ -273,7 +279,7 @@ function onResize() {
} }
function saveAllDrawDatas() { function saveAllDrawDatas() {
const drawApp = getDrawApp(); const drawApp = getDrawApp();
saveDrawDatas(drawApp as JlDrawApp); saveDrawToServer(drawApp as JlDrawApp);
} }
function backConfirm() { function backConfirm() {
@ -285,15 +291,20 @@ const saveAsName = ref('');
async function saveAs(name: string) { async function saveAs(name: string) {
try { try {
const record = await saveAsDraft(+route.params.id as number, { name }); const drawApp = getDrawApp();
console.log('🚀 ~ file: DrawLayout.vue:288 ~ saveAs ~ record:', record); const base64 = saveDrawDatas(drawApp as JlDrawApp);
// if (record) { const record = await saveAsDraft(+route.params.id as number, {
// router.replace(`/painting/${record.id}`); name,
// } proto: base64,
});
if (record) {
router.replace(`/painting/${record.id}/${record.type}`);
}
successNotify('另存为成功'); successNotify('另存为成功');
saveAsDialog.value = false; saveAsDialog.value = false;
} catch (e) { } catch (e) {
errorNotify('另存为异常', e); const error = e as ApiError;
errorNotify(error.title, e);
} }
} }