Skip to content

Commit fae712b

Browse files
committed
仿钉钉流程设计- 表单字段权限设置
1 parent 6ad29c6 commit fae712b

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/components/SimpleProcessDesignerV2/src/nodes-config/UserTaskNodeConfig.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,11 @@ const saveConfig = async () => {
413413
if (!showText) return false
414414
currentNode.value.candidateStrategy = configForm.value.candidateStrategy
415415
currentNode.value.candidateParam = configForm.value.candidateParamArray?.join(',')
416+
// 设置审批方式
417+
currentNode.value.approveMethod = configForm.value.approveMethod
418+
if (configForm.value.approveMethod === ApproveMethodType.APPROVE_BY_RATIO) {
419+
currentNode.value.approveRatio = configForm.value.approveRatio
420+
}
416421
// 设置拒绝处理
417422
currentNode.value.rejectHandler = {
418423
type: configForm.value.rejectHandlerType,
@@ -547,6 +552,11 @@ const setCurrentNode = (node: SimpleFlowNode) => {
547552
} else {
548553
notAllowedMultiApprovers.value = false
549554
}
555+
// 设置审批方式
556+
configForm.value.approveMethod = node.approveMethod
557+
if (node.approveMethod == ApproveMethodType.APPROVE_BY_RATIO) {
558+
configForm.value.approveRatio = node.approveRatio
559+
}
550560
configForm.value.rejectHandlerType = node.rejectHandler?.type
551561
configForm.value.returnNodeId = node.rejectHandler?.returnNodeId
552562
configForm.value.timeoutHandlerEnable = node.timeoutHandler?.enable

src/views/bpm/processInstance/detail/index.vue

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ const handleAudit = async (task, pass) => {
200200
// 1.2 校验表单
201201
const elForm = unref(auditFormRef)
202202
if (!elForm) return
203-
const valid = await elForm.validate()
203+
let valid = await elForm.validate()
204+
if (!valid) return
205+
// 校验申请表单
206+
if (!fApi.value) return
207+
valid = await fApi.value.validate()
204208
if (!valid) return
205209
206210
// 2.1 提交审批
@@ -216,6 +220,9 @@ const handleAudit = async (task, pass) => {
216220
await formCreateApi.validate()
217221
data.variables = approveForms.value[index].value
218222
}
223+
// 获取表单可编辑字段的值
224+
data.variables = getWritableValueOfForm(task.fieldsPermission)
225+
219226
await TaskApi.approveTask(data)
220227
message.success('审批通过成功')
221228
} else {
@@ -251,11 +258,11 @@ const handleSign = async (task: any) => {
251258
}
252259
253260
/** 获得详情 */
254-
const getDetail = () => {
255-
// 1. 获得流程实例相关
261+
const getDetail = async () => {
262+
// 1. 获得流程任务列表(审批记录)。 需要先获取任务,表单的权限设置需要根据任务来设置
263+
await getTaskList()
264+
// 2. 获得流程实例相关
256265
getProcessInstance()
257-
// 2. 获得流程任务列表(审批记录)
258-
getTaskList()
259266
}
260267
261268
/** 加载流程实例 */
@@ -283,6 +290,15 @@ const getProcessInstance = async () => {
283290
fApi.value?.btn.show(false)
284291
fApi.value?.resetBtn.show(false)
285292
fApi.value?.disabled(true)
293+
// 设置表单权限。后续需要改造成。只处理一个运行中的任务
294+
if (runningTasks.value.length > 0) {
295+
const task = runningTasks.value.at(0)
296+
if (task.fieldsPermission) {
297+
Object.keys(task.fieldsPermission).forEach((item) => {
298+
setFieldPermission(item, task.fieldsPermission[item])
299+
})
300+
}
301+
}
286302
})
287303
} else {
288304
// 注意:data.processDefinition.formCustomViewPath 是组件的全路径,例如说:/crm/contract/detail/index.vue
@@ -353,6 +369,7 @@ const loadRunningTask = (tasks) => {
353369
if (!task.assigneeUser || task.assigneeUser.id !== userId) {
354370
return
355371
}
372+
356373
// 2.3 添加到处理任务
357374
runningTasks.value.push({ ...task })
358375
auditForms.value.push({
@@ -371,6 +388,35 @@ const loadRunningTask = (tasks) => {
371388
})
372389
}
373390
391+
/**
392+
* 设置表单权限
393+
*/
394+
const setFieldPermission = (field: string, permission: string) => {
395+
if (permission === '1') {
396+
fApi.value?.disabled(true, field)
397+
}
398+
if (permission === '2') {
399+
fApi.value?.disabled(false, field)
400+
}
401+
if (permission === '3') {
402+
fApi.value?.hidden(true, field)
403+
}
404+
}
405+
/**
406+
* 获取可以编辑字段的值
407+
*/
408+
const getWritableValueOfForm = (fieldsPermission: Object) => {
409+
const fieldsValue = {}
410+
if (fieldsPermission && fApi.value) {
411+
Object.keys(fieldsPermission).forEach((item) => {
412+
if (fieldsPermission[item] === '2') {
413+
fieldsValue[item] = fApi.value.getValue(item)
414+
}
415+
})
416+
}
417+
return fieldsValue
418+
}
419+
374420
/** 初始化 */
375421
const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
376422
onMounted(async () => {

0 commit comments

Comments
 (0)