pad端六熟悉
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

170 lines
6.5 KiB

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 { MatTableDataSource } from '@angular/material/table';
import { DomSanitizer } from '@angular/platform-browser';
import {PlanOpen} from '../plan-audit/plan-audit.component'
import {ViewUnitDetailsPlanComponent} from '../../key-unit/view-unit-details-plan/view-unit-details-plan.component'
export interface Food {
name:string;
value: string;
}
@Component({
selector: 'app-plan-pass',
templateUrl: './plan-pass.component.html',
styleUrls: ['./plan-pass.component.scss']
})
export class PlanPassComponent implements OnInit {
constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,private tree: TreeService,public dialog: MatDialog,
public snackBar: MatSnackBar,private sanitizer: DomSanitizer) { }
type:any //审核按钮是否出现
ngOnInit(): void {
this.type = this.route.snapshot.queryParams.type
this.getCompanyData()
this.getPlanData()
}
displayedColumns: string[] = ['filename','addtime','operation']; //表头
compantData:any = {name:'',organizationName: '', buildingTypes:[{name:''}], address:''}; //当前单位信息
planData:any; //审核预案信息
//获取当前单位信息
getCompanyData () {
let header = {
CompanyName: this.route.snapshot.queryParams.companyName || '',
PageSize: '100'}
this.http.get('/api/Plans',{params:header}).subscribe((data:any)=>{
data.items.forEach(element => {
if (element.companyId===this.route.snapshot.queryParams.id) {
this.compantData = element.company
return } });
})
}
//获取当前单位审核预案的信息
getPlanData () {
let header = {
CompanyName: this.route.snapshot.queryParams.companyName || '',
AuditStatus: this.route.snapshot.queryParams.auditStatus || '',
PageSize: '100',
}
this.http.get('/api/PlanAudits',{params:header}).subscribe((data:any)=>{
data.items.forEach(element => {
if (element.id===this.route.snapshot.queryParams.auditPlanId) {
this.planData = element
this.handleData()
return } });
})
}
planType:any; //展示预案类型
allFile:any = []; //类型=0时所有文件
thirdPartyURL:any; //类型=3时网址
handleData () {
this.planType = this.planData.planMode
let data = this.planData
if (this.planData.planMode==0) { //预案planMode=0时, 下载文件
data.attachmentUrls.forEach(item => {
this.http.get(`/api/ObjectMetadata/PlanPlatform/${item}`).subscribe((data:any)=>{
data.isLoading = false
this.allFile.push(data)
this.allFile = new MatTableDataSource<any>(this.allFile) })
});
} else if (this.planData.planMode==1) { //预案planMode=1时, 解析文档
} else if (this.planData.planMode==2) { //预案planMode=2时, 跳查看页面组件
sessionStorage.setItem("buildingTypeId", this.compantData.buildingTypes.length? this.compantData.buildingTypes[0].id: undefined);
sessionStorage.setItem("companyId",this.route.snapshot.queryParams.id);
sessionStorage.setItem("planId",this.route.snapshot.queryParams.auditPlanId);
sessionStorage.setItem("editable",'0');
} else if (this.planData.planMode==3) { //预案planMode=3时, 第三方网址
this.thirdPartyURL = this.sanitizer.bypassSecurityTrustResourceUrl(data.url)
}
}
//预案审核
toExamine () {
let data = this.route.snapshot.queryParams.auditPlanId
const dialogRef = this.dialog.open(PlanOpen,{data});
}
suffix:string; //文件名后缀
//下载
download (e) {
e.isLoading = true
let file = e
let fileSize = file.fileLength //下载文件的总大小
let shardSize = 10 * 1024 * 1024 //文件大小是否大于10MB
this.suffix = this.compantData.name + '.' + (e.objectName.substring(e.objectName.lastIndexOf(".")+1,e.objectName.length));
if (file && fileSize<=shardSize) { //<=10MB时直接下载
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;
link.setAttribute("download", e.fileName?e.fileName : this.suffix);
document.body.appendChild(link);
link.click();
e.isLoading = false
})
} else if (file && fileSize>shardSize) { //>10MB时分块下载
this.blockingDownload(e) //分段下载
}
}
//分段下载并合并
async blockingDownload (e) {
let file = e
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<allSlice;i++) {
let start = i * shardSize //每次下载文件开始位置
let end = Math.min(fileSize, start + shardSize-1); //每次下载文件结束为止
let result = await new Promise ((result,reject)=>{
this.http.get(`/api/Objects/PlanPlatform/${file.objectName}`,{headers:{'range':`bytes= ${start}-${end}`},responseType:'blob'}).subscribe(data=>{
result(data) })
})
allFile.push(result)
e.progress = 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;
link.setAttribute("download", e.fileName?e.fileName : this.suffix);
document.body.appendChild(link);
link.click();
e.isLoading = false
e.progress = ''
}
} //for循环
}
}