18 lines
513 B
TypeScript
18 lines
513 B
TypeScript
import { FileType } from '@/constants/enum/fileType';
|
|
|
|
const imgTypeList = ['png', 'jpg', 'gif', 'jpeg', 'nmp'];
|
|
const videoTypeList = ['mp4'];
|
|
export const getFileType = (url: string = '') => {
|
|
// 获取最后一个.的位置
|
|
const index = url.lastIndexOf('.');
|
|
// 获取后缀
|
|
const ext = url.substr(index + 1);
|
|
if (imgTypeList.indexOf(ext) > -1) {
|
|
return FileType.IMAGE;
|
|
} else if (videoTypeList.indexOf(ext) > -1) {
|
|
return FileType.VIDEO;
|
|
}
|
|
return null;
|
|
};
|
|
export default getFileType;
|