|
@@ -21,7 +21,7 @@ export class UploadComponent implements OnInit {
|
|
|
|
|
|
@Input('maxlenght') maxlenght: number = 1; //文件数量限制
|
|
|
@Input('type') type: string = 'image';
|
|
|
- @Input('size') size: number = 2048; //上传文件限制大小单位KB
|
|
|
+ @Input('size') size: number = 10240; //上传文件限制大小单位KB
|
|
|
@Input('active') active: boolean = false; //选择文件后主动触发上传
|
|
|
|
|
|
@Input('multiple') multiple: boolean = false; //是否允许选择多张
|
|
@@ -64,7 +64,7 @@ export class UploadComponent implements OnInit {
|
|
|
}> = [];
|
|
|
Previewfilelist: any; //预览图片数组
|
|
|
loading: any;
|
|
|
- currentPreviewImg:string = ''
|
|
|
+ currentPreviewImg: string = '';
|
|
|
constructor(
|
|
|
private toastController: ToastController,
|
|
|
public loadCtrl: LoadingController
|
|
@@ -96,8 +96,8 @@ export class UploadComponent implements OnInit {
|
|
|
});
|
|
|
this.Previewfilelist = this.fileList;
|
|
|
}
|
|
|
- onPreview(url:string){
|
|
|
- this.currentPreviewImg = url
|
|
|
+ onPreview(url: string) {
|
|
|
+ this.currentPreviewImg = url;
|
|
|
}
|
|
|
onDelete(index: number) {
|
|
|
console.log(index);
|
|
@@ -120,14 +120,24 @@ export class UploadComponent implements OnInit {
|
|
|
await this.changeFileReader(f);
|
|
|
}
|
|
|
console.log(this.fileList);
|
|
|
- this.active && this.onUpload()
|
|
|
+ this.active && this.onUpload();
|
|
|
}
|
|
|
//转图片格式
|
|
|
changeFileReader(file: any) {
|
|
|
- return new Promise((res) => {
|
|
|
+ return new Promise(async (res) => {
|
|
|
const windowURL = window.URL || window.webkitURL;
|
|
|
const src = windowURL.createObjectURL(file);
|
|
|
let size = file.size / 1024; //KB
|
|
|
+ if(size > this.size){
|
|
|
+ const toast = await this.toastController.create({
|
|
|
+ message: `${file.name || '未知'}超过${Math.ceil(this.size/1024)}MB`,
|
|
|
+ color: 'warning',
|
|
|
+ duration: 1500,
|
|
|
+ });
|
|
|
+ toast.present();
|
|
|
+ res(true);
|
|
|
+ return
|
|
|
+ }
|
|
|
this.fileList.push({
|
|
|
url: src,
|
|
|
size: size,
|
|
@@ -176,26 +186,31 @@ export class UploadComponent implements OnInit {
|
|
|
duration: 1000,
|
|
|
});
|
|
|
toast.present();
|
|
|
+ return;
|
|
|
}
|
|
|
let fs = this.fileList;
|
|
|
this.loading = await this.loadCtrl.create({ message: '上传中' });
|
|
|
this.loading.present();
|
|
|
- for (let index = 0; index < fs.length; index++) {
|
|
|
- const f = fs[index];
|
|
|
- if (f.type == 'local') {
|
|
|
- console.log(f);
|
|
|
- let url = await this.onQiniuUpFile(f);
|
|
|
- await this.saveAttachment({
|
|
|
- size: f.size,
|
|
|
- url: url,
|
|
|
- name: f.name,
|
|
|
- type: this.fileList[index].file.type,
|
|
|
- });
|
|
|
- this.fileList[index].url = url;
|
|
|
- this.fileList[index].type = 'http';
|
|
|
- delete this.fileList[index].file;
|
|
|
- delete this.fileList[index].size;
|
|
|
+ try{
|
|
|
+ for (let index = 0; index < fs.length; index++) {
|
|
|
+ const f = fs[index];
|
|
|
+ if (f.type == 'local') {
|
|
|
+ console.log(f);
|
|
|
+ let url = await this.onQiniuUpFile(f);
|
|
|
+ await this.saveAttachment({
|
|
|
+ size: f.size,
|
|
|
+ url: url,
|
|
|
+ name: f.name,
|
|
|
+ type: this.fileList[index].file.type,
|
|
|
+ });
|
|
|
+ this.fileList[index].url = url;
|
|
|
+ this.fileList[index].type = 'http';
|
|
|
+ delete this.fileList[index].file;
|
|
|
+ delete this.fileList[index].size;
|
|
|
+ }
|
|
|
}
|
|
|
+ }catch(err){
|
|
|
+ this.loading.dismiss();
|
|
|
}
|
|
|
this.onChange.emit(this.fileList);
|
|
|
this.loading.dismiss();
|
|
@@ -264,9 +279,9 @@ export class UploadComponent implements OnInit {
|
|
|
let datepath = this.DateFormat(new Date(), 'hhmmss');
|
|
|
let qiniuFileKey = this.company + '/' + datepath + '/' + file.name;
|
|
|
const putExtra = {
|
|
|
- fname: '',
|
|
|
- params: {},
|
|
|
- mimeType: this.accept === 'image/*'?'image/*' : undefined,
|
|
|
+ // fname: '',
|
|
|
+ // params: {},
|
|
|
+ // mimeType: this.accept === 'image/*' ? 'image/*' : undefined,
|
|
|
};
|
|
|
const config = {
|
|
|
useCdnDomain: true, //使用cdn加速
|