Browse Source

[新增]增加文件下载链接

tangshan
邵佳豪 3 years ago
parent
commit
4d7f03dc4e
  1. 1
      src/app/statistic-analysis/home/home.component.ts
  2. 12
      src/app/tabbar/tabbar.component.html
  3. 166
      src/app/tabbar/tabbar.component.ts

1
src/app/statistic-analysis/home/home.component.ts

@ -52,7 +52,6 @@ export class HomeComponent implements OnInit {
this.planState.resize() this.planState.resize()
this.chartDwsjcj.resize() this.chartDwsjcj.resize()
this.chartZdgzqy.resize() this.chartZdgzqy.resize()
} */ } */
//获取数据 //获取数据
ordata ordata

12
src/app/tabbar/tabbar.component.html

@ -243,6 +243,18 @@
<mat-icon>save_alt</mat-icon> <mat-icon>save_alt</mat-icon>
<span>下载帮助文档</span> <span>下载帮助文档</span>
</button> </button>
<button mat-menu-item (click)="aFile('../../assets/helpword/plantemplate.zip','级卡片式预案模板')">
<mat-icon>save_alt</mat-icon>
<span>V级卡片式预案模板</span>
</button>
<button mat-menu-item (click)="aFile('../../assets/helpword/plancustom.zip','V级预案自定义')">
<mat-icon>save_alt</mat-icon>
<span>V级预案自定义</span>
</button>
<button mat-menu-item (click)="aFile('../../assets/helpword/planwebmake.zip','V级在线编制以及转在线导入')">
<mat-icon>save_alt</mat-icon>
<span>V级在线编制以及转在线导入</span>
</button>
</mat-menu> </mat-menu>
<!-- 全屏 --> <!-- 全屏 -->
<button mat-button (click)="!isfullscreen?fullscreenToggle():closefullscreen()" class="fullscreen"> <button mat-button (click)="!isfullscreen?fullscreenToggle():closefullscreen()" class="fullscreen">

