提交 291a96d9 编写于 作者: hisoka0728's avatar hisoka0728

update: 限制文件上传类型

上级 e46f23d8
...@@ -254,6 +254,14 @@ export default class AppFileUpload extends Vue { ...@@ -254,6 +254,14 @@ export default class AppFileUpload extends Vue {
*/ */
public appData: any; public appData: any;
/**
* 文件上传限制类型
*
* @type {*}
* @memberof DiskFileUpload
*/
limitType:Array<String> = ['application/x-msdownload','text/x-sh','text/html','text/javascript']
/** /**
* 设置files * 设置files
* *
...@@ -394,6 +402,10 @@ export default class AppFileUpload extends Vue { ...@@ -394,6 +402,10 @@ export default class AppFileUpload extends Vue {
* @memberof AppFileUpload * @memberof AppFileUpload
*/ */
public beforeUpload(file: any) { public beforeUpload(file: any) {
if(this.limitType.includes(file.type)){
Message.error('不可上传 html、js、 exe、sh类型的文件!')
return false
}
if(this.imageOnly){ if(this.imageOnly){
const imageTypes = ["image/jpeg" , "image/gif" , "image/png" , "image/bmp"]; const imageTypes = ["image/jpeg" , "image/gif" , "image/png" , "image/bmp"];
const isImage = imageTypes.some((type: any)=> Object.is(type, file.type)); const isImage = imageTypes.some((type: any)=> Object.is(type, file.type));
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
:disabled="disabled" :disabled="disabled"
:action="getAction()" :action="getAction()"
:headers="myHeaders" :headers="myHeaders"
:before-upload="beforeUpload"
:file-list="uploadFileList" :file-list="uploadFileList"
:show-file-list="false" :show-file-list="false"
:http-request="customUploadFile"> :http-request="customUploadFile">
...@@ -281,6 +282,14 @@ ...@@ -281,6 +282,14 @@
*/ */
public iframeUrl: any = ''; public iframeUrl: any = '';
/**
* 文件上传限制类型
*
* @type {*}
* @memberof DiskFileUpload
*/
limitType:Array<String> = ['application/x-msdownload','text/x-sh','text/html','text/javascript']
/** /**
* 关闭自定义弹框 * 关闭自定义弹框
* *
...@@ -440,6 +449,20 @@ ...@@ -440,6 +449,20 @@
}) })
} }
/**
* 上传之前
*
* @param file
* @memberof DiskFileUpload
*/
public beforeUpload(file:any){
if(this.limitType.includes(file.type)){
Message.error('不可上传 html、js、 exe、sh类型的文件!')
return false
}
return true
}
/** /**
* 下载文件 * 下载文件
* *
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册