当前位置: 首页 > news >正文

东莞建材网站建设和京东一样做电子产品的网站

东莞建材网站建设,和京东一样做电子产品的网站,阿里云主机 搭建网站,公司做网站多少钱成品效果图&#xff1a; 解决问题&#xff1a;上传文件过大时&#xff0c;等待时间过长&#xff0c;但是进度条却不会动&#xff0c;只会在上传完成之后才会显示上传完成 上传文件的upload.component.html <nz-modal [(nzVisible)]"isVisible" [nzTitle]"文…

成品效果图:

解决问题:上传文件过大时,等待时间过长,但是进度条却不会动,只会在上传完成之后才会显示上传完成

上传文件的upload.component.html

<nz-modal [(nzVisible)]="isVisible" [nzTitle]="'文件上传'" [nzWidth]="'1000px'" [nzFooter]="modalFooter"(nzOnCancel)="onCancel()" class="advice-upload-file"><div nz-row><nz-upload #uploadListData nzType="drag" [(nzFileList)]="fileList" [nzMultiple]="isMultiple" [nzLimit]="0"[nzBeforeUpload]="beforeUpload"><p class="ant-upload-drag-icon"><i nz-icon nzType="inbox"></i></p><p>点击或拖拽上传</p></nz-upload><div style="padding-top: 10px"><h6>文件上传进度:</h6><nz-progress [nzPercent]="percent"></nz-progress></div></div><ng-template #modalFooter><button nz-button nzType="default" (click)="cleanList()">清空上传队列</button><button nz-button nzType="default" (click)="onCancel()">取消</button><button nz-button nzType="primary" (click)="submit()">上传</button></ng-template>
</nz-modal>

upload.component.ts

  /** 是否允许上传多个文件 */isMultiple = true;/*** 文件赋值列表*/fileList = [];/*** 上传进度条*/percent = null;/** 上传 */submit() {let successCount = 0;this.fileList.forEach(file => {const formData: FormData = new FormData();formData.append('file', file.originFileObj, file.name);this.uploadService.uploadMultiFiles(formData, this.categoryId, file.name).subscribe(data => {if (data) {successCount++;this.msg.create('success', data['fileName'] + `上传成功!`);this.percent = Number((successCount / this.fileList.length * 100).toFixed(2));}if (this.fileList.length === successCount) {setTimeout(() => {this.onCancel();this.notification.emit({operation: null,data: null});}, 1000);}});});}cleanList() {this.fileList = [];}beforeUpload = (file: UploadFile) => {// const isLt200M = file.size / 1024 / 1024 < 200;// if (!isLt200M) {//   this.msg.error('文件大小不超过200MB!');//   return false;// }return true;}

接口:

/** 上传文件 */uploadMultiFiles(files: FormData, categoryId: string, fileName: string): Observable<Array<any>> {return this.http.post(`${this.URL}` + `/uploadFile?fileName=${fileName}&categoryId=${categoryId}`, files);}

效果就是上传文件大时进度条一直是0%,然后上传完成才100%(会让用户误解没上传成功重复上传)

效果图:

解决方法如下:

1、修改接口里面的传参post,鼠标移上去一般有显示类型参数

  /** 上传文件 */uploadMultiFiles(files: FormData, categoryId: string, fileName: string): Observable<any> {return this.http.post(`${this.URL}` + `/uploadFile?fileName=${fileName}&categoryId=${categoryId}`, files, {}, {reportProgress: true,observe: 'events',});}

2、修改upload.component.ts 文件的提交方法

  /** 上传 */submit() {this.fileList.forEach(file => {const formData: FormData = new FormData();formData.append('file', file.originFileObj, file.name);this.uploadService.uploadMultiFiles(formData, this.categoryId, file.name).subscribe(event => {if (event.type === HttpEventType.UploadProgress) {this.percent = Math.round(100 * event.loaded / event.total);} else if (event.type === HttpEventType.Response) {// 文件上传成功this.msg.create('success', event.body['fileName'] + `上传成功!`);setTimeout(() => {this.onCancel();this.notification.emit({operation: null,data: null});}, 1000);}});});}

效果图:进度值会随着上传多少变化

参考文章:

angular:

https://www.yisu.com/jc/843309.html

axios:

https://www.jianshu.com/p/9564b549d2d6

http://www.yayakq.cn/news/246927/

相关文章:

  • 网站开发接外包怎样建立自己的网站平台
  • 南宁律师网站建设高端网站开发注意事项
  • 产品包装设计网站找谁做企业网络营销策划书模板
  • 电商后台管理网站模板阿里巴巴外贸平台怎么样
  • 深圳门户网站建设方案做国外的网站
  • 企业网站建设策划书案例江门模板建站系统
  • 长安镇网站建设凡客诚品市场份额
  • 长沙网站建设找哪家北京北控京奥建设有限公司网站
  • 做网站备案需要什么有什么可以接单做设计的网站
  • 任务网站的接口怎么做网站建设明细表
  • 手机建设中网站网站开发的费用
  • 网站建设及报价格方案湖北网站建设营销qq
  • 襄阳门户网站建设音乐网站开发结语
  • 广州魔站建站中国水土保持生态环境建设网站
  • 空气能空调如何做网站网站子页面如何做seo
  • 网站开发报价ppt永康城乡建设局网站
  • 北京 手机网站建设软件开发都有哪些项目
  • 百度推广交了钱不给做网站网站做非经营性广告需备案
  • 对网站建设的讲话私密浏览器如何下载视频
  • 工程网站模板广州 济南网站建设公司 网络服务
  • 怎么搭建网站平台django 开放api 做网站
  • 网站做招聘需要什么资质网站开发需要的知识
  • 精品在线开发网站建设企业网站怎么做跟淘宝链接
  • 专业定制网站建设团队最新发布的手机有哪些
  • 用illustrator做网站哪里可以接网站开发项目做
  • 备案核验单 网站类型做一个内容网站多少钱
  • 中国最大的软件公司排名百度seo怎么收费
  • 做网站赚钱全攻略网站密码怎么做
  • 无障碍网站建设推广前景外国建筑网站
  • 做网站卖高仿做了半个月跨境电商不想干了