king
2022-11-04 3c50bfdd8d605b3dd449adcb54cdf7f7c25d6c16
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, Button, notification } from 'antd'
import { ArrowUpOutlined } from '@ant-design/icons'
// import moment from 'moment'
 
import { colorTransform } from '@/utils/option.js'
// import Api from '@/api'
import Utils from '@/utils/utils.js'
import './index.scss'
 
const { confirm } = Modal
 
class UpdateTable extends Component {
  static propTpyes = {
    config: PropTypes.object
  }
 
  state = {}
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  trigger = () => {
    const { config } = this.props
    const _this = this
 
    if (!config.enabled) {
      notification.warning({
        top: 92,
        message: '未启用菜单不可升级!',
        duration: 5
      })
      return
    }
    
    confirm({
      title: '确定升级当前菜单吗?',
      content: '',
      onOk() {
        return new Promise(resolve => {
          _this.execUpdate(resolve)
        })
      },
      onCancel() {}
    })
  }
 
  execUpdate = (_resolve) => {
    const { config } = this.props
 
    let _config = {
      version: 1.0,
      uuid: config.uuid,
      MenuID: config.uuid,
      parentId: config.ParentId,
      Template: 'BaseTable',
      easyCode: config.easyCode,
      enabled: false,
      MenuName: config.MenuName,
      MenuNo: config.MenuNo,
      tables: config.tables || [],
      urlFields: config.urlFields || [],
      hidden: config.hidden,
      autoMatic: {},
      Remark: config.Remark,
      components: [],
      viewType: 'menu',
      style: { backgroundColor: '#ffffff', paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'},
    }
 
    let uuids = {}
    let formActions = []
    let popActions = []
 
    let tbl = this.getTable(config, uuids, formActions, popActions)
 
    if (config.autoMatic && config.autoMatic.enable === 'true' && uuids[config.autoMatic.action]) {
      _config.autoMatic = {...config.autoMatic}
      _config.autoMatic.action = uuids[config.autoMatic.action]
    } else {
      _config.autoMatic = {enable: 'false'}
    }
 
    _config.components.push(tbl)
 
    console.log(config)
    console.log(_config)
 
    setTimeout(() => {
      _resolve()
    }, 5000)
  }
 
  getTable = (config, uuids, formActions, popActions) => { 
    let _card = {
      uuid: Utils.getuuid(),
      type: 'table',
      format: 'array',
      pageable: true,
      switchable: true,
      search: config.search.map(item => {
        item.uuid = Utils.getuuid()
        return item
      }),
      action: [],
      subtype: 'basetable',
      setting: { },
      wrap: { },
      style: {},
      headerStyle: {},
      columns: [],
      cols: [],
      scripts: []
    }
 
    let _cols = {}
    let _colspan = []
    let lineMarks = []
    config.columns.forEach(col => {
      if (col.type === 'colspan') {
        _colspan.push(col.subfield.split(', '))
      }
      if (!col.field) return
 
      let _col = fromJS(col).toJS()
 
      if (_col.marks) {
        _col.marks = []
        col.marks.forEach(m => {
          if (m.signType === 'card') return
 
          let field = []
          field.push(m.field)
          field.push(m.contrastType)
 
          if (m.contrastField) {
            field.push(m.contrastField)
          }
          let color = '#1890ff'
          if (m.color && m.color[1]) {
            color = colorTransform[m.color[1]]
          }
          let signType = ['font']
          if (m.signType === 'background') {
            signType = ['background']
          } else if (m.signType === 'icon') {
            if (m.position === 'back') {
              signType = ['iconback']
            } else {
              signType = ['iconfront']
            }
            signType.push(m.iconType)
            signType.push(m.icon)
          }
 
          if (m.signType === 'line') {
            lineMarks.push({
              $index: lineMarks.length + 1,
              field: field,
              color: color,
              contrastValue: m.contrastValue || '',
              match: m.match,
              signType: ['background']
            })
          } else {
            _col.marks.push({
              $index: _col.marks.length + 1,
              field: field,
              color: color,
              contrastValue: m.contrastValue || '',
              match: m.match,
              signType: signType
            })
          }
        })
      }
 
      _cols[col.field] = _col
    })
 
    config.columns.forEach(col => {
      if (col.type === 'index') {
        _card.cols.push(fromJS(col).toJS())
      } else if (col.field && _cols[col.field]) {
        let _col = fromJS(_cols[col.field]).toJS()
 
        if (_colspan.includes(col.field)) {
          _col.Hide = 'true'
        }
 
        _card.cols.push(_col)
      }
 
      if (col.type === 'colspan') {
        let ucol = {
          Align: col.Align,
          Hide: col.Hide,
          label: col.label,
          marks: [],
          isSub: false,
          uuid: col.uuid,
          blacklist: []
        }
        if (col.unfold === 'true') {
          ucol.type = 'colspan'
          ucol.subcols = []
 
          col.subfield.split(', ').forEach(sub => {
            if (_cols[sub]) {
              let _col = fromJS(_cols[sub]).toJS()
              _col.Hide = 'false'
              _col.isSub = true
              _col.uuid = Utils.getuuid()
 
              ucol.subcols.push(_col)
            }
          })
 
          if (ucol.subcols.length > 0) {
            _card.cols.push(ucol)
          }
        } else {
          ucol.Width = 120
          ucol.type = 'custom'
          ucol.elements = []
          ucol.style = {paddingTop: '12px', paddingLeft: '8px', paddingBottom: '12px', paddingRight: '8px'}
 
          col.subfield.split(', ').forEach(sub => {
            if (_cols[sub]) {
              let _col = {
                copyable: 'false',
                datatype: 'dynamic',
                eleType: _cols[sub].type !== 'number' ? 'text' : 'number',
                field: sub,
                height: 1,
                innerHeight: 21,
                marks: _cols[sub].marks || null,
                noValue: 'show',
                style: {},
                width: 24,
                uuid: Utils.getuuid()
              }
 
              ucol.elements.push(_col)
            }
          })
 
          if (ucol.elements.length > 0) {
            _card.cols.push(ucol)
          }
        }
      }
    })
 
    _card.lineMarks = lineMarks
    _card.columns = []
    _card.absFields = []
    _card.cols.forEach(col => {
      if (!col.field) return
      if (['text', 'picture', 'video', 'textarea'].includes(col.type)) {
        _card.columns.push({
          datatype: `Nvarchar(${col.fieldlength || 50})`,
          field: col.field,
          fieldlength: col.fieldlength || 50,
          label: col.label,
          type: 'text',
          uuid: col.uuid
        })
      } else if (col.type === 'link') {
        _card.columns.push({
          datatype: `Nvarchar(${col.fieldlength || 50})`,
          field: col.field,
          fieldlength: col.fieldlength || 50,
          label: col.label,
          type: 'text',
          uuid: col.uuid
        })
        if (col.nameField) {
          _card.columns.push({
            datatype: `Nvarchar(${col.fieldlength || 50})`,
            field: col.nameField,
            fieldlength: col.fieldlength || 50,
            label: col.label + '(名称)',
            type: 'text',
            uuid: col.uuid + 'name'
          })
        }
      } else if (col.type === 'number') {
        _card.columns.push({
          datatype: `Decimal(18,${col.decimal || 0})`,
          field: col.field,
          decimal: col.decimal || 0,
          label: col.label,
          type: 'number',
          uuid: col.uuid
        })
 
        if (col.format === 'abs') {
          _card.absFields.push(col.field)
        }
      }
    })
 
    if (_card.absFields.length) {
      _card.absFields = Array.from(new Set(_card.absFields))
    } else {
      _card.absFields = null
    }
 
    let colbtns = []
    let colors = { primary: '#1890ff', yellow: '#c49f47', orange: 'orange', danger: '#ff4d4f', green: '#26C281', dgreen: '#32c5d2', purple: '#8E44AD', cyan: '#13c2c2', gray: '#666666', default: '#333333' }
 
    config.action.forEach(btn => {
      let _c = btn.class ? btn.class.replace('border-', '') : ''
      let color = colors[_c] || '#1890ff'
      let _btn = fromJS(btn).toJS()
      _btn.uuid = Utils.getuuid()
      delete _btn.position
      delete _btn.linkTab
 
      uuids[btn.uuid] = _btn.uuid
 
      if (btn.OpenType === 'pop' || (btn.OpenType === 'funcbutton' && btn.funcType === 'print' && btn.execMode === 'pop')) {
 
        formActions.push({origin: btn.uuid, uuid: _btn.uuid})
      } else if (btn.OpenType === 'popview') {
 
        popActions.push({origin: btn.uuid, linkTab: btn.linkTab || '', uuid: _btn.uuid})
      } else if (btn.OpenType === 'tab') {
        if (btn.tabTemplate === 'FormTab' || !btn.linkmenu || btn.linkmenu.length !== 3) {
          return
        }
      }
 
      if (_btn.tabType === 'CommonTable') {
        _btn.tabType = 'BaseTable'
      }
 
      if (btn.position === 'grid') {
        _btn.eleType = 'button'
        _btn.width = 24
        _btn.style = {color: color, backgroundColor: 'transparent', borderColor: 'transparent'}
        colbtns.push(_btn)
      } else {
        if (btn.class.indexOf('border') > -1 || btn.class === 'default') {
          _btn.style = {color: color, backgroundColor: '#fff', borderColor: color, marginRight: '15px'}
        } else {
          _btn.style = {color: '#fff', backgroundColor: color, borderColor: color, marginRight: '15px'}
        }
        _card.action.push(_btn)
      }
    })
 
    if (colbtns.length > 0) {
      _card.cols.push({
        Align: 'left',
        label: '操作',
        marks: [],
        isSub: false,
        uuid: Utils.getuuid(),
        type: 'action',
        Width: 120,
        elements: colbtns,
        style: {paddingTop: '12px', paddingLeft: '8px', paddingBottom: '12px', paddingRight: '8px'}
      })
    }
 
    let sets = ['tableName', 'interType', 'sysInterface', 'innerFunc', 'interface', 'proInterface', 'outerFunc', 'dataresource', ['queryType', 'query'], 'primaryKey', 'order', 'execute', ['laypage', 'true'], ['pageSize', 10], ['onload', 'true']]
    let wraps = ['tableType', ['bordered', 'true'], 'actionfixed', ['size', 'middle'], ['selected', 'false'], ['tableMode', 'compatible'], ['mask', 'show'], ['borderColor', '#e8e8e8'], 'height', 'controlField', 'controlVal']
    // useMSearch supModule
    _card.scripts = config.setting.scripts
 
    sets.forEach(n => {
      if (n === 'interType' && !['system', 'inner', 'outer'].includes(config.setting.interType)) {
        _card.setting.interType = 'system'
      } else if (typeof(n) === 'string') {
        _card.setting[n] = config.setting[n] || ''
      } else {
        _card.setting[n[0]] = config.setting[n[0]] || n[1]
      }
    })
    wraps.forEach(w => {
      if (typeof(w) === 'string') {
        _card.wrap[w] = config.setting[w] || ''
      } else {
        _card.wrap[w[0]] = config.setting[w[0]] || w[1]
      }
    })
 
    if (config.setting.doubleClick && uuids[config.setting.doubleClick]) {
      _card.wrap.doubleClick = uuids[config.setting.doubleClick]
    } else {
      _card.wrap.doubleClick = ''
    }
 
    return _card
  }
 
  render() {
    return (
      <div style={{display: 'inline-block'}}>
        <Button className="mk-border-purple" onClick={this.trigger}><ArrowUpOutlined /> 升级</Button>
      </div>
    )
  }
}
 
export default UpdateTable