diff --git a/src/app/tabbar/tabbar.component.ts b/src/app/tabbar/tabbar.component.ts index 22b415c..846f094 100644 --- a/src/app/tabbar/tabbar.component.ts +++ b/src/app/tabbar/tabbar.component.ts @@ -1,9 +1,9 @@ -import { Component, OnInit,Output,EventEmitter } from '@angular/core'; +import { Component, OnInit, Output, EventEmitter } from '@angular/core'; import { HttpClient } from '@angular/common/http' -import { Router,ActivatedRoute,NavigationEnd } from '@angular/router' -import {CacheTokenService} from '../http-interceptors/cache-token.service'//引入服务 +import { Router, ActivatedRoute, NavigationEnd } from '@angular/router' +import { CacheTokenService } from '../http-interceptors/cache-token.service'//引入服务 import { MatDialog } from '@angular/material/dialog'; -import {ChangepasswordComponent} from '../ui/changepassword/changepassword.component' +import { ChangepasswordComponent } from '../ui/changepassword/changepassword.component' import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; import { filter } from 'rxjs/operators'; import { TabbarAndScoreService } from '../http-interceptors/tabbar-and-score.service'; @@ -23,127 +23,131 @@ export class TabbarComponent implements OnInit { defaulttheme = new EventEmitter(); @Output() redtheme = new EventEmitter(); - - onChange(eventValue: boolean){ + + onChange(eventValue: boolean) { this.toggleDarkTheme.emit(eventValue); } - constructor(private tabbarService: TabbarAndScoreService,private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,public dialog: MatDialog,public snackBar: MatSnackBar) { } + constructor(private tabbarService: TabbarAndScoreService, private http: HttpClient, private router: Router, private route: ActivatedRoute, public token: CacheTokenService, public dialog: MatDialog, public snackBar: MatSnackBar) { } grade = null //单位完整度得分 - title:any = "数字化预案编制管理平台" - planName:any = null + title: any = "数字化预案编制管理平台" + planName: any = null routerEventsListener //监测路由变化 - integrityData:any - companyIntegrityScore:any//是否显示单位分数 - isUpdates:any //是否显示单位提交审核 撤销审核等按钮 - contentVerify:any//当前单位的审核状态信息 - ngOnInit() { - + integrityData: any + companyIntegrityScore: any//是否显示单位分数 + isUpdates: any //是否显示单位提交审核 撤销审核等按钮 + contentVerify: any//当前单位的审核状态信息 + ngOnInit() { + this.routerEventsListener = this.router.events.pipe( filter(event => event instanceof NavigationEnd) ).subscribe((e) => { - this.title = "数字化预案编制管理平台" - this.planName = null - this.grade = null - this.isUpdates = null - if(this.router.url.indexOf("editunitinfo") == -1 || this.router.url.indexOf("viewunitinfoplan") == -1){//如果url地址是从录入预案跳转 - this.companyIntegrityScore = '' - } + this.title = "数字化预案编制管理平台" + this.planName = null + this.grade = null + this.isUpdates = null + if (this.router.url.indexOf("editunitinfo") == -1 || this.router.url.indexOf("viewunitinfoplan") == -1) {//如果url地址是从录入预案跳转 + this.companyIntegrityScore = '' + } }) - if(this.router.url.indexOf("editunitinfo") != -1 || this.router.url.indexOf("viewunitinfoplan") != -1){//如果url地址是从录入预案跳转 + if (this.router.url.indexOf("editunitinfo") != -1 || this.router.url.indexOf("viewunitinfoplan") != -1) {//如果url地址是从录入预案跳转 this.title = sessionStorage.getItem("companyName") this.planName = sessionStorage.getItem("planName") } - if(this.router.url.indexOf("editplaninfo") != -1 || (this.router.url.indexOf("viewunitinfo") != -1 && this.router.url.indexOf("viewunitinfoplan") == -1)){//如果url地址是从重点单位跳转 + if (this.router.url.indexOf("editplaninfo") != -1 || (this.router.url.indexOf("viewunitinfo") != -1 && this.router.url.indexOf("viewunitinfoplan") == -1)) {//如果url地址是从重点单位跳转 this.title = sessionStorage.getItem("companyName") this.getIntegrityScore() //从维护更新页面进入需要显示提交审核按钮 - if(this.route.snapshot.queryParams["isUpdates"] == '1'){ + if (this.route.snapshot.queryParams["isUpdates"] == '1') { this.contentVerify = JSON.parse(sessionStorage.getItem('contentVerify')) // console.log(6666,JSON.parse(sessionStorage.getItem('contentVerify'))) this.isUpdates = true } - this.tabbarService.getMessage().subscribe((message: any)=>{ + this.tabbarService.getMessage().subscribe((message: any) => { this.getIntegrityScore() }); } this.getUserInfo() - + } //根据usci获取当前单位的分数信息 - getIntegrityScore(){ - let params:any = { - USCI : this.route.snapshot.queryParams.usci - } - this.http.get('/api/Companies',{params:params}).subscribe((data:any) => { - this.companyIntegrityScore = data.items[0].companyIntegrityScore + getIntegrityScore() { + // let params:any = { + // USCI : this.route.snapshot.queryParams.usci + // } + // this.http.get('/api/Companies',{params:params}).subscribe((data:any) => { + // this.companyIntegrityScore = data.items[0].companyIntegrityScore + // }) + let unitId = sessionStorage.getItem('companyId') + this.http.get(`/api/Companies/${unitId}`).subscribe((data: any) => { + this.companyIntegrityScore = data.companyIntegrityScore }) } - isSpinner:boolean = false//下载帮助文档进度 + isSpinner: boolean = false//下载帮助文档进度 //下载帮助文档 - downloadHelpFile () { + downloadHelpFile() { this.getFileMSG() } - helpFile:any = 'api/ObjectMetadata/help/数字化预案编制管理平台手册.pdf'; //下载文件的url地址 - download:any; //下载的文件 + helpFile: any = 'api/ObjectMetadata/help/数字化预案编制管理平台手册.pdf'; //下载文件的url地址 + download: any; //下载的文件 //获取下载文件信息 - getFileMSG () { + getFileMSG() { this.isSpinner = true - this.http.get(`${this.helpFile}`).subscribe(data=>{ + this.http.get(`${this.helpFile}`).subscribe(data => { this.download = data this.downloadFile() - },err=>{ + }, err => { let config = new MatSnackBarConfig(); config.verticalPosition = 'bottom'; config.duration = 3000 - this.snackBar.open('下载失败','确定',config); + this.snackBar.open('下载失败', '确定', config); }) } //提交单位审核 - submitAudit(){ - let body:any = { - title : sessionStorage.getItem('companyName'), - Operation : sessionStorage.getItem('contentVerify') ? 1 : 0, - itemId : sessionStorage.getItem('companyId'), - verifyState : 3, - contentType : 11 + submitAudit() { + let body: any = { + title: sessionStorage.getItem('companyName'), + Operation: sessionStorage.getItem('contentVerify') ? 1 : 0, + itemId: sessionStorage.getItem('companyId'), + verifyState: 3, + contentType: 11 } - this.http.post(`/api/ContentVerifies`,body).subscribe(data=>{ + this.http.post(`/api/ContentVerifies`, body).subscribe(data => { this.contentVerify = data - sessionStorage.setItem('contentVerify',JSON.stringify(data)) - },err=>{ - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open(err,'确定',config); + sessionStorage.setItem('contentVerify', JSON.stringify(data)) + }, err => { + const config = new MatSnackBarConfig(); + config.verticalPosition = 'top'; + config.duration = 3000 + this.snackBar.open(err, '确定', config); }) } //撤销单位审核 - cancelAudit(){ - this.http.delete(`/api/ContentVerifies/${this.contentVerify.id}`).subscribe(data=>{ + cancelAudit() { + this.http.delete(`/api/ContentVerifies/${this.contentVerify.id}`).subscribe(data => { this.contentVerify = data - sessionStorage.setItem('contentVerify',JSON.stringify(data)) + sessionStorage.setItem('contentVerify', JSON.stringify(data)) }, - err=>{ - const config = new MatSnackBarConfig(); - config.verticalPosition = 'top'; - config.duration = 3000 - this.snackBar.open(err,'确定',config); - }) + err => { + const config = new MatSnackBarConfig(); + config.verticalPosition = 'top'; + config.duration = 3000 + this.snackBar.open(err, '确定', config); + }) } //初始化下载 - downloadFile () { + downloadFile() { let file = this.download let fileSize = file.fileLength//下载文件的总大小 let shardSize = 10 * 1024 * 1024 //文件大小是否大于10MB - if (file && fileSize<=shardSize) { //<=10MB时直接下载 - this.http.get(`/api/Objects/help/${file.objectName}`,{responseType: 'blob'},).subscribe(data=>{ + if (file && fileSize <= shardSize) { //<=10MB时直接下载 + this.http.get(`/api/Objects/help/${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"; @@ -152,33 +156,34 @@ export class TabbarComponent implements OnInit { document.body.appendChild(link); link.click(); this.isSpinner = false - },err=>{ + }, err => { let config = new MatSnackBarConfig(); config.verticalPosition = 'bottom'; config.duration = 3000 - this.snackBar.open('下载失败','确定',config); + this.snackBar.open('下载失败', '确定', config); }) - } else if (file && fileSize>shardSize) { //>10MB时分块下载 + } else if (file && fileSize > shardSize) { //>10MB时分块下载 this.blockingDownload() //分段下载 } } //分段下载并合并 - async blockingDownload () { + 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分段 + let allFile: any = [] //所有的file分段 - for (let i=0;i{ - this.http.get(`/api/Objects/help/${file.objectName}`,{headers:{'range':`bytes= ${start}-${end}`},responseType:'blob'}).subscribe(data=>{ - result(data) }) + let result = await new Promise((result, reject) => { + this.http.get(`/api/Objects/help/${file.objectName}`, { headers: { 'range': `bytes= ${start}-${end}` }, responseType: 'blob' }).subscribe(data => { + result(data) + }) }) allFile.push(result) @@ -196,44 +201,44 @@ export class TabbarComponent implements OnInit { } //for循环 } - - ngOnDestroy(){ + + ngOnDestroy() { this.routerEventsListener.unsubscribe() } - integrityDetails(width,zong){ - let style:any = {} - style.width = (width/zong)*100 +'%'; + integrityDetails(width, zong) { + let style: any = {} + style.width = (width / zong) * 100 + '%'; return style } //计分规则 - scoringRuleImg:boolean = false - scoringRule(){ + scoringRuleImg: boolean = false + scoringRule() { this.scoringRuleImg = !this.scoringRuleImg } - closebtn(){ + closebtn() { this.scoringRuleImg = false } - boxed(css){ + boxed(css) { const Element = document.body; Element.style.width = '1200px' } - standard(){ + standard() { const Element = document.body; Element.style.width = '100%' } - isfullscreen:boolean = false; - fullscreenToggle(){ + isfullscreen: boolean = false; + fullscreenToggle() { const docElmWithBrowsersFullScreenFunctions = document.documentElement as HTMLElement & { mozRequestFullScreen(): Promise; webkitRequestFullscreen(): Promise; msRequestFullscreen(): Promise; }; - + if (docElmWithBrowsersFullScreenFunctions.requestFullscreen) { docElmWithBrowsersFullScreenFunctions.requestFullscreen(); } else if (docElmWithBrowsersFullScreenFunctions.mozRequestFullScreen) { /* Firefox */ @@ -243,32 +248,32 @@ export class TabbarComponent implements OnInit { } else if (docElmWithBrowsersFullScreenFunctions.msRequestFullscreen) { /* IE/Edge */ docElmWithBrowsersFullScreenFunctions.msRequestFullscreen(); } - - this.isfullscreen = true; - - } - closefullscreen(){ - const docWithBrowsersExitFunctions = document as Document & { - mozCancelFullScreen(): Promise; - webkitExitFullscreen(): Promise; - msExitFullscreen(): Promise; - }; - if (docWithBrowsersExitFunctions.exitFullscreen) { - docWithBrowsersExitFunctions.exitFullscreen(); - } else if (docWithBrowsersExitFunctions.mozCancelFullScreen) { /* Firefox */ - docWithBrowsersExitFunctions.mozCancelFullScreen(); - } else if (docWithBrowsersExitFunctions.webkitExitFullscreen) { /* Chrome, Safari and Opera */ - docWithBrowsersExitFunctions.webkitExitFullscreen(); - } else if (docWithBrowsersExitFunctions.msExitFullscreen) { /* IE/Edge */ - docWithBrowsersExitFunctions.msExitFullscreen(); + + this.isfullscreen = true; + } - this.isfullscreen = false; + closefullscreen() { + const docWithBrowsersExitFunctions = document as Document & { + mozCancelFullScreen(): Promise; + webkitExitFullscreen(): Promise; + msExitFullscreen(): Promise; + }; + if (docWithBrowsersExitFunctions.exitFullscreen) { + docWithBrowsersExitFunctions.exitFullscreen(); + } else if (docWithBrowsersExitFunctions.mozCancelFullScreen) { /* Firefox */ + docWithBrowsersExitFunctions.mozCancelFullScreen(); + } else if (docWithBrowsersExitFunctions.webkitExitFullscreen) { /* Chrome, Safari and Opera */ + docWithBrowsersExitFunctions.webkitExitFullscreen(); + } else if (docWithBrowsersExitFunctions.msExitFullscreen) { /* IE/Edge */ + docWithBrowsersExitFunctions.msExitFullscreen(); + } + this.isfullscreen = false; } - realName:any; //登录用户信息 + realName: any; //登录用户信息 //获取用户信息 - getUserInfo () { - this.http.get("/api/Account/Profiles").subscribe((data:any)=>{ + getUserInfo() { + this.http.get("/api/Account/Profiles").subscribe((data: any) => { this.realName = data.realName }) } @@ -276,9 +281,9 @@ export class TabbarComponent implements OnInit { //退出系统 signOut = () => { let out = confirm("您确定要退出吗") - if(out) { - this.http.post('/api/Account/SignOut',{}).subscribe( - data=> { + if (out) { + this.http.post('/api/Account/SignOut', {}).subscribe( + data => { this.token.delete() sessionStorage.clear() window.localStorage.clear() @@ -286,7 +291,7 @@ export class TabbarComponent implements OnInit { const config = new MatSnackBarConfig(); config.verticalPosition = 'bottom'; config.duration = 3000 - this.snackBar.open('成功退出','确定',config); + this.snackBar.open('成功退出', '确定', config); } ) } @@ -294,10 +299,10 @@ export class TabbarComponent implements OnInit { //修改密码 changpsw() { - let dialogRef = this.dialog.open(ChangepasswordComponent, - {width:'348px'}); + let dialogRef = this.dialog.open(ChangepasswordComponent, + { width: '348px' }); - dialogRef.afterClosed().subscribe(); + dialogRef.afterClosed().subscribe(); } }