Skip to content

Commit

Permalink
fix: 🐛 图片大小的筛选问题
Browse files Browse the repository at this point in the history
Closes: #88
  • Loading branch information
meetqy committed Mar 6, 2023
1 parent dbdd523 commit dc01e32
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/JustifyLayout/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const JustifyLayoutSearch = (props: Props) => {
{!hidden && (
<Col>
<SearchModule.Size
value={params.size}
onChange={(e) =>
onChange({
...params,
Expand Down
23 changes: 18 additions & 5 deletions components/JustifyLayout/SearchModule/Size.tsx
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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(() => {
Expand Down Expand Up @@ -69,6 +78,7 @@ const Size = (props: Props) => {
<InputNumber
value={value.width.min}
onChange={(e) => changeValue(e, "width", "min")}
onBlur={() => props?.onChange(value)}
placeholder="最小"
size="small"
min={0}
Expand All @@ -77,6 +87,7 @@ const Size = (props: Props) => {
<InputNumber
value={value.width.max}
onChange={(e) => changeValue(e, "width", "max")}
onBlur={() => props?.onChange(value)}
placeholder="最大"
size="small"
min={0}
Expand All @@ -89,6 +100,7 @@ const Size = (props: Props) => {
<InputNumber
value={value.height.min}
onChange={(e) => changeValue(e, "height", "min")}
onBlur={() => props?.onChange(value)}
placeholder="最小"
size="small"
min={0}
Expand All @@ -97,6 +109,7 @@ const Size = (props: Props) => {
<InputNumber
value={value.height.max}
onChange={(e) => changeValue(e, "height", "max")}
onBlur={() => props?.onChange(value)}
placeholder="最大"
size="small"
min={0}
Expand Down
1 change: 0 additions & 1 deletion components/JustifyLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion hooks/prismaInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function getLoadMoreList(params: Params): Promise<Result> {
body: JSON.stringify({
where: {
AND: [
handleSize({ size: body.size }),
...handleSize({ size: body.size }),
!_.isEmpty(body.tags)
? { tags: { some: { id: { in: body.tags } } } }
: undefined,
Expand Down

0 comments on commit dc01e32

Please sign in to comment.