From 742f7d11557526038d332e60a8c8ca18177bc4e4 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 26 十月 2023 15:51:58 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/menu/components/table/edit-table/columns/editColumn/index.jsx | 125 ++++++++++++++++++++++++++++++++++------- 1 files changed, 103 insertions(+), 22 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 9a107bb..baca4f6 100644 --- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx +++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx @@ -7,18 +7,20 @@ import Api from '@/api' import Utils from '@/utils/utils.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 = { text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'editable', 'initval', 'blacklist'], number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'editable', 'initval', 'sum', 'blacklist'], textarea: ['label', 'field', 'type', 'Align', 'Hide', 'Width', 'prefix', 'initval', 'postfix', 'blacklist'], - custom: ['label', 'type', 'Align', 'Width', 'blacklist'], + custom: ['label', 'type', 'Align', 'Width', 'blacklist', 'IsSort'], colspan: ['label', 'type', 'Align', 'Hide', 'blacklist'], action: ['label', 'type', 'Align', 'Width'], formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist'], @@ -70,11 +72,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') } 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') @@ -90,6 +94,8 @@ } if (this.record.type === 'formula' && this.record.eval === 'true') { _options.push('decimal') + } 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') @@ -142,6 +148,10 @@ this.record[key] = value if (key === 'type') { + if (['textarea', 'custom'].includes(value)) { + this.record.IsSort = 'false' + } + let _options = this.getOptions() let _field = '' @@ -161,7 +171,9 @@ return item }) }, () => { - if (value === 'colspan') { + if (['textarea', 'custom'].includes(value)) { + this.props.form.setFieldsValue({IsSort: 'false'}) + } else if (value === 'colspan') { this.props.form.setFieldsValue({Align: 'center'}) } else if (value === 'formula' && _field) { this.props.form.setFieldsValue({formula: '@' + _field + '@'}) @@ -203,7 +215,7 @@ } } else if (key === 'format' && value === 'percent') { this.props.form.setFieldsValue({postfix: '%'}) - } else if (['editable', 'editType', 'resourceType', 'ctrlField', 'eval', 'Hide'].includes(key)) { + } else if (['editable', 'editType', 'resourceType', 'ctrlField', 'eval', 'Hide', 'IsSort'].includes(key)) { let _options = this.getOptions() this.setState({ @@ -257,8 +269,8 @@ this.props.form.setFieldsValue({dataSource: resource}) } - changeOptions = (data) => { - this.record.options = data || [] + changeOptions = (data, key) => { + this.record[key] = data || [] } getFields() { @@ -303,6 +315,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} @@ -310,7 +328,7 @@ onChange={(value, option) => {this.typeChange(item.key, value, option)}} getPopupContainer={() => document.getElementById('edit-table-column-winter')} > - {item.options.map((option, i) => + {options.map((option, i) => <Select.Option key={i} datatype={option.datatype || ''} label={option.label || ''} value={(option.value || option.field || option.MenuID)}> {(option.text || option.label || option.MenuName)} </Select.Option> @@ -338,7 +356,6 @@ </Select> } else if (item.type === 'textarea') { span = 24 - className = 'text-area' rules = [ { required: item.required, message: '璇疯緭鍏�' + item.label + '!' } ] @@ -371,9 +388,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}</> } @@ -381,7 +399,6 @@ content = <CodeMirror /> } else if (item.type === 'options') { span = 24 - className = 'text-area' let linkSubFields = this.record.linkSubField || [] @@ -396,7 +413,14 @@ 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( @@ -495,9 +519,9 @@ } } - if (values.dataSource && /\s/.test(values.dataSource)) { + if (values.dataSource) { let error = Utils.verifySql(values.dataSource) - + if (error) { notification.warning({ top: 92, @@ -506,16 +530,17 @@ }) return } + } - this.setState({ - loading: true - }) + 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, '').replace(/@(BID|ID|time_id)@/ig, `'1949-10-01 15:00:00'`) + let rduri = '' if (window.GLOB.mainSystemApi && values.database === 'sso') { rduri = window.GLOB.mainSystemApi @@ -533,6 +558,62 @@ }) } }) + } 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, '\'\'') + sql = sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`) + sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`) + sql = sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`) + sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`) + + 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