load file

This commit is contained in:
zhandouxiaojiji committed 2020-10-14 15:18:27 +08:00
1 parent 001d122e5a
commit 3ed022af37
2 files changed
+10 -1

No files matched your search

-1
View File
@@ -17,7 +17,6 @@ export function initMenu(mainWindow: BrowserWindow) {
{name: "Json", extensions:['json']}
]
});
console.log("open res", res);
mainWindow.webContents.send(MainEventType.OPEN_FILE, res.filePaths[0]);
})();
}
+10
View File
@@ -1,6 +1,7 @@
import React, { Component } from "react";
import { DatePicker } from 'antd';
import { ipcRenderer } from 'electron';
import * as fs from 'fs';
import MainEventType from "../../common/MainEventType";
interface EditorState {
@@ -28,6 +29,14 @@ export default class Editor extends Component {
});
}
renderJson() {
if(this.state.filepaths.length>0) {
const path = this.state.filepaths[0];
const str = fs.readFileSync(path, 'utf8');
return (<div>{str}</div>)
}
}
render() {
return (
<div>
@@ -37,6 +46,7 @@ export default class Editor extends Component {
<div>
当前文件:{this.state.filepaths.join("\n")}
</div>
{this.renderJson()}
</div>
)
}