Commit d7e3efa8 authored by limingzhe's avatar limingzhe

fix: debug

parent 783b94c5
......@@ -25,6 +25,22 @@
</div>
<div style="float: right; margin-right: -110px;" align="center">
<button style="" nz-button nzShape="circle" (click)="sortQues(i+1, i)">
<i nz-icon nzType="up" nzTheme="outline"></i>
</button>
<div style="margin: 5px;">
<input type="text" style="text-align: center; width: 50px;" nz-input [(ngModel)]="ques.quesIndex" (blur)="sortQues(i+1, ques.quesIndex)" >
</div>
<button style="" nz-button nzShape="circle" (click)="sortQues(i+1, i+2)">
<i nz-icon nzType="down" nzTheme="outline"></i>
</button>
</div>
<div style=" display: flex; align-items: center; ">
<span>标题:</span>
<input type="text" nz-input [(ngModel)]="ques.title" (blur)="save()" style=" width: 350px;">
......
......@@ -509,9 +509,46 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
// if (!this.item.group_arr) {
// this.item.group_arr = [];
// }
this.refreshQuesIndex();
}
refreshQuesIndex() {
this.item.quesArr.forEach((element, index) => {
element.quesIndex = index + 1;
});
}
sortQues(baseId, targetId) {
console.log(' baseIndex : ' + baseId );
console.log(' targetIndex : ' + targetId );
this.moveElement(this.item.quesArr, baseId - 1, targetId - 1);
// this.refreshQuesIndex();
}
moveElement(arr, fromIndex, toIndex) {
// 检查索引是否有效
if (fromIndex < 0 || fromIndex >= arr.length || toIndex < 0 || toIndex >= arr.length) {
throw new Error('Invalid index');
}
// 获取要移动的元素
const element = arr[fromIndex];
// 移除元素
arr.splice(fromIndex, 1);
// 插入元素到新位置
arr.splice(toIndex, 0, element);
this.save();
return arr;
}
......@@ -1340,6 +1377,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
*/
save() {
this.refreshQuesIndex();
// if (this.tempItem) {
// this.item.tempItem = this.tempItem;
// }
......
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