feat: only support to upload .json file

This commit is contained in:
夜鹰 2022-06-17 18:09:58 +08:00
parent 5cd80ab96a
commit 8160607473
2 changed files with 9 additions and 2 deletions

View File

@ -34,8 +34,8 @@
</nz-radio-group>
</div>
<div class="mt-4" *ngIf="allowDrag">
<nz-upload *ngIf="extensionList.length" nzType="drag" [nzBeforeUpload]="parserFile">
<div class="mt-4" *ngIf="allowDrag && extensionList.length">
<nz-upload nzType="drag" [nzBeforeUpload]="parserFile">
<p class="ant-upload-drag-icon">
<i nz-icon nzType="inbox"></i>
</p>

View File

@ -1,6 +1,7 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Observable, Observer } from 'rxjs';
import { parserJsonFile } from '../../../utils';
import { EoMessageService } from '../../../eoui/message/eo-message.service';
type optionType = {
label: string;
@ -22,6 +23,8 @@ export class ExtensionSelectComponent {
@Output() uploadChange = new EventEmitter<any>();
filename = '';
constructor(private message: EoMessageService) {}
selectExtension({ key, properties }) {
this.extensionChange.emit(key);
if (!properties) {
@ -37,6 +40,10 @@ export class ExtensionSelectComponent {
parserFile = (file) =>
new Observable((observer: Observer<boolean>) => {
if (file.type !== 'application/json') {
this.message.error('仅支持上传 JSON 格式的文件');
observer.complete();
}
parserJsonFile(file).then((result: { name: string }) => {
this.filename = result.name;
this.uploadChange.emit(result);