2026-06-04 16:25:38 +08:00
|
|
|
|
import type { DictValueEnumObj } from '@/components/DictTag';
|
|
|
|
|
|
|
|
|
|
|
|
/** 字典值转展示文案 */
|
|
|
|
|
|
export function getDictLabel(
|
|
|
|
|
|
enums: DictValueEnumObj | Record<string, any>,
|
|
|
|
|
|
value?: string | number | null,
|
|
|
|
|
|
): string {
|
|
|
|
|
|
if (value === null || value === undefined || value === '') {
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
const strVal = String(value);
|
|
|
|
|
|
if (!enums || !Object.keys(enums).length) {
|
|
|
|
|
|
return strVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const direct = enums[strVal] ?? enums[Number(value)];
|
|
|
|
|
|
if (direct) {
|
|
|
|
|
|
return direct.label || direct.text || strVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const matched = Object.values(enums).find((item: any) => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
String(item.value) === strVal ||
|
|
|
|
|
|
String(item.key) === strVal ||
|
|
|
|
|
|
String(item.id) === strVal
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matched) {
|
|
|
|
|
|
return (matched as any).label || (matched as any).text || strVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return strVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 树形数据 id 转 label(岗位分类 / 行业等) */
|
|
|
|
|
|
export function findTreeLabelById(
|
|
|
|
|
|
nodes: any[] | undefined,
|
|
|
|
|
|
id?: string | number | null,
|
|
|
|
|
|
): string {
|
|
|
|
|
|
if (id === null || id === undefined || id === '') {
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
const idStr = String(id);
|
|
|
|
|
|
if (!nodes?.length) {
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const node of nodes) {
|
|
|
|
|
|
const nodeId = String(node.id ?? node.value ?? '');
|
|
|
|
|
|
if (nodeId === idStr) {
|
|
|
|
|
|
return node.label ?? node.title ?? '';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (node.children?.length) {
|
|
|
|
|
|
const childLabel = findTreeLabelById(node.children, id);
|
|
|
|
|
|
if (childLabel) {
|
|
|
|
|
|
return childLabel;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-04 17:15:41 +08:00
|
|
|
|
/** 所属行业:数字 id 走行业树,已是文案则直接展示 */
|
|
|
|
|
|
export function resolveIndustryLabel(
|
|
|
|
|
|
tree: any[] | undefined,
|
|
|
|
|
|
value?: string | number | null,
|
|
|
|
|
|
): string {
|
|
|
|
|
|
const str = value == null ? '' : String(value).trim();
|
|
|
|
|
|
if (!str) return '';
|
|
|
|
|
|
if (/^\d+$/.test(str)) {
|
|
|
|
|
|
return findTreeLabelById(tree, str) || str;
|
|
|
|
|
|
}
|
|
|
|
|
|
return str;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-04 16:25:38 +08:00
|
|
|
|
/** @deprecated 使用 findTreeLabelById */
|
|
|
|
|
|
export const findIndustryLabelInTree = findTreeLabelById;
|