Files
offerpai_web/src/utils/jobCategory.ts
T

26 lines
896 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import store from '@/stores/index'
import type { JobCategoryItem } from '@/api/common'
/**
* 根据岗位分类 ID 从 store 岗位树中查找对应的岗位名称
* 遍历一级→二级→三级,匹配到即返回名称,未匹配返回 ID 本身
* @param id 岗位分类 ID(如 305
* @returns 匹配到的岗位名称,未匹配则返回 ID 字符串
*/
export function resolveJobCategoryName(id: number): string {
if (!id && id !== 0) return ''
const categories: JobCategoryItem[] = store.state.jobCategories
for (const lv1 of categories) {
if (String(lv1.id) === String(id)) return lv1.name
for (const lv2 of lv1.children) {
if (String(lv2.id) === String(id)) return lv2.name
if (lv2.children) {
for (const lv3 of lv2.children) {
if (String(lv3.id) === String(id)) return lv3.name
}
}
}
}
return String(id)
}