fix: file icon

This commit is contained in:
chenos 2021-04-22 14:51:23 +08:00
parent e3a5dc73b7
commit 80eb229696
2 changed files with 10 additions and 18 deletions

View File

@ -24,7 +24,7 @@ const exts = [
},
{
ext: /\.jpe?g$/i,
icon: '//img.alicdn.com/tfs/TB1wrT5r9BYBeNjy0FeXXbnmFXa-200-200.png',
// icon: '//img.alicdn.com/tfs/TB1wrT5r9BYBeNjy0FeXXbnmFXa-200-200.png',
},
{
ext: /\.pdf$/i,
@ -32,7 +32,7 @@ const exts = [
},
{
ext: /\.png$/i,
icon: '//img.alicdn.com/tfs/TB1BHT5r9BYBeNjy0FeXXbnmFXa-200-200.png',
// icon: '//img.alicdn.com/tfs/TB1BHT5r9BYBeNjy0FeXXbnmFXa-200-200.png',
},
{
ext: /\.eps$/i,
@ -44,11 +44,11 @@ const exts = [
},
{
ext: /\.gif$/i,
icon: '//img.alicdn.com/tfs/TB1DTiGrVOWBuNjy0FiXXXFxVXa-200-200.png',
// icon: '//img.alicdn.com/tfs/TB1DTiGrVOWBuNjy0FiXXXFxVXa-200-200.png',
},
{
ext: /\.svg$/i,
icon: '//img.alicdn.com/tfs/TB1uUm9rY9YBuNjy0FgXXcxcXXa-200-200.png',
// icon: '//img.alicdn.com/tfs/TB1uUm9rY9YBuNjy0FgXXcxcXXa-200-200.png',
},
{
ext: /\.xlsx?$/i,
@ -88,14 +88,13 @@ const testOpts = (ext, options) => {
return true;
};
export const testUrl = (url, options) => {
export const testUrl = (url, options = {}) => {
for (let i = 0; i < exts.length; i++) {
if (exts[i].ext.test(url) && testOpts(exts[i].ext, options)) {
return false;
return !exts[i].icon;
}
}
return true;
return false;
};
export const getImageByUrl = (url, options) => {
@ -178,9 +177,7 @@ export function getImgUrls(value) {
const values = Array.isArray(value) ? value : [value];
return values
.filter(item =>
testUrl(item.url, {
exclude: ['.png', '.jpg', '.jpeg', '.gif'],
}),
testUrl(item.url),
)
.map(item => toValue(item));
}

View File

@ -386,11 +386,7 @@ export function LinkToFieldLink(props) {
function getImgUrls(value) {
const values = Array.isArray(value) ? value : [value];
return values
.filter(item =>
testUrl(item.url, {
exclude: ['.png', '.jpg', '.jpeg', '.gif'],
}),
)
.filter(item => testUrl(item.url))
.map(item => item);
}
@ -403,7 +399,6 @@ export function AttachmentField(props: any) {
}
const values = Array.isArray(value) ? value : [value];
const images = getImgUrls(values);
// console.log(images);
return (
<div
onClick={e => {
@ -443,7 +438,7 @@ export function AttachmentField(props: any) {
export function AttachmentFieldItem(props: any) {
const { title, url } = props.data || {};
const img = getImageByUrl(url, {
exclude: ['.png', '.jpg', '.jpeg', '.gif'],
// exclude: ['.png', '.jpg', '.jpeg', '.gif'],
});
// const [visible, setVisible] = useState(false);
return (