166
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 { HttpClient } from '@angular/common/http'
import { Router,ActivatedRoute,NavigationEnd } from '@angular/router' import { Router, ActivatedRoute, NavigationEnd } from '@angular/router'
import {CacheTokenService} from '../http-interceptors/cache-token.service'//引入服务 import { CacheTokenService } from '../http-interceptors/cache-token.service'//引入服务
import { MatDialog } from '@angular/material/dialog'; 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 { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { filter } from 'rxjs/operators'; import { filter } from 'rxjs/operators';
import { TabbarAndScoreService } from '../http-interceptors/tabbar-and-score.service'; import { TabbarAndScoreService } from '../http-interceptors/tabbar-and-score.service';
@ -24,22 +24,22 @@ export class TabbarComponent implements OnInit {
@Output() @Output()
redtheme = new EventEmitter<boolean>(); redtheme = new EventEmitter<boolean>();
onChange(eventValue: boolean){ onChange(eventValue: boolean) {
this.toggleDarkTheme.emit(eventValue); 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 //单位完整度得分 grade = null //单位完整度得分
title:any = "数字化预案编制管理平台" title: any = "数字化预案编制管理平台"
planName:any = null planName: any = null
routerEventsListener //监测路由变化 routerEventsListener //监测路由变化
integrityData:any integrityData: any
companyIntegrityScore:any//是否显示单位分数 companyIntegrityScore: any//是否显示单位分数
isUpdates:any //是否显示单位提交审核 撤销审核等按钮 isUpdates: any //是否显示单位提交审核 撤销审核等按钮
contentVerify:any//当前单位的审核状态信息 contentVerify: any//当前单位的审核状态信息
ngOnInit() { ngOnInit() {
this.routerEventsListener = this.router.events.pipe( this.routerEventsListener = this.router.events.pipe(
@ -49,25 +49,25 @@ export class TabbarComponent implements OnInit {
this.planName = null this.planName = null
this.grade = null this.grade = null
this.isUpdates = null this.isUpdates = null
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.companyIntegrityScore = '' 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.title = sessionStorage.getItem("companyName")
this.planName = sessionStorage.getItem("planName") 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.title = sessionStorage.getItem("companyName")
this.getIntegrityScore() this.getIntegrityScore()
//从维护更新页面进入需要显示提交审核按钮 //从维护更新页面进入需要显示提交审核按钮
if(this.route.snapshot.queryParams["isUpdates"] == '1'){ if (this.route.snapshot.queryParams["isUpdates"] == '1') {
this.contentVerify = JSON.parse(sessionStorage.getItem('contentVerify')) this.contentVerify = JSON.parse(sessionStorage.getItem('contentVerify'))
// console.log(6666,JSON.parse(sessionStorage.getItem('contentVerify'))) // console.log(6666,JSON.parse(sessionStorage.getItem('contentVerify')))
this.isUpdates = true this.isUpdates = true
} }
this.tabbarService.getMessage().subscribe((message: any)=>{ this.tabbarService.getMessage().subscribe((message: any) => {
this.getIntegrityScore() this.getIntegrityScore()
}); });
} }
@ -75,81 +75,88 @@ export class TabbarComponent implements OnInit {
} }
//根据usci获取当前单位的分数信息 //根据usci获取当前单位的分数信息
getIntegrityScore(){ getIntegrityScore() {
let unitId = sessionStorage.getItem('companyId') let unitId = sessionStorage.getItem('companyId')
this.http.get(`/api/Companies/${unitId}`).subscribe((data:any) => { this.http.get(`/api/Companies/${unitId}`).subscribe((data: any) => {
this.companyIntegrityScore = data.companyIntegrityScore this.companyIntegrityScore = data.companyIntegrityScore
}) })
} }
isSpinner:boolean = false//下载帮助文档进度 isSpinner: boolean = false//下载帮助文档进度
//下载帮助文档 //下载帮助文档
downloadHelpFile () { downloadHelpFile() {
this.getFileMSG() this.getFileMSG()
} }
helpFile:any = 'api/ObjectMetadata/help/数字化预案编制管理平台手册.pdf'; //下载文件的url地址 helpFile: any = 'api/ObjectMetadata/help/数字化预案编制管理平台手册.pdf'; //下载文件的url地址
download:any; //下载的文件 download: any; //下载的文件
//获取下载文件信息 //获取下载文件信息
getFileMSG () { getFileMSG() {
this.isSpinner = true this.isSpinner = true
this.http.get(`${this.helpFile}`).subscribe(data=>{ this.http.get(`${this.helpFile}`).subscribe(data => {
this.download = data this.download = data
this.downloadFile() this.downloadFile()
},err=>{ }, err => {
let config = new MatSnackBarConfig(); let config = new MatSnackBarConfig();
config.verticalPosition = 'bottom'; config.verticalPosition = 'bottom';
config.duration = 3000 config.duration = 3000
this.snackBar.open('下载失败','确定',config); this.snackBar.open('下载失败', '确定', config);
}) })
} }
aFile(url, name) {
console.log('下载帮助文件')
let a = document.createElement("a");
a.href = url;
a.download = name;
a.click();
}
//提交单位审核 //提交单位审核
submitAudit(){ submitAudit() {
let isTrue = confirm('您确定要审核该条信息吗') let isTrue = confirm('您确定要审核该条信息吗')
if(isTrue){ if (isTrue) {
let body:any = { let body: any = {
title : sessionStorage.getItem('companyName'), title: sessionStorage.getItem('companyName'),
Operation : sessionStorage.getItem('contentVerify') ? 1 : 0, Operation: sessionStorage.getItem('contentVerify') ? 1 : 0,
itemId : sessionStorage.getItem('companyId'), itemId: sessionStorage.getItem('companyId'),
verifyState : 3, verifyState: 3,
contentType : 11 contentType: 11
} }
this.http.post(`/api/ContentVerifies`,body).subscribe(data=>{ this.http.post(`/api/ContentVerifies`, body).subscribe(data => {
this.contentVerify = data this.contentVerify = data
sessionStorage.setItem('contentVerify',JSON.stringify(data)) sessionStorage.setItem('contentVerify', JSON.stringify(data))
},err=>{ }, err => {
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open(err,'确定',config); this.snackBar.open(err, '确定', config);
}) })
} }
} }
//撤销单位审核 //撤销单位审核
cancelAudit(){ cancelAudit() {
let isTrue = confirm('您确定要撤销审核该条信息吗') let isTrue = confirm('您确定要撤销审核该条信息吗')
if(isTrue){ if (isTrue) {
this.http.delete(`/api/ContentVerifies/${this.contentVerify.id}`).subscribe(data=>{ this.http.delete(`/api/ContentVerifies/${this.contentVerify.id}`).subscribe(data => {
this.contentVerify = data this.contentVerify = data
sessionStorage.setItem('contentVerify',JSON.stringify(data)) sessionStorage.setItem('contentVerify', JSON.stringify(data))
}, },
err=>{ err => {
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'top'; config.verticalPosition = 'top';
config.duration = 3000 config.duration = 3000
this.snackBar.open(err,'确定',config); this.snackBar.open(err, '确定', config);
}) })
} }
} }
//初始化下载 //初始化下载
downloadFile () { downloadFile() {
let file = this.download let file = this.download
let fileSize = file.fileLength//下载文件的总大小 let fileSize = file.fileLength//下载文件的总大小
let shardSize = 10 * 1024 * 1024 //文件大小是否大于10MB let shardSize = 10 * 1024 * 1024 //文件大小是否大于10MB
if (file && fileSize<=shardSize) { //<=10MB时直接下载 if (file && fileSize <= shardSize) { //<=10MB时直接下载
this.http.get(`/api/Objects/help/${file.objectName}`,{responseType: 'blob'},).subscribe(data=>{ this.http.get(`/api/Objects/help/${file.objectName}`, { responseType: 'blob' },).subscribe(data => {
let url = window.URL.createObjectURL(new Blob([data])); //createObjectURL创建一个下载Blob的url地址 let url = window.URL.createObjectURL(new Blob([data])); //createObjectURL创建一个下载Blob的url地址
let link = document.createElement("a"); let link = document.createElement("a");
link.style.display = "none"; link.style.display = "none";
@ -158,33 +165,34 @@ export class TabbarComponent implements OnInit {
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
this.isSpinner = false this.isSpinner = false
},err=>{ }, err => {
let config = new MatSnackBarConfig(); let config = new MatSnackBarConfig();
config.verticalPosition = 'bottom'; config.verticalPosition = 'bottom';
config.duration = 3000 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() //分段下载 this.blockingDownload() //分段下载
} }
} }
//分段下载并合并 //分段下载并合并
async blockingDownload () { async blockingDownload() {
let file = this.download let file = this.download
let fileSize = file.fileLength //下载文件的总大小 let fileSize = file.fileLength //下载文件的总大小
let shardSize = 3 * 1024 * 1024 //3MB一个分片 let shardSize = 3 * 1024 * 1024 //3MB一个分片
let allSlice = Math.ceil(fileSize / shardSize) //总文件/3MB===共分多少段 let allSlice = Math.ceil(fileSize / shardSize) //总文件/3MB===共分多少段
let allFile:any = [] //所有的file分段 let allFile: any = [] //所有的file分段
for (let i=0;i<allSlice;i++) { for (let i = 0; i < allSlice; i++) {
let start = i * shardSize //每次下载文件开始位置 let start = i * shardSize //每次下载文件开始位置
let end = Math.min(fileSize, start + shardSize-1); //每次下载文件结束为止 let end = Math.min(fileSize, start + shardSize - 1); //每次下载文件结束为止
let result = await new Promise ((result,reject)=>{ let result = await new Promise((result, reject) => {
this.http.get(`/api/Objects/help/${file.objectName}`,{headers:{'range':`bytes= ${start}-${end}`},responseType:'blob'}).subscribe(data=>{ this.http.get(`/api/Objects/help/${file.objectName}`, { headers: { 'range': `bytes= ${start}-${end}` }, responseType: 'blob' }).subscribe(data => {
result(data) }) result(data)
})
}) })
allFile.push(result) allFile.push(result)
@ -204,36 +212,36 @@ export class TabbarComponent implements OnInit {
} }
ngOnDestroy(){ ngOnDestroy() {
this.routerEventsListener.unsubscribe() this.routerEventsListener.unsubscribe()
} }
integrityDetails(width,zong){ integrityDetails(width, zong) {
let style:any = {} let style: any = {}
style.width = (width/zong)*100 +'%'; style.width = (width / zong) * 100 + '%';
return style return style
} }
//计分规则 //计分规则
scoringRuleImg:boolean = false scoringRuleImg: boolean = false
scoringRule(){ scoringRule() {
this.scoringRuleImg = !this.scoringRuleImg this.scoringRuleImg = !this.scoringRuleImg
} }
closebtn(){ closebtn() {
this.scoringRuleImg = false this.scoringRuleImg = false
} }
boxed(css){ boxed(css) {
const Element = document.body; const Element = document.body;
Element.style.width = '1200px' Element.style.width = '1200px'
} }
standard(){ standard() {
const Element = document.body; const Element = document.body;
Element.style.width = '100%' Element.style.width = '100%'
} }
isfullscreen:boolean = false; isfullscreen: boolean = false;
fullscreenToggle(){ fullscreenToggle() {
const docElmWithBrowsersFullScreenFunctions = document.documentElement as HTMLElement & { const docElmWithBrowsersFullScreenFunctions = document.documentElement as HTMLElement & {
mozRequestFullScreen(): Promise<void>; mozRequestFullScreen(): Promise<void>;
webkitRequestFullscreen(): Promise<void>; webkitRequestFullscreen(): Promise<void>;
@ -253,7 +261,7 @@ export class TabbarComponent implements OnInit {
this.isfullscreen = true; this.isfullscreen = true;
} }
closefullscreen(){ closefullscreen() {
const docWithBrowsersExitFunctions = document as Document & { const docWithBrowsersExitFunctions = document as Document & {
mozCancelFullScreen(): Promise<void>; mozCancelFullScreen(): Promise<void>;
webkitExitFullscreen(): Promise<void>; webkitExitFullscreen(): Promise<void>;
@ -271,10 +279,10 @@ export class TabbarComponent implements OnInit {
this.isfullscreen = false; this.isfullscreen = false;
} }
realName:any; //登录用户信息 realName: any; //登录用户信息
//获取用户信息 //获取用户信息
getUserInfo () { getUserInfo() {
this.http.get("/api/Account/Profiles").subscribe((data:any)=>{ this.http.get("/api/Account/Profiles").subscribe((data: any) => {
this.realName = data.realName this.realName = data.realName
}) })
} }
@ -282,9 +290,9 @@ export class TabbarComponent implements OnInit {
//退出系统 //退出系统
signOut = () => { signOut = () => {
let out = confirm("您确定要退出吗") let out = confirm("您确定要退出吗")
if(out) { if (out) {
this.http.post('/api/Account/SignOut',{}).subscribe( this.http.post('/api/Account/SignOut', {}).subscribe(
data=> { data => {
this.token.delete() this.token.delete()
sessionStorage.clear() sessionStorage.clear()
window.localStorage.clear() window.localStorage.clear()
@ -292,7 +300,7 @@ export class TabbarComponent implements OnInit {
const config = new MatSnackBarConfig(); const config = new MatSnackBarConfig();
config.verticalPosition = 'bottom'; config.verticalPosition = 'bottom';
config.duration = 3000 config.duration = 3000
this.snackBar.open('成功退出','确定',config); this.snackBar.open('成功退出', '确定', config);
} }
) )
} }
@ -301,7 +309,7 @@ export class TabbarComponent implements OnInit {
//修改密码 //修改密码
changpsw() { changpsw() {
let dialogRef = this.dialog.open(ChangepasswordComponent, let dialogRef = this.dialog.open(ChangepasswordComponent,
{width:'348px'}); { width: '348px' });
dialogRef.afterClosed().subscribe(); dialogRef.afterClosed().subscribe();
} }

Loading…
Cancel
Save