| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Button, notification } from 'antd' |
| | | import { Form, Row, Col, Input, Button, notification, Modal } from 'antd' |
| | | import moment from 'moment' |
| | | |
| | | import Utils from '@/utils/utils.js' |
| | | import Api from '@/api' |
| | | import './index.scss' |
| | | |
| | | const { TextArea } = Input |
| | |
| | | btn: PropTypes.object, // 按钮信息 |
| | | scripts: PropTypes.array, // 自定义脚本列表 |
| | | isdefault: PropTypes.any, // 是否使用默认sql |
| | | usefulfields: PropTypes.string, // 可用字段 |
| | | usefulfields: PropTypes.any, // 可用字段 |
| | | scriptsChange: PropTypes.func // 表单 |
| | | } |
| | | |
| | | state = { |
| | | editItem: null, |
| | | usefulfields: null |
| | | usefulfields: null, |
| | | loading: false, |
| | | verifySql: '' |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const {usefulfields} = this.props |
| | | const {usefulfields, btn} = this.props |
| | | |
| | | let fields = usefulfields.map(item => item.Column) |
| | | fields = ['BID', 'ID', ...fields] |
| | | fields = Array.from(new Set(fields)) |
| | | if (!fields.includes('ID')) { |
| | | fields.unshift('ID') |
| | | } |
| | | if (!fields.includes('BID')) { |
| | | fields.unshift('BID') |
| | | } |
| | | |
| | | let _sql = `Declare @${btn.sheet} table (${usefulfields.map(item => item.Column + ' ' + item.type).join(',')},jskey nvarchar(50) ) |
| | | Declare @UserName nvarchar(50),@FullName nvarchar(50) |
| | | ` |
| | | |
| | | this.setState({ |
| | | verifySql: _sql, |
| | | usefulfields: fields.join(', ') |
| | | }) |
| | | } |
| | |
| | | |
| | | this.props.form.setFieldsValue({ |
| | | sql: `Insert into ${btn.sheet} (${fields},createuserid,createuser,createstaff,bid) |
| | | Select ${fields},@userid,@username,@fullname,@BID From @${btn.sheet}` |
| | | Select ${fields},@userid@,@username,@fullname,@BID@ From @${btn.sheet}` |
| | | }) |
| | | } |
| | | } |
| | |
| | | return |
| | | } |
| | | |
| | | this.props.scriptsChange(values) |
| | | this.setState({ |
| | | editItem: null |
| | | }) |
| | | this.props.form.setFieldsValue({ |
| | | sql: '' |
| | | let param = { |
| | | func: 's_debug_sql', |
| | | LText: this.state.verifySql + values.sql |
| | | } |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | |
| | | this.setState({loading: true}) |
| | | Api.getLocalConfig(param).then(res => { |
| | | if (res.status) { |
| | | this.props.scriptsChange(values) |
| | | this.setState({ |
| | | loading: false, |
| | | editItem: null |
| | | }) |
| | | this.props.form.setFieldsValue({ |
| | | sql: '' |
| | | }) |
| | | } else { |
| | | this.setState({loading: false}) |
| | | |
| | | Modal.error({ |
| | | title: res.message |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={3} className="add"> |
| | | <Button onClick={this.handleConfirm} type="primary" className="add-row"> |
| | | <Button onClick={this.handleConfirm} loading={this.state.loading} type="primary" className="add-row"> |
| | | 确定 |
| | | </Button> |
| | | </Col> |