king
2022-03-03 3fc643dea8f8c957a95a86d250b5d8b06fb740e1
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
import React, {Component} from 'react'
import { is, fromJS } from 'immutable'
import { Modal, notification } from 'antd'
 
import Api from '@/api'
import { menuOptions } from './option'
import SourceWrap from './dragsource'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const { confirm } = Modal
 
class ModelSource extends Component {
  state = {
    menuOptions: null,
  }
 
  UNSAFE_componentWillMount () {
    const { MenuType, components } = this.props
    let options = []
    
    if (components) {
      options = fromJS(components).toJS()
    } else {
      options = fromJS(menuOptions).toJS()
    }
 
    options = options.filter(item => !item.forbid || !item.forbid.includes(MenuType))
 
    this.setState({
      menuOptions: options
    })
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (nextProps.components && !is(fromJS(this.props.components), fromJS(nextProps.components))) {
      this.setState({
        menuOptions: fromJS(nextProps.components).toJS()
      })
    }
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  triggerDel = (item) => {
    confirm({
      title: `确定删除<${item.title}>吗?`,
      content: '',
      onOk() {
        return new Promise(resolve => {
          Api.getSystemConfig({
            func: 's_custom_components_adduptdel',
            c_id: item.uuid,
            images: '',
            c_name: item.title,
            typename: sessionStorage.getItem('appType') || '',
            long_param: '',
            del_type: 'Y'
          }).then(result => {
            if (result.status) {
              notification.success({
                top: 92,
                message: '删除成功!',
                duration: 5
              })
 
              MKEmitter.emit('updateCustomComponent')
            } else {
              notification.warning({
                top: 92,
                message: result.message,
                duration: 5
              })
            }
            resolve()
          })
        })
      },
      onCancel() {}
    })
  }
 
  render() {
    const { menuOptions } = this.state
 
    return (
      <div className="mob-card-source-box">
        {menuOptions.map((item, index) => (<SourceWrap key={index} item={item} triggerDel={this.triggerDel} />))}
      </div>
    )
  }
}
 
export default ModelSource