Commit 4fbf5765 authored by 张烨's avatar 张烨

style: 优化图片库样式

parent 0096bd1f
...@@ -2,17 +2,29 @@ import { getImageBases } from '@/services/common/api'; ...@@ -2,17 +2,29 @@ import { getImageBases } from '@/services/common/api';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
const UploadContext = React.createContext(); const UploadContext = React.createContext();
const sleep = time =>
new Promise((res, rej) => {
setTimeout(() => {
res();
}, time);
});
const PictureWallProvider = props => { const PictureWallProvider = props => {
const { children, ...rest } = props; const { children, ...rest } = props;
const [imgBed, setImgBed] = useState([]); const [imgBed, setImgBed] = useState([]);
const update = () => { const update = () =>
getImageBases('').then(res => { getImageBases('')
.then(res => {
if (res.code === 0) { if (res.code === 0) {
setImgBed(res.data); setImgBed(res.data);
} }
})
.catch(err => {
// eslint-disable-next-line no-console
console.error(err);
return sleep(3000).then(update);
}); });
};
useEffect(() => { useEffect(() => {
update(); update();
......
...@@ -41,19 +41,39 @@ ...@@ -41,19 +41,39 @@
overflow: auto; overflow: auto;
.imgItem { .imgItem {
flex: 0 0 50px; flex: 0 0 75px;
position: relative; position: relative;
flex-direction: column;
max-width: 75px;
// margin-right: 16px; // margin-right: 16px;
// margin-bottom: 16px; // margin-bottom: 16px;
margin: 10px; margin: 10px;
width: 50px; max-height: 100px;
max-height: 50px; // overflow: hidden;
overflow: hidden;
cursor: pointer; cursor: pointer;
background-color: rgba(238,238,238,1); display: flex;
>div{
flex: 1;
display: flex;
max-height: 78px;
}
>span{
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
&:hover>span{
color: #2f54eb;
}
img { img {
margin: auto;
width: 100%; width: 100%;
height: 100%; object-fit: contain;
max-height: 100%;
}
.svgGray{
background-color: rgba(238,238,238,1);
} }
&:hover, &:hover,
&.seleted { &.seleted {
......
...@@ -221,6 +221,11 @@ class PicturesWall extends React.Component<PicturesWallType> { ...@@ -221,6 +221,11 @@ class PicturesWall extends React.Component<PicturesWallType> {
return `${window.location.origin}/${path}`.replace(/\\/g, '/') return `${window.location.origin}/${path}`.replace(/\\/g, '/')
} }
getFileName(path:string){
const match = path.match(/(?<=[\/\\])([^\\\/\.]*)(\.?\w*)$/)
return match&&match[1]||''
}
render() { render() {
const { const {
previewVisible, previewVisible,
...@@ -323,19 +328,23 @@ class PicturesWall extends React.Component<PicturesWallType> { ...@@ -323,19 +328,23 @@ class PicturesWall extends React.Component<PicturesWallType> {
<div className={styles.imgBox}> <div className={styles.imgBox}>
{item.child?.map(m => m.fileUrls).flat(Infinity).map((item: string, i: number) => { {item.child?.map(m => m.fileUrls).flat(Infinity).map((item: string, i: number) => {
return ( return (
<div
className={styles.imgItem}
key={i}
onClick={() => this.handleImgSelected(item)}>
<div <div
className={classnames( className={classnames(
styles.imgItem,
curSelectedImg === item ? styles.seleted : '', curSelectedImg === item ? styles.seleted : '',
)} )}
key={i}
onClick={() => this.handleImgSelected(item)}
> >
<img src={this.getImageUrl(item)} alt="熊猫运维中台系统" /> <img className={classnames({[styles.svgGray]: /\.svg$/.test(item)})} src={this.getImageUrl(item)} title={item} alt="熊猫运维中台系统" />
<span className={styles.iconBtn}> <span className={styles.iconBtn}>
<CheckCircleFilled /> <CheckCircleFilled />
</span> </span>
</div> </div>
<span>{this.getFileName(item)}</span>
</div>
); );
})} })}
</div> </div>
......
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