upload-collect.component.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import Parse from 'parse';
  4. import { CompUploadComponent } from '../../../../app/comp-upload/comp-upload.component';
  5. import { NzRadioModule } from 'ng-zorro-antd/radio';
  6. import { CommonCompModule } from '../../../../services/common.modules';
  7. import { NzMessageService } from 'ng-zorro-antd/message';
  8. import { textbookServer } from '../../../../services/textbook';
  9. import { ProvierOssAli } from '../../../../app/comp-upload/provider-oss-aliyun';
  10. import { NzModalService } from 'ng-zorro-antd/modal';
  11. interface link {
  12. url: string;
  13. username?: string;
  14. password?: string;
  15. }
  16. @Component({
  17. selector: 'app-upload-collect',
  18. templateUrl: './upload-collect.component.html',
  19. styleUrls: ['./upload-collect.component.scss'],
  20. standalone: true,
  21. imports: [CommonCompModule, CommonModule, CompUploadComponent, NzRadioModule],
  22. })
  23. export class UploadCollectComponent implements OnInit {
  24. @Input('review') review: boolean = false; //只读
  25. @Input('eduTextbookVolume') eduTextbookVolume: Parse.Object | undefined;
  26. @Output() save: EventEmitter<any> = new EventEmitter<any>();
  27. collectFiles: Array<any> = []; //纸质教材PDF文件列表
  28. collectDigitFiles: Array<any> = []; //数字资源PDF文件列表
  29. collectLink: link = {
  30. url: '',
  31. username: '',
  32. password: '',
  33. }; //链接、账号密码
  34. radioValue: string = '上传文件';
  35. carrierShape: string = ''; //类型
  36. ossProvider: { signatureUrl: any } | undefined;
  37. constructor(
  38. private modal: NzModalService,
  39. public tbookSer: textbookServer,
  40. private msg: NzMessageService
  41. ) {
  42. this.ossProvider = new ProvierOssAli();
  43. }
  44. ngOnInit() {
  45. this.collectFiles = this.eduTextbookVolume?.get('collectFiles') || [];
  46. this.collectDigitFiles =
  47. this.eduTextbookVolume?.get('collectDigitFiles') || [];
  48. this.collectLink = this.eduTextbookVolume?.get('collectLink') || {
  49. url: '',
  50. username: '',
  51. password: '',
  52. };
  53. this.radioValue = this.eduTextbookVolume?.get('collectCheck') || '上传文件';
  54. this.carrierShape = this.eduTextbookVolume?.get('carrierShape')?.trim();
  55. }
  56. upload(e: any, type: string) {
  57. console.log('上传材料发生改变');
  58. console.log(e);
  59. if (type == 'collectFiles' || type == 'collectDigitFiles') {
  60. this[type] = e;
  61. }
  62. }
  63. async submitForm(type: string) {
  64. if (
  65. this.carrierShape == '纸质教材' ||
  66. this.carrierShape == '纸质教材附带数字资源'
  67. ) {
  68. let upload = this.collectFiles?.some((item) => item.url);
  69. // console.log(upload);
  70. if (!upload && type == 'sbmit') {
  71. // this.msg.warning('请上传纸质教材PDF文件');
  72. return;
  73. }
  74. this.eduTextbookVolume?.set('collectFiles', this.collectFiles);
  75. }
  76. if (
  77. this.carrierShape == '数字教材' ||
  78. this.carrierShape == '纸质教材附带数字资源'
  79. ) {
  80. let upload = this.collectDigitFiles?.some((item) => item.url);
  81. // console.log(upload);
  82. if (this.radioValue == '上传文件' && !upload && type == 'sbmit') {
  83. // this.msg.warning('请上传数字文件PDF');
  84. return;
  85. }
  86. this.eduTextbookVolume?.set('collectDigitFiles', this.collectDigitFiles);
  87. this.eduTextbookVolume?.set('collectCheck', this.radioValue);
  88. if (
  89. type == 'sbmit' &&
  90. ((this.radioValue == '链接' && !this.collectLink?.url) ||
  91. (this.radioValue == '链接和账号密码' &&
  92. (!this.collectLink?.url ||
  93. !this.collectLink?.username ||
  94. !this.collectLink?.password)))
  95. ) {
  96. // this.msg.warning('请填写完整信息');
  97. return;
  98. }
  99. this.eduTextbookVolume?.set('collectLink', this.collectLink);
  100. }
  101. /* 100:已上传 200:已提交*/
  102. this.eduTextbookVolume?.set(
  103. 'collectStatus',
  104. type == 'sbmit' ? '200' : '100'
  105. );
  106. await this.eduTextbookVolume?.save();
  107. return true;
  108. }
  109. async openUrl(url: string) {
  110. if (
  111. this.eduTextbookVolume?.get('editionUnit') ===
  112. this.tbookSer.profile.user?.department?.name
  113. ) {
  114. url = await this.ossProvider?.signatureUrl(url,{expires:120});
  115. this.modal.warning({
  116. nzTitle: '提示',
  117. nzContent: '教材文件临时链接已打开,请勿外泄。'
  118. });
  119. }
  120. window.open(url);
  121. }
  122. }