Skip to content

Commit 6309d32

Browse files
committed
fix: 修复windows下选中图片后,导出图片到当前prg文件目录下时,跑到C盘或者D盘的问题
1 parent 0c2cf85 commit 6309d32

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

app/src/utils/imageExport.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ImageNode } from "@/core/stage/stageObject/entity/ImageNode";
2+
import { dirname, join } from "@tauri-apps/api/path";
23
import { exists, writeFile } from "@tauri-apps/plugin-fs";
34
import mime from "mime";
45

@@ -20,8 +21,8 @@ export async function exportImagesToProjectDirectory(
2021
let successCount = 0;
2122
let failedCount = 0;
2223

23-
// 获取当前 prg 文件所在目录
24-
const projectDir = projectPath.substring(0, projectPath.lastIndexOf("/"));
24+
// 获取当前 prg 文件所在目录(使用 Tauri 的 dirname 函数,支持跨平台)
25+
const projectDir = await dirname(projectPath);
2526

2627
for (let i = 0; i < imageNodes.length; i++) {
2728
const imageNode = imageNodes[i];
@@ -40,7 +41,7 @@ export async function exportImagesToProjectDirectory(
4041

4142
// 构建文件名:如果是批量导出,添加数字后缀
4243
const finalFileName = isBatch ? `${fileName}_${i + 1}` : fileName;
43-
const saveFilePath = `${projectDir}/${finalFileName}.${ext}`;
44+
const saveFilePath = await join(projectDir, `${finalFileName}.${ext}`);
4445

4546
// 检查文件是否已存在
4647
const fileExists = await exists(saveFilePath);

0 commit comments

Comments
 (0)