Browse Source

update 上传组件类型

warrior 7 months ago
parent
commit
2420bffd3a

+ 1 - 1
projects/textbook/src/app/comp-upload/comp-upload.component.html

@@ -4,7 +4,7 @@
   [nzHeaders]="{ authorization: 'authorization-text' }"
   (nzChange)="handleChange($event)"
   [nzFileList]="fileList"
-  [nzAccept]="'file'"
+  [nzAccept]="accept"
   [nzPreview]="preview"
 >
   <div style="color: #3e49b3;cursor: pointer;">

+ 31 - 9
projects/textbook/src/app/comp-upload/comp-upload.component.ts

@@ -19,7 +19,29 @@ export class CompUploadComponent implements OnInit {
   @Input('files') files: Array<any> = [];
   @Output() change: EventEmitter<any> = new EventEmitter<any>();
   @Input('width') width: number = 0;
-  @Input('maxlenght') maxlenght:number = 1 //文件数量限制
+  @Input('maxlenght') maxlenght: number = 1; //文件数量限制
+  @Input('type') type: string = 'file';
+  get accept() {
+    let type;
+    switch (this.type) {
+      case 'image':
+        type = 'image/*';
+        break;
+      case 'pdf':
+        type = 'application/pdf';
+        break;
+      case 'audio':
+        type = 'audio/*';
+        break;
+      case 'video':
+        type = 'video/*';
+        break;
+      default:
+        type = 'file';
+        break;
+    }
+    return type;
+  }
 
   fileList: any = [
     // {
@@ -41,11 +63,11 @@ export class CompUploadComponent implements OnInit {
       console.log(item);
       return {
         url: item?.url,
-        name:item?.name,
+        name: item?.name,
         status: 'done',
       };
     });
-    this.Previewfilelist = this.fileList
+    this.Previewfilelist = this.fileList;
   }
   ossFileList: any;
   Previewfilelist: any;
@@ -53,7 +75,7 @@ export class CompUploadComponent implements OnInit {
     console.log(info);
     let fileList = [...info.fileList];
     fileList = fileList.slice(-this.maxlenght);
-    fileList = fileList.map(file => {
+    fileList = fileList.map((file) => {
       if (file.response) {
         file.url = file.response.url;
       }
@@ -71,10 +93,10 @@ export class CompUploadComponent implements OnInit {
         ossFileList?.map((item) => {
           // console.log(item);
           let f = {
-            name:item.locaname,
-            url:item?.url
-          }
-          return f
+            name: item.locaname,
+            url: item?.url,
+          };
+          return f;
         })
       );
     }
@@ -97,7 +119,7 @@ export class CompUploadComponent implements OnInit {
           ossFile = await this.ossProvider?.upload(file?.originFileObj);
         } catch (err) {}
         if (ossFile) {
-          ossFile.locaname = file.name
+          ossFile.locaname = file.name;
           ossFileList.push(ossFile);
         }
       }

+ 1 - 1
projects/textbook/src/modules/nav-author/components/attachment/attachment.component.html

@@ -11,7 +11,7 @@
               版权页截图
             </a>
           }
-          <app-comp-upload [width]="320" (change)="upload($event, 'copyrightImgUrl')" title="上传PDF"></app-comp-upload>
+          <app-comp-upload [type]="'pdf'" [width]="320" (change)="upload($event, 'copyrightImgUrl')" title="上传PDF"></app-comp-upload>
 
           <div class="text upText" style="margin: 10px 0">
             支持上传PDF,大小不超过 2M