cl-view-group 添加泛型

This commit is contained in:
神仙都没用 2024-03-25 15:42:26 +08:00
parent 7754e14bf4
commit ad841ac140
4 changed files with 40 additions and 29 deletions

View File

@ -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);
}

View File

@ -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: "左右侧布局",

View File

@ -2,8 +2,8 @@ import { provide, ref } from "vue";
import { useParent } from "/@/cool";
import type { ClViewGroup } from "../types";
export function useViewGroup(options?: DeepPartial<ClViewGroup.Options>) {
const ViewGroup = ref<ClViewGroup.Ref>();
export function useViewGroup<T = ClViewGroup.Item>(options?: DeepPartial<ClViewGroup.Options<T>>) {
const ViewGroup = ref<ClViewGroup.Ref<T>>();
useParent("cl-view-group", ViewGroup);
if (options) {

View File

@ -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> = T & Item;
interface Ref<T = Item> {
selected: M<T> | undefined;
isExpand: boolean;
select(data?: any): void;
expand(value?: boolean): void;
edit(item?: Item): void;
remove(item: Item): void;
edit(item?: M<T>): void;
remove(item: M<T>): void;
refresh(params?: any): void;
}
interface Options {
interface Options<T = Item> {
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<ClForm.Options>;
onContextMenu?(item: Item): ClContextMenu.Options;
onData?(list: any[]): any[];
onSelect?(item: M<T>): void;
onEdit?(item?: M<T>): DeepPartial<ClForm.Options>;
onContextMenu?(item: M<T>): ClContextMenu.Options;
onData?(list: M<T>[]): any[];
onDelete?(item: M<T>, { next }: { next(params: any): void }): Promise<void> | void;
}
}