fix(api):update store
This commit is contained in:
parent
602e2e4ab9
commit
3e877a15b5
File diff suppressed because it is too large
Load Diff
|
@ -17,7 +17,7 @@
|
|||
"@types/react": "^18.0.21",
|
||||
"@types/react-dom": "^18.0.6",
|
||||
"ali-oss": "^6.18.1",
|
||||
"antd": "^4.23.6",
|
||||
"antd": "^5.20.6",
|
||||
"axios": "^1.2.1",
|
||||
"babel-jest": "^27.4.2",
|
||||
"babel-loader": "^8.2.3",
|
||||
|
|
39
src/App.tsx
39
src/App.tsx
|
@ -1,11 +1,37 @@
|
|||
import { inject, observer } from "mobx-react";
|
||||
import "antd/dist/antd.css";
|
||||
// import Home from "./pages/home/home";
|
||||
import { Modal } from "antd";
|
||||
import { Store } from "antd/lib/form/interface";
|
||||
import { Outlet } from "react-router";
|
||||
import SimpleForm from "./components/form/simple_form";
|
||||
import { FormInstance } from "antd/lib/form";
|
||||
import React from "react";
|
||||
const App = (props: Store) => {
|
||||
const { usrStore } = props;
|
||||
const formRef = React.useRef<FormInstance>(null);
|
||||
const loginForm = [
|
||||
{
|
||||
type: "input",
|
||||
label: "用户名",
|
||||
name: "account",
|
||||
value: "",
|
||||
rules: [{ required: true, message: "请输入用户名!" }],
|
||||
},
|
||||
{
|
||||
type: "password",
|
||||
label: "密码",
|
||||
name: "password",
|
||||
value: "",
|
||||
rules: [{ required: true, message: "请输入密码!" }],
|
||||
},
|
||||
];
|
||||
const onFinish = (values: any) => {
|
||||
usrStore.login({
|
||||
userName: values.account,
|
||||
passWord: values.password,
|
||||
});
|
||||
};
|
||||
const onFinishFailed = () => {};
|
||||
return (
|
||||
<>
|
||||
<Outlet />
|
||||
|
@ -16,13 +42,20 @@ const App = (props: Store) => {
|
|||
open={usrStore.isNeedLogin}
|
||||
afterClose={() => {}}
|
||||
onOk={() => {
|
||||
usrStore.closeLoginDilog();
|
||||
formRef.current?.submit();
|
||||
}}
|
||||
onCancel={() => {
|
||||
usrStore.closeLoginDilog();
|
||||
}}
|
||||
>
|
||||
<p>cascsa</p>
|
||||
<SimpleForm
|
||||
formRef={formRef}
|
||||
formName="login_basic"
|
||||
colProps={4}
|
||||
formDatas={loginForm}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import React from "react";
|
||||
|
||||
interface MyComponentProps {
|
||||
hasError?: boolean;
|
||||
chi?: React.ReactNode;
|
||||
}
|
||||
|
||||
interface MyComponentState {
|
||||
hasError: boolean;
|
||||
}
|
||||
|
||||
class MyComponent extends React.Component<MyComponentProps, MyComponentState> {
|
||||
constructor(props: MyComponentProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
hasError: false, // 初始值
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
// 现在你可以安全地访问 this.state.hasError
|
||||
return <div>{this.state.hasError ? 'Error' : this.props.chi}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
export default MyComponent
|
|
@ -1,5 +1,6 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import AMapLoader from "@amap/amap-jsapi-loader";
|
||||
import MapUtl from "./mapUtil";
|
||||
|
||||
export default function MapContainer() {
|
||||
let [amap, setmaps] = useState<any>(null);
|
||||
|
@ -8,6 +9,7 @@ export default function MapContainer() {
|
|||
return () => {
|
||||
amap?.destroy();
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const loadMaps = async () => {
|
||||
|
@ -22,6 +24,7 @@ export default function MapContainer() {
|
|||
center: [103.55, 30.34], // 初始化地图中心点位置
|
||||
mapStyle: "amap://styles/darkblue",
|
||||
});
|
||||
|
||||
setmaps(amap);
|
||||
addMaket(Amap);
|
||||
};
|
||||
|
@ -32,6 +35,8 @@ export default function MapContainer() {
|
|||
});
|
||||
//将创建的点标记添加到已有的地图实例:
|
||||
amap.add(marker);
|
||||
MapUtl.makerList.push(marker)
|
||||
MapUtl.amap = m;
|
||||
};
|
||||
|
||||
return <div id="container" style={{ height: "100vh" }}></div>;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class MapUtl {
|
||||
static makerList: any[] = [];
|
||||
static amap:any = null;
|
||||
}
|
||||
|
||||
export default MapUtl;
|
|
@ -0,0 +1,102 @@
|
|||
import { Button, Space, Modal, FormInstance, Flex } from "antd";
|
||||
import { inject, observer } from "mobx-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Store } from "antd/lib/form/interface";
|
||||
import SimpleForm from "@/components/form/simple_form";
|
||||
import React from "react";
|
||||
import FolderTwoTone from "@ant-design/icons/FolderOpenTwoTone";
|
||||
|
||||
const Archives = (props: Store) => {
|
||||
const { archivesStore } = props;
|
||||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
||||
const [projectConfig, setProjectConfig] = useState<any>([]);
|
||||
const formRef = React.useRef<FormInstance>(null);
|
||||
const [tagId, setId] = useState<Number | null>(null);
|
||||
|
||||
const onFinish = (values: any) => {
|
||||
let data = values;
|
||||
data.head_img = values.head_img[0].url;
|
||||
if (!tagId) {
|
||||
archivesStore.add(data);
|
||||
} else {
|
||||
archivesStore.putItem(tagId, data);
|
||||
}
|
||||
setIsModalOpen(false);
|
||||
};
|
||||
useEffect(() => {
|
||||
archivesStore.getlist("folder/list");
|
||||
}, [archivesStore]);
|
||||
const defaultConfig = [
|
||||
{
|
||||
type: "input",
|
||||
label: "所属档案分类",
|
||||
name: "ac_identity",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
label: "文件夹名称",
|
||||
name: "folder_name",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
type: "input",
|
||||
label: "文件夹描述",
|
||||
name: "folder_desc",
|
||||
value: "",
|
||||
},
|
||||
];
|
||||
const onFinishFailed = () => {};
|
||||
return (
|
||||
<div className="contentBox">
|
||||
<Space direction="vertical" size="middle" style={{ display: "flex" }}>
|
||||
<Space direction="horizontal" size={"middle"}>
|
||||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
setProjectConfig(defaultConfig);
|
||||
setId(null);
|
||||
setIsModalOpen(true);
|
||||
}}
|
||||
>
|
||||
添加
|
||||
</Button>
|
||||
</Space>
|
||||
<Flex wrap gap="25px" justify="start">
|
||||
{Array.from({ length: archivesStore.list?.length??0 }, (_, i) => (
|
||||
<div key={i}>
|
||||
<FolderTwoTone rotate={-270} style={{ fontSize: "120px" }} />
|
||||
<p>{archivesStore.list[i].folder_name}</p>
|
||||
</div>
|
||||
))}
|
||||
</Flex>
|
||||
|
||||
<Modal
|
||||
title={!tagId ? "添加文件夹" : "编辑文件夹"}
|
||||
width={800}
|
||||
open={isModalOpen}
|
||||
afterClose={() => formRef.current?.resetFields()}
|
||||
onOk={() => formRef.current?.submit()}
|
||||
onCancel={() => {
|
||||
setId(null);
|
||||
setIsModalOpen(false);
|
||||
}}
|
||||
>
|
||||
<SimpleForm
|
||||
formRef={formRef}
|
||||
createCallback={() => {}}
|
||||
formName="card_basic"
|
||||
colProps={4}
|
||||
subBtnName="提交"
|
||||
formDatas={projectConfig}
|
||||
onFinish={onFinish}
|
||||
initialValues={true}
|
||||
onFinishFailed={onFinishFailed}
|
||||
/>
|
||||
</Modal>
|
||||
</Space>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default inject("archivesStore")(observer(Archives));
|
|
@ -2,14 +2,23 @@ import { useState } from "react";
|
|||
import { Modal } from "antd";
|
||||
import "./left.less";
|
||||
import { useNavigate } from "react-router";
|
||||
import MapUtl from "@/components/map/mapUtil";
|
||||
const HomeLeft = () => {
|
||||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
||||
const navigate = useNavigate();
|
||||
const openDispatch = () => {
|
||||
setIsModalOpen(true);
|
||||
// 位置移动
|
||||
MapUtl.makerList[0].setPosition([103.55, 30.342]);
|
||||
var m = MapUtl.amap;
|
||||
var newIcon = new m.Icon({
|
||||
image: "//a.amap.com/jsapi_demos/static/demo-center/icons/dir-marker.png", //Icon 的图像
|
||||
size: new m.Size(25, 34), // 图标大小
|
||||
anchor: new m.Pixel(12, 32), // 图标锚点
|
||||
});
|
||||
MapUtl.makerList[0].setIcon(newIcon);
|
||||
};
|
||||
const jumpToUser = () => {
|
||||
navigate("/user")
|
||||
navigate("/user");
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -188,7 +188,7 @@ const User = (props: Store) => {
|
|||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/dep");
|
||||
nav("/archives");
|
||||
}}
|
||||
>
|
||||
档案管理
|
||||
|
@ -196,7 +196,7 @@ const User = (props: Store) => {
|
|||
<Button
|
||||
type="default"
|
||||
onClick={() => {
|
||||
nav("/dep");
|
||||
nav("/archives");
|
||||
}}
|
||||
>
|
||||
仓库管理
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import Archives from "@/pages/archives";
|
||||
import Dep from "@/pages/dep";
|
||||
import Home from "@/pages/home/home";
|
||||
import Tag from "@/pages/tag/tag";
|
||||
|
@ -29,4 +30,9 @@ export const homeRouter = [
|
|||
index: true,
|
||||
element: <Dep />
|
||||
},
|
||||
{
|
||||
path: "/archives",
|
||||
index: true,
|
||||
element: <Archives />
|
||||
},
|
||||
];
|
|
@ -1,5 +1,5 @@
|
|||
class UserConfig {
|
||||
static LOGINURI: string = "login"
|
||||
static LOGINURI: string = "anth/login"
|
||||
static LIST: string = "userMgmt/user/list"
|
||||
static ADD: string = "user"
|
||||
static DELETE: string = "user"
|
||||
|
|
|
@ -3,12 +3,12 @@ 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.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
|
||||
axios.interceptors.request.use((config) => {
|
||||
config.baseURL = "http://127.0.0.1:12214/v1/";
|
||||
config.timeout = 5000;
|
||||
let token = window.localStorage.getItem("token")
|
||||
config.headers.Authorization = token
|
||||
config.headers.Authorization = token ?? "1"
|
||||
return config;
|
||||
}, (error) => {
|
||||
// 对请求错误做些什么
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import { makeObservable } from "mobx";
|
||||
// 用户信息
|
||||
import BaseStore from "./baseStore";
|
||||
import { TagDataType } from "@/model/userModel";
|
||||
|
||||
class ArchivesConfig {
|
||||
static LIST: string = "archives/folder/list"
|
||||
static ADD: string = "archives"
|
||||
static DELETE: string = "archives"
|
||||
static EDIT: string = "archives"
|
||||
}
|
||||
class ArchivesStore extends BaseStore<TagDataType> {
|
||||
constructor() {
|
||||
super(ArchivesConfig)
|
||||
makeObservable(this, {})
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/no-anonymous-default-export
|
||||
export default new ArchivesStore();
|
||||
|
|
@ -69,20 +69,16 @@ class BaseStore<B> implements BaseStoreInterface<B> {
|
|||
this.listStatus = false;
|
||||
return;
|
||||
}
|
||||
console.log(res.data.record);
|
||||
for (let i = 0; i < res.data.record.length; i++) {
|
||||
data.push({
|
||||
key: res.data.record[i].id,
|
||||
...res.data.record[i]
|
||||
})
|
||||
}
|
||||
console.log(data);
|
||||
|
||||
runInAction(() => {
|
||||
this.list = data;
|
||||
this.total = res.data.count
|
||||
})
|
||||
console.log(this.list);
|
||||
this.listStatus = false;
|
||||
}
|
||||
list!: Array<B>;
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import usrStore from '@/store/user'
|
||||
import tagStore from '@/store/tag'
|
||||
import depStore from '@/store/dep'
|
||||
import archivesStore from '@/store/archives'
|
||||
|
||||
const store = {
|
||||
usrStore,
|
||||
tagStore,
|
||||
depStore
|
||||
depStore,
|
||||
archivesStore
|
||||
};
|
||||
|
||||
export default store;
|
|
@ -33,19 +33,14 @@ class UserStore extends BaseStore<UserDataType> {
|
|||
this.item = "";
|
||||
}
|
||||
async login(params: UserInfos) {
|
||||
let data = await baseHttp.post(UserConfig.LOGINURI, {
|
||||
acount: params.userName,
|
||||
passwd: params.passWord,
|
||||
loginType:5
|
||||
})
|
||||
this._userinfo = {
|
||||
userName: data.data.name,
|
||||
token: data.data.token,
|
||||
headerImag: data.data.headerImag,
|
||||
role: "",
|
||||
passWord: data.data.password,
|
||||
};
|
||||
let param = {
|
||||
account: params.userName,
|
||||
password: params.passWord,
|
||||
genre: 1
|
||||
}
|
||||
let data =await baseHttp.post(UserConfig.LOGINURI, param)
|
||||
window.localStorage.setItem("token", data.data.token ?? "");
|
||||
this.closeLoginDilog()
|
||||
}
|
||||
openLoginDilog() {
|
||||
this.isNeedLogin = true;
|
||||
|
|
Loading…
Reference in New Issue