上海预案管理平台
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.
 
 
 
 
 

303 lines
11 KiB

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 { MatDialog } from '@angular/material/dialog';
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';
@Component({
selector: 'app-tabbar',
templateUrl: './tabbar.component.html',
styleUrls: ['./tabbar.component.scss']
})
export class TabbarComponent implements OnInit {
theme: boolean = true;
@Output()
toggle = new EventEmitter<void>();
@Output()
toggleDarkTheme = new EventEmitter<boolean>();
@Output()
defaulttheme = new EventEmitter<boolean>();
@Output()
redtheme = new EventEmitter<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) { }
grade = null //单位完整度得分
title:any = "数字化预案编制管理平台"
planName:any = null
routerEventsListener //监测路由变化
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 = ''
}
})
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地址是从重点单位跳转
this.title = sessionStorage.getItem("companyName")
this.getIntegrityScore()
//从维护更新页面进入需要显示提交审核按钮
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.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
})
}
isSpinner:boolean = false//下载帮助文档进度
//下载帮助文档
downloadHelpFile () {
this.getFileMSG()
}
helpFile:any = 'api/ObjectMetadata/help/数字化预案编制管理平台手册.pdf'; //下载文件的url地址
download:any; //下载的文件
//获取下载文件信息
getFileMSG () {
this.isSpinner = true
this.http.get(`${this.helpFile}`).subscribe(data=>{
this.download = data
this.downloadFile()
},err=>{
let config = new MatSnackBarConfig();
config.verticalPosition = 'bottom';
config.duration = 3000
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
}
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);
})
}
//撤销单位审核
cancelAudit(){
this.http.delete(`/api/ContentVerifies/${this.contentVerify.id}`).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);
})
}
//初始化下载
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=>{
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", '数字化预案编制管理平台手册.pdf');
document.body.appendChild(link);
link.click();
this.isSpinner = false
},err=>{
let config = new MatSnackBarConfig();
config.verticalPosition = 'bottom';
config.duration = 3000
this.snackBar.open('下载失败','确定',config);
})
} else if (file && fileSize>shardSize) { //>10MB时分块下载
this.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分段
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/help/${file.objectName}`,{headers:{'range':`bytes= ${start}-${end}`},responseType:'blob'}).subscribe(data=>{
result(data) })
})
allFile.push(result)
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", '数字化预案编制管理平台手册.pdf');
document.body.appendChild(link);
link.click();
this.isSpinner = false
}
} //for循环
}
ngOnDestroy(){
this.routerEventsListener.unsubscribe()
}
integrityDetails(width,zong){
let style:any = {}
style.width = (width/zong)*100 +'%';
return style
}
//计分规则
scoringRuleImg:boolean = false
scoringRule(){
this.scoringRuleImg = !this.scoringRuleImg
}
closebtn(){
this.scoringRuleImg = false
}
boxed(css){
const Element = document.body;
Element.style.width = '1200px'
}
standard(){
const Element = document.body;
Element.style.width = '100%'
}
isfullscreen:boolean = false;
fullscreenToggle(){
const docElmWithBrowsersFullScreenFunctions = document.documentElement as HTMLElement & {
mozRequestFullScreen(): Promise<void>;
webkitRequestFullscreen(): Promise<void>;
msRequestFullscreen(): Promise<void>;
};
if (docElmWithBrowsersFullScreenFunctions.requestFullscreen) {
docElmWithBrowsersFullScreenFunctions.requestFullscreen();
} else if (docElmWithBrowsersFullScreenFunctions.mozRequestFullScreen) { /* Firefox */
docElmWithBrowsersFullScreenFunctions.mozRequestFullScreen();
} else if (docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen();
} else if (docElmWithBrowsersFullScreenFunctions.msRequestFullscreen) { /* IE/Edge */
docElmWithBrowsersFullScreenFunctions.msRequestFullscreen();
}
this.isfullscreen = true;
}
closefullscreen(){
const docWithBrowsersExitFunctions = document as Document & {
mozCancelFullScreen(): Promise<void>;
webkitExitFullscreen(): Promise<void>;
msExitFullscreen(): Promise<void>;
};
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; //登录用户信息
//获取用户信息
getUserInfo () {
this.http.get("/api/Account/Profiles").subscribe((data:any)=>{
this.realName = data.realName
})
}
//退出系统
signOut = () => {
let out = confirm("您确定要退出吗")
if(out) {
this.http.post('/api/Account/SignOut',{}).subscribe(
data=> {
this.token.delete()
sessionStorage.clear()
window.localStorage.clear()
this.router.navigate(['/login'])
const config = new MatSnackBarConfig();
config.verticalPosition = 'bottom';
config.duration = 3000
this.snackBar.open('成功退出','确定',config);
}
)
}
}
//修改密码
changpsw() {
let dialogRef = this.dialog.open(ChangepasswordComponent,
{width:'348px'});
dialogRef.afterClosed().subscribe();
}
}