import { $t } from "@/locales"; /** 后端登录失败细分文案 → i18n 键(zh 值 = 后端现有文案,en 值见 locales) */ const AUTH_MSG_KEYS: Record = { "账号或密码错误": "login.auth.invalidCredentials", "用户不存在": "login.auth.userNotFound", "用户已被停用": "login.auth.userDisabled", "验证码不能为空": "login.auth.captchaEmpty", "验证码标识不能为空": "login.auth.captchaIdEmpty", "验证码已过期,请刷新": "login.auth.captchaExpired", "验证码已使用": "login.auth.captchaUsed", "请先完成滑块验证": "login.auth.sliderRequired", "登录类型不能为空": "login.auth.loginTypeEmpty", }; /** 已知后端登录失败文案 → 翻译;未命中返回 null(调用方用通用 fallback) */ export function translateAuthError(msg?: string): string | null { const key = msg ? AUTH_MSG_KEYS[msg] : undefined; return key ? $t(key) : null; }