From 6456b1c33dc5fbad1a2b7489d640a3f21084ccaa Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Mon, 8 Dec 2025 10:20:45 +0800 Subject: [PATCH] =?UTF-8?q?useTable=E5=A2=9E=E5=8A=A0usePermission?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=BC=A0=E9=80=92menuPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/useTable/index.d.ts | 2 ++ hooks/useTable/index.js | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hooks/useTable/index.d.ts b/hooks/useTable/index.d.ts index 48d8e91..a99baad 100644 --- a/hooks/useTable/index.d.ts +++ b/hooks/useTable/index.d.ts @@ -12,6 +12,8 @@ export interface UseTableOptions ext defaultPagination?: { current: number; pageSize: number }; /** 是否使用存储查询条件,默认是 */ useStorageQueryCriteria?: boolean; + /** 是否使用数据权限,默认是 */ + usePermission?: boolean; /** 额外参数 */ params?: Record | (() => Record); /** 表单数据转换函数,在每次请求之前调用,接收当前搜索的表单项,要求返回一个对象 */ diff --git a/hooks/useTable/index.js b/hooks/useTable/index.js index 7ae4b54..e51d689 100644 --- a/hooks/useTable/index.js +++ b/hooks/useTable/index.js @@ -4,7 +4,7 @@ import useUrlQueryCriteria from "../useUrlQueryCriteria"; /** * 获取数据 */ -function getService(service, getExtraParams = {}, transform) { +function getService(service, getExtraParams = {}, transform, usePermission) { // 获取额外的参数 const extraParams = (typeof getExtraParams === "function" ? getExtraParams() : getExtraParams) || {}; // 获取数据 @@ -19,14 +19,18 @@ function getService(service, getExtraParams = {}, transform) { } } - // 发起请求 - const res = await service({ + const params = { pageIndex: current, pageSize, ...transformedFormData, ...extraParams, - menuPath: window.location.pathname, - }); + } + + if (usePermission) + params.menuPath = window.location.pathname + + // 发起请求 + const res = await service(params); // 返回数据 return { list: res.data || [], @@ -50,6 +54,7 @@ function useTable(service, options) { const { useStorageQueryCriteria = true, usePagination = true, + usePermission = true, defaultType = "advance", defaultCurrent = 1, defaultPageSize = 20, @@ -70,7 +75,7 @@ function useTable(service, options) { // 调用 ahooks 的 useAntdTable const res = useAntdTable( - getService(service, extraParams, transform), + getService(service, extraParams, transform, usePermission), { ...restRestOptions, defaultParams: [actualPagination, actualSearchForm],