king
2024-02-04 0bbaa727cdfc65622e33e91c4bf694c83f184535
src/templates/sharecomponent/actioncomponent/verifyexcelin/index.jsx
@@ -17,8 +17,10 @@
const { TabPane } = Tabs
const { confirm } = Modal
const { Search } = Input
const { Paragraph } = Typography
const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
const FullScripts = asyncComponent(() => import('@/templates/zshare/verifycard/fullScripts'))
class VerifyCard extends Component {
  static propTpyes = {
@@ -30,6 +32,7 @@
    verify: {},
    systemScripts: [],
    activeKey: 'basemsg',
    searchKey: '',
    excelColumns: [
      {
        title: '字段',
@@ -37,6 +40,9 @@
        width: '14%',
        inputType: 'input',
        unique: true,
        strict: true,
        searchable: true,
        copy: true,
        editable: true
      },
      {
@@ -44,6 +50,7 @@
        dataIndex: 'Text',
        width: '14%',
        inputType: 'input',
        searchable: true,
        editable: true
      },
      {
@@ -52,6 +59,7 @@
        width: '15%',
        editable: true,
        inputType: 'select',
        keyCol: true,
        options: [
          { value: 'Nvarchar(10)', text: 'Nvarchar(10)' },
          { value: 'Nvarchar(20)', text: 'Nvarchar(20)' },
@@ -61,13 +69,35 @@
          { value: 'Nvarchar(512)', text: 'Nvarchar(512)' },
          { value: 'Nvarchar(1024)', text: 'Nvarchar(1024)' },
          { value: 'Nvarchar(2048)', text: 'Nvarchar(2048)' },
          { value: 'Nvarchar(4000)', text: 'Nvarchar(4000)' },
          { value: 'Nvarchar(max)', text: 'Nvarchar(max)' },
          { value: 'Int', text: 'Int' },
          { value: 'Decimal(18,0)', text: 'Decimal(18,0)' },
          { value: 'Decimal(18,2)', text: 'Decimal(18,2)' },
          { value: 'Decimal(18,4)', text: 'Decimal(18,4)' },
          { value: 'Decimal(18,6)', text: 'Decimal(18,6)' },
          { value: 'date', text: 'date' }
          { value: 'date', text: 'date' },
          { value: 'datetime', text: 'datetime' }
        ]
      },
      {
        title: '导入',
        dataIndex: 'import',
        width: '10%',
        editable: true,
        inputType: 'radio',
        render: (text, record) => {
          if (record.import === 'init') {
            return '初始化'
          } else if (record.import === 'false') {
            return '否'
          }
          return '是'
        },
        options: [
          { value: 'true', text: '是' },
          { value: 'false', text: '否' },
          { value: 'init', text: '初始化' }
        ]
      },
      {
@@ -79,21 +109,16 @@
        render: (text, record) => record.required === 'true' ? '是' : '否'
      },
      {
        title: '导入',
        dataIndex: 'import',
        width: '10%',
        editable: true,
        inputType: 'switch',
        render: (text, record) => record.import !== 'false' ? '是' : '否'
      },
      {
        title: '最小值',
        dataIndex: 'min',
        width: '10%',
        required: false,
        inputType: 'number',
        unlimit: true,
        editable: true
        editable: true,
        keyVals: ['Int', 'Decimal(18,0)', 'Decimal(18,2)', 'Decimal(18,4)', 'Decimal(18,6)'],
        render: (text, record) => /^Decimal/ig.test(record.type) || /^int/ig.test(record.type) ? text : ''
      },
      {
        title: '最大值',
@@ -102,7 +127,9 @@
        required: false,
        inputType: 'number',
        unlimit: true,
        editable: true
        editable: true,
        keyVals: ['Int', 'Decimal(18,0)', 'Decimal(18,2)', 'Decimal(18,4)', 'Decimal(18,6)'],
        render: (text, record) => /^Decimal/ig.test(record.type) || /^int/ig.test(record.type) ? text : ''
      }
    ],
    uniqueColumns: [
@@ -253,8 +280,6 @@
    let _verify = fromJS(card.verify || {}).toJS()
    let _columns = _verify.columns || []
    delete _verify.dataresource
    // 旧数据兼容
    _columns = _columns.map(col => {
      col.required = col.required || 'true'
@@ -283,6 +308,7 @@
    }
    this.setState({
      searchKey: '',
      verify: {
        ..._verify,
        default: _verify.default || 'true',
@@ -311,20 +337,21 @@
    
    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 {
@@ -374,48 +401,102 @@
    const { verify } = this.state
    let _columns = JSON.parse(JSON.stringify(verify.columns))
    let _names = {}
    let _cols = _columns.map(item => {
      let key = item.Column.toLowerCase()
      _names[key] = item.Text
    let _cols = _columns.map(col => col.Column)
      return key
    })
    let names = {$up: false}
    columns.forEach(col => {
      if (col.field && !_cols.includes(col.field)) {
        let _type = 'Nvarchar(50)'
        let _limit = '50'
        if (col.type === 'number' && !col.decimal) {
          _type = 'Int'
          _limit = ''
        } else if (col.type === 'number') {
          _type = 'Decimal(18,' + col.decimal + ')'
          _limit = col.decimal
      if (!col.field) return
      let key = col.field.toLowerCase()
      if (_cols.includes(key)) {
        if (_names[key] !== col.label) {
          names.$up = true
          names[key] = col.label
        }
        let _cell = {
          uuid: col.uuid,
          Column: col.field,
          Text: col.label,
          type: _type,
          limit: _limit,
          import: 'true',
          required: 'true'
        }
        if (_type !== 'Nvarchar(50)') {
          _cell.min = 0
          _cell.max = 999999
        }
        _columns.push(_cell)
        return
      }
      let _type = 'Nvarchar(50)'
      let _limit = '50'
      if (col.type === 'number' && !col.decimal) {
        _type = 'Int'
        _limit = ''
      } else if (col.type === 'number') {
        _type = 'Decimal(18,' + col.decimal + ')'
        _limit = col.decimal
      }
      let _cell = {
        uuid: col.uuid,
        Column: col.field,
        Text: col.label,
        type: _type,
        limit: _limit,
        import: 'true',
        required: 'true'
      }
      if (_type !== 'Nvarchar(50)') {
        _cell.min = 0
        _cell.max = 999999
      }
      _columns.push(_cell)
    })
    this.setState({
      verify: {
        ...verify,
        columns: _columns
      }
    }, () => {
      this.resetUniqueColumns()
    })
    if (names.$up) {
      const that = this
      confirm({
        content: '部分字段名称与显示列不一致,是否更新?',
        okText: '更新',
        cancelText: '不更新',
        onOk() {
          _columns = _columns.map(item => {
            let key = item.Column.toLowerCase()
            if (names[key]) {
              item.Text = names[key]
            }
            return item
          })
          that.setState({
            verify: {
              ...verify,
              columns: _columns
            }
          }, () => {
            that.resetUniqueColumns()
          })
        },
        onCancel() {
          that.setState({
            verify: {
              ...verify,
              columns: _columns
            }
          }, () => {
            that.resetUniqueColumns()
          })
        }
      })
    } else {
      this.setState({
        verify: {
          ...verify,
          columns: _columns
        }
      }, () => {
        this.resetUniqueColumns()
      })
    }
  }
  clearField = () => {
@@ -472,13 +553,18 @@
        col.type = 'Decimal(18,2)'
      }
      if (col.import === 'init') {
        col.required = 'false'
        col.min = ''
        col.max = ''
      }
      if (/^Nvarchar/ig.test(col.type)) {
        col.limit = col.type.match(/\d+/) ? col.type.match(/\d+/)[0] : '20000'
      } else if (/^Decimal/ig.test(col.type)) {
        col.limit = col.type.match(/\d+/ig)[1]
        col.required = 'true'
      } else if (/^int/ig.test(col.type)) {
        col.required = 'true'
      } else {
        col.limit = ''
      }
@@ -626,7 +712,7 @@
        if (!err) {
          let _verify = {...verify, ...values}
          let cols = _verify.columns.map(col => col.Column)
          let cols = _verify.columns.map(col => col.Column.toLowerCase())
          cols = Array.from(new Set(cols))
          if (_verify.columns.length === 0) {
@@ -654,6 +740,15 @@
              return
            }
          }
          _verify.columns.sort((a, b) => {
            if (a.import === 'init' && b.import !== 'init') {
              return 1
            } else if (a.import !== 'init' && b.import === 'init') {
              return -1
            }
            return 0
          })
          let _loading = false
          if (this.scriptsForm && this.scriptsForm.state.editItem) {
@@ -753,7 +848,7 @@
  render() {
    const { card } = this.props
    const { getFieldDecorator } = this.props.form
    const { verify, excelColumns, scriptsColumns, uniqueColumns, activeKey } = this.state
    const { verify, excelColumns, scriptsColumns, uniqueColumns, activeKey, searchKey } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -821,13 +916,13 @@
          } key="excelcolumn">
            <ColumnForm columnChange={this.columnChange}/>
            <Button className="excel-col-add mk-green" title="添加显示列字段" onClick={this.columnFieldInput}>
              同步显示列
              同步字段集
            </Button>
            <Button className="excel-col-add mk-red" title="清空Excel列" onClick={this.clearField}>
              清空Excel列
            </Button>
            <Col style={{fontSize: '12px', color: '#757575', paddingLeft: '10px'}} span={24}>注:数值类型(int 或 decimal),内容为必填;最大值和最小值在类型为数值时有效。</Col>
            <EditTable actions={['edit', 'move', 'copy', 'del']} type="excelcolumn" data={verify.columns} columns={excelColumns} onChange={this.changeColumns}/>
            <Col style={{fontSize: '12px', color: '#757575', paddingLeft: '10px'}} span={24}>注:数值类型(int 或 decimal),内容为必填;最大值和最小值在类型为数值时有效。导入-初始化:用于excel中不存在,导入时需要初始化的字段</Col>
            <EditTable actions={['edit', 'move', 'copy', 'del', 'extra:required:是否必填']} searchKey={searchKey} type="excelcolumn" data={verify.columns} columns={excelColumns} onChange={this.changeColumns}/>
          </TabPane>
          {card.intertype === 'system' ? <TabPane tab={
            <span>
@@ -844,6 +939,23 @@
              {verify.scripts.length ? <span className="count-tip">{verify.scripts.length}</span> : null}
            </span>
          } key="scripts" id="mk-exin-script">
            <FullScripts
              scripts={verify.scripts}
              getScriptsFullForm={() => this.scriptsFullForm}
              getScriptsForm={() => this.scriptsForm}
              handleStatus={this.handleStatus}
              handleDelete={this.handleDelete}
            >
              <CustomScript
                type="fullscreen"
                btn={this.props.card}
                usefulfields={verify.columns}
                scripts={verify.scripts}
                systemScripts={this.state.systemScripts}
                scriptsChange={this.scriptsChange}
                wrappedComponentRef={(inst) => this.scriptsFullForm = inst}
              />
            </FullScripts>
            <CustomScript
              btn={this.props.card}
              usefulfields={verify.columns}
@@ -854,11 +966,16 @@
            />
            <EditTable actions={['move']} data={verify.scripts} columns={scriptsColumns} onChange={(scripts) => {this.setState({verify: {...verify, scripts}})}}/>
          </TabPane> : null}
          <TabPane tab="信息提示" key="tip">
          <TabPane tab={
            <span>
              信息提示
              {activeKey === 'excelcolumn' ? <span onClick={(e) => {e.stopPropagation()}}><Search className="mk-search-fields" defaultValue={searchKey} allowClear onSearch={(val, e) => {e.stopPropagation();this.setState({searchKey: val})}} /></span> : null}
            </span>
          } 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">
                      查看
@@ -866,14 +983,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">
                      查看
@@ -883,7 +1000,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">
                      查看
@@ -891,14 +1016,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">
                      查看
@@ -906,14 +1031,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">
                      查看
@@ -923,7 +1048,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">
                      查看
@@ -933,9 +1058,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>