refactor: invert dice interaction

This commit is contained in:
hypercross 2026-03-25 14:08:29 +08:00
parent 33d29252dc
commit 8af559fe1c
1 changed files with 6 additions and 7 deletions

View File

@ -54,7 +54,8 @@ customElement("md-dice", { key: "" }, (props, { element }) => {
} }
}); });
const handleRoll = () => { const handleRoll = (e: MouseEvent) => {
e.preventDefault();
// 点击骰子图标:总是重 roll // 点击骰子图标:总是重 roll
const rollResult = rollFormula(formula).result; const rollResult = rollFormula(formula).result;
setResult(rollResult.total); setResult(rollResult.total);
@ -65,7 +66,8 @@ customElement("md-dice", { key: "" }, (props, { element }) => {
} }
}; };
const handleTextClick = () => { const handleTextClick = (e: MouseEvent) => {
e.preventDefault();
// 点击文本:总是重置为公式 // 点击文本:总是重置为公式
setResult(null); setResult(null);
setIsRolled(false); setIsRolled(false);
@ -80,17 +82,14 @@ customElement("md-dice", { key: "" }, (props, { element }) => {
return ( return (
<span class="inline-flex items-center px-1"> <span class="inline-flex items-center px-1">
<span <span
onClick={(e) => { onClick={handleTextClick}
e.preventDefault();
handleRoll();
}}
class="text-blue-600 hover:text-blue-800 cursor-pointer" class="text-blue-600 hover:text-blue-800 cursor-pointer"
title={rollDetail() || "掷骰子"} title={rollDetail() || "掷骰子"}
> >
🎲 🎲
</span> </span>
<a <a
onClick={handleTextClick} onClick={handleRoll}
class="cursor-pointer text-gray-700 hover:text-gray-900" class="cursor-pointer text-gray-700 hover:text-gray-900"
title={isRolled() ? "点击重置为公式" : formula} title={isRolled() ? "点击重置为公式" : formula}
> >