21 lines
733 B
TypeScript
21 lines
733 B
TypeScript
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)
|
||
}
|