Files
offerpai_web/src/utils/industry.ts
T

21 lines
733 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 { IndustryItem } from '@/api/common'
/**
* 根据行业 ID 从 store 行业树中查找对应的行业名称
* 遍历一级→二级,匹配到即返回名称,未匹配返回 ID 本身
* @param id 行业 ID(如 12
* @returns 匹配到的行业名称,未匹配则返回 ID 字符串
*/
export function resolveIndustryName(id: number): string {
if (!id && id !== 0) return ''
const industries: IndustryItem[] = store.state.industries
for (const parent of industries) {
if (String(parent.id) === String(id)) return parent.name
for (const child of parent.children) {
if (String(child.id) === String(id)) return child.name
}
}
return String(id)
}