/* * @Descripttion: * @version: * @Author: sueRimn * @Date: 2020-12-24 14:15:10 * @LastEditors: sueRimn * @LastEditTime: 2021-05-14 17:09:58 */ import { Component, OnInit, ViewChild, Inject } from '@angular/core'; import { HttpClient } from '@angular/common/http' import { MatTreeFlatDataSource, MatTreeFlattener } from '@angular/material/tree'; import { MatPaginator } from '@angular/material/paginator'; import { FlatTreeControl } from '@angular/cdk/tree'; import { FormControl } from '@angular/forms'; import { Router,ActivatedRoute } from '@angular/router' import { PageEvent } from '@angular/material/paginator'; import { MatDialogRef, MatDialog, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; import { TreeService } from '../../http-interceptors/tree.service' import { ConstantPool } from '@angular/compiler'; import { MatTableDataSource } from '@angular/material/table'; declare var CryptoJS @Component({ selector: 'app-onetwo-entry-plan', templateUrl: './onetwo-entry-plan.component.html', styleUrls: ['./onetwo-entry-plan.component.scss'] }) export class OnetwoEntryPlanComponent implements OnInit { constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,private tree: TreeService,public dialog: MatDialog,public snackBar: MatSnackBar) { } ngOnInit(): void { if(window.matchMedia("(max-width: 1400px)").matches){ this.pcMore=false this.padMore=true this.pcfind=false this.padjt=true }else{ this.pcfind=true this.pcMore=true this.padMore=false this.padjt=false } this.levels = sessionStorage.getItem("level"); if(this.levels == "0"){//如果是总队 this.preparelevels = [ {name:"总队",value:"1"}, {name:"支队",value:"2"}, {name:"大队",value:"4"}, {name:"中队",value:"8"} ] } if(this.levels == "1"){//如果是支队 this.preparelevels = [ {name:"支队",value:"2"}, {name:"大队",value:"4"}, {name:"中队",value:"8"} ] } if(this.levels == "2"){//如果是大队 this.preparelevels = [ {name:"大队",value:"4"}, {name:"中队",value:"8"} ] } if(this.levels == "3"){//如果是中队 this.preparelevels = [ {name:"中队",value:"8"} ] } this.url=window.location.href.substring(window.location.href.length-1,window.location.href.length) this.getAlltabledate() } pcMore//pc更多 pcput=false//pc收起 pcfind//pc查询 padjt=false padMore=true//pad收缩控制 padput=false//pad收起按钮 imgsrcopen="../../../assets/images/routdown2.png" imgsrcdown="../../../assets/images/routup2.png" pcInfo(){ this.pcMore=!this.pcMore this.pcput=!this.pcput } padInfo(){ this.padMore=!this.padMore this.padput=!this.padput } levels url preparelevels:any plcheck:boolean //编制级别勾选框 displayedColumns: string[] = ['unitname','level','addname','addtime', 'plantype', 'passstate','isopen','projectlevel','operation']; tabledataSource unitname//预案名称 level//预案级别 addname//添加人 addtime//添加时间 endtime//结束时间 reservePlanType//预案类型 unitstate//审核状态 projectlevel//编制级别 typePlan//新预案类型 //分页 @ViewChild(MatPaginator, {static: true}) pageEvent: PageEvent; paginator: MatPaginator; length:any; //共多少条数据 pageSize:any; //每页条数 pageSizeOptions: number[] = [10] //设置每页条数 PageNumber:any; //第几页 //获取表格数据 getAlltabledate(){ let reservePlanType this.reservePlanType ? reservePlanType = JSON.parse(JSON.stringify(this.reservePlanType)) : reservePlanType = '' if(this.reservePlanType && this.reservePlanType.length != 0){ reservePlanType = eval(this.reservePlanType.join("|")) } let paramsdata:any = { Name:this.unitname||'', planCategories:this.url=='2'?2:1, //PlanType:reservePlanType||'', DisasterType:this.typePlan||'', CreatorName:this.addname||'', AuditStatus:this.unitstate|| '', CreationTimeRangeStart:this.addtime||'', CreationTimeRangeEnd:this.endtime||'', PlanLevel:this.projectlevel||'', HasChildrenPlanLevel:this.plcheck||'', PageNumber: this.PageNumber || '1', PageSize: this.pageSizeOptions[0], } this.http.get("/api/PlanComponentsMajor",{params:paramsdata}).subscribe((data:any)=>{ this.length = data.totalCount this.tabledataSource = data.items }) } //分页事件 changePage(e){ this.PageNumber = e.pageIndex+1 this.getAlltabledate() } //重置 reset(){ this.typePlan='' this.unitname='' this.level='' this.addname='' this.addtime='' this.endtime='' this.reservePlanType='' this.unitstate='' this.projectlevel='' this.plcheck=false this.getAlltabledate() } //查询 onSubmit (value) { //console.log(value) if(this.endtime!=undefined&&this.addtime>this.endtime){ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.snackBar.open('开始时间不能大于结束时间!','确定',config); }else{ this.PageNumber = 1 this.pageEvent.pageIndex = 0 this.getAlltabledate(); } } //删除预案 deletePlan(id){ let isTrue = confirm('您确定要删除吗') if(isTrue){ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.http.delete(`/api/PlanComponentsMajor/${id}`).subscribe(data=>{ this.snackBar.open('删除成功!','确定',config); this.getAlltabledate() },err => { this.snackBar.open(err,'确定',config); }) } } //提交审核 submitAudit(element){ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 /* if(element.auditStatus == 4){ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.snackBar.open('审核退回的预案需要修改后方可再次提交审核!','确定',config); } */ this.http.put(`/api/PlanComponentsMajor/${element.id}/Commit`,"").subscribe(data=>{ this.getAlltabledate() },err => { this.snackBar.open(err,'确定',config); }) } //撤销审核 cancelAudit(element){ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.http.put(`/api/PlanComponentsMajor/${element.id}/Cancel`,"").subscribe(data=>{ this.getAlltabledate() },err => { this.snackBar.open(err,'确定',config); }) } //查看预案 openPlan(element){ let filename:string let fetchUrl = element.attachmentUrls[0] let docIdWordArray = CryptoJS.enc.Utf8.parse(`PlanPlatform/` + fetchUrl); let docId = CryptoJS.enc.Base64.stringify(docIdWordArray); let jwt = sessionStorage.getItem("token"); let rawJwt = CryptoJS.enc.Base64.parse(jwt.split('.')[1]); let identityJson = CryptoJS.enc.Utf8.stringify(rawJwt); let identityJsonparse=JSON.parse(identityJson) this.http.get(`/api/ObjectMetadata/PlanPlatform/${fetchUrl}`).subscribe((data:any)=>{ filename=data.fileName let json={ doc: { docId: docId, title: filename, fetchUrl: `http://172.18.0.1:8000/api/Objects/PlanPlatform/`+fetchUrl, }, user: { uid: identityJsonparse.sub, nickName: identityJsonparse.name, avatar: "", privilege:element.auditStatus!='1'&&element.auditStatus!='16'?[ 'FILE_READ','FILE_WRITE','FILE_DOWNLOAD', 'FILE_PRINT' ]:[ 'FILE_READ','FILE_DOWNLOAD', 'FILE_PRINT' ], }, } var stringjson=JSON.stringify(json) var wordArray = CryptoJS.enc.Utf8.parse(stringjson); var base64 = CryptoJS.enc.Base64.stringify(wordArray); window.open(`http://10.81.73.39:18080/apps/editor/openPreview?data=${base64}`) }) } //新增预案弹窗 addunit(){ const dialogRef = this.dialog.open(newunitComponent, { width: '340px', height:'410px', disableClose:true //data: paperDataInfo }); dialogRef.afterClosed().subscribe(result => { this.getAlltabledate() } ); } //审核结果 auditResult(element){ // console.log(element) const dialogRef = this.dialog.open(onetwoAuditResult, { width:"400px", //height:"300px", data: {element:element} }); } //下载↓ selectDownloadFile:any; //选择下载的文件 download:any; //下载文件元数据 downloadisLoading:boolean = false; //进度条loading加载 downloadProgress:number=0; //进度条进度 downloadFileName:any fileUrls:any //当前预案附件地址 fileDatas:any = [] selectedFileIndex : any = 0 selectedFileData : any uploadFileLonging:any //读取下载文件信息 readFile (element) { this.uploadFileLonging = element element.attachmentUrls.forEach(item=>{ this.http.get('/api/ObjectMetadata/PlanPlatform/'+item).subscribe((data:any)=>{ data.filePige = (data.fileLength / (1024*1024)).toFixed(2) //console.log(data) this.download = data this.downloadFile() }) }) } //初始化下载 downloadFile () { this.downloadProgress = 0 let file = this.download let fileSize = file.fileLength//下载文件的总大小 let shardSize = 10 * 1024 * 1024 //文件大小是否大于10MB if (file && fileSize<=shardSize) { //<=10MB时直接下载 this.downloadisLoading = true // this.setFileLoading() this.http.get(`/api/Objects/PlanPlatform/${file.objectName}`,{responseType: 'blob'},).subscribe(data=>{ let url = window.URL.createObjectURL(new Blob([data])); //createObjectURL创建一个下载Blob的url地址 let link = document.createElement("a"); link.style.display = "none"; link.href = url; let suffix = file.objectName.substring(file.objectName.lastIndexOf(".")+1,file.objectName.length) ; link.setAttribute("download", file.fileName + "-" +this.uploadFileLonging.name + "." + suffix); document.body.appendChild(link); link.click(); this.downloadisLoading = false // this.setFileLoading() }) } else if (file && fileSize > shardSize) { //>10MB时分块下载 this.blockingDownload() //分段下载 this.downloadisLoading = true // this.setFileLoading() } } //分段下载并合并 async blockingDownload () { let file = this.download let fileSize = file.fileLength //下载文件的总大小 let shardSize = 3 * 1024 * 1024 //3MB一个分片 let allSlice = Math.ceil(fileSize / shardSize) //总文件/3MB===共分多少段 let allFile:any = [] //所有的file分段 for (let i=0;i{ this.http.get(`/api/Objects/PlanPlatform/${file.objectName}`,{headers:{'range':`bytes= ${start}-${end}`},responseType:'blob'}).subscribe(data=>{ result(data) }) }) allFile.push(result) this.downloadProgress = Number((i/allSlice).toFixed(2))*100 if (allFile.length === allSlice) { //合并文件输出给浏览器 let url = window.URL.createObjectURL(new Blob(allFile)); //createObjectURL创建一个下载Blob的url地址 let link = document.createElement("a"); link.style.display = "none"; link.href = url; let suffix = file.objectName.substring(file.objectName.lastIndexOf(".")+1,file.objectName.length) ; link.setAttribute("download", file.fileName + "-" +this.uploadFileLonging.name + "." + suffix); document.body.appendChild(link); link.click(); // this.downloadProgress = 0 this.downloadisLoading = false // this.setFileLoading() } } //for循环 } //取消分块下载 cancelDowload () { } //查看预案按钮跳转 routerTo(element){ sessionStorage.setItem("companyName",element.unitname) window.open(`/planManagement/entryPlandetail?unitId=${element.company.id}&unitTypeId=${element.company.buildingTypes.length == 0 ? null :element.company.buildingTypes[0].id}&operation=true&pagetype=entryplan&unitName=${element.company.name}&orName=${element.company.organizationName}&unitType=${element.company.buildingTypes.length == 0 ? null :element.company.buildingTypes[0].name}&unitAdd=${element.company.address}`); } } //新建 @Component({ selector: 'new-unit', templateUrl: './newunit.html', styleUrls: ['./newunit.scss'] }) export class newunitComponent{ constructor(private router:Router,private http: HttpClient,public dialog: MatDialog,public snackBar: MatSnackBar,public dialogRef: MatDialogRef,@Inject(MAT_DIALOG_DATA) public data: any) {} ngOnInit(): void { this.url=window.location.href.substring(window.location.href.length-1,window.location.href.length) } url unitname//预案名称 level//预案级别 addname//添加人 addtime//添加时间 reservePlanType//预案类型 unitstate//审核状态 projectlevel//编制级别 //上传文件↓ file:any; //上传的文件 fileName:any; //上传文件name uploadisLoading:boolean = false; //进度条loading加载 uploadProgress:number=0; //进度条进度 objectName:any; //上传对象名 uploadId:any; //上传分块上传事件编号 uploadover:any = false //上传完成之后提示 selectedPLanType:any//所选预案类型 selectedPLanName:any//所选预案名称 localup:boolean = false //本地上传 defaultisshow = '0' //默认显示上传input框 //上传 upload(){ document.getElementById('up').click() } //上传文件input filechange(e){ this.file = e.target.files[0] || null //上传的文件 } //上传文件 startUploading (planType) { let file = this.file || null //获取上传的文件 let fileSize = file.size || null //上传文件的总大小 let shardSize = 5 * 1024 * 1024 //5MB一个分片 if (file && fileSize<=shardSize) { //上传文件<=5MB时 let formData = new FormData() formData.append("file",file) const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.http.post(this.url=='2'?`/api/Objects/PlanPlatform/twoClass`:'/api/Objects/PlanPlatform/oneClass',formData).subscribe((data:any)=>{ this.objectName = data.objectName //this.snackBar.open('上传成功!','确定',config); let level = sessionStorage.getItem("level") // console.log(level) let PlanLevel if(level == '0'){ PlanLevel = 1 } if(level == '1'){ PlanLevel = 2 } if(level == '2'){ PlanLevel = 4 } if(level == '3'){ PlanLevel = 8 } let body:any = { Name:this.unitname||'', PlanCategory:this.url=='2'?2:1, disasterType: this.reservePlanType, PlanLevel:PlanLevel, PlanMode:1, planType:16, attachmentUrls:[`${this.objectName}`] } this.http.post("/api/PlanComponentsMajor",body).subscribe((data:any)=>{ this.snackBar.open('创建成功!','确定',config); this.dialogRef.close(); },err=>{ this.snackBar.open('创建失败!','确定',config); }) },err=>{ this.snackBar.open('上传失败!','确定',config); }) } else if (file && fileSize>shardSize) { //上传文件>5MB时,分块上传 let data = {filename: file.name} this.uploadisLoading = true this.http.post(this.url=='2'?`/api/NewMultipartUpload/PlanPlatform/twoClass`:'/api/NewMultipartUpload/PlanPlatform/oneClass',{},{params:data}).subscribe((data:any)=>{ //初始化分段上传 this.objectName = data.objectName this.uploadId = data.uploadId this.subsectionUploading(planType) }) } } PartNumberETag:any=[]; //每次返回需要保存的信息 //开始分段上传 async subsectionUploading (planType) { let file = this.file || null //获取上传的文件 let fileSize = file.size || null //上传文件的总大小 let shardSize = 5 * 1024 * 1024 //5MB一个分片 let allSlice = Math.ceil(fileSize / shardSize) //总文件/5MB===共分多少段 向上取整 for (let i = 0;i < allSlice;i++) { //循环分段上传 let start = i * shardSize //切割文件开始位置 let end = Math.min(fileSize, start + shardSize); //切割文件结束位置 (对比取小数) let formData = new FormData() formData.append("file",file.slice(start, end)) //同步写法实现异步调用 let result = await new Promise((resolve, reject) => { // await 需要后面返回一个 promise 对象 this.http.post(`/api/MultipartUpload/PlanPlatform/${this.objectName}?uploadId=${this.uploadId}&partNumber=${i+1}`,formData).subscribe((data:any)=>{ let msg = { "partNumber":data.partNumber || null, "eTag": data.eTag || null} resolve(msg) // 调用 promise 内置方法处理成功 }) }); this.PartNumberETag.push(result) this.uploadProgress = Number((i/allSlice).toFixed(2))*100 if (this.PartNumberETag.length === allSlice) { this.uploadProgress = 100 this.endUploading(planType)} }//for循环 } //完成分块上传 endUploading (planType) { let data = this.PartNumberETag let paramsData = {uploadId:this.uploadId} this.http.post(`/api/CompleteMultipartUpload/PlanPlatform/${this.objectName}`,data,{params:paramsData}).subscribe(data=>{ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 //this.snackBar.open('上传成功!','确定',config); this.uploadProgress = 0; this.uploadisLoading = false this.PartNumberETag =[] //清空保存返回的信息 this.uploadover = true let level = sessionStorage.getItem("level") // console.log(level) let PlanLevel if(level == '0'){ PlanLevel = 1 } if(level == '1'){ PlanLevel = 2 } if(level == '2'){ PlanLevel = 4 } if(level == '3'){ PlanLevel = 8 } let body:any = { Name:this.unitname||'', PlanCategory:this.url=='2'?2:1, disasterType: this.reservePlanType, PlanLevel:PlanLevel, PlanMode:1, planType:16, attachmentUrls:[`${this.objectName}`] } this.http.post("/api/PlanComponentsMajor",body).subscribe((data:any)=>{ this.snackBar.open('创建成功!','确定',config); this.dialogRef.close(); },err=>{ this.snackBar.open('创建失败!','确定',config); }) }) } //取消分块上传 cancel () { this.http.delete(`/api/MultipartUpload/PlanPlatform/${this.objectName}?uploadId=${this.uploadId}`).subscribe(data=>{ this.uploadProgress = 0; this.uploadisLoading= false; (document.getElementById('up')).value = null this.PartNumberETag =[] //清空保存返回的信息 const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 this.snackBar.open('取消上传成功!','确定',config); this.uploadover = false this.file = null }) } //创建预案 newplan(){ const config = new MatSnackBarConfig(); config.verticalPosition = 'top'; config.duration = 3000 if(this.unitname==undefined||this.reservePlanType==undefined){ this.snackBar.open('请输入预案名称或类型!','确定',config); } else if(this.file==undefined){ this.snackBar.open('请先上传文件!','确定',config); } else{ if(this.reservePlanType!='1'){ this.startUploading("非二维") } else{this.startUploading("二维")} } } //取消按钮 close(){ this.dialogRef.close(); } } //查看审核结果 @Component({ selector: 'resultonetwo', templateUrl: './resultPlanonetwo.html', styleUrls: ['./onetwo-entry-plan.component.scss'] }) export class onetwoAuditResult{ constructor(private http: HttpClient,public dialogRef: MatDialogRef,@Inject(MAT_DIALOG_DATA) public data,public snackBar: MatSnackBar) {} planName:any = this.data.element.name commitTime:any = this.data.element.committedTime commitOrganizationName:any = this.data.element.committerOrganizationName auditOrganizationName:any = this.data.element.auditorOrganizationName auditResult:any = this.data.element.auditStatus auditOpinion:any = this.data.element.auditOpinion ngOnInit(): void { } onNoClick(): void { this.dialogRef.close(); } }