yuand 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/es/components/Table/index.d.ts +12 -0
- package/es/components/Table/index.js +326 -0
- package/es/components/Table/style.css +3 -0
- package/es/components/Table/types.d.ts +101 -0
- package/es/components/Table/types.js +1 -0
- package/es/components/Table/useTable.d.ts +3 -0
- package/es/components/Table/useTable.js +76 -0
- package/es/components/TableConfig/index.d.ts +11 -0
- package/es/components/TableConfig/index.js +19 -0
- package/es/components/TableUseFetch/index.d.ts +12 -0
- package/es/components/TableUseFetch/index.js +283 -0
- package/es/components/TableUseFetch/style.css +3 -0
- package/es/components/TableUseFetch/types.d.ts +100 -0
- package/es/components/TableUseFetch/types.js +1 -0
- package/es/components/TableUseFetch/useTable.d.ts +3 -0
- package/es/components/TableUseFetch/useTable.js +78 -0
- package/es/components/index.d.ts +3 -0
- package/es/components/index.js +3 -0
- package/es/fetch.d.ts +137 -0
- package/es/fetch.js +534 -0
- package/es/hooks/index.d.ts +4 -0
- package/es/hooks/index.js +4 -0
- package/es/hooks/useFetch.d.ts +17 -0
- package/es/hooks/useFetch.js +41 -0
- package/es/hooks/useMutation.d.ts +14 -0
- package/es/hooks/useMutation.js +26 -0
- package/es/hooks/useQuery.d.ts +14 -0
- package/es/hooks/useQuery.js +40 -0
- package/es/hooks/useX.d.ts +1 -0
- package/es/hooks/useX.js +13 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +4 -0
- package/es/utils/index.d.ts +6 -0
- package/es/utils/index.js +23 -0
- package/es/utils/table.d.ts +15 -0
- package/es/utils/table.js +106 -0
- package/es/utils/util.d.ts +2 -0
- package/es/utils/util.js +6 -0
- package/lang/en_US.json +6 -0
- package/lang/zh_CN.json +6 -0
- package/lib/components/Table/index.d.ts +12 -0
- package/lib/components/Table/index.js +330 -0
- package/lib/components/Table/style.css +3 -0
- package/lib/components/Table/types.d.ts +101 -0
- package/lib/components/Table/types.js +17 -0
- package/lib/components/Table/useTable.d.ts +3 -0
- package/lib/components/Table/useTable.js +85 -0
- package/lib/components/TableConfig/index.d.ts +11 -0
- package/lib/components/TableConfig/index.js +55 -0
- package/lib/components/TableUseFetch/index.d.ts +12 -0
- package/lib/components/TableUseFetch/index.js +303 -0
- package/lib/components/TableUseFetch/style.css +3 -0
- package/lib/components/TableUseFetch/types.d.ts +100 -0
- package/lib/components/TableUseFetch/types.js +17 -0
- package/lib/components/TableUseFetch/useTable.d.ts +3 -0
- package/lib/components/TableUseFetch/useTable.js +86 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.js +45 -0
- package/lib/fetch.d.ts +137 -0
- package/lib/fetch.js +366 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.js +48 -0
- package/lib/hooks/useFetch.d.ts +17 -0
- package/lib/hooks/useFetch.js +62 -0
- package/lib/hooks/useMutation.d.ts +14 -0
- package/lib/hooks/useMutation.js +43 -0
- package/lib/hooks/useQuery.d.ts +14 -0
- package/lib/hooks/useQuery.js +57 -0
- package/lib/hooks/useX.d.ts +1 -0
- package/lib/hooks/useX.js +37 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +29 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +60 -0
- package/lib/utils/table.d.ts +15 -0
- package/lib/utils/table.js +124 -0
- package/lib/utils/util.d.ts +2 -0
- package/lib/utils/util.js +32 -0
- package/package.json +46 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FormInstance, TableColumnType, TableProps, FormProps } from "antd";
|
|
3
|
+
import type { HttpMethod } from "../../fetch";
|
|
4
|
+
import type { UseBoundStore, StoreApi } from "zustand";
|
|
5
|
+
import type { GetQueryProps } from "../../utils/table";
|
|
6
|
+
type RecordType = Record<string, any>;
|
|
7
|
+
interface SorterType {
|
|
8
|
+
field?: string;
|
|
9
|
+
order?: "ascend" | "descend";
|
|
10
|
+
}
|
|
11
|
+
export interface TableState<TData = any> {
|
|
12
|
+
page: number;
|
|
13
|
+
size: number;
|
|
14
|
+
sorter: SorterType;
|
|
15
|
+
data: TData;
|
|
16
|
+
search: RecordType | null | undefined;
|
|
17
|
+
params: any[] | Record<string, any> | null | undefined;
|
|
18
|
+
setState: (values: Partial<TableState>) => void;
|
|
19
|
+
ready: boolean;
|
|
20
|
+
}
|
|
21
|
+
type UseStoreType<TData> = UseBoundStore<StoreApi<TableState<TData>>>;
|
|
22
|
+
export interface TableInstance<TData = any> {
|
|
23
|
+
useStore: UseStoreType<TData>;
|
|
24
|
+
queryKey: any[];
|
|
25
|
+
run: () => void;
|
|
26
|
+
clear: () => void;
|
|
27
|
+
refresh: () => void;
|
|
28
|
+
reset: () => void;
|
|
29
|
+
sortOrder: (key: string) => any;
|
|
30
|
+
update: () => void;
|
|
31
|
+
resetStore: () => void;
|
|
32
|
+
form?: FormInstance;
|
|
33
|
+
}
|
|
34
|
+
interface FormOptions extends Omit<FormProps, "form" | "title" | "children"> {
|
|
35
|
+
title?: React.ReactNode;
|
|
36
|
+
/** @deprecated 此属性已废弃,请使用新的formItem属性代替 */
|
|
37
|
+
items?: React.ReactNode | React.ReactNode[];
|
|
38
|
+
formItem?: React.ReactNode | React.ReactNode[];
|
|
39
|
+
extra?: React.ReactNode;
|
|
40
|
+
right?: React.ReactNode;
|
|
41
|
+
handleValues?: (values: Record<string, any>) => any;
|
|
42
|
+
reset?: boolean;
|
|
43
|
+
onResetBefore?: () => void | boolean;
|
|
44
|
+
dataForm?: FormProps;
|
|
45
|
+
}
|
|
46
|
+
export interface ProTableProps<Tdata = any> extends Omit<TableProps<Tdata>, "columns"> {
|
|
47
|
+
classNames?: {
|
|
48
|
+
root?: string;
|
|
49
|
+
form?: string;
|
|
50
|
+
table?: string;
|
|
51
|
+
};
|
|
52
|
+
styles?: {
|
|
53
|
+
root?: React.CSSProperties;
|
|
54
|
+
form?: React.CSSProperties;
|
|
55
|
+
table?: React.CSSProperties;
|
|
56
|
+
toolbar?: React.CSSProperties;
|
|
57
|
+
};
|
|
58
|
+
/** API 请求配置 */
|
|
59
|
+
request: {
|
|
60
|
+
/** 请求地址方法 */
|
|
61
|
+
url?: string;
|
|
62
|
+
method?: HttpMethod;
|
|
63
|
+
/** 请求参数 */
|
|
64
|
+
params?: Record<string, any>;
|
|
65
|
+
onBefore?: () => any;
|
|
66
|
+
onSuccess?: (data: any) => any;
|
|
67
|
+
};
|
|
68
|
+
url: string;
|
|
69
|
+
table: TableInstance<Tdata> | null;
|
|
70
|
+
locale?: Record<string, any>;
|
|
71
|
+
dataKey?: string;
|
|
72
|
+
totalKey?: string;
|
|
73
|
+
manual?: boolean;
|
|
74
|
+
nostyle?: boolean;
|
|
75
|
+
params?: RecordType;
|
|
76
|
+
columns: ((data: Tdata) => TableColumnType<unknown>[]) | TableColumnType<unknown>[];
|
|
77
|
+
form?: FormOptions;
|
|
78
|
+
alert?: React.ReactNode | ((data: Tdata) => React.ReactNode);
|
|
79
|
+
toolbar?: React.ReactNode;
|
|
80
|
+
pageSizeOptions?: number[];
|
|
81
|
+
onBefore?: () => void;
|
|
82
|
+
onSuccess?: (data: Tdata) => any;
|
|
83
|
+
pagination?: {
|
|
84
|
+
showQuickJumper?: boolean;
|
|
85
|
+
showSizeChanger?: boolean;
|
|
86
|
+
hideOnSinglePage?: boolean;
|
|
87
|
+
};
|
|
88
|
+
loadingDelay?: number;
|
|
89
|
+
method?: HttpMethod;
|
|
90
|
+
useData?: boolean;
|
|
91
|
+
}
|
|
92
|
+
export interface UseTableProps {
|
|
93
|
+
page?: number;
|
|
94
|
+
size?: number;
|
|
95
|
+
sorter?: SorterType;
|
|
96
|
+
}
|
|
97
|
+
export interface ProTableConfigOptions {
|
|
98
|
+
getQuery?: (data: GetQueryProps) => Record<string, unknown>;
|
|
99
|
+
pageSizeOptions?: number[];
|
|
100
|
+
}
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/components/Table/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/components/Table/useTable.ts
|
|
20
|
+
var useTable_exports = {};
|
|
21
|
+
__export(useTable_exports, {
|
|
22
|
+
default: () => useTable_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useTable_exports);
|
|
25
|
+
var import_antd = require("antd");
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var import_zustand = require("zustand");
|
|
28
|
+
var useTable = (options = {}) => {
|
|
29
|
+
const [_, update] = (0, import_react.useState)(0);
|
|
30
|
+
const [form] = import_antd.Form.useForm();
|
|
31
|
+
const tableRef = (0, import_react.useRef)(null);
|
|
32
|
+
if (!tableRef.current) {
|
|
33
|
+
const initState = {
|
|
34
|
+
page: options.page ?? 1,
|
|
35
|
+
size: options.size ?? 10,
|
|
36
|
+
sorter: options.sorter ?? {},
|
|
37
|
+
search: {},
|
|
38
|
+
params: {},
|
|
39
|
+
data: {},
|
|
40
|
+
ready: false
|
|
41
|
+
};
|
|
42
|
+
const useStore = (0, import_zustand.create)((set) => ({
|
|
43
|
+
...initState,
|
|
44
|
+
setState(values = {}) {
|
|
45
|
+
set(values);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
tableRef.current = {
|
|
49
|
+
form,
|
|
50
|
+
useStore,
|
|
51
|
+
queryKey: [],
|
|
52
|
+
run() {
|
|
53
|
+
},
|
|
54
|
+
clear: () => {
|
|
55
|
+
},
|
|
56
|
+
refresh: () => {
|
|
57
|
+
},
|
|
58
|
+
reset: () => {
|
|
59
|
+
},
|
|
60
|
+
sortOrder(key) {
|
|
61
|
+
const sorter = useStore.getState().sorter;
|
|
62
|
+
if (sorter && sorter.field === key) {
|
|
63
|
+
return sorter.order;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
},
|
|
67
|
+
resetStore() {
|
|
68
|
+
useStore.getState().setState(initState);
|
|
69
|
+
},
|
|
70
|
+
update: () => update((v) => v + 1)
|
|
71
|
+
};
|
|
72
|
+
useStore.subscribe((state, prevState) => {
|
|
73
|
+
var _a, _b, _c, _d;
|
|
74
|
+
const sorterChanged = state.sorter !== prevState.sorter;
|
|
75
|
+
const orderChanged = ((_a = state.sorter) == null ? void 0 : _a.order) !== ((_b = prevState.sorter) == null ? void 0 : _b.order);
|
|
76
|
+
const fieldChanged = ((_c = state.sorter) == null ? void 0 : _c.field) !== ((_d = prevState.sorter) == null ? void 0 : _d.field);
|
|
77
|
+
if (sorterChanged && (orderChanged || fieldChanged)) {
|
|
78
|
+
tableRef.current = { ...tableRef.current };
|
|
79
|
+
update((v) => v + 1);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return [tableRef.current];
|
|
84
|
+
};
|
|
85
|
+
var useTable_default = useTable;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface Props {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
lang?: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare const I18nContext: import("react").Context<{
|
|
7
|
+
lang?: Record<string, any>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const t: (key: string, i18n: Record<string, any>) => any;
|
|
10
|
+
export default function TableConfig({ children, lang }: Props): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/TableConfig/index.tsx
|
|
30
|
+
var TableConfig_exports = {};
|
|
31
|
+
__export(TableConfig_exports, {
|
|
32
|
+
I18nContext: () => I18nContext,
|
|
33
|
+
default: () => TableConfig,
|
|
34
|
+
t: () => t
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(TableConfig_exports);
|
|
37
|
+
var import_react = require("react");
|
|
38
|
+
var import_zh_CN = __toESM(require("../../../lang/zh_CN.json"));
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
var I18nContext = (0, import_react.createContext)({});
|
|
41
|
+
var t = (key, i18n) => {
|
|
42
|
+
if (!i18n)
|
|
43
|
+
return key;
|
|
44
|
+
return i18n[key] || key;
|
|
45
|
+
};
|
|
46
|
+
function TableConfig({ children, lang = import_zh_CN.default }) {
|
|
47
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(I18nContext.Provider, { value: {
|
|
48
|
+
lang
|
|
49
|
+
}, children });
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
I18nContext,
|
|
54
|
+
t
|
|
55
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ProTableProps, ProTableConfigOptions } from "./types";
|
|
2
|
+
import "./style.css";
|
|
3
|
+
declare const ProTable: {
|
|
4
|
+
<T extends Record<string, any>>(props: ProTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
useTable: (options?: import("./types").UseTableProps) => import("./types").TableRef[];
|
|
6
|
+
getQuery(options: any): Record<string, unknown>;
|
|
7
|
+
formatDate: (key: string, data: Record<string, any>, format?: string) => Record<string, any>;
|
|
8
|
+
removeEmpty: (data: Record<string, any>) => Record<string, any>;
|
|
9
|
+
pageSizeOptions: number[];
|
|
10
|
+
config(options: ProTableConfigOptions): void;
|
|
11
|
+
};
|
|
12
|
+
export default ProTable;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/TableUseFetch/index.tsx
|
|
30
|
+
var TableUseFetch_exports = {};
|
|
31
|
+
__export(TableUseFetch_exports, {
|
|
32
|
+
default: () => TableUseFetch_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(TableUseFetch_exports);
|
|
35
|
+
var import_shallow = require("zustand/react/shallow");
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_antd = require("antd");
|
|
38
|
+
var import_table = require("../../utils/table");
|
|
39
|
+
var import_util = require("../../utils/util");
|
|
40
|
+
var import_useFetch = __toESM(require("../../hooks/useFetch"));
|
|
41
|
+
var import_useX = __toESM(require("../../hooks/useX"));
|
|
42
|
+
var import_useTable = __toESM(require("./useTable"));
|
|
43
|
+
var import_style = require("./style.css");
|
|
44
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
+
var defaultClassNames = {
|
|
46
|
+
root: "main-container",
|
|
47
|
+
form: "search-form",
|
|
48
|
+
table: "main-table"
|
|
49
|
+
};
|
|
50
|
+
var defaultStyles = {
|
|
51
|
+
root: {},
|
|
52
|
+
form: {
|
|
53
|
+
display: "flex",
|
|
54
|
+
justifyContent: "space-between"
|
|
55
|
+
},
|
|
56
|
+
table: {},
|
|
57
|
+
toolbar: {
|
|
58
|
+
marginBottom: 15
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var ProTable = (props) => {
|
|
62
|
+
const {
|
|
63
|
+
classNames = defaultClassNames,
|
|
64
|
+
styles = defaultStyles,
|
|
65
|
+
table,
|
|
66
|
+
locale,
|
|
67
|
+
dataKey = "data",
|
|
68
|
+
totalKey = "total",
|
|
69
|
+
manual = false,
|
|
70
|
+
nostyle,
|
|
71
|
+
request = {},
|
|
72
|
+
columns,
|
|
73
|
+
form = {},
|
|
74
|
+
alert,
|
|
75
|
+
toolbar = null,
|
|
76
|
+
pageSizeOptions = [10, 20, 50, 100],
|
|
77
|
+
pagination,
|
|
78
|
+
loadingDelay = 300,
|
|
79
|
+
scroll,
|
|
80
|
+
...prop
|
|
81
|
+
} = props;
|
|
82
|
+
const {
|
|
83
|
+
title: formTitle,
|
|
84
|
+
extra: formExtra,
|
|
85
|
+
right: formRight,
|
|
86
|
+
formItem,
|
|
87
|
+
items,
|
|
88
|
+
reset: formReset,
|
|
89
|
+
dataForm,
|
|
90
|
+
handleValues: formHandleValues,
|
|
91
|
+
onResetBefore: formOnResetBefore,
|
|
92
|
+
...otherFormProps
|
|
93
|
+
} = form;
|
|
94
|
+
const formItems = formItem || items;
|
|
95
|
+
const { data, page, size, sorter, search, ready, setState } = table.useStore(
|
|
96
|
+
(0, import_shallow.useShallow)((state) => {
|
|
97
|
+
return {
|
|
98
|
+
data: state.data,
|
|
99
|
+
page: state.page,
|
|
100
|
+
size: state.size,
|
|
101
|
+
sorter: state.sorter,
|
|
102
|
+
search: state.search,
|
|
103
|
+
ready: state.ready,
|
|
104
|
+
setState: state.setState
|
|
105
|
+
};
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
const { loading } = (0, import_useFetch.default)(request.url, {
|
|
109
|
+
method: request.method,
|
|
110
|
+
onBefore: request.onBefore,
|
|
111
|
+
json: ProTable.getQuery({
|
|
112
|
+
page,
|
|
113
|
+
size,
|
|
114
|
+
sorter,
|
|
115
|
+
search,
|
|
116
|
+
params: request.params
|
|
117
|
+
}),
|
|
118
|
+
ready,
|
|
119
|
+
onFinally: () => {
|
|
120
|
+
setState({
|
|
121
|
+
ready: false
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
onSuccess(data2) {
|
|
125
|
+
setState({
|
|
126
|
+
data: data2
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
loadingDelay
|
|
130
|
+
});
|
|
131
|
+
const { dataSource, total, column, renderAlert } = (0, import_react.useMemo)(() => {
|
|
132
|
+
return {
|
|
133
|
+
column: typeof columns === "function" ? columns(data) : columns,
|
|
134
|
+
dataSource: (0, import_table.getDataSource)(data, dataKey),
|
|
135
|
+
renderAlert: typeof alert === "function" ? alert(data) : alert,
|
|
136
|
+
total: (0, import_table.getTotal)(totalKey, data)
|
|
137
|
+
};
|
|
138
|
+
}, [columns, data, dataKey, totalKey]);
|
|
139
|
+
const onSearch = () => {
|
|
140
|
+
if (formItems) {
|
|
141
|
+
table.form.submit();
|
|
142
|
+
} else {
|
|
143
|
+
setState({
|
|
144
|
+
ready: true
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const onReset = () => {
|
|
149
|
+
setState({
|
|
150
|
+
size: 10,
|
|
151
|
+
sorter: {}
|
|
152
|
+
});
|
|
153
|
+
if (formItems) {
|
|
154
|
+
if ((formOnResetBefore == null ? void 0 : formOnResetBefore()) === false)
|
|
155
|
+
return;
|
|
156
|
+
table.form.resetFields();
|
|
157
|
+
if (formReset === void 0 || formReset === true) {
|
|
158
|
+
table.form.submit();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
if (table) {
|
|
163
|
+
table.run = onSearch;
|
|
164
|
+
table.reset = () => {
|
|
165
|
+
if (formItems) {
|
|
166
|
+
onReset();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
(0, import_react.useEffect)(() => {
|
|
171
|
+
if (manual)
|
|
172
|
+
return;
|
|
173
|
+
if (formItems) {
|
|
174
|
+
table.form.submit();
|
|
175
|
+
} else {
|
|
176
|
+
setState({
|
|
177
|
+
ready: true
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}, [table]);
|
|
181
|
+
const onFinish = (values) => {
|
|
182
|
+
if (formHandleValues) {
|
|
183
|
+
values = formHandleValues(values);
|
|
184
|
+
}
|
|
185
|
+
if (!values)
|
|
186
|
+
return;
|
|
187
|
+
setState({
|
|
188
|
+
page: 1,
|
|
189
|
+
search: values,
|
|
190
|
+
ready: true
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const tableChange = (pagination2, sorter2) => {
|
|
194
|
+
setState({
|
|
195
|
+
page: pagination2.current,
|
|
196
|
+
size: pagination2.pageSize,
|
|
197
|
+
sorter: sorter2,
|
|
198
|
+
ready: true
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
const x = (0, import_useX.default)(column);
|
|
202
|
+
const y = scroll == null ? void 0 : scroll.y;
|
|
203
|
+
const renderTable = () => {
|
|
204
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
205
|
+
import_antd.Table,
|
|
206
|
+
{
|
|
207
|
+
columns: column,
|
|
208
|
+
loading,
|
|
209
|
+
scroll: { x, y },
|
|
210
|
+
locale,
|
|
211
|
+
onChange: (p, _, sorter2) => tableChange(p, sorter2),
|
|
212
|
+
pagination: {
|
|
213
|
+
current: page,
|
|
214
|
+
pageSize: size,
|
|
215
|
+
showQuickJumper: pagination ? pagination.showQuickJumper : true,
|
|
216
|
+
showSizeChanger: pagination ? pagination.showSizeChanger : true,
|
|
217
|
+
hideOnSinglePage: pagination ? pagination.hideOnSinglePage : false,
|
|
218
|
+
pageSizeOptions,
|
|
219
|
+
total,
|
|
220
|
+
showTotal(total2) {
|
|
221
|
+
return `共 ${total2} 条记录`;
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
dataSource,
|
|
225
|
+
...prop
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
};
|
|
229
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
230
|
+
"div",
|
|
231
|
+
{
|
|
232
|
+
className: (classNames == null ? void 0 : classNames.root) ?? defaultClassNames.root,
|
|
233
|
+
style: styles.root,
|
|
234
|
+
children: [
|
|
235
|
+
!!formItems && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
236
|
+
"div",
|
|
237
|
+
{
|
|
238
|
+
className: (classNames == null ? void 0 : classNames.form) ?? defaultClassNames.form,
|
|
239
|
+
style: styles.form,
|
|
240
|
+
children: [
|
|
241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
242
|
+
import_antd.Form,
|
|
243
|
+
{
|
|
244
|
+
form: table.form,
|
|
245
|
+
layout: "inline",
|
|
246
|
+
onFinish,
|
|
247
|
+
...otherFormProps,
|
|
248
|
+
children: [
|
|
249
|
+
formTitle && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Form.Item, { children: formTitle }),
|
|
250
|
+
formItems,
|
|
251
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Form.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_antd.Space, { children: [
|
|
252
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Button, { type: "primary", loading, htmlType: "submit", children: "查询" }),
|
|
253
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Button, { onClick: onReset, disabled: loading, children: "重置" }),
|
|
254
|
+
formExtra
|
|
255
|
+
] }) })
|
|
256
|
+
]
|
|
257
|
+
}
|
|
258
|
+
),
|
|
259
|
+
formRight
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
264
|
+
"div",
|
|
265
|
+
{
|
|
266
|
+
className: (classNames == null ? void 0 : classNames.table) ?? defaultClassNames.table,
|
|
267
|
+
style: styles.table,
|
|
268
|
+
children: [
|
|
269
|
+
toolbar && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles.toolbar, children: toolbar }),
|
|
270
|
+
renderAlert,
|
|
271
|
+
!!dataForm ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Form, { ...dataForm, children: renderTable() }) : renderTable()
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
);
|
|
278
|
+
};
|
|
279
|
+
ProTable.useTable = import_useTable.default;
|
|
280
|
+
ProTable.getQuery = (options) => {
|
|
281
|
+
const { page, size, sorter, search, params } = options;
|
|
282
|
+
return (0, import_table.getQuery)({
|
|
283
|
+
page,
|
|
284
|
+
size,
|
|
285
|
+
sorter,
|
|
286
|
+
search,
|
|
287
|
+
params
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
ProTable.formatDate = import_table.formatDate;
|
|
291
|
+
ProTable.removeEmpty = import_table.removeEmpty;
|
|
292
|
+
ProTable.pageSizeOptions = [10, 20, 50, 100];
|
|
293
|
+
ProTable.config = (options) => {
|
|
294
|
+
if (!options || !(0, import_util.isObject)(options))
|
|
295
|
+
return;
|
|
296
|
+
if (options.getQuery) {
|
|
297
|
+
ProTable.getQuery = options.getQuery;
|
|
298
|
+
}
|
|
299
|
+
if (options.pageSizeOptions) {
|
|
300
|
+
ProTable.pageSizeOptions = options.pageSizeOptions;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var TableUseFetch_default = ProTable;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { FormInstance, TableColumnType, TableProps, FormProps } from "antd";
|
|
3
|
+
import type { HttpMethod } from "../../fetch";
|
|
4
|
+
import type { UseBoundStore, StoreApi } from "zustand";
|
|
5
|
+
import type { GetQueryProps } from "../../utils/table";
|
|
6
|
+
type RecordType = Record<string, any>;
|
|
7
|
+
interface SorterType {
|
|
8
|
+
field?: string;
|
|
9
|
+
order?: "ascend" | "descend";
|
|
10
|
+
}
|
|
11
|
+
export interface TableState<TData = any> {
|
|
12
|
+
page: number;
|
|
13
|
+
size: number;
|
|
14
|
+
sorter: SorterType;
|
|
15
|
+
data: TData;
|
|
16
|
+
search: RecordType | null | undefined;
|
|
17
|
+
params: any[] | Record<string, any> | null | undefined;
|
|
18
|
+
setState: (values: Partial<TableState>) => void;
|
|
19
|
+
ready: boolean;
|
|
20
|
+
}
|
|
21
|
+
type UseStoreType<TData> = UseBoundStore<StoreApi<TableState<TData>>>;
|
|
22
|
+
export interface TableInstance<TData = any> {
|
|
23
|
+
useStore: UseStoreType<TData>;
|
|
24
|
+
run: () => void;
|
|
25
|
+
clear: () => void;
|
|
26
|
+
refresh: () => void;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
sortOrder: (key: string) => any;
|
|
29
|
+
update: () => void;
|
|
30
|
+
form?: FormInstance;
|
|
31
|
+
}
|
|
32
|
+
interface FormOptions extends Omit<FormProps, "form" | "title"> {
|
|
33
|
+
title?: React.ReactNode;
|
|
34
|
+
/** @deprecated 此属性已废弃,请使用新的formItem属性代替 */
|
|
35
|
+
items?: React.ReactNode | React.ReactNode[];
|
|
36
|
+
formItem?: React.ReactNode | React.ReactNode[];
|
|
37
|
+
extra?: React.ReactNode;
|
|
38
|
+
right?: React.ReactNode;
|
|
39
|
+
handleValues?: (values: Record<string, any>) => any;
|
|
40
|
+
reset?: boolean;
|
|
41
|
+
onResetBefore?: () => void | boolean;
|
|
42
|
+
dataForm?: FormProps;
|
|
43
|
+
}
|
|
44
|
+
export interface ProTableProps<Tdata = any> extends Omit<TableProps<Tdata>, "columns"> {
|
|
45
|
+
classNames?: {
|
|
46
|
+
root?: string;
|
|
47
|
+
form?: string;
|
|
48
|
+
table?: string;
|
|
49
|
+
};
|
|
50
|
+
styles?: {
|
|
51
|
+
root?: React.CSSProperties;
|
|
52
|
+
form?: React.CSSProperties;
|
|
53
|
+
table?: React.CSSProperties;
|
|
54
|
+
toolbar?: React.CSSProperties;
|
|
55
|
+
};
|
|
56
|
+
request?: {
|
|
57
|
+
url?: string;
|
|
58
|
+
method?: HttpMethod;
|
|
59
|
+
params?: RecordType;
|
|
60
|
+
onBefore?: () => any;
|
|
61
|
+
onSuccess?: (data: Tdata) => any;
|
|
62
|
+
};
|
|
63
|
+
table: TableInstance<Tdata> | null;
|
|
64
|
+
locale?: Record<string, any>;
|
|
65
|
+
dataKey?: string;
|
|
66
|
+
totalKey?: string;
|
|
67
|
+
manual?: boolean;
|
|
68
|
+
nostyle?: boolean;
|
|
69
|
+
columns: ((data: Tdata) => TableColumnType<unknown>[]) | TableColumnType<unknown>[];
|
|
70
|
+
form?: FormOptions;
|
|
71
|
+
alert?: React.ReactNode | ((data: Tdata) => React.ReactNode);
|
|
72
|
+
toolbar?: React.ReactNode;
|
|
73
|
+
pageSizeOptions?: number[];
|
|
74
|
+
pagination?: {
|
|
75
|
+
showQuickJumper?: boolean;
|
|
76
|
+
showSizeChanger?: boolean;
|
|
77
|
+
hideOnSinglePage?: boolean;
|
|
78
|
+
};
|
|
79
|
+
loadingDelay?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface UseTableProps {
|
|
82
|
+
page?: number;
|
|
83
|
+
size?: number;
|
|
84
|
+
sorter?: SorterType;
|
|
85
|
+
}
|
|
86
|
+
export interface TableRef {
|
|
87
|
+
form: FormInstance;
|
|
88
|
+
useStore: UseStoreType<any>;
|
|
89
|
+
run: () => void;
|
|
90
|
+
clear: () => void;
|
|
91
|
+
refresh: () => void;
|
|
92
|
+
reset: () => void;
|
|
93
|
+
sortOrder: (key: string) => "ascend" | "descend" | null;
|
|
94
|
+
update: () => void;
|
|
95
|
+
}
|
|
96
|
+
export interface ProTableConfigOptions {
|
|
97
|
+
getQuery?: (data: GetQueryProps) => Record<string, unknown>;
|
|
98
|
+
pageSizeOptions?: number[];
|
|
99
|
+
}
|
|
100
|
+
export {};
|