king
2025-04-21 f3d4db769ba9b51b799d981511a710fd443d0e08
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import React, { Component } from 'react'
import { is, fromJS } from 'immutable'
import PropTypes from 'prop-types'
import { notification, Modal, Collapse, Card, Switch, Button } from 'antd'
 
import MKEmitter from '@/utils/events.js'
import SourceElement from '@/templates/zshare/dragsource'
import asyncComponent from '@/utils/asyncComponent'
import Source from '../source'
 
import './index.scss'
 
const { Panel } = Collapse
const { confirm } = Modal
 
const MenuShell = asyncComponent(() => import('@/menu/tableshell'))
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
const NormalCopy = asyncComponent(() => import('@/menu/normalCopy'))
const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
 
class PopViewDesign extends Component {
  static propTpyes = {
    btn: PropTypes.object,
    save: PropTypes.func,
    cancel: PropTypes.func
  }
 
  state = {
    menuloading: false,
    oriConfig: null,
    config: null,
    comloading: false,
  }
 
  UNSAFE_componentWillMount() {
    const { btn } = this.props
    sessionStorage.setItem('editMenuType', 'popview')
 
    let config = fromJS(btn.config).toJS()
 
    window.GLOB.urlFields = []               // url变量
    window.GLOB.customMenu = config          // 保存菜单信息
 
    this.setState({config: config, oriConfig: fromJS(config).toJS()})
  }
 
  componentDidMount () {
    MKEmitter.addListener('completeSave', this.completeSave)
    MKEmitter.addListener('triggerMenuSave', this.submitConfig)
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('completeSave', this.completeSave)
    MKEmitter.removeListener('triggerMenuSave', this.submitConfig)
  }
 
  closeView = () => {
    const { oriConfig, config } = this.state
 
    if (!is(fromJS(oriConfig), fromJS(config))) {
      const that = this
 
      confirm({
        title: '配置已修改,放弃保存吗?',
        content: '',
        onOk() {
          that.props.cancel()
        },
        onCancel() {}
      })
    } else {
      this.props.cancel()
    }
  }
 
  completeSave = () => {
    this.setState({
      oriConfig: fromJS(this.state.config).toJS(),
      menuloading: false
    })
  }
 
  submitConfig = () => {
    let config = fromJS(this.state.config).toJS()
 
    if (config.cacheUseful === 'true' && !config.cacheTime) {
      notification.warning({
        top: 92,
        message: '请完善缓存设置!',
        duration: 5
      })
      return
    }
 
    if (config.enabled && this.verifyConfig()) {
      config.enabled = false
    }
 
    config.$tables = Array.from(new Set(config.components[0].$tables || []))
 
    this.setState({
      config: config,
      menuloading: true
    })
 
    window.GLOB.customMenu = config
 
    this.props.save(fromJS(config).toJS())
  }
 
  onEnabledChange = () => {
    const { config } = this.state
 
    if (!config.enabled && this.verifyConfig(true)) {
      return
    }
 
    this.setState({
      config: {...config, enabled: !config.enabled}
    })
  }
 
  verifyConfig = (show) => {
    const { config } = this.state
    let error = ''
    
    if (config.components[0].errors) {
      config.components[0].errors.forEach(err => {
        if (err.level !== 0 || error) return
        error = err.detail
      })
    }
    
    if (show && error) {
      notification.warning({
        top: 92,
        message: error,
        duration: 5
      })
    }
 
    return error
  }
 
  // 更新配置信息
  updateConfig = (config) => {
    this.setState({
      config: config
    })
 
    window.GLOB.customMenu = config
  }
 
  resetConfig = (config) => {
    this.setState({
      config,
      comloading: true
    }, () => {
      this.setState({
        comloading: false
      })
    })
 
    window.GLOB.customMenu = config
  }
 
  /**
   * @description 更新常用表信息,快捷添加后更新配置信息
   */
  updatetable = (config) => {
    this.setState({ config })
 
    window.GLOB.customMenu = config
  }
 
  render () {
    const { comloading, config, menuloading } = this.state
 
    return (
      <div className="pc-poper-view">
        <div className="menu-body">
          <div className="menu-setting">
            <Collapse accordion defaultActiveKey="basedata" bordered={false}>
              {/* 基本信息 */}
              <Panel header="基本信息" key="basedata">
                {/* 表名添加 */}
                <TableComponent config={config} updatetable={this.updatetable}/>
                <NormalCopy />
              </Panel>
              {/* 组件添加 */}
              <Panel header="搜索" key="search">
                {Source.searchItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
              </Panel>
              <Panel header="按钮" key="action">
                {Source.popactionItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
              </Panel>
              <Panel header="显示列" key="cols">
                {Source.columnItems.map((item, index) => (<SourceElement key={index} content={item}/>))}
              </Panel>
              <Panel header="页面样式" key="background">
                <BgController config={config} updateConfig={this.updateConfig} />
              </Panel>
            </Collapse>
          </div>
          <div className={'menu-view' + (menuloading ? ' saving' : '')}>
            <Card title={
              <div> {config.MenuName} </div>
            } bordered={false} extra={
              <div>
                <ReplaceField config={config} updateConfig={this.resetConfig}/>
                <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config.enabled} onChange={this.onEnabledChange} />
                <Button type="primary" id="save-pop-config" onClick={this.submitConfig} loading={menuloading}>保存</Button>
                <Button type="default" disabled={menuloading} onClick={this.closeView}>返回</Button>
              </div>
            } style={{ width: '100%' }}>
              {!comloading ? <MenuShell menu={config} handleList={this.updateConfig} /> : null}
            </Card>
          </div>
        </div>
      </div>
    )
  }
}
 
export default PopViewDesign