mirror of
https://github.com/Powerful-517/yys-editor.git
synced 2026-01-23 22:43:28 +00:00
迁移schema
This commit is contained in:
@@ -84,22 +84,12 @@ export interface GraphEdge {
|
|||||||
|
|
||||||
export interface GraphDocument { nodes: GraphNode[]; edges: GraphEdge[]; }
|
export interface GraphDocument { nodes: GraphNode[]; edges: GraphEdge[]; }
|
||||||
|
|
||||||
export interface FlowFile {
|
|
||||||
label: string;
|
|
||||||
name: string;
|
|
||||||
visible: boolean;
|
|
||||||
type: string; // 'FLOW'
|
|
||||||
graphRawData: GraphDocument;
|
|
||||||
transform: Transform;
|
|
||||||
createdAt?: number;
|
|
||||||
updatedAt?: number;
|
|
||||||
id?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RootDocument {
|
export interface RootDocument {
|
||||||
schemaVersion: string;
|
schemaVersion: string;
|
||||||
fileList: FlowFile[];
|
fileList: FlowFile[];
|
||||||
activeFile: string;
|
activeFile: string;
|
||||||
|
// 可以缺省,旧数据会在加载时通过名称回退
|
||||||
|
activeFileId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DefaultNodeStyle: NodeStyle = {
|
export const DefaultNodeStyle: NodeStyle = {
|
||||||
@@ -187,10 +177,8 @@ export function migrateToV1(input: any): RootDocument {
|
|||||||
const edges = Array.isArray(raw.edges) ? raw.edges : [];
|
const edges = Array.isArray(raw.edges) ? raw.edges : [];
|
||||||
return { nodes, edges };
|
return { nodes, edges };
|
||||||
};
|
};
|
||||||
|
const wrap = (files: any[], activeName?: string): RootDocument => {
|
||||||
const wrap = (files: any[], active?: string): RootDocument => ({
|
const normalizedFiles = files.map((f, i) => ({
|
||||||
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
||||||
fileList: files.map((f, i) => ({
|
|
||||||
label: f?.label ?? `File ${i + 1}`,
|
label: f?.label ?? `File ${i + 1}`,
|
||||||
name: f?.name ?? `File ${i + 1}`,
|
name: f?.name ?? `File ${i + 1}`,
|
||||||
visible: f?.visible ?? true,
|
visible: f?.visible ?? true,
|
||||||
@@ -200,9 +188,19 @@ export function migrateToV1(input: any): RootDocument {
|
|||||||
createdAt: f?.createdAt ?? now,
|
createdAt: f?.createdAt ?? now,
|
||||||
updatedAt: f?.updatedAt ?? now,
|
updatedAt: f?.updatedAt ?? now,
|
||||||
id: f?.id,
|
id: f?.id,
|
||||||
})),
|
}));
|
||||||
activeFile: active ?? (files[0]?.name ?? 'File 1'),
|
|
||||||
});
|
const fallbackName = normalizedFiles[0]?.name ?? 'File 1';
|
||||||
|
const resolvedActiveName = activeName ?? fallbackName;
|
||||||
|
const activeFile = normalizedFiles.find(f => f.name === resolvedActiveName) ?? normalizedFiles[0];
|
||||||
|
|
||||||
|
return {
|
||||||
|
schemaVersion: CURRENT_SCHEMA_VERSION,
|
||||||
|
fileList: normalizedFiles,
|
||||||
|
activeFile: resolvedActiveName,
|
||||||
|
activeFileId: activeFile?.id,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if (!input) {
|
if (!input) {
|
||||||
return wrap([{ label: 'File 1', name: 'File 1', visible: true, type: 'FLOW' }]);
|
return wrap([{ label: 'File 1', name: 'File 1', visible: true, type: 'FLOW' }]);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {defineStore} from 'pinia';
|
import {defineStore} from 'pinia';
|
||||||
import {defineStore} from 'pinia';
|
|
||||||
import {ref, computed} from 'vue';
|
import {ref, computed} from 'vue';
|
||||||
// import type { Edge, Node, ViewportTransform } from '@vue-flow/core';
|
// import type { Edge, Node, ViewportTransform } from '@vue-flow/core';
|
||||||
import {ElMessageBox} from "element-plus";
|
import {ElMessageBox} from "element-plus";
|
||||||
@@ -13,10 +12,7 @@ const {showMessage} = useGlobalMessage();
|
|||||||
let localStorageDebounceTimer: NodeJS.Timeout | null = null;
|
let localStorageDebounceTimer: NodeJS.Timeout | null = null;
|
||||||
const LOCALSTORAGE_DEBOUNCE_DELAY = 1000; // 1秒防抖
|
const LOCALSTORAGE_DEBOUNCE_DELAY = 1000; // 1秒防抖
|
||||||
|
|
||||||
type PersistedRoot = RootDocument & {
|
type PersistedRoot = RootDocument;
|
||||||
activeFileId?: string;
|
|
||||||
activeFile?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface FlowFile {
|
interface FlowFile {
|
||||||
id: string; // stable identity, do not rely on name for selection
|
id: string; // stable identity, do not rely on name for selection
|
||||||
@@ -356,4 +352,4 @@ export const useFilesStore = defineStore('files', () => {
|
|||||||
activeFileId,
|
activeFileId,
|
||||||
visibleFiles,
|
visibleFiles,
|
||||||
};
|
};
|
||||||
});;;
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user