From 7b0dbecd1d6155d26ec67be0a47a16264c738c85 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 09 五月 2023 14:48:10 +0800 Subject: [PATCH] 2023-05-09 --- src/tabviews/zshare/mutilform/index.jsx | 212 +++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 175 insertions(+), 37 deletions(-) diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx index d60164b..f6f2a1c 100644 --- a/src/tabviews/zshare/mutilform/index.jsx +++ b/src/tabviews/zshare/mutilform/index.jsx @@ -19,6 +19,7 @@ const MKCheckCard = asyncComponent(() => import('./mkCheckCard')) const MKSwitch = asyncComponent(() => import('./mkSwitch')) +const MKCheck = asyncComponent(() => import('./mkCheck')) const MKCheckbox = asyncComponent(() => import('./mkCheckbox')) const MKRadio = asyncComponent(() => import('./mkRadio')) const MKDatePicker = asyncComponent(() => import('./mkDatePicker')) @@ -27,6 +28,7 @@ const MKColor = asyncComponent(() => import('./mkColor')) const MkFormula = asyncComponent(() => import('./mkFormula')) const MkCascader = asyncComponent(() => import('./mkCascader')) +const MkVercode = asyncComponent(() => import('./mkVercode')) const MKEditor = asyncComponent(() => import('@/components/editor')) class MainSearch extends Component { @@ -35,17 +37,22 @@ data: PropTypes.any, // 琛ㄦ牸鏁版嵁 BID: PropTypes.any, // 涓昏〃ID BData: PropTypes.any, // 涓昏〃鏁版嵁 + unload: PropTypes.any, // 涓嬫媺鑿滃崟涓嶅姞杞芥暟鎹� inputSubmit: PropTypes.func // input鍥炶溅鎻愪氦 } state = { formlist: [], // 琛ㄥ崟椤� + ID: '', + send_type: '', + timestamp: '', + n_id: '' } record = {} componentDidMount () { - const { action } = this.props + const { action, unload } = this.props let data = {} let BData = {} @@ -98,6 +105,12 @@ delete item.style.marginRight } + if (item.type === 'split' && item.splitctrl) { + if (data.hasOwnProperty(item.splitctrl.toLowerCase()) && data[item.splitctrl.toLowerCase()] === '') { + return false + } + } + if (item.type === 'split' || item.type === 'formula') return true if (item.type === 'hint') { if (item.field && data[item.field.toLowerCase()]) { @@ -105,18 +118,20 @@ } delete item.field return true - } else if (item.type === 'date') { // 鏃堕棿鎼滅储 + } else if (item.type === 'date') { item.precision = item.precision || 'day' } else if (item.type === 'datetime') { item.type = 'date' item.precision = 'second' } - if (!item.field || !['text', 'number', 'switch', 'rate', 'select', 'link', 'cascader', 'linkMain', 'funcvar', 'date', 'datemonth', 'radio', 'checkbox', 'checkcard', 'fileupload', 'textarea', 'multiselect', 'brafteditor', 'color'].includes(item.type)) return false + if (!item.field || !['text', 'number', 'switch', 'check', 'rate', 'select', 'link', 'cascader', 'linkMain', 'funcvar', 'date', 'datemonth', 'radio', 'checkbox', 'checkcard', 'fileupload', 'textarea', 'multiselect', 'brafteditor', 'color', 'vercode'].includes(item.type)) return false if (/^\s+$/.test(item.label)) { item.style = item.style || {} - item.style.color = 'transparent' + item.style.opacity = 0 + item.style.width = 1 + item.style.display = 'inline-block' } // 鏁版嵁鑷姩濉厖 @@ -159,6 +174,23 @@ }) } item.oriOptions = fromJS(item.options).toJS() + + if (item.empty === 'hidden' && item.oriOptions.length === 0) { + item.hidden = true + } + if (item.type === 'checkcard' && item.readonly && item.unchecked === 'hidden') { + let selectKeys = item.initval + if (item.multiple === 'true') { + selectKeys = selectKeys ? selectKeys.split(',') : [] + item.options = item.options.filter(item => selectKeys.includes(item.$value)) + } else { + item.options = item.options.filter(item => selectKeys === item.$value) + } + item.oriOptions = fromJS(item.options).toJS() + if (item.options.length === 0) { + item.hidden = true + } + } } let newval = '$empty' @@ -189,7 +221,7 @@ if (newval === '$empty' && item.initval) { newval = moment().subtract(item.initval, 'month').format('YYYY-MM') } - } else if (item.type === 'switch') { // 寮�鍏冲彧鎺ユ敹鍥哄畾鍊� + } else if (item.type === 'switch' || item.type === 'check') { // 寮�鍏冲嬀閫夋鍙帴鏀跺浐瀹氬�� if (newval !== '$empty' && (newval === item.closeVal || newval === item.openVal)) { } else if (item.initval === true) { @@ -300,7 +332,7 @@ }) } else if (item.regular === 'email') { _rules.push({ - pattern: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/, + pattern: /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/, message: item.regularText || '璇锋纭緭鍏ラ偖绠卞湴鍧�' }) } @@ -349,7 +381,7 @@ message: formRule.input.formMessage.replace('@max', item.fieldlength) } ] - } else if (item.type === 'linkMain') { + } else if (item.type === 'linkMain' || item.type === 'vercode') { item.rules = [ { required: item.required === 'true', @@ -381,10 +413,13 @@ let cell = fieldMap.get(item.field) - if (cell.hidden) return - + // if (cell.hidden) return + if (supItem.hidden || !item.values.includes(supItem.initval)) { cell.hidden = true + if (cell.empty === 'hidden') { + cell.$hidden = true + } fieldMap.set(item.field, cell) } @@ -447,17 +482,19 @@ item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal || option.value === '') } - if (['select', 'link', 'radio'].includes(item.type) && item.resourceType === '0') { // 閫変腑绗竴椤� - if (typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) { - item.initval = item.options[0] ? item.options[0].value : '' + if (['select', 'link', 'radio'].includes(item.type)) { // 閫変腑绗竴椤� + if (/^\s*\$first\s*$/.test(item.initval)) { + item.$first = true + item.initval = '' + } + if (item.resourceType === '0') { // 閫変腑绗竴椤� + if (item.$first) { + item.initval = item.options[0] ? item.options[0].value : '' + } } } - if (typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) { - record[item.field] = '' - } else { - record[item.field] = item.initval - } + record[item.field] = item.initval if (linkFields[item.field]) { item.linkFields = linkFields[item.field] @@ -505,7 +542,9 @@ this.record = record - this.setState({ formlist }, () => { + this.setState({ formlist, ID: this.props.data ? this.props.data.$$uuid || '' : '' }, () => { + if (unload) return + if (action.setting && action.setting.focus && fieldMap.has(action.setting.focus)) { setTimeout(() => { MKEmitter.emit('mkFC', 'focus', fieldMap.get(action.setting.focus).uuid) @@ -532,12 +571,34 @@ let mainItems = [] // 浜戠鎴栧崟鐐规暟鎹� let localItems = [] // 鏈湴鏁版嵁 let cache = action.setting.cache !== 'false' + let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud') + + let _sql = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20) select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n` + let _sso = _sql deForms.forEach(item => { if (item.database === 'sso') { - mainItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`) + let sql = _sso + item.base_sql + _sso = '' + + sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`) + sql = sql.replace(/@BID@/ig, `'${BID}'`) + + if (debug) { + console.info(sql) + } + mainItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`) } else { - localItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`) + let sql = _sql + item.base_sql + _sql = '' + + sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`) + sql = sql.replace(/@BID@/ig, `'${BID}'`) + + if (debug) { + console.info(sql) + } + localItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`) } }) @@ -547,8 +608,7 @@ LText: localItems.join(' union all '), obj_name: '', arr_field: '', - table_type: 'Y', - BID: BID || '' + table_type: 'Y' } if (param.LText) { @@ -582,8 +642,7 @@ LText: mainItems.join(' union all '), obj_name: '', arr_field: '', - table_type: 'Y', - BID: BID || '' + table_type: 'Y' } if (mainparam.LText) { @@ -635,16 +694,25 @@ */ improveSimpleActionForm = (deForms) => { let cache = this.props.action.setting.cache !== 'false' + let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud') + let _sql = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20) select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n` let deffers = deForms.map((form, index) => { let param = { func: 'sPC_Get_SelectedList', - LText: form.data_sql, + LText: _sql + form.base_sql, obj_name: form.field, - arr_field: form.arr_field, - BID: this.props.BID || '' + arr_field: form.arr_field + } + + param.LText = param.LText.replace(/@ID@/ig, `'${this.state.ID || ''}'`) + param.LText = param.LText.replace(/@BID@/ig, `'${this.props.BID || ''}'`) + + if (debug) { + console.info(param.LText) } + param.LText = Utils.formatOptions(param.LText) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) @@ -691,6 +759,7 @@ if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect', 'cascader'].includes(item.type) && result[item.field] && result[item.field].length > 0) { let options = [] let map = new Map() + let all = false result[item.field].forEach(cell => { let _cell = { key: Utils.getuuid() , ParentID: ''} @@ -701,12 +770,26 @@ if (item.type !== 'checkcard') { _cell.value = cell[item.valueField] _cell.label = cell[item.valueText] + '' - if (!_cell.label || map.has(_cell.ParentID + _cell.value)) return + if (map.has(_cell.ParentID + _cell.value)) return + if (!_cell.label) { + if (!all) { + _cell.label = '鍏ㄩ儴' + all = true + } else { + return + } + } map.set(_cell.ParentID + _cell.value, 0) } else { _cell.$value = cell[item.cardValField] _cell = {..._cell, ...cell} + + if (item.urlField) { + _cell.$url = cell[item.urlField] || '' + } else if (item.colorField) { + _cell.$color = cell[item.colorField] || '' + } if (map.has(_cell.ParentID + _cell.$value)) return @@ -736,7 +819,7 @@ item.options = item.oriOptions } - if (['select', 'link', 'radio'].includes(item.type) && typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) { // 閫変腑绗竴椤� + if (['select', 'link', 'radio'].includes(item.type) && item.$first) { // 閫変腑绗竴椤� item.initval = item.options[0] ? item.options[0].value : '' this.record[item.field] = item.initval } @@ -754,6 +837,25 @@ item.subFields.forEach(n => { reFieldsVal[n.field] = option[n.field] }) + } + } + + if (item.empty === 'hidden' && item.oriOptions.length > 0 && !item.$hidden) { + item.hidden = false + } + if (item.type === 'checkcard' && item.readonly && item.unchecked === 'hidden') { + let selectKeys = item.initval + if (item.multiple === 'true') { + selectKeys = selectKeys ? selectKeys.split(',') : [] + item.options = item.options.filter(item => selectKeys.includes(item.$value)) + } else { + item.options = item.options.filter(item => selectKeys === item.$value) + } + item.oriOptions = fromJS(item.options).toJS() + if (item.options.length === 0) { + item.hidden = true + } else { + item.hidden = false } } } @@ -814,6 +916,10 @@ current.controlFields.forEach(cell => { let m = map.get(cell.field) m.hidden = current.hidden || !cell.values.includes(val) + + if (m.empty === 'hidden' && m.oriOptions.length === 0) { + m.hidden = true + } if (m.hidden) { m.initval = this.record[m.field] @@ -892,6 +998,8 @@ content = (<MKCheckCard config={item} onChange={(val, other) => this.recordChange({[item.field]: val, ...other}, item)}/>) } else if (item.type === 'switch') { content = (<MKSwitch config={item} onChange={(val) => this.recordChange({[item.field]: val}, item)}/>) + } else if (item.type === 'check') { + content = (<MKCheck config={item} onChange={(val) => this.recordChange({[item.field]: val}, item)}/>) } else if (item.type === 'checkbox') { content = (<MKCheckbox config={item} onChange={(val) => this.recordChange({[item.field]: val})}/>) } else if (item.type === 'radio') { @@ -906,6 +1014,8 @@ content = (<MKTextArea config={item} onChange={(val, defer) => !defer && this.recordChange({[item.field]: val})}/>) } else if (item.type === 'rate') { content = (<Rate count={item.rateCount} disabled={item.readonly} style={{color: item.color || '#fadb14'}} onChange={(val) => this.recordChange({[item.field]: val})} character={item.character ? <MkIcon type={item.character}/> : <StarFilled />} allowHalf={item.allowHalf}/>) + } else if (item.type === 'vercode') { + content = (<MkVercode config={item} record={this.record} onSend={(send_type, timestamp, n_id) => this.setState({send_type, timestamp, n_id})} onChange={(val) => this.recordChange({[item.field]: val})} onSubmit={this.props.inputSubmit}/>) } else if (item.type === 'brafteditor') { content = (<MKEditor config={item} onChange={(val) => this.recordChange({[item.field]: val})}/>) label = item.hidelabel !== 'true' ? label : '' @@ -937,7 +1047,7 @@ } handleConfirm = () => { - const { formlist } = this.state + const { formlist, send_type, timestamp, n_id } = this.state // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� return new Promise((resolve, reject) => { @@ -946,7 +1056,7 @@ reject(err) return } - let search = [] + let forms = [] let record = {...this.record, ...values} formlist.forEach(item => { @@ -984,16 +1094,44 @@ _item.value = _item.value.slice(-item.fieldlength) } } - } else if (item.type.indexOf('date') > -1) { - if (item.declareType === 'nvarchar(50)') { - _item.type = 'text' - } + } else if (item.type === 'datemonth') { + _item.type = 'text' + } else if (item.type === 'date') { + _item.type = item.declareType === 'nvarchar(50)' ? 'text' : 'date' + } else if (item.type === 'vercode') { + _item.type = 'text' + forms.push({ + type: 'text', + readin: false, + writein: false, + fieldlen: 50, + key: 'mk_timestamp', + value: timestamp || '' + }) + + forms.push({ + type: 'text', + readin: false, + writein: false, + fieldlen: 50, + key: 'mk_send_type', + value: send_type || '' + }) + + forms.push({ + type: 'text', + readin: false, + writein: false, + fieldlen: 50, + key: 'mk_n_id', + value: n_id || '' + }) } - search.push(_item) + forms.push(_item) }) - resolve(search) + resolve(forms) }) }) } -- Gitblit v1.8.0