优化审批流

This commit is contained in:
hero920103 committed 2026-10-07 22:56:35 +08:00
1 parent ffaadc26ae
commit 438145cae7
17 files changed
+1131 -187

No files matched your search

+55 -9
View File
@@ -33,7 +33,6 @@
>
<div class="flow-name">
{{ f.flow_name }}
<el-tag v-if="f.is_default === 1" size="small" type="success">默认</el-tag>
</div>
<div class="flow-code">{{ f.flow_code || '(保存后生成编号)' }}</div>
<div class="flow-sub">
@@ -75,18 +74,23 @@
<el-input v-model="current.description" type="textarea" :rows="2" placeholder="流程用途说明" />
</el-form-item>
<el-row :gutter="12">
<el-col :span="12">
<el-form-item label="设为默认">
<el-switch v-model="current.is_default" :active-value="1" :inactive-value="0" />
<span class="hint">同分类仅一条默认,新申请走默认流程</span>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="启用状态">
<el-switch v-model="current.status" :active-value="1" :inactive-value="0" />
</el-form-item>
</el-col>
</el-row>
<el-form-item label="适用部门">
<el-tree-select v-model="current.apply_dept_ids" :data="orgTree"
multiple show-checkbox check-strictly default-expand-all
:render-after-expand="false"
node-key="id" :props="{ label: 'name', children: 'children', value: 'id' }"
clearable filterable
@change="onDeptChange"
placeholder="留空表示全公司通用(选公司=全员;选部门=覆及子部门)"
style="width:100%" />
<!-- <div class="hint">祖先链命中:选中上级部门或公司时,其下子部门成员都会命中本流程</div> -->
</el-form-item>
</el-form>
<el-divider content-position="left">流程编排(拖拽节点 · 手动连线 · 条件分支)</el-divider>
@@ -119,6 +123,7 @@ import {
saveApprovalFlow,
deleteApprovalFlow
} from '@/api/approval'
import { buildOrgTree } from '@/views/apps/organization/composables'
const modules = ref<any[]>([])
const activeModule = ref<string>('')
@@ -127,7 +132,6 @@ const current = ref<any>(null)
const saving = ref(false)
const canvasRef = ref<any>(null)
// 传给画布的模型:{ nodes, edges }
const graphModel = ref<any>({ nodes: [], edges: [] })
const pools = reactive<{ users: any[]; roles: any[]; orgs: any[]; positions: any[] }>({
@@ -137,6 +141,44 @@ const pools = reactive<{ users: any[]; roles: any[]; orgs: any[]; positions: any
positions: []
})
// 将平面部门列表拼成树(复用组织管理页的 buildOrgTree,内部做 Number 强转)
// 去除空 children 数组,避免 el-tree-select 叶节点渲染异常导致无法点击选中
function stripEmptyChildren(nodes: any[]): any[] {
return nodes.map((n) => {
const node = { ...n }
if (node.children && node.children.length > 0) {
node.children = stripEmptyChildren(node.children)
} else {
delete node.children
}
return node
})
}
const orgTree = computed(() => stripEmptyChildren(buildOrgTree(pools.orgs)))
// 祖先剪枝:若某选中节点的上级(含公司)也已被勾选,则子节点冗余,自动剔除
function pruneRedundantDepts(ids: any[]): number[] {
if (!ids || !ids.length) return []
const numIds = ids.map((v) => Number(v))
const set = new Set(numIds)
const parentOf = new Map<number, number>()
pools.orgs.forEach((o: any) => parentOf.set(Number(o.id), Number(o.parent_id || 0)))
return numIds.filter((id) => {
let p = parentOf.get(id) || 0
const guard = new Set<number>([id])
while (p && parentOf.has(p) && !guard.has(p)) {
if (set.has(p)) return false // 祖先已选 → 冗余
guard.add(p)
p = parentOf.get(p) || 0
}
return true
})
}
function onDeptChange(ids: any[]) {
if (current.value) current.value.apply_dept_ids = pruneRedundantDepts(ids)
}
// 租户侧 6 种审批人类型
const approverTypes = [
{ value: 1, label: '指定用户', needsSelection: true, selectLabel: '审批人', poolKey: 'users' },
@@ -185,6 +227,8 @@ async function selectFlow(id: number) {
const res: any = await getApprovalFlowDetail(id)
if (res.code === 200) {
const d = res.data || {}
// 回显时对历史冗余选择做一次剪枝
d.apply_dept_ids = pruneRedundantDepts(d.apply_dept_ids || [])
current.value = d
graphModel.value = { nodes: d.nodes || [], edges: d.edges || [] }
}
@@ -199,7 +243,8 @@ function openNewFlow() {
flow_code: '',
description: '',
is_default: 0,
status: 1
status: 1,
apply_dept_ids: [] as number[]
}
// 预置开始/结束,方便用户直接拖审批节点连线
graphModel.value = {
@@ -231,6 +276,7 @@ async function saveFlow() {
description: current.value.description,
is_default: current.value.is_default,
status: current.value.status,
apply_dept_ids: current.value.apply_dept_ids || [],
nodes: graph.nodes,
edges: graph.edges
}