Skip to content

Commit

Permalink
fix: 修复Store不显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft authored and jianbing.chen committed Dec 18, 2024
1 parent 446f41d commit cd7591a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/admin/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { memo, useEffect, useState } from 'react';
import { Dropdown, Flex, Space } from 'antd';
import { DownOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
import { useNavigate } from 'react-router-dom';
import { usePageStore } from '@/stores/pageStore';
import { usePageStore } from '@marsview/materials/stores/pageStore';
import { useProjectStore } from '@/stores/projectStore';
import Logo from '../Logo/Logo';
import BreadList from '../BreadList/BreadList';
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ConfigProvider, Layout } from 'antd';
import Header from '../components/Header/Header';
import Menu from '../components/Menu/Menu';
import { useProjectStore } from '@/stores/projectStore';
import { UserInfoStore, usePageStore } from '@/stores/pageStore';
import { UserInfoStore, usePageStore } from '@marsview/materials/stores/pageStore';
import { getProjectDetail, getProjectMenu } from '@/api/index';
import Tab from '../components/Tab';
import Logo from '@/components/Logo/Logo';
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Form, Input } from 'antd';
import { useNavigate } from 'react-router-dom';
import { login } from '@/api';
import storage from '@/utils/storage';
import { usePageStore } from '@/stores/pageStore';
import { usePageStore } from '@marsview/materials/stores/pageStore';
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import style from './index.module.less';
type FieldType = {
Expand Down
9 changes: 7 additions & 2 deletions packages/admin/src/pages/page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { ConfigProvider } from 'antd';
import { useShallow } from 'zustand/react/shallow';
import { Page } from '@marsview/materials/Page';
import { usePageStore as usePageStore2 } from '@marsview/materials/stores/pageStore';
import { usePageStore } from '@marsview/materials/stores/pageStore';
import { message } from '@/utils/AntdGlobal';
import { getPageDetail } from '@/api/index';
import locale from 'antd/locale/zh_CN';
import 'dayjs/locale/zh-cn';
export default function () {
const [theme, setTheme] = useState('');
const { id, env } = useParams();
const { savePageInfo } = usePageStore2();
const savePageInfo = usePageStore(
useShallow((state) => {
return state.savePageInfo;
}),
);
const navigate = useNavigate();
useEffect(() => {
if (id) {
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/pages/project/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getPageDetail } from '@/api/index';
import { useParams } from 'react-router-dom';
import { useEffect, useState } from 'react';
import { usePageStore as usePageStore2 } from '@marsview/materials/stores/pageStore';
import { usePageStore } from '@marsview/materials/stores/pageStore';
import { message } from '@/utils/AntdGlobal';
import NotFound from './notFound';
import { Page } from '@marsview/materials/Page';
Expand All @@ -10,7 +10,7 @@ import { useShallow } from 'zustand/react/shallow';
export default function () {
const { projectId, env, pageId } = useParams();
const [notFound, setNotFound] = useState(false);
const { savePageInfo, clearPageInfo } = usePageStore2(
const { savePageInfo, clearPageInfo } = usePageStore(
useShallow((state) => {
return {
savePageInfo: state.savePageInfo,
Expand Down
3 changes: 2 additions & 1 deletion packages/admin/src/router/AuthLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export default async function AuthLoader() {
window.location.replace(`/login?callback=${window.location.href}`);
return '';
}
const res: { userName: string } = await getUserInfo();
const res: any = await getUserInfo();
const userInfo = {
userId: res.userId,
userName: res.userName,
};
return userInfo;
Expand Down
29 changes: 0 additions & 29 deletions packages/admin/src/stores/pageStore.ts

This file was deleted.

18 changes: 11 additions & 7 deletions packages/materials/stores/pageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import { create } from 'zustand';
import { produce } from 'immer';
import { ComponentType, ApiType, PageVariable, EventType, ComItemType } from '../types';

/**
* 页面信息存储
*/
export interface UserInfoStore {
user_id: number;
user_name: string;
userId: number;
userName: string;
identifier: string;
}
export interface PageState {
Expand Down Expand Up @@ -60,15 +57,16 @@ export interface PageState {
};
}
export interface PageAction {
saveUserInfo: (userInfo: UserInfoStore) => void;
savePageInfo: (pageInfo: any) => void;
setVariableData: (payload: any) => void;
setFormData: (payload: any) => void;
clearPageInfo: () => void;
}
export const usePageStore = create<PageState & PageAction>((set) => ({
userInfo: {
user_id: 0,
user_name: '',
userId: 0,
userName: '',
identifier: '',
},
selectedElement: undefined,
Expand Down Expand Up @@ -113,6 +111,12 @@ export const usePageStore = create<PageState & PageAction>((set) => ({
timeoutErrorMessage: '请求超时,请稍后再试',
},
},
saveUserInfo: (userInfo: UserInfoStore) =>
set(
produce((state) => {
state.userInfo = userInfo;
}),
),
// 保存页面信息
savePageInfo: (payload: any) =>
set(
Expand Down

0 comments on commit cd7591a

Please sign in to comment.