| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification } from 'antd' |
| | | import { Form, Row, Col, Input, Radio, Select, Tooltip, notification, InputNumber } from 'antd' |
| | | import { QuestionCircleOutlined } from '@ant-design/icons' |
| | | |
| | | import { formRule } from '@/utils/option.js' |
| | | import Utils from '@/utils/utils.js' |
| | | import './index.scss' |
| | | |
| | | const { TextArea } = Input |
| | |
| | | dict: PropTypes.object, // 字典项 |
| | | menu: PropTypes.object, |
| | | config: PropTypes.object, |
| | | usefulFields: PropTypes.array |
| | | inputSubmit: PropTypes.any // 回车提交事件 |
| | | } |
| | | |
| | | state = { |
| | | interType: null, |
| | | interType: (this.props.config.setting && this.props.config.setting.interType) || 'inner', |
| | | columns: null, |
| | | currentTabs: null, |
| | | selectTabs: [] |
| | | usefulFields: [], |
| | | interReadonly: false, |
| | | } |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { config, menu } = this.props |
| | | console.log(menu) |
| | | console.log(config) |
| | | let _tabs = [] |
| | | let _select = [] |
| | | let _tabMap = new Map() |
| | | let _columns = [] |
| | | let _interType = 'inner' |
| | | let _setting = config.setting |
| | | const { config } = this.props |
| | | |
| | | let _columns = [] |
| | | let _setting = config.setting |
| | | |
| | | try { |
| | | _columns = menu.LongParam.columns.filter(item => item.field && item.type !== 'colspan') |
| | | // config.groups.forEach(group => { |
| | | // if (group.isDefault) { |
| | | // _columns.push() |
| | | // } |
| | | // group.sublist |
| | | // }) |
| | | _interType = menu.LongParam.setting.interType |
| | | } catch { |
| | | config.groups.forEach(group => { |
| | | let list = group.sublist.filter(item => item.field) |
| | | _columns = [..._columns, ...list] |
| | | }) |
| | | |
| | | let _colMap = new Map() |
| | | _columns = _columns.filter(item => { |
| | | if (_colMap.has(item.field)) { |
| | | return false |
| | | } else { |
| | | _colMap.set(item.field, true) |
| | | return true |
| | | } |
| | | }) |
| | | } catch (e) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '菜单信息错误!', |
| | | duration: 10 |
| | | duration: 5 |
| | | }) |
| | | } |
| | | |
| | | config.tabgroups.forEach(groupname => { |
| | | config[groupname].forEach(tab => { |
| | | if (tab.origin) return |
| | | |
| | | _tabs.push(tab) |
| | | _tabMap.set(tab.uuid, true) |
| | | }) |
| | | }) |
| | | |
| | | _setting.subtabs && _setting.subtabs.forEach(tabId => { |
| | | if (_tabMap.has(tabId)) { |
| | | _select.push(tabId) |
| | | let usefulFields = sessionStorage.getItem('permFuncField') |
| | | if (usefulFields) { |
| | | try { |
| | | usefulFields = JSON.parse(usefulFields) |
| | | } catch (e) { |
| | | usefulFields = [] |
| | | } |
| | | }) |
| | | } else { |
| | | usefulFields = [] |
| | | } |
| | | |
| | | this.setState({ |
| | | currentTabs: _tabs, |
| | | selectTabs: _select, |
| | | columns: _columns, |
| | | interType: _interType, |
| | | setting: _setting |
| | | setting: _setting, |
| | | interType: _setting.interType || 'inner', |
| | | interReadonly: _setting.sysInterface === 'true', |
| | | datatype: _setting.datatype || 'maintable', |
| | | usefulFields |
| | | }) |
| | | } |
| | | |
| | |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | | if (!err) { |
| | | values.actionfixed = values.actionfixed === 'true' |
| | | values.columnfixed = values.columnfixed === 'true' |
| | | let error = Utils.verifySql(values.dataresource) |
| | | |
| | | if (values.interType === 'inner' && !values.innerFunc && !values.dataresource) { |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请自定义函数或填写数据源!', |
| | | duration: 10 |
| | | message: '数据源中不可使用' + error, |
| | | duration: 5 |
| | | }) |
| | | } else { |
| | | resolve(values) |
| | | return |
| | | } |
| | | |
| | | resolve(values) |
| | | } else { |
| | | reject(err) |
| | | } |
| | |
| | | }) |
| | | } |
| | | |
| | | onSysChange = (e) => { |
| | | if (e.target.value === 'true') { |
| | | this.props.form.setFieldsValue({ |
| | | interface: window.GLOB.mainSystemApi || '' |
| | | }) |
| | | this.setState({ |
| | | interReadonly: true |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | interReadonly: false |
| | | }) |
| | | } |
| | | } |
| | | |
| | | onChange = (e) => { |
| | | this.setState({ |
| | | interType: e.target.value |
| | | }, () => { |
| | | if (e.target.value === 'inner') return |
| | | |
| | | let _type = this.props.form.getFieldValue('sysInterface') |
| | | if (_type === 'true') { |
| | | this.props.form.setFieldsValue({ |
| | | interface: window.GLOB.mainSystemApi || '' |
| | | }) |
| | | this.setState({ |
| | | interReadonly: true |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | interReadonly: false |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | selectChange = (val) => { |
| | | this.props.form.setFieldsValue({ |
| | | order: `${val} desc` |
| | | sourceChange = (e) => { |
| | | const { interType } = this.state |
| | | |
| | | this.setState({ |
| | | datatype: e.target.value |
| | | }, () => { |
| | | if (interType === 'inner') return |
| | | |
| | | let _type = this.props.form.getFieldValue('sysInterface') |
| | | if (_type === 'true') { |
| | | this.props.form.setFieldsValue({ |
| | | interface: window.GLOB.mainSystemApi || '' |
| | | }) |
| | | this.setState({ |
| | | interReadonly: true |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | interReadonly: false |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | handleSubmit = (e) => { |
| | | e.preventDefault() |
| | | |
| | | if (this.props.inputSubmit) { |
| | | this.props.inputSubmit() |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { dict, menu, usefulFields } = this.props |
| | | const { dict, menu } = this.props |
| | | const { getFieldDecorator } = this.props.form |
| | | const { interType, columns, selectTabs, setting } = this.state |
| | | const { interType, setting, datatype, usefulFields } = this.state |
| | | |
| | | const formItemLayout = { |
| | | labelCol: { |
| | |
| | | xs: { span: 24 }, |
| | | sm: { span: 16 } |
| | | } |
| | | } |
| | | |
| | | let primaryKey = setting.primaryKey |
| | | if (primaryKey) { |
| | | let field = columns.filter(column => column.field === primaryKey) |
| | | if (field.length !== 1) { |
| | | primaryKey = '' |
| | | } |
| | | } |
| | | if (!primaryKey && columns.length === 0) { |
| | | primaryKey = 'ID' |
| | | } |
| | | |
| | | let str = '^(' + usefulFields.join('|') + ')' |
| | |
| | | message: dict['form.required.input'] + '表名!' |
| | | }, |
| | | { |
| | | max: formRule.input.max, |
| | | message: formRule.input.message |
| | | max: 50, |
| | | message: '表名最长为50个字符!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={12}> |
| | | <Form.Item label={dict['header.form.intertype']}> |
| | | {getFieldDecorator('interType', { |
| | | initialValue: setting.interType || 'inner' |
| | | <Form.Item label="列数"> |
| | | {getFieldDecorator('cols', { |
| | | initialValue: setting.cols || '2' |
| | | })( |
| | | <Radio.Group onChange={this.onChange}> |
| | | <Radio value="inner">{dict['header.form.interface.inner']}</Radio> |
| | | <Radio value="outer">{dict['header.form.interface.outer']}</Radio> |
| | | <Select> |
| | | <Select.Option value="1">1列</Select.Option> |
| | | <Select.Option value="2">2列</Select.Option> |
| | | <Select.Option value="3">3列</Select.Option> |
| | | <Select.Option value="4">4列</Select.Option> |
| | | </Select> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={12}> |
| | | <Form.Item label={dict['header.menu.datasource']}> |
| | | {getFieldDecorator('datatype', { |
| | | initialValue: setting.datatype || 'query' |
| | | })( |
| | | <Radio.Group onChange={this.sourceChange}> |
| | | <Radio value="maintable">{dict['header.menu.maintable']}</Radio> |
| | | <Radio value="query">{dict['header.menu.query']}</Radio> |
| | | </Radio.Group> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | {interType === 'outer' ? <Col span={12}> |
| | | <Col span={12}> |
| | | <Form.Item label="主键"> |
| | | {getFieldDecorator('primaryKey', { |
| | | initialValue: setting.primaryKey |
| | | })(<Input placeholder="" autoComplete="off" disabled/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | {datatype === 'query' ? <Col span={12}> |
| | | <Form.Item label={dict['header.form.intertype']}> |
| | | {getFieldDecorator('interType', { |
| | | initialValue: interType |
| | | })( |
| | | <Radio.Group onChange={this.onChange}> |
| | | <Radio value="inner">{dict['model.interface.inner']}</Radio> |
| | | <Radio value="outer">{dict['model.interface.outer']}</Radio> |
| | | </Radio.Group> |
| | | )} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {datatype === 'query' && interType === 'outer' ? <Col span={12}> |
| | | <Form.Item label={dict['header.form.sysInterface']}> |
| | | {getFieldDecorator('sysInterface', { |
| | | initialValue: setting.sysInterface || 'false' |
| | | })( |
| | | <Radio.Group onChange={this.onSysChange}> |
| | | <Radio value="true">{dict['model.true']}</Radio> |
| | | <Radio value="false">{dict['model.false']}</Radio> |
| | | </Radio.Group> |
| | | )} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {datatype === 'query' && interType === 'outer' ? <Col span={12}> |
| | | <Form.Item label={dict['header.form.interface']}> |
| | | {getFieldDecorator('interface', { |
| | | initialValue: setting.interface || '', |
| | | initialValue: setting.sysInterface === 'true' ? (window.GLOB.mainSystemApi || '') : (setting.interface || ''), |
| | | rules: [ |
| | | { |
| | | required: true, |
| | |
| | | message: formRule.input.message |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | })(<Input placeholder="" autoComplete="off" disabled={this.state.interReadonly} onPressEnter={this.handleSubmit} />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {interType !== 'outer' ? <Col span={12}> |
| | | {datatype === 'query' && interType !== 'outer' ? <Col span={12}> |
| | | <Form.Item label={ |
| | | <Tooltip placement="topLeft" overlayClassName="middle" title={`可自定义数据处理函数,函数名称需以${usefulFields.join(', ')}等字符开始;未设置时会调用系统函数,使用系统函数需完善数据源。`}> |
| | | <Icon type="question-circle" /> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {dict['header.form.innerFunc']} |
| | | </Tooltip> |
| | | }> |
| | |
| | | message: formRule.func.maxMessage |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {interType !== 'outer' ? <Col span={24}> |
| | | {datatype === 'query' && interType !== 'outer' ? <Col span={24}> |
| | | <Form.Item help={'数据ID:' + menu.MenuID} label={ |
| | | <Tooltip placement="topLeft" title="使用系统函数时,需填写数据源,自定义函数时,可忽略。"> |
| | | <Icon type="question-circle" /> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {'数据源'} |
| | | </Tooltip> |
| | | } className="textarea"> |
| | |
| | | })(<TextArea rows={4} />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {interType === 'outer' ? <Col span={12}> |
| | | {datatype === 'query' && interType === 'outer' ? <Col span={12}> |
| | | <Form.Item label={dict['header.form.outerFunc']}> |
| | | {getFieldDecorator('outerFunc', { |
| | | initialValue: setting.outerFunc || '', |
| | |
| | | message: formRule.func.maxMessage |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" />)} |
| | | })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)} |
| | | </Form.Item> |
| | | </Col> : null} |
| | | |
| | | <Col span={12}> |
| | | <Form.Item label="主键"> |
| | | {getFieldDecorator('primaryKey', { |
| | | initialValue: primaryKey |
| | | })( |
| | | <Select |
| | | getPopupContainer={() => document.getElementById('commontable-setting-form')} |
| | | onChange={this.selectChange} |
| | | > |
| | | <Select.Option key='unset' value="">不设置</Select.Option> |
| | | {columns.length === 0 ? |
| | | <Select.Option key='id' value="ID">ID</Select.Option> : null |
| | | } |
| | | {columns.map((option, index) => |
| | | <Select.Option id={option.uuid} title={option.label} key={index} value={option.field}>{option.label}</Select.Option> |
| | | )} |
| | | </Select> |
| | | )} |
| | | <Form.Item label="宽度"> |
| | | {getFieldDecorator('width', { |
| | | initialValue: setting.width || 100 |
| | | })(<InputNumber min={10} max={100} precision={0} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={12}> |
| | | <Form.Item label={ |
| | | <Tooltip placement="topLeft" title="主表可选取关联标签,标签关联后,主表数据切换时,下级标签会跟随主表主键值变化。"> |
| | | <Icon type="question-circle" /> |
| | | {'下级标签'} |
| | | </Tooltip> |
| | | }> |
| | | {getFieldDecorator('subtabs', { |
| | | initialValue: selectTabs |
| | | <Form.Item label="初始化"> |
| | | {getFieldDecorator('onload', { |
| | | initialValue: setting.onload || 'true' |
| | | })( |
| | | <Select |
| | | mode="multiple" |
| | | style={{ width: '100%' }} |
| | | placeholder="Please select" |
| | | > |
| | | {this.state.currentTabs.map((option, index) => |
| | | <Select.Option id={option.uuid} title={option.label} key={index} value={option.uuid}>{option.label}</Select.Option> |
| | | )} |
| | | <Select> |
| | | <Select.Option value="true">加载数据</Select.Option> |
| | | <Select.Option value="false">不加载数据</Select.Option> |
| | | </Select> |
| | | )} |
| | | </Form.Item> |