king
2021-01-14 3cbad93c94c39730e45600efeabdfebcd424c2cc
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Modal, notification } from 'antd'
import html2canvas from 'html2canvas'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import UserForm from './settingform'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
class DataSource extends Component {
  static propTpyes = {
    btnlog: PropTypes.array,
    handlelog: PropTypes.func
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false,
    loading: false
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  trigger = () => {
    this.setState({
      visible: true,
      loading: false
    })
  }
 
  submit = () => {
    const { config } = this.props
 
    this.verifyRef.handleConfirm().then(res => {
      this.setState({loading: true})
      document.getElementsByClassName('menu-view')[0].classList.add('saving')
 
      html2canvas(document.getElementById(config.uuid)).then(canvas => {
        let img = canvas.toDataURL('image/png') // 获取生成的图片
        Api.fileuploadbase64(img, 'cloud').then(result => {
          if (result.status) {
            Api.getSystemConfig({
              func: 's_custom_components_adduptdel',
              c_id: config.uuid,
              images: Utils.getcloudurl(result.Images),
              c_name: res.name,
              long_param: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
              del_type: ''
            }).then(response => {
              if (response.status) {
                this.setState({loading: false, visible: false})
                notification.success({
                  top: 92,
                  message: '保存成功',
                  duration: 2
                })
                document.getElementsByClassName('menu-view')[0].classList.remove('saving')
                MKEmitter.emit('updateCustomComponent')
              } else {
                this.setState({loading: false})
                notification.warning({
                  top: 92,
                  message: response.message,
                  duration: 5
                })
              }
            })
          } else {
            this.setState({loading: false})
            notification.warning({
              top: 92,
              message: result.ErrMesg,
              duration: 5
            })
          }
        })
      })
    })
  }
 
  cancel = () => {
    this.setState({ visible: false })
    document.getElementsByClassName('menu-view')[0].classList.remove('saving')
  }
 
  render () {
    const { visible, dict, loading } = this.state
 
    return (
      <div className="user-component-wrap">
        <Icon type="user" title="生成自定义组件" onClick={this.trigger} />
        <Modal
          wrapClassName="popview-modal"
          title="自定义组件"
          visible={visible}
          width={500}
          maskClosable={false}
          confirmLoading={loading}
          onOk={this.submit}
          onCancel={this.cancel}
          destroyOnClose
        >
          <UserForm dict={dict} inputSubmit={this.submit} wrappedComponentRef={(inst) => this.verifyRef = inst}/>
        </Modal>
      </div>
    )
  }
}
 
export default DataSource