wujingjing
2025-02-24 a61bd8abfb6bedacccbc1f1cdb01e4f433e58fd7
start bug;重复导入文件bug
已修改1个文件
34 ■■■■■ 文件已修改
src/views/project/yw/systemManage/flowApp/components/Header.vue 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/project/yw/systemManage/flowApp/components/Header.vue
@@ -53,7 +53,7 @@
        default: false,
    },
});
const emit = defineEmits(['export','saveClick']);
const emit = defineEmits(['export', 'saveClick']);
const { toObject, fromObject, nodes, edges, removeEdges, removeNodes } = useVueFlow();
const { files, open, reset, onCancel, onChange } = useFileDialog({
    //   accept: 'image/*', // Set to accept only image files
@@ -67,36 +67,43 @@
        name: 'WorkFlowIndex',
    });
};
const applyClearGraph = async () => {
    removeEdges(edges.value);
    removeNodes(nodes.value);
};
const clearGraph = async () => {
    const yes = await elConfirm('确定要清空画布吗?');
    if (!yes) {
        return;
    }
    removeEdges(edges.value);
    removeNodes(nodes.value);
    applyClearGraph();
};
const saveFlow = async () => {
    const obj = toObject();
    const jsonStr = obj ? JSONFormat(obj) : '';
    emit('saveClick',jsonStr);
    emit('saveClick', jsonStr);
};
onChange((file) => {
    console.log(file);
    if (!file) return;
    // 获取json 中的内容
    const reader = new FileReader();
    reader.readAsText(file[0]);
    reader.onload = (e) => {
        const jsonStr = e.target?.result as string;
        const json = JSON.parse(jsonStr);
        fromObject(json)
            .then((val) => {})
            .catch((err) => {
                ElMessage.error('导入失败' + err);
            });
        applyClearGraph();
        setTimeout(() => {
            const json = JSON.parse(jsonStr);
            fromObject(json)
                .then((val) => {})
                .catch((err) => {
                    ElMessage.error('导入失败' + err);
                });
        }, 30);
    };
    reader.readAsText(file[0]);
});
const handleCommand = (command: string | number | object) => {
    const obj = toObject();
@@ -105,6 +112,7 @@
        const jsonStr = obj ? JSONFormat(obj) : '';
        downloadJSON(jsonStr, 'flow');
    } else if (command === 'import') {
        reset();
        open();
    }
};