@@ -5,11 +5,11 @@ import Button from "../../components/Button";
55import { Dialog } from "../../components/dialog" ;
66import { StageExportPng } from "../../core/service/dataGenerateService/stageExportEngine/StageExportPng" ;
77import { Camera } from "../../core/stage/Camera" ;
8- import { Stage } from "../../core/stage/Stage" ;
98import { isExportPNGPanelOpenAtom } from "../../state" ;
109import { cn } from "../../utils/cn" ;
11- import { PathString } from "../../utils/pathString" ;
1210import { StageManager } from "../../core/stage/stageManager/StageManager" ;
11+ import { isMac } from "../../utils/platform" ;
12+ import { writeFileBase64 } from "../../utils/fs" ;
1313
1414/**
1515 * 导出png的面板
@@ -47,23 +47,36 @@ export default function ExportPNGPanel() {
4747 const downloadImage = ( ) => {
4848 const imageBox = document . getElementById ( "export-png-image-box" ) as HTMLDivElement ;
4949 const image = imageBox . querySelector ( "img" ) as HTMLImageElement ;
50- if ( image ) {
51- const a = document . createElement ( "a" ) ;
52- a . href = image . src ;
53-
54- let fileName = "file" ;
55- if ( Stage . path . isDraft ( ) ) {
56- fileName = "草稿" ;
57- } else {
58- fileName = PathString . getFileNameFromPath ( Stage . path . getFilePath ( ) ) ;
59- }
60- a . download = `${ fileName } .png` ;
61- a . click ( ) ;
62- } else {
50+ if ( ! image ) {
6351 Dialog . show ( {
6452 title : "提示" ,
6553 content : "请先渲染图片" ,
6654 } ) ;
55+ return ;
56+ }
57+
58+ const fileName = "导出图片" ;
59+
60+ if ( isMac ) {
61+ try {
62+ const base64Data = image . src . split ( "," ) [ 1 ] ;
63+ const filePath = `${ fileName } .png` ;
64+ writeFileBase64 ( filePath , base64Data ) ;
65+ Dialog . show ( {
66+ title : "导出成功" ,
67+ content : `图片已保存,名称为 ${ filePath } ,用访达搜索该文件可以找到它` ,
68+ } ) ;
69+ } catch ( error ) {
70+ Dialog . show ( {
71+ title : "导出失败" ,
72+ content : `保存图片时出错: ${ error } ` ,
73+ } ) ;
74+ }
75+ } else {
76+ const a = document . createElement ( "a" ) ;
77+ a . href = image . src ;
78+ a . download = `${ fileName } .png` ;
79+ a . click ( ) ;
6780 }
6881 } ;
6982
0 commit comments