Newer
Older
import {Component, OnInit} from '@angular/core';
import {SystemService} from '../system/system.service';
import {LocalStorageService} from 'ngx-webstorage';
import {NzMessageService} from 'ng-zorro-antd';
@Component({
selector: 'smart-mine',
templateUrl: './mine.component.html',
styles: []
})
export class MineComponent implements OnInit {
dataSet = [];
constructor(private systemSer: SystemService, private localStorage: LocalStorageService,
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
}
ngOnInit() {
this.getList();
}
getList() {
this.systemSer.getMenuBySeparation().subscribe(
(res) => {
if (res.errCode == 10000) {
this.dataSet = res.data;
this.updateEditCache(null);
}
}
);
}
updateEditCache(num: number): void {
for (let i = 0; i < this.dataSet.length; i++) {
this.dataSet[i].key = i.toString();
}
this.dataSet.forEach((item, index) => {
item.key = index;
if (!this.editCache[item.key]) {
this.editCache[item.key] = {
edit: false,
data: item
};
}
if (item.key == num) {
this.editCache[item.key].edit = true;
}
});
}
add() {
const item = {
name: '',
parentId: '',
code: '',
url: '',
imageUrl: '',
showOrder: '',
this.dataSet = [item, ...this.dataSet];
this.editCache = [{data: item, edit: true}, ...this.editCache];
}
startEdit(key: string): void {
this.editCache[key].edit = true;
}
cancelEdit(key: string): void {
this.editCache[key].edit = false;
}
saveEdit(key: string): void {
const index = this.dataSet.findIndex(item => item.key === key);
this.dataSet[index] = this.editCache[key].data;
this.editCache[key].edit = false;
this.systemSer.createMenu(this.dataSet[index]).subscribe(
(res) => {
this.message.success('保存成功');
}
);
}
deleteItem(id: string) {
this.systemSer.deleteMenu(id).subscribe(
(res) => {
this.message.success('删除成功');
this.getList();
}
);
}
}