king
2020-11-05 ee50d5424a093209d1c5c549f4578107893b22f8
src/menu/datasource/verifycard/index.jsx
@@ -122,19 +122,77 @@
  }
  UNSAFE_componentWillMount() {
    const { config, mainSearch } = this.props
    const { config, mainSearch, menu } = this.props
    let search = config.search || []
    search = [...search, ...mainSearch]
    if (config.setting.useMSearch === 'true') { // 使用主搜索条件
      search = [...search, ...mainSearch]
    }
    let Marks = []
    let getcomponentmarks = (box, conf) => {
      if (!conf.parentId && box.Template === 'CustomPage') {
        box.components.forEach(item => {
          if (item.uuid !== conf.uuid && item.setting && item.setting.varMark) {
            Marks.push(item.setting.varMark)
          }
        })
      } else if (conf.parentId === box.parentId && conf.tabId === box.uuid) {
        box.components.forEach(item => {
          if (item.uuid !== conf.uuid && item.setting && item.setting.varMark) {
            Marks.push(item.setting.varMark)
          }
        })
      } else {
        box.components.forEach(item => {
          if (item.type !== 'tabs') return
          item.subtabs.forEach(tab => {
            getcomponentmarks(tab, conf)
          })
        })
      }
    }
    getcomponentmarks(menu, config)
    let _setting = fromJS(config.setting).toJS()
    if (!_setting.varMark) {
      _setting.varMark = this.getMark(Marks)
    }
    this.setState({
      columns: fromJS(config.columns).toJS(),
      setting: fromJS(config.setting).toJS(),
      setting: _setting,
      scripts: fromJS(config.scripts).toJS(),
      searches: search
      searches: search,
      varMarks: Marks
    })
    this.getsysScript()
  }
  getMark = (varMarks) => {
    let m = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    let i = 0
    let n = 25
    let name = ''
    while (!name) {
      name = `${m[n]}${m[i]}_`
      if (varMarks.includes(name) && n > 0) {
        i++
        if (i >= 26) {
          n--
          i = 0
        }
        name = ''
      }
    }
    return name
  }
  getsysScript = () => {
@@ -309,12 +367,32 @@
  }
  changeTab = (val) => {
    const { activeKey } = this.state
    const { config, mainSearch } = this.props
    const { activeKey, varMarks } = this.state
    this.setState({loading: true})
    if (activeKey === 'setting') {
      this.settingForm.handleConfirm().then(res => {
        let search = config.search || []
        if (res.useMSearch === 'true') { // 使用主搜索条件
          search = [...search, ...mainSearch]
        }
        if (res.varMark && varMarks.includes(res.varMark)) {
          notification.warning({
            top: 92,
            message: '变量标识不可重复!',
            duration: 5
          })
          this.setState({
            loading: false
          })
          return
        }
        this.setState({
          searches: search,
          setting: res
        }, () => {
          this.sqlverify(() => { // 验证成功
@@ -324,6 +402,7 @@
            })
          }, () => {             // 验证失败
            this.setState({
              activeKey: val,
              loading: false
            })
          }, true)
@@ -340,7 +419,7 @@
      let _loading = false
      if (this.scriptsForm && this.scriptsForm.state.editItem) {
        _loading = true
      } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
      } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && this.scriptsForm.props.form.getFieldValue('sql') !== ' ') {
        _loading = true
      }
@@ -360,27 +439,34 @@
        activeKey: val,
        loading: false
      })
      // this.sqlverify(() => { // 验证成功
      //   this.setState({
      //     activeKey: val,
      //     loading: false
      //   })
      // }, () => {             // 验证失败
      //   this.setState({
      //     loading: false
      //   })
      // }, true)
    }
  }
  submitDataSource = () => {
    const { activeKey, setting, columns, scripts } = this.state
    const { config, mainSearch } = this.props
    const { activeKey, setting, columns, scripts, varMarks } = this.state
    return new Promise((resolve, reject) => {
      if (activeKey === 'setting') {
        this.settingForm.handleConfirm().then(res => {
          let search = config.search || []
          if (res.useMSearch === 'true') { // 使用主搜索条件
            search = [...search, ...mainSearch]
          }
          if (res.varMark && varMarks.includes(res.varMark)) {
            notification.warning({
              top: 92,
              message: '变量标识不可重复!',
              duration: 5
            })
            reject()
            return
          }
          this.setState({
            searches: search,
            setting: res
          }, () => {
            this.sqlverify(() => { resolve({setting: res, columns, scripts }) }, reject, false)
@@ -394,7 +480,7 @@
        let _loading = false
        if (this.scriptsForm && this.scriptsForm.state.editItem) {
          _loading = true
        } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
        } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && this.scriptsForm.props.form.getFieldValue('sql') !== ' ') {
          _loading = true
        }
@@ -432,9 +518,21 @@
    }
    if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) {
      let result = SettingUtils.getDebugSql(setting, _scripts, columns, searches)
      if (result.error) {
        notification.warning({
          top: 92,
          message: result.error,
          duration: 5
        })
        reject()
        return
      }
      let param = {
        func: 's_debug_sql',
        LText: SettingUtils.getDebugSql(setting, _scripts, columns, searches)
        LText: result.sql
      }
      param.LText = Utils.formatOptions(param.LText)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')