|
@@ -3,6 +3,8 @@ import { NzUploadModule } from 'ng-zorro-antd/upload';
|
|
|
import { CommonCompModule } from '../../services/common.modules';
|
|
|
import { NzMessageService } from 'ng-zorro-antd/message';
|
|
|
import { NzUploadChangeParam, NzUploadFile } from 'ng-zorro-antd/upload';
|
|
|
+import { ProvierOssAli } from './provider-oss-aliyun';
|
|
|
+
|
|
|
@Component({
|
|
|
selector: 'app-comp-upload',
|
|
|
standalone: true,
|
|
@@ -24,7 +26,10 @@ export class CompUploadComponent implements OnInit {
|
|
|
// url: 'http://www.baidu.com/xxx.png'
|
|
|
// },
|
|
|
];
|
|
|
- constructor(private msg: NzMessageService) {}
|
|
|
+ ossProvider:{upload:any}|undefined
|
|
|
+ constructor(private msg: NzMessageService) {
|
|
|
+ this.ossProvider = new ProvierOssAli()
|
|
|
+ }
|
|
|
|
|
|
ngOnInit() {
|
|
|
this.fileList = this.files.map((item:any)=> {
|
|
@@ -33,16 +38,38 @@ export class CompUploadComponent implements OnInit {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- handleChange(info: NzUploadChangeParam): void {
|
|
|
+ async handleChange(info: NzUploadChangeParam) {
|
|
|
console.log(info);
|
|
|
if (info.file.status !== 'uploading') {
|
|
|
+ // 选择文件后,自动开始上传
|
|
|
console.log(info.file, info.fileList);
|
|
|
+ let ossFileList = await this.uploadAllFileList(info?.fileList)
|
|
|
+ this.change.emit(ossFileList?.map(item=>item?.url))
|
|
|
}
|
|
|
if (info.file.status === 'done') {
|
|
|
- this.msg.success(`${info.file.name} file uploaded successfully`);
|
|
|
+ // this.msg.success(`${info.file.name} file uploaded successfully`);
|
|
|
} else if (info.file.status === 'error') {
|
|
|
- this.msg.error(`${info.file.name} file upload failed.`);
|
|
|
+ // this.msg.error(`${info.file.name} file upload failed.`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // this.change.emit(info.fileList)
|
|
|
+ }
|
|
|
+
|
|
|
+ async uploadAllFileList(fileList:Array<NzUploadFile>){
|
|
|
+ let ossFileList = []
|
|
|
+ for (let index = 0; index < fileList.length; index++) {
|
|
|
+ let file = fileList[index];
|
|
|
+ if(file){
|
|
|
+ let ossFile
|
|
|
+ try{
|
|
|
+ ossFile = await this.ossProvider?.upload(file?.originFileObj);
|
|
|
+ }catch(err){}
|
|
|
+ if(ossFile){
|
|
|
+ ossFileList.push(ossFile)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- this.change.emit(info.fileList)
|
|
|
+ console.log(ossFileList)
|
|
|
+ return ossFileList
|
|
|
}
|
|
|
}
|