Commit 45239ce4 authored by chenshouchao's avatar chenshouchao

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

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