| | |
| | | import { matchBusinessTypeValue } from "../approve-list/approveListConstants.js"; |
| | | |
| | | /** |
| | | * 各业务模块与审批模板类型的映射(配置化入口) |
| | | * |
| | | * 各业务模块与审批模板类型的映射(配置化入口) * |
| | | * 使用方式: |
| | | * 1. 在业务页引入 ApprovalTemplateBindDialog,传入 moduleKey |
| | | * 2. 或在表单内嵌 ApprovalTemplateFormSection + useApprovalTemplateBinding({ moduleKey }) |
| | |
| | | OVERTIME: "overtime", |
| | | TRAVEL_REIMBURSE: "travel_reimburse", |
| | | COST_REIMBURSE: "cost_reimburse", |
| | | ENTERPRISE_NEWS: "enterprise_news", |
| | | }; |
| | | |
| | | /** @type {Record<string, import('./approvalModuleRegistry.js').ApprovalModuleConfig>} */ |
| | |
| | | [APPROVAL_MODULE_KEYS.RESIGN]: { |
| | | label: "离职申请", |
| | | approvalType: "resign", |
| | | typeLabels: ["离职", "离职申请"], |
| | | typeLabels: ["离职", "离职申请", "离职审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.WORK_HANDOVER]: { |
| | | label: "工作交接", |
| | | approvalType: "work_handover", |
| | | typeLabels: ["工作交接", "交接"], |
| | | typeLabels: ["工作交接", "交接", "工作交接审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.LEAVE]: { |
| | | label: "请假申请", |
| | | approvalType: "leave", |
| | | typeLabels: ["请假", "请假申请"], |
| | | typeLabels: ["请假", "请假申请", "请假审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.OVERTIME]: { |
| | | label: "加班申请", |
| | | approvalType: "overtime", |
| | | typeLabels: ["加班", "加班申请"], |
| | | typeLabels: ["加班", "加班申请", "加班审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE]: { |
| | | label: "差旅报销", |
| | |
| | | label: "费用报销", |
| | | approvalType: "cost_reimburse", |
| | | typeLabels: ["费用", "费用报销"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.ENTERPRISE_NEWS]: { |
| | | label: "企业新闻", |
| | | approvalType: "enterprise_news", |
| | | typeLabels: ["企业新闻", "新闻", "新闻发布"], |
| | | }, |
| | | }; |
| | | |
| | |
| | | return APPROVAL_MODULE_REGISTRY[moduleKey] || null; |
| | | } |
| | | |
| | | export function listApprovalModuleEntries() { |
| | | return Object.entries(APPROVAL_MODULE_REGISTRY).map(([moduleKey, cfg]) => ({ |
| | | moduleKey, |
| | | ...cfg, |
| | | })); |
| | | /** 列表查询默认 businessType(与审批列表 listPage 约定一致) */ |
| | | export function getModuleListBusinessType(moduleKey) { |
| | | const cfg = getApprovalModuleConfig(moduleKey); |
| | | if (!cfg) return ""; |
| | | if (cfg.businessType != null && cfg.businessType !== "") return cfg.businessType; |
| | | return cfg.approvalType || ""; |
| | | } |
| | | |
| | | /** 从 TypeEnums 选项中解析本模块的 businessType */ |
| | | /** 从 TypeEnums 选项中解析本模块的 businessType(与审批列表下拉一致) */ |
| | | export function resolveModuleBusinessType(moduleKey, typeOptions = []) { |
| | | const cfg = getApprovalModuleConfig(moduleKey); |
| | | if (!cfg) return null; |
| | | if (cfg.businessType != null && cfg.businessType !== "") return cfg.businessType; |
| | | |
| | | const labels = [cfg.label, ...(cfg.typeLabels || [])].filter(Boolean); |
| | | const hit = (typeOptions || []).find((opt) => { |
| | | const hitByLabel = (typeOptions || []).find((opt) => { |
| | | const optLabel = String(opt?.label || "").trim(); |
| | | if (!optLabel) return false; |
| | | return labels.some( |
| | | (l) => optLabel === l || optLabel.includes(l) || l.includes(optLabel) |
| | | ); |
| | | }); |
| | | if (hit?.value != null && hit.value !== "") return hit.value; |
| | | if (hitByLabel?.value != null && hitByLabel.value !== "") return hitByLabel.value; |
| | | |
| | | if (cfg.approvalType) { |
| | | const hitByValue = (typeOptions || []).find( |
| | | (opt) => |
| | | matchBusinessTypeValue(opt?.value, cfg.approvalType) || |
| | | matchBusinessTypeValue(opt?.code, cfg.approvalType) |
| | | ); |
| | | if (hitByValue?.value != null && hitByValue.value !== "") return hitByValue.value; |
| | | } |
| | | |
| | | return cfg.approvalType || null; |
| | | } |
| | | |
| | | /** 收集与模块相关的全部 businessType 取值(枚举值 + approvalType),用于模板列表过滤 */ |
| | | export function getModuleMatchingBusinessTypes(moduleKey, typeOptions = []) { |
| | | const cfg = getApprovalModuleConfig(moduleKey); |
| | | if (!cfg) return []; |
| | | |
| | | const values = new Set(); |
| | | const primary = resolveModuleBusinessType(moduleKey, typeOptions); |
| | | if (primary != null && primary !== "") values.add(primary); |
| | | if (cfg.approvalType) values.add(cfg.approvalType); |
| | | |
| | | const labels = [cfg.label, ...(cfg.typeLabels || [])].filter(Boolean); |
| | | for (const opt of typeOptions || []) { |
| | | const optLabel = String(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]; |
| | | } |