| | |
| | | key: key, |
| | | value: vals.join(',') |
| | | }) |
| | | } else if (this.state.datatype[key] === 'funcvar') { |
| | | } else if (this.state.datatype[key] === 'text') { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: values[key] |
| | | value: values[key].replace(/(^\s*|\s*$) | \t* | \v*/ig, '') |
| | | }) |
| | | } else { |
| | | search.push({ |
| | | type: this.state.datatype[key], |
| | | readonly: this.state.readtype[key], |
| | | key: key, |
| | | value: values[key].replace(/(^\s*|\s*$)/ig, '') |
| | | // value: values[key].replace(/[\x00-\xff]+/ig, '') |
| | | value: values[key] |
| | | }) |
| | | } |
| | | }) |
| | |
| | | import Utils from '@/utils/utils.js' |
| | | // import zhCN from '@/locales/zh-CN/comtable.js' |
| | | // import enUS from '@/locales/en-US/comtable.js' |
| | | import zhCN from '@/locales/zh-CN/comtable.js' |
| | | import enUS from '@/locales/en-US/comtable.js' |
| | | |
| | | // const CommonDict = (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS |
| | | const CommonDict = (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS |
| | | |
| | | class CommonTableBaseData { |
| | | baseConfig = { |
| | |
| | | }, |
| | | { |
| | | type: 'form', |
| | | label: '函数变量', |
| | | label: CommonDict['header.form.funcvar'], |
| | | subType: 'funcvar', |
| | | url: '' |
| | | } |
| | |
| | | } |
| | | |
| | | if (isvalid) { |
| | | ['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => { |
| | | if (values[item]) { |
| | | values[item] = values[item].replace(/\s* | \t* | \v* | \r*/ig, '') |
| | | } |
| | | }) |
| | | |
| | | resolve(values) |
| | | } else { |
| | | notification.warning({ |
| | |
| | | <Form {...formItemLayout} className="verify-form"> |
| | | <Row gutter={24}> |
| | | <Col span={10}> |
| | | <Form.Item label={'函数变量'}> |
| | | <Form.Item label={this.props.dict['header.form.funcvar']}> |
| | | {getFieldDecorator('field', { |
| | | initialValue: '', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.input'] + '函数变量!' |
| | | message: this.props.dict['form.required.input'] + this.props.dict['header.form.funcvar'] + '!' |
| | | } |
| | | ] |
| | | })( |
New file |
| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Select, Button, Input } from 'antd' |
| | | import './index.scss' |
| | | |
| | | |
| | | class UniqueForm extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | contrastChange: PropTypes.func // 修改函数 |
| | | } |
| | | |
| | | state = { |
| | | editItem: null // 编辑元素 |
| | | } |
| | | |
| | | edit = (record) => { |
| | | this.setState({ |
| | | editItem: record |
| | | }) |
| | | |
| | | this.props.form.setFieldsValue({ |
| | | frontfield: record.frontfield, |
| | | operator: record.operator, |
| | | backfield: record.backfield, |
| | | errmsg: record.errmsg, |
| | | errorCode: record.errorCode |
| | | }) |
| | | } |
| | | |
| | | |
| | | handleConfirm = () => { |
| | | // 表单提交时检查输入值是否正确 |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | | if (!err) { |
| | | values.uuid = this.state.editItem ? this.state.editItem.uuid : '' |
| | | |
| | | this.props.contrastChange(values) |
| | | this.setState({ |
| | | editItem: null |
| | | }) |
| | | this.props.form.setFieldsValue({ |
| | | frontfield: '', |
| | | backfield: '', |
| | | errmsg: '' |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | const { getFieldDecorator } = this.props.form |
| | | const formItemLayout = { |
| | | labelCol: { |
| | | xs: { span: 24 }, |
| | | sm: { span: 8 } |
| | | }, |
| | | wrapperCol: { |
| | | xs: { span: 24 }, |
| | | sm: { span: 16 } |
| | | } |
| | | } |
| | | |
| | | return ( |
| | | <Form {...formItemLayout} className="verify-form" id="verifycard1"> |
| | | <Row gutter={24}> |
| | | <Col span={7}> |
| | | <Form.Item label={'内容1'}> |
| | | {getFieldDecorator('frontfield', { |
| | | initialValue: '', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.input'] + '内容1!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Form.Item label={'运算符'}> |
| | | {getFieldDecorator('operator', { |
| | | initialValue: '=', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.select'] + '运算符!' |
| | | } |
| | | ] |
| | | })( |
| | | <Select> |
| | | <Select.Option value="="> = </Select.Option> |
| | | <Select.Option value="!="> != </Select.Option> |
| | | <Select.Option value=">"> > </Select.Option> |
| | | <Select.Option value="<"> < </Select.Option> |
| | | <Select.Option value=">="> >= </Select.Option> |
| | | <Select.Option value="<="> <= </Select.Option> |
| | | <Select.Option value="in"> in </Select.Option> |
| | | <Select.Option value="like"> like </Select.Option> |
| | | </Select> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Form.Item label={'内容2'}> |
| | | {getFieldDecorator('backfield', { |
| | | initialValue: '', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.input'] + '内容2!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={3} className="add"> |
| | | <Button onClick={this.handleConfirm} type="primary" className="add-row"> |
| | | 确定 |
| | | </Button> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Form.Item label={'提示信息'}> |
| | | {getFieldDecorator('errmsg', { |
| | | initialValue: '', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.input'] + '提示信息!' |
| | | }, |
| | | { |
| | | pattern: /^[^']*$/ig, |
| | | message: '提示信息不允许包含\'' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={7}> |
| | | <Form.Item label={'报错编码'}> |
| | | {getFieldDecorator('errorCode', { |
| | | initialValue: 'E', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.select'] + '报错编码!' |
| | | } |
| | | ] |
| | | })( |
| | | <Select> |
| | | <Select.Option value="E"> E </Select.Option> |
| | | <Select.Option value="N"> N </Select.Option> |
| | | <Select.Option value="F"> F </Select.Option> |
| | | <Select.Option value="NM"> NM </Select.Option> |
| | | </Select> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Form> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | export default Form.create()(UniqueForm) |
| | |
| | | class CustomForm extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | fields: PropTypes.array, // 表单 |
| | | usefulfields: PropTypes.string, // 可用字段 |
| | | customChange: PropTypes.func // 表单 |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { usefulfields } = this.props |
| | | const { getFieldDecorator } = this.props.form |
| | | const formItemLayout = { |
| | | labelCol: { |
| | |
| | | return ( |
| | | <Form {...formItemLayout} className="verify-form" id="verifycard2"> |
| | | <Row gutter={24}> |
| | | {usefulfields ? <Col span={21} className="sqlfield"> |
| | | <Form.Item label={'可用字段'}> |
| | | {usefulfields} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | <Col span={21} className="sql"> |
| | | <Form.Item label={'sql'}> |
| | | {getFieldDecorator('sql', { |
| | |
| | | class CustomForm extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | fields: PropTypes.array, // 表单 |
| | | usefulfields: PropTypes.string, // 可用字段 |
| | | scriptsChange: PropTypes.func // 表单 |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { fields } = this.props |
| | | const { usefulfields } = this.props |
| | | const { getFieldDecorator } = this.props.form |
| | | const formItemLayout = { |
| | | labelCol: { |
| | |
| | | sm: { span: 16 } |
| | | } |
| | | } |
| | | let _fields = fields.map(item => item.field) |
| | | |
| | | return ( |
| | | <Form {...formItemLayout} className="verify-form" id="verifycard2"> |
| | | <Row gutter={24}> |
| | | {fields && fields.length > 0 ? <Col span={21} className="sqlfield"> |
| | | <Form.Item label={'表单字段'}> |
| | | {_fields.join(', ')} |
| | | {usefulfields ? <Col span={21} className="sqlfield"> |
| | | <Form.Item label={'可用字段'}> |
| | | {usefulfields} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | <Col span={21} className="sql"> |
| | |
| | | import Utils from '@/utils/utils.js' |
| | | |
| | | import UniqueForm from './uniqueform' |
| | | import ContrastForm from './contrastform' |
| | | import CustomForm from './customform' |
| | | import CustomScript from './customscript' |
| | | import BillcodeForm from './billcodeform' |
| | |
| | | state = { |
| | | verify: {}, |
| | | fields: [], |
| | | usefulfields: '', |
| | | orderModular: [], |
| | | orderModularDetail: [], |
| | | voucher: [], |
| | |
| | | { |
| | | title: '字段名', |
| | | dataIndex: 'field', |
| | | width: '45%' |
| | | width: '35%' |
| | | }, |
| | | { |
| | | title: '报错编码', |
| | | dataIndex: 'errorCode', |
| | | width: '15%' |
| | | width: '12%' |
| | | }, |
| | | { |
| | | title: '验证类型', |
| | | dataIndex: 'verifyType', |
| | | width: '13%', |
| | | render: (text, record) => record.verifyType === 'logic' ? '逻辑验证' : '物理验证' |
| | | }, |
| | | { |
| | | title: '状态', |
| | |
| | | <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'unique', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span> |
| | | <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'unique', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span> |
| | | <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record, 'unique')} style={{color: '#8E44AD'}}><Icon type="swap" /></span> |
| | | </div>) |
| | | } |
| | | ], |
| | | contrastColumns: [ |
| | | { |
| | | title: '内容1', |
| | | dataIndex: 'frontfield', |
| | | width: '13%' |
| | | }, |
| | | { |
| | | title: '运算符', |
| | | dataIndex: 'operator', |
| | | width: '13%' |
| | | }, |
| | | { |
| | | title: '内容2', |
| | | dataIndex: 'backfield', |
| | | width: '13%', |
| | | }, |
| | | { |
| | | title: '提示信息', |
| | | dataIndex: 'errmsg', |
| | | width: '13%' |
| | | }, |
| | | { |
| | | title: '报错编码', |
| | | dataIndex: 'errorCode', |
| | | width: '13%' |
| | | }, |
| | | { |
| | | title: '状态', |
| | | dataIndex: 'status', |
| | | width: '15%', |
| | | render: (text, record) => record.status === 'false' ? |
| | | ( |
| | | <div> |
| | | {this.props.dict['header.form.status.forbidden']} |
| | | <Icon style={{marginLeft: '5px'}} type="stop" theme="twoTone" twoToneColor="#ff4d4f" /> |
| | | </div> |
| | | ) : |
| | | ( |
| | | <div> |
| | | {this.props.dict['header.form.status.open']} |
| | | <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" /> |
| | | </div> |
| | | ) |
| | | }, |
| | | { |
| | | title: '操作', |
| | | align: 'center', |
| | | width: '20%', |
| | | dataIndex: 'operation', |
| | | render: (text, record) => |
| | | (<div> |
| | | <span className="operation-btn" title={this.props.dict['header.edit']} onClick={() => this.handleEdit(record, 'contrast')} style={{color: '#1890ff'}}><Icon type="edit" /></span> |
| | | <Popconfirm |
| | | title={this.props.dict['header.form.query.delete']} |
| | | okText={this.props.dict['header.confirm']} |
| | | cancelText={this.props.dict['header.cancel']} |
| | | onConfirm={() => this.handleDelete(record, 'contrast') |
| | | }> |
| | | <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span> |
| | | </Popconfirm> |
| | | <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'contrast', 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span> |
| | | <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'contrast', 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span> |
| | | <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record, 'contrast')} style={{color: '#8E44AD'}}><Icon type="swap" /></span> |
| | | </div>) |
| | | } |
| | | ], |
| | |
| | | ], |
| | | orderColumns: [ |
| | | { |
| | | title: '函数变量', |
| | | title: this.props.dict['header.form.funcvar'], |
| | | dataIndex: 'fieldName', |
| | | width: '13%', |
| | | render: (text, record) => (`${record.fieldName || ''}(${record.field})`) |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { columns } = this.props |
| | | let _verify = this.props.card.verify || {} |
| | | |
| | | this.setState({ |
| | | verify: { |
| | | invalid: _verify.invalid || 'false', |
| | | uniques: _verify.uniques || [], |
| | | contrasts: _verify.contrasts || [], |
| | | accountdate: _verify.accountdate || 'false', |
| | | customverifys: _verify.customverifys || [], |
| | | billcodes: _verify.billcodes || [], |
| | |
| | | _fields = _LongParam.fields |
| | | } |
| | | |
| | | let _usefulfields = [] |
| | | _fields.forEach(_f => { |
| | | if (_f.field) { |
| | | _usefulfields.push(_f.field) |
| | | } |
| | | }) |
| | | |
| | | if (columns && columns.length > 0) { |
| | | columns.forEach(_f => { |
| | | if (_f.field) { |
| | | _usefulfields.push(_f.field) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | _usefulfields = Array.from(new Set(_usefulfields)) |
| | | _usefulfields = _usefulfields.join(', ') |
| | | |
| | | |
| | | this.setState({ |
| | | fields: _fields |
| | | fields: _fields, |
| | | usefulfields: _usefulfields |
| | | }) |
| | | } else { |
| | | notification.warning({ |
| | |
| | | }) |
| | | } |
| | | |
| | | contrastChange = (values) => { |
| | | let verify = JSON.parse(JSON.stringify(this.state.verify)) |
| | | |
| | | if (values.uuid) { |
| | | verify.contrasts = verify.contrasts.map(item => { |
| | | if (item.uuid === values.uuid) { |
| | | return values |
| | | } else { |
| | | return item |
| | | } |
| | | }) |
| | | } else { |
| | | values.uuid = Utils.getuuid() |
| | | verify.contrasts.push(values) |
| | | } |
| | | |
| | | this.setState({ |
| | | verify: verify |
| | | }) |
| | | } |
| | | |
| | | customChange = (values) => { |
| | | let verify = JSON.parse(JSON.stringify(this.state.verify)) |
| | | |
| | |
| | | verify.billcodes = verify.billcodes.filter(item => item.uuid !== record.uuid) |
| | | } else if (type === 'scripts') { |
| | | verify.scripts = verify.scripts.filter(item => item.uuid !== record.uuid) |
| | | } else if (type === 'contrast') { |
| | | verify.contrasts = verify.contrasts.filter(item => item.uuid !== record.uuid) |
| | | } |
| | | |
| | | this.setState({ verify: verify }) |
| | |
| | | this.orderForm.edit(record) |
| | | } else if (type === 'scripts') { |
| | | this.scriptsForm.edit(record) |
| | | } else if (type === 'contrast') { |
| | | this.contrastForm.edit(record) |
| | | } |
| | | } |
| | | |
| | |
| | | }) |
| | | } else if (type === 'unique') { |
| | | verify.uniques = verify.uniques.map(item => { |
| | | if (item.uuid === record.uuid) { |
| | | return record |
| | | } else { |
| | | return item |
| | | } |
| | | }) |
| | | } else if (type === 'contrast') { |
| | | verify.contrasts = verify.contrasts.map(item => { |
| | | if (item.uuid === record.uuid) { |
| | | return record |
| | | } else { |
| | |
| | | } else { |
| | | verify.customverifys.splice(index + 1, 0, record) |
| | | } |
| | | |
| | | this.setState({ |
| | | verify: verify |
| | | }) |
| | | } else if (type === 'unique') { |
| | | verify.uniques = verify.uniques.filter((item, i) => { |
| | | if (item.uuid === record.uuid) { |
| | |
| | | } else { |
| | | verify.uniques.splice(index + 1, 0, record) |
| | | } |
| | | } else if (type === 'contrast') { |
| | | verify.contrasts = verify.contrasts.filter((item, i) => { |
| | | if (item.uuid === record.uuid) { |
| | | index = i |
| | | } |
| | | |
| | | this.setState({ |
| | | verify: verify |
| | | return item.uuid !== record.uuid |
| | | }) |
| | | if ((index === 0 && direction === 'up') || (index === verify.contrasts.length && direction === 'down')) { |
| | | return |
| | | } |
| | | |
| | | if (direction === 'up') { |
| | | verify.contrasts.splice(index - 1, 0, record) |
| | | } else { |
| | | verify.contrasts.splice(index + 1, 0, record) |
| | | } |
| | | } else if (type === 'ordercode') { |
| | | verify.billcodes = verify.billcodes.filter((item, i) => { |
| | | if (item.uuid === record.uuid) { |
| | |
| | | } else { |
| | | verify.billcodes.splice(index + 1, 0, record) |
| | | } |
| | | |
| | | this.setState({ |
| | | verify: verify |
| | | }) |
| | | } else if (type === 'scripts') { |
| | | verify.scripts = verify.scripts.filter((item, i) => { |
| | | if (item.uuid === record.uuid) { |
| | |
| | | } else { |
| | | verify.scripts.splice(index + 1, 0, record) |
| | | } |
| | | } |
| | | |
| | | this.setState({ |
| | | verify: verify |
| | | }) |
| | | } |
| | | } |
| | | |
| | | voucherChange = (voucher) => { |
| | |
| | | } |
| | | |
| | | render() { |
| | | // const { getFieldDecorator } = this.props.form |
| | | const { verify, fields, uniqueColumns, customColumns, orderColumns, scriptsColumns, orderModular, orderModularDetail, voucher, voucherDetail } = this.state |
| | | const { verify, fields, uniqueColumns, contrastColumns, customColumns, orderColumns, scriptsColumns, orderModular, orderModularDetail, voucher, voucherDetail } = this.state |
| | | const formItemLayout = { |
| | | labelCol: { |
| | | xs: { span: 24 }, |
| | |
| | | </Row> |
| | | </Form> |
| | | </TabPane> |
| | | <TabPane tab="比较验证" key="2x"> |
| | | <ContrastForm |
| | | dict={this.props.dict} |
| | | contrastChange={this.contrastChange} |
| | | wrappedComponentRef={(inst) => this.contrastForm = inst} |
| | | /> |
| | | <Table |
| | | bordered |
| | | rowKey="uuid" |
| | | className="custom-table" |
| | | dataSource={verify.contrasts} |
| | | columns={contrastColumns} |
| | | pagination={false} |
| | | /> |
| | | </TabPane> |
| | | <TabPane tab="唯一性验证" key="2"> |
| | | <UniqueForm |
| | | fields={fields} |
| | |
| | | <TabPane tab="自定义验证" key="3"> |
| | | <CustomForm |
| | | dict={this.props.dict} |
| | | usefulfields={this.state.usefulfields} |
| | | customChange={this.customChange} |
| | | wrappedComponentRef={(inst) => this.customForm = inst} |
| | | /> |
| | |
| | | </TabPane> |
| | | <TabPane tab="自定义脚本" key="6"> |
| | | <CustomScript |
| | | fields={fields} |
| | | usefulfields={this.state.usefulfields} |
| | | dict={this.props.dict} |
| | | scriptsChange={this.scriptsChange} |
| | | wrappedComponentRef={(inst) => this.scriptsForm = inst} |
| | |
| | | |
| | | this.props.form.setFieldsValue({ |
| | | field: record.field.split(','), |
| | | errorCode: record.errorCode |
| | | errorCode: record.errorCode, |
| | | verifyType: record.verifyType || 'physical' |
| | | }) |
| | | } |
| | | |
| | |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={6}> |
| | | <Form.Item label={'验证类型'}> |
| | | {getFieldDecorator('verifyType', { |
| | | initialValue: 'physical', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: this.props.dict['form.required.select'] + '验证类型!' |
| | | } |
| | | ] |
| | | })( |
| | | <Select> |
| | | <Select.Option value="physical"> 物理验证 </Select.Option> |
| | | <Select.Option value="logic"> 逻辑验证 </Select.Option> |
| | | </Select> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={2} className="add"> |
| | | <Button onClick={this.handleConfirm} type="primary" className="add-row"> |
| | | 确定 |
| | |
| | | values.initval = '' |
| | | } |
| | | |
| | | ['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => { |
| | | if (values[item]) { |
| | | values[item] = values[item].replace(/\s* | \t* | \v* | \r*/ig, '') |
| | | } |
| | | }) |
| | | |
| | | if (isvalid) { |
| | | resolve(values) |
| | | } |
| | |
| | | let BID = param.BID |
| | | let verify = btn.verify |
| | | let _formFieldValue = {} |
| | | |
| | | // 需要声明的变量集 |
| | | let _vars = ['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'UserName', 'FullName'] |
| | | let _vars = ['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'UserName', 'FullName', 'ID', 'BID'] |
| | | |
| | | // 主键字段 |
| | | let primaryKey = setting.primaryKey || 'id' |
| | |
| | | }) |
| | | } |
| | | |
| | | // 添加数据中字段,表单值优先 |
| | | if (data) { |
| | | _formFieldValue = {...data, ..._formFieldValue} |
| | | } |
| | | |
| | | // 添加时主键为空 |
| | | if (btn.sqlType === 'insert') { |
| | | primaryId = '' |
| | | } |
| | | |
| | | // 声明表单及列表数据字段,初始化赋值 |
| | | let keys = Object.keys(_formFieldValue) |
| | | let _initfields = [] |
| | | let _initvars = ['ID', 'BID'] |
| | | let _formfields = [] |
| | | keys.forEach(key => { |
| | | if (!_initvars.includes(key)) { |
| | | _initvars.push(key) |
| | | _initfields.push(`@${key}='${_formFieldValue[key]}'`) |
| | | } |
| | | |
| | | if (!_vars.includes(key)) { |
| | | _vars.push(key) |
| | | _formfields.push(`@${key} nvarchar(50)`) |
| | | } |
| | | }) |
| | | |
| | | _formfields = _formfields.join(',') |
| | | if (_formfields) { |
| | | _sql += `,${_formfields} |
| | | ` |
| | | } |
| | | |
| | | _initfields = _initfields.join(',') |
| | | if (_initfields) { |
| | | _sql += `select ${_initfields} |
| | | ` |
| | | } |
| | | |
| | | // 去除禁用的验证 |
| | | if (verify) { |
| | | if (verify.contrasts) { |
| | | verify.contrasts = verify.contrasts.filter(item => item.status !== 'false') |
| | | } |
| | | if (verify.uniques) { |
| | | verify.uniques = verify.uniques.filter(item => item.status !== 'false') |
| | | } |
| | |
| | | if (verify.scripts) { |
| | | verify.scripts = verify.scripts.filter(item => item.status !== 'false') |
| | | } |
| | | } |
| | | |
| | | // 设置有自定义脚本时,声明变量中添加所有表单字段,并避免重复 |
| | | if (verify && verify.scripts && verify.scripts.length > 0 && formdata && formdata.length > 0) { |
| | | let _initfields = [] |
| | | let _formfields = formdata.filter(form => { |
| | | _initfields.push(`@${form.key}='${form.value}'`) |
| | | |
| | | return !_vars.includes(form.key) |
| | | }) |
| | | |
| | | _formfields = _formfields.map(form => { |
| | | _vars.push(form.key) |
| | | return `@${form.key} nvarchar(50)` |
| | | }) |
| | | _formfields = _formfields.join(',') |
| | | _sql += `,${_formfields} |
| | | ` |
| | | _initfields = _initfields.join(',') |
| | | _sql += `select ${_initfields} |
| | | ` |
| | | |
| | | } |
| | | |
| | | // 初始化凭证字段 |
| | |
| | | ` |
| | | } |
| | | |
| | | // 唯一性验证,必须存在表单(表单存在时,主键均为单值),必须填写数据源 |
| | | if (formdata && verify && verify.uniques.length > 0) { |
| | | let _primaryId = primaryId |
| | | if (btn.sqlType === 'insert') { |
| | | _primaryId = '' |
| | | // 比较验证 |
| | | if (verify && verify.contrasts && verify.contrasts.length > 0) { |
| | | verify.contrasts.forEach(item => { |
| | | _sql += `If ${item.frontfield} ${item.operator} ${item.backfield} |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' |
| | | goto aaa |
| | | end |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | // 唯一性验证,必须存在表单(表单存在时,主键均为单值),必须填写数据源 |
| | | if (formdata && verify && verify.uniques.length > 0) { |
| | | verify.uniques.forEach(item => { |
| | | let _fieldValue = [] // 表单键值对field=value |
| | | let _value = [] // 表单值,用于错误提示 |
| | |
| | | _value.push(`${_labels[index] || ''}:${_formFieldValue[_field] || ''}`) |
| | | }) |
| | | |
| | | let _verifyType = '' |
| | | if (item.verifyType === 'logic') { |
| | | _verifyType = ' and deleted=0' |
| | | } |
| | | |
| | | _sql += `select @tbid='', @ErrorCode='',@retmsg='' |
| | | select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !='${_primaryId}' |
| | | select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !='${primaryId}'${_verifyType} |
| | | If @tbid!='' |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 已存在' |
| | |
| | | }) |
| | | } |
| | | |
| | | // 自定义验证,使用列表及表单数据(表单优先),替换所有@相同字段、@ID、@BID |
| | | // 自定义验证 |
| | | if (verify && verify.customverifys.length > 0) { |
| | | let _primaryId = primaryId |
| | | if (btn.sqlType === 'insert') { |
| | | _primaryId = '' |
| | | } |
| | | |
| | | verify.customverifys.forEach(item => { |
| | | let _cuSql = item.sql |
| | | if (data) { |
| | | _formFieldValue = {...data, ..._formFieldValue} |
| | | } |
| | | let keys = Object.keys(_formFieldValue) |
| | | keys = keys.sort((a, b) => { |
| | | return b.length - a.length |
| | | }) |
| | | |
| | | keys.forEach(key => { |
| | | let reg = new RegExp('@' + key, 'ig') |
| | | _cuSql = _cuSql.replace(reg, `'${_formFieldValue[key]}'`) |
| | | }) |
| | | let idreg = new RegExp('@ID', 'ig') |
| | | _cuSql = _cuSql.replace(idreg, `'${_primaryId}'`) |
| | | |
| | | let bidreg = new RegExp('@BID', 'ig') |
| | | _cuSql = _cuSql.replace(bidreg, `'${BID}'`) |
| | | |
| | | _sql += `select @tbid='', @ErrorCode='',@retmsg='' |
| | | select top 1 @tbid='X' from (${_cuSql}) a |
| | | select top 1 @tbid='X' from (${item.sql}) a |
| | | If @tbid ${item.result === 'true' ? '!=' : '='}'' |
| | | Begin |
| | | select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' |