| | |
| | | import { matchBusinessTypeValue } from "../approve-list/approveListConstants.js"; |
| | | |
| | | /** |
| | | * 各业务模块与审批模板类型的映射(配置化入口) |
| | | * |
| | | * 使用方式: |
| | | * 1. 在业务页引入 ApprovalTemplateBindDialog,传入 moduleKey |
| | | * 2. 或在表单内嵌 ApprovalTemplateFormSection + useApprovalTemplateBinding({ moduleKey }) |
| | | * |
| | | * businessType:若后端 TypeEnums 已固定 code,可直接写死 value;否则用 typeLabels 按名称匹配 |
| | | * businessType 与后端 TypeEnums / listPage 约定一致(写死枚举值) |
| | | */ |
| | | export const APPROVAL_MODULE_KEYS = { |
| | | REGULAR: "regular", |
| | |
| | | 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, |
| | | }; |
| | | |
| | | /** @type {Record<string, import('./approvalModuleRegistry.js').ApprovalModuleConfig>} */ |
| | |
| | | [APPROVAL_MODULE_KEYS.REGULAR]: { |
| | | label: "转正申请", |
| | | approvalType: "regular", |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.REGULAR], |
| | | typeLabels: ["转正", "转正申请"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.TRANSFER]: { |
| | | label: "调岗申请", |
| | | approvalType: "transfer", |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.TRANSFER], |
| | | typeLabels: ["调岗", "调动", "调岗申请", "调动申请"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.RESIGN]: { |
| | | label: "离职申请", |
| | | approvalType: "resign", |
| | | typeLabels: ["离职", "离职申请"], |
| | | typeLabels: ["离职", "离职申请", "离职审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.WORK_HANDOVER]: { |
| | | label: "工作交接", |
| | | approvalType: "work_handover", |
| | | typeLabels: ["工作交接", "交接"], |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.WORK_HANDOVER], |
| | | typeLabels: ["工作交接", "交接", "工作交接审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.LEAVE]: { |
| | | label: "请假申请", |
| | | approvalType: "leave", |
| | | typeLabels: ["请假", "请假申请"], |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.LEAVE], |
| | | typeLabels: ["请假", "请假申请", "请假审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.OVERTIME]: { |
| | | label: "加班申请", |
| | | approvalType: "overtime", |
| | | typeLabels: ["加班", "加班申请"], |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.OVERTIME], |
| | | typeLabels: ["加班", "加班申请", "加班审批"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE]: { |
| | | label: "差旅报销", |
| | | approvalType: "travel_reimburse", |
| | | typeLabels: ["差旅", "差旅报销"], |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.TRAVEL_REIMBURSE], |
| | | typeLabels: ["差旅", "差旅报销", "出差报销"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.COST_REIMBURSE]: { |
| | | label: "费用报销", |
| | | approvalType: "cost_reimburse", |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.COST_REIMBURSE], |
| | | typeLabels: ["费用", "费用报销"], |
| | | }, |
| | | [APPROVAL_MODULE_KEYS.ENTERPRISE_NEWS]: { |
| | | label: "企业新闻", |
| | | approvalType: "enterprise_news", |
| | | businessType: APPROVAL_BUSINESS_TYPE[APPROVAL_MODULE_KEYS.ENTERPRISE_NEWS], |
| | | typeLabels: ["企业新闻", "新闻", "新闻发布"], |
| | | }, |
| | | }; |
| | | |
| | | /** |
| | | * @typedef {object} ApprovalModuleConfig |
| | | * @property {string} label |
| | | * @property {string} [approvalType] 列表样式用 |
| | | * @property {string|number} [businessType] 与 TypeEnums value 一致时可写死 |
| | | * @property {string[]} [typeLabels] 与 TypeEnums label 模糊匹配 |
| | | * @property {string} [approvalType] |
| | | * @property {string|number} [businessType] |
| | | * @property {string[]} [typeLabels] |
| | | */ |
| | | |
| | | export function getApprovalModuleConfig(moduleKey) { |
| | |
| | | return APPROVAL_MODULE_REGISTRY[moduleKey] || null; |
| | | } |
| | | |
| | | export function listApprovalModuleEntries() { |
| | | return Object.entries(APPROVAL_MODULE_REGISTRY).map(([moduleKey, cfg]) => ({ |
| | | moduleKey, |
| | | ...cfg, |
| | | })); |
| | | /** 列表查询 businessType(优先配置枚举,不再回退 approvalType 字符串) */ |
| | | 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] ?? ""; |
| | | } |
| | | |
| | | /** 从 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 fixed = getModuleListBusinessType(moduleKey); |
| | | if (fixed != null && fixed !== "") return fixed; |
| | | |
| | | const labels = [cfg.label, ...(cfg.typeLabels || [])].filter(Boolean); |
| | | const hit = (typeOptions || []).find((opt) => { |
| | | const optLabel = String(opt?.label || "").trim(); |
| | | const hitByLabel = (typeOptions || []).find((opt) => { |
| | | const optLabel = String(opt?.label || opt?.name || "").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; |
| | | |
| | | return cfg.approvalType || null; |
| | | } |
| | | |
| | | /** 列表/模板过滤用的 businessType 集合 */ |
| | | 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?.label || opt?.name || "").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]; |
| | | } |