king
2019-12-10 88f02c2c018fb1e5c171bd4975dac534c584c3ba
src/templates/comtableconfig/index.jsx
@@ -3,7 +3,7 @@
import { is, fromJS } from 'immutable'
import { DndProvider } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import { Button, Card, Modal, Collapse, notification, Spin, Select, List, Icon, Empty } from 'antd'
import { Button, Card, Modal, Collapse, notification, Spin, Select, List, Icon, Empty, Switch } from 'antd'
import moment from 'moment'
import DragElement from './dragelement'
import SourceElement from './dragelement/source'
@@ -37,28 +37,29 @@
  }
  state = {
    operaType: '', // 操作类型,新建或编辑
    dict: CommonDict, // 字典
    config: null, // 页面配置
    visible: false, // 搜索条件、按钮、显示列,模态框显示控制
    tableVisible: false, // 数据表字段模态框
    addType: '', // 添加类型-搜索条件或显示列
    tableColumns: [], // 表格显示列
    fields: null, // 搜索条件及显示列,可选字段
    menuformlist: null, // 基本信息表单字段
    formlist: null, // 搜索条件、按钮、显示列表单字段
    formtemp: '', // 表单类型,显示列、按钮、搜索条件
    card: null, // 编辑元素
    searchloading: false, // 搜索条件加载中
    actionloading: false, // 按钮加载中
    columnsloading: false, // 显示列加载中
    menuloading: false, // 菜单保存中
    loading: false, // 加载中,页面spin
    settingVisible: false, // 全局配置模态框
    closeVisible: false, // 关闭模态框
    tables: [], // 可用表名
    selectedTables: [], // 已选表名
    originMenu: null, // 原始菜单
    operaType: '',           // 操作类型,新建或编辑
    dict: CommonDict,        // 字典
    config: null,            // 页面配置
    visible: false,          // 搜索条件、按钮、显示列,模态框显示控制
    tableVisible: false,     // 数据表字段模态框
    addType: '',             // 添加类型-搜索条件或显示列
    tableColumns: [],        // 表格显示列
    fields: null,            // 搜索条件及显示列,可选字段
    menuformlist: null,      // 基本信息表单字段
    formlist: null,          // 搜索条件、按钮、显示列表单字段
    formtemp: '',            // 表单类型,显示列、按钮、搜索条件
    card: null,              // 编辑元素
    searchloading: false,    // 搜索条件加载中
    actionloading: false,    // 按钮加载中
    columnsloading: false,   // 显示列加载中
    menuloading: false,      // 菜单保存中
    menucloseloading: false, // 菜单关闭时,选择保存
    loading: false,          // 加载中,页面spin
    settingVisible: false,   // 全局配置模态框
    closeVisible: false,     // 关闭模态框
    tables: [],              // 可用表名
    selectedTables: [],      // 已选表名
    originMenu: null,        // 原始菜单
    originActions: null
  }
