文件
2026-11-20 15:32:57 +08:00

23 行
2.8 KiB
TypeScript

import { reactive } from 'vue';
import { design } from './data';
import type { LogicalSnapshot } from '@/api/datagov/model-design/types';
export const scenario = reactive({ fail: false, loseSaveReply: false, modelSaves: 0 });
let savedDesign = structuredClone(design);
const receipts = new Map<string, string>();
const blocked = async () => { throw new Error('此检查环境不执行业务写入'); };
export const getModelDesign = async () => ({ data: structuredClone(savedDesign) });
export const saveLogicalModel = async (id: string, command: { snapshot: LogicalSnapshot; version: string | number }, key: string) => {
const body = JSON.stringify(command);
if (receipts.has(key)) { if (receipts.get(key) !== body) throw new Error('合成接口:原键载荷变化'); return { data: { result: structuredClone(savedDesign) } }; }
if (String(id) !== String(savedDesign.designId) || String(command.version) !== String(savedDesign.version)) throw { response: { status: 409 } };
savedDesign = { ...savedDesign, logical: JSON.parse(JSON.stringify(command.snapshot)), version: String(BigInt(savedDesign.version) + 1n), currentVersionNo: String(BigInt(savedDesign.currentVersionNo) + 1n) };
receipts.set(key, body); scenario.modelSaves++;
if (scenario.loseSaveReply) { scenario.loseSaveReply = false; throw new Error('合成接口:已保存但响应丢失'); }
return { data: { result: structuredClone(savedDesign) } };
};
export const getModelLayout = async (_id: string, layer: string) => ({ data: { designId: design.designId, layer: layer.toUpperCase(), layoutVersion:'0',snapshotSha256:'a'.repeat(64),positions:[],viewport:null,stale:false,updatedAt:null,droppedNodeIds:[] } });
export const pageModelDesignVersions = async () => { const old = structuredClone(design); old.physical.tables[0].fields[2].nullable = true; old.physical.tables[0].fields[2].dataType = 'DOUBLE'; return { data: { rows: [{ ...old, versionNo:'7',versionId:'v7',changeSummary:'调整金额类型与非空约束',createTime:'2026-10-20T09:00:00' }], total:1 } }; };
export const sourceCandidates = async () => ({ data: [{ tableId:'fixture-table',label:'交易库 / orders',engineType:'MYSQL' }] });
export const sourceStructure = async (id: string) => { if (scenario.fail) { scenario.fail = false; throw new Error('模拟字段读取失败'); } return {data: { tableId:id,sourceVersion:'12',revision:'3',observedAt:'2026-10-21T08:30:00',engineType:'MYSQL',fields:[{name:'id',dataType:'BIGINT',nullable:false,restricted:false},{name:'customer_id',dataType:'BIGINT',nullable:null,restricted:false},{name:'amount',dataType:'DOUBLE',nullable:true,restricted:false}],uniqueKeys:[['id']] }}; };
export const saveModelLayout=blocked,saveConceptualModel=blocked,savePhysicalModel=blocked,saveModelDefinition=blocked,structureContext=blocked,generateStructure=blocked,reviewStructure=blocked,prepareStructure=blocked;