feat: 优化语言切换下拉交互并支持玩法规则多语言内容
This commit is contained in:
@@ -6,10 +6,11 @@ import { Loader2 } from "lucide-react";
|
||||
|
||||
import { getPublicSettings } from "@/api";
|
||||
import { PlayerPanel } from "@/components/layout/player-panel";
|
||||
import { resolvePlayRulesHtml } from "@/lib/play-rules-html";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
|
||||
export function PlayRulesScreen() {
|
||||
const { t } = useTranslation("player");
|
||||
const { t, i18n } = useTranslation("player");
|
||||
const [htmlContent, setHtmlContent] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
@@ -17,9 +18,9 @@ export function PlayRulesScreen() {
|
||||
async function loadRules() {
|
||||
try {
|
||||
const res = await getPublicSettings("frontend");
|
||||
const ruleItem = res.items.find((item) => item.key === "frontend.play_rules_html");
|
||||
if (ruleItem && typeof ruleItem.value === "string" && ruleItem.value.trim() !== "") {
|
||||
setHtmlContent(ruleItem.value);
|
||||
const html = resolvePlayRulesHtml(res.items, i18n.language);
|
||||
if (html) {
|
||||
setHtmlContent(html);
|
||||
} else {
|
||||
setHtmlContent(`<div style="text-align:center;padding:2rem;color:#64748b;">${t("rules.empty", { defaultValue: "暂无玩法规则说明" })}</div>`);
|
||||
}
|
||||
@@ -30,7 +31,7 @@ export function PlayRulesScreen() {
|
||||
}
|
||||
}
|
||||
void loadRules();
|
||||
}, [t]);
|
||||
}, [i18n.language, t]);
|
||||
|
||||
return (
|
||||
<PlayerPanel
|
||||
|
||||
Reference in New Issue
Block a user