|
@@ -6,11 +6,13 @@ import { NzUploadChangeParam, NzUploadFile } from 'ng-zorro-antd/upload';
|
|
|
import { ProvierOssAli } from './provider-oss-aliyun';
|
|
|
import { NzImageService } from 'ng-zorro-antd/image';
|
|
|
import { NzImageModule } from 'ng-zorro-antd/image';
|
|
|
+import { NzNotificationModule } from 'ng-zorro-antd/notification';
|
|
|
+import { NzNotificationService } from 'ng-zorro-antd/notification';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-comp-upload',
|
|
|
standalone: true,
|
|
|
- imports: [NzUploadModule, CommonCompModule, NzImageModule],
|
|
|
+ imports: [NzUploadModule, CommonCompModule, NzImageModule,NzNotificationModule],
|
|
|
templateUrl: './comp-upload.component.html',
|
|
|
styleUrls: ['./comp-upload.component.scss'],
|
|
|
})
|
|
@@ -56,11 +58,12 @@ export class CompUploadComponent implements OnInit {
|
|
|
Previewfilelist: any;
|
|
|
ossProvider: { upload: any } | undefined;
|
|
|
|
|
|
- disabled:boolean = false
|
|
|
+ disabled: boolean = false
|
|
|
|
|
|
constructor(
|
|
|
private msg: NzMessageService,
|
|
|
- private nzImageService: NzImageService
|
|
|
+ private nzImageService: NzImageService,
|
|
|
+ private notification: NzNotificationService
|
|
|
) {
|
|
|
this.ossProvider = new ProvierOssAli();
|
|
|
}
|
|
@@ -78,9 +81,13 @@ export class CompUploadComponent implements OnInit {
|
|
|
}
|
|
|
async handleChange(info: NzUploadChangeParam) {
|
|
|
console.log(info);
|
|
|
- if(info.type == 'removed'){
|
|
|
+ if (info.type == 'removed') {
|
|
|
return
|
|
|
}
|
|
|
+ let isEncrypt = await this.isEncrypt(info)
|
|
|
+ // if (isEncrypt) {
|
|
|
+ // return
|
|
|
+ // }
|
|
|
this.disabled = true
|
|
|
if (info.file.status !== 'uploading') {
|
|
|
// 选择文件后,自动开始上传
|
|
@@ -93,7 +100,7 @@ export class CompUploadComponent implements OnInit {
|
|
|
};
|
|
|
return f;
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
let fileList = [...this.fileList, ...nowUploadFiles];
|
|
|
this.fileList = fileList.slice(-this.maxlenght);
|
|
|
// fileList = fileList.map((file) => {
|
|
@@ -106,7 +113,6 @@ export class CompUploadComponent implements OnInit {
|
|
|
|
|
|
this.Previewfilelist = [...this.fileList];
|
|
|
// this.ossFileList = ossFileList;
|
|
|
-
|
|
|
this.change.emit(this.fileList);
|
|
|
this.disabled = false
|
|
|
}
|
|
@@ -127,7 +133,7 @@ export class CompUploadComponent implements OnInit {
|
|
|
let ossFile;
|
|
|
try {
|
|
|
ossFile = await this.ossProvider?.upload(file?.originFileObj);
|
|
|
- } catch (err) {}
|
|
|
+ } catch (err) { }
|
|
|
if (ossFile) {
|
|
|
ossFile.locaname = file.name;
|
|
|
ossFileList.push(ossFile);
|
|
@@ -136,10 +142,10 @@ export class CompUploadComponent implements OnInit {
|
|
|
}
|
|
|
return ossFileList;
|
|
|
}
|
|
|
- onRemove = (e: any):boolean =>{
|
|
|
+ onRemove = (e: any): boolean => {
|
|
|
console.log(e);
|
|
|
- let i = this.fileList.findIndex((item:any)=> item.url == e?.url)
|
|
|
- this.fileList.splice(i,1)
|
|
|
+ let i = this.fileList.findIndex((item: any) => item.url == e?.url)
|
|
|
+ this.fileList.splice(i, 1)
|
|
|
this.change.emit(this.fileList);
|
|
|
return false
|
|
|
}
|
|
@@ -156,4 +162,37 @@ export class CompUploadComponent implements OnInit {
|
|
|
this.nzImageService.preview([{ src: url }], { nzZoom: 1, nzRotate: 0 });
|
|
|
}
|
|
|
};
|
|
|
+ timeOut: any
|
|
|
+ /**判断pdf文件是否加密 */
|
|
|
+ isEncrypt(info: NzUploadChangeParam): Promise<boolean> {//只查file,不查fileList
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ let isEncrypt: boolean = false
|
|
|
+ if (info.file.originFileObj) {
|
|
|
+ let reader = new FileReader()
|
|
|
+ let file = info.file.originFileObj
|
|
|
+ reader.readAsArrayBuffer(file)
|
|
|
+ reader.onload = () => {
|
|
|
+ if (reader.result) {
|
|
|
+ let files = new Blob([reader.result], { type: 'application/pdf' })
|
|
|
+ files.text().then(x => {
|
|
|
+ isEncrypt = x.substring(x.lastIndexOf("<<"), x.lastIndexOf(">>")).includes("/Encrypt")
|
|
|
+ if (isEncrypt) {
|
|
|
+ clearTimeout(this.timeOut)
|
|
|
+ this.timeOut = setTimeout(() => {
|
|
|
+ this.notification.create(
|
|
|
+ 'error',
|
|
|
+ '请勿上传加密文件',
|
|
|
+ `${file.name} 为加密文件,影响导出,请替换。`,
|
|
|
+ { nzDuration: 0 }
|
|
|
+ );
|
|
|
+
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ resolve(isEncrypt)
|
|
|
+ })
|
|
|
+ } else { resolve(false) }
|
|
|
+ }
|
|
|
+ } else { resolve(false) }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|