Commit ad313276 authored by Bill's avatar Bill

fix: 修改首页权限,兼容未登录时权限为空导致报错问题

parent c49d7c42
......@@ -42,7 +42,7 @@ const collection2Obj = <T, >(list: T[], name: string, isCover?: boolean) => {
const useGetAuth = () => {
const userAuth = getAuth();
const cacheAuth = useMemo(() => userAuth, [userAuth]);
const urls = useMemo(() => cacheAuth.urls, [cacheAuth])
const urls = useMemo(() => cacheAuth?.urls || [], [cacheAuth])
const abilityUrls = useMemo(() => {
return {
......@@ -130,7 +130,7 @@ const useGetAuth = () => {
return currentAbilityUrl.some((_item) => urls?.some((_row) => _row.includes(_item)));
}, [urls, abilityUrls])
const isConsumer = useMemo(() => cacheAuth.memberRoleType === 2, [cacheAuth])
const isConsumer = useMemo(() => cacheAuth?.memberRoleType === 2, [cacheAuth])
/**
* 直接判断有没有大模块如果有,那么表示应该显示此模块,
......
......@@ -8,50 +8,76 @@ import { useDebounceFn } from '@umijs/hooks';
const AllQuery = () => {
const [dataSource, setDataSource] = useState([]);
const [dataSource, setDataSource] = useState<any[]>([]);
const [totalCount, setTotalCount] = useState<number>(1);
const [page, setPage] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(10);
const fetchData = useCallback(async (page: number, pageSize: number) => {
setDataSource([{
no: 1,
value: '1',
level: 1,
}]);
}, [])
useEffect(() => {
fetchData(page, pageSize)
}, [])
const handleSetValue = (params: { dataIndex: string, value: string, index: number }) => {
const { index, dataIndex, value } = params;
const newData = dataSource.map((_item, currentIndex) => {
if (index === currentIndex) {
return {
..._item,
[dataIndex]: value,
}
}
return _item;
})
setDataSource(newData);
}
const columns = useMemo<ColumnsType<any>>(() => {
return [
{
title: '序号',
dataIndex: 'no',
},
{
title: '预警条件',
dataIndex: 'memberName',
},
{
title: '预警提示语',
dataIndex: 'project',
},
{
title: '预警提示语',
dataIndex: 'notice',
},
{
title: '预警值',
dataIndex: 'value',
render: (text, record, index) => {
return <Input value={text} onChange={(e) => handleSetValue({ dataIndex: 'value', value: e.target.value, index: index})}/>
}
},
{
title: '预警值',
dataIndex: 'value',
render: (text, record) => {
return <Select value={text} />
}
const paginationOnChange = useCallback((page: number, pageSize: number) => {
setPage(page);
setPageSize(pageSize);
fetchData(page, pageSize)
}, [fetchData])
const columns = [
{
title: '序号',
dataIndex: 'no',
},
{
title: '预警条件',
dataIndex: 'memberName',
},
{
title: '预警提示语',
dataIndex: 'project',
},
{
title: '预警提示语',
dataIndex: 'notice',
},
{
title: '预警值',
dataIndex: 'value',
render: (text, record, index) => {
return <Input value={text} onChange={(e) => handleSetValue({ dataIndex: 'value', value: e.target.value, index: index})}/>
}
]
}, [])
},
{
title: '预警级别',
dataIndex: 'level',
render: (text, record) => {
return <Select value={text} />
}
}
]
return (
<PageHeaderWrapper
......@@ -61,6 +87,10 @@ const AllQuery = () => {
<Table
columns={columns}
dataSource={dataSource}
rowKey="no"
pagination={{
onChange: paginationOnChange,
}}
></Table>
</Card>
</PageHeaderWrapper>
......
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