1
0
Liyuan Li 5 жил өмнө
parent
commit
4480040b56

+ 1 - 0
README.md

@@ -336,6 +336,7 @@ xhr.send(JSON.stringify({url: src})); // src is the address of the image outside
 | file | Process the uploaded file before returning (files: File[]): File[] | - |
 | setHeaders | Use the return value to set the header before uploading (): { [key: string]: string } | - |
 | extraData | Append data to FormData { [key: string]: string | Blob } | - |
+| multiple | Allow multiple file uploads | true |
 
 #### options.resize
 

+ 6 - 3
src/ts/toolbar/Upload.ts

@@ -6,11 +6,14 @@ import {MenuItem} from "./MenuItem";
 export class Upload extends MenuItem {
     constructor(vditor: IVditor, menuItem: IMenuItem) {
         super(vditor, menuItem);
-        let inputHTML = '<input multiple="multiple" type="file">';
+        let inputHTML = '<input type="file"';
+        if (vditor.options.upload.multiple) {
+            inputHTML += ' multiple="multiple"';
+        }
         if (vditor.options.upload.accept) {
-            inputHTML = `<input multiple="multiple" type="file" accept="${vditor.options.upload.accept}">`;
+            inputHTML += ` accept="${vditor.options.upload.accept}"`;
         }
-        this.element.children[0].innerHTML = `${(menuItem.icon || uploadSVG)}${inputHTML}`;
+        this.element.children[0].innerHTML = `${(menuItem.icon || uploadSVG)}${inputHTML}>`;
         this._bindEvent(vditor);
     }
 

+ 2 - 1
src/ts/upload/index.ts

@@ -141,7 +141,8 @@ const genUploadedLabel = (responseText: string, vditor: IVditor) => {
 const uploadFiles = (vditor: IVditor, files: FileList | DataTransferItemList | File[], element?: HTMLInputElement) => {
     // FileList | DataTransferItemList | File[] => File[]
     let fileList = [];
-    for (let iMax = files.length, i = 0; i < iMax; i++) {
+    const iMax = vditor.options.upload.multiple === true ? files.length : 1;
+    for (let i = 0; i < iMax; i++) {
         let fileItem = files[i];
         if (fileItem instanceof DataTransferItem) {
             fileItem = fileItem.getAsFile();

+ 1 - 0
src/ts/util/Options.ts

@@ -138,6 +138,7 @@ export class Options {
             filename: (name: string) => name.replace(/\W/g, ""),
             linkToImgUrl: "",
             max: 10 * 1024 * 1024,
+            multiple: true,
             url: "",
             withCredentials: false,
         },

+ 2 - 0
types/index.d.ts

@@ -251,6 +251,8 @@ interface IUpload {
     headers?: IObject;
     /** 额外请求参数 */
     extraData?: { [key: string]: string | Blob };
+    /** 是否允许多文件上传。默认值:true */
+    multiple?: boolean;
 
     /** 每次上传前都会重新设置请求头 */
     setHeaders?(): IObject;