mirror of
https://github.com/PlayEdu/backend
synced 2025-06-08 01:04:30 +08:00
系统全局存储部门和分类
This commit is contained in:
parent
36ab0200a0
commit
c1adb96a0a
@ -1,6 +1,6 @@
|
||||
import { Tree } from "antd";
|
||||
import { useState, useEffect } from "react";
|
||||
import { resourceCategory } from "../../api/index";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
interface Option {
|
||||
key: string | number;
|
||||
@ -19,6 +19,9 @@ export const TreeCategory = (props: PropInterface) => {
|
||||
const [treeData, setTreeData] = useState<any>([]);
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [selectKey, setSelectKey] = useState<number[]>([]);
|
||||
const resourceCategories = useSelector(
|
||||
(state: any) => state.systemConfig.value.resourceCategories
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.selected && props.selected.length > 0) {
|
||||
@ -27,21 +30,17 @@ export const TreeCategory = (props: PropInterface) => {
|
||||
}, [props.selected]);
|
||||
|
||||
useEffect(() => {
|
||||
resourceCategory.resourceCategoryList().then((res: any) => {
|
||||
const categories: CategoriesBoxModel = res.data.categories;
|
||||
if (JSON.stringify(categories) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(categories, 0);
|
||||
if (props.type === "no-cate") {
|
||||
new_arr.unshift({
|
||||
key: 0,
|
||||
title: <span className="tree-title-elli">未分类</span>,
|
||||
});
|
||||
}
|
||||
|
||||
setTreeData(new_arr);
|
||||
if (JSON.stringify(resourceCategories) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(resourceCategories, 0);
|
||||
if (props.type === "no-cate") {
|
||||
new_arr.unshift({
|
||||
key: 0,
|
||||
title: <span className="tree-title-elli">未分类</span>,
|
||||
});
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
setTreeData(new_arr);
|
||||
}
|
||||
}, [resourceCategories]);
|
||||
|
||||
const checkArr = (categories: CategoriesBoxModel, id: number) => {
|
||||
const arr = [];
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Button, Input, message, Tree } from "antd";
|
||||
import { useState, useEffect } from "react";
|
||||
import { department } from "../../api/index";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
interface Option {
|
||||
key: string | number;
|
||||
@ -22,6 +23,9 @@ export const TreeDepartment = (props: PropInterface) => {
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [selectKey, setSelectKey] = useState<number[]>([]);
|
||||
const [userTotal, setUserTotal] = useState(0);
|
||||
const localDepartments = useSelector(
|
||||
(state: any) => state.systemConfig.value.departments
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.selected && props.selected.length > 0) {
|
||||
@ -31,18 +35,30 @@ export const TreeDepartment = (props: PropInterface) => {
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments: DepartmentsBoxModel = res.data.departments;
|
||||
const departCount: DepIdsModel = res.data.dep_user_count;
|
||||
setUserTotal(res.data.user_total);
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
if (props.showNum) {
|
||||
if (props.showNum) {
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments: DepartmentsBoxModel = res.data.departments;
|
||||
const departCount: DepIdsModel = res.data.dep_user_count;
|
||||
setUserTotal(res.data.user_total);
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
const new_arr: any[] = checkNewArr(departments, 0, departCount);
|
||||
setTreeData(new_arr);
|
||||
} else {
|
||||
const new_arr: any[] = checkArr(departments, 0);
|
||||
const new_arr: Option[] = [
|
||||
{
|
||||
key: "",
|
||||
title: "全部",
|
||||
children: [],
|
||||
},
|
||||
];
|
||||
setTreeData(new_arr);
|
||||
}
|
||||
setLoading(false);
|
||||
});
|
||||
} else {
|
||||
if (JSON.stringify(localDepartments) !== "{}") {
|
||||
const new_arr: any[] = checkArr(localDepartments, 0);
|
||||
setTreeData(new_arr);
|
||||
} else {
|
||||
const new_arr: Option[] = [
|
||||
{
|
||||
@ -54,8 +70,8 @@ export const TreeDepartment = (props: PropInterface) => {
|
||||
setTreeData(new_arr);
|
||||
}
|
||||
setLoading(false);
|
||||
});
|
||||
}, [props.refresh]);
|
||||
}
|
||||
}, [props.refresh, localDepartments]);
|
||||
|
||||
const checkNewArr = (
|
||||
departments: DepartmentsBoxModel,
|
||||
|
@ -27,6 +27,8 @@ const InitPage = (props: Props) => {
|
||||
systemH5Url: props.configData["system.h5_url"],
|
||||
memberDefaultAvatar: props.configData["member.default_avatar"],
|
||||
courseDefaultThumbs: props.configData["default.course_thumbs"],
|
||||
departments: props.configData["departments"],
|
||||
resourceCategories: props.configData["resource_categories"],
|
||||
};
|
||||
dispatch(saveConfigAction(config));
|
||||
}
|
||||
|
@ -67,6 +67,8 @@ const LoginPage = () => {
|
||||
systemH5Url: res.data["system.h5_url"],
|
||||
memberDefaultAvatar: res.data["member.default_avatar"],
|
||||
courseDefaultThumbs: res.data["default.course_thumbs"],
|
||||
departments: res.data["departments"],
|
||||
resourceCategories: res.data["resource_categories"],
|
||||
};
|
||||
dispatch(saveConfigAction(data));
|
||||
};
|
||||
|
@ -259,6 +259,8 @@ const SystemConfigPage = () => {
|
||||
systemH5Url: res.data["system.h5_url"],
|
||||
memberDefaultAvatar: res.data["member.default_avatar"],
|
||||
courseDefaultThumbs: res.data["default.course_thumbs"],
|
||||
departments: res.data["departments"],
|
||||
resourceCategories: res.data["resource_categories"],
|
||||
};
|
||||
dispatch(saveConfigAction(data));
|
||||
});
|
||||
|
@ -9,6 +9,8 @@ type SystemConfigStoreInterface = {
|
||||
systemName?: string;
|
||||
memberDefaultAvatar?: string;
|
||||
courseDefaultThumbs?: string[];
|
||||
departments: any;
|
||||
resourceCategories: any;
|
||||
};
|
||||
|
||||
const systemConfigSlice = createSlice({
|
||||
|
Loading…
x
Reference in New Issue
Block a user