审批流保存数据检验
This commit is contained in:
1 parent
7e094cd83e
commit
9bec3c6de0
8 files changed
+169
-30
No files matched your search
@@ -219,7 +219,7 @@ Vue.component("create-task-drawer", {
|
||||
}
|
||||
formObj.workflowConfig = formObj.workflowConfig ? formObj.workflowConfig : null;
|
||||
formObj.workflowForm = formObj.workflowForm ? (typeof formObj.workflowForm == 'string'? JSON.parse(formObj.workflowForm): formObj.workflowForm) : [];
|
||||
formObj.workflowForm.forEach(f => f.answer = []) // 兼容多选
|
||||
formObj.workflowForm.forEach(f => f.answer = ['multiple', 'file'].includes(f.type) ? [] : '') // 兼容多选
|
||||
this.defaultWorkflowConfig = _.cloneDeep(formObj.workflowConfig);
|
||||
this.defaultWorkflowForm = _.cloneDeep(formObj.workflowForm);
|
||||
this.defaultWorkflowConfig.nodeList.forEach(node =>{
|
||||
@@ -525,9 +525,21 @@ Vue.component("create-task-drawer", {
|
||||
|
||||
// -- <<<<<<<<<<<<< 操作审批流 --------------------
|
||||
// -- 新建任务 >>>>>>>>>>> ---------------
|
||||
isValidDateTime(str) {
|
||||
// 正则表达式,考虑日期和时间的范围
|
||||
const regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
|
||||
|
||||
// 使用test方法检查字符串是否符合正则表达式
|
||||
return regex.test(str);
|
||||
},
|
||||
|
||||
async prepareCreateValidate() {
|
||||
// 检查必填是否已填 TODO:注意文件
|
||||
this.taskData.workflowForm.forEach(f => {
|
||||
if(f.type == 'time' && !this.isValidDateTime(f.answer)){
|
||||
window.vtoast.fail("时间日期格式不正确!")
|
||||
throw new Error("时间日期格式不正确!")
|
||||
}
|
||||
// 检查必填是否已填
|
||||
if(f.isRequire){
|
||||
if(!f.answer || f.answer && f.answer.length == 0){
|
||||
window.vtoast.fail("请完善表单信息")
|
||||
@@ -535,13 +547,14 @@ Vue.component("create-task-drawer", {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
async confirmCreateWorkDialog() {
|
||||
if (await window.confirmDialog({ title: "新建任务", content: "确定新建任务吗?" }) === false) {
|
||||
throw new Error("[confirmCreateFormDialog] 否");
|
||||
}
|
||||
},
|
||||
|
||||
prepareDoWorkItem() {
|
||||
const { workflowInfo, workflowForm, workflowConfig, workflowName, taskTemplateGroup, } = this.taskData
|
||||
var curNode = this.curWorkflow[0]
|
||||
|
||||
@@ -353,7 +353,8 @@
|
||||
return window.innerWidth < 600;
|
||||
},
|
||||
prioritys(){
|
||||
var num = this.workflowConfig.nodeList.filter(n=>n.properties.type == 'conditionTask').length
|
||||
const { nodeList } = this.workflowConfig
|
||||
var num = nodeList.filter(n=>n.properties.type == 'conditionTask').length
|
||||
return [
|
||||
{ text: '默认条件', priority: -1 },
|
||||
..._.times(num - 1, i => {
|
||||
|
||||
@@ -266,6 +266,9 @@ Vue.component("process-flow", {
|
||||
case 'deleteNodeBySimple':
|
||||
await this.deleteNodeBySimple(uiActionData);
|
||||
break;
|
||||
case 'dataValidate':
|
||||
await this.dataValidate();
|
||||
break;
|
||||
default:
|
||||
console.error("[doUiAction] uiActionId not find", {uiActionId});
|
||||
break;
|
||||
@@ -390,10 +393,9 @@ Vue.component("process-flow", {
|
||||
},
|
||||
// 切换展示模式
|
||||
changeDisplayMode(displayMode){
|
||||
var changeAble = true
|
||||
var changeText = ""
|
||||
var lineList = this.workflowConfig.lineList
|
||||
var nodeList = this.workflowConfig.nodeList
|
||||
var changeAble = true,
|
||||
changeText = "";
|
||||
const {lineList, nodeList} = this.workflowConfig;
|
||||
|
||||
if(displayMode == 'simple'){
|
||||
// 检查是否有多个开始节点或结束节点
|
||||
@@ -787,8 +789,96 @@ Vue.component("process-flow", {
|
||||
*/
|
||||
parseBusinessDataTologicFlowData() {
|
||||
return {
|
||||
nodes: this.workflowConfig.nodeList.map(node => node).filter(node => node != null),
|
||||
edges: this.workflowConfig.lineList.map(line => line).filter(line => line != null)
|
||||
nodes: this.workflowConfig.nodeList.filter(node => node != null),
|
||||
edges: this.workflowConfig.lineList.filter(line => line != null)
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 检验数据
|
||||
*/
|
||||
async dataValidate(){
|
||||
var isPassValidate = true,
|
||||
disPassValidateText = '';
|
||||
const { lineList, nodeList } = this.workflowConfig;
|
||||
|
||||
|
||||
// 不允许多个开始节点或结束节点
|
||||
if(nodeList.filter(n=>n.properties.type == 'start').length != 1 || nodeList.filter(n=>n.properties.type == 'end').length != 1){
|
||||
isPassValidate = false
|
||||
disPassValidateText += "只允许存在1个开始节点或结束节点!"
|
||||
}
|
||||
|
||||
// 不允许孤立节点 => 除了开始节点和结束节点外,每个节点都有入线和出线
|
||||
var lineBySourceNodeId = _.groupBy(lineList, 'sourceNodeId'),
|
||||
lineByTargetNodeId = _.groupBy(lineList, 'targetNodeId'),
|
||||
mergeTemp = _.mergeWith(_.cloneDeep(lineBySourceNodeId), lineByTargetNodeId, (objValue, srcValue)=>{
|
||||
if (_.isArray(objValue)) {
|
||||
return objValue.concat(srcValue);
|
||||
}
|
||||
});
|
||||
if(Object.keys(mergeTemp).length < nodeList.length){
|
||||
isPassValidate = false
|
||||
disPassValidateText += '存在孤立节点!\n'
|
||||
}else{
|
||||
// 判断开始节点是否只含有出线sourceNodeId
|
||||
if(_.some(Object.keys(lineByTargetNodeId), (i) => i.startsWith('start-'))){
|
||||
isPassValidate = false
|
||||
disPassValidateText += "连线终点不能为开始节点!\n"
|
||||
}
|
||||
// 结束节点是否是含有入线targetNodeId
|
||||
if(_.some(Object.keys(lineBySourceNodeId), (i) => i.startsWith('end-'))){
|
||||
isPassValidate = false
|
||||
disPassValidateText += "连线起点不能为结束节点!\n"
|
||||
}
|
||||
// 其他的节点必须至少有一个入线和出线
|
||||
for (const key in mergeTemp) {
|
||||
if (Object.hasOwnProperty.call(mergeTemp, key)) {
|
||||
if(!(key.startsWith('start-') || key.startsWith('end-'))){
|
||||
const element = mergeTemp[key];
|
||||
|
||||
if(!_.some(element, i => i.sourceNodeId == key) || !_.some(element, i => i.targetNodeId == key)){
|
||||
isPassValidate = false
|
||||
disPassValidateText += "存在除了开始和结束节点以外的节点没有入线或出线!"
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 不允许条件节点和审批/通知节点存在同一层级
|
||||
for (const key in lineBySourceNodeId) {
|
||||
if (Object.hasOwnProperty.call(lineBySourceNodeId, key)) {
|
||||
const element = lineBySourceNodeId[key];
|
||||
// 拿到同一层的节点
|
||||
var node = element.map(l => nodeList.find(n => n.id === l.targetNodeId))
|
||||
|
||||
if(_.some(node, i => i.properties.type == "conditionTask") && _.some(node, i => i.properties.type != "conditionTask")){
|
||||
isPassValidate = false
|
||||
disPassValidateText += "不允许条件节点和审批/通知节点存在同一层级!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 不允许有条件节点的优先级没有默认优先级节点, 允许存在多个默认节点,读取顺序按放置时间的先后顺序
|
||||
var conditionNodeLineBySourceNodeId = _.groupBy(lineList.filter(i => i.targetNodeId.startsWith('conditionTask-')), 'sourceNodeId');
|
||||
for (const key in conditionNodeLineBySourceNodeId) {
|
||||
if (Object.hasOwnProperty.call(conditionNodeLineBySourceNodeId, key)) {
|
||||
const element = conditionNodeLineBySourceNodeId[key];
|
||||
// 拿到同一层的条件节点
|
||||
var conditionNode = element.map(l => nodeList.find(n => n.id === l.targetNodeId))
|
||||
|
||||
if(!_.some(conditionNode, i => i.properties.priority == -1)){
|
||||
isPassValidate = false
|
||||
disPassValidateText += "存在某层条件节点没有默认条件优先级!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!isPassValidate){
|
||||
await window.vtoast.fail(disPassValidateText);
|
||||
throw new Error(disPassValidateText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
v-model="formItem.answer"
|
||||
></v-text-field>
|
||||
</template>
|
||||
<v-date-picker no-title scrollable></v-date-picker>
|
||||
<v-date-picker no-title scrollable v-model="formItem.answer"></v-date-picker>
|
||||
</v-menu>
|
||||
</v-list-item-content>
|
||||
|
||||
|
||||
@@ -260,6 +260,17 @@ Vue.component("form-item-list-generator", {
|
||||
return this.formItemList;
|
||||
},
|
||||
|
||||
dataValidate(){
|
||||
console.log('formItemListGenerator-dataValidate', this.formItemList);
|
||||
// 检查单选多选是否还有选项
|
||||
this.formItemList.forEach(async element => {
|
||||
if(['single', 'multiple'].includes(element.type) && !(element.optionList && element.optionList.length)){
|
||||
await window.vtoast.fail("存在选择题没有选项!");
|
||||
throw new Error("存在选择题没有选项!")
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -38,19 +38,24 @@
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// 每个属性值发生变化就会调用这个函数
|
||||
form(newVal, oldVal) {
|
||||
this.saveData(newVal)
|
||||
},
|
||||
// 深度监听 属性的变化
|
||||
deep: true
|
||||
|
||||
},
|
||||
async created() {
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
saveData(newVal) {
|
||||
// this.$emit('change-structure', this.form);
|
||||
async doUiAction(uiActionId, uiActionData) {
|
||||
switch (uiActionId) {
|
||||
case 'dataValidate':
|
||||
await this.dataValidate();
|
||||
break;
|
||||
default:
|
||||
console.error("[doUiAction] uiActionId not find", {uiActionId});
|
||||
break;
|
||||
}
|
||||
},
|
||||
dataValidate(){
|
||||
this.$refs.formItemListGenerator.dataValidate()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<template id="workflow-basic-info">
|
||||
<div class="workflow-basic-info-container">
|
||||
<v-form ref="basicInfoForm" lazy-validation>
|
||||
<v-row>
|
||||
<v-col cols="12" sm="12" md="12" xl="12">
|
||||
<span class="jh-input-label">流程名<span class="red--text text--accent-2 ml-1">*必填</span></span>
|
||||
@@ -45,7 +46,7 @@
|
||||
<div class="d-flex flex-wrap">
|
||||
<div
|
||||
v-for="icon in materialDesignIcons"
|
||||
:class="`item-icon pa-1 ${workflowInfo.taskTemplateIcon == icon && 'green'}`"
|
||||
:class="`item-icon pa-1 ${workflowInfo.taskTemplateIcon == icon && 'grey lighten-2'}`"
|
||||
@click="workflowInfo.taskTemplateIcon = icon"
|
||||
>
|
||||
<v-img
|
||||
@@ -73,6 +74,7 @@
|
||||
</v-text-field>
|
||||
</v-col> -->
|
||||
</v-row>
|
||||
</v-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -111,13 +113,20 @@ Vue.component("workflow-basic-info", {
|
||||
methods: {
|
||||
async doUiAction(uiActionId, uiActionData) {
|
||||
switch (uiActionId) {
|
||||
case 'dataValidate':
|
||||
await this.dataValidate();
|
||||
break;
|
||||
default:
|
||||
console.error("[doUiAction] uiActionId not find", {uiActionId});
|
||||
break;
|
||||
}
|
||||
},
|
||||
setIcon(icon){
|
||||
this.$set(this.workflowInfo, 'taskTemplateIcon', icon)
|
||||
async dataValidate(){
|
||||
if (await this.$refs.basicInfoForm.validate()) {
|
||||
return true;
|
||||
}
|
||||
await window.vtoast.fail("请完善基础信息!");
|
||||
throw new Error("请完善基础信息!")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<v-card-text class="pa-0">
|
||||
<div class="mt-1">
|
||||
<!-- <div class="text-subtitle-2 mb-2">基础信息</div> -->
|
||||
<workflow-basic-info :workflow-info="formObj.workflowInfo"></workflow-basic-info>
|
||||
<workflow-basic-info ref="basicInfo" :workflow-info="formObj.workflowInfo"></workflow-basic-info>
|
||||
</div>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
@@ -55,7 +55,7 @@
|
||||
<v-card-text class="pa-0">
|
||||
<div class="mt-1">
|
||||
<!-- <div class="text-subtitle-2 mb-2">表单设置</div> -->
|
||||
<tpl-form-design :form="formObj.workflowForm" v-if="!loading"></tpl-form-design>
|
||||
<tpl-form-design ref="tplFormDesign" :form="formObj.workflowForm" v-if="!loading"></tpl-form-design>
|
||||
</div>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
@@ -125,6 +125,11 @@ Vue.component("workflow-editor-drawer", {
|
||||
step: 1
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
step(newVal, oldVal){
|
||||
console.log('step', newVal, oldVal);
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isMobile() {
|
||||
return window.innerWidth < 600;
|
||||
@@ -154,6 +159,7 @@ Vue.component("workflow-editor-drawer", {
|
||||
break;
|
||||
case 'createItem':
|
||||
await this.confirmCreateItemDialog();
|
||||
await this.prepareValidate();
|
||||
await this.prepareFormSubmitData();
|
||||
await this.doCreateItem();
|
||||
await this.syncUpdateFormObj();
|
||||
@@ -161,6 +167,7 @@ Vue.component("workflow-editor-drawer", {
|
||||
break;
|
||||
case 'updateItem':
|
||||
await this.confirmUpdateItemDialog();
|
||||
await this.prepareValidate();
|
||||
await this.prepareFormSubmitData();
|
||||
await this.doUpdateItem();
|
||||
await this.syncUpdateFormObj();
|
||||
@@ -258,7 +265,6 @@ Vue.component("workflow-editor-drawer", {
|
||||
},
|
||||
// -- <<<<<<<<<<<<< 获取数据 --------------------
|
||||
// -- constantObj 数据构建 >>>>>>>>>>> ---------------
|
||||
|
||||
buildConstantWorkflowConfig() {
|
||||
if (!this.formObj.workflowConfig) return;
|
||||
this.$refs.processFlow.doUiAction('complexModeInit');
|
||||
@@ -286,19 +292,23 @@ Vue.component("workflow-editor-drawer", {
|
||||
await this.prepareFormObj();
|
||||
this.hideLoading();
|
||||
},
|
||||
|
||||
hideLoading() {
|
||||
setTimeout(() => {
|
||||
this.loading = false;
|
||||
}, 300)
|
||||
},
|
||||
// TODO: 检验数据
|
||||
|
||||
prepareValidate(){
|
||||
const { id, workflowId, workflowInfo, workflowForm } = this.formObj;
|
||||
var submitAble = false
|
||||
// 判断info的数据
|
||||
// 判断form的数据
|
||||
|
||||
// 判断info的数据 ==>
|
||||
this.$refs.basicInfo.doUiAction('dataValidate')
|
||||
// 判断form的数据 ==> 判断单选多选是否有选项
|
||||
this.$refs.tplFormDesign.doUiAction('dataValidate')
|
||||
// 判断流程图的数据
|
||||
// 只允许在第一个节点设置条件节点
|
||||
// 不允许节点孤立
|
||||
this.$refs.processFlow.doUiAction('dataValidate')
|
||||
|
||||
},
|
||||
prepareFormSubmitData() {
|
||||
|
||||
Reference in new issue
Block a user