king
2021-01-29 44671509a4fb322a48885ab1250b091cb8244d96
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { DndProvider } from 'react-dnd'
import { is, fromJS } from 'immutable'
import moment from 'moment'
import HTML5Backend from 'react-dnd-html5-backend'
import { Icon, Tabs, notification, Modal } from 'antd'
// import html2canvas from 'html2canvas'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
import asyncComponent from '@/utils/asyncComponent'
 
import './index.scss'
 
const { TabPane } = Tabs
const { confirm } = Modal
 
const Header = asyncComponent(() => import('@/mob/header'))
const Controller = asyncComponent(() => import('@/mob/controller'))
const MobShell = asyncComponent(() => import('@/mob/mobshell'))
const SourceWrap = asyncComponent(() => import('@/mob/modelsource'))
const DataSource = asyncComponent(() => import('@/mob/datasource'))
 
class Mobile extends Component {
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    appId: this.props.match.params.appId,
    appType: this.props.match.params.appType,
    appCode: this.props.match.params.appCode,
    appName: this.props.match.params.appName,
    oriConfig: null,
    parentId: '',
    openEdition: '',
    saveIng: false,
    config: null,
    pageIndex: 0,
    editElem: null
  }
 
  UNSAFE_componentWillMount() {
    this.getAppParam(this.props.match.params.appId)
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  jumpToManage = () => {
    const { oriConfig, config } = this.state
    const _this = this
 
    if (!is(fromJS(oriConfig), fromJS(config))) {
      confirm({
        title: '配置已修改,放弃保存吗?',
        content: '',
        okText: _this.state.dict['mob.confirm'],
        cancelText: _this.state.dict['mob.cancel'],
        onOk() {
          _this.props.history.replace('/mobmanage')
        },
        onCancel() {}
      })
    } else {
      _this.props.history.replace('/mobmanage')
    }
  }
 
  triggerSave = () => {
    const { config, openEdition, parentId } = this.state
 
    this.setState({
      saveIng: true
    })
 
    let param = {
      func: 'sPC_TrdMenu_AddUpt',
      ParentID: config.entrance ? '' : parentId,
      MenuID: config.uuid,
      MenuNo: config.MenuNo,
      EasyCode: '',
      Template: '',
      MenuName: '',
      PageParam: '',
      LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
      // LText: _vals.func.map(item => `select '${menu.MenuID}' as MenuID,'${item.func}' as ProcName,'${item.label}' as MenuName`),
      // LTexttb: _tables.map(item => `select '${menu.MenuID}' as MenuID,'${item}' as tbName`),
      TypeCharOne: 'mob'
    }
 
    let _LText = ''
    // _LText = _LText.join(' union all ')
    let _LTexttb = ''
    // _LTexttb = _LTexttb.join(' union all ')
    
    param.LText = Utils.formatOptions(_LText)
    param.LTexttb = Utils.formatOptions(_LTexttb)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
    if (openEdition) { // 版本管理
      param.open_edition = openEdition
    }
 
    Api.getSystemConfig(param).then(response => {
      if (response.status) {
        this.setState({
          oriConfig: fromJS(config).toJS(),
          openEdition: response.open_edition || '',
          saveIng: false
        })
      } else {
        notification.warning({
          top: 92,
          message: response.message,
          duration: 5
        })
      }
    })
    
  }
 
  getAppParam = (id) => {
    Api.getSystemConfig({
      func: 'sPC_Get_LongParam',
      MenuID: id,
      TypeCharOne: 'mob'
    }).then(result => {
      if (result.status) {
        let config = null
 
        if (result.LongParam) {
          try {
            config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
          } catch (e) {
            console.warn('Parse Failure')
            config = null
          }
        }
 
        if (!config) {
          config = {
            version: 1.0,
            entrance: true,
            label: '',
            uuid: this.props.match.params.appId,
            pageIndex: 0,
            MenuNo: this.props.match.params.appCode,
            sourcelist: [],
            components: []
          }
        }
        this.setState({
          oriConfig: config,
          config: fromJS(config).toJS(),
          openEdition: result.open_edition || '',
        })
      } else {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      }
    })
  }
 
  deleteCard = (id) => {
    let _this = this
    let config = fromJS(this.state.config).toJS()
 
    confirm({
      title: '确定删除元素吗?',
      content: '',
      okText: this.state.dict['mob.confirm'],
      cancelText: this.state.dict['mob.cancel'],
      onOk() {
        config.components = config.components.filter(item => item.uuid !== id)
 
        _this.setState({
          config: config
        })
      },
      onCancel() {}
    })
  }
 
  editCard = (element) => {
    this.setState({
      editElem: element
    })
  }
 
  updateStyle = (proper) => {
    const { config } = this.state
 
    config.components = config.components.map(component => {
      if (component.uuid === proper.componentId) {
        Object.keys(component).forEach(key => {
          let _uuid = component[key].uuid
          if (_uuid && (_uuid === proper.uuid || _uuid === proper.classId)) {
            if (component[key].substyle) {
 
            } else {
              component[key].style = {...component[key].style, ...proper.style}
              // eslint-disable-next-line
              for (let index in component[key].style) {
                if (component[key].style[index] === '') {
                  delete component[key].style[index]
                }
              }
            }
          }
        })
      }
      return component
    })
    this.setState({config})
  }
 
  updateConfig = (config) => {
    this.setState({
      config: config
    })
  }
 
  render () {
    const { saveIng, appType, config, editElem } = this.state
 
    return (
      <div className="mobile-view">
        <Header view="design" jumpToManage={this.jumpToManage} triggerSave={this.triggerSave} saveIng={saveIng} />
        <DndProvider backend={HTML5Backend}>
          <div className="mob-body">
            <div className="mob-tool">
              <div className="mob-tool-content">
                <div className="plus-content">
                  <Icon type="plus-circle" />添 加 组 件
                </div>
                <div className="useable-component">
                  <SourceWrap appType={appType} />
                </div>
              </div>
              <div className="mob-tool-other"></div>
            </div>
            {appType === 'mob' && config ?
              <div className="mob-shell">
                <MobShell
                  config={config}
                  deleteCard={this.deleteCard}
                  editCard={this.editCard}
                  editId={editElem ? editElem.uuid : ''}
                  handleList={this.updateConfig}
                />
              </div> : null
            }
            <div className="mob-setting">
              {config ? <Tabs defaultActiveKey="1" animated={false} size="small">
                <TabPane tab="配置" key="1">
                  <Controller editElem={editElem} updateStyle={this.updateStyle} />
                </TabPane>
                <TabPane tab="数据源" key="2">
                  <DataSource config={config} updateConfig={this.updateConfig} />
                </TabPane>
              </Tabs> : null}
            </div>
          </div>
        </DndProvider>
      </div>
    )
  }
}
 
const mapStateToProps = () => {
  return {}
}
 
const mapDispatchToProps = () => {
  return {}
}
 
export default connect(mapStateToProps, mapDispatchToProps)(Mobile)