Skip to content

Commit dbb24c9

Browse files
committed
refactor: Consolidate delete functions and update component imports
1 parent 88edfdd commit dbb24c9

File tree

6 files changed

+16
-46
lines changed

6 files changed

+16
-46
lines changed

src/components/delete-modal/index.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { NzMessageService } from 'ng-zorro-antd/message'
1111
import event from 'src/utils/mitt'
1212
import { $t } from 'src/locale'
1313
import { NzCheckboxModule } from 'ng-zorro-antd/checkbox'
14-
import { deleteWebByIds, deleteClassByIds } from 'src/utils/web'
14+
import { deleteByIds } from 'src/utils/web'
1515

1616
interface Props {
1717
ids: number[]
@@ -69,9 +69,7 @@ export class DeleteModalComponent {
6969
isDelRid = true
7070
}
7171

72-
const ok = await (this.isClass
73-
? deleteClassByIds(this.ids, isDelRid)
74-
: deleteWebByIds(this.ids, isDelRid))
72+
const ok = await deleteByIds(this.ids, isDelRid)
7573
if (ok) {
7674
this.onOk?.()
7775
this.message.success($t('_delSuccess'))

src/components/move-web/index.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { NzMessageService } from 'ng-zorro-antd/message'
1313
import { NzModalModule } from 'ng-zorro-antd/modal'
1414
import { NzCheckboxModule } from 'ng-zorro-antd/checkbox'
1515
import { NzSelectModule } from 'ng-zorro-antd/select'
16-
import { deleteWebByIds, deleteClassByIds } from 'src/utils/web'
16+
import { deleteByIds } from 'src/utils/web'
1717
import { getClassById } from 'src/utils'
1818
import { getTempId, isSelfDevelop } from 'src/utils/utils'
1919
import event from 'src/utils/mitt'
@@ -124,7 +124,7 @@ export class MoveWebComponent {
124124
delete item.rId
125125
}
126126
} else {
127-
await deleteClassByIds([item.rId || id], !!item.rId)
127+
await deleteByIds([item.rId || id], !!item.rId)
128128
}
129129
this.navs.update((prev) => {
130130
prev[oneIndex].nav.unshift(item)
@@ -155,7 +155,7 @@ export class MoveWebComponent {
155155
delete item.rId
156156
}
157157
} else {
158-
await deleteClassByIds([item.rId || id], !!item.rId)
158+
await deleteByIds([item.rId || id], !!item.rId)
159159
}
160160
this.navs.update((prev) => {
161161
prev[oneIndex].nav[twoIndex].nav.unshift(item)
@@ -189,7 +189,7 @@ export class MoveWebComponent {
189189
delete item.rId
190190
}
191191
} else {
192-
await deleteWebByIds([item.rId || id], !!item.rId)
192+
await deleteByIds([item.rId || id], !!item.rId)
193193
}
194194
this.navs.update((prev) => {
195195
prev[oneIndex].nav[twoIndex].nav[threeIndex].nav.unshift(item)

src/utils/web.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,17 @@ export function toggleCollapseAll(navs: INavProps[]): boolean {
9494
return collapsed
9595
}
9696

97-
export async function deleteWebByIds(
97+
export async function deleteByIds(
9898
ids: number[],
9999
isDelRid = false,
100100
): Promise<boolean> {
101101
let hasDelete = false
102102
const navsData = dfsNavs({
103103
navs: navs(),
104104
filter: (w) => {
105-
if (w.name) {
106-
if (ids.includes(isDelRid ? (w.rId as number) : w.id)) {
107-
hasDelete = true
108-
return false
109-
}
105+
if (ids.includes(isDelRid ? (w.rId as number) : w.id)) {
106+
hasDelete = true
107+
return false
110108
}
111109
return true
112110
},
@@ -182,32 +180,6 @@ export function updateByClass(oldId: number, newData: any) {
182180
return ok
183181
}
184182

185-
export async function deleteClassByIds(
186-
ids: number[],
187-
isDelRid = false,
188-
): Promise<boolean> {
189-
let hasDelete = false
190-
191-
const navsData = dfsNavs({
192-
navs: navs(),
193-
filter: (w) => {
194-
if (w.title) {
195-
if (ids.includes(isDelRid ? (w['rId'] as number) : w.id)) {
196-
hasDelete = true
197-
return false
198-
}
199-
}
200-
return true
201-
},
202-
})
203-
204-
if (hasDelete) {
205-
navs.set(navsData)
206-
await setNavs(navsData)
207-
}
208-
return hasDelete
209-
}
210-
211183
export function pushDataByAny(parentId: number, data: any): boolean {
212184
let ok = false
213185

src/view/system/collect/index.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { NzTableModule } from 'ng-zorro-antd/table'
1818
import { LogoComponent } from 'src/components/logo/logo.component'
1919
import { TagListComponent } from 'src/components/tag-list/index.component'
2020
import { ActionType } from 'src/types'
21-
import { deleteWebByIds, getWebById } from 'src/utils/web'
21+
import { deleteByIds, getWebById } from 'src/utils/web'
2222
import { JumpService } from 'src/services/jump'
2323
import event from 'src/utils/mitt'
2424

@@ -227,7 +227,7 @@ export default class CollectComponent {
227227
this.modal.info({
228228
nzTitle: $t('_confirmDel'),
229229
nzOnOk: async () => {
230-
if (await deleteWebByIds([data.id])) {
230+
if (await deleteByIds([data.id])) {
231231
this.message.success($t('_delSuccess'))
232232
} else {
233233
this.message.error('Delete failed')

src/view/system/web/index.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*ngIf="!isSelfDevelop"
1313
nz-button
1414
style="margin: 0 15px 20px 15px"
15-
(click)="handleReset()"
15+
(click)="handleRestoreData()"
1616
>
1717
{{ $t('_resetInitData') }}
1818
</button>

src/view/system/web/index.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { NzIconModule } from 'ng-zorro-antd/icon'
3535
import { NzModalModule } from 'ng-zorro-antd/modal'
3636
import { NzFormModule } from 'ng-zorro-antd/form'
3737
import { NzSwitchModule } from 'ng-zorro-antd/switch'
38-
import { NzToolTipModule } from 'ng-zorro-antd/tooltip'
38+
import { NzTooltipModule } from 'ng-zorro-antd/tooltip'
3939
import { LogoComponent } from 'src/components/logo/logo.component'
4040
import { TagListComponent } from 'src/components/tag-list/index.component'
4141
import { CommonService } from 'src/services/common'
@@ -47,7 +47,7 @@ import { cleanWebAttrs } from 'src/utils/pureUtils'
4747
standalone: true,
4848
imports: [
4949
CommonModule,
50-
NzToolTipModule,
50+
NzTooltipModule,
5151
FormsModule,
5252
ReactiveFormsModule,
5353
NzInputModule,
@@ -233,7 +233,7 @@ export default class WebpComponent {
233233
}
234234
}
235235

236-
handleReset() {
236+
handleRestoreData() {
237237
this.modal.info({
238238
nzTitle: $t('_resetInitData'),
239239
nzContent: $t('_warnReset'),

0 commit comments

Comments
 (0)