feat(bpm): 抽取 useSubApproveUserResolver 统一 username→realname 解析,修复 isEnd 切换时审批意见不响应
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { ref } from 'vue';
|
||||
import { getUserList } from '/@/api/common/api';
|
||||
|
||||
function normalizeCommaList(value: string): string {
|
||||
return String(value || '')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
.join(',');
|
||||
}
|
||||
|
||||
function normalizeDisplayNames(value: string): string {
|
||||
return String(value || '')
|
||||
.split(/[,,;;、]/)
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
.join('、');
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门经办人选人 + 名称解析,统一 BgXiSpeak / DqInspectTask 等 BPM 表单的
|
||||
* username → realname 转换逻辑。
|
||||
*
|
||||
* - `usernames`: 原始 username(逗号分隔),绑定 sz-dept-user-modal 的 v-model
|
||||
* - `displayNames`: 真实姓名(顿号分隔),用于审批意见模板和 formScope
|
||||
* - `setDisplayNames`: modal @confirm 已携带 realname 时直接设置(同步,无 API)
|
||||
* - `initFromData`: 从已保存数据初始化时,通过 API 一次性解析 username → realname
|
||||
*/
|
||||
export function useSubApproveUserResolver() {
|
||||
const usernames = ref('');
|
||||
const displayNames = ref('');
|
||||
|
||||
/** modal @confirm 回调直接设置已携带的 realname */
|
||||
function setDisplayNames(userIds: string, realnames: string) {
|
||||
usernames.value = normalizeCommaList(userIds);
|
||||
displayNames.value = normalizeDisplayNames(realnames);
|
||||
}
|
||||
|
||||
/** 从已保存数据初始化(需 API 解析 username → realname) */
|
||||
async function initFromData(rawUsernames: string) {
|
||||
usernames.value = normalizeCommaList(rawUsernames);
|
||||
if (!usernames.value) {
|
||||
displayNames.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await getUserList({
|
||||
username: usernames.value,
|
||||
isMultiTranslate: 'true',
|
||||
pageNo: 1,
|
||||
pageSize: 999,
|
||||
});
|
||||
const records = res?.records || res?.result?.records || res || [];
|
||||
const nameMap: Record<string, string> = {};
|
||||
for (const item of records) {
|
||||
const u = String(item?.username || '').trim();
|
||||
const r = String(item?.realname || item?.name || '').trim();
|
||||
if (u && r) nameMap[u] = r;
|
||||
}
|
||||
const resolved = usernames.value
|
||||
.split(',')
|
||||
.map((u) => nameMap[u.trim()] || u.trim())
|
||||
.filter(Boolean);
|
||||
displayNames.value = normalizeDisplayNames(resolved.join(','));
|
||||
} catch {
|
||||
// 解析失败,保持空
|
||||
}
|
||||
}
|
||||
|
||||
return { usernames, displayNames, setDisplayNames, initFromData };
|
||||
}
|
||||
Reference in New Issue
Block a user