fix(api):update store
This commit is contained in:
parent
f7e8a7bd1e
commit
c08daa777e
45
src/App.tsx
45
src/App.tsx
|
@ -36,30 +36,29 @@ const App = (props: Store) => {
|
|||
<>
|
||||
<MyComponent>
|
||||
<Outlet />
|
||||
<Modal
|
||||
title="登录"
|
||||
className="owner_model"
|
||||
width={"50%"}
|
||||
open={usrStore.isNeedLogin}
|
||||
afterClose={() => {}}
|
||||
onOk={() => {
|
||||
formRef.current?.submit();
|
||||
}}
|
||||
onCancel={() => {
|
||||
usrStore.closeLoginDilog();
|
||||
}}
|
||||
>
|
||||
<SimpleForm
|
||||
formRef={formRef}
|
||||
formName="login_basic"
|
||||
colProps={4}
|
||||
formDatas={loginForm}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
/>
|
||||
</Modal>
|
||||
</MyComponent>
|
||||
|
||||
<Modal
|
||||
title="登录"
|
||||
className="owner_model"
|
||||
width={"50%"}
|
||||
open={usrStore.isNeedLogin}
|
||||
afterClose={() => {}}
|
||||
onOk={() => {
|
||||
formRef.current?.submit();
|
||||
}}
|
||||
onCancel={() => {
|
||||
usrStore.closeLoginDilog();
|
||||
}}
|
||||
>
|
||||
<SimpleForm
|
||||
formRef={formRef}
|
||||
formName="login_basic"
|
||||
colProps={4}
|
||||
formDatas={loginForm}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ import Modal from "antd/lib/modal";
|
|||
import { PlusOutlined } from "@ant-design/icons";
|
||||
import Upload, { RcFile, UploadFile, UploadProps } from "antd/lib/upload";
|
||||
import { useEffect, useState } from "react";
|
||||
import Config from "@/util/config";
|
||||
|
||||
interface UploadFileProps {
|
||||
imgList: Array<UploadFileEx>;
|
||||
|
@ -14,6 +15,7 @@ interface UploadFileEx extends UploadFile {
|
|||
redictUrl?: string;
|
||||
id?: number;
|
||||
}
|
||||
|
||||
const getBase64 = (file: RcFile): Promise<string> =>
|
||||
new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
|
@ -45,7 +47,7 @@ const AliUpload = (props: UploadFileProps) => {
|
|||
|
||||
const handleChange: UploadProps["onChange"] = ({ fileList: newFileList }) => {
|
||||
newFileList.forEach((i)=>{
|
||||
i.url = "http://127.0.0.1:12214/uploads/"+i.name
|
||||
i.url = `${Config.uploadUrl}uploads/`+i.name
|
||||
})
|
||||
setFileList(newFileList);
|
||||
props.onChnage(newFileList)
|
||||
|
@ -62,7 +64,7 @@ const AliUpload = (props: UploadFileProps) => {
|
|||
<Upload
|
||||
listType="picture-card"
|
||||
fileList={files}
|
||||
action={"http://127.0.0.1:12214/v1/public/fts/upload"}
|
||||
action={`${Config.uploadUrl}v1/public/fts/upload`}
|
||||
onPreview={handlePreview}
|
||||
maxCount={1}
|
||||
onChange={handleChange}
|
||||
|
|
|
@ -1,12 +1,99 @@
|
|||
import { Content, Header } from "antd/es/layout/layout";
|
||||
import "./layout.less";
|
||||
import React from "react";
|
||||
const LayOut = (props: any) => {
|
||||
|
||||
import { Menu } from "antd";
|
||||
import { Footer } from "antd/lib/layout/layout";
|
||||
import { Outlet, useNavigate } from "react-router";
|
||||
import { HomeTwoTone } from "@ant-design/icons";
|
||||
import { inject, observer } from "mobx-react";
|
||||
import { Store } from "antd/es/form/interface";
|
||||
import { useEffect } from "react";
|
||||
const LayOut = (props: Store) => {
|
||||
const { usrStore } = props;
|
||||
const nav = useNavigate();
|
||||
console.log(usrStore.isNeedLogin);
|
||||
useEffect(() => {
|
||||
if (usrStore.isNeedLogin) {
|
||||
nav("/login");
|
||||
}
|
||||
}, [usrStore,nav]);
|
||||
const items = [
|
||||
{
|
||||
key: "/admin/user",
|
||||
label: `用户管理`,
|
||||
},
|
||||
{
|
||||
key: "/admin/dep",
|
||||
label: `部门管理`,
|
||||
},
|
||||
{
|
||||
key: "/admin/archives",
|
||||
label: `档案管理`,
|
||||
},
|
||||
{
|
||||
key: "/admin/whseMgmt",
|
||||
label: `仓库管理`,
|
||||
},
|
||||
{
|
||||
key: "/admin/leaveApproval",
|
||||
label: `请假审批`,
|
||||
},
|
||||
{
|
||||
key: "/admin/politicalStudy",
|
||||
label: `政治学习`,
|
||||
},
|
||||
{
|
||||
key: `/admin/polRegulations`,
|
||||
label: `政治法规管理`,
|
||||
},
|
||||
{
|
||||
key: "/admin/materialMgmt",
|
||||
label: `物资管理`,
|
||||
},
|
||||
{
|
||||
key: "/admin/teamMgmt",
|
||||
label: `队伍属性管理`,
|
||||
},
|
||||
{
|
||||
key: "/admin/persMgmt",
|
||||
label: `个人身份管理`,
|
||||
},
|
||||
];
|
||||
return (
|
||||
<div className="layout">
|
||||
|
||||
<Header
|
||||
style={{
|
||||
position: "sticky",
|
||||
top: 0,
|
||||
zIndex: 1,
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
padding: "0 10px",
|
||||
}}
|
||||
>
|
||||
<HomeTwoTone
|
||||
onClick={() => nav("/")}
|
||||
style={{ fontSize: "36px", marginRight: "10px" }}
|
||||
/>
|
||||
<Menu
|
||||
theme="dark"
|
||||
mode="horizontal"
|
||||
defaultSelectedKeys={["/admin/user"]}
|
||||
items={items}
|
||||
onClick={(e) => {
|
||||
nav(e.key);
|
||||
}}
|
||||
style={{ flex: 1, minWidth: 0 }}
|
||||
/>
|
||||
</Header>
|
||||
<Content style={{ padding: "0 20px" }}>
|
||||
<Outlet />
|
||||
</Content>
|
||||
<Footer style={{ textAlign: "center" }}>
|
||||
Ant Design ©{new Date().getFullYear()} Created by Ant UED
|
||||
</Footer>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LayOut;
|
||||
export default inject("usrStore")(observer(LayOut));
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
html{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
|
|
|
@ -18,7 +18,7 @@ const HomeLeft = () => {
|
|||
MapUtl.makerList[0].setIcon(newIcon);
|
||||
};
|
||||
const jumpToUser = () => {
|
||||
navigate("/user");
|
||||
navigate("admin/user");
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
const LeaveApproval = () => {
|
||||
return (
|
||||
<>
|
||||
<p>leaveApproval</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default LeaveApproval;
|
|
@ -10,17 +10,17 @@ const Login = (props) => {
|
|||
const navigate = useNavigate();
|
||||
const onFinish = (values: any) => {
|
||||
usrStore.login({
|
||||
userName: values.username,
|
||||
userName: values.account,
|
||||
passWord: values.password,
|
||||
});
|
||||
navigate("/", { replace: true });
|
||||
navigate("/admin/user", { replace: true });
|
||||
};
|
||||
const onFinishFailed = () => {};
|
||||
const loginForm = [
|
||||
{
|
||||
type: "input",
|
||||
label: "用户名",
|
||||
name: "username",
|
||||
name: "account",
|
||||
value: "",
|
||||
rules: [{ required: true, message: "请输入用户名!" }],
|
||||
},
|
||||
|
@ -42,7 +42,7 @@ const Login = (props) => {
|
|||
<SimpleForm
|
||||
formRef={formRef}
|
||||
formName="login_basic"
|
||||
colProps={4}
|
||||
colProps={16}
|
||||
formDatas={loginForm}
|
||||
onFinish={onFinish}
|
||||
initialValues={true}
|
||||
|
@ -54,7 +54,7 @@ const Login = (props) => {
|
|||
formRef.current?.submit();
|
||||
}}
|
||||
>
|
||||
Login
|
||||
登录
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
const MaterialMgmt = () => {
|
||||
return (
|
||||
<>
|
||||
<p>MaterialMgmt</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default MaterialMgmt;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
const PersMgmt = () => {
|
||||
return (
|
||||
<>
|
||||
<p>PersMgmt</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default PersMgmt;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
const PolRegulations = () => {
|
||||
return (
|
||||
<>
|
||||
<p>PolRegulations</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default PolRegulations;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
const PoliticalStudy = () => {
|
||||
return (
|
||||
<>
|
||||
<p>PoliticalStudy</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default PoliticalStudy;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
const TeamMgmt = () => {
|
||||
return (
|
||||
<>
|
||||
<p>TeamMgmt</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TeamMgmt;
|
||||
|
|
@ -164,7 +164,6 @@ const User = (props: Store) => {
|
|||
>
|
||||
添加用户
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
|
@ -173,66 +172,6 @@ const User = (props: Store) => {
|
|||
>
|
||||
标签管理
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/dep");
|
||||
}}
|
||||
>
|
||||
部门管理
|
||||
</Button>
|
||||
<Button type="default" onClick={() => {}}>
|
||||
部门管理
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/archives");
|
||||
}}
|
||||
>
|
||||
档案管理
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/archives");
|
||||
}}
|
||||
>
|
||||
仓库管理
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/dep");
|
||||
}}
|
||||
>
|
||||
请假审批
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/dep");
|
||||
}}
|
||||
>
|
||||
政治学习
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/dep");
|
||||
}}
|
||||
>
|
||||
政治法规管理
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/dep");
|
||||
}}
|
||||
>
|
||||
物资管理
|
||||
</Button>
|
||||
</Space>
|
||||
|
||||
<BTable store={usrStore} columns={columns} dataSource={usrStore.list} />
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
const WhseMgmt = () => {
|
||||
return (
|
||||
<>
|
||||
<p>WhseMgmt</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default WhseMgmt;
|
||||
|
|
@ -1,27 +1,17 @@
|
|||
import { createHashRouter } from "react-router-dom";
|
||||
import App from "@/App";
|
||||
import ErrorPage from "@/pages/errorPage";
|
||||
import Login from "@/pages/login/login";
|
||||
import { homeRouter } from "@/router/routers/home_router"
|
||||
import { homeRouter } from "@/router/routers/home_router";
|
||||
const routers = createHashRouter([
|
||||
{
|
||||
path: "/",
|
||||
element: <App />,
|
||||
children: [
|
||||
...homeRouter,
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
element: <Login />,
|
||||
},
|
||||
{
|
||||
path: "/404",
|
||||
element: <ErrorPage />,
|
||||
},
|
||||
...homeRouter
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
export { routers };
|
|
@ -1,38 +1,86 @@
|
|||
import LayOut from "@/components/layout/layout";
|
||||
import Archives from "@/pages/archives";
|
||||
import Dep from "@/pages/dep";
|
||||
import Home from "@/pages/home/home";
|
||||
import LeaveApproval from "@/pages/leaveApproval";
|
||||
import MaterialMgmt from "@/pages/materialMgmt";
|
||||
import PersMgmt from "@/pages/persMgmt";
|
||||
import PoliticalStudy from "@/pages/politicalStudy";
|
||||
import PolRegulations from "@/pages/polRegulations";
|
||||
import Tag from "@/pages/tag/tag";
|
||||
import TeamMgmt from "@/pages/teamMgmt";
|
||||
import User from "@/pages/user/user";
|
||||
import WhseMgmt from "@/pages/whseMgmt";
|
||||
export const homeRouter = [
|
||||
{
|
||||
path: "/",
|
||||
index: true,
|
||||
element: <Home />
|
||||
// element: <Navigate to="/dashbord" replace />
|
||||
element: <Home />,
|
||||
},
|
||||
{
|
||||
path: "/dashbord",
|
||||
index: false,
|
||||
element: <Home />
|
||||
element: <Home />,
|
||||
},
|
||||
{
|
||||
path: "/user",
|
||||
index: true,
|
||||
element: <User />
|
||||
},
|
||||
{
|
||||
path: "/tag",
|
||||
index: true,
|
||||
element: <Tag />
|
||||
},
|
||||
{
|
||||
path: "/dep",
|
||||
index: true,
|
||||
element: <Dep />
|
||||
},
|
||||
{
|
||||
path: "/archives",
|
||||
index: true,
|
||||
element: <Archives />
|
||||
path: "/admin",
|
||||
element: <LayOut />,
|
||||
children: [
|
||||
{
|
||||
path: "/admin/user",
|
||||
index: true,
|
||||
element: <User />,
|
||||
},
|
||||
{
|
||||
path: "/admin/tag",
|
||||
index: true,
|
||||
element: <Tag />,
|
||||
},
|
||||
{
|
||||
path: "/admin/dep",
|
||||
index: true,
|
||||
element: <Dep />,
|
||||
},
|
||||
{
|
||||
path: "/admin/archives",
|
||||
index: true,
|
||||
element: <Archives />,
|
||||
},
|
||||
{
|
||||
path: "/admin/leaveApproval",
|
||||
index: true,
|
||||
element: <LeaveApproval />,
|
||||
},
|
||||
{
|
||||
path: "/admin/materialMgmt",
|
||||
index: true,
|
||||
element: <MaterialMgmt />,
|
||||
},
|
||||
{
|
||||
path: "/admin/persMgmt",
|
||||
index: true,
|
||||
element: <PersMgmt />,
|
||||
},
|
||||
{
|
||||
path: "/admin/politicalStudy",
|
||||
index: true,
|
||||
element: <PoliticalStudy />,
|
||||
},
|
||||
{
|
||||
path: "/admin/polRegulations",
|
||||
index: true,
|
||||
element: <PolRegulations />,
|
||||
},
|
||||
{
|
||||
path: "/admin/teamMgmt",
|
||||
index: true,
|
||||
element: <TeamMgmt />,
|
||||
},
|
||||
{
|
||||
path: "/admin/whseMgmt",
|
||||
index: true,
|
||||
element: <WhseMgmt />,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
|
@ -1,11 +1,11 @@
|
|||
import store from "@/store";
|
||||
import Config from "@/util/config";
|
||||
import axios, { AxiosResponse } from "axios";
|
||||
// 添加请求拦截器
|
||||
// axios.defaults.headers.common["CommonType"] = "shouka";
|
||||
axios.defaults.headers.common["Content-Type"] = "application/json; charset=utf8";
|
||||
axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
|
||||
axios.interceptors.request.use((config) => {
|
||||
config.baseURL = "http://127.0.0.1:12214/v1/";
|
||||
config.baseURL = `${Config.baseUrl}v1/`;
|
||||
config.timeout = 5000;
|
||||
let token = window.localStorage.getItem("token")
|
||||
config.headers.Authorization = token ?? "1"
|
||||
|
@ -18,6 +18,7 @@ axios.interceptors.request.use((config) => {
|
|||
// 添加响应拦截器
|
||||
axios.interceptors.response.use((res: AxiosResponse) => {
|
||||
if (res.data.status === 401) {
|
||||
console.log("res.data.status",res.data.status);
|
||||
store.usrStore.openLoginDilog()
|
||||
store.usrStore.logOut()
|
||||
}
|
||||
|
|
|
@ -15,5 +15,5 @@ class ArchivesStore extends BaseStore<TagDataType> {
|
|||
makeObservable(this, {})
|
||||
}
|
||||
}
|
||||
const archivesStore = new ArchivesStore()
|
||||
export default archivesStore;
|
||||
export const archivesStore = new ArchivesStore()
|
||||
|
||||
|
|
|
@ -16,5 +16,5 @@ class ArchivesCategoryStore extends BaseStore<TagDataType> {
|
|||
makeObservable(this, {})
|
||||
}
|
||||
}
|
||||
const acStore = new ArchivesCategoryStore()
|
||||
export default acStore;
|
||||
export const acStore = new ArchivesCategoryStore()
|
||||
|
||||
|
|
|
@ -16,6 +16,5 @@ class DepStore extends BaseStore<TagDataType> {
|
|||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/no-anonymous-default-export
|
||||
export default new DepStore();
|
||||
export const depStore = new DepStore();
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import usrStore from '@/store/user'
|
||||
import tagStore from '@/store/tag'
|
||||
import depStore from '@/store/dep'
|
||||
import archivesStore from '@/store/archives'
|
||||
import { depStore } from '@/store/dep'
|
||||
import { archivesStore } from '@/store/archives'
|
||||
import folderStore from '@/store/folder';
|
||||
import acStore from '@/store/archives_category';
|
||||
import { acStore } from '@/store/archives_category';
|
||||
|
||||
const store = {
|
||||
usrStore,
|
||||
|
|
|
@ -16,6 +16,6 @@ class TagStore extends BaseStore<TagDataType> {
|
|||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/no-anonymous-default-export
|
||||
export default new TagStore();
|
||||
export const tagStore = new TagStore();
|
||||
export default tagStore;
|
||||
|
|
@ -43,9 +43,14 @@ class UserStore extends BaseStore<UserDataType> {
|
|||
password: params.passWord,
|
||||
genre: 1
|
||||
}
|
||||
let data =await baseHttp.post(UserConfig.LOGINURI, param)
|
||||
window.localStorage.setItem("token", data.data.token ?? "");
|
||||
this.closeLoginDilog()
|
||||
try {
|
||||
let data = await baseHttp.post(UserConfig.LOGINURI, param)
|
||||
window.localStorage.setItem("token", data.data.token ?? "");
|
||||
return true
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
openLoginDilog() {
|
||||
this.isNeedLogin = true;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class Config {
|
||||
static baseUrl = "http://127.0.0.1:12214/";
|
||||
static uploadUrl = "http://127.0.0.1:12214/";
|
||||
}
|
||||
export default Config;
|
Loading…
Reference in New Issue