king
2024-02-04 0bbaa727cdfc65622e33e91c4bf694c83f184535
src/menu/components/table/edit-table/columns/tableIn/index.jsx
@@ -1,13 +1,14 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Tabs, Row, Col, Input, Button, Table, Popconfirm, notification, Modal, message, InputNumber, Radio, Typography } from 'antd'
import { StopTwoTone, CheckCircleTwoTone, EditOutlined, ArrowUpOutlined, ArrowDownOutlined, SwapOutlined, DeleteOutlined } from '@ant-design/icons'
import { Form, Tabs, Row, Col, Input, Button, Popconfirm, notification, Modal, message, Select, Cascader, Tooltip, InputNumber, Radio, Typography } from 'antd'
import { StopTwoTone, CheckCircleTwoTone, EditOutlined, SwapOutlined, DeleteOutlined, QuestionCircleOutlined } from '@ant-design/icons'
import moment from 'moment'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import MenuUtils from '@/utils/utils-custom.js'
import UniqueForm from './uniqueform'
import CustomScript from './customscript'
import asyncComponent from '@/utils/asyncComponent'
@@ -17,17 +18,18 @@
const { confirm } = Modal
const { Paragraph } = Typography
const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
const FullScripts = asyncComponent(() => import('@/templates/zshare/verifycard/fullScripts'))
class VerifyTableCard extends Component {
  static propTpyes = {
    columns: PropTypes.array,  // 显示列
    dict: PropTypes.object,    // 字典项
    card: PropTypes.object,
  }
  state = {
    verify: {},
    fields: [],
    modules: [],
    fieldLabel: {},
    systemScripts: [],
    activeKey: 'basemsg',
@@ -48,7 +50,7 @@
      {
        title: '报错编码',
        dataIndex: 'errorCode',
        width: '12%',
        width: '10%',
        editable: true,
        inputType: 'select',
        options: [
@@ -61,13 +63,24 @@
      {
        title: '验证类型',
        dataIndex: 'verifyType',
        width: '12%',
        render: (text, record) => record.verifyType === 'logic' ? '逻辑验证' : '物理验证',
        width: '14%',
        render: (text, record) => {
          let names = {
            physical: '物理验证(全量验证)',
            logic: '逻辑验证(全量验证)',
            physical_temp: '物理验证(仅临时表)',
            logic_temp: '逻辑验证(仅临时表)',
          }
          return names[text] || '物理验证(全量验证)'
        },
        inputType: 'select',
        editable: true,
        options: [
          { value: 'physical', text: '物理验证' },
          { value: 'logic', text: '逻辑验证' }
          { value: 'physical', text: '物理验证(全量验证)' },
          { value: 'logic', text: '逻辑验证(全量验证)' },
          { value: 'physical_temp', text: '物理验证(仅临时表)' },
          { value: 'logic_temp', text: '逻辑验证(仅临时表)' }
        ]
      },
      {
@@ -80,13 +93,13 @@
        render: (text, record) => record.status === 'false' ?
          (
            <div>
              {this.props.dict['model.status.forbidden']}
              禁用
              <StopTwoTone style={{marginLeft: '5px'}} twoToneColor="#ff4d4f" />
            </div>
          ) :
          (
            <div>
              {this.props.dict['model.status.open']}
              启用
              <CheckCircleTwoTone style={{marginLeft: '5px'}} twoToneColor="#52c41a" />
            </div>
          )
@@ -100,12 +113,12 @@
        render: (text) => {
          let title = text.match(/^\s*\/\*.+\*\//)
          title = title && title[0] ? title[0] : ''
          text = title ? text.replace(title, '') : text
          let _text = title ? text.replace(title, '') : text
          return (
            <div>
              {title ? <span style={{color: '#a50'}}>{title}</span> : null}
              <Paragraph copyable ellipsis={{ rows: 4, expandable: true }}>{text}</Paragraph>
              {title ? <span style={{color: '#a50'}}>{title}<span style={{fontSize: '12px', marginLeft: '5px'}}>{_text.length}</span></span> : null}
              <Paragraph copyable={{ text: text }} ellipsis={{ rows: 4, expandable: true }}>{_text}</Paragraph>
            </div>
          )
        }
@@ -115,15 +128,13 @@
        dataIndex: 'position',
        width: '10%',
        render: (text, record) => {
          let _text = ''
          if (record.position === 'front') {
            _text = 'sql前'
          } else if (record.position === 'init') {
            _text = '初始化'
          if (record.position === 'init') {
            return <span style={{color: 'orange'}}>初始化</span>
          } else if (record.position === 'front') {
            return <span style={{color: '#26C281'}}>sql前</span>
          } else {
            _text = 'sql后'
            return <span style={{color: '#1890ff'}}>sql后</span>
          }
          return _text
        }
      },
      {
@@ -133,13 +144,13 @@
        render: (text, record) => record.status === 'false' ?
          (
            <div>
              {this.props.dict['model.status.forbidden']}
              禁用
              <StopTwoTone style={{marginLeft: '5px'}} twoToneColor="#ff4d4f" />
            </div>
          ) :
          (
            <div>
              {this.props.dict['model.status.open']}
              启用
              <CheckCircleTwoTone style={{marginLeft: '5px'}} twoToneColor="#52c41a" />
            </div>
          )
@@ -150,14 +161,12 @@
        width: '20%',
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
          (<div style={{textAlign: 'center'}}>
            <span className="operation-btn" onClick={() => this.handleEdit(record, 'scripts')} style={{color: '#1890ff'}}><EditOutlined /></span>
            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'scripts', 'up')} style={{color: '#1890ff'}}><ArrowUpOutlined /></span>
            <span className="operation-btn" onClick={() => this.handleUpDown(record, 'scripts', 'down')} style={{color: '#ff4d4f'}}><ArrowDownOutlined /></span>
            <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record, 'scripts')} style={{color: '#8E44AD'}}><SwapOutlined /></span>
            <span className="operation-btn" title="状态切换" onClick={() => this.handleStatus(record, 'scripts')} style={{color: '#8E44AD'}}><SwapOutlined /></span>
            <Popconfirm
              overlayClassName="popover-confirm"
              title={this.props.dict['model.query.delete']}
              title="确定删除吗?"
              onConfirm={() => this.handleDelete(record, 'scripts')
            }>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><DeleteOutlined /></span>
@@ -168,27 +177,34 @@
  }
  UNSAFE_componentWillMount() {
    const { columns, card, setting } = this.props
    let _verify = fromJS(card).toJS()
    const { columns, submit, setting, uuid } = this.props.config
    let _verify = fromJS(submit).toJS()
    _verify.sheet = _verify.sheet || setting.tableName
    let fieldLabel = {}
    // let _columns = []
    // let _fields = {}
    columns.forEach(col => {
      fieldLabel[col.field] = col.label
      // _fields[col.field] = col
    })
    // cols.forEach(col => {
    //   if (!col.field || col.type === 'index' || !_fields[col.field]) return
    //   _columns.push(_fields[col.field])
    // })
    let supId = ''
    if (setting && setting.supModule) {
      let pid = setting.supModule[setting.supModule.length - 1]
      if (pid && pid !== 'empty') {
        supId = pid
      } else {
        supId = ''
      }
    }
    let menu = window.GLOB.customMenu
    let modules = MenuUtils.getSubModules(menu.components, uuid, supId, menu.interfaces || null)
    this.setState({
      fields: fromJS(columns).toJS().filter(item => item.field !== setting.primaryKey),
      fieldLabel,
      modules: modules,
      verify: _verify
    }, () => {
      this.resetUniqueColumns()
@@ -196,31 +212,46 @@
  }
  componentDidMount () {
    this.getsysScript()
  }
  getsysScript = () => {
    if (sessionStorage.getItem('mk_sys_scripts')) {
      this.setState({
        systemScripts: JSON.parse(sessionStorage.getItem('mk_sys_scripts'))
      })
      return
    }
    let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from  s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort`
    _scriptSql = Utils.formatOptions(_scriptSql)
    _scriptSql = Utils.formatOptions(_scriptSql, 'x')
    let _sParam = {
      func: 'sPC_Get_SelectedList',
      LText: _scriptSql,
      obj_name: 'data',
      arr_field: 'funcname,longparam'
      arr_field: 'funcname,longparam',
      exec_type: 'x'
    }
    
    _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp)
    _sParam.secretkey = Utils.encrypt('', _sParam.timestamp)
    _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 云端数据验证
    
    Api.getSystemConfig(_sParam).then(res => {
    Api.getCloudConfig(_sParam).then(res => {
      if (res.status) {
        let _scripts = res.data.map(item => {
          return {
            name: item.funcname,
            value: window.decodeURIComponent(window.atob(item.longparam))
          }
        })
        sessionStorage.setItem('mk_sys_scripts', JSON.stringify(_scripts))
        this.setState({
          systemScripts: res.data.map(item => {
            return {
              name: item.funcname,
              value: window.decodeURIComponent(window.atob(item.longparam))
            }
          })
          systemScripts: _scripts
        })
      } else {
        notification.warning({
@@ -299,6 +330,8 @@
      verify.scripts.push(values)
    }
    MKEmitter.emit('editLineId', values.uuid)
    this.setState({
      verify: verify
    })
@@ -357,51 +390,6 @@
          return item
        }
      })
    }
    this.setState({
      verify: verify
    })
  }
  handleUpDown = (record, type, direction) => {
    let verify = JSON.parse(JSON.stringify(this.state.verify))
    let index = 0
    if (type === 'unique') {
      verify.uniques = verify.uniques.filter((item, i) => {
        if (item.uuid === record.uuid) {
          index = i
        }
        return item.uuid !== record.uuid
      })
      if ((index === 0 && direction === 'up') || (index === verify.uniques.length && direction === 'down')) {
        return
      }
      if (direction === 'up') {
        verify.uniques.splice(index - 1, 0, record)
      } else {
        verify.uniques.splice(index + 1, 0, record)
      }
    } else if (type === 'scripts') {
      verify.scripts = verify.scripts.filter((item, i) => {
        if (item.uuid === record.uuid) {
          index = i
        }
        return item.uuid !== record.uuid
      })
      if ((index === 0 && direction === 'up') || (index === verify.scripts.length && direction === 'down')) {
        return
      }
      if (direction === 'up') {
        verify.scripts.splice(index - 1, 0, record)
      } else {
        verify.scripts.splice(index + 1, 0, record)
      }
    }
    this.setState({
@@ -512,7 +500,8 @@
  }
  render() {
    const { verify, scriptsColumns, uniqueColumns, activeKey, fields } = this.state
    const { config } = this.props
    const { verify, scriptsColumns, uniqueColumns, activeKey, fields, modules } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -527,12 +516,12 @@
    return (
      <div id="verify-excel-box-tab">
        <Tabs activeKey={activeKey} className="verify-card-box" onChange={this.tabchange}>
        <Tabs activeKey={activeKey} className="tablein-verify-card-box" onChange={this.tabchange}>
          <TabPane tab="基础验证" key="basemsg">
            <Form {...formItemLayout}>
              <Row gutter={24}>
                <Col span={8}>
                  <Form.Item required label={this.props.dict['model.form.tablename']}>
                  <Form.Item required label="表名">
                    <Input value={verify.sheet} placeholder="" autoComplete="off" onChange={(e) => this.onOptionChange(e.target.value, 'sheet')}/>
                  </Form.Item>
                </Col>
@@ -549,8 +538,16 @@
                    <Input value={verify.innerFunc} placeholder="" autoComplete="off" onChange={(e) => this.onOptionChange(e.target.value, 'innerFunc')}/>
                  </Form.Item>
                </Col> : null}
                {verify.intertype === 'inner' ? <Col span={8}>
                  <Form.Item required label="记录用户">
                    <Radio.Group value={verify.recordUser || 'false'} onChange={(e) => this.onOptionChange(e.target.value, 'recordUser')}>
                      <Radio value="false">否</Radio>
                      <Radio value="true">是</Radio>
                    </Radio.Group>
                  </Form.Item>
                </Col> : null}
                {verify.intertype === 'system' ? <Col span={8}>
                  <Form.Item required label={'默认sql'}>
                  <Form.Item required label="默认sql">
                    <Radio.Group value={verify.default} onChange={(e) => this.onOptionChange(e.target.value, 'default')}>
                      <Radio value="true">执行</Radio>
                      <Radio value="false">不执行</Radio>
@@ -558,31 +555,50 @@
                  </Form.Item>
                </Col> : null}
                <Col span={8}>
                  <Form.Item label={'成功后'}>
                    <Radio.Group style={{whiteSpace: 'nowrap'}} value={verify.execSuccess} onChange={(e) => this.onOptionChange(e.target.value, 'execSuccess')}>
                      <Radio value="never">不刷新</Radio>
                      <Radio value="grid">刷新表格</Radio>
                      <Radio value="mainline">上级(行)</Radio>
                    </Radio.Group>
                  <Form.Item label={
                    <Tooltip placement="topLeft" title="《刷新行》与《刷新行 / 组件》只在数据提交为 修改项 时有效。">
                      <QuestionCircleOutlined className="mk-form-tip" />
                      成功后
                    </Tooltip>
                  }>
                    <Select value={verify.execSuccess} onChange={(val) => this.onOptionChange(val, 'execSuccess')}>
                      <Select.Option value="never">不刷新</Select.Option>
                      <Select.Option value="line" disabled={config.wrap.commit !== 'change'}>刷新行</Select.Option>
                      <Select.Option value="grid">刷新组件</Select.Option>
                      <Select.Option value="line_grid" disabled={config.wrap.commit !== 'change'}>刷新行 / 组件</Select.Option>
                      <Select.Option value="mainline">上级(行)</Select.Option>
                    </Select>
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'失败后'}>
                    <Radio.Group style={{whiteSpace: 'nowrap'}} value={verify.execError} onChange={(e) => this.onOptionChange(e.target.value, 'execError')}>
                      <Radio value="never">不刷新</Radio>
                      <Radio value="grid">刷新表格</Radio>
                      <Radio value="mainline">上级(行)</Radio>
                    </Radio.Group>
                  <Form.Item label="失败后">
                    <Select value={verify.execError} onChange={(val) => this.onOptionChange(val, 'execError')}>
                      <Select.Option value="never">不刷新</Select.Option>
                      <Select.Option value="line" disabled={config.wrap.commit !== 'change'}>刷新行</Select.Option>
                      <Select.Option value="grid">刷新组件</Select.Option>
                      <Select.Option value="line_grid" disabled={config.wrap.commit !== 'change'}>刷新行 / 组件</Select.Option>
                      <Select.Option value="mainline">上级(行)</Select.Option>
                    </Select>
                  </Form.Item>
                </Col>
                {isPop ? <Col span={8}>
                  <Form.Item label={'成功后'}>
                  <Form.Item label="成功后">
                    <Radio.Group style={{whiteSpace: 'nowrap'}} value={verify.closetab || 'false'} onChange={(e) => this.onOptionChange(e.target.value, 'closetab')}>
                      <Radio value="false">标签不关闭</Radio>
                      <Radio value="true">标签关闭</Radio>
                    </Radio.Group>
                  </Form.Item>
                </Col> : null}
                <Col span={8}>
                  <Form.Item label={
                    <Tooltip placement="topLeft" title="执行成功后(或弹窗标签关闭时),需要同步刷新的组件。注:选择当前组件的上级组件无效,刷新上级组件请选择成功后“上级(行)”。">
                      <QuestionCircleOutlined className="mk-form-tip" />
                      刷新组件
                    </Tooltip>
                  }>
                    <Cascader options={modules} value={verify.syncComponent || []} expandTrigger="hover" allowClear placeholder="" onChange={(val) => this.onOptionChange(val, 'syncComponent')}/>
                  </Form.Item>
                </Col>
              </Row>
            </Form>
          </TabPane>
@@ -592,7 +608,7 @@
              {verify.uniques.length ? <span className="count-tip">{verify.uniques.length}</span> : null}
            </span>
          } key="unique">
            <UniqueForm fields={fields} dict={this.props.dict} uniqueChange={this.uniqueChange}/>
            <UniqueForm fields={fields} uniqueChange={this.uniqueChange}/>
            <EditTable actions={['edit', 'move', 'del']} data={verify.uniques} columns={uniqueColumns} onChange={this.changeUniques}/>
          </TabPane>
          <TabPane disabled={verify.intertype !== 'system'} tab={
@@ -601,8 +617,24 @@
              {verify.scripts.length ? <span className="count-tip">{verify.scripts.length}</span> : null}
            </span>
          } key="scripts">
            <FullScripts
              scripts={verify.scripts}
              getScriptsFullForm={() => this.scriptsFullForm}
              getScriptsForm={() => this.scriptsForm}
              handleStatus={this.handleStatus}
              handleDelete={this.handleDelete}
            >
              <CustomScript
                type="fullscreen"
                btn={verify}
                usefulfields={fields}
                scripts={verify.scripts}
                systemScripts={this.state.systemScripts}
                scriptsChange={this.scriptsChange}
                wrappedComponentRef={(inst) => this.scriptsFullForm = inst}
              />
            </FullScripts>
            <CustomScript
              dict={this.props.dict}
              btn={verify}
              usefulfields={fields}
              scripts={verify.scripts}
@@ -610,20 +642,13 @@
              scriptsChange={this.scriptsChange}
              wrappedComponentRef={(inst) => this.scriptsForm = inst}
            />
            <Table
              bordered
              rowKey="uuid"
              className="custom-table"
              dataSource={verify.scripts}
              columns={scriptsColumns}
              pagination={false}
            />
            <EditTable actions={['move']} data={verify.scripts} columns={scriptsColumns} onChange={(scripts) => {this.setState({verify: {...verify, scripts}})}}/>
          </TabPane>
          <TabPane tab="信息提示" key="tip">
            <Form {...formItemLayout}>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                  <Form.Item label="提示编码">
                    <span className="errorval"> S </span>
                    <Button onClick={() => {this.showError('S')}} type="primary" size="small">
                      查看
@@ -631,14 +656,14 @@
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'停留时间'}>
                  <Form.Item label="停留时间">
                    <InputNumber defaultValue={verify.stime || 2} min={1} max={10000} precision={0} onChange={(val) => {this.timeChange(val, 'stime')}} />
                  </Form.Item>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                  <Form.Item label="提示编码">
                    <span className="errorval"> Y </span>
                    <Button onClick={() => {this.showError('Y')}} type="primary" size="small">
                      查看
@@ -648,7 +673,15 @@
              </Row>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                  <Form.Item label="提示编码">
                    <span className="errorval"> -1 </span>
                    执行成功无提示。
                  </Form.Item>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label="提示编码">
                    <span className="errorval"> N </span>
                    <Button onClick={() => {this.showError('N')}} type="primary" size="small">
                      查看
@@ -656,14 +689,14 @@
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'停留时间'}>
                  <Form.Item label="停留时间">
                    <InputNumber defaultValue={verify.ntime || 10} min={1} max={10000} precision={0} onChange={(val) => {this.timeChange(val, 'ntime')}} />
                  </Form.Item>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                  <Form.Item label="提示编码">
                    <span className="errorval"> F </span>
                    <Button onClick={() => {this.showError('F')}} type="primary" size="small">
                      查看
@@ -671,14 +704,14 @@
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'停留时间'}>
                  <Form.Item label="停留时间">
                    <InputNumber defaultValue={verify.ftime || 10} min={1} max={10000} precision={0} onChange={(val) => {this.timeChange(val, 'ftime')}} />
                  </Form.Item>
                </Col>
              </Row>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                  <Form.Item label="提示编码">
                    <span className="errorval"> E </span>
                    <Button onClick={() => {this.showError('E')}} type="primary" size="small">
                      查看
@@ -688,7 +721,7 @@
              </Row>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                  <Form.Item label="提示编码">
                    <span className="errorval"> NM </span>
                    <Button onClick={() => {this.showError('NM')}} type="primary" size="small">
                      查看
@@ -698,9 +731,9 @@
              </Row>
              <Row gutter={24}>
                <Col offset={6} span={6}>
                  <Form.Item label={'提示编码'}>
                    <span className="errorval"> -1 </span>
                    不提示
                  <Form.Item label="提示编码">
                    <span className="errorval"> -2 </span>
                    执行失败无提示
                  </Form.Item>
                </Col>
              </Row>