From 5d1e75389058c617f64583065f81bc0bb07de67e Mon Sep 17 00:00:00 2001 From: dengbf Date: Thu, 17 Jul 2025 09:57:39 +0800 Subject: [PATCH 1/6] =?UTF-8?q?-=20[=E5=85=B3=E8=81=94]#[1466790037651456]?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=EF=BC=9A=E8=A1=A8=E6=A0=BC=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5=20http://192.168.0.96:8090?= =?UTF-8?q?/demo/rdm.html#/story-detail/939050947543040/939050947543042/14?= =?UTF-8?q?66790037651456?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formtableinputer/condition-mixin.js | 76 +++++++ .../form/component/formtableinputer/index.vue | 204 ++++++++++++++---- 2 files changed, 243 insertions(+), 37 deletions(-) create mode 100644 src/resources/plugins/TsSheet/form/component/formtableinputer/condition-mixin.js 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 00000000..90f1d060 --- /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 9c39f908..4ebb72bc 100644 --- a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue +++ b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue @@ -4,7 +4,7 @@
-
+
@@ -107,7 +111,7 @@ import validmixin from '../common/validate-mixin.js'; import TsTable from '@/resources/components/TsTable/TsTable.vue'; //不能使用异步引入,会导致tssheet列高错位 import ExcelJS from 'exceljs'; import FileSaver from 'file-saver'; - +import conditionMixin from './condition-mixin.js'; export default { name: '', components: { @@ -115,7 +119,7 @@ export default { FormItem: () => import('@/resources/plugins/TsSheet/form-item.vue') }, extends: base, - mixins: [validmixin], + mixins: [validmixin, conditionMixin], props: { readonly: { type: Boolean, default: false }, disabled: { type: Boolean, default: false } @@ -125,14 +129,23 @@ export default { loadingShow: true, isTableSelectorDialogShow: false, selectedIndexList: [], - tableData: { theadList: [], tbodyList: [] }, rowFormItem: {}, //保存每行的定义数据,避免每次都deepClone新数据,导致reaction失效 maxSize: 1024 * 10, isShowExportExcelTemplate: true, isShowExportExcel: true, loading: false, filterComponentList: ['formtableselector', 'formtableinputer', 'formsubassembly', 'formupload', 'formcube', 'formtable', 'formresoureces', 'formprotocol'], //过滤不参与规则的组件 - initExternalData: {} //用于对比外部组件值变换 + initExternalData: {}, //用于对比外部组件值变换 + tablePageConfig: { //table分页配置 + currentPage: 1, + pageSize: 5, + rowNum: 0, + pageSizeOpts: [5, 10, 15, 20, 50, 100], + defaultShowSize: 5 + }, + theadList: [], + tbodyList: [], + validateMap: {} }; }, beforeCreate() {}, @@ -183,7 +196,7 @@ export default { } } if (value.length > 0) { - this.tableData.tbodyList.push(...value); + this.tbodyList.push(...value); } } else if (this.config.lineNumber) { //默认展示行 @@ -196,9 +209,9 @@ export default { this.selectedIndexList = indexList; }, deleteItem(row) { - const index = this.tableData.tbodyList.findIndex(d => d.uuid === row.uuid); + const index = this.tbodyList.findIndex(d => d.uuid === row.uuid); if (index > -1) { - this.tableData.tbodyList.splice(index, 1); + this.tbodyList.splice(index, 1); } }, addRow(index) { @@ -209,13 +222,13 @@ export default { } }); Object.assign(data, this.initExternalData); - this.tableData.tbodyList.splice(index + 1, 0, data); + this.tbodyList.splice(index + 1, 0, data); }, removeSelectedItem() { - for (let i = this.tableData.tbodyList.length - 1; i >= 0; i--) { - const item = this.tableData.tbodyList[i]; + for (let i = this.tbodyList.length - 1; i >= 0; i--) { + const item = this.tbodyList[i]; if (item._selected) { - this.tableData.tbodyList.splice(i, 1); + this.tbodyList.splice(i, 1); } } }, @@ -227,7 +240,7 @@ export default { } }); Object.assign(data, this.initExternalData); - this.tableData.tbodyList.push(data); + this.tbodyList.unshift(data); }, validConfig() { const errorList = []; @@ -309,7 +322,7 @@ export default { } } } - return [...errorList, ...this.validAttrUnique()]; + return [...this.validTable(), ...this.validAttrUnique()]; }, validAttrUnique() { // 校验属性是否唯一 @@ -320,7 +333,7 @@ export default { const uniqueRuleList = dataConfig.filter(v => v.config && v.config['isUnique']); if (!this.$utils.isEmpty(uniqueRuleList)) { let existMap = {}; - this.tableData.tbodyList.forEach(row => { + this.tbodyList.forEach(row => { if (!this.$utils.isEmpty(row)) { Object.keys(row).forEach(key => { const findUnunique = uniqueRuleList.find(d => d.uuid === key); @@ -344,7 +357,7 @@ export default { .join(','); let tempValue = ''; let existList = []; - this.tableData.tbodyList.forEach(row => { + this.tbodyList.forEach(row => { if (!this.$utils.isEmpty(row)) { tempValue = ''; Object.keys(row).forEach((key, index) => { @@ -370,8 +383,8 @@ export default { } }, updateRowSort(event) { - let beforeVal = this.tableData.tbodyList.splice(event.oldIndex, 1)[0]; - this.tableData.tbodyList.splice(event.newIndex, 0, beforeVal); + let beforeVal = this.tbodyList.splice(event.oldIndex, 1)[0]; + this.tbodyList.splice(event.newIndex, 0, beforeVal); }, async exportExcelTemplate() { // 导出excel模板 @@ -381,7 +394,7 @@ export default { // 设置表头 let theadList = []; let theadUuidList = []; - this.tableData.theadList.forEach(item => { + this.theadList.forEach(item => { if (item?.key && item?.title) { if (item.key != 'number' && !this.handleExcludeTable(item.key)) { // 序号是否需要显示 @@ -515,7 +528,7 @@ export default { const _sheet1 = _workbook.addWorksheet('sheet1'); // 添加工作表 let columnsList = []; let theadUuidList = []; // 获取所有表头的uuid列表 - this.tableData.theadList.forEach(item => { + this.theadList.forEach(item => { if (item?.key && item?.title) { if (item.key != 'number' && !this.handleExcludeTable(item.key)) { columnsList.push({ @@ -543,7 +556,7 @@ export default { wrapText: true // 单元格自动换行 }; }); - let tbodyList = this.$utils.deepClone(this.tableData.tbodyList); + let tbodyList = this.$utils.deepClone(this.tbodyList); if (this.selectedIndexList.length > 0) { // 选中行导出 tbodyList = tbodyList.filter((v, index) => this.selectedIndexList.includes(index)); @@ -674,8 +687,8 @@ export default { let rowValue = {}; const rowValuesList = this.$utils.deepClone(row.values).slice(1); // 删除第一列序号 let tbodyIndex = rowIndex - 2; - let tbodyRow = this.tableData.tbodyList[tbodyIndex]; - let theadList = this.tableData.theadList.filter(v => v.key != 'selection' && v.key != 'number'); + let tbodyRow = this.tbodyList[tbodyIndex]; + let theadList = this.theadList.filter(v => v.key != 'selection' && v.key != 'number'); let matrixSearchParamsList = []; for (let tIndex = 0; tIndex < theadList.length; tIndex++) { let theadKey = theadList[tIndex].key; @@ -703,10 +716,10 @@ export default { let item = { ...(tbodyRow || {}), ...rowValue }; if (!this.$utils.isEmpty(tbodyRow)) { // 不为空时,修改数组对象里面的值 - this.tableData.tbodyList.splice(tbodyIndex, 1, item); + this.tbodyList.splice(tbodyIndex, 1, item); } else { // 空数组时,新增一条新的数据 - this.tableData.tbodyList.push({ ...item, uuid: this.$utils.setUuid() }); + this.tbodyList.push({ ...item, uuid: this.$utils.setUuid() }); } }); }); @@ -852,6 +865,83 @@ export default { delete formData[this.formItem.uuid]; } return formData; + }, + changeCurrent(currentPage) { + this.tablePageConfig.currentPage = currentPage; + this.$nextTick(() => { + this.validData(); + }); + }, + changePageSize(pageSize) { + this.tablePageConfig.currentPage = 1; + this.tablePageConfig.pageSize = pageSize; + }, + validTable() { //验证表格数据 + let errorList = []; + if (!this.readonly && !this.disabled && !this.$utils.isEmpty(this.tbodyList)) { + this.tbodyList.forEach((d, index) => { + if (this.validateMap) { + this.theadList.forEach(th => { + const key = th.key; + let isValid = true; + if (!this.readonly && !this.disabled && this.validateMap && this.validateMap[key]) { + const validateList = this.validateMap[key].validateList; + if (!this.$utils.isEmpty(validateList)) { + isValid = this.$utils.validParamValue(d[key], validateList); + } + if (!isValid) { + const pageCount = Math.ceil((index + 1) / this.tablePageConfig.pageSize); + const errItem = errorList.find(d => d.label === this.validateMap[key].label); + if (!errItem) { + errorList.push({ + errorPageList: [pageCount], + label: this.validateMap[key].label, + uuid: this.formItem.key, + error: this.formItem.label + ':第' + pageCount + '页' + this.$t('message.completerequired', {'target': '【' + this.validateMap[key].label + '】'}) + }); + } else { + if (!errItem.errorPageList.find(d => d === pageCount)) { + errItem.errorPageList.push(pageCount); + errItem.errorPageList = errItem.errorPageList.sort(this.$utils.sortNumber()); + errItem.error = this.formItem.label + ':第' + errItem.errorPageList.join(',') + '页' + this.$t('message.completerequired', {'target': '【' + this.validateMap[key].label + '】'}); + } + } + } + if (!this.$utils.isEmpty(th.reaction)) { + const data = Object.assign({}, this.formData || {}, d); + this.vallidReaction(th.reaction, data); + } + } + }); + } + }); + } + return errorList; + }, + isValidRegex(regexString) { //判断正则表达式是否合法 + try { + new RegExp(regexString); + return true; + } catch (error) { + return false; + } + }, + vallidReaction(reaction, formData) { + let reactionMap = { + isHide: false, + isDisabled: false, + isReadOnly: false, + isRequired: false, + isMask: false + }; + for (let key in reaction) { + const reactionObj = reaction[key]; + if (!this.$utils.isEmpty(reactionObj)) { + console.log(formData); + const result = this.executeReaction(reactionObj, formData, {}, reaction); + console.log(result, key); + } + } } }, filter: {}, @@ -873,41 +963,81 @@ export default { }, showTable() { const { hideHeaderWhenDataEmpty = false } = this.config || {}; - const { tbodyList = [] } = this.tableData || {}; + const tbodyList = this.tbodyList || []; return hideHeaderWhenDataEmpty ? tbodyList.length > 0 : true; + }, + pagedTbodyList() { + this.tablePageConfig.rowNum = this.tbodyList.length; + const start = (this.tablePageConfig.currentPage - 1) * this.tablePageConfig.pageSize; + const end = start + this.tablePageConfig.pageSize; + if (this.tbodyList.length <= start) { + return []; + } + return this.tbodyList.slice(start, end); } }, watch: { 'config.dataConfig': { handler: function(val) { - this.tableData.theadList = []; + this.theadList = []; + this.validateMap = {}; if (!this.disabled && !this.readonly) { if (!this.config.hasOwnProperty('isCanAdd') || this.config.isCanAdd) { - this.tableData.theadList.push({ key: 'delete', width: 20 }); - this.tableData.theadList.push({ key: 'selection' }); + this.theadList.push({ key: 'delete', width: 20 }); + this.theadList.push({ key: 'selection' }); } } if (this.config.isShowNumber) { - this.tableData.theadList.push({ key: 'number', title: this.$t('page.ordernumber') }); + this.theadList.push({ key: 'number', title: this.$t('page.ordernumber') }); } this.config.dataConfig.forEach(d => { if (d.isPC) { let item = { key: d.uuid, - title: d.label + title: d.label, + reaction: d.reaction }; - if (d.config && d.config.isRequired) { - this.$set(item, 'isRequired', true); + if (d.config) { + let validateList = []; + if (d.config.isRequired) { + this.$set(item, 'isRequired', true); + validateList.push('required'); + } + if (!this.readonly && !this.disabled) { + if (!this.$utils.isEmpty(d.config.validate)) { + validateList.push(d.config.validate); + } + if (!this.$utils.isEmpty(d.config.regex) && this.isValidRegex(d.config.regex)) { + let findRegex = validateList.find(item => item && item.name === 'regex'); + if (findRegex) { + this.$set(findRegex, 'pattern', d.config.regex); + this.$set(findRegex, 'message', d.config.regexMessage); + } else { + validateList.push({ + name: 'regex', + pattern: d.config.regex, + message: d.config.regexMessage + }); + } + } + if (!this.$utils.isEmpty(validateList)) { + this.validateMap[d.uuid] = { + label: d.label, + validateList: validateList + }; + } + } } - this.tableData.theadList.push(item); + this.theadList.push(item); } }); + console.log(this.validateMap); this.$emit('resize'); }, deep: true, immediate: true }, - 'tableData.tbodyList': { + tbodyList: { handler: function(val) { this.setValue(val); }, -- Gitee From 8cf86315403dd3379ecb432b19f06f3ebb34082d Mon Sep 17 00:00:00 2001 From: dengbf Date: Mon, 21 Jul 2025 17:39:05 +0800 Subject: [PATCH 2/6] =?UTF-8?q?-=20[=E5=85=B3=E8=81=94]=20#[14667900376514?= =?UTF-8?q?56]=E8=A1=A8=E5=8D=95=EF=BC=9A=E8=A1=A8=E6=A0=BC=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5=20http://192.168.?= =?UTF-8?q?0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947?= =?UTF-8?q?543042/1466790037651456?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/plugins/TsSheet/form-edit.vue | 2 +- .../form/component/formtableinputer/index.vue | 214 +++++++++++------- 2 files changed, 138 insertions(+), 78 deletions(-) diff --git a/src/resources/plugins/TsSheet/form-edit.vue b/src/resources/plugins/TsSheet/form-edit.vue index c1df6185..544c0895 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/index.vue b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue index 4ebb72bc..9bb7af1c 100644 --- a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue +++ b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue @@ -301,7 +301,7 @@ export default { return errorList; }, async validData() { - const errorList = []; + //当前页校验样式 if (this.$refs) { for (let name in this.$refs) { if (name.startsWith('formitem_')) { @@ -313,16 +313,13 @@ export default { formitem = this.$refs[name]; } if (formitem) { - const err = await formitem.validData(); - if (err && err.length > 0) { - errorList.push(...err); - } + await formitem.validData(); } } } } } - return [...this.validTable(), ...this.validAttrUnique()]; + return [...this.validTbodyList(), ...this.validAttrUnique()]; }, validAttrUnique() { // 校验属性是否唯一 @@ -339,7 +336,7 @@ export default { const findUnunique = uniqueRuleList.find(d => d.uuid === key); if (findUnunique && row[key]) { if (existMap[key] && existMap[key].includes(row[key])) { - errorList.push({ uuid: this.formItem.uuid, error: `属性唯一:${findUnunique.label}必须唯一` }); + errorList.push({ uuid: this.formItem.uuid, error: `${this.formItem.label}:【${findUnunique.label}】属性必须唯一` }); } else { existMap[key] = existMap[key] ? [...existMap[key], row[key]] : [row[key]]; } @@ -367,7 +364,7 @@ export default { }); if (tempValue) { if (existList.includes(tempValue)) { - errorList.push({ uuid: uniqueRuleConfig[0], error: `属性唯一:${attrLabel}必须唯一` }); + errorList.push({ uuid: uniqueRuleConfig[0], error: `${this.formItem.label}:【${attrLabel}】属性必须唯一` }); } else { existList.push(tempValue); } @@ -876,48 +873,79 @@ export default { this.tablePageConfig.currentPage = 1; this.tablePageConfig.pageSize = pageSize; }, - validTable() { //验证表格数据 + validTbodyList() { //验证表格数据 let errorList = []; if (!this.readonly && !this.disabled && !this.$utils.isEmpty(this.tbodyList)) { - this.tbodyList.forEach((d, index) => { - if (this.validateMap) { - this.theadList.forEach(th => { - const key = th.key; - let isValid = true; - if (!this.readonly && !this.disabled && this.validateMap && this.validateMap[key]) { - const validateList = this.validateMap[key].validateList; - if (!this.$utils.isEmpty(validateList)) { - isValid = this.$utils.validParamValue(d[key], validateList); - } - if (!isValid) { - const pageCount = Math.ceil((index + 1) / this.tablePageConfig.pageSize); - const errItem = errorList.find(d => d.label === this.validateMap[key].label); - if (!errItem) { - errorList.push({ - errorPageList: [pageCount], - label: this.validateMap[key].label, - uuid: this.formItem.key, - error: this.formItem.label + ':第' + pageCount + '页' + this.$t('message.completerequired', {'target': '【' + this.validateMap[key].label + '】'}) + this.tbodyList.forEach((row, index) => { + const pageCount = Math.ceil((index + 1) / this.tablePageConfig.pageSize); + const data = Object.assign({}, this.formData || {}, row); + this.theadList.forEach(th => { + const reactionValid = this.validReaction(th.reaction, data); + if (!this.readonly && !this.disabled && !reactionValid.isDisable) { + errorList = this.getErrorList(row, data, pageCount, th, errorList); + } + }); + + Object.keys(row).forEach(key => { + let err = []; + const findThead = this.theadList.find(th => th.key === key); + if (findThead && findThead.config && !this.$utils.isEmpty(findThead.config.dataConfig)) { + if (!this.$utils.isEmpty(row[key])) { + for (let i = 0; i < row[key].length; i++) { + let item = row[key][i]; + if (this.$utils.isEmpty(err)) { + findThead.config.dataConfig.forEach(dc => { + const dValue = Object.assign({}, data, item); + const dcItem = { + key: dc.uuid, + title: dc.label, + reaction: dc.reaction + }; + err.push(...this.getErrorList(item, dValue, pageCount, dcItem)); + errorList = this.getErrorList(item, dValue, pageCount, dcItem, errorList); }); } else { - if (!errItem.errorPageList.find(d => d === pageCount)) { - errItem.errorPageList.push(pageCount); - errItem.errorPageList = errItem.errorPageList.sort(this.$utils.sortNumber()); - errItem.error = this.formItem.label + ':第' + errItem.errorPageList.join(',') + '页' + this.$t('message.completerequired', {'target': '【' + this.validateMap[key].label + '】'}); - } + break; } } - if (!this.$utils.isEmpty(th.reaction)) { - const data = Object.assign({}, this.formData || {}, d); - this.vallidReaction(th.reaction, data); - } } - }); - } + } + }); }); } return errorList; }, + getErrorList(row, data, pageCount, th, defaultErrorList) { + const key = th.key; + const reactionValid = this.validReaction(th.reaction, data); + let isValid = true; + let errorList = defaultErrorList || []; + if (this.validateMap && this.validateMap[key]) { + const validateList = this.validateMap[key].validateList; + if (!this.$utils.isEmpty(validateList)) { + isValid = this.$utils.validParamValue(row[key], validateList); + } + } + if (!isValid || (this.$utils.isEmpty(row[th.key]) && reactionValid.isRequired)) { + let findItem = errorList.find(d => d.attrUuid === th.key); + if (!findItem) { + errorList.push({ + errorPageList: [pageCount], + label: th.title, + uuid: this.formItem.key, + attrUuid: th.key, + error: this.formItem.label + ':第' + pageCount + '页' + this.$t('message.completerequired', {'target': '【' + th.title + '】'}) + }); + } else { + if (!findItem.errorPageList.find(d => d === pageCount)) { + findItem.errorPageList.push(pageCount); + findItem.errorPageList = findItem.errorPageList.sort(this.$utils.sortNumber()); + findItem.error = this.formItem.label + ':第' + findItem.errorPageList.join(',') + '页' + this.$t('message.completerequired', {'target': '【' + th.title + '】'}); + } + } + } + return errorList; + }, isValidRegex(regexString) { //判断正则表达式是否合法 try { new RegExp(regexString); @@ -926,20 +954,70 @@ export default { return false; } }, - vallidReaction(reaction, formData) { + validReaction(reaction, formData) { //规则必填校验 let reactionMap = { - isHide: false, - isDisabled: false, - isReadOnly: false, - isRequired: false, - isMask: false + mask: false, + hide: false, + readonly: false, + disable: false + }; + let isRequired = false; + let isDisable = false; + if (!this.$utils.isEmpty(reaction)) { + for (let key in reaction) { + const reactionObj = reaction[key]; + if (!this.$utils.isEmpty(reactionObj)) { + const result = this.executeReaction(reactionObj, formData, {}, reaction); + if (reactionMap.hasOwnProperty(key)) { + reactionMap[key] = result; + } + if (key === 'required') { + isRequired = result; + } + } + } + // 当 mask、hide、readonly、disable 中任意一个为 true 时,设置 isDisable 为 true,isRequired 为 false + for (let key in reactionMap) { + if (reactionMap[key]) { + isDisable = true; + isRequired = false; + break; + } + } + } + + return { + isDisable: isDisable, + isRequired: isRequired }; - for (let key in reaction) { - const reactionObj = reaction[key]; - if (!this.$utils.isEmpty(reactionObj)) { - console.log(formData); - const result = this.executeReaction(reactionObj, formData, {}, reaction); - console.log(result, key); + }, + getValidateList(d) { + let validateList = []; + if (d.config.isRequired) { + validateList.push('required'); + } + if (!this.readonly && !this.disabled) { + if (!this.$utils.isEmpty(d.config.validate)) { + validateList.push(d.config.validate); + } + if (!this.$utils.isEmpty(d.config.regex) && this.isValidRegex(d.config.regex)) { + let findRegex = validateList.find(item => item && item.name === 'regex'); + if (findRegex) { + this.$set(findRegex, 'pattern', d.config.regex); + this.$set(findRegex, 'message', d.config.regexMessage); + } else { + validateList.push({ + name: 'regex', + pattern: d.config.regex, + message: d.config.regexMessage + }); + } + } + if (!this.$utils.isEmpty(validateList)) { + this.validateMap[d.uuid] = { + label: d.label, + validateList: validateList + }; } } } @@ -995,43 +1073,25 @@ export default { let item = { key: d.uuid, title: d.label, - reaction: d.reaction + reaction: d.reaction, + config: d.config || {} }; if (d.config) { - let validateList = []; if (d.config.isRequired) { this.$set(item, 'isRequired', true); - validateList.push('required'); } - if (!this.readonly && !this.disabled) { - if (!this.$utils.isEmpty(d.config.validate)) { - validateList.push(d.config.validate); - } - if (!this.$utils.isEmpty(d.config.regex) && this.isValidRegex(d.config.regex)) { - let findRegex = validateList.find(item => item && item.name === 'regex'); - if (findRegex) { - this.$set(findRegex, 'pattern', d.config.regex); - this.$set(findRegex, 'message', d.config.regexMessage); - } else { - validateList.push({ - name: 'regex', - pattern: d.config.regex, - message: d.config.regexMessage - }); + this.getValidateList(d); + if (!this.$utils.isEmpty(d.config.dataConfig)) { + d.config.dataConfig.forEach(c => { + if (c.config) { + this.getValidateList(c); } - } - if (!this.$utils.isEmpty(validateList)) { - this.validateMap[d.uuid] = { - label: d.label, - validateList: validateList - }; - } + }); } } this.theadList.push(item); } }); - console.log(this.validateMap); this.$emit('resize'); }, deep: true, -- Gitee From ca001540703a43e52a55fa6e5483ea17f30a13b2 Mon Sep 17 00:00:00 2001 From: dengbf Date: Tue, 22 Jul 2025 11:54:47 +0800 Subject: [PATCH 3/6] =?UTF-8?q?-=20[=E5=85=B3=E8=81=94]=20#[14667900376514?= =?UTF-8?q?56]=E8=A1=A8=E5=8D=95=EF=BC=9A=E8=A1=A8=E6=A0=BC=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5=20http://192.168.?= =?UTF-8?q?0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947?= =?UTF-8?q?543042/1466790037651456?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/component/formtableinputer/index.vue | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue index 9bb7af1c..55a01200 100644 --- a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue +++ b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue @@ -880,33 +880,24 @@ export default { const pageCount = Math.ceil((index + 1) / this.tablePageConfig.pageSize); const data = Object.assign({}, this.formData || {}, row); this.theadList.forEach(th => { - const reactionValid = this.validReaction(th.reaction, data); - if (!this.readonly && !this.disabled && !reactionValid.isDisable) { - errorList = this.getErrorList(row, data, pageCount, th, errorList); - } + errorList = this.getErrorList(row, data, pageCount, th, errorList); }); - + //内嵌table Object.keys(row).forEach(key => { - let err = []; const findThead = this.theadList.find(th => th.key === key); if (findThead && findThead.config && !this.$utils.isEmpty(findThead.config.dataConfig)) { if (!this.$utils.isEmpty(row[key])) { for (let i = 0; i < row[key].length; i++) { let item = row[key][i]; - if (this.$utils.isEmpty(err)) { - findThead.config.dataConfig.forEach(dc => { - const dValue = Object.assign({}, data, item); - const dcItem = { - key: dc.uuid, - title: dc.label, - reaction: dc.reaction - }; - err.push(...this.getErrorList(item, dValue, pageCount, dcItem)); - errorList = this.getErrorList(item, dValue, pageCount, dcItem, errorList); - }); - } else { - break; - } + findThead.config.dataConfig.forEach(dc => { + const dValue = Object.assign({}, data, item); + const dcItem = { + key: dc.uuid, + title: dc.label, + reaction: dc.reaction + }; + errorList = this.getErrorList(item, dValue, pageCount, dcItem, errorList); + }); } } } @@ -954,7 +945,7 @@ export default { return false; } }, - validReaction(reaction, formData) { //规则必填校验 + validReaction(reaction, formData) { //联动规则必填校验 let reactionMap = { mask: false, hide: false, @@ -992,6 +983,7 @@ export default { }; }, getValidateList(d) { + //获取组件的基础校验规则 let validateList = []; if (d.config.isRequired) { validateList.push('required'); -- Gitee From 13477dc77de96f379bb0b9bd2a346e67fb9ffb48 Mon Sep 17 00:00:00 2001 From: dengbf Date: Wed, 23 Jul 2025 16:19:36 +0800 Subject: [PATCH 4/6] =?UTF-8?q?-=20[=E5=85=B3=E8=81=94]=20#[14667900376514?= =?UTF-8?q?56]=E8=A1=A8=E5=8D=95=EF=BC=9A=E8=A1=A8=E6=A0=BC=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5=20http://192.168.?= =?UTF-8?q?0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947?= =?UTF-8?q?543042/1466790037651456?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/component/formtableinputer/index.vue | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue index 55a01200..10f4e490 100644 --- a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue +++ b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue @@ -135,7 +135,6 @@ export default { isShowExportExcel: true, loading: false, filterComponentList: ['formtableselector', 'formtableinputer', 'formsubassembly', 'formupload', 'formcube', 'formtable', 'formresoureces', 'formprotocol'], //过滤不参与规则的组件 - initExternalData: {}, //用于对比外部组件值变换 tablePageConfig: { //table分页配置 currentPage: 1, pageSize: 5, @@ -209,9 +208,10 @@ export default { this.selectedIndexList = indexList; }, deleteItem(row) { - const index = this.tbodyList.findIndex(d => d.uuid === row.uuid); - if (index > -1) { - this.tbodyList.splice(index, 1); + const findIndex = this.tbodyList.findIndex(d => d.uuid === row.uuid); + this.tbodyList.splice(findIndex, 1); + if (!this.pagedTbodyList.length && this.tablePageConfig.currentPage > 1) { + this.tablePageConfig.currentPage -= 1; } }, addRow(index) { @@ -221,7 +221,6 @@ export default { data[d.uuid] = (d.config && d.config.defaultValue) || null; } }); - Object.assign(data, this.initExternalData); this.tbodyList.splice(index + 1, 0, data); }, removeSelectedItem() { @@ -231,6 +230,9 @@ export default { this.tbodyList.splice(i, 1); } } + if (!this.pagedTbodyList.length && this.tablePageConfig.currentPage > 1) { + this.tablePageConfig.currentPage -= 1; + } }, addData() { const data = { uuid: this.$utils.setUuid() }; @@ -239,7 +241,6 @@ export default { data[d.uuid] = (d.config && d.config.defaultValue) || null; } }); - Object.assign(data, this.initExternalData); this.tbodyList.unshift(data); }, validConfig() { @@ -866,7 +867,9 @@ export default { changeCurrent(currentPage) { this.tablePageConfig.currentPage = currentPage; this.$nextTick(() => { - this.validData(); + if (!this.readonly && !this.disabled) { + this.validData(); + } }); }, changePageSize(pageSize) { -- Gitee From 6444f18abc3a39d71ed1fff82646b4bafd934f9f Mon Sep 17 00:00:00 2001 From: dengbf Date: Mon, 28 Jul 2025 17:34:55 +0800 Subject: [PATCH 5/6] =?UTF-8?q?-=20[=E5=85=B3=E8=81=94]=20#[14667900376514?= =?UTF-8?q?56]=E8=A1=A8=E5=8D=95=EF=BC=9A=E8=A1=A8=E6=A0=BC=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5=20http://192.168.?= =?UTF-8?q?0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947?= =?UTF-8?q?543042/1466790037651456?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/component/formtableinputer/index.vue | 17 +++++++---------- .../table-import-export-mixin.js | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue index 4bfaf3e4..dd5ed195 100644 --- a/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue +++ b/src/resources/plugins/TsSheet/form/component/formtableinputer/index.vue @@ -1,5 +1,5 @@