Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
admin-ci-test
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
test-ci
admin-ci-test
Commits
a0f43900
提交
a0f43900
authored
9月 18, 2023
作者:
龚洪江
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复:上传文件类型错误提示
上级
6fd901d8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
72 行增加
和
3 行删除
+72
-3
index.tsx
src/components/uploader/index.tsx
+9
-3
dictionary.ts
src/utils/dictionary.ts
+63
-0
没有找到文件。
src/components/uploader/index.tsx
浏览文件 @
a0f43900
...
@@ -4,6 +4,7 @@ import { CommonAPI } from '~/api';
...
@@ -4,6 +4,7 @@ import { CommonAPI } from '~/api';
import
'./index.scss'
;
import
'./index.scss'
;
import
Viewer
from
'~/components/viewer'
;
import
Viewer
from
'~/components/viewer'
;
import
saveAs
from
'file-saver'
;
import
saveAs
from
'file-saver'
;
import
{
fileTypeList
}
from
'~/utils/dictionary'
;
interface
PropsType
{
interface
PropsType
{
listType
?:
'text'
|
'picture'
|
'picture-card'
;
// 上传列表的内建样式
listType
?:
'text'
|
'picture'
|
'picture-card'
;
// 上传列表的内建样式
...
@@ -58,9 +59,7 @@ export const Uploader: React.FC<PropsType> = (props) => {
...
@@ -58,9 +59,7 @@ export const Uploader: React.FC<PropsType> = (props) => {
const
isType
=
fileType
?.
includes
(
res
.
type
);
const
isType
=
fileType
?.
includes
(
res
.
type
);
const
isSize
=
res
.
size
/
1024
/
1024
<
(
fileSize
||
2
);
const
isSize
=
res
.
size
/
1024
/
1024
<
(
fileSize
||
2
);
if
(
!
isType
)
{
if
(
!
isType
)
{
message
message
.
error
(
`请上传
${
getFileTypeStr
()}
格式的文件!`
).
then
();
.
error
(
`请上传
${
fileType
.
join
(
'、'
).
replace
(
/image
\/
|video
\/
/g
,
''
)}
格式的文件!`
)
.
then
();
return
isType
;
return
isType
;
}
}
if
(
!
isSize
)
{
if
(
!
isSize
)
{
...
@@ -125,6 +124,13 @@ export const Uploader: React.FC<PropsType> = (props) => {
...
@@ -125,6 +124,13 @@ export const Uploader: React.FC<PropsType> = (props) => {
}
}
},
},
};
};
// 获取文件类型提示
const
getFileTypeStr
=
()
=>
fileType
.
map
((
v
)
=>
fileTypeList
.
find
((
i
)
=>
i
.
value
===
v
)?.
label
)
.
filter
((
v
)
=>
!!
v
)
.
join
(
','
);
useEffect
(()
=>
{
useEffect
(()
=>
{
// 如果有默认文件列表
// 如果有默认文件列表
if
(
defaultFileList
?.
length
)
{
if
(
defaultFileList
?.
length
)
{
...
...
src/utils/dictionary.ts
浏览文件 @
a0f43900
...
@@ -124,3 +124,66 @@ export const contractStatusList = [
...
@@ -124,3 +124,66 @@ export const contractStatusList = [
value
:
5
,
value
:
5
,
},
},
];
];
// 文件字典
export
const
fileTypeList
=
[
{
label
:
'png'
,
value
:
'image/png'
,
},
{
label
:
'jpeg'
,
value
:
'image/jpeg'
,
},
{
label
:
'jpg'
,
value
:
'image/jpg'
,
},
{
label
:
'gif'
,
value
:
'image/gif'
,
},
{
label
:
'mp4'
,
value
:
'video/mp4'
,
},
{
label
:
'avi'
,
value
:
'video/avi'
,
},
{
label
:
'wmv'
,
value
:
'video/wmv'
,
},
{
label
:
'rmvb'
,
value
:
'video/rmvb'
,
},
{
label
:
'doc'
,
value
:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
,
},
{
label
:
'doc'
,
value
:
'application/msword'
,
},
{
label
:
'excel'
,
value
:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
,
},
{
label
:
'excel'
,
value
:
'application/vnd.ms-excel'
,
},
{
label
:
'pdf'
,
value
:
'application/pdf'
,
},
{
label
:
'ppt'
,
value
:
'application/vnd.ms-powerpoint'
,
},
{
label
:
'ppt'
,
value
:
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
,
},
];
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论