Skip to content

Commit

Permalink
fix: 修复Loading问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Aug 28, 2024
1 parent ec4741b commit cbe7ee2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/editor/src/pages/home/LibList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import style from './index.module.less';
export default () => {
const [form] = Form.useForm();
const [list, setList] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [loading, setLoading] = useState(true);
const [total, setTotal] = useState<number>(0);
const [current, setCurrent] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(10);
Expand Down Expand Up @@ -101,7 +101,7 @@ export default () => {

return (
<div className={style.libWrap}>
{total > 0 ? (
{total > 0 || loading ? (
<>
<SearchBar form={form} from="组件" submit={handleSearch} refresh={getList} onCreate={handleCreate} />
<div className={style.libList}>
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/pages/home/PageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default function Index() {
return (
<>
<Layout.Content className={styles.pageList}>
{total > 0 ? (
{total > 0 || loading ? (
<>
<SearchBar form={form} from="页面" submit={handleSearch} refresh={getList} onCreate={handleCreate} />
<div className={styles.pagesContent}>
Expand Down
3 changes: 1 addition & 2 deletions packages/editor/src/pages/home/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default function Index() {
const [form] = Form.useForm();
const [loading, setLoading] = useState(true);
const [projectList, setProjectList] = useState<Project.ProjectItem[]>([]);
const [projectId, setProjectId] = useState(-1);
const [total, setTotal] = useState<number>(0);
const [current, setCurrent] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(12);
Expand Down Expand Up @@ -166,7 +165,7 @@ export default function Index() {
return (
<>
<Layout.Content className={styles.project}>
{total > 0 ? (
{total > 0 || loading ? (
<>
<SearchBar form={form} from="项目" submit={handleSearch} refresh={getList} onCreate={() => navigate('/project/0/config')} />
<div className={styles.projectList}>
Expand Down
7 changes: 5 additions & 2 deletions packages/editor/src/router/LazyLoad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { Spin } from 'antd';
* @param Component 组件对象
* @returns 返回新组件
*/
export const lazyLoad = (Component: React.FC): React.ReactNode => {
export const lazyLoad = (Component: React.FC, isEditor?: boolean): React.ReactNode => {
// 编辑器组件由于比较慢,增加一个Loading效果
return (
<Suspense fallback={<Spin size="large" style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }} />}>
<Suspense
fallback={isEditor ? <Spin size="large" style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginTop: 30 }} /> : null}
>
<Component />
</Suspense>
);
Expand Down
10 changes: 8 additions & 2 deletions packages/editor/src/router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ export const router = [
},
{
path: '/editor/:id',
element: lazyLoad(React.lazy(() => import('@/layout/EditLayout'))),
element: lazyLoad(
React.lazy(() => import('@/layout/EditLayout')),
true,
),
children: [
{
path: '/editor/:id/edit',
element: lazyLoad(React.lazy(() => import('@/pages/editor/editor'))),
element: lazyLoad(
React.lazy(() => import('@/pages/editor/editor')),
true,
),
},
],
},
Expand Down

0 comments on commit cbe7ee2

Please sign in to comment.