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 };
|
defaultPagination?: { current: number; pageSize: number };
|
||||||
/** 是否使用存储查询条件,默认是 */
|
/** 是否使用存储查询条件,默认是 */
|
||||||
useStorageQueryCriteria?: boolean;
|
useStorageQueryCriteria?: boolean;
|
||||||
|
/** 是否使用数据权限,默认是 */
|
||||||
|
usePermission?: boolean;
|
||||||
/** 额外参数 */
|
/** 额外参数 */
|
||||||
params?: Record<string, any> | (() => Record<string, any>);
|
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) || {};
|
const extraParams = (typeof getExtraParams === "function" ? getExtraParams() : getExtraParams) || {};
|
||||||
// 获取数据
|
// 获取数据
|
||||||
|
|
@ -19,14 +19,18 @@ function getService(service, getExtraParams = {}, transform) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发起请求
|
const params = {
|
||||||
const res = await service({
|
|
||||||
pageIndex: current,
|
pageIndex: current,
|
||||||
pageSize,
|
pageSize,
|
||||||
...transformedFormData,
|
...transformedFormData,
|
||||||
...extraParams,
|
...extraParams,
|
||||||
menuPath: window.location.pathname,
|
}
|
||||||
});
|
|
||||||
|
if (usePermission)
|
||||||
|
params.menuPath = window.location.pathname
|
||||||
|
|
||||||
|
// 发起请求
|
||||||
|
const res = await service(params);
|
||||||
// 返回数据
|
// 返回数据
|
||||||
return {
|
return {
|
||||||
list: res.data || [],
|
list: res.data || [],
|
||||||
|
|
@ -50,6 +54,7 @@ function useTable(service, options) {
|
||||||
const {
|
const {
|
||||||
useStorageQueryCriteria = true,
|
useStorageQueryCriteria = true,
|
||||||
usePagination = true,
|
usePagination = true,
|
||||||
|
usePermission = true,
|
||||||
defaultType = "advance",
|
defaultType = "advance",
|
||||||
defaultCurrent = 1,
|
defaultCurrent = 1,
|
||||||
defaultPageSize = 20,
|
defaultPageSize = 20,
|
||||||
|
|
@ -70,7 +75,7 @@ function useTable(service, options) {
|
||||||
|
|
||||||
// 调用 ahooks 的 useAntdTable
|
// 调用 ahooks 的 useAntdTable
|
||||||
const res = useAntdTable(
|
const res = useAntdTable(
|
||||||
getService(service, extraParams, transform),
|
getService(service, extraParams, transform, usePermission),
|
||||||
{
|
{
|
||||||
...restRestOptions,
|
...restRestOptions,
|
||||||
defaultParams: [actualPagination, actualSearchForm],
|
defaultParams: [actualPagination, actualSearchForm],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue