listpage-next 0.0.116 → 0.0.118
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/dist/components/Page/components/ListPage/DataTable.d.ts +8 -7
- package/dist/components/Page/components/ListPage/DataTable.js +12 -4
- package/dist/components/Page/components/ListPage/styles.js +1 -0
- package/dist/components/Page/components/ListPage/v2.d.ts +3 -4
- package/dist/components/Page/components/ListPage/v2.js +5 -11
- package/dist/components/Page/context/listpage.d.ts +19 -6
- package/dist/components/Page/context/listpage.js +47 -5
- package/dist/components/Page/hooks/useHeader.d.ts +7 -0
- package/dist/components/Page/hooks/useHeader.js +20 -0
- package/dist/components/Page/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { TableProps } from 'antd';
|
|
2
|
-
import { ListPageStore } from '../../context/listpage';
|
|
3
|
-
import { ComponentProps, ComponentType } from '../../../DataTable/typings';
|
|
4
2
|
import { ColumnType } from 'antd/es/table';
|
|
3
|
+
import { ListPageStore } from '../../context/listpage';
|
|
5
4
|
import { ColumnRender } from '../../../DataTable/components/Render';
|
|
6
|
-
|
|
5
|
+
import { ComponentProps, ComponentType } from '../../../DataTable/typings';
|
|
6
|
+
export interface DataTableProps<RecordValue extends Record<string, any> = any> extends Omit<TableProps<RecordValue>, 'dataSource' | 'title' | 'columns'> {
|
|
7
7
|
title?: React.ReactNode;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
rowSelectionType?: 'checkbox' | 'radio';
|
|
9
|
+
extra?: React.ReactNode | ((ctx: ListPageStore<any, RecordValue>) => React.ReactNode);
|
|
10
|
+
columns?: ListPageTableColumn<RecordValue>[];
|
|
10
11
|
}
|
|
11
|
-
export interface ListPageTableColumn<Record = any> extends ColumnType<
|
|
12
|
-
component?: ComponentType | ColumnRender<
|
|
12
|
+
export interface ListPageTableColumn<RecordValue extends Record<string, any> = any, FilterValue = any> extends ColumnType<RecordValue> {
|
|
13
|
+
component?: ComponentType | ColumnRender<RecordValue, ListPageStore<FilterValue, RecordValue>>;
|
|
13
14
|
props?: ComponentProps;
|
|
14
15
|
}
|
|
15
16
|
export declare const DataTable: ((props: DataTableProps) => import("react/jsx-runtime").JSX.Element) & {
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Card, Table } from "antd";
|
|
3
|
+
import { observer } from "mobx-react-lite";
|
|
3
4
|
import { useListPageStore } from "../../context/listpage.js";
|
|
4
5
|
import { TableContainer } from "../../../DataTable/index.js";
|
|
5
6
|
import { usePagination } from "../../hooks/usePagination.js";
|
|
6
7
|
import { useColumns } from "../../hooks/useColumns.js";
|
|
7
|
-
import { observer } from "mobx-react-lite";
|
|
8
8
|
const DataTable = observer((props)=>{
|
|
9
|
-
const { title, extra, columns, ...restProps } = props;
|
|
9
|
+
const { title, extra, columns, rowSelectionType, ...restProps } = props;
|
|
10
10
|
const store = useListPageStore();
|
|
11
11
|
const paginationEle = usePagination(props.pagination);
|
|
12
12
|
const newColumns = useColumns(columns);
|
|
13
|
+
const extraEle = 'function' == typeof extra ? extra(store) : extra;
|
|
13
14
|
return /*#__PURE__*/ jsxs(Card, {
|
|
14
15
|
title: title,
|
|
15
|
-
extra:
|
|
16
|
+
extra: extraEle,
|
|
16
17
|
styles: {
|
|
17
18
|
body: {
|
|
18
19
|
padding: 0
|
|
@@ -26,7 +27,14 @@ const DataTable = observer((props)=>{
|
|
|
26
27
|
columns: newColumns,
|
|
27
28
|
loading: store.loadingData,
|
|
28
29
|
dataSource: store.dataSource,
|
|
29
|
-
pagination: false
|
|
30
|
+
pagination: false,
|
|
31
|
+
rowSelection: rowSelectionType && {
|
|
32
|
+
preserveSelectedRowKeys: true,
|
|
33
|
+
...restProps.rowSelection,
|
|
34
|
+
type: rowSelectionType,
|
|
35
|
+
selectedRowKeys: store.selection.selectedRowKeys,
|
|
36
|
+
onChange: store.onSelectChange
|
|
37
|
+
}
|
|
30
38
|
})
|
|
31
39
|
}),
|
|
32
40
|
paginationEle
|
|
@@ -3,7 +3,9 @@ import { TableProps } from 'antd';
|
|
|
3
3
|
import { FloatRender, ListPageStore, TableRequest } from '../../context/listpage';
|
|
4
4
|
import { FilterFormOption } from '../../../FilterGroup';
|
|
5
5
|
import { DataTableColumns } from '../../../DataTable';
|
|
6
|
+
import { HeaderProps } from '../../hooks/useHeader';
|
|
6
7
|
export interface ListPageProps<FilterValue = any, RecordValue extends Record<string, any> = any> {
|
|
8
|
+
storageKey?: string;
|
|
7
9
|
request: TableRequest<FilterValue, RecordValue>;
|
|
8
10
|
floats?: {
|
|
9
11
|
key: string;
|
|
@@ -14,10 +16,7 @@ export interface ListPageProps<FilterValue = any, RecordValue extends Record<str
|
|
|
14
16
|
pageSize?: number;
|
|
15
17
|
currentPage?: number;
|
|
16
18
|
};
|
|
17
|
-
header?:
|
|
18
|
-
title?: ReactNode;
|
|
19
|
-
extra?: ReactNode;
|
|
20
|
-
};
|
|
19
|
+
header?: HeaderProps;
|
|
21
20
|
filter?: {
|
|
22
21
|
options: FilterFormOption[];
|
|
23
22
|
onReset?: () => void;
|
|
@@ -3,14 +3,16 @@ import { observer } from "mobx-react-lite";
|
|
|
3
3
|
import { useMount, useUpdateEffect } from "ahooks";
|
|
4
4
|
import { toJS } from "mobx";
|
|
5
5
|
import { ListPageProvider, useListPageStore } from "../../context/listpage.js";
|
|
6
|
-
import { FilterSection,
|
|
6
|
+
import { FilterSection, ListPageContainer, ToolbarSection } from "./styles.js";
|
|
7
7
|
import { FilterForm } from "../../../FilterGroup/index.js";
|
|
8
8
|
import { useFloat } from "../../hooks/useFloat.js";
|
|
9
9
|
import { DataTable } from "./DataTable.js";
|
|
10
|
+
import { useHeader } from "../../hooks/useHeader.js";
|
|
10
11
|
const PureListPage = observer((props)=>{
|
|
11
12
|
const { header, filter, toolbar, table } = props;
|
|
12
13
|
const store = useListPageStore();
|
|
13
14
|
const floatEle = useFloat();
|
|
15
|
+
const headerEle = useHeader(header);
|
|
14
16
|
useMount(()=>{
|
|
15
17
|
store.refreshTable();
|
|
16
18
|
});
|
|
@@ -21,16 +23,7 @@ const PureListPage = observer((props)=>{
|
|
|
21
23
|
]);
|
|
22
24
|
return /*#__PURE__*/ jsxs(ListPageContainer, {
|
|
23
25
|
children: [
|
|
24
|
-
|
|
25
|
-
children: [
|
|
26
|
-
/*#__PURE__*/ jsx(Title, {
|
|
27
|
-
children: header.title
|
|
28
|
-
}),
|
|
29
|
-
/*#__PURE__*/ jsx("div", {
|
|
30
|
-
children: header.extra
|
|
31
|
-
})
|
|
32
|
-
]
|
|
33
|
-
}),
|
|
26
|
+
headerEle,
|
|
34
27
|
filter && /*#__PURE__*/ jsx(FilterSection, {
|
|
35
28
|
children: /*#__PURE__*/ jsx(FilterForm, {
|
|
36
29
|
onReset: filter.onReset,
|
|
@@ -53,6 +46,7 @@ const PureListPage = observer((props)=>{
|
|
|
53
46
|
});
|
|
54
47
|
});
|
|
55
48
|
const ListPage = (props)=>/*#__PURE__*/ jsx(ListPageProvider, {
|
|
49
|
+
storageKey: props.storageKey,
|
|
56
50
|
request: props.request,
|
|
57
51
|
floats: props.floats,
|
|
58
52
|
initialValues: props.initialValues,
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { JSX, ReactNode } from 'react';
|
|
1
|
+
import { JSX, Key, ReactNode } from 'react';
|
|
2
2
|
import { FloatComponentProps } from '../../../context';
|
|
3
3
|
import { BaseQueryParams, PaginationData } from '../../../http-client/types';
|
|
4
4
|
export type TableRequest<FilterValue = any, RecordValue = any> = (pageParams: BaseQueryParams, filterValues: FilterValue) => Promise<PaginationData<RecordValue>>;
|
|
5
5
|
export type FloatRender<RecordValue extends Record<string, any> = any> = (props: FloatComponentProps<RecordValue>) => JSX.Element;
|
|
6
|
+
export type ListPageStorageOption<FilterValue = any, RecordValue extends Record<string, any> = any> = {
|
|
7
|
+
storageKey?: string;
|
|
8
|
+
initialValues: any;
|
|
9
|
+
request: TableRequest<FilterValue, RecordValue>;
|
|
10
|
+
floats: {
|
|
11
|
+
key: string;
|
|
12
|
+
render: FloatRender<RecordValue>;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
6
15
|
export declare class ListPageStore<FilterValue = any, RecordValue extends Record<string, any> = any> {
|
|
16
|
+
storageKey?: string;
|
|
7
17
|
filters: FilterValue;
|
|
8
18
|
tableDataRequest: TableRequest<FilterValue, RecordValue>;
|
|
9
19
|
floats: {
|
|
@@ -22,24 +32,27 @@ export declare class ListPageStore<FilterValue = any, RecordValue extends Record
|
|
|
22
32
|
pageSize: number;
|
|
23
33
|
total: number;
|
|
24
34
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
35
|
+
selection: {
|
|
36
|
+
selectedRowKeys: Key[];
|
|
37
|
+
selectedRows: RecordValue[];
|
|
38
|
+
};
|
|
39
|
+
constructor(options: ListPageStorageOption<FilterValue, RecordValue>);
|
|
29
40
|
submitFiltersChange(value?: FilterValue): void;
|
|
30
41
|
showFloat(key: string, record: any, onCloseCallback?: () => void): void;
|
|
31
42
|
hideFloat(): void;
|
|
32
43
|
updatePage(page: number, pageSize: number): void;
|
|
33
44
|
fetchTableData(): Promise<void>;
|
|
45
|
+
onSelectChange: (selectedRowKeys: Key[], selectedRows: RecordValue[]) => void;
|
|
34
46
|
refreshTable(): void;
|
|
35
47
|
}
|
|
36
|
-
export declare const ListPageProvider: ({ children, initialValues, request, floats, }: {
|
|
48
|
+
export declare const ListPageProvider: ({ children, initialValues, request, storageKey, floats, }: {
|
|
37
49
|
children: ReactNode;
|
|
38
50
|
initialValues?: {
|
|
39
51
|
filterValues?: any;
|
|
40
52
|
pageSize?: number;
|
|
41
53
|
currentPage?: number;
|
|
42
54
|
};
|
|
55
|
+
storageKey?: string;
|
|
43
56
|
floats?: {
|
|
44
57
|
key: string;
|
|
45
58
|
render: FloatRender<any>;
|
|
@@ -2,6 +2,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { makeAutoObservable, runInAction } from "mobx";
|
|
3
3
|
import { createContext, useContext, useMemo } from "react";
|
|
4
4
|
class ListPageStore {
|
|
5
|
+
storageKey;
|
|
5
6
|
filters = {};
|
|
6
7
|
tableDataRequest;
|
|
7
8
|
floats = [];
|
|
@@ -9,13 +10,21 @@ class ListPageStore {
|
|
|
9
10
|
loadingData = false;
|
|
10
11
|
dataSource = [];
|
|
11
12
|
pagination;
|
|
12
|
-
|
|
13
|
+
selection;
|
|
14
|
+
constructor(options){
|
|
15
|
+
const { initialValues = {}, request, floats = [], storageKey } = options;
|
|
16
|
+
const defaultValue = getDefaultValue(storageKey);
|
|
17
|
+
this.storageKey = storageKey;
|
|
13
18
|
this.filters = initialValues.filterValues || {};
|
|
14
19
|
this.floats = floats;
|
|
15
20
|
this.pagination = {
|
|
16
21
|
total: 0,
|
|
17
|
-
current: initialValues.currentPage ||
|
|
18
|
-
pageSize: initialValues.pageSize ||
|
|
22
|
+
current: initialValues.currentPage || defaultValue.currentPage,
|
|
23
|
+
pageSize: initialValues.pageSize || defaultValue.pageSize
|
|
24
|
+
};
|
|
25
|
+
this.selection = {
|
|
26
|
+
selectedRowKeys: [],
|
|
27
|
+
selectedRows: []
|
|
19
28
|
};
|
|
20
29
|
this.tableDataRequest = request;
|
|
21
30
|
makeAutoObservable(this);
|
|
@@ -39,6 +48,10 @@ class ListPageStore {
|
|
|
39
48
|
if (pageSize !== this.pagination.pageSize) page = 1;
|
|
40
49
|
this.pagination.current = page;
|
|
41
50
|
this.pagination.pageSize = pageSize;
|
|
51
|
+
setDefaultValue(this.storageKey, {
|
|
52
|
+
currentPage: page,
|
|
53
|
+
pageSize
|
|
54
|
+
});
|
|
42
55
|
this.refreshTable();
|
|
43
56
|
}
|
|
44
57
|
async fetchTableData() {
|
|
@@ -60,13 +73,22 @@ class ListPageStore {
|
|
|
60
73
|
});
|
|
61
74
|
}
|
|
62
75
|
}
|
|
76
|
+
onSelectChange = (selectedRowKeys, selectedRows)=>{
|
|
77
|
+
this.selection.selectedRowKeys = selectedRowKeys;
|
|
78
|
+
this.selection.selectedRows = selectedRows;
|
|
79
|
+
};
|
|
63
80
|
refreshTable() {
|
|
64
81
|
this.fetchTableData();
|
|
65
82
|
}
|
|
66
83
|
}
|
|
67
84
|
const ListPageContext = /*#__PURE__*/ createContext({});
|
|
68
|
-
const ListPageProvider = ({ children, initialValues, request, floats = [] })=>{
|
|
69
|
-
const store = useMemo(()=>new ListPageStore(
|
|
85
|
+
const ListPageProvider = ({ children, initialValues, request, storageKey, floats = [] })=>{
|
|
86
|
+
const store = useMemo(()=>new ListPageStore({
|
|
87
|
+
initialValues,
|
|
88
|
+
request,
|
|
89
|
+
floats,
|
|
90
|
+
storageKey
|
|
91
|
+
}), []);
|
|
70
92
|
return /*#__PURE__*/ jsx(ListPageContext.Provider, {
|
|
71
93
|
value: store,
|
|
72
94
|
children: children
|
|
@@ -75,4 +97,24 @@ const ListPageProvider = ({ children, initialValues, request, floats = [] })=>{
|
|
|
75
97
|
function useListPageStore() {
|
|
76
98
|
return useContext(ListPageContext);
|
|
77
99
|
}
|
|
100
|
+
const getDefaultValue = (STORAGE_KEY)=>{
|
|
101
|
+
if (!STORAGE_KEY) return {
|
|
102
|
+
currentPage: 1,
|
|
103
|
+
pageSize: 10
|
|
104
|
+
};
|
|
105
|
+
const storageValue = localStorage.getItem(STORAGE_KEY);
|
|
106
|
+
const value = JSON.parse(storageValue ?? '{}');
|
|
107
|
+
return {
|
|
108
|
+
currentPage: value.currentPage || 1,
|
|
109
|
+
pageSize: value.pageSize || 10
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
const setDefaultValue = (STORAGE_KEY, value)=>{
|
|
113
|
+
if (!STORAGE_KEY) return;
|
|
114
|
+
const defaultValue = getDefaultValue(STORAGE_KEY);
|
|
115
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
|
116
|
+
...defaultValue,
|
|
117
|
+
...value
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
78
120
|
export { ListPageProvider, ListPageStore, useListPageStore };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ListPageStore } from '../context/listpage';
|
|
3
|
+
export type HeaderProps = {
|
|
4
|
+
title?: ReactNode;
|
|
5
|
+
extra?: ReactNode | ((ctx: ListPageStore) => ReactNode);
|
|
6
|
+
};
|
|
7
|
+
export declare function useHeader(props?: HeaderProps): false | import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { HeaderSection, Title } from "../components/ListPage/styles.js";
|
|
3
|
+
import { useListPageStore } from "../context/listpage.js";
|
|
4
|
+
function useHeader(props) {
|
|
5
|
+
const store = useListPageStore();
|
|
6
|
+
if (!props) return false;
|
|
7
|
+
const { title, extra } = props;
|
|
8
|
+
const extraEle = 'function' == typeof extra ? extra(store) : extra;
|
|
9
|
+
return /*#__PURE__*/ jsxs(HeaderSection, {
|
|
10
|
+
children: [
|
|
11
|
+
/*#__PURE__*/ jsx(Title, {
|
|
12
|
+
children: title
|
|
13
|
+
}),
|
|
14
|
+
/*#__PURE__*/ jsx("div", {
|
|
15
|
+
children: extraEle
|
|
16
|
+
})
|
|
17
|
+
]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export { useHeader };
|
|
@@ -4,3 +4,4 @@ export { PageLoading } from './components/Loading';
|
|
|
4
4
|
export { usePageContext } from './context/page';
|
|
5
5
|
export { ListPage as ListPagePro, type ListPageProps as ListPageProProps, } from './components/ListPage/v2';
|
|
6
6
|
export { type ListPageTableColumn } from './components/ListPage/DataTable';
|
|
7
|
+
export { type TableRequest } from './context/listpage';
|