优化: PDF导出成功后打开所在位置选中文件
- 导出落盘后explorer选中PDF,不再只靠一闪而过的弹窗 - 成功文案明确指向导出位置 - explorer用WINDIR绝对路径,不依赖PATH
This commit is contained in:
@@ -929,7 +929,8 @@ const handleExportHtmlPDF = async () => {
|
|||||||
try {
|
try {
|
||||||
const res = await ExportHtmlFileToPDF(srcPath, baseName)
|
const res = await ExportHtmlFileToPDF(srcPath, baseName)
|
||||||
if (res?.success) {
|
if (res?.success) {
|
||||||
Message.success(`PDF 已导出到: ${res.path}`)
|
// 后端导出成功已自动打开资源管理器选中文件,弹窗只做明确指向,不依赖用户记住路径
|
||||||
|
Message.success('PDF 已导出,已在桌面打开所在位置')
|
||||||
} else {
|
} else {
|
||||||
Message.error(res?.message || 'PDF 导出失败')
|
Message.error(res?.message || 'PDF 导出失败')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -451,6 +451,15 @@ func (api *PdfAPI) ExportHtmlFileToPDF(srcPath string, saveName string) (resp *P
|
|||||||
return nil, fmt.Errorf("获取文件信息失败: %v", err)
|
return nil, fmt.Errorf("获取文件信息失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 成功弹窗几秒即逝用户难感知产物位置,改用资源管理器选中 PDF 明示落盘位置;失败静默不影响导出结果
|
||||||
|
// 用户 PATH 无 C:\Windows 根目录,explorer 走 LookPath 解析不到,必须用 WINDIR 拼绝对路径
|
||||||
|
if common.IsWindows() {
|
||||||
|
exePath := filepath.Join(os.Getenv("WINDIR"), "explorer.exe")
|
||||||
|
if selectErr := exec.Command(exePath, "/select,", savePath).Start(); selectErr != nil {
|
||||||
|
appendExportLog(fmt.Sprintf("ExportHtmlFileToPDF explorer select error=%s", selectErr.Error()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &PdfExportResponse{
|
return &PdfExportResponse{
|
||||||
Success: true,
|
Success: true,
|
||||||
Message: "PDF生成成功",
|
Message: "PDF生成成功",
|
||||||
|
|||||||
Reference in New Issue
Block a user