From da64ab0923bf8817fc8599a6e37b953ce38f64c8 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 27 八月 2023 18:37:36 +0800 Subject: [PATCH] 2023-08-27 --- src/tabviews/zshare/mutilform/index.jsx | 164 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 139 insertions(+), 25 deletions(-) diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx index 067bfd2..e9a26ed 100644 --- a/src/tabviews/zshare/mutilform/index.jsx +++ b/src/tabviews/zshare/mutilform/index.jsx @@ -6,7 +6,6 @@ import moment from 'moment' import Api from '@/api' -import options from '@/store/options.js' import { formRule } from '@/utils/option.js' import Utils from '@/utils/utils.js' import asyncComponent from '@/utils/asyncComponent' @@ -31,7 +30,7 @@ const MkVercode = asyncComponent(() => import('./mkVercode')) const MKEditor = asyncComponent(() => import('@/components/editor')) -class MainSearch extends Component { +class MutilFormComponent extends Component { static propTpyes = { action: PropTypes.object, // 鎸夐挳淇℃伅銆佽〃鍗曞垪琛� data: PropTypes.any, // 琛ㄦ牸鏁版嵁 @@ -89,6 +88,7 @@ } else { supvals.push('') } + supvals = Array.from(new Set(supvals)) controlFields[item.supField] = controlFields[item.supField] || [] controlFields[item.supField].push({field: item.field, values: supvals}) } @@ -212,6 +212,35 @@ } if (newval === '$empty' && item.initval) { newval = moment().subtract(item.initval, 'days').format(_format) + } + + if (item.minDate) { + if (item.minDate === 'custom') { + if (/^\d{4}-\d{2}-\d{2}$/.test(item.minDateField)) { + item.minDate = moment(item.minDateField).format('YYYY-MM-DD') + } else { + let val = data[item.minDateField.toLowerCase()] + item.minDate = val ? moment(val).format('YYYY-MM-DD') : '' + } + + item.minDate = item.minDate === 'Invalid date' ? '' : item.minDate + } else { + item.minDate = moment().add(item.minDate, 'days').format('YYYY-MM-DD') + } + } + if (item.maxDate) { + if (item.maxDate === 'custom') { + if (/^\d{4}-\d{2}-\d{2}$/.test(item.maxDateField)) { + item.maxDate = moment(item.maxDateField).format('YYYY-MM-DD') + } else { + let val = data[item.maxDateField.toLowerCase()] + item.maxDate = val ? moment(val).format('YYYY-MM-DD') : '' + } + + item.maxDate = item.maxDate === 'Invalid date' ? '' : item.maxDate + } else { + item.maxDate = moment().add(item.maxDate, 'days').format('YYYY-MM-DD') + } } } else if (item.type === 'datemonth') { if (newval !== '$empty') { @@ -413,9 +442,24 @@ let cell = fieldMap.get(item.field) - // if (cell.hidden) return - - if (supItem.hidden || !item.values.includes(supItem.initval)) { + let _hidden = false + + if (supItem.hidden) { + _hidden = true + } else { + let box = [...item.values] + if (supItem.type === 'multiselect' || (supItem.type === 'checkcard' && supItem.multiple === 'true')) { + box.push(...supItem.initval.split(',')) + } else { + box.push(supItem.initval) + } + + if (box.length === Array.from(new Set(box)).length) { + _hidden = true + } + } + + if (_hidden) { cell.hidden = true if (cell.empty === 'hidden') { cell.$hidden = true @@ -465,6 +509,31 @@ }) item.options = fromJS(item.oriOptions).toJS() + } + item.linkSubField = null + } else if (item.type === 'switch' && item.linkSubField) { + item.options = [] + item.subFields = [] + item.linkSubField.forEach(m => { + let n = fieldMap.get(m) + if (n && ['text', 'number', 'textarea'].includes(n.type)) { + item.subFields.push({ + uuid: n.uuid, + field: m + }) + } + }) + + if (item.subFields.length === 0) { + item.subFields = null + } else { + reFieldsVal = reFieldsVal || {} + + let val = item.initval === item.openVal ? item.openText : item.closeText + + item.subFields.forEach(n => { + reFieldsVal[n.field] = val || '' + }) } item.linkSubField = null } @@ -541,8 +610,9 @@ } this.record = record + let ID = this.props.data ? this.props.data.$$uuid || '' : '' - this.setState({ formlist, ID: this.props.data ? this.props.data.$$uuid || '' : '' }, () => { + this.setState({ formlist, ID }, () => { if (unload) return if (action.setting && action.setting.focus && fieldMap.has(action.setting.focus)) { @@ -560,13 +630,29 @@ } if (deForms.length > 0) { - if (!window.GLOB.mkHS && options.sysType === 'local' && window.GLOB.systemType !== 'production') { - this.improveSimpleActionForm(deForms) + if (action.$cache && action.setting.cache !== 'false') { + Api.getLCacheConfig(action.uuid, action.$time, this.props.BID, ID).then(res => { + if (!res.valid) { + this.getFormData(deForms) + } else { + this.resetFormList(res.data, true) + } + }) } else { - this.improveActionForm(deForms) + this.getFormData(deForms) } } }) + } + + getFormData = (deForms) => { + if (deForms.length === 1) { + this.improveSimpleActionForm(deForms) + } else if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') { + this.improveSimpleActionForm(deForms) + } else { + this.improveActionForm(deForms) + } } /** @@ -578,8 +664,8 @@ let deffers = [] let mainItems = [] // 浜戠鎴栧崟鐐规暟鎹� let localItems = [] // 鏈湴鏁版嵁 - let cache = action.setting.cache !== 'false' - let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud') + let cache = action.setting.cache !== 'false' && !action.$cache + let skip = false 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 @@ -592,7 +678,7 @@ sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`) sql = sql.replace(/@BID@/ig, `'${BID}'`) - if (debug) { + if (window.GLOB.debugger === true) { console.info(sql) } @@ -606,7 +692,7 @@ sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`) sql = sql.replace(/@BID@/ig, `'${BID}'`) - if (debug) { + if (window.GLOB.debugger === true) { console.info(sql) } @@ -643,6 +729,7 @@ message: res.message, duration: 5 }) + skip = true } resolve(res) }) @@ -666,8 +753,8 @@ if (window.GLOB.mkHS) { // 浜戠鏁版嵁楠岃瘉 mainparam.open_key = Utils.encryptOpenKey(mainparam.secretkey, mainparam.timestamp) - if (options.cloudServiceApi) { - mainparam.rduri = options.cloudServiceApi + if (window.GLOB.cloudServiceApi) { + mainparam.rduri = window.GLOB.cloudServiceApi mainparam.userid = sessionStorage.getItem('CloudUserID') || '' mainparam.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' } @@ -684,6 +771,7 @@ message: res.message, duration: 5 }) + skip = true } resolve(res) }) @@ -699,7 +787,7 @@ delete result.message delete result.status - this.resetFormList(result) + this.resetFormList(result, skip) }) } @@ -707,9 +795,11 @@ * @description 娴嬭瘯绯荤粺鑾峰彇涓嬫媺琛ㄥ崟閫夐」淇℃伅 */ improveSimpleActionForm = (deForms) => { - let cache = this.props.action.setting.cache !== 'false' - let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud') + const { action } = this.props + + let cache = this.props.action.setting.cache !== 'false' && !action.$cache 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 skip = false let deffers = deForms.map((form, index) => { let param = { @@ -722,7 +812,7 @@ param.LText = param.LText.replace(/@ID@/ig, `'${this.state.ID || ''}'`) param.LText = param.LText.replace(/@BID@/ig, `'${this.props.BID || ''}'`) - if (debug) { + if (window.GLOB.debugger) { console.info(param.LText) } @@ -744,6 +834,7 @@ message: res.message, duration: 5 }) + skip = true } resolve(res) }) @@ -754,6 +845,7 @@ Promise.all(deffers).then(response => { let result = {} + response.forEach(res => { result = {...result, ...res} }) @@ -763,11 +855,17 @@ delete result.message delete result.status - this.resetFormList(result) + this.resetFormList(result, skip) }) } - resetFormList = (result) => { + resetFormList = (result, skip) => { + const { BID, action } = this.props + + if (action.$cache && action.setting.cache !== 'false' && !skip) { + Api.writeCacheConfig(action.uuid, fromJS(result).toJS(), BID, this.state.ID) + } + let reFieldsVal = null let _formlist = fromJS(this.state.formlist).toJS().map(item => { if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect', 'cascader'].includes(item.type) && result[item.field] && result[item.field].length > 0) { @@ -929,7 +1027,23 @@ current.controlFields.forEach(cell => { let m = map.get(cell.field) - m.hidden = current.hidden || !cell.values.includes(val) + + m.hidden = false + + if (current.hidden) { + m.hidden = true + } else { + let box = [...cell.values] + if (current.type === 'multiselect' || (current.type === 'checkcard' && current.multiple === 'true')) { + box.push(...val.split(',')) + } else { + box.push(val) + } + + if (box.length === Array.from(new Set(box)).length) { + m.hidden = true + } + } if (m.empty === 'hidden' && m.oriOptions.length === 0) { m.hidden = true @@ -1011,7 +1125,7 @@ className = 'checkcard' 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)}/>) + content = (<MKSwitch config={item} onChange={(val, other) => this.recordChange({[item.field]: val, ...other}, item)}/>) } else if (item.type === 'check') { content = (<MKCheck config={item} onChange={(val) => this.recordChange({[item.field]: val}, item)}/>) } else if (item.type === 'checkbox') { @@ -1094,7 +1208,7 @@ _item.fieldlen = item.decimal || 0 } else if (['text', 'textarea', 'linkMain'].includes(item.type)) { _item.value = _item.value + '' - _item.value = _item.value.replace(/\t*|\v*/g, '') // 鍘婚櫎鍒惰〃绗� + _item.value = _item.value.replace(/\t+|\v+/g, '') // 鍘婚櫎鍒惰〃绗� if (item.interception !== 'false') { // 鍘婚櫎棣栧熬绌烘牸 _item.value = _item.value.replace(/(^\s*|\s*$)/g, '') @@ -1171,4 +1285,4 @@ } } -export default Form.create()(MainSearch) \ No newline at end of file +export default Form.create()(MutilFormComponent) \ No newline at end of file -- Gitblit v1.8.0