From 3459016134ec633979f4fbbda12b7f6668d88885 Mon Sep 17 00:00:00 2001 From: unknown <18119604035@163.com> Date: Fri, 22 Sep 2023 16:19:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E3=80=81=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=AD=98=E5=82=A8=E5=85=A8=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/department/index.tsx | 5 ++++- src/pages/resource/resource-category/index.tsx | 5 ++++- src/store/system/systemConfigSlice.ts | 17 +++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pages/department/index.tsx b/src/pages/department/index.tsx index c6aba78..43b8427 100644 --- a/src/pages/department/index.tsx +++ b/src/pages/department/index.tsx @@ -8,7 +8,8 @@ import type { DataNode, TreeProps } from "antd/es/tree"; import { DepartmentCreate } from "./compenents/create"; import { DepartmentUpdate } from "./compenents/update"; import { useNavigate } from "react-router-dom"; -import { useSelector } from "react-redux"; +import { useSelector, useDispatch } from "react-redux"; +import { saveDepartmentsAction } from "../../store/system/systemConfigSlice"; const { confirm } = Modal; @@ -19,6 +20,7 @@ interface Option { } const DepartmentPage = () => { + const dispatch = useDispatch(); const navigate = useNavigate(); const permissions = useSelector( (state: any) => state.loginUser.value.permissions @@ -57,6 +59,7 @@ const DepartmentPage = () => { const getData = () => { department.departmentList().then((res: any) => { const departments: DepartmentsBoxModel = res.data.departments; + dispatch(saveDepartmentsAction(res.data.departments)); if (JSON.stringify(departments) !== "{}") { const new_arr: Option[] = checkArr(departments, 0); setTreeData(new_arr); diff --git a/src/pages/resource/resource-category/index.tsx b/src/pages/resource/resource-category/index.tsx index 23991af..3ebc17d 100644 --- a/src/pages/resource/resource-category/index.tsx +++ b/src/pages/resource/resource-category/index.tsx @@ -8,7 +8,8 @@ import type { DataNode, TreeProps } from "antd/es/tree"; import { ResourceCategoryCreate } from "./compenents/create"; import { ResourceCategoryUpdate } from "./compenents/update"; import { useNavigate } from "react-router-dom"; -import { useSelector } from "react-redux"; +import { useSelector, useDispatch } from "react-redux"; +import { saveCategoriesAction } from "../../../store/system/systemConfigSlice"; const { confirm } = Modal; @@ -19,6 +20,7 @@ interface Option { } const ResourceCategoryPage = () => { + const dispatch = useDispatch(); const navigate = useNavigate(); const permissions = useSelector( (state: any) => state.loginUser.value.permissions @@ -53,6 +55,7 @@ const ResourceCategoryPage = () => { setLoading(true); resourceCategory.resourceCategoryList().then((res: any) => { const categories: CategoriesBoxModel = res.data.categories; + dispatch(saveCategoriesAction(res.data.categories)); if (JSON.stringify(categories) !== "{}") { const new_arr: Option[] = checkArr(categories, 0); setTreeData(new_arr); diff --git a/src/store/system/systemConfigSlice.ts b/src/store/system/systemConfigSlice.ts index ce4facb..6f187b8 100644 --- a/src/store/system/systemConfigSlice.ts +++ b/src/store/system/systemConfigSlice.ts @@ -9,23 +9,32 @@ type SystemConfigStoreInterface = { systemName?: string; memberDefaultAvatar?: string; courseDefaultThumbs?: string[]; - departments: any; - resourceCategories: any; + departments?: any; + resourceCategories?: any; }; +let defaultValue: SystemConfigStoreInterface = {}; + const systemConfigSlice = createSlice({ name: "systemConfig", initialState: { - value: {}, + value: defaultValue, }, reducers: { saveConfigAction(stage, e) { stage.value = e.payload; }, + saveDepartmentsAction(stage, e) { + stage.value.departments = e.payload; + }, + saveCategoriesAction(stage, e) { + stage.value.resourceCategories = e.payload; + }, }, }); export default systemConfigSlice.reducer; -export const { saveConfigAction } = systemConfigSlice.actions; +export const { saveConfigAction, saveDepartmentsAction, saveCategoriesAction } = + systemConfigSlice.actions; export type { SystemConfigStoreInterface };