diff --git a/src/resources/plugins/TsSheet/form-edit.vue b/src/resources/plugins/TsSheet/form-edit.vue index c1df61859ade569de6286614ad00175210916281..544c08959a507af43404f916c0f4586bd0969e05 100644 --- a/src/resources/plugins/TsSheet/form-edit.vue +++ b/src/resources/plugins/TsSheet/form-edit.vue @@ -821,7 +821,7 @@ export default { }, changeVersion(uuid, text) { //改变版本时触发事件 - let formConfig = this.$refs.sheet.getFormConfig(); + let formConfig = this.$refs.sheet && this.$refs.sheet.getFormConfig(); this.currentFormItem = null; if (this.compareData(this.initFormConfig, formConfig)) { //数据没有变化时直接导出 diff --git a/src/resources/plugins/TsSheet/form/component/formtableinputer/condition-mixin.js b/src/resources/plugins/TsSheet/form/component/formtableinputer/condition-mixin.js new file mode 100644 index 0000000000000000000000000000000000000000..90f1d060718bd42b15bba232c314fe0f031c36ae --- /dev/null +++ b/src/resources/plugins/TsSheet/form/component/formtableinputer/condition-mixin.js @@ -0,0 +1,76 @@ +import { EXPRESSIONS } from '@/resources/plugins/TsSheet/form/conditionexpression/index.js'; +export default { + data() { + return { + EXPRESSIONS: EXPRESSIONS, + conditionMap: {} + }; + }, + methods: { + executeReaction(reaction, newFormData, oldFormData) { + let script = ''; + if (reaction && !this.$utils.isEmpty(reaction)) { + const conditionGroupRelList = reaction['conditionGroupRelList']; + const conditinoGroupList = reaction['conditionGroupList']; + if (conditinoGroupList && conditinoGroupList.length > 0) { + for (let i = 0; i < reaction['conditionGroupList'].length; i++) { + const conditionGroup = reaction['conditionGroupList'][i]; + if (i > 0 && conditionGroupRelList && conditionGroupRelList.length > 0) { + if (conditionGroupRelList.length >= i) { + const joinType = conditionGroupRelList[i - 1]; + script += joinType === 'and' ? ' && ' : ' || '; + } else { + //数据异常跳出 + break; + } + } + script += '('; + const conditionList = conditionGroup['conditionList']; + const conditionRelList = conditionGroup['conditionRelList']; + if (conditionList && conditionList.length > 0) { + let cScript = ''; + for (let j = 0; j < conditionList.length; j++) { + if (j > 0 && conditionRelList && conditionRelList.length > 0) { + if (conditionRelList.length >= j) { + const cJoinType = conditionRelList[j - 1]; + cScript += cJoinType === 'and' ? ' && ' : ' || '; + } else { + //数据异常跳出 + break; + } + } + const condition = conditionList[j]; + const uuidList = condition['formItemUuid'].split('#'); + const formItemUuid = uuidList[0]; + this.conditionMap[condition['uuid']] = condition; + cScript += '('; + cScript += 'this.EXPRESSIONS["' + condition['expression'] + '"](this.newFormData.hasOwnProperty("' + formItemUuid + '")?this.newFormData["' + formItemUuid + '"]:null, this.oldFormData.hasOwnProperty("' + formItemUuid + '")?this.oldFormData["' + formItemUuid + '"]:null, this.conditionData("' + condition['uuid'] + '"))'; + cScript += ')'; + } + script += cScript; + } + script += ')'; + } + } + } + if (script) { + const context = {}; + context.newFormData = newFormData || {}; + context.oldFormData = oldFormData || {}; + context.conditionData = this.conditionData; + context.EXPRESSIONS = this.EXPRESSIONS; + const fuc = new Function('return ' + script).bind(context); + return fuc(); + } + return true; + } + + }, + computed: { + conditionData() { + return (uuid) => { + return this.conditionMap[uuid] || {}; + }; + } + } +}; diff --git a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue index 338519e50728c2c9281a23874e479fb17ffcc77e..bd828f01be4630ab1030f06b32b6be4db9de1d78 100644 --- a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue +++ b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue @@ -1,10 +1,10 @@