king
2025-02-06 d1cd5af5adb53e91efdd278328e1b6f8ad834fb5
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal } from 'antd'
import { EditOutlined } from '@ant-design/icons'
 
import CodeMirror from '@/templates/zshare/codemirror'
import './index.scss'
 
class NormalCss extends Component {
  static propTpyes = {
    config: PropTypes.object,
    updateConfig: PropTypes.func
  }
 
  state = {
    visible: false,
    normalcss: ''
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  trigger = () => {
    const { config } = this.props
 
    this.setState({visible: true, normalcss: config.normalcss || ''})
  }
 
  onCssChange = (val) => {
    this.setState({
      normalcss: val
    })
  }
 
  submit = () => {
    const { normalcss } = this.state
 
    this.setState({
      visible: false
    })
 
    this.props.updateConfig({...this.props.config, normalcss: normalcss})
  }
 
  render() {
    const { visible, normalcss } = this.state
 
    return (
      <div className="mk-normal-css">
        全局样式:<EditOutlined onClick={this.trigger} />
        <Modal
          title="全局样式"
          wrapClassName="normal-css-modal"
          visible={visible}
          width={800}
          maskClosable={false}
          onOk={this.submit}
          onCancel={() => { this.setState({ visible: false })}}
          destroyOnClose
        >
          <CodeMirror mode="text/css" theme="cobalt" value={normalcss} onChange={this.onCssChange} />
        </Modal>
      </div>
    )
  }
}
 
export default NormalCss