From dc01e32cc393a6985901885708b44a3339667429 Mon Sep 17 00:00:00 2001 From: meetqy Date: Mon, 6 Mar 2023 17:07:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E7=9A=84=E7=AD=9B=E9=80=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #88 --- components/JustifyLayout/Search.tsx | 1 + .../JustifyLayout/SearchModule/Size.tsx | 23 +++++++++++++++---- components/JustifyLayout/index.tsx | 1 - hooks/prismaInput.ts | 2 +- pages/index.tsx | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/components/JustifyLayout/Search.tsx b/components/JustifyLayout/Search.tsx index 60f113c5..cd35cc3f 100644 --- a/components/JustifyLayout/Search.tsx +++ b/components/JustifyLayout/Search.tsx @@ -76,6 +76,7 @@ const JustifyLayoutSearch = (props: Props) => { {!hidden && ( onChange({ ...params, diff --git a/components/JustifyLayout/SearchModule/Size.tsx b/components/JustifyLayout/SearchModule/Size.tsx index f894d523..57744458 100644 --- a/components/JustifyLayout/SearchModule/Size.tsx +++ b/components/JustifyLayout/SearchModule/Size.tsx @@ -1,9 +1,11 @@ import { CaretDownOutlined } from "@ant-design/icons"; import { Col, InputNumber, Popover, Row, Typography } from "antd"; -import { useMemo, useState } from "react"; +import _ from "lodash"; +import { useEffect, useMemo, useState } from "react"; interface Props { - onChange?: (value: EagleUse.SearchParams["size"]) => void; + value: EagleUse.SearchParams["size"]; + onChange: (value: EagleUse.SearchParams["size"]) => void; } const Size = (props: Props) => { @@ -18,17 +20,24 @@ const Size = (props: Props) => { }, }); + useEffect(() => { + if (_.isEqual(props.value, value)) return; + if (!props.value) return; + + setValue(props.value); + }, [props.value, value]); + const changeValue = ( e: number, size: "width" | "height", type: "min" | "max" ) => { - value[size][type] = e; + const newValue = JSON.parse(JSON.stringify(value)); + newValue[size][type] = e; setValue({ ...value, + [size]: newValue[size], }); - - props?.onChange(value); }; const text = useMemo(() => { @@ -69,6 +78,7 @@ const Size = (props: Props) => { changeValue(e, "width", "min")} + onBlur={() => props?.onChange(value)} placeholder="最小" size="small" min={0} @@ -77,6 +87,7 @@ const Size = (props: Props) => { changeValue(e, "width", "max")} + onBlur={() => props?.onChange(value)} placeholder="最大" size="small" min={0} @@ -89,6 +100,7 @@ const Size = (props: Props) => { changeValue(e, "height", "min")} + onBlur={() => props?.onChange(value)} placeholder="最小" size="small" min={0} @@ -97,6 +109,7 @@ const Size = (props: Props) => { changeValue(e, "height", "max")} + onBlur={() => props?.onChange(value)} placeholder="最大" size="small" min={0} diff --git a/components/JustifyLayout/index.tsx b/components/JustifyLayout/index.tsx index ac4fd2b3..f572bbf7 100644 --- a/components/JustifyLayout/index.tsx +++ b/components/JustifyLayout/index.tsx @@ -65,7 +65,6 @@ const JustifyLayout = ({ infiniteScroll, header }: Props) => { useEffect(() => { if (!size || !size.width) return; const clientWidth = size.width; - console.log(images); setLayoutPos( justifyLayout([...images], { containerWidth: diff --git a/hooks/prismaInput.ts b/hooks/prismaInput.ts index dcb38ec0..fd652984 100644 --- a/hooks/prismaInput.ts +++ b/hooks/prismaInput.ts @@ -8,7 +8,7 @@ export const handleOrderBy = ({ orderBy }: EagleUse.SearchParams) => { // 尺寸 export const handleSize = ({ size }: EagleUse.SearchParams) => { - if (!size) return undefined; + if (!size) return []; const { width, height } = size; diff --git a/pages/index.tsx b/pages/index.tsx index 6f4231ba..2660eb79 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -35,7 +35,7 @@ function getLoadMoreList(params: Params): Promise { body: JSON.stringify({ where: { AND: [ - handleSize({ size: body.size }), + ...handleSize({ size: body.size }), !_.isEmpty(body.tags) ? { tags: { some: { id: { in: body.tags } } } } : undefined,