系统全局存储部门和分类

This commit is contained in:
unknown 2023-09-22 14:50:54 +08:00
parent 36ab0200a0
commit c1adb96a0a
6 changed files with 47 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import { Tree } from "antd"; import { Tree } from "antd";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { resourceCategory } from "../../api/index"; import { useSelector } from "react-redux";
interface Option { interface Option {
key: string | number; key: string | number;
@ -19,6 +19,9 @@ export const TreeCategory = (props: PropInterface) => {
const [treeData, setTreeData] = useState<any>([]); const [treeData, setTreeData] = useState<any>([]);
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
const [selectKey, setSelectKey] = useState<number[]>([]); const [selectKey, setSelectKey] = useState<number[]>([]);
const resourceCategories = useSelector(
(state: any) => state.systemConfig.value.resourceCategories
);
useEffect(() => { useEffect(() => {
if (props.selected && props.selected.length > 0) { if (props.selected && props.selected.length > 0) {
@ -27,21 +30,17 @@ export const TreeCategory = (props: PropInterface) => {
}, [props.selected]); }, [props.selected]);
useEffect(() => { useEffect(() => {
resourceCategory.resourceCategoryList().then((res: any) => { if (JSON.stringify(resourceCategories) !== "{}") {
const categories: CategoriesBoxModel = res.data.categories; const new_arr: Option[] = checkArr(resourceCategories, 0);
if (JSON.stringify(categories) !== "{}") { if (props.type === "no-cate") {
const new_arr: Option[] = checkArr(categories, 0); new_arr.unshift({
if (props.type === "no-cate") { key: 0,
new_arr.unshift({ title: <span className="tree-title-elli"></span>,
key: 0, });
title: <span className="tree-title-elli"></span>,
});
}
setTreeData(new_arr);
} }
}); setTreeData(new_arr);
}, []); }
}, [resourceCategories]);
const checkArr = (categories: CategoriesBoxModel, id: number) => { const checkArr = (categories: CategoriesBoxModel, id: number) => {
const arr = []; const arr = [];

View File

@ -1,6 +1,7 @@
import { Button, Input, message, Tree } from "antd"; import { Button, Input, message, Tree } from "antd";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { department } from "../../api/index"; import { department } from "../../api/index";
import { useSelector } from "react-redux";
interface Option { interface Option {
key: string | number; key: string | number;
@ -22,6 +23,9 @@ export const TreeDepartment = (props: PropInterface) => {
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
const [selectKey, setSelectKey] = useState<number[]>([]); const [selectKey, setSelectKey] = useState<number[]>([]);
const [userTotal, setUserTotal] = useState(0); const [userTotal, setUserTotal] = useState(0);
const localDepartments = useSelector(
(state: any) => state.systemConfig.value.departments
);
useEffect(() => { useEffect(() => {
if (props.selected && props.selected.length > 0) { if (props.selected && props.selected.length > 0) {
@ -31,18 +35,30 @@ export const TreeDepartment = (props: PropInterface) => {
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
department.departmentList().then((res: any) => { if (props.showNum) {
const departments: DepartmentsBoxModel = res.data.departments; department.departmentList().then((res: any) => {
const departCount: DepIdsModel = res.data.dep_user_count; const departments: DepartmentsBoxModel = res.data.departments;
setUserTotal(res.data.user_total); const departCount: DepIdsModel = res.data.dep_user_count;
if (JSON.stringify(departments) !== "{}") { setUserTotal(res.data.user_total);
if (props.showNum) { if (JSON.stringify(departments) !== "{}") {
const new_arr: any[] = checkNewArr(departments, 0, departCount); const new_arr: any[] = checkNewArr(departments, 0, departCount);
setTreeData(new_arr); setTreeData(new_arr);
} else { } else {
const new_arr: any[] = checkArr(departments, 0); const new_arr: Option[] = [
{
key: "",
title: "全部",
children: [],
},
];
setTreeData(new_arr); setTreeData(new_arr);
} }
setLoading(false);
});
} else {
if (JSON.stringify(localDepartments) !== "{}") {
const new_arr: any[] = checkArr(localDepartments, 0);
setTreeData(new_arr);
} else { } else {
const new_arr: Option[] = [ const new_arr: Option[] = [
{ {
@ -54,8 +70,8 @@ export const TreeDepartment = (props: PropInterface) => {
setTreeData(new_arr); setTreeData(new_arr);
} }
setLoading(false); setLoading(false);
}); }
}, [props.refresh]); }, [props.refresh, localDepartments]);
const checkNewArr = ( const checkNewArr = (
departments: DepartmentsBoxModel, departments: DepartmentsBoxModel,

View File

@ -27,6 +27,8 @@ const InitPage = (props: Props) => {
systemH5Url: props.configData["system.h5_url"], systemH5Url: props.configData["system.h5_url"],
memberDefaultAvatar: props.configData["member.default_avatar"], memberDefaultAvatar: props.configData["member.default_avatar"],
courseDefaultThumbs: props.configData["default.course_thumbs"], courseDefaultThumbs: props.configData["default.course_thumbs"],
departments: props.configData["departments"],
resourceCategories: props.configData["resource_categories"],
}; };
dispatch(saveConfigAction(config)); dispatch(saveConfigAction(config));
} }

View File

@ -67,6 +67,8 @@ const LoginPage = () => {
systemH5Url: res.data["system.h5_url"], systemH5Url: res.data["system.h5_url"],
memberDefaultAvatar: res.data["member.default_avatar"], memberDefaultAvatar: res.data["member.default_avatar"],
courseDefaultThumbs: res.data["default.course_thumbs"], courseDefaultThumbs: res.data["default.course_thumbs"],
departments: res.data["departments"],
resourceCategories: res.data["resource_categories"],
}; };
dispatch(saveConfigAction(data)); dispatch(saveConfigAction(data));
}; };

View File

@ -259,6 +259,8 @@ const SystemConfigPage = () => {
systemH5Url: res.data["system.h5_url"], systemH5Url: res.data["system.h5_url"],
memberDefaultAvatar: res.data["member.default_avatar"], memberDefaultAvatar: res.data["member.default_avatar"],
courseDefaultThumbs: res.data["default.course_thumbs"], courseDefaultThumbs: res.data["default.course_thumbs"],
departments: res.data["departments"],
resourceCategories: res.data["resource_categories"],
}; };
dispatch(saveConfigAction(data)); dispatch(saveConfigAction(data));
}); });

View File

@ -9,6 +9,8 @@ type SystemConfigStoreInterface = {
systemName?: string; systemName?: string;
memberDefaultAvatar?: string; memberDefaultAvatar?: string;
courseDefaultThumbs?: string[]; courseDefaultThumbs?: string[];
departments: any;
resourceCategories: any;
}; };
const systemConfigSlice = createSlice({ const systemConfigSlice = createSlice({