import { APPROVAL_MODULE_KEYS } from "./approvalModuleRegistry.js";
|
|
/** 支持审批单号查询/主表展示的审批申请模块 */
|
export const INSTANCE_NO_SEARCH_MODULE_KEYS = new Set([
|
APPROVAL_MODULE_KEYS.REGULAR,
|
APPROVAL_MODULE_KEYS.TRANSFER,
|
APPROVAL_MODULE_KEYS.WORK_HANDOVER,
|
APPROVAL_MODULE_KEYS.LEAVE,
|
APPROVAL_MODULE_KEYS.OVERTIME,
|
]);
|
|
export const INSTANCE_NO_TABLE_COLUMN = {
|
label: "审批单号",
|
prop: "instanceNo",
|
width: 170,
|
showOverflowTooltip: true,
|
};
|
|
/** 扁平化为 Spring GET 可绑定的 query(approvalInstanceDto.xxx,勿用方括号) */
|
export function appendDotNotationQuery(target, prefix, fields) {
|
if (!fields || typeof fields !== "object") return;
|
for (const [key, value] of Object.entries(fields)) {
|
if (value == null || value === "") continue;
|
target[`${prefix}.${key}`] = value;
|
}
|
}
|
|
function pickApplicantFromSearchForm(searchForm = {}) {
|
const out = {};
|
const sf = searchForm || {};
|
const name = (sf.applicantName || "").trim();
|
const kw = (sf.applicantKeyword || "").trim();
|
const id = sf.applicantId;
|
|
if (name) out.applicantName = name;
|
if (kw) {
|
out.applicantName = kw;
|
if (/^\d+$/.test(kw)) out.applicantId = Number(kw);
|
}
|
if (id != null && id !== "") {
|
out.applicantId = typeof id === "number" ? id : Number(id) || id;
|
}
|
return out;
|
}
|
|
function pickInstanceNoFromSearchForm(searchForm = {}) {
|
const no = (searchForm?.instanceNo || "").trim();
|
return no ? { instanceNo: no } : {};
|
}
|
|
/** 组装 approvalInstanceDto 查询片段(申请人 + 审批单号) */
|
export function buildApprovalInstanceSearchDto(searchForm = {}, extraParams = {}) {
|
const dto = {
|
...(extraParams && typeof extraParams === "object" ? extraParams : {}),
|
};
|
Object.assign(dto, pickApplicantFromSearchForm(searchForm));
|
Object.assign(dto, pickInstanceNoFromSearchForm(searchForm));
|
delete dto.createTime;
|
delete dto.createTimeStart;
|
delete dto.createTimeEnd;
|
return dto;
|
}
|
|
function getRowPayloadValue(row, keys) {
|
const keyList = Array.isArray(keys) ? keys : [keys];
|
const payload = row?.formPayload || {};
|
for (const k of keyList) {
|
if (row?.[k] != null && row[k] !== "") return row[k];
|
if (payload[k] != null && payload[k] !== "") return payload[k];
|
}
|
return "";
|
}
|
|
function matchApplicantKeyword(row, keyword) {
|
const kw = (keyword || "").trim().toLowerCase();
|
if (!kw) return true;
|
const parts = [
|
row?.applicantName,
|
row?.applicantNo,
|
row?.applicantId,
|
getRowPayloadValue(row, ["applicant", "applicantName", "applicantId"]),
|
]
|
.filter((v) => v != null && v !== "")
|
.map((v) => String(v).toLowerCase());
|
return parts.some((p) => p.includes(kw));
|
}
|
|
function matchApplicantId(row, applicantId) {
|
if (applicantId == null || applicantId === "") return true;
|
const id = String(applicantId);
|
if (row?.applicantId != null && String(row.applicantId) === id) return true;
|
const payloadApplicant = getRowPayloadValue(row, [
|
"applicant",
|
"applicantId",
|
"applicantUserId",
|
]);
|
return String(payloadApplicant) === id;
|
}
|
|
function matchSelectValue(row, keys, expected) {
|
if (!expected) return true;
|
const raw = getRowPayloadValue(row, keys);
|
return String(raw) === String(expected);
|
}
|
|
function matchInstanceNo(row, instanceNo) {
|
const kw = (instanceNo || "").trim().toLowerCase();
|
if (!kw) return true;
|
const parts = [row?.instanceNo, row?.bizId]
|
.filter((v) => v != null && v !== "")
|
.map((v) => String(v).toLowerCase());
|
return parts.some((p) => p.includes(kw));
|
}
|
|
/** 是否存在列表筛选条件(申请人 / 审批单号) */
|
export function hasActiveModuleSearch(moduleKey, searchForm = {}) {
|
const sf = searchForm || {};
|
if ((sf.instanceNo || "").trim()) return true;
|
if ((sf.applicantKeyword || "").trim()) return true;
|
if ((sf.applicantName || "").trim()) return true;
|
return sf.applicantId != null && sf.applicantId !== "";
|
}
|
|
/** 按申请人、审批单号做前端兜底筛选 */
|
export function filterInstanceRowsByModuleSearch(moduleKey, rows, searchForm = {}) {
|
const sf = searchForm || {};
|
const list = Array.isArray(rows) ? rows : [];
|
if (!hasActiveModuleSearch(moduleKey, sf)) return list;
|
|
return list.filter(
|
(row) =>
|
matchInstanceNo(row, sf.instanceNo) &&
|
matchApplicantId(row, sf.applicantId) &&
|
matchApplicantKeyword(row, sf.applicantKeyword || sf.applicantName)
|
);
|
}
|