Files
workflow/app/view/component/createTaskDrawer.html
T
2024-05-20 13:45:23 +08:00

728 lines
26 KiB
HTML

<template id="create-task-drawer">
<v-card class="pa-4">
<v-navigation-drawer v-model="isDrawerShown" v-if="isDrawerShown" :permanent="isDrawerShown" fixed temporary right width="90%" class="elevation-24">
<!-- 抽屉标题 -->
<v-row no-gutters>
<span class="text-h7 font-weight-bold pa-4">【{{taskData.taskTemplateGroup}}——{{taskData.workflowName}}】创建审批</span>
</v-row>
<!-- {{taskData.workflowForm}} -->
<!-- 表单 -->
<v-row class="ma-4 mt-2">
<template v-if="taskData.workflowForm && taskData.workflowForm.length > 0">
<v-col cols="12" v-for="(formItem, index) in taskData.workflowForm" :key="index" class="px-2 py-1 ma-0">
<span class="jh-input-label">{{ index + 1 }}. {{ formItem.statement }}<span v-show="formItem.isRequire" class="red--text ml-1">*</span></span>
<form-component-list v-if="isDrawerShown" :form-item="formItem" :disabled='false' :readonly='false' @calc-workflow="getWorkflow" ></form-component-list>
</v-col>
</template>
<template v-else>
暂无表单,请联系管理员!
</template>
</v-row>
<v-divider class="jh-divider"></v-divider>
<!-- 审批流 -->
<v-row class="ma-4 mt-2">
<v-col cols="12" class="font-weight-bold pa-0 mx-0 my-2">审批流程</v-col>
<template v-if="curWorkflow.length > 0">
<v-col cols="12" class="pa-0 ma-0">
<div v-for="(node, nodeIndex) in curWorkflow">
<div class="node-box">
<div class="node-box-stepper" color="#cdcfd1">
<v-icon v-if="node.properties.type == 'approvalTask'" color="#cdcfd1">mdi-account-circle</v-icon>
<v-icon v-if="node.properties.type == 'noticeTask'" color="#cdcfd1">mdi-send-circle</v-icon>
<div v-if="nodeIndex < curWorkflow.length - 1" class="vertical-line"></div>
</div>
<div class="node-box-item">
<div class="item-label font-weight-bold ">
{{node.properties.label}}
<v-chip class="ml-1 px-1 py-2" x-small v-if="node.properties.approvalType" label outlined color="#4caf50">
{{node.properties.approvalType}}
</v-chip>
</div>
<div class="d-flex align-center">
<template v-for="(user, userIndex) in node.properties.userIdList">
<div :class="`item-user-box d-flex justify-space-between align-center px-2 mr-2 ${ user.username?.includes('(账号被禁用)') && 'item-user-box-error'} `">
<div class="item-avatar d-flex align-center justify-center mr-2">{{user.username[0] || ''}}</div>
<div class="omit">{{ user.username }}</div>
<v-icon v-if="( node.properties?.approverType == '申请人自选' || node.properties?.noticerType == '申请人自选' ) || taskData.workflowInfo.modifyAuthority == false"
class="ml-1" color="#a4a7aa" @click="doUiAction('deleteNodeUser', {nodeIndex ,userIndex})">
mdi-close
</v-icon>
</div>
<v-icon v-if="userIndex < node.properties.userIdList.length - 1 && node.properties.approvalType == '依次审批'"
class="mr-2" color="#afb1b4" small>
mdi-arrow-right-thin
</v-icon>
</template>
<template v-if=" node.properties.userIdList <= 0 && ( node.properties?.approverType != '申请人自选' && node.properties?.noticerType != '申请人自选' )">
<div class="item-user-box d-flex justify-space-between px-2 mr-2">
<span class="red--text">审批人为空</span>
</div>
</template>
<template v-if="( node.properties?.approverType == '申请人自选' || node.properties?.noticerType == '申请人自选' ) || taskData.workflowInfo.modifyAuthority == false">
<div class="abb-user d-flex justify-center align-center" @click="doUiAction('startAddNodeUser', nodeIndex)">
<v-icon color="#4caf50">mdi-plus</v-icon>
</div>
</template>
</div>
</div>
</div>
</div>
</v-col>
</template>
<template v-else>
暂无节点,请联系管理员!
</template>
</v-row>
<v-row class="justify-end mx-0 my-8 px-4">
<!-- 抽屉操作按钮 -->
<div class="d-flex justify-end pr-4">
<v-btn color="success" @click="doUiAction('createTask')" small :loading="isCreateWorkLoading">提交</v-btn>
<v-btn class="elevation-0 ml-2" @click="isDrawerShown = false" small :loading="isCreateWorkLoading">取消</v-btn>
</div>
</v-row>
<!-- 抽屉关闭按钮 -->
<v-btn elevation="0" color="success" fab absolute top left small tile class="drawer-close-float-btn" @click="isDrawerShown = false">
<v-icon>mdi-close</v-icon>
</v-btn>
</v-navigation-drawer>
<template>
<v-row justify="center">
<v-dialog
v-model="isAddNodeUserDialogShown"
persistent
width="30%"
>
<v-card>
<v-card-title class="text-h5">
添加用户
</v-card-title>
<v-card-text>
<v-autocomplete
class="jh-v-input mr-2"
dense filled single-line clearable
:items="curUserList"
item-text="username"
item-value="userId"
v-model="addNodeUserId">
</v-autocomplete>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="green darken-1"
text
@click="doUiAction('closeAddNodeUserDialog')"
>
取消
</v-btn>
<v-btn
color="green darken-1"
text
@click="doUiAction('doAddNodeUser')"
>
保存
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-row>
</template>
</v-card>
</template>
{% include 'component/tpl/tplFormDesign.html' %}
<script type="module">
Vue.component("create-task-drawer", {
template: '#create-task-drawer',
vuetify: new Vuetify(),
data() {
return {
isDrawerShown: false,
// 表格相关数据
isFormValid: true,
validationRules: {
requireRules: [
v => !!v || '必填',
],
},
constantObj: {
userList: [],
groupList: [],
labelList: []
},
isHelpPageDrawerShown: false,
defaultWorkflowConfig: {},
defaultWorkflowForm: [],
taskData: {},
taskSubmitData: null,
isAddNodeUserDialogShown: false,
addNodeUserIndex: -1,
addNodeUserId: null,
selectedUser: [],
isCreateWorkLoading: false
}
},
computed: {
isMobile() {
return window.innerWidth < 600;
},
curWorkflow(){
return this.taskData.workflowConfig.nodeList.filter(node => !['start', 'end', 'conditionTask'].includes(node.properties.type))
},
curUserList(){
return this.constantObj.userList.filter(u => !this.selectedUser.includes(u.userId))
}
},
watch: {
},
async created() {
this.doUiAction('getConstantData');
},
async mounted() {
},
methods: {
async doUiAction(uiActionId, uiActionData) {
switch (uiActionId) {
case 'open':
await this.prepareTaskData(uiActionData);
await this.getWorkflow();
await this.openDrawer();
break;
case 'close':
await this.closeDrawer();
break;
case 'getConstantData':
await this.getUserList();
await this.getGroupList();
await this.getLabelList();
break;
case 'deleteNodeUser':
await this.deleteNodeUser(uiActionData);
break;
case 'startAddNodeUser':
await this.startAddNodeUser(uiActionData);
break;
case 'doAddNodeUser':
await this.addNodeUser();
await this.closeAddNodeUserDialog();
break;
case 'closeAddNodeUserDialog':
await this.closeAddNodeUserDialog();
break;
case 'createTask':
await this.prepareCreateValidate();
await this.confirmCreateWorkDialog();
await this.prepareDoWorkItem();
await this.doCreateWork();
await this.doUiAction('close')
break;
default:
console.error("[doUiAction] uiActionId not find", {uiActionId});
break;
}
},
async prepareTaskData(item) {
if(item) {
let formObj = _.cloneDeep(item);
formObj.workflowInfo = {
workflowName: item.workflowName,
...item.workflowInfo,
}
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 = ['multiple', 'file'].includes(f.type) ? [] : '') // 兼容多选
this.defaultWorkflowConfig = _.cloneDeep(formObj.workflowConfig);
this.defaultWorkflowForm = _.cloneDeep(formObj.workflowForm);
this.defaultWorkflowConfig.nodeList.forEach(node =>{
if(['approvalTask', 'noticeTask'].includes(node.properties.type)){
node.properties.userIdList = this.getUserByType(node)
}
})
this.taskData = _.cloneDeep(formObj);
} else {
window.vtoast.fail('[createTaskDrawer] 出错,请联系管理员!');
throw new Error('[createTaskDrawer] 出错,请联系管理员!')
}
},
async openDrawer() {
this.isDrawerShown = true;
},
async closeDrawer() {
this.defaultWorkflowConfig = null;
this.defaultWorkflowForm = null;
this.taskData = null;
this.isDrawerShown = false;
},
// -- 获取数据 >>>>>>>>>>> ---------------
// 获取user数据
async getUserList() {
const {rows} = (await window.jianghuAxios({
data: {
appData: {
pageId: 'taskApply',
actionId: 'selectUserList',
actionData: {},
where: {},
}
}
})).data.appData.resultData;
this.constantObj.userList = await this.handleMultiGroupUser(rows)
},
async handleMultiGroupUser(userList){
let groupByUserId = _.groupBy(userList,'userId');
_.forEach(groupByUserId,(val, key)=>{
// 合并groupAllName,若只有一个值则转为数组
const group = _.map(val, (u) => {
return {
groupId: u.groupId,
groupPath: u.groupPath,
groupAllName: u.groupAllName,
isMainGroup: u.isMainGroup,
roleId: u.roleId,
roleName: u.roleName
}
}).filter(g => g.groupId)
// 集成到第一个对象中
val[0].group = group
groupByUserId[key] = _.pick(val[0], ['userId', 'username', 'directSupervisor', 'group'])
})
return _.values(groupByUserId)
},
// 获取group数据
async getGroupList() {
const {rows} = (await window.jianghuAxios({
data: {
appData: {
pageId: 'taskApply',
actionId: 'selectGroupList',
actionData: {},
where: {},
}
}
})).data.appData.resultData;
this.constantObj.groupList = rows
},
// 获取label数据
async getLabelList() {
const {rows} = (await window.jianghuAxios({
data: {
appData: {
pageId: 'allPage',
actionId: 'selectLabelList',
actionData: {},
where: {},
}
}
})).data.appData.resultData;
this.constantObj.labelList = rows;
},
// -- <<<<<<<<<<<<< 获取数据 --------------------
// -- 计算审批流 >>>>>>>>>>> ---------------
getUserByType(node){
var userList = []
var type = node.properties.type == 'approvalTask' ?
node.properties.approverType : node.properties.noticerType
switch (type) {
case '指定上级':
var num = 0
node.properties.user.forEach(u =>{
num = u == '直属上级' ? 1 : u[1]
userList = userList.concat(this.getDirectSupervisor([`<$ ctx.userInfo.userId $>`], num))
})
userList = userList.map(id => { return { userId: id, username: this.constantObj.userList.find(u => u.userId == id)?.username || id + '(账号被禁用)'}})
break;
case '指定部门负责人':
var num = 0
node.properties.user.forEach(u =>{
num = u == '直接部门负责人' ? 1 : u[1]
var groupId = this.constantObj.userList.find(u => u.userId == `<$ ctx.userInfo.userId $>`)?.group.find(g => g.isMainGroup == '是')?.groupId
userList = userList.concat(this.getHeadId(groupId, num))
})
userList = userList.map(id => { return { userId: id, username: this.constantObj.userList.find(u => u.userId == id)?.username || id + '(账号被禁用)'}})
break;
case '指定标签':
node.properties.user.forEach(u =>{
let userIdList = this.constantObj.labelList.find(l => l.labelId == u)?.user.split(',')
if(userIdList && userIdList.length > 0) userList = userList.concat(userIdList)
})
userList = userList.map(id => { return { userId: id, username: this.constantObj.userList.find(u => u.userId == id)?.username || id + '(账号被禁用)'}})
break;
case '指定人员':
userList = node.properties.user
userList = userList.map(id => { return { userId: id, username: this.constantObj.userList.find(u => u.userId == id)?.username || id + '(账号被禁用)'}})
break;
case '申请人自选':
break;
default:
break;
}
return userList
},
// 获取第n级上级
getDirectSupervisor(userIdList = [], num){
var directSupervisorList = []
if(num > 0 && userIdList.length > 0){
while(num > 0){
num--
directSupervisorList = []
userIdList.forEach(userId => {
let user = this.constantObj.userList.find(u => u.userId == userId)
if(user){
directSupervisorList = directSupervisorList.concat(user.directSupervisor ? user.directSupervisor.split(',') : [])
}
})
userIdList = directSupervisorList
}
}
return directSupervisorList
},
getHeadId(groupId, num){
var headerId = []
while(num > 0){
num--
headerId = []
if(!groupId) break
var group = this.constantObj.groupList.find(g => g.groupId == groupId)
if(group){
headerId = group.headId?.split(',') || []
}
groupId = group.groupPath
}
return headerId
},
async getWorkflow(){
this.taskData.workflowConfig = await this.calcWorkflow(this.defaultWorkflowConfig)
},
// 计算审批流
calcWorkflow(workflow = {}){
var newWorkflow = {
nodeList: [],
lineList: []
}
// 先找到开始节点
var beginNode = workflow.nodeList?.filter(n => n.properties.type == 'start')
if(beginNode.length != 1){
window.vtoast.fail('审批流-开始节点出错,请联系管理员!')
throw new Error('[calcWorkflow] 审批流-开始节点出错,请联系管理员!')
}
// 再找开始节点的下一个节点
var nextNode = beginNode[0]
newWorkflow.nodeList.push(beginNode[0])
do{
const { node, prevline } = this.calcNode(workflow, nextNode)
newWorkflow.nodeList.push(node)
newWorkflow.lineList.push(prevline)
nextNode = node
}while(nextNode.properties.type != 'end')
return newWorkflow
},
// 查找传入节点的下一个节点,直到找到结束节点
calcNode(workflow, node){
var lineList = workflow.lineList,
nodeList = workflow.nodeList,
nextNode = null,
prevLine = null,
nextNodeList = []
nextNodeList = _.intersectionWith(nodeList, lineList.filter(line => line.sourceNodeId == node.id),
(node, line) => line.targetNodeId == node.id);
if(nextNodeList.length == 1){
nextNode = nextNodeList[0]
}else if(nextNodeList.length > 1){
if(_.every(nextNodeList, (n) => n.properties.type == 'conditionTask')){
// 条件节点按优先级升序排序,默认条件节点放最后
var nextNodeListbySort = _.sortBy(nextNodeList, (obj) => obj.properties.priority == -1 ? Infinity : obj.properties.priority)
// 判断是否符合条件节点
for(let i = 0; i < nextNodeListbySort.length; i++){
if(nextNodeListbySort[i].properties.priority == -1){
nextNode = nextNode || nextNodeListbySort[i]
}
if(nextNodeListbySort[i].properties.conditionList?.length > 0 && _.every(this.isMatchCondition(nextNodeListbySort[i].properties.conditionList))){
nextNode = nextNode || nextNodeListbySort[i]
}
}
}
}
if(!nextNode){
window.vtoast.fail('审批流出错,请联系管理员!')
throw new Error('[calcNode] 审批流出错,请联系管理员!')
}
prevLine = lineList.filter(line => line.sourceNodeId == node.id && line.targetNodeId == nextNode.id)
return {
node: nextNode,
prevline: prevLine[0]
}
},
// 判断是否命中条件节点
isMatchCondition(conditionList){
var isMatch = new Array(conditionList.length)
conditionList.forEach((condition, index) => {
// 申请人
if(condition.id == 'single-applyPerson'){
if(condition.option.includes(`<$ ctx.userInfo.userId $>`)){
isMatch[index] = true
}
}else{
var answer = this.taskData.workflowForm.find(w => w.id == condition.id)?.answer
if(answer.length > 0){
switch (condition.type) {
case 'single':
isMatch[index] = condition.option.includes(answer)
break;
case 'multiple':
if(condition.express == 'fullInclude'){
isMatch[index] = answer.length > 0 && _.intersection(condition.option, answer).length == condition.option.length
}else if(condition.express == 'oneInclude'){
isMatch[index] = answer.length > 0 && _.intersection(answer, condition.option).length > 0
}
break;
case 'number':
if(condition.express != 'between'){
switch (condition.express) {
case '<':
isMatch[index] = Number(answer) < condition.option
break;
case '<=':
isMatch[index] = Number(answer) <= condition.option
break;
case '==':
isMatch[index] = Number(answer) == condition.option
break;
case '>=':
isMatch[index] = Number(answer) >= condition.option
break;
case '>':
isMatch[index] = Number(answer) > condition.option
break;
default:
break;
}
}else{
if(condition.option.begin <= Number(answer) && Number(answer) <= condition.option.end){
isMatch[index] = true
}
}
break;
default :
isMatch[index] = false
break;
}
}
}
})
return isMatch
},
// -- <<<<<<<<<<<<< 计算审批流 --------------------
// -- 操作审批流 >>>>>>>>>>> ---------------
deleteNodeUser({nodeIndex ,userIndex}){
this.curWorkflow[nodeIndex].properties.userIdList.splice(userIndex, 1)
this.$forceUpdate()
},
startAddNodeUser(nodeIndex){
this.addNodeUserIndex = nodeIndex
this.selectedUser = this.curWorkflow[nodeIndex].properties.userIdList.map(u => u.userId)
this.isAddNodeUserDialogShown = true
},
addNodeUser(){
if(!this.addNodeUserId) return window.vtoast.fail('保存用户失败!')
this.curWorkflow[this.addNodeUserIndex].properties.userIdList.push({
userId: this.addNodeUserId,
username: this.constantObj.userList.find(u => u.userId == this.addNodeUserId)?.username || id + '(账号被禁用)'
})
window.vtoast.success('保存用户成功!')
},
closeAddNodeUserDialog(){
this.isAddNodeUserDialogShown = false
this.addNodeUserIndex = -1
this.addNodeUserId = null
},
// -- <<<<<<<<<<<<< 操作审批流 --------------------
// -- 新建任务 >>>>>>>>>>> ---------------
isValidDateTime(str) {
// 正则表达式,考虑日期和时间的范围
const regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
// 使用test方法检查字符串是否符合正则表达式
return regex.test(str);
},
async prepareCreateValidate() {
this.curWorkflow.forEach(n => {
if(!n.properties.userIdList.length){
window.vtoast.fail("存在节点没有设置人员!")
throw new Error("存在节点没有设置人员!")
}else{
if(_.some(n.properties.userIdList, (user) => user.username.includes('(账号被禁用)'))){
window.vtoast.fail("存在节点中账号被禁用,请联系管理员修改!")
throw new Error("存在节点中账号被禁用,请联系管理员修改!")
}
}
})
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("请完善表单信息")
throw new Error("请完善表单信息")
}
}
})
},
async confirmCreateWorkDialog() {
if (await window.confirmDialog({ title: "新建任务", content: "确定新建任务吗?" }) === false) {
throw new Error("[confirmCreateFormDialog] 否");
}
},
prepareDoWorkItem() {
const { workflowInfo, workflowForm, workflowConfig, workflowName, taskTemplateGroup, } = this.taskData
var startNode = this.curWorkflow[0]
workflowConfig.nodeList.forEach(node => {
if(node.properties.userIdList){
node.properties.userIdList = node.properties.userIdList.map(u => u.userId)
}
})
var taskLineType = workflowConfig.lineList.filter(line => line.sourceNodeId == startNode.id)[0]?.properties.type
var taskViewUserList = this.curWorkflow.reduce((acc, cur) => acc.concat(cur.properties.userIdList), [] )
this.taskSubmitData = {
taskTitle: `<$ ctx.userInfo.username $>` + '的' + workflowName,
taskStatus: 'running',
taskInfo: JSON.stringify(workflowInfo),
taskFormInput: JSON.stringify(workflowForm),
taskDefaultForm: JSON.stringify(this.defaultWorkflowForm),
taskWorkflow: JSON.stringify(workflowConfig),
taskDefaultWorkflow: JSON.stringify(this.defaultWorkflowConfig),
taskConfigId: startNode.id,
taskLineType: taskLineType,
taskEditUserList: startNode.properties.userIdList.join(','),
taskViewUserList: _.uniq(taskViewUserList).join(','),
taskCreateAt: dayjs().format('YYYY-MM-DD HH:mm:ss'),
taskInitUser: `<$ ctx.userInfo.userId $>`,
taskTemplateGroup,
}
},
async doCreateWork() {
this.isCreateWorkLoading = true
await window.jhMask.show();
await window.jianghuAxios({
data: {
appData: {
pageId: 'workflowManagement',
actionId: 'createTask',
actionData: this.taskSubmitData,
bizIdGenerate: {
tableName: "task",
prefix: "SP",
type: "idSequence",
bizId: "taskId",
},
}
}
})
await window.jhMask.hide();
await window.vtoast.success("申请成功");
this.isCreateWorkLoading = false
},
// -- <<<<<<<<<<<<< 新建任务 --------------------
}
})
</script>
<style scoped>
.omit{
white-space: nowrap;
overflow-x: hidden;
text-overflow: ellipsis;
word-wrap: break-word;
}
.node-box {
display: flex;
}
.node-box .node-box-stepper {
padding: 12px 10px 0px 4px;
}
.node-box .node-box-stepper .vertical-line {
height: 80%;
width: 0px;
margin: 0 auto;
border: #cdcfd1 solid 1px;
}
.node-box .node-box-item .item-label {
margin: 14px 0px 6px;
}
.node-box .node-box-item .item-avatar {
width: 25px;
height: 25px;
color: white;
font-weight: 600;
background-color: #5fb362;
}
.node-box .node-box-item .item-user-box {
min-width: 60px;
height: 40px;
line-height: 40px;
background-color: #edf5fe;
border-radius: 2px;
}
.item-user-box-error{
background-color: rgb(231, 75, 75) !important;
color: white;
}
.node-box-item .abb-user {
height: 40px;
width: 40px;
background-color: #edf5fe;
border-radius: 2px;
}
.node-box-item .abb-user:hover{
background-color: #d6dee7;
}
</style>