diff --git a/src/plugins/view/components/group.vue b/src/plugins/view/components/group.vue index 78721eb..9e40c8f 100644 --- a/src/plugins/view/components/group.vue +++ b/src/plugins/view/components/group.vue @@ -279,24 +279,31 @@ function remove(item: ClViewGroup.Item) { type: "warning" }) .then(() => { - config.service - .delete({ - ids: [item.id] - }) - .then(async () => { - ElMessage.success("删除成功"); + function next(params: any) { + config.service + .delete(params) + .then(async () => { + ElMessage.success("删除成功"); - // 刷新列表 - await refresh(); + // 刷新列表 + await refresh(); - // 删除当前 - if (selected.value?.id == item.id) { - select(); - } - }) - .catch((err) => { - ElMessage.error(err.message); - }); + // 删除当前 + if (selected.value?.id == item.id) { + select(); + } + }) + .catch((err) => { + ElMessage.error(err.message); + }); + } + + // 删除事件 + if (config.onDelete) { + config.onDelete(item, { next }); + } else { + next({ ids: [item.id] }); + } }) .catch(() => null); } diff --git a/src/plugins/view/config.ts b/src/plugins/view/config.ts index d7f1b3e..5bbae6f 100644 --- a/src/plugins/view/config.ts +++ b/src/plugins/view/config.ts @@ -5,8 +5,8 @@ export default (): ModuleConfig => { label: "视图组件", description: "左右侧布局、顶部详情等", author: "COOL", - version: "1.0.3", - updateTime: "2024-03-23", + version: "1.0.4", + updateTime: "2024-03-25", demo: [ { name: "左右侧布局", diff --git a/src/plugins/view/hooks/group.ts b/src/plugins/view/hooks/group.ts index 489ff8b..66dfe5d 100644 --- a/src/plugins/view/hooks/group.ts +++ b/src/plugins/view/hooks/group.ts @@ -2,8 +2,8 @@ import { provide, ref } from "vue"; import { useParent } from "/@/cool"; import type { ClViewGroup } from "../types"; -export function useViewGroup(options?: DeepPartial) { - const ViewGroup = ref(); +export function useViewGroup(options?: DeepPartial>) { + const ViewGroup = ref>(); useParent("cl-view-group", ViewGroup); if (options) { diff --git a/src/plugins/view/types/index.d.ts b/src/plugins/view/types/index.d.ts index a6fe4ba..12a33d4 100644 --- a/src/plugins/view/types/index.d.ts +++ b/src/plugins/view/types/index.d.ts @@ -5,20 +5,23 @@ export declare namespace ClViewGroup { interface Item { id: any; name: string; + children: Item[]; [key: string]: any; } - interface Ref { - selected: Item | undefined; + type M = T & Item; + + interface Ref { + selected: M | undefined; isExpand: boolean; select(data?: any): void; expand(value?: boolean): void; - edit(item?: Item): void; - remove(item: Item): void; + edit(item?: M): void; + remove(item: M): void; refresh(params?: any): void; } - interface Options { + interface Options { label: string; title: string; leftWidth: string; @@ -57,9 +60,10 @@ export declare namespace ClViewGroup { enableAdd?: boolean; enableRefresh?: boolean; custom?: boolean; - onSelect?(item: Item): void; - onEdit?(item?: Item): DeepPartial; - onContextMenu?(item: Item): ClContextMenu.Options; - onData?(list: any[]): any[]; + onSelect?(item: M): void; + onEdit?(item?: M): DeepPartial; + onContextMenu?(item: M): ClContextMenu.Options; + onData?(list: M[]): any[]; + onDelete?(item: M, { next }: { next(params: any): void }): Promise | void; } }