From c59e0c5a408aebe8080dfce3b2ebc4711f20e7a9 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 04 二月 2020 08:56:11 +0800 Subject: [PATCH] 2020-02-04 --- src/tabviews/tableshare/mutilform/index.jsx | 10 /dev/null | 133 ------- src/templates/modalconfig/index.jsx | 3 src/tabviews/formtab/index.jsx | 183 +-------- src/tabviews/formtab/formgroup/index.jsx | 640 +++++++++++++++++++++++++++++++++++ src/tabviews/commontable/index.jsx | 45 +- src/tabviews/formtab/formgroup/index.scss | 36 ++ src/tabviews/tableshare/actionList/index.jsx | 2 8 files changed, 733 insertions(+), 319 deletions(-) diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx index 6f0699b..418a487 100644 --- a/src/tabviews/commontable/index.jsx +++ b/src/tabviews/commontable/index.jsx @@ -688,32 +688,33 @@ visible: true }) } else if (btn.OpenType === 'tab') { - // const { tabviews, MenuNo, MenuID } = this.props - // let newtab = { - // MenuNo: MenuNo, - // MenuID: btn.uuid, - // MenuName: btn.label, - // type: btn.tabTemplate, - // selected: true, - // param: { - // btn: btn, - // data: data - // } - // } + const { tabviews, MenuNo, MenuID } = this.props + let newtab = { + MenuNo: MenuNo, + MenuID: btn.uuid, + MenuName: btn.label, + type: btn.tabTemplate, + selected: true, + param: { + btn: btn, + data: data, + arr_field: this.state.arr_field + } + } - // let index = 0 - // let tabs = tabviews.map((tab, i) => { - // if (tab.MenuID === MenuID) { - // index = i - // } - // tab.selected = false + let index = 0 + let tabs = tabviews.map((tab, i) => { + if (tab.MenuID === MenuID) { + index = i + } + tab.selected = false - // return tab - // }) + return tab + }) - // tabs.splice(index + 1, 0, newtab) + tabs.splice(index + 1, 0, newtab) - // this.props.modifyTabview(tabs) + this.props.modifyTabview(tabs) } } diff --git a/src/tabviews/formtab/formgroup/index.jsx b/src/tabviews/formtab/formgroup/index.jsx new file mode 100644 index 0000000..b7d9516 --- /dev/null +++ b/src/tabviews/formtab/formgroup/index.jsx @@ -0,0 +1,640 @@ +import React, {Component} from 'react' +import PropTypes from 'prop-types' +import { Form, Row, Col, Input, InputNumber, Select, DatePicker, notification } from 'antd' +import moment from 'moment' +import { formRule } from '@/utils/option.js' +import Utils from '@/utils/utils.js' +import FileUpload from '@/tabviews/tableshare/fileupload' +import './index.scss' + +const {MonthPicker} = DatePicker +const { TextArea } = Input + +class MainSearch extends Component { + static propTpyes = { + action: PropTypes.object, // 鎸夐挳淇℃伅銆佽〃鍗曞垪琛� + dict: PropTypes.object, // 瀛楀吀椤� + data: PropTypes.any, // 琛ㄦ牸鏁版嵁 + BData: PropTypes.any, // 涓昏〃鏁版嵁 + configMap: PropTypes.object, // 鎸夐挳鍙婁笅鎷夎〃鍗曢厤缃俊鎭泦 + inputSubmit: PropTypes.func // input鍥炶溅鎻愪氦 + } + + state = { + datatype: null, + readtype: null, + formlist: [] + } + + componentDidMount () { + const { data, BData } = this.props + let action = JSON.parse(JSON.stringify(this.props.action)) + + let datatype = {} + let readtype = {} + let formlist = [] + if (action.groups.length > 0) { + action.groups.forEach(group => { + if (group.sublist.length === 0) return + + if (!group.default) { + formlist.push({ + type: 'title', + label: group.label, + uuid: group.uuid + }) + } + + group.sublist.forEach(item => { + datatype[item.field] = item.type + readtype[item.field] = item.readonly === 'true' + formlist.push(item) + }) + }) + } else { + formlist = action.fields.map(item => { + datatype[item.field] = item.type + readtype[item.field] = item.readonly === 'true' + + return item + }) + } + + let _inputfields = formlist.filter(item => item.type === 'text' || item.type === 'number') // 鐢ㄤ簬杩囨护涓嬫媺鑿滃崟鍏宠仈琛ㄥ崟 + + formlist = formlist.map(item => { + if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') { + if (item.setAll === 'true') { + item.options.unshift({ + key: Utils.getuuid(), + Value: '', + Text: this.props.dict['main.all'] + }) + } + + if (item.resourceType === '1' && this.props.configMap.hasOwnProperty(item.uuid)) { + item.options = [...item.options, ...this.props.configMap[item.uuid]] + } + + item.oriOptions = JSON.parse(JSON.stringify(item.options)) + + if (item.linkSubField && item.linkSubField.length > 0) { + let _fields = _inputfields.map(_item => _item.field) + item.linkSubField = item.linkSubField.filter(_item => _fields.includes(_item)) + } + } + + if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) { + item.initval = BData[item.field] + } else if (!/^date/.test(item.type) && this.props.data && this.props.data.hasOwnProperty(item.field)) { + item.initval = this.props.data[item.field] + } + + return item + }) + + let error = false + + formlist = formlist.map(item => { + if (item.type === 'link') { + let supItem = formlist.filter(form => form.field === item.linkField)[0] + + if (!supItem && data && data.hasOwnProperty(item.linkField)) { + supItem = {initval: data[item.linkField]} + } + + if (!supItem) { + error = true + } else { + item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) + } + } + + return item + }) + + if (error) { + notification.warning({ + top: 92, + message: '鍏宠仈鑿滃崟璁剧疆閿欒锛�', + duration: 10 + }) + } + + this.setState({ + readtype: readtype, + datatype: datatype, + formlist: formlist + }, () => { + if (action.setting && action.setting.focus) { + try { + let _form = document.getElementById('main-form-box') + let _item = _form.getElementsByTagName('input') + _item = [..._item] + _item.forEach(input => { + if (!input || input.id !== action.setting.focus) return + input.select() + }) + } catch { + console.warn('琛ㄥ崟鑾峰彇澶辫触锛�') + } + } + }) + } + + resetform = (formlist, supfields, index, fieldsvalue) => { + index++ + let subfields = [] + + supfields.forEach(supfield => { + formlist = formlist.map(item => { + if (item.type === 'link' && item.linkField === supfield.field) { + item.options = item.oriOptions.filter(option => option.parentId === supfield.initval) + item.initval = item.options[0] ? item.options[0].Value : '' + + fieldsvalue[item.field] = item.initval + + subfields.push(item) + } + return item + }) + }) + + if (subfields.length === 0 || index > 6) { + this.props.form.setFieldsValue(fieldsvalue) + return formlist + } else { + return this.resetform(formlist, subfields, index, fieldsvalue) + } + } + + selectChange = (_field, value, option) => { + let formlist = JSON.parse(JSON.stringify(this.state.formlist)) + + let subfields = [] + let fieldsvalue = {} + formlist = formlist.map(item => { + if (item.type === 'link' && item.linkField === _field.field) { + item.options = item.oriOptions.filter(option => option.parentId === value) + item.initval = item.options[0] ? item.options[0].Value : '' + + fieldsvalue[item.field] = item.initval + + subfields.push(item) + } + return item + }) + + // 琛ㄥ崟鍒囨崲鏃讹紝鏇存柊鍏宠仈瀛楁 + if (_field.type === 'select' && _field.linkSubField && _field.linkSubField.length > 0 && option.props.data) { + let _data = option.props.data + let fieldVal = {} + _field.linkSubField.forEach(subfield => { + fieldVal[subfield] = _data[subfield] + }) + this.props.form.setFieldsValue(fieldVal) + } + + if (subfields.length === 0) return + + formlist = this.resetform(formlist, subfields, 0, fieldsvalue) + + this.setState({ + formlist: formlist + }) + } + + getFields() { + const { getFieldDecorator } = this.props.form + + const fields = [] + let cols = 2 + if (this.props.action.setting && this.props.action.setting.cols) { + cols = parseInt(this.props.action.setting.cols) + if (cols > 3 || cols < 1) { + cols = 2 + } + } + + this.state.formlist.forEach((item, index) => { + if ((!item.field && item.type !== 'title') || item.hidden === 'true') return + + if (item.type === 'title') { + fields.push( + <Col span={24} key={index}> + <p>{item.label}</p> + </Col> + ) + } else if (item.type === 'text') { + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: item.initval || '', + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.input'] + item.label + '!' + }, + { + max: formRule.input.max, + message: formRule.input.message + } + ] + })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} />)} + </Form.Item> + </Col> + ) + } else if (item.type === 'number') { // 鏁板瓧 + let min = (item.min || item.min === 0) ? item.min : -Infinity + let max = (item.max || item.max === 0) ? item.max : Infinity + let _initval = item.initval + let precision = (item.decimal || item.decimal === 0) ? item.decimal : null + + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: _initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.input'] + item.label + '!' + } + ] + })( + precision === null ? + <InputNumber min={min} max={max} disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> : + <InputNumber min={min} max={max} precision={precision} disabled={item.readonly === 'true'} onPressEnter={this.handleSubmit} /> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'select' || item.type === 'link') { // 涓嬫媺鎼滅储 + let hasSubField = false + if (item.linkSubField && item.linkSubField.length > 0) { // 瀛樺湪鍏宠仈瀛楁锛屾暟鎹瓨鍌� + hasSubField = true + } + + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: item.initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + <Select + showSearch + filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} + onChange={(value, option) => {this.selectChange(item, value, option)}} + > + {item.options.map(option => + <Select.Option id={option.key} data={hasSubField ? option : ''} title={option.Text} key={option.key} value={option.Value}>{option.Text}</Select.Option> + )} + </Select> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'multiselect') { // 澶氶�� + let _initval = item.initval ? item.initval.split(',').filter(Boolean) : [] + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: _initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + <Select + showSearch + mode="multiple" + filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} + > + {item.options.map(option => + <Select.Option id={option.key} title={option.Text} key={option.key} value={option.Value}>{option.Text}</Select.Option> + )} + </Select> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'date') { // 鏃堕棿鎼滅储 + let _initval = this.props.data ? this.props.data[item.field] : '' + if (_initval) { + _initval = moment(_initval, 'YYYY-MM-DD') + } else { + _initval = item.initval ? moment().subtract(item.initval, 'days') : null + } + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: _initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + <DatePicker /> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'datemonth') { + let _initval = this.props.data ? this.props.data[item.field] : '' + if (_initval) { + _initval = moment(_initval, 'YYYY-MM') + } else { + _initval = item.initval ? moment().subtract(item.initval, 'month') : null + } + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: _initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + <MonthPicker /> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'datetime') { + let _initval = this.props.data ? this.props.data[item.field] : '' + if (_initval) { + _initval = moment(_initval, 'YYYY-MM-DD HH:mm:ss') + } else { + _initval = item.initval ? moment().subtract(item.initval, 'days') : null + } + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: _initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + // <DatePicker showTime getCalendarContainer={() => document.getElementById('form-box')} /> + <DatePicker showTime /> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'fileupload') { + let filelist = this.props.data ? this.props.data[item.field] : item.initval + if (filelist) { + try { + filelist = filelist.split(',').map((url, index) => { + return { + uid: `${index}`, + name: url.slice(url.lastIndexOf('/') + 1), + status: 'done', + url: url, + origin: true + } + }) + } catch { + filelist = [] + } + } + + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: filelist, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + <FileUpload /> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'linkMain') { + fields.push( + <Col span={24 / cols} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.field, { + initialValue: item.initval, + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.input'] + item.label + '!' + } + ] + })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} />)} + </Form.Item> + </Col> + ) + } else if (item.type === 'funcvar') { + // fields.push( + // <Col span={24 / cols} key={index}> + // <Form.Item label={item.label}> + // {getFieldDecorator(item.field, { + // initialValue: item.linkfield || '', + // })(<Input placeholder="" autoComplete="off" disabled={item.readonly === 'true'} />)} + // </Form.Item> + // </Col> + // ) + } else if (item.type === 'textarea') { + let _labelcol = cols !== 3 ? 8 / cols : 3 + let _wrapcol = cols !== 3 ? 16 + (cols - 1) * 4 : 21 + let _style = {} + if (cols === 2) { + _style.paddingLeft = '7px' + } + fields.push( + <Col span={24} key={index} className="textarea-row" style={{..._style}}> + <Form.Item label={item.label} labelCol={{xs: { span: 24 }, sm: { span: _labelcol }}} wrapperCol={ {xs: { span: 24 }, sm: { span: _wrapcol }} }> + {getFieldDecorator(item.field, { + initialValue: item.initval || '', + rules: [ + { + required: item.required === 'true', + message: this.props.dict['form.required.input'] + item.label + '!' + }, + { + max: formRule.textarea.max, + message: formRule.textarea.message + } + ] + })(<TextArea autosize={{ minRows: 2, maxRows: 6 }} disabled={item.readonly === 'true'} />)} + </Form.Item> + </Col> + ) + } + }) + + return fields + } + + handleConfirm = () => { + // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� + return new Promise((resolve, reject) => { + this.props.form.validateFieldsAndScroll((err, values) => { + if (!err) { + let search = [] + // 闅愯棌琛ㄥ崟 + this.state.formlist.forEach(item => { + if (!item.field) return + + if (item.type === 'funcvar') { + search.push({ + type: 'funcvar', + readonly: 'true', + key: item.field, + value: '' + }) + } else if (item.hidden === 'true') { + search.push({ + type: this.state.datatype[item.field], + readonly: this.state.readtype[item.field], + key: item.field, + value: item.initval + }) + } + }) + + Object.keys(values).forEach(key => { + if (this.state.datatype[key] === 'datetime') { + let _value = '' + if (values[key]) { + _value = moment(values[key]).format('YYYY-MM-DD HH:mm:ss') + } + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: _value + }) + } else if (this.state.datatype[key] === 'datemonth') { + let _value = '' + if (values[key]) { + _value = moment(values[key]).format('YYYY-MM') + } + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: _value + }) + } else if (this.state.datatype[key] === 'date') { + let _value = '' + if (values[key]) { + _value = moment(values[key]).format('YYYY-MM-DD') + } + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: _value + }) + } else if (this.state.datatype[key] === 'number') { + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: values[key] + }) + } else if (this.state.datatype[key] === 'multiselect') { + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: values[key] ? values[key].join(',') : '' + }) + } else if (this.state.datatype[key] === 'fileupload') { + let vals = [] + + if (values[key] && values[key].length > 0) { + values[key].forEach(_val => { + if (_val.origin && _val.url) { + vals.push(_val.url) + } else if (!_val.origin && _val.status === 'done' && _val.response) { + vals.push(Utils.getrealurl(_val.response)) + } + }) + } + + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: vals.join(',') + }) + } else if (this.state.datatype[key] === 'funcvar') { + search.push({ + type: this.state.datatype[key], + readonly: this.state.readtype[key], + key: key, + value: values[key] + }) + } 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, '') + }) + } + }) + resolve(search) + } else { + reject(err) + } + }) + }) + } + + handleSubmit = (e) => { + e.preventDefault() + this.props.inputSubmit() + } + + render() { + const formItemLayout = { + labelCol: { + xs: { span: 24 }, + sm: { span: 8 } + }, + wrapperCol: { + xs: { span: 24 }, + sm: { span: 16 } + } + } + return ( + <Form {...formItemLayout} className="ant-advanced-search-form main-form-field" id="main-form-box"> + <Row gutter={24}>{this.getFields()}</Row> + </Form> + ) + } +} + +export default Form.create()(MainSearch) \ No newline at end of file diff --git a/src/tabviews/formtab/formgroup/index.scss b/src/tabviews/formtab/formgroup/index.scss new file mode 100644 index 0000000..62fcc66 --- /dev/null +++ b/src/tabviews/formtab/formgroup/index.scss @@ -0,0 +1,36 @@ +.ant-advanced-search-form.main-form-field { + position: relative; + padding: 0px 24px 20px; + .ant-form-item { + display: flex; + } + .ant-form-item-control-wrapper { + flex: 1; + } + .ant-form-item-label { + overflow: hidden; + display: inline-block; + text-overflow: ellipsis; + white-space: nowrap; + } + .textarea-row { + .ant-col-sm-3 { + width: 10.5%; + } + .ant-col-sm-21 { + width: 89.5%; + } + } + .ant-input-number { + width: 100%; + } + .ant-form-explain { + overflow:hidden; + text-overflow:ellipsis; + white-space:nowrap; + } + p { + color: #1890ff; + border-bottom: 1px solid #d9d9d9; + } +} \ No newline at end of file diff --git a/src/tabviews/formtab/index.jsx b/src/tabviews/formtab/index.jsx index c63349d..8a9bbc4 100644 --- a/src/tabviews/formtab/index.jsx +++ b/src/tabviews/formtab/index.jsx @@ -2,19 +2,20 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { BackTop, notification, Spin, Tabs, Icon, Switch, Modal, Button} from 'antd' +import { BackTop, notification, Spin, Tabs, Icon, Modal, Button} from 'antd' import moment from 'moment' + import Api from '@/api' -import MainTable from './mainTable' +import zhCN from '@/locales/zh-CN/main.js' +import enUS from '@/locales/en-US/main.js' +import Utils from '@/utils/utils.js' + +import FormGroup from './formgroup' import MainAction from '@/tabviews/tableshare/actionList' -import MainSearch from '@/tabviews/tableshare/topSearch' import SubTable from '@/tabviews/subtable' import NotFount from '@/components/404' import asyncComponent from '@/utils/asyncLoadComponent' import {refreshTabView} from '@/store/action' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' -import Utils from '@/utils/utils.js' import './index.scss' const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable')) @@ -24,7 +25,8 @@ static propTpyes = { MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟 MenuName: PropTypes.string, // 鑿滃崟鍙傛暟 - MenuID: PropTypes.string // 鑿滃崟Id + MenuID: PropTypes.string, // 鑿滃崟Id + param: PropTypes.any // 涓昏〃浼犻�掑弬鏁� } state = { @@ -32,14 +34,11 @@ loadingview: true, // 椤甸潰鍔犺浇涓� viewlost: false, // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤 lostmsg: '', // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅 - config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑 - searchlist: null, // 鎼滅储鏉′欢 + config: {}, // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佽〃鍗曘�佹爣绛剧瓑 actions: null, // 鎸夐挳闆� - columns: null, // 鏄剧ず鍒� arr_field: '', // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆� setting: null, // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑 data: null, // 鍒楄〃鏁版嵁闆� - total: 0, // 鎬绘暟 loading: false, // 鍒楄〃鏁版嵁鍔犺浇涓� pageIndex: 1, // 椤电爜 pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 @@ -97,59 +96,26 @@ } let _arrField = [] // 瀛楁闆� - let _columns = [] // 鏄剧ず鍒� - let _hideCol = [] // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆� - let colMap = new Map() + if (this.props.param && this.props.param.arr_field) { + _arrField = this.props.param.arr_field + } else { + config.groups.forEach(group => { + group.sublist.forEach(item => { + if (!item.field) return + + _arrField.push(item.field) + }) + }) + _arrField = _arrField.join(',') + } + console.log(config) // 鏉冮檺杩囨护 config.action = config.action.filter(item => permAction[item.uuid]) // config.tabgroups.forEach(group => { // if (!config[group]) return // config[group] = config[group].filter(tab => permAction[tab.uuid]) // }) - - // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid - config.columns.forEach(col => { - if (col.field) { - _arrField.push(col.field) - } - if (col.type === 'colspan' && col.sublist) { // 绛涢�夐殣钘忓垪 - _hideCol = _hideCol.concat(col.sublist) - } else if (col.Hide === 'true') { - _hideCol.push(col.uuid) - } - colMap.set(col.uuid, col) - }) - - // 鐢熸垚鏄剧ず鍒楋紝澶勭悊鍚堝苟鍒椾腑鐨勫瓧娈� - config.columns.forEach(col => { - if (_hideCol.includes(col.uuid)) return - - if (col.type === 'colspan' && col.sublist) { - let _col = JSON.parse(JSON.stringify(col)) - let subColumn = [] - _col.sublist.forEach(sub => { - if (colMap.has(sub)) { - subColumn.push(colMap.get(sub)) - } - }) - _col.subColumn = subColumn - _columns.push(_col) - } else { - _columns.push(col) - } - }) - - let _actions = config.action.filter(item => item.position === 'toolbar') // 杩囨护宸ュ叿鏍忔寜閽� - let _operations = config.action.filter(item => item.position === 'grid') // 娣诲姞鎿嶄綔鍒楋紙瀛樺湪鏃讹級 - - if (config.gridBtn && config.gridBtn.display && _operations.length > 0) { - _columns.push({ - ...config.gridBtn, - operations: _operations - }) - } - let _isLinkMain = false // 妫�鏌ユ槸鍚︽湁涓庝富琛ㄥ叧鑱旂殑瀛愯〃 let supmenus = {} @@ -177,11 +143,9 @@ loadingview: false, config: config, setting: config.setting, - searchlist: config.search, - actions: _actions, - columns: _columns, + actions: config.action, isLinkMain: _isLinkMain, - arr_field: _arrField.join(','), + arr_field: _arrField, search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級 loading: true }, () => { @@ -315,7 +279,6 @@ item.key = index return item }), - total: result.total, loading: false, BIDs: { ...BIDs, @@ -386,12 +349,10 @@ } let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows` - let DateCount = `select count(1) as total from ${_dataresource} ${_search}` param.LText = Utils.formatOptions(LText) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' param.secretkey = Utils.encrypt(param.LText, param.timestamp) - param.DateCount = Utils.formatOptions(DateCount) return param } @@ -472,11 +433,9 @@ config: {}, searchlist: null, actions: null, - columns: null, arr_field: '', setting: null, data: null, - total: 0, loading: false, pageIndex: 1, pageSize: 10, @@ -509,8 +468,6 @@ this.reloadview() } else if (btn.popClose === 'grid' && type === 'pop') { this.reloadtable() - } else if (type === 'excelOut') { - this.handleDefaultExcelout(btn) } } @@ -519,61 +476,6 @@ */ handleMainTable = () => { this.reloadtable() - } - - /** - * @description 浣跨敤榛樿瀛樺偍杩囩▼ sPC_Get_TableData 瀵煎嚭excel琛ㄦ牸 - */ - handleDefaultExcelout = (btn) => { - const { MenuName } = this.props - const { arr_field, orderColumn, orderType, search, setting, config } = this.state - - let _arr_labels = [] // 鍒楀悕绉伴泦 - let _arr_label_field = [] // 鍒楀悕绉板瓧娈甸泦 - - config.columns.forEach(col => { - if (col.field) { - _arr_labels.push(col.label) - _arr_label_field.push(`${col.field} as ${col.label}`) - } - }) - - _arr_labels = _arr_labels.join(',') - _arr_label_field = _arr_label_field.join(',') - - let _search = Utils.joinMainSearchkey(search) - _search = _search ? 'where ' + _search : '' - - // 鑾峰彇excel鏁版嵁锛屼笌鑾峰彇鍒楄〃鏁版嵁涓嶅悓涓烘湭璁剧疆椤电爜绛夊弬鏁� - let param = { - func: 'sPC_Get_TableData', - obj_name: 'data', - arr_field: _arr_labels - } - - let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order - let _dataresource = setting.dataresource - - if (/\s/.test(_dataresource)) { - _dataresource = '(' + _dataresource + ') tb' - } - - let LText = `select ${_arr_label_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows` - - param.LText = Utils.formatOptions(LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - param.secretkey = Utils.encrypt(param.LText, param.timestamp) - param.DateCount = '' - - let name = `${MenuName}${moment().format('YYYYMMDDHHmmss')}.xlsx` - - Api.getExcelOut(param, name).then(res => { - if (res && res.status === false) { - this.refs.mainButton.execError(res, btn) - } else { - this.refs.mainButton.execSuccess(btn) - } - }) } /** @@ -671,16 +573,16 @@ } render() { - const { setting, searchlist, actions, columns, loadingview, viewlost, setsingle, pickup, isLinkMain, config } = this.state + const { setting, actions, loadingview, viewlost, isLinkMain, config } = this.state return ( <div className={'commontable ' + (isLinkMain ? 'pick-control' : '')} id={'commontable' + this.props.MenuID}> {loadingview && <Spin size="large" />} - {searchlist && searchlist.length > 0 ? - <MainSearch + {config ? + <FormGroup dict={this.state.dict} - searchlist={searchlist} - refreshdata={this.refreshbysearch} + groups={config.groups} + wrappedComponentRef={(inst) => this.formGroupRef = inst} /> : null } {actions && setting.onload !== 'false' ? @@ -696,31 +598,6 @@ triggerPopview={this.triggerPopview} gettableselected={this.gettableselected} /> : null - } - {columns && setting.onload !== 'false' ? - <div className="main-table-box"> - {isLinkMain ? - <div className="pickchange"> - {setting.tableType === 'checkbox' ? <Switch title="鍗曢�夊垏鎹�" checkedChildren="鍗�" unCheckedChildren="澶�" defaultChecked={setsingle} onChange={this.checkChange} /> : null} - {this.state.BIDs.mainTable && (setting.tableType === 'radio' || setsingle) ? <Switch title="鏀惰捣" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null} - </div> : null - } - <MainTable - ref="mainTable" - pickup={pickup} - setting={setting} - columns={columns} - setsingle={setsingle} - dict={this.state.dict} - data={this.state.data} - total={this.state.total} - MenuID={this.props.MenuID} - loading={this.state.loading} - refreshdata={this.refreshbytable} - buttonTrigger={this.buttonTrigger} - handleTableId={this.handleTableId} - /> - </div> : null } {setting && setting.onload !== 'false' && config.tabgroups.map(group => { diff --git a/src/tabviews/formtab/mainTable/index.jsx b/src/tabviews/formtab/mainTable/index.jsx deleted file mode 100644 index b2223cd..0000000 --- a/src/tabviews/formtab/mainTable/index.jsx +++ /dev/null @@ -1,393 +0,0 @@ -import React, {Component} from 'react' -import PropTypes from 'prop-types' -import { is, fromJS } from 'immutable' -import { Table, message, Affix, Button, Typography } from 'antd' -import './index.scss' - -const { Paragraph } = Typography - -export default class MainTable extends Component { - static propTpyes = { - dict: PropTypes.object, // 瀛楀吀椤� - MenuID: PropTypes.string, // 鑿滃崟Id - setting: PropTypes.object, // 琛ㄦ牸鍏ㄥ眬璁剧疆锛歵ableType锛堣〃鏍兼槸鍚﹀彲閫夈�佸崟閫夈�佸閫夛級銆乧olumnfixed锛堝垪鍥哄畾锛夈�乤ctionfixed锛堟寜閽浐瀹氾級 - pickup: PropTypes.any, // 鏁版嵁鏀惰捣 - setsingle: PropTypes.any, // 璁剧疆鍗曢�夊閫� - columns: PropTypes.array, // 琛ㄦ牸鍒� - data: PropTypes.any, // 琛ㄦ牸鏁版嵁 - total: PropTypes.number, // 鎬绘暟 - loading: PropTypes.bool, // 琛ㄦ牸鍔犺浇涓� - refreshdata: PropTypes.func, // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂� - buttonTrigger: PropTypes.func, // 琛ㄦ牸涓寜閽Е鍙戞搷浣� - handleTableId: PropTypes.func // 鏁版嵁鍒囨崲 - } - - state = { - selectedRowKeys: [], // 琛ㄦ牸涓�変腑琛� - pageIndex: 1, // 鍒濆椤甸潰绱㈠紩 - pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 - columns: null, // 鏄剧ず鍒� - selectId: '', - isSingleSelect: false - } - - UNSAFE_componentWillMount () { - const { columns, setting } = this.props - let _columns = [] - - columns.forEach(item => { - let cell = { - align: item.Align, - dataIndex: item.field || item.uuid, - title: item.label, - sorter: item.field && item.IsSort === 'true', - width: item.Width || 120, - render: (text, record) => { - return this.getContent(item, record) - } - } - _columns.push(cell) - }) - - this.setState({ - columns: _columns, - isSingleSelect: setting.tableType === 'radio' - }) - } - - UNSAFE_componentWillReceiveProps(nextProps) { - if (!is(fromJS(this.props.setsingle), fromJS(nextProps.setsingle))) { - this.setState({ - isSingleSelect: nextProps.setsingle, - selectedRowKeys: [], - selectId: '' - }) - } - } - - getContent = (item, record) => { - if (item.type === 'text') { - let content = '' - let match = false - if (item.field && record.hasOwnProperty(item.field)) { - content = `${record[item.field]}` - } - - if (content && item.matchVal && content.indexOf(item.matchVal) > 0) { - match = true - } - - content = (item.prefix || '') + content + (item.postfix || '') - - return ( - <div className={match ? item.color : ''}> - <div className="background"></div> - <div className="content" style={{ minWidth: (item.Width || 120) + 'px' }}> - {content} - </div> - </div> - ) - } else if (item.type === 'number') { - let content = '' - let match = false - if (item.field && record.hasOwnProperty(item.field)) { - content = +record[item.field] - } - - if (content && item.match && item.matchVal) { - if (item.match === '>') { - if (content > item.matchVal) { - match = true - } - } else if (item.match === '<') { - if (content < item.matchVal) { - match = true - } - } else if (item.match === '>=') { - if (content >= item.matchVal) { - match = true - } - } else if (item.match === '<=') { - if (content <= item.matchVal) { - match = true - } - } - } - - if (content && item.format === 'thdSeparator') { - content = `${content}` - content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') - } - - content = (item.prefix || '') + content + (item.postfix || '') - - return ( - <div className={match ? item.color : ''}> - <div className={'background'}></div> - <div className="content" style={{ minWidth: (item.Width || 120) + 'px' }}> - {content} - </div> - </div> - ) - } else if (item.type === 'picture') { - let photos = '' - if (item.field && record.hasOwnProperty(item.field)) { - photos = record[item.field].split(',') - } else { - photos = '' - } - return ( - <div className="picture-col" style={{ minWidth: (item.Width || 120) + 'px' }}> - {photos && photos.map((url, i) => { - return <img key={`${i}`} src={url} alt=""/> - })} - </div> - ) - } else if (item.type === 'textarea') { - let content = '' - let match = false - if (item.field && record.hasOwnProperty(item.field)) { - content = `${record[item.field]}` - } - - if (content && item.matchVal && content.indexOf(item.matchVal) > 0) { - match = true - } - - content = (item.prefix || '') + content + (item.postfix || '') - - return ( - <div className={match ? item.color : ''}> - <div className="background"></div> - <div className="content" style={{ minWidth: (item.Width || 120) + 'px' }}> - <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> - </div> - </div> - ) - } else if (item.type === 'action') { - return ( - <div className={item.style} style={{ minWidth: (item.Width || 120) + 'px' }}> - {item.operations.map(btn => { - return <Button - className={'mk-btn mk-' + btn.class} - icon={btn.icon} - key={btn.uuid} - onClick={(e) => {this.actionTrigger(e, btn, record)}} - >{btn.label}</Button> - })} - </div> - ) - } else if (item.type === 'colspan') { - let contents = '' - if (item.subColumn.length > 0) { - contents = item.subColumn.map(col => { - let content = '' - if (col.type === 'text' || col.type === 'textarea') { - if (col.field && record.hasOwnProperty(col.field)) { - content = `${record[col.field]}` - } - - content = (col.prefix || '') + content + (col.postfix || '') - } else if (col.type === 'number') { - if (col.field && record.hasOwnProperty(col.field)) { - content = +record[col.field] - } - if (content && col.format === 'thdSeparator') { - content = `${content}` - content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') - } - content = (col.prefix || '') + content + (col.postfix || '') - } - return content - }) - } - - if (contents && item.order === 'vertical2') { - let _contents = [] - for(let i = 0; i < contents.length; i += 2) { - _contents.push(contents.slice(i, i + 2).join(' ')) - } - contents = _contents - } - - return ( - <div> - <div className="content" style={{ minWidth: (item.Width || 120) + 'px' }}> - {contents && item.order === 'vertical' && contents.map((content, index) => { - return (<p key={index}>{content}</p>) - })} - {contents && item.order === 'vertical2' && contents.map((content, index) => { - return (<p key={index}>{content}</p>) - })} - {contents && item.order === 'horizontal' && contents.map((content, index) => { - return (<span key={index}>{content}</span>) - })} - </div> - </div> - ) - } - } - - actionTrigger = (e, btn, record) => { - e.stopPropagation() - this.props.buttonTrigger(btn, record) - } - - copycontent = (e, content) => { - // 琛ㄦ牸涓唴瀹瑰鍒� - e.stopPropagation() - let oInput = document.createElement('input') - oInput.value = content - document.body.appendChild(oInput) - oInput.select() - document.execCommand('Copy') - oInput.className = 'oInput' - oInput.style.display='none' - message.success(this.props.dict['main.copy.success']) - } - - onSelectChange = selectedRowKeys => { - if (this.props.pickup) return - - let index = '' - if (selectedRowKeys.length > 0) { - index = selectedRowKeys[selectedRowKeys.length - 1] - } - - this.changedata(index) - - this.setState({ selectedRowKeys }) - } - - changeRow = (record, index) => { - // 鐐瑰嚮鏁磋锛岃Е鍙戝垏鎹紝鍒ゆ柇鏄惁鍙�夛紝鍗曢�夋垨澶氶�夛紝杩涜瀵瑰簲鎿嶄綔 - if (!this.props.setting.tableType || this.props.pickup) return - - let newkeys = JSON.parse(JSON.stringify(this.state.selectedRowKeys)) - let _re = newkeys.includes(index) - - if (this.props.setting.tableType === 'radio' || this.state.isSingleSelect) { - this.changedata(index) - this.setState({ selectedRowKeys: [index] }) - } else { - if (_re) { - newkeys = newkeys.filter(item => item !== index) - this.changedata('') - } else { - newkeys.push(index) - this.changedata(index) - } - - this.setState({ selectedRowKeys: newkeys }) - } - } - - changeTable = (pagination, filters, sorter) => { - this.setState({ - pageIndex: pagination.current, - pageSize: pagination.pageSize, - selectedRowKeys: [] - }) - this.props.refreshdata(pagination, filters, sorter) - } - - changedata = (index) => { - const { data, setting } = this.props - let _id = '' - - if (data && data.length > 0 && index !== '') { - _id = data[index][setting.primaryKey] || '' - } - - this.setState({ - selectId: _id - }) - - this.props.handleTableId('mainTable', _id) - } - - resetTable = () => { - this.setState({ - pageIndex: 1, - selectId: '', - selectedRowKeys: [] - }) - } - - render() { - const { setting, pickup } = this.props - let { selectedRowKeys, isSingleSelect, selectId } = this.state - - let rowSelection = null - if (setting.tableType) { - rowSelection = { - selectedRowKeys, - type: (setting.tableType === 'radio' || isSingleSelect) ? 'radio' : 'checkbox', - onChange: this.onSelectChange - } - } - let offset = null - if (setting.columnfixed) { - // 琛ㄦ牸澶撮儴鍥哄畾浜庨《閮ㄦ椂锛屽垽鏂窛椤堕儴楂樺害 - if (!setting.actionfixed) { - offset = 48 - } else { - let box = document.getElementById(this.props.MenuID + 'mainaction') - if (box) { - offset = 48 + box.offsetHeight - } else { - offset = 105 - } - } - } - - let _data = this.props.data ? this.props.data : [] - - if (selectId && pickup && isSingleSelect) { - _data = _data.filter(item => item[setting.primaryKey] === selectId) - } - - return ( - <div className="main-table"> - {setting.columnfixed && <Affix offsetTop={offset} className="fix-header"> - <Table - size="middle" - bordered={true} - rowSelection={rowSelection} - columns={this.state.columns.map(column => { - return { - align: column.align, - dataIndex: column.dataIndex, - title: column.title, - width: column.width - } - })} - /> - </Affix>} - <Table - size="middle" - bordered={true} - rowSelection={rowSelection} - columns={this.state.columns} - dataSource={_data} - loading={this.props.loading} - scroll={{ x: '100%', y: false }} - onRow={(record, index) => { - return { - onClick: () => {this.changeRow(record, index)} - } - }} - onChange={this.changeTable} - pagination={{ - current: this.state.pageIndex, - pageSize: this.state.pageSize, - pageSizeOptions: ['10', '25', '50', '100', '500', '1000'], - showSizeChanger: true, - total: this.props.total, - showTotal: (total, range) => `${range[0]}-${range[1]} ${this.props.dict['main.pagination.of']} ${total} ${this.props.dict['main.pagination.items']}` - }} - /> - </div> - ) - } -} diff --git a/src/tabviews/formtab/mainTable/index.scss b/src/tabviews/formtab/mainTable/index.scss deleted file mode 100644 index 93f37b9..0000000 --- a/src/tabviews/formtab/mainTable/index.scss +++ /dev/null @@ -1,133 +0,0 @@ -.main-table { - padding: 0 20px 30px; - table { - max-width: 100%; - width: 100%; - .ant-table-column-title { - white-space: nowrap; - } - .ant-table-selection-column { - width: 60px; - min-width: 60px; - max-width: 60px; - } - // .ant-table-tbody > tr td:not(.ant-table-selection-column) { - // padding: 0!important; - // } - // .ant-table-tbody > tr td .content { - // padding: 12px 8px; - // height: 100%; - // background: lightblue; - // } - .ant-table-tbody > tr.ant-table-row-selected td { - background-color: #c4ebfd; - } - .ant-table-tbody > tr.ant-table-row-selected:hover .ant-table-column-sort { - background-color: #c4ebfd; - } - } - .ant-table-body { - overflow-x: auto!important; - min-height: 90px; - border: 1px solid #e8e8e8; - border-radius: 4px; - border-top: none; - border-bottom: none; - table { - border-left: 0; - .ant-table-thead > tr > th:last-child { - border-right: 0; - } - .ant-table-tbody > tr > td:last-child { - border-right: 0; - } - .ant-table-tbody > tr > td { - vertical-align: top; - .content { - position: relative; - z-index: 1; - word-wrap: break-word; - word-break: break-word; - } - .picture-col { - img { - max-width: 100%; - } - } - } - .ant-table-tbody > tr > td.ant-table-column-has-actions { - position: relative; - .background { - position: absolute; - top: 0px; - left: 0px; - right: 0px; - bottom: 0px; - } - - .content { - position: relative; - z-index: 1; - word-wrap: break-word; - word-break: break-word; - } - .red { - .content { - color: red; - } - } - .redbg { - .background { - background: lightcoral; - } - } - } - .ant-table-tbody > tr > td .content { - p { - margin-bottom: 5px; - } - span { - display: inline-block; - margin-right: 5px; - } - } - .ant-table-tbody > tr > td .button { - .ant-btn { - margin-bottom: 10px; - } - } - } - } - .ant-table-body::-webkit-scrollbar { - width: 8px; - height: 10px; - } - ::-webkit-scrollbar-thumb { - border-radius: 5px; - box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.13); - background: rgba(0, 0, 0, 0.13); - } - ::-webkit-scrollbar-track {/*婊氬姩鏉¢噷闈㈣建閬�*/ - box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.05); - border-radius: 3px; - border: 1px solid rgba(0, 0, 0, 0.07); - background: rgba(0, 0, 0, 0); - } - .fix-header { - .ant-table-body { - min-height: unset - } - .ant-table-placeholder { - display: none; - } - .ant-table-wrapper { - display: none; - } - .ant-affix .ant-table-wrapper { - display: block; - } - // .ant-table-column-sorter, .anticon-filter { - // display: none; - // } - } -} \ No newline at end of file diff --git a/src/tabviews/tableshare/actionList/index.jsx b/src/tabviews/tableshare/actionList/index.jsx index 9c65c49..351af34 100644 --- a/src/tabviews/tableshare/actionList/index.jsx +++ b/src/tabviews/tableshare/actionList/index.jsx @@ -862,6 +862,7 @@ const { execAction, tabledata } = this.state let _this = this let _fields = [] + if (execAction.groups.length > 0) { execAction.groups.forEach(group => { _fields = [..._fields, ...group.sublist] @@ -869,6 +870,7 @@ } else { _fields = execAction.fields } + let result = _fields.map(item => { return { key: item.field, diff --git a/src/tabviews/tableshare/mutilform/index.jsx b/src/tabviews/tableshare/mutilform/index.jsx index b56eea3..25bd9f3 100644 --- a/src/tabviews/tableshare/mutilform/index.jsx +++ b/src/tabviews/tableshare/mutilform/index.jsx @@ -204,16 +204,6 @@ }) } - // handleInputNumber = (rule, value, callback, item) => { - // if (item.required === 'true' && (!value && value !== 0)) { - // callback(this.props.dict['form.required.input'] + item.label + '!') - // } else if ((item.min || item.min === 0) && (value || value === 0) && value < item.min) { - // callback(item.label + '鏈�灏忓�间负' + item.min + '!') - // } else if ((item.max || item.max === 0) && (value || value === 0) && value > item.max) { - // callback(item.label + '鏈�澶у�间负' + item.max + '!') - // } - // } - getFields() { const { getFieldDecorator } = this.props.form diff --git a/src/templates/modalconfig/index.jsx b/src/templates/modalconfig/index.jsx index 3db06af..32ef6c9 100644 --- a/src/templates/modalconfig/index.jsx +++ b/src/templates/modalconfig/index.jsx @@ -956,7 +956,7 @@ <div className="modal-form-board"> <DndProvider backend={HTML5Backend}> <div className="tools"> - <Collapse accordion defaultActiveKey="0" bordered={false}> + <Collapse accordion defaultActiveKey="1" bordered={false}> <Panel header={this.state.dict['header.menu.basedata']} key="0" id="modal-basedata"> <MenuForm dict={this.state.dict} @@ -1094,6 +1094,7 @@ width={'65vw'} style={{minWidth: '900px', maxWidth: '1200px'}} onOk={this.addFieldSubmit} + cancelText={this.state.dict['header.close']} onCancel={() => { this.setState({ tableVisible: false }) }} destroyOnClose > -- Gitblit v1.8.0