import { RhApiUrlsService, MsgHelper, FileHelper } from 'rh-base/core'; import { RhPortType, RhPortLocalFieldType } from 'rh-base/model'; import { DataResultT, RhBaseDto, RhSafeAny, RhTableButtonInfoDto, CodeClassModel, RhDynamicTableFieldDto, OpMode, RhTableQueryOptionDto, RhSelectItem, RhTableDisplayDto } from 'rh-base/model'; import { DynamicFormComponent } from 'rh-base/shared'; import { Component, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'rh-equipment-attach-file-manage', templateUrl: './equipment-attach-file-manage.component.html', styleUrls: ['./equipment-attach-file-manage.component.less'] }) export class RhEquipmentAttachFileManageComponent implements OnInit { @ViewChild('queryForm', { static: false }) queryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataresult!: DataResultT; defaultFieldDataset: RhDynamicTableFieldDto[] = []; dataLoading = false; editDto: RhBaseDto = {}; isShowPreviewModal = false; isVisualScan = false; fileUrl!: string; fileName!: string; fileCatory!: string; defaultEquipmentCode = ''; defaultQueryDto: RhSafeAny = {}; defaultEditDto: RhSafeAny = {}; readLoading = false; editButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('edit', '编辑', 'default', 'edit', false, null, (data) => this.openEditTab(data as RhBaseDto), true), new RhTableButtonInfoDto( 'scan', '附件查看', 'primary', false, 'eye', false, null, (data) => this.preview(data as RhBaseDto), true, true ), new RhTableButtonInfoDto( 'download', '附件下载', 'primary', false, 'download', false, null, (data) => this.downloadFile(data as RhBaseDto), true, true ) ]; titleButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('newButton', '新建', 'primary', 'file', false, null, () => this.openEditTab(), true) ]; extraButtonDataset: RhTableButtonInfoDto[] = [ // new RhTableButtonInfoDto('export', '数据导出', 'default', 'export', false, null, () => this.exportTable(), true) ]; documentTypes: RhSelectItem[] = []; // mappedDatas = [ // new RhTableDisplayDto('设备编码', 'EquipmentCode'), // new RhTableDisplayDto('文件名称', 'FileName'), // RhTableDisplayDto.create('文档类别', 'DocumentType', this.documentTypes), // new RhTableDisplayDto('上传时间', 'FileUploadTime', 'date', (item: Date): string => { // if (item) { // return DateHelper.format(new Date(item), 'yyyy-MM-dd HH:mm'); // } else { // return ''; // } // }), // new RhTableDisplayDto('备注', 'Remark') // ]; constructor(private apiUrls: RhApiUrlsService, private route: ActivatedRoute) { // } ngOnInit(): void { // this.initQueryDto(); } setDatas(dataset: DataResultT) { this.dataresult = dataset; } setInitFieldDataset(item: CodeClassModel) { const tempDatas: RhDynamicTableFieldDto[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } dataLoadingChange(status: boolean) { this.dataLoading = status; } openEditTab(data?: RhBaseDto) { if (data) { this.editDto = data; this.editDto.OpSign = OpMode.OpEdit; } else { this.editDto = {}; this.editDto.OpSign = OpMode.OpAdd; this.editDto['EquipmentCode'] = this.defaultEquipmentCode; } this.selectedIndex = 1; } closeEditTab() { this.selectedIndex = 0; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } private getDatas(option?: RhTableQueryOptionDto) { if (this.queryFormCmt) { this.queryFormCmt.submitDefaultForm(null, option); } } // 查看文件 closePreviewModal() { this.isShowPreviewModal = false; } openPreviewModal() { this.isShowPreviewModal = true; } onStoreDatas(result: DataResultT) { if (result && result.Success) { const msg = this.editDto.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}数据成功`); this.selectedIndex = 0; this.getDatas(); } else { MsgHelper.ShowWarningMessage(`数据存储失败!${result.Message}`); } } /** 文档预览 */ preview(item: RhSafeAny) { // const querDto = DocumentAbsoluteAddressQueryDto.create(); // querDto.DocumentInfoCode = item.EquipmentAttachCode; // const extensionName = /\.(png|jpg|jpeg|bmp|gif)/; // // 非图片传false,否则传入true // if (!extensionName.test(item.FileName.toLowerCase())) { // querDto.IsOriginalFile = false; // } else { // querDto.IsOriginalFile = true; // } // const url = this.apiUrls.GetApiOperateUrl( // RhPortType.emp, // 'EquipmentLedgerApi', // 'DownloadEquipmentAttachFile', // RhPortLocalFieldType.mdp // ); // FileHelper.PostFileBlob(url, querDto).subscribe((result) => { // this.fileUrl = FileHelper.CreateDownloadFileUrl(result); // this.fileName = item.FileName; // // this.fileCatory='.'+item.PdfRelativePath; // // const toPdfReg = /\.(png|jpg|jpeg|bmp|gif|webp|psd|svg|tiff|pdf)/; // // if (toPdfReg.test(this.fileCatory.toLowerCase())) { // /** 打开文档预览Modal */ // this.openPreviewModal(); // // } else { // // const anchor = document.createElement('a'); // // const FileName=item.FileName; // // anchor.download = FileName; // // anchor.href = this.fileUrl; // // anchor.click(); // // } // }); /** 打开文档预览Modal */ this.openPreviewModal(); //更换接口(Get接口),需上传新的文档才可用(因为后端路径有更改) const url = this.apiUrls.GetApiOperateUrl( RhPortType.emp, 'EquipmentLedgerApi', `PreviewEquipmentAttachFile?equipmentAttachCode=${item.EquipmentAttachCode}`, RhPortLocalFieldType.emp ); this.readLoading = true; FileHelper.GetFileBlob(url).subscribe( (result) => { this.fileUrl = FileHelper.CreateDownloadFileUrl(result); this.fileName = item.FileName; // this.fileCatory='.'+item.PdfRelativePath; // const toPdfReg = /\.(png|jpg|jpeg|bmp|gif|webp|psd|svg|tiff|pdf)/; // if (toPdfReg.test(this.fileCatory.toLowerCase())) { this.readLoading = false; // } else { // const anchor = document.createElement('a'); // const FileName=item.FileName; // // anchor.download = FileName.substring(0,FileName.indexOf('.')+1)+'pdf'; // anchor.download = FileName; // anchor.href = this.fileUrl; // anchor.click(); // } }, () => (this.readLoading = false) ); } /** 下载附件 */ downloadFile(item: RhSafeAny) { // const querDto = DocumentAbsoluteAddressQueryDto.create(); // querDto.DocumentInfoCode = item.EquipmentAttachCode; // querDto.IsOriginalFile = true; // const url = this.apiUrls.GetApiOperateUrl( // RhPortType.emp, // 'EquipmentLedgerApi', // 'DownloadEquipmentAttachFile', // RhPortLocalFieldType.mdp // ); // FileHelper.PostFileBlob(url, querDto).subscribe((result) => { // this.fileUrl = FileHelper.CreateDownloadFileUrl(result); // this.fileName = item.FileName; // const anchor = document.createElement('a'); // const FileName = item.FileName; // anchor.download = FileName; // // anchor.download = FileName.substring(0,FileName.indexOf('.')+1)+'pdf'; // anchor.href = this.fileUrl; // anchor.click(); // }); //更换接口(Get接口),需上传新的文档可用(因为后端路径有更改) const url = this.apiUrls.GetApiOperateUrl( RhPortType.emp, 'EquipmentLedgerApi', `DownloadEquipmentAttachFile?equipmentAttachCode=${item.EquipmentAttachCode}`, RhPortLocalFieldType.emp ); MsgHelper.ShowGlobalLoadingMessage('正在下载文件,请稍候。。。'); FileHelper.GetFileBlob(url).subscribe((result) => { this.fileUrl = FileHelper.CreateDownloadFileUrl(result); this.fileName = item.FileName; const anchor = document.createElement('a'); const FileName = item.FileName; anchor.download = FileName; // anchor.download = FileName.substring(0,FileName.indexOf('.')+1)+'pdf'; anchor.href = this.fileUrl; anchor.click(); setTimeout(() => { MsgHelper.CloseGlobalLoadingMessage(); }, 1000); }); } initQueryDto() { // 要在html中自定义表单组件里传值给rhValue this.route.queryParamMap.subscribe((result) => { this.defaultEquipmentCode = result.get('EquipmentCode') as string; this.defaultQueryDto.EquipmentCode = this.defaultEquipmentCode; // 编辑form给设备赋值 this.defaultEditDto.EquipmentCode = this.defaultEquipmentCode; this.defaultQueryDto = { ...this.defaultQueryDto }; }); } // ngOnChanges(changes: SimpleChanges) { // const { defaultEquipmentCode } = changes; // if (defaultEquipmentCode && !defaultEquipmentCode.isFirstChange && defaultEquipmentCode.currentValue) { // this.defaultEditDto.EquipmentCode = this.defaultEquipmentCode; // this.defaultQueryDto = { ...this.defaultQueryDto }; // } // } //#region 前端导出测试区域开始 //前端导出测试 // async exportTable() { // if (!this.dataresult.Attach.length) { // MsgHelper.ShowWarningModal('表格无数据!'); // return; // } // // 显示正在导出对话框 // const messageId = MsgHelper.ShowLoadingMessage('正在导出。。。'); // await this.getControlStatusName(); // FileHelper.formatExportExcelFile(this.dataresult.Attach, '数据导出', `导出测试`, this.mappedDatas); // MsgHelper.CloseLoadingMessage(messageId); // } // private getControlStatusName(): Promise { // return new Promise((resolve, reject) => { // this.apiUrls.getSettingEntry('EquipmentManagement', 'EquipmentLedger', 'EquipmentFileType').subscribe((result) => { // if (result.Success) { // this.documentTypes = result.Attach; // } else { // this.documentTypes = []; // } // this.mappedDatas = [ // new RhTableDisplayDto('设备编码', 'EquipmentCode'), // new RhTableDisplayDto('文件名称', 'FileName'), // RhTableDisplayDto.create('文档类别', 'DocumentType', this.documentTypes), // new RhTableDisplayDto('上传时间', 'FileUploadTime', 'date', (item: Date): string => { // if (item) { // return DateHelper.format(new Date(item), 'yyyy-MM-dd HH:mm'); // } else { // return ''; // } // }), // new RhTableDisplayDto('备注', 'Remark') // ]; // resolve(this.documentTypes); // }); // }); // } //#endregion 前端导出测试区域结束 }