mirror of
https://github.com/Powerful-517/yys-editor.git
synced 2026-03-05 15:05:27 +00:00
test: 集成 Vitest 测试框架和开发规范
- 安装 vitest, @vue/test-utils, jsdom 等测试依赖 - 配置 vitest.config.js 测试环境 - 添加 schema.test.ts (7个数据结构验证测试) - 添加 useStore.test.ts (7个状态管理测试) - 创建测试指南文档 (docs/testing.md) - 创建测试规范文档 (docs/testing-rules.md) - 创建开发规范文档 (docs/development-rules.md) - 创建开发工作流程文档 (docs/1management/workflow.md) - 添加测试相关 npm scripts (test, test:watch, test:ui, test:coverage) - 所有测试通过 (14/14)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
<div>
|
||||
<el-button icon="Upload" type="primary" @click="handleImport">{{ t('import') }}</el-button>
|
||||
<el-button icon="Download" type="primary" @click="handleExport">{{ t('export') }}</el-button>
|
||||
<el-button icon="View" type="success" @click="handlePreviewData">数据预览</el-button>
|
||||
<el-button icon="Share" type="primary" @click="prepareCapture">{{ t('prepareCapture') }}</el-button>
|
||||
<el-button icon="Setting" type="primary" @click="state.showWatermarkDialog = true">{{ t('setWatermark') }}</el-button>
|
||||
<el-button type="info" @click="loadExample">{{ t('loadExample') }}</el-button>
|
||||
@@ -97,6 +98,19 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 数据预览对话框 -->
|
||||
<el-dialog v-model="state.showDataPreviewDialog" title="数据预览" width="70%">
|
||||
<div style="max-height: 600px; overflow-y: auto;">
|
||||
<pre style="background: #f5f5f5; padding: 16px; border-radius: 4px; font-size: 12px; line-height: 1.5;">{{ state.previewDataContent }}</pre>
|
||||
</div>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="state.showDataPreviewDialog = false">关闭</el-button>
|
||||
<el-button type="primary" @click="copyDataToClipboard">复制到剪贴板</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -124,6 +138,8 @@ const state = reactive({
|
||||
showWatermarkDialog: false, // 控制水印设置弹窗的显示状态,
|
||||
showUpdateLogDialog: false, // 控制更新日志对话框的显示状态
|
||||
showFeedbackFormDialog: false, // 控制反馈表单对话框的显示状态
|
||||
showDataPreviewDialog: false, // 控制数据预览对话框的显示状态
|
||||
previewDataContent: '', // 存储预览的数据内容
|
||||
});
|
||||
|
||||
// 重新渲染 LogicFlow 画布的通用方法
|
||||
@@ -216,6 +232,39 @@ const handleExport = () => {
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
const handlePreviewData = () => {
|
||||
// 预览前先更新当前数据
|
||||
filesStore.updateTab();
|
||||
|
||||
// 延迟一点确保更新完成后再预览
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const activeName = filesStore.fileList.find(f => f.id === filesStore.activeFileId)?.name || '';
|
||||
const dataObj = {
|
||||
schemaVersion: 1,
|
||||
fileList: filesStore.fileList,
|
||||
activeFileId: filesStore.activeFileId,
|
||||
activeFile: activeName,
|
||||
};
|
||||
state.previewDataContent = JSON.stringify(dataObj, null, 2);
|
||||
state.showDataPreviewDialog = true;
|
||||
} catch (error) {
|
||||
console.error('生成预览数据失败:', error);
|
||||
showMessage('error', '数据预览失败');
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
|
||||
const copyDataToClipboard = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(state.previewDataContent);
|
||||
showMessage('success', '已复制到剪贴板');
|
||||
} catch (error) {
|
||||
console.error('复制失败:', error);
|
||||
showMessage('error', '复制失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleImport = () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
|
||||
@@ -197,6 +197,24 @@ function normalizeAllNodes() {
|
||||
const lfInstance = lf.value;
|
||||
if (!lfInstance) return;
|
||||
lfInstance.graphModel?.nodes.forEach((model: BaseNodeModel) => normalizeNodeModel(model));
|
||||
|
||||
// 检查是否所有节点的 zIndex 都相同且为默认值(通常是从历史恢复的情况)
|
||||
const allNodes = lfInstance.graphModel?.nodes || [];
|
||||
if (allNodes.length > 1) {
|
||||
const firstZIndex = allNodes[0]?.zIndex;
|
||||
const allSameZIndex = allNodes.every(n => n.zIndex === firstZIndex);
|
||||
|
||||
// 只有当所有节点的 zIndex 都是默认值 1 时才重新分配
|
||||
if (allSameZIndex && firstZIndex === 1) {
|
||||
console.log('[初始化] 检测到所有节点 zIndex 都为默认值 1,开始重新分配 zIndex');
|
||||
// 为所有节点分配递增的 zIndex,避免层级操作异常
|
||||
allNodes.forEach((node, index) => {
|
||||
const newZIndex = index + 1;
|
||||
node.setZIndex(newZIndex);
|
||||
});
|
||||
console.log('[初始化] zIndex 重新分配完成:', allNodes.map(n => ({ id: n.id, zIndex: n.zIndex })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateNodeMeta(model: BaseNodeModel, updater: (meta: Record<string, any>) => Record<string, any>) {
|
||||
@@ -262,7 +280,16 @@ function bringToFront(nodeId?: string) {
|
||||
if (!lfInstance) return;
|
||||
const targetId = nodeId || selectedNode.value?.id;
|
||||
if (!targetId) return;
|
||||
|
||||
// 诊断日志:查看所有节点的 zIndex
|
||||
const allNodes = lfInstance.graphModel.nodes;
|
||||
console.log('[置于顶层] 目标节点ID:', targetId);
|
||||
console.log('[置于顶层] 所有节点的 zIndex:', allNodes.map(n => ({ id: n.id, zIndex: n.zIndex })));
|
||||
|
||||
lfInstance.setElementZIndex(targetId, 'top');
|
||||
|
||||
// 操作后再次查看
|
||||
console.log('[置于顶层] 操作后所有节点的 zIndex:', allNodes.map(n => ({ id: n.id, zIndex: n.zIndex })));
|
||||
}
|
||||
|
||||
function sendToBack(nodeId?: string) {
|
||||
@@ -270,7 +297,16 @@ function sendToBack(nodeId?: string) {
|
||||
if (!lfInstance) return;
|
||||
const targetId = nodeId || selectedNode.value?.id;
|
||||
if (!targetId) return;
|
||||
|
||||
// 诊断日志:查看所有节点的 zIndex
|
||||
const allNodes = lfInstance.graphModel.nodes;
|
||||
console.log('[置于底层] 目标节点ID:', targetId);
|
||||
console.log('[置于底层] 所有节点的 zIndex:', allNodes.map(n => ({ id: n.id, zIndex: n.zIndex })));
|
||||
|
||||
lfInstance.setElementZIndex(targetId, 'bottom');
|
||||
|
||||
// 操作后再次查看
|
||||
console.log('[置于底层] 操作后所有节点的 zIndex:', allNodes.map(n => ({ id: n.id, zIndex: n.zIndex })));
|
||||
}
|
||||
|
||||
function bringForward(nodeId?: string) {
|
||||
@@ -663,7 +699,7 @@ onMounted(() => {
|
||||
grid: { type: 'dot', size: 10 },
|
||||
allowResize: true,
|
||||
allowRotate: true,
|
||||
overlapMode: -1,
|
||||
overlapMode: 0,
|
||||
snapline: snaplineEnabled.value,
|
||||
keyboard: {
|
||||
enabled: true
|
||||
@@ -902,8 +938,20 @@ onMounted(() => {
|
||||
lfInstance.on(EventType.NODE_DRAG, (args) => handleNodeDrag(args as any));
|
||||
|
||||
lfInstance.on(EventType.NODE_ADD, ({ data }) => {
|
||||
console.log('[NODE_ADD 事件触发] 节点ID:', data.id);
|
||||
const model = lfInstance.getNodeModelById(data.id);
|
||||
if (model) normalizeNodeModel(model);
|
||||
if (model) {
|
||||
console.log('[NODE_ADD] 获取到节点模型,当前 zIndex:', model.zIndex);
|
||||
normalizeNodeModel(model);
|
||||
|
||||
// 设置新节点的 zIndex 为 1000
|
||||
const newZIndex = 1000;
|
||||
console.log(`[NODE_ADD] 准备设置 zIndex: ${newZIndex}`);
|
||||
model.setZIndex(newZIndex);
|
||||
console.log(`[NODE_ADD] 设置后的 zIndex:`, model.zIndex);
|
||||
} else {
|
||||
console.log('[NODE_ADD] 未能获取到节点模型');
|
||||
}
|
||||
});
|
||||
|
||||
lfInstance.on(EventType.GRAPH_RENDERED, () => normalizeAllNodes());
|
||||
|
||||
Reference in New Issue
Block a user