Commit 3d30aa6c authored by chechunchi's avatar chechunchi

fix single

parent 6a432a7e
......@@ -27,6 +27,7 @@ export default async ({
cancelable,
min: min,
max: max,
single: true,
selecteds: [...selecteds1, ...selecteds2],
mustSelects: [...mustSelect1, ...mustSelect2],
selectables: [...selectable1, ...selectable2],
......
......@@ -19,11 +19,12 @@ const defaultProps: Omit<
> & { isChain: boolean } = {
isOpen: false,
isChain: false,
min: 0,
max: 0,
selecteds: [] as Option[], // 最少选择多少卡
selectables: [] as Option[], // 最多选择多少卡
mustSelects: [] as Option[], // 单选
min: 0, // 最少选择多少卡
max: 0, // 最多选择多少卡
single: false, // 是否只能单选
selecteds: [] as Option[],
selectables: [] as Option[],
mustSelects: [] as Option[],
cancelable: false, // 能否取消
finishable: false, // 选择足够了之后,能否确认
totalLevels: 0, // 需要的总等级数(用于同调/仪式/...)
......@@ -38,6 +39,7 @@ export const SelectActionsModal: React.FC = () => {
isChain,
min,
max,
single,
selecteds,
selectables,
mustSelects,
......@@ -73,6 +75,7 @@ export const SelectActionsModal: React.FC = () => {
isOpen,
min,
max,
single,
selecteds,
selectables,
mustSelects,
......
......@@ -18,6 +18,7 @@ export interface SelectCardsModalProps {
isOpen: boolean;
min: number;
max: number;
single: boolean;
selecteds: Snapshot<Option[]>; // 已经选择了的卡
selectables: Snapshot<Option[]>; // 最多选择多少卡
mustSelects: Snapshot<Option[]>; // 单选
......@@ -34,6 +35,7 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
isOpen,
min,
max,
single,
selecteds: _selecteds,
selectables,
mustSelects,
......@@ -48,7 +50,6 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
// FIXME: handle `selecteds`
const [result, setResult] = useState<Option[]>([]);
const [submitable, setSubmitable] = useState(false);
const single = min === 1 && max === 1; // 是否是单选
const hint = useSnapshot(matStore.hint);
const preHintMsg = hint?.esHint || "";
......@@ -56,6 +57,8 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
const minMaxText = min === max ? min : `${min}-${max}`;
const isMultiple = !single && min > 1;
// 判断是否可以提交
useEffect(() => {
const [sumLevel1, sumLevel2] = (["level1", "level2"] as const).map((key) =>
......@@ -96,7 +99,8 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
<>
<span>{preHintMsg}</span>
<span>{selectHintMsg}</span>
<span>(请选择 {single ? 1 : minMaxText} 张卡)</span>
<span>(请选择 {minMaxText} 张卡)</span>
<span>{single ? "每次选择一张" : ""}</span>
</>
} // TODO: 这里可以再细化一些
width={600}
......@@ -138,10 +142,10 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
<div className="checkcard-container" key={i}>
<CheckCard.Group
onChange={(res) => {
setResult((single ? [res] : res) as any);
setResult((isMultiple ? res : [res]) as any);
}}
// TODO 考虑如何设置默认值,比如只有一个的,就直接选中
multiple={!single}
multiple={isMultiple}
style={{
display: "grid",
gridTemplateColumns: "repeat(6, 1fr)",
......
......@@ -17,12 +17,13 @@ export const SimpleSelectCardsModal: React.FC = () => {
isOpen={isOpen}
min={1}
max={1}
single={false}
selecteds={[]}
mustSelects={[]}
selectables={selectables}
cancelable
finishable={false}
totalLevels={1}
totalLevels={0}
overflow
onSubmit={rs}
onFinish={() => rs([])}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment