Commit 8894f5b6 authored by 李维's avatar 李维

增加表单数据一键复制

parent c15fb9c1
No preview for this file type
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.
......@@ -242,6 +242,13 @@
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>
添加题目
</button>
<button nz-button nzType="default" class="copy-btn" (click)="copyJsonData()">
<i nz-icon nzType="copy" nzTheme="outline"></i>
复制JSON数据
</button>
</div>
<textarea #copyTextArea style="position: fixed; left: -10000;" [(ngModel)]="jsonData" nz-input></textarea>
</div>
</div>
......@@ -48,7 +48,12 @@
padding: 10px;
padding-top: 5vw;
}
}
}
}
}
.copy-btn {
margin-left: 10px;
}
\ No newline at end of file
import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef} from '@angular/core';
import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ElementRef, ViewChild} from '@angular/core';
import {NzMessageService} from "ng-zorro-antd";
@Component({
selector: 'app-form',
templateUrl: './form.component.html',
......@@ -10,6 +10,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
dataArray = [];
_item: any;
jsonData: String = "";
KEY = 'DataKey_MultipleChoice';
set item(item) {
......@@ -19,9 +20,11 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
return this._item;
}
@ViewChild('copyTextArea', {static: true}) copyTextArea: ElementRef;
@Output()
update = new EventEmitter();
constructor(private appRef: ApplicationRef) {
constructor(private appRef: ApplicationRef, private nzMessageService: NzMessageService) {
}
......@@ -144,6 +147,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
saveItem() {
this.save();
this.jsonData = JSON.stringify(this.item)
}
save() {
......@@ -152,6 +156,12 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
console.log(this.item)
}
copyJsonData() {
this.copyTextArea.nativeElement.select();
document.execCommand('copy');
this.nzMessageService.success('已复制');
}
refresh() {
setTimeout(() => {
this.appRef.tick();
......
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