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" type: "warning"
}) })
.then(() => { .then(() => {
config.service function next(params: any) {
.delete({ config.service
ids: [item.id] .delete(params)
}) .then(async () => {
.then(async () => { ElMessage.success("删除成功");
ElMessage.success("删除成功");
// //
await refresh(); await refresh();
// //
if (selected.value?.id == item.id) { if (selected.value?.id == item.id) {
select(); select();
} }
}) })
.catch((err) => { .catch((err) => {
ElMessage.error(err.message); ElMessage.error(err.message);
}); });
}
//
if (config.onDelete) {
config.onDelete(item, { next });
} else {
next({ ids: [item.id] });
}
}) })
.catch(() => null); .catch(() => null);
} }

View File

@ -5,8 +5,8 @@ export default (): ModuleConfig => {
label: "视图组件", label: "视图组件",
description: "左右侧布局、顶部详情等", description: "左右侧布局、顶部详情等",
author: "COOL", author: "COOL",
version: "1.0.3", version: "1.0.4",
updateTime: "2024-03-23", updateTime: "2024-03-25",
demo: [ demo: [
{ {
name: "左右侧布局", name: "左右侧布局",

View File

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

View File

@ -5,20 +5,23 @@ export declare namespace ClViewGroup {
interface Item { interface Item {
id: any; id: any;
name: string; name: string;
children: Item[];
[key: string]: any; [key: string]: any;
} }
interface Ref { type M<T> = T & Item;
selected: Item | undefined;
interface Ref<T = Item> {
selected: M<T> | undefined;
isExpand: boolean; isExpand: boolean;
select(data?: any): void; select(data?: any): void;
expand(value?: boolean): void; expand(value?: boolean): void;
edit(item?: Item): void; edit(item?: M<T>): void;
remove(item: Item): void; remove(item: M<T>): void;
refresh(params?: any): void; refresh(params?: any): void;
} }
interface Options { interface Options<T = Item> {
label: string; label: string;
title: string; title: string;
leftWidth: string; leftWidth: string;
@ -57,9 +60,10 @@ export declare namespace ClViewGroup {
enableAdd?: boolean; enableAdd?: boolean;
enableRefresh?: boolean; enableRefresh?: boolean;
custom?: boolean; custom?: boolean;
onSelect?(item: Item): void; onSelect?(item: M<T>): void;
onEdit?(item?: Item): DeepPartial<ClForm.Options>; onEdit?(item?: M<T>): DeepPartial<ClForm.Options>;
onContextMenu?(item: Item): ClContextMenu.Options; onContextMenu?(item: M<T>): ClContextMenu.Options;
onData?(list: any[]): any[]; onData?(list: M<T>[]): any[];
onDelete?(item: M<T>, { next }: { next(params: any): void }): Promise<void> | void;
} }
} }