数据结构重构优化

This commit is contained in:
unknown 2023-08-07 10:15:51 +08:00
parent 8c52461558
commit 2348cfb54d
4 changed files with 29 additions and 11 deletions

View File

@ -11,12 +11,18 @@ interface PropsInterface {
onCancel: () => void;
}
type selAttachmentModel = {
name: string;
rid: number;
type: string;
};
export const SelectAttachment = (props: PropsInterface) => {
const [refresh, setRefresh] = useState(true);
const [tabKey, setTabKey] = useState(1);
const [selectKeys, setSelectKeys] = useState<any>([]);
const [selectVideos, setSelectVideos] = useState<any>([]);
const [selectKeys, setSelectKeys] = useState<number[]>([]);
const [selectVideos, setSelectVideos] = useState<selAttachmentModel[]>([]);
useEffect(() => {
setRefresh(!refresh);

View File

@ -11,11 +11,18 @@ interface PropsInterface {
onCancel: () => void;
}
type selVideosModel = {
name: string;
rid: number;
type: string;
duration: number;
};
export const SelectResource = (props: PropsInterface) => {
const [refresh, setRefresh] = useState(true);
const [tabKey, setTabKey] = useState(1);
const [selectKeys, setSelectKeys] = useState<any>([]);
const [selectVideos, setSelectVideos] = useState<any>([]);
const [selectKeys, setSelectKeys] = useState<number[]>([]);
const [selectVideos, setSelectVideos] = useState<selVideosModel[]>([]);
useEffect(() => {
setRefresh(!refresh);
@ -62,6 +69,7 @@ export const SelectResource = (props: PropsInterface) => {
maskClosable={false}
onOk={() => {
props.onSelected(selectKeys, selectVideos);
console.log(selectKeys, selectVideos);
setSelectKeys([]);
setSelectVideos([]);
}}

View File

@ -18,7 +18,7 @@ interface PropInterface {
export const TreeCategory = (props: PropInterface) => {
const [treeData, setTreeData] = useState<any>([]);
const [loading, setLoading] = useState<boolean>(true);
const [selectKey, setSelectKey] = useState<any>([]);
const [selectKey, setSelectKey] = useState<number[]>([]);
useEffect(() => {
if (props.selected && props.selected.length > 0) {
@ -28,7 +28,7 @@ export const TreeCategory = (props: PropInterface) => {
useEffect(() => {
resourceCategory.resourceCategoryList().then((res: any) => {
const categories = res.data.categories;
const categories: CategoriesBoxModel = res.data.categories;
if (JSON.stringify(categories) !== "{}") {
const new_arr: Option[] = checkArr(categories, 0);
if (props.type === "no-cate") {
@ -43,7 +43,7 @@ export const TreeCategory = (props: PropInterface) => {
});
}, []);
const checkArr = (categories: any[], id: number) => {
const checkArr = (categories: CategoriesBoxModel, id: number) => {
const arr = [];
for (let i = 0; i < categories[id].length; i++) {
if (!categories[categories[id][i].id]) {

View File

@ -32,8 +32,8 @@ export const TreeDepartment = (props: PropInterface) => {
useEffect(() => {
setLoading(true);
department.departmentList().then((res: any) => {
const departments = res.data.departments;
const departCount = res.data.dep_user_count;
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) {
@ -57,7 +57,11 @@ export const TreeDepartment = (props: PropInterface) => {
});
}, [props.refresh]);
const checkNewArr = (departments: any[], id: number, counts: any) => {
const checkNewArr = (
departments: DepartmentsBoxModel,
id: number,
counts: any
) => {
const arr = [];
for (let i = 0; i < departments[id].length; i++) {
if (!departments[departments[id][i].id]) {
@ -89,7 +93,7 @@ export const TreeDepartment = (props: PropInterface) => {
return arr;
};
const checkArr = (departments: any[], id: number) => {
const checkArr = (departments: DepartmentsBoxModel, id: number) => {
const arr = [];
for (let i = 0; i < departments[id].length; i++) {
if (!departments[departments[id][i].id]) {