Commit 6c75af40 authored by Bill's avatar Bill

fix: 修改首页没有菜单权限仍然显示数据bug

parent d0e67dd8
......@@ -152,8 +152,8 @@ export enum LAYOUT_TYPE {
// 本地环境跳过权限校验
export const isDev = process.env.NODE_ENV === "development"
// export const isDev = process.env.NODE_ENV === "development"
export const isDev = false
......
......@@ -28,7 +28,7 @@ const BIND_MANAGER = '/memberCenter/channelAbility/memberList'
const ChannelMallCenter: React.FC<Iprops> = () => {
const intl = useIntl();
const { userAuth, hasAbilityFunc } = useGetAuth();
const { loading, responseData, isError, ref, inViewPort } = useViewRequest<GetTemplateWebMemberChannelWebFindCurrMemberChannelResponse, any>(getTemplateWebMemberChannelWebFindCurrMemberChannel, { memberId: userAuth.memberId })
const { loading, responseData, isError, ref, inViewPort } = useViewRequest<GetTemplateWebMemberChannelWebFindCurrMemberChannelResponse, any>(getTemplateWebMemberChannelWebFindCurrMemberChannel, { memberId: userAuth.memberId }, { isFilterList: false });
const hasAbility = hasAbilityFunc('channelAbility');
const bindAuth = useMemo(() => userAuth.urls?.includes(BIND_MANAGER), [userAuth]);
const [salerNum, setSalerNum] = useState(0);
......
......@@ -22,7 +22,7 @@ const CREATE_SHOP = '/memberCenter/shopAbility/infoManage';
// 5、如果当前用户有创建店铺权限,但还未创建店铺,则显示:您还没有创建店铺,请先创建店铺,点击创建店铺,跳转能力中心-店铺能力-店铺管理-创建店铺页
const ShopCenter: React.FC<Iprops> = () => {
const { loading, responseData, isError, ref } = useViewRequest<GetTemplateWebMemberShopWebFindCurrMemberShopResponse, any>(getTemplateWebMemberShopWebFindCurrMemberShop, {})
const { loading, responseData, isError, ref } = useViewRequest<GetTemplateWebMemberShopWebFindCurrMemberShopResponse, any>(getTemplateWebMemberShopWebFindCurrMemberShop, {}, {isFilterList: false})
const intl = useIntl();
const userAuth = getAuth();
const hasShopAbility = userAuth.urls?.some((_item) => _item.includes(SHOP_ABILITY));
......
import { IRequestSuccess } from '@/index.d';
import { getAuth } from '@/utils/auth';
import { useInViewport } from '@umijs/hooks';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
type Options = {
/** 是否进行权限过滤处理 */
isFilterList: boolean
}
/***
* 当下拉滚动到可视区域时请求数据
*/
function useViewRequest<T, P>(fn: (postData: P) => Promise<IRequestSuccess<T>>, params?: P) {
function useViewRequest<T, P>(fn: (postData: P) => Promise<IRequestSuccess<T>>, params?: P, options?: Options) {
const [loading, setLoading] = useState<boolean>(false);
const [isError, setIsError] = useState<boolean>(false);
const [inViewPort, ref] = useInViewport<HTMLDivElement>();
const [hasRequest, setHasRequest] = useState<boolean>(false)
const [responseData, setResponseData] = useState<T | null>(null);
const userAuth = getAuth();
const cacheAuth = useMemo(() => userAuth, [userAuth]);
const urls = useMemo(() => cacheAuth?.urls || [], [cacheAuth])
const { isFilterList = true } = options || {}
// const hasFetchingRef = useRef(false);
const fetchData = useCallback(async (params) => {
setLoading(() => true);
try {
const { data, code, message } = await fn(params);
setHasRequest(() => true)
setHasRequest(true)
// throw new Error("123");
if (code === 1000) {
setResponseData(data as T)
}
} catch(error) {
setIsError(() => true);
setIsError(true);
} finally {
setHasRequest(() => true);
setLoading(() => false);
setHasRequest(true);
setLoading(false);
}
}, [fn])
......@@ -46,7 +56,7 @@ function useViewRequest<T, P>(fn: (postData: P) => Promise<IRequestSuccess<T>>,
}
const filterEmptyList = useMemo(() => {
if(!responseData) {
if(!responseData || !isFilterList) {
return responseData
}
......@@ -57,11 +67,14 @@ function useViewRequest<T, P>(fn: (postData: P) => Promise<IRequestSuccess<T>>,
if (!responseData) {
return result
}
console.log(responseData, "responData");
Object.keys(responseData).forEach((_row) => {
if (responseData[_row] && responseData[_row].length !== 0) {
result[_row] = responseData[_row];
result[_row] = responseData[_row]?.filter((_item) => urls.includes(_item.link));
}
})
console.log(result, "result");
return result;
}, [responseData])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment