/** * @author oldj * @blog http://oldj.net */ 'use strict' import React from 'react' import {Input} from 'antd' import Agent from '../Agent' import MyFrame from './frame' import './sudo.less' export default class SudoPrompt extends React.Component { constructor (props) { super(props) this.onSuccess = null this.state = { show: false, pswd: '' } } componentDidMount () { Agent.on('sudo_prompt', (success) => { this.setState({show: true}) this.onSuccess = success setTimeout(() => { let el = this.refs.body el && el.querySelector('input').focus() }, 100) }) } onOK () { let {pswd} = this.state if (!pswd) { //let el = body //el && el.querySelector('input').focus() this.refs.pswd.focus() return } this.setState({ show: false }) Agent.emit('sudo_pswd', pswd) if (typeof this.onSuccess === 'function') { this.onSuccess(pswd) } this.onSuccess = null } onCancel () { Agent.emit('sudo_cancel') this.setState({ show: false }) this.onSuccess = null } body () { let {lang} = this.props return (