Commit 3d30aa6c authored by chechunchi's avatar chechunchi

fix single

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