@@ -95,7 +96,7 @@
      originActions: _oriActions,
      config: _config,
      operaType: _type,
      originMenu: JSON.parse(JSON.stringify({...menu})),
      originMenu: JSON.parse(JSON.stringify(menu)),
      selectedTables: _config.tables || [],
      menuformlist: [
        {
@@ -240,29 +241,31 @@
    })
  }
  handleList = (listObj) => {
    let config = this.state.config
    if (this.state.operaType === 'add') {
      let key = Object.keys(listObj)[0]
      let newlength = listObj[key].length
      if (newlength > config[key].length) {
        listObj[key] = listObj[key].filter(item => !item.origin)
      }
      if (newlength > listObj[key].length) {
  handleList = (type, list, card) => {
    const { config } = this.state
    if (list.length > config[type].length) {
      list = list.filter(item => !item.origin)
      this.setState({
        [type + 'loading']: true,
        config: {...config, [type]: list }
      }, () => {
        // 刷新对应的配置信息
        this.setState({
          [key + 'loading']: true,
          config: {...config, ...listObj}
        }, () => {
          // 刷新对应的配置信息
          this.setState({
            [key + 'loading']: false
          })
          [type + 'loading']: false
        })
      } else {
        this.setState({config: {...config, ...listObj}})
      }
        if (type === 'search') {
          this.handleSearch(card)
        } else if (type === 'action') {
          this.handleAction(card)
        } else if (type === 'columns') {
          this.handleColumn(card)
        }
      })
    } else {
      this.setState({config: {...config, ...listObj}})
      this.setState({config: {...config, [type]: list}})
    }
  }
@@ -622,20 +625,20 @@
            text: this.state.dict['header.form.refresh.view']
          }]
        },
        {
          type: 'select',
          key: 'method',
          label: this.state.dict['header.form.request.method'],
          initVal: card.method || 'POST',
          required: true,
          options: [{
            MenuID: 'POST',
            text: 'POST'
          }, {
            MenuID: 'GET',
            text: 'GET'
          }]
        },
        // {
        //   type: 'select',
        //   key: 'method',
        //   label: this.state.dict['header.form.request.method'],
        //   initVal: card.method || 'POST',
        //   required: true,
        //   options: [{
        //     MenuID: 'POST',
        //     text: 'POST'
        //   }, {
        //     MenuID: 'GET',
        //     text: 'GET'
        //   }]
        // },
        {
          type: 'select',
          key: 'icon',
@@ -653,11 +656,31 @@
          options: []
        },
        {
          type: 'textarea',
          type: 'text',
          key: 'sql',
          label: this.state.dict['header.form.datasource'],
          initVal: card.sql || '',
          initVal: card.sql || this.state.config.setting.tableName || '',
          required: false
        },
        {
          type: 'select',
          key: 'sqlType',
          label: this.state.dict['header.form.action.type'],
          initVal: card.sqlType || 'insert',
          required: false,
          options: [{
            MenuID: 'insert',
            text: this.state.dict['header.form.action.insert']
          }, {
            MenuID: 'update',
            text: this.state.dict['header.form.action.update']
          }, {
            MenuID: 'LogicDelete',
            text: this.state.dict['header.form.action.LogicDelete']
          }, {
            MenuID: 'delete',
            text: this.state.dict['header.form.action.delete']
          }]
        }
      ]
    })
@@ -697,6 +720,12 @@
            }, {
              MenuID: 'picture',
              text: this.state.dict['header.form.picture']
            }, {
              MenuID: 'number',
              text: this.state.dict['header.form.number']
            }, {
              MenuID: 'textarea',
              text: this.state.dict['header.form.textarea']
            }]
          },
          {
@@ -731,7 +760,7 @@
            }]
          },
          {
            type: 'select',
            type: 'radio',
            key: 'IsSort',
            label: this.state.dict['header.form.IsSort'],
            initVal: card.IsSort,
@@ -747,10 +776,110 @@
          {
            type: 'number',
            key: 'Width',
            min: 1,
            max: 1000,
            decimal: 0,
            label: this.state.dict['header.form.columnWidth'],
            initVal: card.Width,
            required: true
          },
          {
            type: 'number',
            key: 'decimal',
            min: 0,
            max: 18,
            decimal: 0,
            label: this.state.dict['header.form.decimal'],
            initVal: card.decimal,
            required: false
          },
          {
            type: 'select',
            key: 'format',
            label: this.state.dict['header.form.format'],
            initVal: card.format || '',
            options: [{
              MenuID: '',
              text: this.state.dict['header.form.empty']
            }, {
              MenuID: 'thdSeparator',
              text: this.state.dict['header.form.thdSeparator']
            }],
            required: false
          },
          {
            type: 'text',
            key: 'prefix',
            label: this.state.dict['header.form.prefix'],
            initVal: card.prefix || '',
            required: false,
            readonly: false
          },
          {
            type: 'select',
            key: 'match',
            label: this.state.dict['header.form.match'],
            initVal: card.match || '',
            options: [{
              MenuID: '',
              text: this.state.dict['header.form.empty']
            }, {
              MenuID: '>',
              text: '>'
            }, {
              MenuID: '<',
              text: '<'
            }, {
              MenuID: '>=',
              text: '>='
            }, {
              MenuID: '<=',
              text: '<='
            }, {
              MenuID: 'between',
              text: 'between'
            }],
            required: false
          },
          {
            type: 'text',
            key: 'matchVal',
            min: -Infinity,
            max: Infinity,
            decimal: 0,
            label: this.state.dict['header.form.matchVal'],
            initVal: card.matchVal || '',
            required: false,
            readonly: false
          },
          {
            type: 'select',
            key: 'color',
            label: this.state.dict['header.form.color'],
            initVal: card.color || '',
            options: [{
              MenuID: '',
              text: this.state.dict['header.form.empty']
            }, {
              MenuID: 'red',
              text: '红色(内容)'
            }, {
              MenuID: 'redbg',
              text: '红色(背景)'
            }, {
              MenuID: 'orange',
              text: '橙色(内容)'
            }, {
              MenuID: 'orangebg',
              text: '橙色(背景)'
            }, {
              MenuID: 'green',
              text: '绿色(内容)'
            }, {
              MenuID: 'greenbg',
              text: '绿色(背景)'
            }],
            required: false
          }
        ]
      })
@@ -981,9 +1110,15 @@
          LongParam: _LongParam
        }
        
        this.setState({
          menuloading: true
        })
        if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
          this.setState({
            menucloseloading: true
          })
        } else {
          this.setState({
            menuloading: true
          })
        }
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
@@ -1001,7 +1136,8 @@
            this.submitAction(btnParam)
          } else {
            this.setState({
              menuloading: false
              menuloading: false,
              menucloseloading: false
            })
            notification.warning({
              top: 92,
@@ -1021,9 +1157,16 @@
          PageParam: JSON.stringify(_pageParam),
          LongParam: _LongParam
        }
        this.setState({
          menuloading: true
        })
        if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
          this.setState({
            menucloseloading: true
          })
        } else {
          this.setState({
            menuloading: true
          })
        }
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
@@ -1040,7 +1183,8 @@
            this.submitAction(btnParam)
          } else {
            this.setState({
              menuloading: false
              menuloading: false,
              menucloseloading: false
            })
            notification.warning({
              top: 92,
@@ -1074,12 +1218,14 @@
          this.props.handleConfig('')
        } else {
          this.setState({
            menuloading: false
            menuloading: false,
            menucloseloading: false
          })
        }
      } else {
        this.setState({
          menuloading: false
          menuloading: false,
          menucloseloading: false
        })
        notification.warning({
          top: 92,
@@ -1499,6 +1645,14 @@
    }
  }
  onEnabledChange = () => {
    const { config } = this.state
    this.setState({
      config: {...config, enabled: !config.enabled}
    })
  }
  render () {
    const configAction = this.state.config.action.filter(_action =>
      !_action.origin && (_action.OpenType === 'pop' || _action.OpenType === 'popview' || _action.OpenType === 'blank' || _action.OpenType === 'tab')
@@ -1598,6 +1752,7 @@
          <div className="setting">
            <Card title={this.state.dict['header.menu.page.configurable']} bordered={false} extra={
              <div>
                <Switch className="big" checkedChildren="启" unCheckedChildren="关" defaultChecked={this.state.config.enabled} onChange={this.onEnabledChange} />
                <Button type="primary" onClick={this.changeTemplate}>{this.state.dict['header.menu.template.change']}</Button>
                <Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['header.save']}</Button>
                <Button onClick={this.cancelConfig}>{this.state.dict['header.return']}</Button>
@@ -1745,7 +1900,7 @@
          visible={this.state.closeVisible}
          onCancel={() => { this.setState({closeVisible: false}) }}
          footer={[
            <Button key="save" className="mk-btn mk-green" onClick={this.submitConfig}>{this.state.dict['header.save']}</Button>,
            <Button key="save" className="mk-btn mk-green" loading={this.state.menucloseloading} onClick={this.submitConfig}>{this.state.dict['header.save']}</Button>,
            <Button key="confirm" className="mk-btn mk-yellow" onClick={() => {this.props.handleConfig('')}}>{this.state.dict['header.notsave']}</Button>,
            <Button key="cancel" onClick={() => { this.setState({closeVisible: false}) }}>{this.state.dict['header.cancel']}</Button>
          ]}