|
@@ -23,6 +23,8 @@ import {
|
|
|
} from '@angular/forms';
|
|
|
import { textbookServer } from '../../../../services/textbook';
|
|
|
import * as eduTextBook from '../../../../services/EduTextbook'
|
|
|
+import { HttpClient } from '@angular/common/http';
|
|
|
+
|
|
|
@Component({
|
|
|
selector: 'app-attachment',
|
|
|
imports: [
|
|
@@ -91,7 +93,8 @@ export class AttachmentComponent implements OnInit {
|
|
|
constructor(
|
|
|
public tbookSer: textbookServer,
|
|
|
private msg: NzMessageService,
|
|
|
- private modal: NzModalService
|
|
|
+ private modal: NzModalService,
|
|
|
+ private http: HttpClient
|
|
|
) { }
|
|
|
ngOnInit() {
|
|
|
if (this.eduTextbook.id) {
|
|
@@ -297,4 +300,19 @@ export class AttachmentComponent implements OnInit {
|
|
|
let result = decodeURIComponent(str?.substring(index + 1))
|
|
|
return result || '未知文件名'
|
|
|
}
|
|
|
+
|
|
|
+ downloadFile(fileName:string){
|
|
|
+ // let fileName = '十四五”普通高等教育本科国家级规划教材第一次遴选推荐申报表.docx'
|
|
|
+ const fileUrl = `../../../../../public/file/${fileName}`;
|
|
|
+ this.http.get(fileUrl, { responseType: 'blob' }).subscribe((blob) => {
|
|
|
+ const url = window.URL.createObjectURL(blob);
|
|
|
+ const a = document.createElement('a');
|
|
|
+ a.href = url;
|
|
|
+ a.download = fileName;
|
|
|
+ document.body.appendChild(a);
|
|
|
+ a.click();
|
|
|
+ document.body.removeChild(a);
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|