| | |
| | | } |
| | | |
| | | changeTab = (val) => { |
| | | const { activeKey } = this.state |
| | | const { activeKey, setting } = this.state |
| | | |
| | | this.setState({loading: true}) |
| | | if (activeKey === 'setting') { |
| | | this.settingForm.handleConfirm().then(res => { |
| | | if (res.interType !== 'system' && val === 'scripts') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '使用系统接口时,才可以设置自定义脚本!', |
| | | duration: 5 |
| | | }) |
| | | this.setState({loading: false}) |
| | | return |
| | | } |
| | | |
| | | this.setState({ |
| | | setting: res |
| | | }, () => { |
| | | this.sqlverify(() => { // 验证成功 |
| | | if (res.interType === 'system') { // 系统接口,sql验证 |
| | | this.sqlverify(() => { // 验证成功 |
| | | this.setState({ |
| | | activeKey: val, |
| | | loading: false |
| | | }) |
| | | }, () => { // 验证失败 |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | }, activeKey) |
| | | } else { |
| | | this.setState({ |
| | | activeKey: val, |
| | | loading: false |
| | | }) |
| | | }, () => { // 验证失败 |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | }, true) |
| | | } |
| | | }) |
| | | }, () => { |
| | | this.setState({loading: false}) |
| | | }) |
| | | } else if (activeKey === 'columns') { |
| | | if (setting.interType !== 'system' && val === 'scripts') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '使用系统接口时,才可以设置自定义脚本!', |
| | | duration: 5 |
| | | }) |
| | | this.setState({loading: false}) |
| | | return |
| | | } else if (setting.interType !== 'system') { |
| | | this.setState({ |
| | | activeKey: val, |
| | | loading: false |
| | | }) |
| | | return |
| | | } |
| | | |
| | | this.sqlverify(() => { // 验证成功 |
| | | this.setState({ |
| | | activeKey: val, |
| | |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | }, true) |
| | | }, activeKey) |
| | | } else if (activeKey === 'scripts') { |
| | | let _loading = false |
| | | if (this.scriptsForm && this.scriptsForm.state.editItem) { |
| | |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | }, true) |
| | | }, activeKey) |
| | | } |
| | | } |
| | | |
| | |
| | | this.setState({ |
| | | setting: res |
| | | }, () => { |
| | | this.sqlverify(() => { resolve({setting: res, columns, scripts }) }, reject, false) |
| | | this.sqlverify(() => { resolve({setting: res, columns, scripts }) }, reject, 'submit') |
| | | }) |
| | | }, () => { |
| | | reject() |
| | | }) |
| | | } else if (activeKey === 'columns') { |
| | | this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, false) |
| | | this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, 'submit') |
| | | } else if (activeKey === 'scripts') { |
| | | let _loading = false |
| | | if (this.scriptsForm && this.scriptsForm.state.editItem) { |
| | |
| | | return |
| | | } |
| | | |
| | | this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, false) |
| | | this.sqlverify(() => { resolve({setting, columns, scripts }) }, reject, 'submit') |
| | | } |
| | | }) |
| | | } |
| | | |
| | | sqlverify = (resolve, reject, change = false, testScripts) => { |
| | | sqlverify = (resolve, reject, type, testScripts) => { |
| | | const { searches } = this.props |
| | | const { columns, setting, scripts, activeKey } = this.state |
| | | const { columns, setting, scripts } = this.state |
| | | let _scripts = [] |
| | | |
| | | if (testScripts) { |
| | |
| | | _scripts = scripts.filter(item => item.status !== 'false') |
| | | } |
| | | |
| | | if (!change && setting.interType === 'system' && !setting.innerFunc && setting.execute === 'false' && _scripts.length === 0) { |
| | | if (type === 'submit' && setting.interType === 'system' && setting.execute === 'false' && _scripts.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '不执行默认sql时,请添加自定义脚本!', |
| | |
| | | } |
| | | |
| | | // 不使用默认sql切换 |
| | | if (change && activeKey === 'setting' && setting.interType === 'system' && setting.execute === 'false') { |
| | | if (type === 'setting' && setting.interType === 'system' && setting.execute === 'false') { |
| | | resolve() |
| | | } else if (change && activeKey === 'scripts' && _scripts.length === 0) { |
| | | } else if (type === 'scripts' && _scripts.length === 0) { |
| | | resolve() |
| | | } else if ((setting.interType === 'system' && setting.execute !== 'false') || _scripts.length > 0) { |
| | | } else if (setting.interType === 'system' && (setting.execute !== 'false' || _scripts.length > 0)) { |
| | | let param = { |
| | | func: 's_debug_sql', |
| | | LText: SettingUtils.getDebugSql(setting, _scripts, columns, searches) |