一单四制优化及加入工作流
This commit is contained in:
71
components/flow/flowAssigneeUtils.js
Normal file
71
components/flow/flowAssigneeUtils.js
Normal file
@@ -0,0 +1,71 @@
|
||||
export const resolveAssigneeIdentityId = (user) => {
|
||||
if (!user) return '';
|
||||
const id = user.identityId ?? user.userIdentityId ?? user.userId ?? '';
|
||||
return id === '' || id == null ? '' : String(id);
|
||||
};
|
||||
|
||||
export const getAssigneeItemKey = (user) => {
|
||||
const identityId = resolveAssigneeIdentityId(user);
|
||||
if (identityId) return `identity-${identityId}`;
|
||||
return `user-${user.userId || user.nickName || ''}`;
|
||||
};
|
||||
|
||||
export const formatAssigneeDisplayName = (user) => {
|
||||
if (!user) return '';
|
||||
if (user.identityName) {
|
||||
return `${user.nickName || user.userName || ''}_${user.identityName}`;
|
||||
}
|
||||
if (user.postName) {
|
||||
return `${user.nickName || user.userName || ''}_${user.postName}`;
|
||||
}
|
||||
return user.nickName || user.userName || user.name || '未知人员';
|
||||
};
|
||||
|
||||
export const normalizeApproverDeptTree = (data) => {
|
||||
if (!data) return [];
|
||||
if (Array.isArray(data)) return data;
|
||||
if (Array.isArray(data.records)) return data.records;
|
||||
if (Array.isArray(data.list)) return data.list;
|
||||
return [];
|
||||
};
|
||||
|
||||
export const findAssigneeUserInDeptTree = (depts, identityId) => {
|
||||
if (!identityId || !Array.isArray(depts)) return null;
|
||||
for (const dept of depts) {
|
||||
const user = (dept.users || []).find(
|
||||
(item) => String(resolveAssigneeIdentityId(item)) === String(identityId)
|
||||
);
|
||||
if (user) return user;
|
||||
if (dept.children?.length) {
|
||||
const found = findAssigneeUserInDeptTree(dept.children, identityId);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/** 将部门树拍平为可渲染行(部门标题 + 人员),避免小程序递归组件不展示子部门 */
|
||||
export const flattenApproverDeptTree = (depts, level = 0) => {
|
||||
const rows = [];
|
||||
if (!Array.isArray(depts)) return rows;
|
||||
for (const dept of depts) {
|
||||
rows.push({
|
||||
type: 'dept',
|
||||
key: `dept-${dept.deptId ?? dept.deptName ?? level}`,
|
||||
deptName: dept.deptName || '',
|
||||
level
|
||||
});
|
||||
for (const user of dept.users || []) {
|
||||
rows.push({
|
||||
type: 'user',
|
||||
key: getAssigneeItemKey(user),
|
||||
user,
|
||||
level: level + 1
|
||||
});
|
||||
}
|
||||
if (dept.children?.length) {
|
||||
rows.push(...flattenApproverDeptTree(dept.children, level + 1));
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
};
|
||||
Reference in New Issue
Block a user