|
/** 与 Web approvalModuleRegistry 一致 */
|
export const APPROVAL_MODULE_KEYS = {
|
REGULAR: "regular",
|
TRANSFER: "transfer",
|
WORK_HANDOVER: "work_handover",
|
LEAVE: "leave",
|
OVERTIME: "overtime",
|
TRAVEL_REIMBURSE: "travel_reimburse",
|
COST_REIMBURSE: "cost_reimburse",
|
ENTERPRISE_NEWS: "enterprise_news",
|
};
|
|
/** 审批实例 listPage businessType(与后端约定一致) */
|
export const APPROVAL_BUSINESS_TYPE = {
|
[APPROVAL_MODULE_KEYS.REGULAR]: 10,
|
[APPROVAL_MODULE_KEYS.TRANSFER]: 11,
|
[APPROVAL_MODULE_KEYS.WORK_HANDOVER]: 13,
|
[APPROVAL_MODULE_KEYS.LEAVE]: 14,
|
[APPROVAL_MODULE_KEYS.OVERTIME]: 15,
|
[APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE]: 16,
|
[APPROVAL_MODULE_KEYS.COST_REIMBURSE]: 17,
|
[APPROVAL_MODULE_KEYS.ENTERPRISE_NEWS]: 18,
|
};
|
|
export const APPROVAL_MODULE_REGISTRY = {
|
[APPROVAL_MODULE_KEYS.REGULAR]: {
|
label: "转正申请",
|
approvalType: "regular",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.REGULAR],
|
typeLabels: ["转正", "转正申请"],
|
listFields: [
|
{ label: "入职日期", prop: "entryDate" },
|
{ label: "转正日期", prop: "regularDate" },
|
],
|
},
|
[APPROVAL_MODULE_KEYS.TRANSFER]: {
|
label: "调岗申请",
|
approvalType: "transfer",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.TRANSFER],
|
typeLabels: ["调岗", "调动", "调岗申请", "调动申请"],
|
listFields: [
|
{ label: "原岗位", prop: "fromPost" },
|
{ label: "目标岗位", prop: "toPost" },
|
],
|
},
|
[APPROVAL_MODULE_KEYS.WORK_HANDOVER]: {
|
label: "工作交接",
|
approvalType: "work_handover",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.WORK_HANDOVER],
|
typeLabels: ["工作交接", "交接", "工作交接审批"],
|
listFields: [
|
{ label: "交接人", prop: "handoverTo" },
|
{ label: "交接事项", prop: "handoverItems" },
|
],
|
},
|
[APPROVAL_MODULE_KEYS.LEAVE]: {
|
label: "请假申请",
|
approvalType: "leave",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.LEAVE],
|
typeLabels: ["请假", "请假申请", "请假审批"],
|
listFields: [
|
{ label: "请假类型", prop: "leaveType" },
|
{ label: "开始时间", prop: "startTime" },
|
{ label: "结束时间", prop: "endTime" },
|
],
|
},
|
[APPROVAL_MODULE_KEYS.OVERTIME]: {
|
label: "加班申请",
|
approvalType: "overtime",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.OVERTIME],
|
typeLabels: ["加班", "加班申请", "加班审批"],
|
listFields: [
|
{ label: "加班日期", prop: "overtimeDate" },
|
{ label: "时长(小时)", prop: "hours" },
|
],
|
},
|
[APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE]: {
|
label: "差旅报销",
|
approvalType: "travel_reimburse",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE],
|
typeLabels: ["差旅", "差旅报销", "出差报销"],
|
listFields: [],
|
},
|
[APPROVAL_MODULE_KEYS.COST_REIMBURSE]: {
|
label: "费用报销",
|
approvalType: "cost_reimburse",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.COST_REIMBURSE],
|
typeLabels: ["费用", "费用报销"],
|
listFields: [],
|
},
|
[APPROVAL_MODULE_KEYS.ENTERPRISE_NEWS]: {
|
label: "企业新闻",
|
approvalType: "enterprise_news",
|
businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.ENTERPRISE_NEWS],
|
typeLabels: ["企业新闻", "新闻", "新闻发布"],
|
listFields: [],
|
},
|
};
|
|
export function getApprovalModuleConfig(moduleKey) {
|
if (!moduleKey) return null;
|
return APPROVAL_MODULE_REGISTRY[moduleKey] || null;
|
}
|
|
export function getModuleListBusinessType(moduleKey) {
|
const cfg = getApprovalModuleConfig(moduleKey);
|
if (!cfg) return "";
|
if (cfg.businessType != null && cfg.businessType !== "") return cfg.businessType;
|
return APPROVAL_BUSINESS_TYPE[moduleKey] ?? "";
|
}
|
|
function matchBiz(a, b) {
|
if (a == null || a === "" || b == null || b === "") return false;
|
return a === b || a === Number(b) || Number(a) === b || String(a) === String(b);
|
}
|
|
export function resolveModuleBusinessType(moduleKey, typeOptions = []) {
|
const cfg = getApprovalModuleConfig(moduleKey);
|
if (!cfg) return null;
|
|
const fixed = getModuleListBusinessType(moduleKey);
|
if (fixed != null && fixed !== "") return fixed;
|
|
const labels = [cfg.label, ...(cfg.typeLabels || [])].filter(Boolean);
|
const hitByLabel = (typeOptions || []).find(opt => {
|
const optLabel = String(opt?.name || opt?.label || "").trim();
|
if (!optLabel) return false;
|
return labels.some(
|
l => optLabel === l || optLabel.includes(l) || l.includes(optLabel)
|
);
|
});
|
if (hitByLabel?.value != null && hitByLabel.value !== "") return hitByLabel.value;
|
|
if (cfg.approvalType) {
|
const hitByValue = (typeOptions || []).find(
|
opt =>
|
matchBiz(opt?.value, cfg.approvalType) || matchBiz(opt?.code, cfg.approvalType)
|
);
|
if (hitByValue?.value != null && hitByValue.value !== "") return hitByValue.value;
|
}
|
|
return null;
|
}
|
|
export function getModuleMatchingBusinessTypes(moduleKey, typeOptions = []) {
|
const cfg = getApprovalModuleConfig(moduleKey);
|
if (!cfg) return [];
|
|
const fixed = getModuleListBusinessType(moduleKey);
|
if (fixed != null && fixed !== "") return [fixed];
|
|
const values = new Set();
|
const primary = resolveModuleBusinessType(moduleKey, typeOptions);
|
if (primary != null && primary !== "") values.add(primary);
|
|
const labels = [cfg.label, ...(cfg.typeLabels || [])].filter(Boolean);
|
for (const opt of typeOptions || []) {
|
const optLabel = String(opt?.name || opt?.label || "").trim();
|
if (!optLabel) continue;
|
const matched = labels.some(
|
l => optLabel === l || optLabel.includes(l) || l.includes(optLabel)
|
);
|
if (matched && opt.value != null && opt.value !== "") {
|
values.add(opt.value);
|
}
|
}
|
return [...values];
|
}
|
|
export const PAGE_KEY_TO_MODULE = {
|
"HrManage/regular-apply": APPROVAL_MODULE_KEYS.REGULAR,
|
"HrManage/transfer-apply": APPROVAL_MODULE_KEYS.TRANSFER,
|
"HrManage/work-handover": APPROVAL_MODULE_KEYS.WORK_HANDOVER,
|
"AttendManage/leave-apply": APPROVAL_MODULE_KEYS.LEAVE,
|
"AttendManage/overtime-apply": APPROVAL_MODULE_KEYS.OVERTIME,
|
"ReimburseManage/travel-reimburse": APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE,
|
"ReimburseManage/cost-reimburse": APPROVAL_MODULE_KEYS.COST_REIMBURSE,
|
"EnterpriseNews/news-manage": APPROVAL_MODULE_KEYS.ENTERPRISE_NEWS,
|
};
|
|
export function getModuleKeyFromPageKey(pageKey) {
|
return PAGE_KEY_TO_MODULE[pageKey] || "";
|
}
|