king
2023-03-02 d1f19b794216b37417e114b71c1cd7a2ac3d7748
src/menu/components/form/tab-form/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Popover, Modal, Button, Switch, notification } from 'antd'
import { Popover, Modal, Button, Switch, notification, message } from 'antd'
import { PlusOutlined, SettingOutlined, EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined } from '@ant-design/icons'
import moment from 'moment'
@@ -9,12 +9,10 @@
import asyncComponent from '@/utils/asyncComponent'
import asyncIconComponent from '@/utils/asyncIconComponent'
import { getModalForm } from '@/templates/zshare/formconfig'
import { resetStyle } from '@/utils/utils-custom.js'
import { resetStyle, getTables } from '@/utils/utils-custom.js'
import MKEmitter from '@/utils/events.js'
import Utils from '@/utils/utils.js'
import getWrapForm from '../step-form/options'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import './index.scss'
const ModalForm = asyncComponent(() => import('@/templates/zshare/modalform'))
@@ -39,7 +37,6 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    appType: sessionStorage.getItem('appType'),
    card: null,
    back: false,
@@ -59,12 +56,9 @@
      let _card = {
        uuid: card.uuid,
        type: card.type,
        tabId: card.tabId || '',
        parentId: card.parentId || '',
        format: 'object',   // 组件属性 - 数据格式
        pageable: false,    // 组件属性 - 是否可分页
        switchable: false,  // 组件属性 - 数据是否可切换
        dataName: card.dataName || '',
        width: card.width || 24,
        name: card.name,
        subtype: card.subtype,
@@ -130,11 +124,6 @@
    }
  }
  componentDidMount () {
    MKEmitter.addListener('submitStyle', this.getStyle)
    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
@@ -146,25 +135,6 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('submitStyle', this.getStyle)
    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
  }
  updateComponentStyle = (parentId, keys, style) => {
    const { card } = this.state
    if (card.uuid !== parentId) return
    let subcards = card.subcards.map(item => {
      if (keys.includes(item.uuid)) {
        item.style = {...item.style, ...style}
      }
      return item
    })
    this.setState({card: {...card, subcards: []}}, () => {
      this.updateComponent({...card, subcards: subcards})
    })
  }
  /**
@@ -181,7 +151,6 @@
        supModule = ''
      }
      let columns = card.columns.map(c => c.field)
      // let lowcols = card.columns.map(c => c.field.toLowerCase())
      if (card.setting.interType === 'system' && card.setting.execute !== 'false' && !card.setting.dataresource) {
        card.errors.push({ level: 0, detail: '未设置数据源!'})
@@ -195,22 +164,26 @@
        card.errors.push({ level: 0, detail: '未设置上级组件!'})
      }
      if (card.errors.length === 0) {
        card.$tables = getTables(card)
      }
      card.subcards.forEach(item => {
        item.fields.forEach(m => {
          if (m.type === 'linkMain' && !supModule) {
            card.errors.push({ level: 1, detail: `分组“${item.setting.title}”中关联主表表单“${m.label}”无效`})
          // } else if (m.field && !columns.includes(m.field) && lowcols.includes(m.field.toLowerCase())) {
          //   card.errors.push({ level: 1, detail: `分组“${item.setting.title}”中表单“${m.label}”大小写与字段集不一致`})
            card.errors.push({ level: 1, detail: `请检查分组“${item.setting.title}”中关联主表“${m.label}”是否有效`})
          }
        })
      })
    } else {
      let supModule = card.wrap.supModule ? card.wrap.supModule[card.wrap.supModule.length - 1] : ''
      card.$tables = getTables(card)
      card.subcards.forEach(item => {
        item.fields.forEach(m => {
          if (m.type === 'linkMain' && !supModule) {
            card.errors.push({ level: 1, detail: `分组“${item.setting.title}”中关联主表表单“${m.label}”无效`})
            card.errors.push({ level: 1, detail: `请检查分组“${item.setting.title}”中关联主表“${m.label}”是否有效`})
          }
        })
      })
@@ -240,29 +213,11 @@
  changeStyle = () => {
    const { card } = this.state
    MKEmitter.emit('changeStyle', [card.uuid], ['height', 'background', 'border', 'padding', 'margin', 'shadow'], card.style)
    MKEmitter.emit('changeStyle', ['height', 'font1', 'background', 'border', 'padding', 'margin', 'shadow', 'clear', 'minHeight'], card.style, this.getStyle)
  }
  getStyle = (comIds, style) => {
    const { card, group } = this.state
    if (comIds[0] === 'form') {
      let Index = group.fields.findIndex(n => n.uuid === comIds[1])
      if (Index === -1) return
      let _group = fromJS(group).toJS()
      _group.fields[Index].style = style
      this.updateGroup(_group)
      return
    }
    if (comIds.length !== 1 || comIds[0] !== card.uuid) return
    let _card = {...card, style}
  getStyle = (style) => {
    let _card = {...this.state.card, style}
    this.updateComponent(_card)
  }
@@ -492,38 +447,28 @@
    let index = null
    uniq.set(_form.field, true)
    let _inputIndex = 1
    let _tabIndex = 1
    let _linkIndex = 1
    group.fields.forEach((item, i) => {
      if (_form.uuid === item.uuid) {
        index = i
      }
      let label = item.label || ''
      if (item.field && item.field.toLowerCase() !== label.toLowerCase()) {
        label = label + ' (' + item.field + ')'
      }
      if (['text', 'number', 'textarea', 'color'].includes(item.type) && _item.field !== item.field) {
        _inputfields.push({
          field: item.field,
          label: _inputIndex + '、' + label
          label: item.label
        })
        _inputIndex++
      }
      if (_form.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type)) {
        _tabfields.push({
          field: item.field,
          label: _tabIndex + '、' + label
          label: item.label
        })
        _tabIndex++
      }
      if (item.type === 'switch') {
        _linksupFields.push({
          field: item.field,
          label: _linkIndex + '、' + label
          label: item.label
        })
      }
      
@@ -533,19 +478,15 @@
        uniq.set(item.field, true)
        _linkableFields.push({
          value: item.field,
          text: _linkIndex + '、' + item.label + ' (表单)'
          field: item.field,
          label: item.label + '-表单'
        })
        _linksupFields.push({
          value: item.field,
          text: _linkIndex + '、' + label
          field: item.field,
          label: item.label
        })
        _linkIndex++
      }
    })
    _tabfields.unshift({field: '', label: '原表单'})
    if (index !== null) {
      if (index === 0) {
@@ -561,9 +502,8 @@
        _linkableFields.push({
          field: col.field,
          label: _linkIndex + '、' + col.label + ' (显示列)'
          label: col.label + '-显示列'
        })
        _linkIndex++
      }
    })
@@ -581,7 +521,7 @@
      standardform,
      visible: true,
      editform: _form,
      formlist: getModalForm(_form, _inputfields, _tabfields, _linkableFields, _linksupFields)
      formlist: getModalForm(_form, _inputfields, _tabfields, _linkableFields, _linksupFields, card.columns)
    })
  }
@@ -628,11 +568,13 @@
        let param = {
          func: 's_debug_sql',
          exec_type: 'y',
          LText: res.dataSource
          LText: `declare @mk_organization nvarchar(512)
            ${res.dataSource}`
        }
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'${param.timestamp}'`)
        param.LText = param.LText.replace(/\n/g, ' ')
        
        param.LText = Utils.formatOptions(param.LText)
        param.secretkey = Utils.encrypt('', param.timestamp)
@@ -641,7 +583,7 @@
          param.rduri = window.GLOB.mainSystemApi
        }
        
        Api.getLocalConfig(param).then(result => {
        Api.genericInterface(param).then(result => {
          if (result.status) {
            this.setState({
              sqlVerifing: false,
@@ -774,12 +716,23 @@
  clickComponent = (e) => {
    if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') {
      e.stopPropagation()
      MKEmitter.emit('clickComponent', this.state.card)
      MKEmitter.emit('clickComponent', this.state.card.uuid, null, (style) => {
        let _card = {...this.state.card}
        _card.style = {..._card.style, ...style}
        this.setState({ card: _card })
        this.props.updateConfig(_card)
      })
    }
  }
  render() {
    const { card, dict, group, appType } = this.state
    const { card, group, appType } = this.state
    let labelSize = 14
    if (card.style.fontSize) {
      labelSize = parseInt(card.style.fontSize)
    }
    return (
      <div className="menu-normal-form-edit-box" style={resetStyle(card.style)} onClick={this.clickComponent} id={card.uuid}>
@@ -802,6 +755,7 @@
        </Popover>
        <FormTitle
          list={card.subcards}
          labelSize={labelSize}
          tabtype={card.wrap.tabtype || ''}
          selectId={group ? group.uuid : ''}
          handleList={this.changecards}
@@ -813,7 +767,7 @@
          <PlusOutlined className="plus" title="添加表单" onClick={this.addForm}/>
          <FieldsComponent config={group} type="form" plusFields={this.plusFields} />
          <span style={{color: 'red', marginLeft: '30px', cursor: 'pointer'}} onClick={this.clearGroup}>清空</span>
          <Switch checkedChildren={dict['model.switch.open']} unCheckedChildren={dict['model.switch.close']} defaultChecked={this.state.showField} onChange={(val) => this.setState({showField: val})} />
          <Switch checkedChildren="开" unCheckedChildren="关" defaultChecked={this.state.showField} onChange={(val) => this.setState({showField: val})} />
          {appType !== 'mob' ? <Button className="mk-cols-change" onClick={() => this.changecols(1)}>1列</Button> : null}
          {appType !== 'mob' ? <Button className="mk-cols-change" onClick={() => this.changecols(2)}>2列</Button> : null}
          {appType !== 'mob' ? <Button className="mk-cols-change" onClick={() => this.changecols(3)}>3列</Button> : null}
@@ -823,7 +777,6 @@
            list={group.fields}
            setting={group.setting}
            showField={this.state.showField}
            placeholder={dict['header.form.modal.placeholder']}
            handleList={this.handleList}
            handleForm={this.handleForm}
            closeForm={this.closeForm}
@@ -839,7 +792,15 @@
        </div> : null}
        <div className="component-name">
          <div className="center">
            <div className="title">{card.name}</div>
            <div className="title" onDoubleClick={() => {
              let oInput = document.createElement('input')
              oInput.value = card.uuid
              document.body.appendChild(oInput)
              oInput.select()
              document.execCommand('Copy')
              document.body.removeChild(oInput)
              message.success('复制成功。')
            }}>{card.name}</div>
            <div className="content">
              {card.errors && card.errors.map((err, index) => {
                if (err.level === 0) {
@@ -852,7 +813,7 @@
          </div>
        </div>
        <Modal
          title={this.state.dict['model.edit']}
          title="编辑"
          visible={this.state.visible}
          width={950}
          maskClosable={false}
@@ -862,7 +823,6 @@
          destroyOnClose
        >
          <ModalForm
            dict={this.state.dict}
            card={this.state.editform}
            formlist={this.state.formlist}
            inputSubmit={this.handleSubmit}