king
2025-04-24 92664ef80a97a63fde223b14097ccda3ae6ff183
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { Component } from 'react'
import { Modal, Button, Input, message } from 'antd'
import { CopyOutlined } from '@ant-design/icons'
 
import './index.scss'
 
const { TextArea } = Input
 
class LowerText extends Component {
  state = {
    visible: false,
    content: ''
  }
 
  trigger = () => {
    this.setState({
      visible: true,
      content: ''
    })
  }
 
  changeValue = (e) => {
    this.setState({content: e.target.value.toLowerCase()})
  }
 
  copy = () => {
    const { content } = this.state
    
    if (navigator.clipboard) {
      navigator.clipboard.writeText(content)
    } else {
      let oInput = document.createElement('input')
      oInput.value = content
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      document.body.removeChild(oInput)
    }
    
    message.success('复制成功。')
  }
 
  render() {
    const { visible, content } = this.state
 
    return (
      <>
        <Button className="mk-border-yellow" onClick={this.trigger}>文本转小写</Button>
        <Modal
          title="文本转小写"
          wrapClassName="lower-text-modal"
          visible={visible}
          width={850}
          maskClosable={false}
          centered={true}
          onCancel={() => { this.setState({ visible: false })}}
          footer={[
            <Button key="cancel" onClick={() => { this.setState({ visible: false })}}>关闭</Button>
          ]}
          destroyOnClose
        >
          <TextArea defaultValue="" autoFocus rows={7} onChange={this.changeValue}/>
          <CopyOutlined onClick={this.copy}/>
          <div className="lower-value">{content}</div>
        </Modal>
      </>
    )
  }
}
 
export default LowerText