Commit 785ff202 authored by 李维's avatar 李维

添加直接从JSON设置数据功能

parent 69b1542d
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -58,7 +58,7 @@
<thead>
<tr>
<th nzWidth="100px" nzAlign="center">序号</th>
<th *ngIf="it.hotZoneType == '3' || it.hotZoneType == '4'" nzWidth="100px" nzAlign="center">正确答案</th>
<th nzWidth="100px" nzAlign="center">正确答案</th>
<th *ngIf="it.hotZoneType == '4'" nzWidth="100px" nzAlign="center">分数</th>
<th *ngIf="it.hotZoneType == '0'">文字</th>
<th *ngIf="it.hotZoneType == '1'">图片</th>
......@@ -70,7 +70,7 @@
<tr *ngFor="let data of contentTable.data; let i = index;">
<ng-container *ngIf="!(editCache[i] && editCache[i].edit); else editTemplate">
<td nzWidth="100px" nzAlign="center">{{ i + 1 }}</td>
<td *ngIf="it.hotZoneType == '3'" nzWidth="100px" nzAlign="center">{{ data.isCorrect?'正确':'错误' }}</td>
<td *ngIf="it.hotZoneType != '4'" nzWidth="100px" nzAlign="center">{{ data.isCorrect?'正确':'错误' }}</td>
<td *ngIf="it.hotZoneType == '4'" nzWidth="100px" nzAlign="center">{{ data.isCheck?'勾选':'不勾选' }}</td>
<td *ngIf="it.hotZoneType == '4'" nzWidth="100px" nzAlign="center">{{ data.score }}</td>
<td *ngIf="it.hotZoneType == '0'">{{ data.text }}</td>
......@@ -89,7 +89,7 @@
</ng-container>
<ng-template #editTemplate>
<td nzWidth="100px" nzAlign="center">{{ i + 1 }}</td>
<td *ngIf="it.hotZoneType == '3'" nzWidth="100px" nzAlign="center">
<td *ngIf="it.hotZoneType != '3'" nzWidth="100px" nzAlign="center">
<label nz-checkbox [(ngModel)]="editCache[i].data.isCorrect"></label>
</td>
<td *ngIf="it.hotZoneType == '4'" nzWidth="100px" nzAlign="center">
......@@ -206,7 +206,12 @@
<label nz-checkbox [(ngModel)]="item.isDebug" (ngModelChange)="save()">调试模式</label>
</div>
<button nz-button nzType="primary" (click)="copyChangeData()" style="float: right;"><i nz-icon nzType="copy"></i>复制数据表单</button>
<button nz-button nzType="danger" (click)="showPasteModal=true;" style="float: right; margin-right: 10px;"><i nz-icon nzType="import"></i>从JSON导入配置</button>
</div>
<nz-modal [(nzVisible)]="showPasteModal" nzTitle="从JSON导入配置" (nzOnCancel)="showPasteModal=false;" (nzOnOk)="handlePasteData()">
<textarea [(ngModel)]="jsonData" nz-input rows="20" placeholder="请粘贴JSON数据"></textarea>
</nz-modal>
</div>
</div>
......@@ -25,7 +25,10 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy, AfterViewIni
saveKey = "OP72";
// 储存对象
item;
// JSON粘贴数据模态框
showPasteModal = false;
// 直接设置JSON数据
jsonData = "";
// 表格编辑缓存
editCache: { [key: string]: { edit: boolean; data } } = {};
......@@ -191,6 +194,19 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy, AfterViewIni
this.nzMessageService.success('复制成功');
}
// 直接从JSON设置数据
handlePasteData() {
try {
const data = JSON.parse(this.jsonData);
this.item = data;
this.showPasteModal = false;
this.nzMessageService.success('数据导入成功');
this.save();
} catch (e) {
this.nzMessageService.error('导入失败,请检查是否是标准的JSON格式');
}
}
ngAfterViewInit() {
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment