This commit is contained in:
guochunsi
2026-01-14 18:32:09 +08:00
parent 6055033289
commit 8166fa31e0
33 changed files with 3926 additions and 3383 deletions

35
src/utils/dictLabel.ts Normal file
View File

@@ -0,0 +1,35 @@
// 通用:根据字典列表和 value 获取 label 文本
export function getLabelValue(
list: Array<{ label: string; value: string | number }>,
value: string | number | null | undefined,
): string {
if (!list || !Array.isArray(list)) return ''
const item = list.find((it: any) => String(it.value) === String(value))
return item ? item.label : ''
}
// 通用:根据指定 key/value 字段,从列表中取 label原 global.getLabelValueByPropes
export function getLabelValueByProps(
list: any[],
key: string | number | null | undefined,
props: { key: string; value: string },
): string {
if (!list || !Array.isArray(list)) return ''
const item = list.find((it: any) => String(it[props.key]) === String(key))
return item ? item[props.value] : ''
}
// 通用:根据 key 取“专业名称 || 学制年制”展示(原 global.getLabelValueByPropes2
export function getMajorLabelWithYears(
list: any[],
key: string | number | null | undefined,
props: { key: string; value: string },
): string {
if (!list || !Array.isArray(list)) return ''
const item = list.find((it: any) => String(it[props.key]) === String(key))
if (!item) return ''
const majorName = item[props.value] ?? ''
const years = item.xz != null ? `${item.xz} 年制` : ''
return years ? `${majorName} || ${years}` : majorName
}