zy-react-library 1.0.146 → 1.0.147
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/hooks/useTable/index.d.ts +2 -0
- package/hooks/useTable/index.js +11 -6
- package/package.json +1 -1
|
@@ -12,6 +12,8 @@ export interface UseTableOptions<TData extends Data, TParams extends Params> ext
|
|
|
12
12
|
defaultPagination?: { current: number; pageSize: number };
|
|
13
13
|
/** 是否使用存储查询条件,默认是 */
|
|
14
14
|
useStorageQueryCriteria?: boolean;
|
|
15
|
+
/** 是否使用数据权限,默认是 */
|
|
16
|
+
usePermission?: boolean;
|
|
15
17
|
/** 额外参数 */
|
|
16
18
|
params?: Record<string, any> | (() => Record<string, any>);
|
|
17
19
|
/** 表单数据转换函数,在每次请求之前调用,接收当前搜索的表单项,要求返回一个对象 */
|
package/hooks/useTable/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import useUrlQueryCriteria from "../useUrlQueryCriteria";
|
|
|
4
4
|
/**
|
|
5
5
|
* 获取数据
|
|
6
6
|
*/
|
|
7
|
-
function getService(service, getExtraParams = {}, transform) {
|
|
7
|
+
function getService(service, getExtraParams = {}, transform, usePermission) {
|
|
8
8
|
// 获取额外的参数
|
|
9
9
|
const extraParams = (typeof getExtraParams === "function" ? getExtraParams() : getExtraParams) || {};
|
|
10
10
|
// 获取数据
|
|
@@ -19,14 +19,18 @@ function getService(service, getExtraParams = {}, transform) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
const res = await service({
|
|
22
|
+
const params = {
|
|
24
23
|
pageIndex: current,
|
|
25
24
|
pageSize,
|
|
26
25
|
...transformedFormData,
|
|
27
26
|
...extraParams,
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (usePermission)
|
|
30
|
+
params.menuPath = window.location.pathname
|
|
31
|
+
|
|
32
|
+
// 发起请求
|
|
33
|
+
const res = await service(params);
|
|
30
34
|
// 返回数据
|
|
31
35
|
return {
|
|
32
36
|
list: res.data || [],
|
|
@@ -50,6 +54,7 @@ function useTable(service, options) {
|
|
|
50
54
|
const {
|
|
51
55
|
useStorageQueryCriteria = true,
|
|
52
56
|
usePagination = true,
|
|
57
|
+
usePermission = true,
|
|
53
58
|
defaultType = "advance",
|
|
54
59
|
defaultCurrent = 1,
|
|
55
60
|
defaultPageSize = 20,
|
|
@@ -70,7 +75,7 @@ function useTable(service, options) {
|
|
|
70
75
|
|
|
71
76
|
// 调用 ahooks 的 useAntdTable
|
|
72
77
|
const res = useAntdTable(
|
|
73
|
-
getService(service, extraParams, transform),
|
|
78
|
+
getService(service, extraParams, transform, usePermission),
|
|
74
79
|
{
|
|
75
80
|
...restRestOptions,
|
|
76
81
|
defaultParams: [actualPagination, actualSearchForm],
|