king
2025-05-13 1a176e4bdba485301385caac1a29102e598d25cc
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
import React, {Component} from 'react'
import { is, fromJS } from 'immutable'
 
import { menuOptions } from './option'
import SourceWrap from './dragsource'
import './index.scss'
 
class ModelSource extends Component {
  state = {
    menuOptions: null,
  }
 
  UNSAFE_componentWillMount () {
    const { components, viewType } = this.props
    let options = []
    
    if (components) {
      options = fromJS(components).toJS()
    } else {
      options = fromJS(menuOptions).toJS()
      let adapters = sessionStorage.getItem('adapter') || ''
      if (adapters.indexOf('wxmini') === -1) {
        options = options.filter(item => item.adapter !== 'mini')
      }
    }
 
    if (viewType === 'popview') {
      options = options.filter(item => !['topbar', 'navbar', 'login', 'officialAccount'].includes(item.component))
    }
 
    this.setState({
      menuOptions: options
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  render() {
    const { menuOptions } = this.state
 
    return (
      <div className="mob-card-source-box">
        {menuOptions.map((item, index) => (<SourceWrap key={index} item={item}/>))}
      </div>
    )
  }
}
 
export default ModelSource