Skip to content

Commit

Permalink
✨ add: clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ConardLi committed Jun 3, 2019
1 parent e08317b commit 8349303
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions render/views/System/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { Button, Alert } from 'antd';
import { Button, Alert, Input } from 'antd';
import electron from 'electron';
import os from 'os';
import styles from './index.css';

const { remote } = electron;
const { remote, clipboard } = electron;
const { app } = remote;


Expand All @@ -19,6 +19,9 @@ class System extends React.Component {
node: '',
v8: '',
systemPath: '',
text: '复制我呀',
copy: '',
copyVal: ''
}
}

Expand All @@ -34,9 +37,25 @@ class System extends React.Component {
this.setState({ systemPath: os.homedir() })
}

changeText = (e) => {
this.setState({ text: e.target.value })
}

copy = () => {
clipboard.writeText(this.state.text);
this.setState({
copy: '复制成功!' + this.state.text
})
}

copyVal = () => {
this.setState({
copyVal: clipboard.readText()
})
}

render() {
const { appPath, electron, chrome, node, v8, systemPath } = this.state;
const { appPath, electron, chrome, node, v8, systemPath, text, copy, copyVal } = this.state;
return (
<div className={styles.demoContainer}>
<Alert className={styles.margin} message={"点击获取当前应用程序路径:" + appPath} type="info" />
Expand All @@ -51,6 +70,14 @@ class System extends React.Component {
{node && <Alert className={styles.margin} message={"node版本:" + node} type="success" />}
{v8 && <Alert className={styles.margin} message={"v8版本:" + v8} type="success" />}
<Button className={styles.margin} onClick={this.getVersion}>获取版本</Button>

<Input className={styles.margin} value={text} onChange={this.changeText} />

<Alert className={styles.margin} message={"点击复制上面的内容:" + copy} type="warning" />
<Button className={styles.margin} onClick={this.copy}>复制</Button>

<Alert className={styles.margin} message={"点击粘贴剪切板的内容:" + copyVal} type="warning" />
<Button className={styles.margin} onClick={this.copyVal}>粘贴</Button>
</div>
);
}
Expand Down

0 comments on commit 8349303

Please sign in to comment.