Commit 45239ce4 authored by chenshouchao's avatar chenshouchao

feat: 选中的产品和项目用sessionstorage做持久化

parent 6557c960
......@@ -11,22 +11,39 @@ type productInfo = {
id?: string;
name?: string;
};
const sessionStorageCurrentProjectInfo = JSON.parse(
sessionStorage.getItem("currentProjectInfo") || "{}"
);
const sessionStorageCurrentProductInfo = JSON.parse(
sessionStorage.getItem("currentProductInfo") || "{}"
);
const sessionStorageProjectList = JSON.parse(
sessionStorage.getItem("projectList") || "[]"
);
class currentProject {
constructor() {
makeAutoObservable(this);
}
// 选中的项目
currentProjectInfo: projectInfo = {};
currentProjectInfo: projectInfo = sessionStorageCurrentProjectInfo;
// 选中的产品下的项目列表
projectList: Array<projectInfo> = [];
projectList: Array<projectInfo> = sessionStorageProjectList;
// 选中的产品
currentProductInfo: productInfo = {};
currentProductInfo: productInfo = sessionStorageCurrentProductInfo;
setProjectList = (list: Array<projectInfo>) => {
this.projectList = list;
sessionStorage.setItem("projectList", JSON.stringify(list));
};
changeProject = (project: projectInfo) => {
this.currentProjectInfo = project;
sessionStorage.setItem("currentProjectInfo", JSON.stringify(project));
};
changeProductInfo = (productInfo: productInfo) => {
this.currentProductInfo = productInfo;
sessionStorage.setItem("currentProductInfo", JSON.stringify(productInfo));
};
}
......
......@@ -61,6 +61,7 @@ const ConsoleLayout = observer(() => {
// 切换产品
const getProduct = (item: any) => {
currentProjectStore.changeProductInfo({ id: item.name, name: item.name });
setCurrentProduct(item);
runGetProjectList({
product: item.name,
......
......@@ -84,17 +84,16 @@ const AddProject = (props: any) => {
const handleClickOpen = () => {
DialogRef.current.handleClickOpen();
initData()
initData();
};
const initData = () => {
setName('')
setDesc('')
setName("");
setDesc("");
if (zoneIdOptions.length > 0) {
setZoneId(zoneIdOptions[0].id)
setZoneId(zoneIdOptions[0].id);
}
}
};
const checkName = (name: string) => {
if (name) {
......
......@@ -45,7 +45,6 @@ const CurrentProject = observer(() => {
const openAddProject = () => {
addProjectRef.current.handleClickOpen();
// setAddProjectOpen(true);
setProjectListOpen(false);
};
......
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