From 10f5efae1624c89d9a8f04ac331e07c895ea282a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 25 五月 2024 18:22:58 +0800 Subject: [PATCH] 2024-05-25 --- src/menu/components/table/edit-table/columns/editColumn/index.jsx | 225 ++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 171 insertions(+), 54 deletions(-) diff --git a/src/menu/components/table/edit-table/columns/editColumn/index.jsx b/src/menu/components/table/edit-table/columns/editColumn/index.jsx index 796a764..dd97ea0 100644 --- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx +++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx @@ -6,12 +6,15 @@ import Api from '@/api' import Utils from '@/utils/utils.js' +import { checkSQL } from '@/utils/utils-custom.js' import { getColumnForm } from './formconfig' +import asyncComponent from '@/utils/asyncComponent' import { formRule } from '@/utils/option.js' import CodeMirror from '@/templates/zshare/codemirror' import EditTable from '@/templates/zshare/modalform/modaleditable' import './index.scss' +const FieldsTable = asyncComponent(() => import('@/templates/zshare/editTable')) const { TextArea } = Input const columnTypeOptions = { @@ -20,6 +23,7 @@ textarea: ['label', 'field', 'type', 'Align', 'Hide', 'Width', 'prefix', 'initval', 'postfix', 'blacklist'], custom: ['label', 'type', 'Align', 'Width', 'blacklist', 'IsSort'], colspan: ['label', 'type', 'Align', 'Hide', 'blacklist'], + extend: ['label', 'field', 'type', 'Align', 'Width', 'colUnit', 'shift', 'quota', 'supField'], action: ['label', 'type', 'Align', 'Width'], formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist'], index: ['label', 'type', 'Align', 'Width'] @@ -28,6 +32,7 @@ class EdiTableColumn extends Component { static propTpyes = { column: PropTypes.object, + wrap: PropTypes.object, columns: PropTypes.array, fields: PropTypes.array, submitCol: PropTypes.func, // 鎻愪氦浜嬩欢 @@ -61,6 +66,8 @@ getOptions = () => { let _options = fromJS(columnTypeOptions[this.record.type]).toJS() + let reLabel = {} + if (['number', 'text'].includes(this.record.type) && this.record.editable === 'true') { _options.push('ctrlField') if (this.record.ctrlField) { @@ -70,11 +77,13 @@ _options.push('editType') if (this.record.editType === 'switch') { - _options.push('enter', 'openVal', 'closeVal', 'openText', 'closeText', 'editField') + _options.push('enter', 'openVal', 'closeVal', 'openText', 'closeText') } else if (this.record.editType === 'date') { _options.push('required', 'precision', 'enter', 'declareType') + } else if (this.record.editType === 'popSelect') { + _options.push('required', 'enter', 'linkSubField', 'columns', 'dataSource', 'primaryKey', 'order', 'showField', 'controlField', 'searchKey', 'popWidth', 'laypage', 'cache', 'onload') } else if (this.record.editType === 'select') { - _options.push('required', 'enter', 'resourceType', 'linkSubField', 'editField', 'dropdown') + _options.push('required', 'enter', 'resourceType', 'linkSubField', 'dropdown') if (this.record.resourceType === '0') { _options.push('options') @@ -84,8 +93,18 @@ } else { _options.push('required', 'enter') } + + reLabel.required = '蹇呭~' } else if (this.record.type === 'number') { - _options.push('max', 'min', 'enter') + _options.push('max', 'min', 'required', 'enter', 'clearField') + + reLabel.required = '涓嶇瓑浜�0' + } + } else if (this.record.type === 'extend') { + if (this.record.colUnit === 'day') { + _options.push('dayFormat') + } else { + _options.push('hourFormat') } } if (this.record.type === 'formula' && this.record.eval === 'true') { @@ -93,11 +112,16 @@ } else if (this.record.type === 'custom' && this.record.IsSort === 'true') { _options.push('sortField') } - if (['number', 'formula'].includes(this.record.type) && this.record.Hide !== 'true') { - _options.push('noValue') + + if (this.record.Hide !== 'true') { + if (['number', 'formula'].includes(this.record.type)) { + _options.push('noValue') + } else if (this.record.type === 'text' && ['YYYY-MM-DD', 'YYYY-MM-DD HH:mm:ss'].includes(this.record.textFormat)) { + _options.push('noValue') + } } - return _options + return {options: _options, reLabel} } editColumn = (column) => { @@ -106,19 +130,23 @@ return item }) - let formlist = getColumnForm(column, fields, this.props.columns) + let formlist = getColumnForm(column, fields, this.props.columns, this.props.wrap) this.record = {} formlist.forEach(item => { this.record[item.key] = item.initVal }) - let _options = this.getOptions() + let { options, reLabel } = this.getOptions() this.setState({ visible: true, formlist: formlist.map(item => { - item.hidden = !_options.includes(item.key) + item.hidden = !options.includes(item.key) + + if (reLabel[item.key]) { + item.label = reLabel[item.key] + } if (item.key === 'formula') { item.fields = this.props.fields.map(col => col.field) @@ -148,7 +176,7 @@ this.record.IsSort = 'false' } - let _options = this.getOptions() + let { options, reLabel } = this.getOptions() let _field = '' if (value === 'formula') { @@ -162,7 +190,10 @@ } item.initVal = this.record[item.key] - item.hidden = !_options.includes(item.key) + item.hidden = !options.includes(item.key) + if (reLabel[item.key]) { + item.label = reLabel[item.key] + } return item }) @@ -194,12 +225,15 @@ this.record.type = values.type if (values.type !== _type) { - let _options = this.getOptions() + let { options, reLabel } = this.getOptions() this.setState({ formlist: this.state.formlist.map(item => { item.initVal = this.record[item.key] - item.hidden = !_options.includes(item.key) + item.hidden = !options.includes(item.key) + if (reLabel[item.key]) { + item.label = reLabel[item.key] + } return item }) @@ -211,13 +245,34 @@ } } else if (key === 'format' && value === 'percent') { this.props.form.setFieldsValue({postfix: '%'}) - } else if (['editable', 'editType', 'resourceType', 'ctrlField', 'eval', 'Hide', 'IsSort'].includes(key)) { - let _options = this.getOptions() + } else if (key === 'editType') { + let { options, reLabel } = this.getOptions() + + this.setState({ + formlist: this.state.formlist.map(item => { + if (item.key === 'enter' && item.options && item.options[item.options.length - 1].field === '$noActX') { + item.options[item.options.length - 1].disabled = value !== 'select' + } + + item.initVal = this.record[item.key] + item.hidden = !options.includes(item.key) + if (reLabel[item.key]) { + item.label = reLabel[item.key] + } + + return item + }) + }) + } else if (['editable', 'editType', 'resourceType', 'ctrlField', 'eval', 'Hide', 'IsSort', 'textFormat'].includes(key)) { + let { options, reLabel } = this.getOptions() this.setState({ formlist: this.state.formlist.map(item => { item.initVal = this.record[item.key] - item.hidden = !_options.includes(item.key) + item.hidden = !options.includes(item.key) + if (reLabel[item.key]) { + item.label = reLabel[item.key] + } return item }) @@ -265,8 +320,8 @@ this.props.form.setFieldsValue({dataSource: resource}) } - changeOptions = (data) => { - this.record.options = data || [] + changeOptions = (data, key) => { + this.record[key] = data || [] } getFields() { @@ -285,6 +340,14 @@ let content = null let extra = null let initVal = item.initVal || '' + let label = item.label + if (item.tooltip) { + if (item.toolWidth) { + label = <Tooltip placement="topLeft" overlayStyle={{maxWidth: item.toolWidth}} title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip> + } else { + label = <Tooltip placement="topLeft" title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip> + } + } if (item.type === 'text') { rules = [ @@ -311,6 +374,12 @@ rules = [ { required: item.required, message: '璇烽�夋嫨' + item.label + '!' } ] + + let options = item.options + if (typeof(item.options) === 'string') { + options = this.record[item.options] || [] + } + content = <Select showSearch allowClear={item.allowClear === true} @@ -318,8 +387,8 @@ onChange={(value, option) => {this.typeChange(item.key, value, option)}} getPopupContainer={() => document.getElementById('edit-table-column-winter')} > - {item.options.map((option, i) => - <Select.Option key={i} datatype={option.datatype || ''} label={option.label || ''} value={(option.value || option.field || option.MenuID)}> + {options.map((option, i) => + <Select.Option key={i} disabled={option.disabled === true} datatype={option.datatype || ''} label={option.label || ''} value={(option.value || option.field || option.MenuID)}> {(option.text || option.label || option.MenuName)} </Select.Option> )} @@ -346,7 +415,6 @@ </Select> } else if (item.type === 'textarea') { span = 24 - className = 'text-area' rules = [ { required: item.required, message: '璇疯緭鍏�' + item.label + '!' } ] @@ -354,12 +422,7 @@ if (item.key === 'formula') { fields.push( <Col span={span} key={index}> - <Form.Item className={className} extra={extra} label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <QuestionCircleOutlined className="mk-form-tip" /> - {item.label} - </Tooltip> : item.label - }> + <Form.Item className={className} extra={extra} label={label}> {getFieldDecorator(item.key, { initialValue: initVal, rules: rules @@ -379,9 +442,10 @@ { required: item.required, message: '璇疯緭鍏�' + item.label + '!' } ] span = 24 - className = 'text-area' - extra = <span className="add-resource-empty" onClick={this.handleEmpty}>绌�</span> + if (this.record.editType !== 'popSelect') { + extra = <span className="add-resource-empty" onClick={this.handleEmpty}>绌�</span> + } if (item.placeholder) { extra = <><span className="resource-public-var">{item.placeholder}</span>{extra}</> } @@ -389,7 +453,6 @@ content = <CodeMirror /> } else if (item.type === 'options') { span = 24 - className = 'text-area' let linkSubFields = this.record.linkSubField || [] @@ -404,17 +467,19 @@ columns.push({ title: transfield[field] || field, key: field }) }) - content = <EditTable columns={columns} module="form" onChange={this.changeOptions}/> + content = <EditTable columns={columns} module="form" onChange={(data) => this.changeOptions(data, item.key)}/> + } else if (item.type === 'fields') { + span = 24 + rules = [ + { required: item.required, message: '璇锋坊鍔�' + item.label + '!' } + ] + + content = <FieldsTable indexShow={false} actions={['edit', 'move', 'del', 'add']} columns={item.columns} data={this.record[item.key] || []} onChange={(data) => this.changeOptions(data, item.key)}/> } fields.push( <Col span={span} key={index}> - <Form.Item className={className} extra={extra} label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <QuestionCircleOutlined className="mk-form-tip" /> - {item.label} - </Tooltip> : item.label - }> + <Form.Item className={className} extra={extra} label={label}> {getFieldDecorator(item.key, { initialValue: initVal, rules: rules @@ -503,27 +568,27 @@ } } - if (values.dataSource && /\s/.test(values.dataSource)) { - let error = Utils.verifySql(values.dataSource) - - if (error) { - notification.warning({ - top: 92, - message: '鏁版嵁婧愪腑涓嶅彲浣跨敤' + error, - duration: 5 - }) - return + if (values.type === 'text' && values.editable === 'true') { + if (values.editType !== 'select' && values.enter === '$noActX') { + values.enter = '$noAct' } + } - this.setState({ - loading: true - }) + if (values.dataSource) { + let pass = checkSQL(values.dataSource) + + if (!pass) return + } + + if (values.editType === 'select' && values.resourceType === '1' && values.dataSource) { + let _option = Utils.getSelectQueryOptions(values) let sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20) - ${values.dataSource}` - - sql = sql.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'1949-10-01 15:00:00'`) - + ${_option.sql}` + + // LoginUID|SessionUid|UserID|Appkey 宸叉浛鎹� + sql = sql.replace(/@\$|\$@/ig, '') + let rduri = '' if (window.GLOB.mainSystemApi && values.database === 'sso') { rduri = window.GLOB.mainSystemApi @@ -541,6 +606,58 @@ }) } }) + } else if (values.editType === 'popSelect' && values.dataSource) { + let arrfield = values.columns.map(f => f.field) + + if (values.linkSubField && values.linkSubField.length > 0) { + values.linkSubField.forEach(n => { + if (!arrfield.includes(n)) { + arrfield.push(n) + } + }) + } + + let _datasource = values.dataSource + let sql = '' + + if (/\s/.test(_datasource)) { // 鎷兼帴鍒悕 + _datasource = '(' + _datasource + ') tb' + } + + arrfield = arrfield.join(',') + + let _search = '' + + if (values.searchKey) { + let fields = values.searchKey.split(',').map(field => field + ' like \'%mk%\'') + _search = 'where ' + fields.join(' OR ') + } + + if (values.laypage === 'true') { + sql = `/*system_query*/select top 10 ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by ${values.order}) as rows from ${_datasource} ${_search}) tmptable where rows > 0 order by tmptable.rows ` + } else if (values.order) { + sql = `/*system_query*/select ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by ${values.order}) as rows from ${_datasource} ${_search}) tmptable order by tmptable.rows ` + } else { + sql = `/*system_query*/select ${arrfield} from ${_datasource} ${_search} ` + } + + sql = `declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20) + ${sql}` + + sql = sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, `''`) + + Api.sDebug(sql).then(result => { + if (result.status || result.ErrCode === '-2') { + this.setState({visible: false, loading: false, formlist: null}) + this.props.submitCol(values) + this.record = null + } else { + this.setState({loading: false}) + Modal.error({ + title: result.message + }) + } + }) } else { this.setState({visible: false, formlist: null}) this.props.submitCol(values) -- Gitblit v1.8.0