Skip to content

Commit

Permalink
feat: only support to upload .json file
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfuboy committed Jun 17, 2022
1 parent 5cd80ab commit 8160607
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 8160607

Please sign in to comment.