| | |
| | | import EditTable from '../searcheditable' |
| | | import Utils from '@/utils/utils.js' |
| | | import CodeMirror from '@/templates/zshare/codemirror' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import './index.scss' |
| | | |
| | | const ColorSketch = asyncComponent(() => import('@/mob/colorsketch')) |
| | | const FieldsTable = asyncComponent(() => import('@/templates/zshare/modalform/fieldtable')) |
| | | const DataTable = asyncComponent(() => import('@/templates/zshare/modalform/datatable')) |
| | | |
| | | const groupOptions = [ |
| | | { |
| | |
| | | multiselect: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'], |
| | | link: ['label', 'field', 'resourceType', 'initval', 'type', 'linkField', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'setAll'], |
| | | date: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'], |
| | | checkcard: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'resourceType', 'display', 'width', 'multiple', 'borderColor', 'required', 'Hide', 'labelShow', 'advanced'], |
| | | dateweek: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'], |
| | | datemonth: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'], |
| | | daterange: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'], |
| | |
| | | openType: null, // 搜索条件显示类型 |
| | | resourceType: null, // 下拉搜索时,选项来源类型 |
| | | formlist: null, // 表单 |
| | | display: null, |
| | | cFields: [], |
| | | textTooltip: '字段名可以使用逗号分隔,进行综合搜索', |
| | | } |
| | | |
| | |
| | | UNSAFE_componentWillMount () { |
| | | const { formlist, dict } = this.props |
| | | |
| | | let type = formlist.filter(cell => cell.key === 'type')[0].initVal |
| | | let _items = formlist.filter(cell => cell.key === 'items')[0].initVal |
| | | let resourceType = formlist.filter(cell => cell.key === 'resourceType')[0].initVal |
| | | let type = '' |
| | | let _items = [] |
| | | let resourceType = '' |
| | | let display = '' |
| | | let cFields = [] |
| | | |
| | | let _options = this.getOptions(type, resourceType) |
| | | formlist.forEach(cell => { |
| | | if (cell.key === 'type') { |
| | | type = cell.initVal |
| | | } else if (cell.key === 'items') { |
| | | _items = cell.initVal |
| | | } else if (cell.key === 'display') { |
| | | display = cell.initVal |
| | | } else if (cell.key === 'resourceType') { |
| | | resourceType = cell.initVal |
| | | } else if (cell.key === 'fields') { |
| | | cFields = cell.initVal |
| | | } |
| | | }) |
| | | |
| | | let _options = this.getOptions(type, resourceType, display) |
| | | |
| | | this.setState({ |
| | | display, |
| | | cFields, |
| | | openType: type, |
| | | items: _items, |
| | | resourceType: resourceType, |
| | | resourceType, |
| | | formlist: formlist.map(form => { |
| | | // 表单为初始值字段,且数据类型属于时间类型时,设置初始值为下拉选择,并重置选择项 |
| | | if (form.key === 'initval' && dateOptions.hasOwnProperty(type)) { |
| | |
| | | form.options = matchReg.text |
| | | } else if (type === 'multiselect') { |
| | | form.options = matchReg.multiselect |
| | | } else if (type === 'select' || type === 'link') { |
| | | } else if (type === 'select' || type === 'link' || type === 'checkcard') { |
| | | form.options = matchReg.select |
| | | } else if (type === 'date') { |
| | | form.options = matchReg.date |
| | |
| | | } |
| | | } |
| | | |
| | | getOptions = (type, resourceType) => { |
| | | getOptions = (type, resourceType, display) => { |
| | | let _options = fromJS(searchTypeOptions[type]).toJS() // 选项列表 |
| | | |
| | | if (['multiselect', 'select', 'link'].includes(type) && resourceType === '0') { // 下拉选择类型、选项为自定义资源 |
| | | _options.push('options') |
| | | } else if (['multiselect', 'select', 'link'].includes(type) && resourceType === '1') { // 下拉选择类型、选项为后台数据源中获取 |
| | | _options.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database') |
| | | } else if (type === 'checkcard') { |
| | | if (display === 'picture') { |
| | | if (resourceType === '0') { // 自定义资源 |
| | | _options.push('options', 'picratio') |
| | | } else if (resourceType === '1') { // 数据源 |
| | | _options.push('dataSource', 'cardValField', 'urlField', 'orderBy', 'orderType', 'database', 'picratio') |
| | | } |
| | | } else { |
| | | if (resourceType === '0') { // 自定义资源 |
| | | _options.push('options', 'fields', 'backgroundColor') |
| | | } else if (resourceType === '1') { // 数据源 |
| | | _options.push('dataSource', 'cardValField', 'fields', 'orderBy', 'orderType', 'database', 'backgroundColor') |
| | | } |
| | | } |
| | | } |
| | | |
| | | return _options |
| | |
| | | */ |
| | | openTypeChange = (key, value) => { |
| | | const { dict } = this.props |
| | | const { resourceType, items } = this.state |
| | | const { resourceType, items, display } = this.state |
| | | |
| | | if (key === 'type') { |
| | | let _options = this.getOptions(value, resourceType) |
| | | let _options = this.getOptions(value, resourceType, display) |
| | | let matchs = [] |
| | | |
| | | this.setState({ |
| | |
| | | form.options = matchReg.text |
| | | } else if (value === 'multiselect') { |
| | | form.options = matchReg.multiselect |
| | | } else if (value === 'select' || value === 'link') { |
| | | } else if (value === 'select' || value === 'link' || value === 'checkcard') { |
| | | form.options = matchReg.select |
| | | } else if (value === 'date') { |
| | | form.options = matchReg.date |
| | |
| | | * @description 数据源类型切换 |
| | | */ |
| | | onChange = (e, key) => { |
| | | const { openType } = this.state |
| | | const { openType, display, resourceType } = this.state |
| | | let value = e.target.value |
| | | |
| | | if (key === 'resourceType') { |
| | | let _options = this.getOptions(openType, value) |
| | | let _options = this.getOptions(openType, value, display) |
| | | |
| | | this.setState({ |
| | | resourceType: value, |
| | |
| | | return form |
| | | }) |
| | | }) |
| | | } else if (key === 'display') { |
| | | let _options = this.getOptions(openType, resourceType, value) |
| | | |
| | | this.setState({ |
| | | display: value, |
| | | formlist: this.state.formlist.map(form => { |
| | | form.hidden = !_options.includes(form.key) |
| | | return form |
| | | }) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | changeField = (data) => { |
| | | this.setState({ |
| | | cFields: data, |
| | | formlist: this.state.formlist.map(form => { |
| | | if (form.key === 'fields') { |
| | | form.initVal = data |
| | | } |
| | | return form |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | checkChange = (values, key) => { |
| | |
| | | ) |
| | | } else if (item.type === 'textarea') { |
| | | fields.push( |
| | | <Col span={20} offset={4} key={index}> |
| | | <Form.Item className="text-area"> |
| | | <Col span={24} key={index}> |
| | | <Form.Item className="text-area" label={item.label}> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal, |
| | | rules: [ |
| | |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'options') { |
| | | if (openType !== 'checkcard') { |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | | <Form.Item label={item.label} className="text-area"> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal |
| | | })(<EditTable dict={this.props.dict} type={this.state.openType} data={item.initVal}/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else { |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | | <Form.Item label={item.label} className="text-area"> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal |
| | | })(<DataTable dict={this.props.dict} type={this.state.display} fields={this.state.cFields}/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } |
| | | } else if (item.type === 'fields') { |
| | | fields.push( |
| | | <Col span={20} offset={4} key={index}> |
| | | <EditTable data={item.initVal} type={this.state.openType} dict={this.props.dict} ref="editTable"/> |
| | | <Col span={24} key={index}> |
| | | <Form.Item label={item.label} className="text-area"> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal |
| | | })(<FieldsTable dict={this.props.dict} onChange={this.changeField}/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'checkbox') { |
| | |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'color') { |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.label} className="color-form-item"> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal |
| | | })(<ColorSketch allowClear={true}/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } |
| | | }) |
| | | |
| | |
| | | let isvalid = true |
| | | values.uuid = this.props.card.uuid |
| | | // 下拉菜单或联动菜单 |
| | | if ((values.type === 'multiselect' || values.type === 'select' || values.type === 'link') && values.resourceType === '0') { |
| | | values.options = this.refs.editTable.state.dataSource |
| | | if (['multiselect', 'select', 'link', 'checkcard'].includes(values.type) && values.resourceType === '0') { |
| | | values.options = values.options || [] |
| | | values.dataSource = '' |
| | | let emptys = [] |
| | | if (values.type === 'multiselect' || values.type === 'select') { |
| | | if (['multiselect', 'select'].includes(values.type)) { |
| | | emptys = values.options.filter(op => !(op.Value && op.Text)) |
| | | } else { |
| | | } else if (values.type === 'link') { |
| | | emptys = values.options.filter(op => !(op.Value && op.Text && op.ParentID)) |
| | | } |
| | | if (emptys.length > 0) { |
| | | isvalid = false |
| | | } |
| | | } else if ((values.type === 'multiselect' || values.type === 'select' || values.type === 'link') && values.resourceType === '1') { |
| | | } else if (['multiselect', 'select', 'link', 'checkcard'].includes(values.type) && values.resourceType === '1') { |
| | | values.options = [] |
| | | } |
| | | |
| | | console.log(values) |
| | | |
| | | if (isvalid) { |
| | | ['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => { |
| | | if (values[item]) { |