Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-R7-Res
提交
6e8cea05
提交
6e8cea05
编写于
9月 19, 2025
作者:
jlj05024111@163.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 更新文件上传支持白名单,支持自定义上传文件大小限制
上级
76cffded
变更
2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
95 行增加
和
5 行删除
+95
-5
app-file-upload.less
src/components/app-file-upload/app-file-upload.less
+8
-0
app-file-upload.vue
src/components/app-file-upload/app-file-upload.vue
+87
-5
未找到文件。
src/components/app-file-upload/app-file-upload.less
浏览文件 @
6e8cea05
...
...
@@ -13,6 +13,14 @@
}
}
}
.has-uploadtip>.el-upload{
text-align: left;
}
.upload-description{
font-size: 12px;
opacity: 0.5;
color: #000;
}
}
.upload-preview-modal{
.ivu-modal{
...
...
src/components/app-file-upload/app-file-upload.vue
浏览文件 @
6e8cea05
...
...
@@ -6,6 +6,7 @@
</el-col>
<el-col
:span=
"(rowPreview && files.length > 0) ? 12 : 24"
class=
"upload-col"
>
<el-upload
:class=
"
{'has-uploadtip': !!uploadTip}"
:disabled="disabled"
:file-list="files"
:action="getAction()"
...
...
@@ -21,6 +22,7 @@
<el-button
v-if=
"!isdrag"
size=
'small'
icon=
'el-icon-upload2'
:disabled=
"disabled"
>
{{
this
.
$t
(
'app.fileUpload.caption'
)
}}
</el-button>
<i
v-if=
"isdrag"
class=
"el-icon-upload2"
></i>
<div
v-if=
"isdrag"
class=
"el-upload__text"
v-safe-html=
"$t('components.appFileUpload.uploadText')"
></div>
<div
class=
"upload-description"
>
{{
uploadTip
}}
</div>
</el-upload>
</el-col>
</el-row>
...
...
@@ -192,6 +194,26 @@ export default class AppFileUpload extends Vue {
*/
@
Prop
()
public
ownerid
!
:
string
;
/**
* 默认文件最大上传大小
*/
@
Prop
()
public
defaultSize
?:
number
|
string
;
/**
* 允许上传的文件类型
*/
@
Prop
({
default
:
''
})
public
whiteList
?:
string
;
/**
* 上传描述
*/
@
Prop
({
default
:
''
})
public
uploadDescription
?:
string
;
/**
* 上传文件提示
*/
public
uploadTip
:
string
=
''
/**
* 文件列表
*
...
...
@@ -300,9 +322,18 @@ export default class AppFileUpload extends Vue {
})
}
this
.
files
.
forEach
((
file
:
any
)
=>
{
let
url
=
`
${
Environment
.
BaseUrl
}${
Environment
.
ExportFile
}
/
${
file
.
id
}
`
;
let
downloadUrl
=
`
${
Environment
.
BaseUrl
}${
Environment
.
ExportFile
}
/
${
file
.
id
}
`
;
const
entityName
=
this
.
appEntityService
.
APPDENAME
;
const
base64
=
`
${
file
.
id
}
|
${
entityName
}
|
${
this
.
ownerid
}
|
${
this
.
context
.
srfpersonid
||
this
.
context
.
srfuserid
}
`
;
let
url
=
`
${
downloadUrl
}
?key=
${
window
.
btoa
(
base64
)}${
Math
.
floor
(
1000
+
Math
.
random
()
*
9000
,
)}
`
if
(
this
.
export_params
.
length
>
0
)
{
if
(
!
url
.
includes
(
'?'
))
{
url
+=
'?'
;
}
this
.
export_params
.
forEach
((
item
:
any
,
i
:
any
)
=>
{
url
+=
`
${
Object
.
keys
(
item
)[
0
]}
=
${
Object
.
values
(
item
)[
0
]}
`
;
if
(
i
<
this
.
export_params
.
length
-
1
){
...
...
@@ -314,6 +345,32 @@ export default class AppFileUpload extends Vue {
});
}
/**
* 计算上传配置
*/
public
calcFileUploadConfig
(){
const
config
:{
whiteList
:
string
[],
maxSize
:
number
,
description
:
string
}
=
{
whiteList
:[],
maxSize
:
10
,
description
:
''
}
const
_whiteList
=
this
.
whiteList
||
Environment
.
fileUploadWhiteList
;
const
_maxSize
=
this
.
defaultSize
||
Environment
.
fileUploadMaxSize
;
const
_description
=
this
.
uploadDescription
||
Environment
.
fileUploadDescription
;
if
(
_whiteList
){
config
.
whiteList
=
_whiteList
.
split
(
','
);
}
config
.
maxSize
=
Number
(
_maxSize
);
config
.
description
=
_description
;
if
(
!
_description
&&
_whiteList
&&
_whiteList
.
length
>
0
){
config
.
description
=
`
${
this
.
$t
(
'components.appFileUpload.supportextends'
)}
:
${
_whiteList
.
split
(
','
).
map
(
type
=>
`.
${
type
?.
toLowerCase
()}
`).join(' ')},
${
this
.
$t
(
'components.appFileUpload.singlefile'
)}${
_maxSize
}
MB`
;
}
return
config
;
}
/**
...
...
@@ -332,6 +389,8 @@ export default class AppFileUpload extends Vue {
}
});
}
const
config
=
this
.
calcFileUploadConfig
();
this
.
uploadTip
=
config
.
description
;
}
/**
...
...
@@ -403,12 +462,27 @@ export default class AppFileUpload extends Vue {
* @memberof AppFileUpload
*/
public
beforeUpload
(
file
:
any
)
{
const
config
=
this
.
calcFileUploadConfig
();
const
blackList
=
Environment
.
blackList
;
// 白名单
const
whiteList
=
config
.
whiteList
;
const
fileName
=
file
.
name
?.
trim
().
toLowerCase
();
if
(
Array
.
isArray
(
blackList
)
&&
typeof
fileName
===
'string'
&&
blackList
.
some
(
item
=>
fileName
.
endsWith
(
`.
${
item
}
`
)))
{
const
blackResult
=
Array
.
isArray
(
blackList
)
&&
typeof
fileName
===
'string'
&&
blackList
.
some
(
item
=>
fileName
.
endsWith
(
`.
${
item
}
`
));
const
whiteResult
=
Array
.
isArray
(
whiteList
)
&&
typeof
fileName
===
'string'
&&
whiteList
.
some
(
item
=>
fileName
.
endsWith
(
`.
${
item
}
`
));
if
(
whiteList
.
length
>
0
&&
!
whiteResult
){
Message
.
error
(
`
${
fileName
}
文件格式不正确,请上传
${
whiteList
.
join
(
'、'
)}
类型的文件`
);
return
false
;
}
if
(
blackResult
&&
!
whiteResult
)
{
Message
.
error
(
`不可上传
${
blackList
.
join
(
'、'
)}
类型的文件!`
);
return
false
;
}
if
(
file
.
size
>
config
.
maxSize
*
1024
*
1024
){
Message
.
error
(
`
${
fileName
}
超出文件限制大小,单个文件不能超过
${
config
.
maxSize
}
MB`
);
return
false
}
if
(
this
.
imageOnly
){
const
imageTypes
=
[
"image/jpeg"
,
"image/gif"
,
"image/png"
,
"image/bmp"
];
const
isImage
=
imageTypes
.
some
((
type
:
any
)
=>
Object
.
is
(
type
,
file
.
type
));
...
...
@@ -490,9 +564,17 @@ export default class AppFileUpload extends Vue {
const
downloadUrl
=
`
${(
window
as
any
).
Environment
.
ExportFile
}
`
+
'/'
+
id
+
'/'
+
name
;
const
entityName
=
this
.
appEntityService
.
APPDENAME
;
const
base64
=
`
${
id
}
|
${
entityName
}
|
${
this
.
ownerid
}
|
${
this
.
context
.
srfpersonid
||
this
.
context
.
srfuserid
}
`
;
cons
t
url
=
`
${
downloadUrl
}
?key=
${
window
.
btoa
(
base64
)}${
Math
.
floor
(
le
t
url
=
`
${
downloadUrl
}
?key=
${
window
.
btoa
(
base64
)}${
Math
.
floor
(
1000
+
Math
.
random
()
*
9000
,
)}
`
if
(
this
.
export_params
.
length
>
0
)
{
this
.
export_params
.
forEach
((
item
:
any
,
i
:
any
)
=>
{
url
+=
`
${
Object
.
keys
(
item
)[
0
]}
=
${
Object
.
values
(
item
)[
0
]}
`
;
if
(
i
<
this
.
export_params
.
length
-
1
){
url
+=
'&'
;
}
})
}
// 发送get请求
Axios
.
get
(
url
,
{
responseType
:
'arraybuffer'
,
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录