cool-admin-vue/packages/crud/index.d.ts

758 lines
16 KiB
TypeScript
Raw Normal View History

2023-09-28 13:50:15 +08:00
// vue
declare namespace Vue {
interface Ref<T = any> {
value: T;
}
type Emit = (name: any, ...args: any[]) => void;
}
// element-plus
declare namespace ElementPlus {
type Size = "large" | "default" | "small";
2024-01-14 22:25:40 +08:00
type Align = "left" | "center" | "right";
2023-09-28 13:50:15 +08:00
interface FormProps {
inline?: boolean;
labelPosition?: "left" | "right" | "top";
labelWidth?: string | number;
labelSuffix?: string;
hideRequiredAsterisk?: boolean;
showMessage?: boolean;
inlineMessage?: boolean;
statusIcon?: boolean;
validateOnRuleChange?: boolean;
size?: Size;
disabled?: boolean;
[key: string]: any;
}
}
// 方法
declare type fn = () => void;
// 对象
declare type obj = {
[key: string]: any;
};
// 全部可选
declare type DeepPartial<T> = T extends Function
? T
: T extends object
2024-01-15 13:30:07 +08:00
? { [P in keyof T]?: DeepPartial<T[P]> }
: T;
2023-09-28 13:50:15 +08:00
// 合并
declare type Merge<A, B> = Omit<A, keyof B> & B;
// 移除 [key]
declare type RemoveIndex<T> = {
[P in keyof T as string extends P ? never : number extends P ? never : P]: T[P];
};
// 任用列表
declare type List<T> = Array<DeepPartial<T> | (() => DeepPartial<T>)>;
// 字典选项
declare type DictOptions = {
2023-10-18 16:14:13 +08:00
label?: string;
value?: any;
2023-09-28 13:50:15 +08:00
color?: string;
type?: string;
[key: string]: any;
}[];
// emitter
declare interface EmitterItem {
name: string;
callback(data: any, events: { refresh(params: any): void; crudList: ClCrud.Ref[] }): void;
}
declare interface Emitter {
list: EmitterItem[];
init(events: any): void;
emit(name: string, data?: any): void;
on(name: string, callback: (data: any) => void): void;
}
// browser
declare type Browser = {
screen: string;
isMini: boolean;
};
// hook
declare namespace Hook {
interface Options {
form: obj;
prop: string;
method: "submit" | "bind";
}
type fn = (value: any, options: Options) => any;
type FormPipe =
| "number"
| "string"
| "split"
| "join"
| "boolean"
| "booleanNumber"
| "datetimeRange"
| "splitJoin"
| "json"
| "empty"
| fn;
type FormPipes = FormPipe | FormPipe[];
type Form =
| string
| {
bind?: FormPipes;
submit?: FormPipes;
};
}
// render
declare namespace Render {
type OpButton =
| `slot-${string}`
| {
label: string;
type?: string;
hidden?: boolean;
onClick(options: { scope: obj }): void;
[key: string]: any;
};
interface Props {
onChange?(value: any): void;
[key: string]: any;
}
interface Component {
name?: string;
options?: DictOptions | Vue.Ref<DictOptions>;
props?: Props | Vue.Ref<Props>;
style?: obj;
functionSlot?: boolean;
vm?: any;
[key: string]: any;
}
}
2024-01-14 22:25:40 +08:00
// 获取keys
type PropKey<T> = keyof RemoveIndex<T> | (string & {});
2024-01-13 23:30:02 +08:00
2023-09-28 13:50:15 +08:00
declare namespace ClCrud {
interface Label {
op: string;
add: string;
delete: string;
multiDelete: string;
update: string;
refresh: string;
info: string;
search: string;
reset: string;
clear: string;
save: string;
close: string;
confirm: string;
advSearch: string;
searchKey: string;
placeholder: string;
2023-11-23 21:17:17 +08:00
placeholderSelect: string;
2023-09-28 13:50:15 +08:00
tips: string;
saveSuccess: string;
deleteSuccess: string;
deleteConfirm: string;
empty: string;
desc: string;
asc: string;
select: string;
deselect: string;
seeMore: string;
hideContent: string;
nonEmpty: string;
[key: string]: string;
}
interface Dict {
primaryId: string;
api: {
list: string;
add: string;
update: string;
delete: string;
info: string;
page: string;
};
pagination: {
page: string;
size: string;
};
search: {
keyWord: string;
query: string;
};
sort: {
order: string;
prop: string;
};
label: Label;
}
interface Permission {
page?: boolean;
list?: boolean;
add?: boolean;
delete?: boolean;
update?: boolean;
info?: boolean;
[key: string]: any;
}
interface Params {
page: {
page?: number;
size?: number;
[key: string]: any;
};
list: obj;
add: obj;
delete: {
ids?: any[];
[key: string]: any;
};
update: {
id?: any;
[key: string]: any;
};
info: {
id?: any;
[key: string]: any;
};
}
interface Response {
page: {
list: any[];
pagination: {
total: number;
page: number;
size: number;
[key: string]: any;
};
[key: string]: any;
};
list: any[];
add: any;
update: any;
info: any;
delete: any;
}
interface Service {
api: {
page(params?: Params["page"]): Promise<Response["page"]>;
list(params?: Params["list"]): Promise<Response["list"]>;
add(params?: Params["add"]): Promise<Response["add"]>;
update(params?: Params["update"]): Promise<Response["update"]>;
info(params?: Params["info"]): Promise<Response["info"]>;
delete(params?: Params["delete"]): Promise<Response["delete"]>;
[key: string]: (params?: any) => Promise<any>;
};
}
interface Config {
name: string;
service: Service["api"];
permission: Permission;
dict: Dict;
onRefresh(
params: obj,
event: {
done: fn;
next: Service["api"]["page"];
render: (
list: Response["page"]["list"],
pagination?: Response["page"]["pagination"]
) => void;
}
): void;
onDelete(
selection: obj[],
event: {
next: Service["api"]["delete"];
}
): void;
}
interface Ref {
"cl-table": ClTable.Ref;
"cl-upsert": ClUpsert.Ref;
name: string;
routePath: string;
permission: Permission;
dict: Dict;
service: Service["api"];
loading: boolean;
params: obj;
selection: obj[];
set(key: "dict" | "style" | "service" | "permission", value: any): void;
done(): void;
getParams(): obj;
getPermission(key?: string): boolean;
rowInfo(data: obj): void;
rowAdd(): void;
rowEdit(data: obj): void;
rowAppend(data?: obj): void;
rowClose(): void;
rowDelete(...selection: obj[]): void;
proxy(name: string, data?: any[]): any;
paramsReplace(params: obj): obj;
refresh: Service["api"]["page"];
[key: string]: any;
}
2024-01-14 22:25:40 +08:00
interface Options extends DeepPartial<Config> {
service?: any;
}
2023-09-28 13:50:15 +08:00
}
declare namespace ClTable {
type OpButton = Array<"info" | "edit" | "delete" | Render.OpButton>;
2024-01-13 23:30:02 +08:00
interface Column<T = any> {
2023-09-28 13:50:15 +08:00
type: "index" | "selection" | "expand" | "op";
hidden: boolean | Vue.Ref<boolean>;
component: Render.Component;
2023-12-14 21:53:40 +08:00
search: {
isInput: boolean;
value: any;
2024-01-15 13:30:07 +08:00
refreshOnChange: Boolean;
2023-12-14 21:53:40 +08:00
component: Render.Component;
};
2023-09-28 13:50:15 +08:00
dict: DictOptions | Vue.Ref<DictOptions>;
dictFormatter: (values: DictOptions) => string;
dictColor: boolean;
2023-10-26 16:09:35 +08:00
dictSeparator: string;
2023-12-14 21:53:40 +08:00
dictAllLevels: boolean;
2024-01-13 23:30:02 +08:00
buttons: OpButton | ((options: { scope: T }) => OpButton);
2024-01-14 22:25:40 +08:00
align: ElementPlus.Align;
2024-01-13 23:30:02 +08:00
label: any;
2023-09-28 13:50:15 +08:00
className: string;
2024-01-13 23:30:02 +08:00
prop: PropKey<T>;
2023-09-28 13:50:15 +08:00
orderNum: number;
width: number;
minWidth: number | string;
renderHeader: (options: { column: any; $index: number }) => any;
sortable: boolean | "desc" | "descending" | "ascending" | "asc" | "custom";
sortMethod: fn;
2024-01-13 23:30:02 +08:00
sortBy: string | ((row: T, index: number) => any) | any[];
2023-09-28 13:50:15 +08:00
resizable: boolean;
columnKey: string;
2024-01-14 22:25:40 +08:00
headerAlign: ElementPlus.Align;
2023-09-28 13:50:15 +08:00
showOverflowTooltip: boolean;
fixed: boolean | string;
2024-01-13 23:30:02 +08:00
formatter: (row: T, column: any, value: any, index: number) => any;
selectable: (row: T, index: number) => boolean;
2023-09-28 13:50:15 +08:00
reserveSelection: boolean;
filterMethod: fn;
filteredValue: unknown[];
filters: unknown[];
filterPlacement: string;
filterMultiple: boolean;
index: ((index: number) => number) | number;
sortOrders: unknown[];
2024-01-13 23:30:02 +08:00
children: Column<T>[];
2023-09-28 13:50:15 +08:00
[key: string]: any;
}
type ContextMenu = Array<
| ClContextMenu.Item
| ((row: obj, column: obj, event: PointerEvent) => ClContextMenu.Item)
| "refresh"
| "check"
| "update"
| "edit"
| "delete"
| "info"
| "order-desc"
| "order-asc"
>;
2024-01-13 23:30:02 +08:00
interface Config<T = any> {
columns: Column<T>[];
2023-09-28 13:50:15 +08:00
autoHeight: boolean;
height: string | number;
contextMenu: ContextMenu;
defaultSort: {
prop: string;
order: "descending" | "ascending";
};
sortRefresh: boolean;
emptyText: string;
rowKey: string;
2024-01-13 23:30:02 +08:00
onRowContextmenu?(row: T, column: any, event: any): void;
2023-09-28 13:50:15 +08:00
}
2024-01-13 23:30:02 +08:00
interface Ref<T = any> {
2023-09-28 13:50:15 +08:00
Table: any;
config: obj;
2024-01-13 23:30:02 +08:00
selection: T[];
data: T[];
columns: Column<T>[];
2023-09-28 13:50:15 +08:00
reBuild(cb?: fn): void;
calcMaxHeight(): void;
2024-01-13 23:30:02 +08:00
setData(data: T[]): void;
2023-09-28 13:50:15 +08:00
setColumns(columns: Column[]): void;
2024-01-13 23:30:02 +08:00
showColumn(props: PropKey<T> | PropKey<T>[], status?: boolean): void;
hideColumn(props: PropKey<T> | PropKey<T>[]): void;
changeSort(prop: PropKey<T>, order: string): void;
2023-09-28 13:50:15 +08:00
clearSelection(): void;
getSelectionRows(): any[];
2024-01-13 23:30:02 +08:00
toggleRowSelection(row: T, selected?: boolean): void;
2023-09-28 13:50:15 +08:00
toggleAllSelection(): void;
2024-01-13 23:30:02 +08:00
toggleRowExpansion(row: T, expanded?: boolean): void;
setCurrentRow(row: T): void;
2023-09-28 13:50:15 +08:00
clearSort(): void;
2024-01-13 23:30:02 +08:00
clearFilter(columnKeys: PropKey<T>[]): void;
2023-09-28 13:50:15 +08:00
doLayout(): void;
2024-01-13 23:30:02 +08:00
sort(prop: PropKey<T>, order: string): void;
2023-09-28 13:50:15 +08:00
scrollTo(position: { top?: number; left?: number }): void;
setScrollTop(top: number): void;
setScrollLeft(left: number): void;
}
2024-01-13 23:30:02 +08:00
interface Options<T = any> extends DeepPartial<Config<T>> {
columns?: List<ClTable.Column<T>>;
2023-09-28 13:50:15 +08:00
}
}
2023-11-23 21:00:25 +08:00
declare namespace ClFormTabs {
type labels = {
label: string;
value: string;
name?: string;
icon?: any;
lazy?: boolean;
[key: string]: any;
}[];
}
2023-09-28 13:50:15 +08:00
declare namespace ClForm {
type CloseAction = "close" | "save";
interface Rule {
type?:
| "string"
| "number"
| "boolean"
| "method"
| "regexp"
| "integer"
| "float"
| "array"
| "object"
| "enum"
| "date"
| "url"
| "hex"
| "email"
| "any";
required?: boolean;
message?: string;
min?: number;
max?: number;
trigger?: any;
validator?(rule: any, value: any, callback: (error?: Error) => void): void;
[key: string]: any;
}
2024-01-13 23:30:02 +08:00
interface Item<T = any> {
2023-09-28 13:50:15 +08:00
type?: "tabs";
2024-01-13 23:30:02 +08:00
prop?: PropKey<T>;
2023-09-28 13:50:15 +08:00
props?: {
2023-11-23 21:00:25 +08:00
labels?: ClFormTabs.labels;
2023-09-28 13:50:15 +08:00
justify?: "left" | "center" | "right";
color?: string;
mergeProp?: boolean;
labelWidth?: string;
error?: string;
showMessage?: boolean;
inlineMessage?: boolean;
size?: "medium" | "default" | "small";
[key: string]: any;
};
span?: number;
col?: {
span: number;
offset: number;
push: number;
pull: number;
xs: any;
sm: any;
md: any;
lg: any;
xl: any;
tag: string;
};
hook?: Hook.Form;
group?: string;
collapse?: boolean;
value?: any;
label?: string;
renderLabel?: any;
flex?: boolean;
2024-01-14 22:25:40 +08:00
hidden?: (options: { scope: obj }) => boolean;
2023-09-28 13:50:15 +08:00
prepend?: Render.Component;
component?: Render.Component;
append?: Render.Component;
rules?: Rule | Rule[];
required?: boolean;
children?: Item[];
[key: string]: any;
}
2024-01-14 22:25:40 +08:00
interface Config<T = any> {
2023-09-28 13:50:15 +08:00
title?: any;
height?: string;
width?: string;
props: ElementPlus.FormProps;
items: Item[];
form: obj;
isReset?: boolean;
on?: {
2024-01-14 22:25:40 +08:00
open?(data: T): void;
2023-09-28 13:50:15 +08:00
close?(action: CloseAction, done: fn): void;
2024-01-14 22:25:40 +08:00
submit?(data: T, event: { close: fn; done: fn }): void;
2023-09-28 13:50:15 +08:00
};
op: {
hidden?: boolean;
saveButtonText?: string;
closeButtonText?: string;
justify?: "flex-start" | "center" | "flex-end";
buttons?: Array<CloseAction | Render.OpButton>;
};
dialog: {
title?: any;
height?: string;
width?: string;
hideHeader?: boolean;
controls?: Array<"fullscreen" | "close">;
[key: string]: any;
};
[key: string]: any;
}
2024-01-13 23:30:02 +08:00
type Plugin = (options: {
exposed: Ref;
onOpen(cb: () => void): void;
onClose(cb: () => void): void;
onSubmit(cb: (data: obj) => obj): void;
}) => void;
2023-09-28 13:50:15 +08:00
2024-01-13 23:30:02 +08:00
type Items<T = any> = List<Item<T>>;
2023-09-28 13:50:15 +08:00
2024-01-13 23:30:02 +08:00
interface Ref<T = any> {
2023-09-28 13:50:15 +08:00
Form: any;
2024-01-13 23:30:02 +08:00
form: T;
2023-09-28 13:50:15 +08:00
config: {
items: Item[];
[key: string]: any;
};
2024-01-13 23:30:02 +08:00
open(options: Options<T>, plugins?: Plugin[]): void;
2023-09-28 13:50:15 +08:00
close(action?: CloseAction): void;
done(): void;
clear(): void;
reset(): void;
showLoading(): void;
hideLoading(): void;
setDisabled(flag?: boolean): void;
setData(prop: string, value: any): void;
bindForm(data: obj): void;
getForm(prop?: string): any;
setForm(prop: string, value: any): void;
setOptions(prop: string, list: DictOptions): void;
setProps(prop: string, value: any): void;
setConfig(path: string, value: any): void;
showItem(props: string[] | string): void;
hideItem(props: string[] | string): void;
toggleItem(prop: string, flag?: boolean): void;
resetFields(): void;
clearValidate(props?: string[] | string): void;
validateField(
props?: string[] | string,
callback?: (isValid: boolean, invalidFields: any[]) => void
): Promise<void>;
validate(callback: (isValid: boolean, invalidFields: any[]) => void): Promise<void>;
changeTab(value: any, valid?: boolean): Promise<any>;
setTitle(value: string): void;
submit(cb?: (data: obj) => void): void;
[key: string]: any;
}
2024-01-13 23:30:02 +08:00
interface Options<T = any> extends DeepPartial<Config> {
items?: Items<T>;
}
2023-09-28 13:50:15 +08:00
}
declare namespace ClUpsert {
2024-01-14 22:25:40 +08:00
interface Config<T = any> {
2024-01-13 23:30:02 +08:00
sync: boolean;
2023-09-28 13:50:15 +08:00
items: ClForm.Item[];
props: ClForm.Config["props"];
op: ClForm.Config["op"];
dialog: ClForm.Config["dialog"];
2024-01-13 23:30:02 +08:00
onOpen?(): void;
onOpened?(data: T): void;
2023-09-28 13:50:15 +08:00
onClose?(action: ClForm.CloseAction, done: fn): void;
onClosed?(): void;
onInfo?(
2024-01-13 23:30:02 +08:00
data: T,
event: { close: fn; done(data: T): void; next: ClCrud.Service["api"]["info"] }
2023-09-28 13:50:15 +08:00
): void;
onSubmit?(
2024-01-13 23:30:02 +08:00
data: T,
2023-09-28 13:50:15 +08:00
event: { close: fn; done: fn; next: ClCrud.Service["api"]["update"] }
): void;
plugins?: ClForm.Plugin[];
}
2024-01-13 23:30:02 +08:00
interface Ref<T = any> extends ClForm.Ref<T> {
2023-09-28 13:50:15 +08:00
mode: "add" | "update" | "info";
}
2024-01-15 13:30:07 +08:00
interface Options<T = any> extends DeepPartial<Config<T>> {
2024-01-13 23:30:02 +08:00
items?: ClForm.Items<T>;
2023-09-28 13:50:15 +08:00
}
}
2024-01-14 22:25:40 +08:00
interface UpsertOptions {
items: ClForm.Items;
}
2023-09-28 13:50:15 +08:00
declare namespace ClAdvSearch {
2024-01-13 23:30:02 +08:00
interface Config<T = any> {
2023-09-28 13:50:15 +08:00
items?: ClForm.Item[];
title?: string;
size?: string | number;
op?: Array<"clear" | "reset" | "close" | "search">;
2024-01-13 23:30:02 +08:00
onSearch?(data: T, options: { next: ClCrud.Service["api"]["page"]; close(): void }): void;
2023-09-28 13:50:15 +08:00
}
2024-01-13 23:30:02 +08:00
interface Ref<T = any> extends ClForm.Ref<T> {}
2023-09-28 13:50:15 +08:00
2024-01-13 23:30:02 +08:00
interface Options<T = any> extends DeepPartial<Config<T>> {
items?: ClForm.Items<T>;
}
2023-09-28 13:50:15 +08:00
}
declare namespace ClSearch {
2024-01-13 23:30:02 +08:00
interface Config<T = any> {
2023-09-28 13:50:15 +08:00
items?: ClForm.Item[];
2024-01-13 23:30:02 +08:00
data?: T;
2023-09-28 13:50:15 +08:00
resetBtn?: boolean;
2024-01-13 23:30:02 +08:00
onLoad?(data: T): void;
onSearch?(data: T, options: { next: ClCrud.Service["api"]["page"] }): void;
2023-09-28 13:50:15 +08:00
}
2024-01-13 23:30:02 +08:00
interface Ref<T = any> extends ClForm.Ref<T> {
2023-09-28 13:50:15 +08:00
search(params?: obj): void;
reset(): void;
}
2024-01-13 23:30:02 +08:00
interface Options<T = any> extends DeepPartial<Config<T>> {
items?: ClForm.Items<T>;
}
2023-09-28 13:50:15 +08:00
}
declare namespace ClContextMenu {
interface Item {
label: string;
icon?: string;
prefixIcon?: string;
suffixIcon?: string;
ellipsis?: boolean;
disabled?: boolean;
hidden?: boolean;
children?: Item[];
showChildren?: boolean;
callback?(done: fn): void;
[key: string]: any;
}
interface Event {
pageX: number;
pageY: number;
[key: string]: any;
}
interface Options {
hover?:
| boolean
| {
target?: string;
className?: string;
};
list: Item[];
}
interface Ref {
open(event: Event, options: Options): Ref;
close(): void;
}
}
declare namespace ClDialog {
interface Provide {
visible: Vue.Ref<boolean>;
fullscreen: Vue.Ref<boolean>;
}
}
declare interface Config {
dict: ClCrud.Dict;
permission: ClCrud.Permission;
events: {
[key: string]: (...args: any[]) => any;
};
render: {
functionSlots: {
exclude: string[];
};
};
style: {
size: ElementPlus.Size;
colors: string[];
form: {
2023-10-19 14:33:14 +08:00
labelPosition: ElementPlus.FormProps["labelPosition"];
2023-09-28 13:50:15 +08:00
labelWidth: ElementPlus.FormProps["labelWidth"];
span: number;
};
table: {
stripe: boolean;
border: boolean;
highlightCurrentRow: boolean;
resizable: boolean;
autoHeight: boolean;
contextMenu: ClTable.ContextMenu;
column: {
minWidth: number;
align: ElementPlus.Align;
headerAlign: ElementPlus.Align;
};
};
};
}
declare type Options = DeepPartial<Config>;
declare interface CrudOptions {
options: Options;
}