diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 77a8d51..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: node_js -node_js: - - '10' -branchs: - only: - - master -install: - - yarn install -script: - - yarn build -addons: - ssh_known_hosts: 39.96.191.154 -before_install: - - openssl aes-256-cbc -K $encrypted_e6c41ade86ae_key -iv $encrypted_e6c41ade86ae_iv -in id_rsa.enc -out ~/.ssh/id_rsa -d -after_success: - - chmod 600 ~/.ssh/id_rsa - - ssh travis@39.96.191.154 -o StrictHostKeyChecking=no 'cd ~/markdown-resume && git pull && yarn install && yarn build' \ No newline at end of file diff --git a/id_rsa.enc b/id_rsa.enc deleted file mode 100644 index 512703e..0000000 Binary files a/id_rsa.enc and /dev/null differ diff --git a/src/App.js b/src/App.js index bc288d3..60af774 100755 --- a/src/App.js +++ b/src/App.js @@ -34,6 +34,14 @@ class App extends Component { this.props.navbar.setBtnDisable(true); } }; + + window.onbeforeunload = e => { + e = e || window.event; + if (e) { + e.returnValue = "数据目前存储在浏览器中,记得保存到本地备份!"; + } + return "数据目前存储在浏览器中,记得保存到本地备份!"; + }; } componentDidUpdate() { diff --git a/src/components/Button/Export.js b/src/components/Button/Export.js new file mode 100644 index 0000000..9aed65c --- /dev/null +++ b/src/components/Button/Export.js @@ -0,0 +1,165 @@ +import React, { Component } from "react"; + +import PropTypes from "prop-types"; +import { withStyles } from "@material-ui/core/styles"; + +import Menu from "@material-ui/core/Menu"; +import Button from "@material-ui/core/Button"; +import MenuItem from "@material-ui/core/MenuItem"; +import Tooltip from "@material-ui/core/Tooltip"; + +import corner from "../../icons/corner.svg"; + +import { ENTER_DELAY, LEAVE_DELAY, STORAGE_LAYOUT } from "../../utils/constant"; +import { downloadFile } from "../../utils/helper"; + +import { observer, inject } from "mobx-react"; + +@inject("navbar") +@inject("dialog") +@observer +class Export extends Component { + state = { + exportAnchorEl: null + }; + + openModeMenu = event => { + event.stopPropagation(); + this.setState({ exportAnchorEl: event.currentTarget }); + }; + + closeModeMenu = event => { + event.stopPropagation(); + this.setState({ exportAnchorEl: null }); + }; + + handleExport = event => { + event.stopPropagation(); + this.props.navbar.setExported(true); + this.setState({ exportAnchorEl: null }); + }; + + saveToLocal = event => { + event.stopPropagation(); + const layout = window.localStorage.getItem(STORAGE_LAYOUT); + const filename = `markdown-resume-${new Date().getTime()}.json`; + downloadFile(filename, layout); + this.setState({ exportAnchorEl: null }); + }; + + importFromLocal = event => { + event.stopPropagation(); + const file = event.target.files[0]; + this.fileReader = new FileReader(); + this.fileReader.onloadend = this.handleFileRead; + this.fileReader.readAsText(file); + this.setState({ exportAnchorEl: null }); + }; + + handleFileRead = e => { + const content = this.fileReader.result; + window.localStorage.setItem(STORAGE_LAYOUT, content); + window.location.href = "/"; + }; + + openHelpDialog = event => { + event.stopPropagation(); + this.props.dialog.setHelpOpened(true); + this.setState({ exportAnchorEl: null }); + }; + + render() { + const { classes } = this.props; + + const { exportAnchorEl } = this.state; + const exportOpen = Boolean(exportAnchorEl); + + return ( +
+ + + + + {/* 模板选择器菜单 */} + + + + 导出PDF + + + 保存到本地 + + + + 帮助 + + +
+ ); + } +} + +const styles = theme => ({ + btn: { + padding: "0px 10px", + height: "100%", + width: "100px" + }, + menu: { + top: "40px !important" + }, + menuItem: { + fontSize: "0.95em" + }, + corner: { + position: "absolute", + bottom: 2, + right: 2 + }, + input: { + display: "none" + }, + label: { + width: "100%", + height: "100%" + } +}); + +Export.propTypes = { + classes: PropTypes.object.isRequired +}; + +export default withStyles(styles)(Export); diff --git a/src/components/Dialog/DialogHelp.js b/src/components/Dialog/DialogHelp.js index ac23a14..a4f8421 100644 --- a/src/components/Dialog/DialogHelp.js +++ b/src/components/Dialog/DialogHelp.js @@ -61,9 +61,9 @@ class DialogHelp extends Component { indicatorColor="primary" textColor="primary" > + - {value === 0 && ( )} - {value === 2 &&

Item Three

} + {value === 2 && ( + + )} - + */} + {/* */} - logo - + */} ); } diff --git a/src/utils/constant.js b/src/utils/constant.js index ff46f61..7b4a575 100644 --- a/src/utils/constant.js +++ b/src/utils/constant.js @@ -77,6 +77,10 @@ export const HELP_MARKDOWN = ` \`\`\` `; -export const HELP_INFO = [HELP_USE, HELP_MARKDOWN]; +export const HELP_NOTICE = ` +### 简历数据目前自动保存在浏览器中,如果清理浏览器将会丢失! +### 记得编辑后保存到本地备份! +` +export const HELP_INFO = [HELP_NOTICE, HELP_USE, HELP_MARKDOWN]; export const THEMES = [THEME0, THEME1, THEME2, THEME3, THEME4]; diff --git a/src/utils/helper.js b/src/utils/helper.js index af1b672..7b27dfd 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -224,3 +224,17 @@ const solveLine = value => { } return html; }; + +/** + * 创建并下载文件 + * @param {String} fileName 文件名 + * @param {String} content 文件内容 + */ +export const downloadFile = (fileName, content) => { + var aTag = document.createElement('a'); + var blob = new Blob([content]); + aTag.download = fileName; + aTag.href = URL.createObjectURL(blob); + aTag.click(); + URL.revokeObjectURL(blob); +} \ No newline at end of file