useTable增加usePermission参数,用于判断是否传递menuPath
parent
33a5a4f4f5
commit
6456b1c33d
|
|
@ -12,6 +12,8 @@ export interface UseTableOptions<TData extends Data, TParams extends Params> ext
|
|||
defaultPagination?: { current: number; pageSize: number };
|
||||
/** 是否使用存储查询条件,默认是 */
|
||||
useStorageQueryCriteria?: boolean;
|
||||
/** 是否使用数据权限,默认是 */
|
||||
usePermission?: boolean;
|
||||
/** 额外参数 */
|
||||
params?: Record<string, any> | (() => Record<string, any>);
|
||||
/** 表单数据转换函数,在每次请求之前调用,接收当前搜索的表单项,要求返回一个对象 */
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
|
|
|
|||
Loading…
Reference in New Issue