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> </nz-radio-group>
</div> </div>
<div class="mt-4" *ngIf="allowDrag"> <div class="mt-4" *ngIf="allowDrag && extensionList.length">
<nz-upload *ngIf="extensionList.length" nzType="drag" [nzBeforeUpload]="parserFile"> <nz-upload nzType="drag" [nzBeforeUpload]="parserFile">
<p class="ant-upload-drag-icon"> <p class="ant-upload-drag-icon">
<i nz-icon nzType="inbox"></i> <i nz-icon nzType="inbox"></i>
</p> </p>

View File

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