mirror of
https://github.com/PlayEdu/backend
synced 2025-06-19 23:02:43 +08:00
资源图片渲染
This commit is contained in:
parent
bbcac7d54a
commit
68d5718b26
@ -42,9 +42,9 @@
|
|||||||
.checked {
|
.checked {
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
background: #fff2f0;
|
background: #ff4d4f;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
border: 2px solid #fff2f0;
|
border: 2px solid #ff4d4f;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 10px;
|
left: 10px;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
@ -52,18 +52,27 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: #ff4d4f;
|
color: #ffffff;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.imageItem {
|
.images-box {
|
||||||
position: relative;
|
display: grid;
|
||||||
width: 150px;
|
gap: 24px;
|
||||||
|
grid-template-columns: repeat(8, minmax(0, 1fr));
|
||||||
|
.imageItem {
|
||||||
|
width: 100%;
|
||||||
height: 150px;
|
height: 150px;
|
||||||
overflow: hidden;
|
background-repeat: no-repeat;
|
||||||
display: flex;
|
background-size: contain;
|
||||||
align-items: center;
|
background-position: center center;
|
||||||
justify-content: center;
|
background-color: #f6f6f6;
|
||||||
background: #f4fafe;
|
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
|
&:hover {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ export const ResourceImagesPage = () => {
|
|||||||
const [total, setTotal] = useState(0);
|
const [total, setTotal] = useState(0);
|
||||||
const [category_ids, setCategoryIds] = useState<any>([]);
|
const [category_ids, setCategoryIds] = useState<any>([]);
|
||||||
const [selectKey, setSelectKey] = useState<any>([]);
|
const [selectKey, setSelectKey] = useState<any>([]);
|
||||||
|
const [visibleArr, setVisibleArr] = useState<any>([]);
|
||||||
|
const [hoverArr, setHoverArr] = useState<any>([]);
|
||||||
|
|
||||||
// 删除图片
|
// 删除图片
|
||||||
const removeResource = () => {
|
const removeResource = () => {
|
||||||
@ -71,6 +73,13 @@ export const ResourceImagesPage = () => {
|
|||||||
.then((res: any) => {
|
.then((res: any) => {
|
||||||
setTotal(res.data.result.total);
|
setTotal(res.data.result.total);
|
||||||
setImageList(res.data.result.data);
|
setImageList(res.data.result.data);
|
||||||
|
let data = res.data.result.data;
|
||||||
|
let arr = [];
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
arr.push(false);
|
||||||
|
}
|
||||||
|
setVisibleArr(arr);
|
||||||
|
setHoverArr(arr);
|
||||||
})
|
})
|
||||||
.catch((err: any) => {
|
.catch((err: any) => {
|
||||||
console.log("错误,", err);
|
console.log("错误,", err);
|
||||||
@ -88,7 +97,9 @@ export const ResourceImagesPage = () => {
|
|||||||
getImageList();
|
getImageList();
|
||||||
}, [category_ids, refresh, page, size]);
|
}, [category_ids, refresh, page, size]);
|
||||||
|
|
||||||
const onChange = (id: number) => {
|
const onChange = (e: any, id: number) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
const arr = [...selectKey];
|
const arr = [...selectKey];
|
||||||
if (arr.indexOf(id) === -1) {
|
if (arr.indexOf(id) === -1) {
|
||||||
arr.push(id);
|
arr.push(id);
|
||||||
@ -110,6 +121,21 @@ export const ResourceImagesPage = () => {
|
|||||||
setSelectKey([]);
|
setSelectKey([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showImage = (index: number, value: boolean) => {
|
||||||
|
const arr = [...visibleArr];
|
||||||
|
arr[index] = value;
|
||||||
|
setVisibleArr(arr);
|
||||||
|
};
|
||||||
|
|
||||||
|
const showHover = (index: number, value: boolean) => {
|
||||||
|
const arr = [...hoverArr];
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
arr[i] = false;
|
||||||
|
}
|
||||||
|
arr[index] = value;
|
||||||
|
setHoverArr(arr);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="tree-main-body">
|
<div className="tree-main-body">
|
||||||
@ -135,7 +161,7 @@ export const ResourceImagesPage = () => {
|
|||||||
<div className="d-flex">
|
<div className="d-flex">
|
||||||
{selectKey.length > 0 && (
|
{selectKey.length > 0 && (
|
||||||
<Button className="mr-16" onClick={() => cancelAll()}>
|
<Button className="mr-16" onClick={() => cancelAll()}>
|
||||||
取消全选
|
取消选择
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<Button className="mr-16" onClick={() => selectAll()}>
|
<Button className="mr-16" onClick={() => selectAll()}>
|
||||||
@ -154,38 +180,52 @@ export const ResourceImagesPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row gutter={[24, 24]}>
|
|
||||||
{imageList.length === 0 && (
|
{imageList.length === 0 && (
|
||||||
|
<div className="d-flex">
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
<Empty description="暂无图片" />
|
<Empty description="暂无图片" />
|
||||||
</Col>
|
</Col>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
<div className={styles["images-box"]}>
|
||||||
{imageList.map((item: any) => (
|
{imageList.map((item: any, index: number) => (
|
||||||
<Col key={item.id} span={3}>
|
<div
|
||||||
<div className={styles.imageItem}>
|
key={item.id}
|
||||||
<i
|
className={styles.imageItem}
|
||||||
className={
|
style={{ backgroundImage: `url(${item.url})` }}
|
||||||
selectKey.indexOf(item.id) === -1
|
onClick={() => showImage(index, true)}
|
||||||
? styles.checkbox
|
onMouseOver={() => showHover(index, true)}
|
||||||
: styles.checked
|
onMouseOut={() => showHover(index, false)}
|
||||||
}
|
|
||||||
onClick={() => onChange(item.id)}
|
|
||||||
>
|
>
|
||||||
{selectKey.indexOf(item.id) !== -1 && <CheckOutlined />}
|
{hoverArr[index] && (
|
||||||
|
<i
|
||||||
|
className={styles.checkbox}
|
||||||
|
onClick={(e) => onChange(e, item.id)}
|
||||||
|
></i>
|
||||||
|
)}
|
||||||
|
{selectKey.indexOf(item.id) !== -1 && (
|
||||||
|
<i
|
||||||
|
className={styles.checked}
|
||||||
|
onClick={(e) => onChange(e, item.id)}
|
||||||
|
>
|
||||||
|
<CheckOutlined />
|
||||||
</i>
|
</i>
|
||||||
|
)}
|
||||||
<Image
|
<Image
|
||||||
preview={true}
|
width={200}
|
||||||
style={{
|
style={{ display: "none" }}
|
||||||
width: "150px",
|
|
||||||
height: "auto",
|
|
||||||
}}
|
|
||||||
src={item.url}
|
src={item.url}
|
||||||
|
preview={{
|
||||||
|
visible: visibleArr[index],
|
||||||
|
src: item.url,
|
||||||
|
onVisibleChange: (value) => {
|
||||||
|
showImage(index, value);
|
||||||
|
},
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
|
||||||
))}
|
))}
|
||||||
|
</div>
|
||||||
{imageList.length > 0 && (
|
{imageList.length > 0 && (
|
||||||
<Col
|
<Col
|
||||||
span={24}
|
span={24}
|
||||||
@ -203,7 +243,6 @@ export const ResourceImagesPage = () => {
|
|||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
)}
|
)}
|
||||||
</Row>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user