mirror of
https://github.com/PlayEdu/backend
synced 2025-06-17 05:58:28 +08:00
部门、分类管理拖拽排序
This commit is contained in:
parent
b6c68d0abc
commit
b1946c7a54
@ -36,3 +36,17 @@ export function updateDepartment(
|
||||
export function destroyDepartment(id: number) {
|
||||
return client.destroy(`/backend/v1/department/${id}`);
|
||||
}
|
||||
|
||||
export function dropSameClass(ids: number[]) {
|
||||
return client.put(`/backend/v1/department/update/sort`, {
|
||||
ids: ids,
|
||||
});
|
||||
}
|
||||
|
||||
export function dropDiffClass(id: number, parent_id: number, ids: number[]) {
|
||||
return client.put(`/backend/v1/department/update/parent`, {
|
||||
id: id,
|
||||
parent_id: parent_id,
|
||||
ids: ids,
|
||||
});
|
||||
}
|
||||
|
@ -40,3 +40,17 @@ export function updateResourceCategory(
|
||||
export function destroyResourceCategory(id: number) {
|
||||
return client.destroy(`/backend/v1/resource-category/${id}`);
|
||||
}
|
||||
|
||||
export function dropSameClass(ids: number[]) {
|
||||
return client.put(`/backend/v1/resource-category/update/sort`, {
|
||||
ids: ids,
|
||||
});
|
||||
}
|
||||
|
||||
export function dropDiffClass(id: number, parent_id: number, ids: number[]) {
|
||||
return client.put(`/backend/v1/resource-category/update/parent`, {
|
||||
id: id,
|
||||
parent_id: parent_id,
|
||||
ids: ids,
|
||||
});
|
||||
}
|
||||
|
@ -192,6 +192,13 @@ export const DepartmentPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
const data = [...treeData];
|
||||
let isTop = false;
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (data[i].key === dragKey) {
|
||||
isTop = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Find dragObject
|
||||
let dragObj: DataNode;
|
||||
@ -233,6 +240,46 @@ export const DepartmentPage: React.FC = () => {
|
||||
}
|
||||
}
|
||||
setTreeData(data);
|
||||
submitDrop(isTop, data, dragKey);
|
||||
};
|
||||
|
||||
const submitDrop = (isTop: boolean, data: any, key: any) => {
|
||||
let result = checkDropArr(data, key);
|
||||
if (result) {
|
||||
if (isTop) {
|
||||
department.dropSameClass(result.ids).then((res: any) => {
|
||||
console.log("ok");
|
||||
});
|
||||
} else {
|
||||
submitChildDrop(key, 0, result);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const submitChildDrop = (key: any, pid: any, ids: any) => {
|
||||
department.dropDiffClass(key, pid, ids.ids).then((res: any) => {
|
||||
console.log("ok");
|
||||
});
|
||||
};
|
||||
|
||||
const checkDropArr = (data: any, key: any) => {
|
||||
let ids = [];
|
||||
let isSame = false;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].key);
|
||||
if (data[i].key === key) {
|
||||
isSame = true;
|
||||
}
|
||||
if (data[i].children) {
|
||||
let res: any = checkDropArr(data[i].children, key);
|
||||
if (res) {
|
||||
submitChildDrop(key, data[i].key, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isSame) {
|
||||
return { key, ids };
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -172,7 +172,6 @@ export const ResourceCategoryPage: React.FC = () => {
|
||||
const dropPos = info.node.pos.split("-");
|
||||
const dropPosition =
|
||||
info.dropPosition - Number(dropPos[dropPos.length - 1]);
|
||||
|
||||
const loop = (
|
||||
data: DataNode[],
|
||||
key: React.Key,
|
||||
@ -188,6 +187,13 @@ export const ResourceCategoryPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
const data = [...treeData];
|
||||
let isTop = false;
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (data[i].key === dragKey) {
|
||||
isTop = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Find dragObject
|
||||
let dragObj: DataNode;
|
||||
@ -229,6 +235,46 @@ export const ResourceCategoryPage: React.FC = () => {
|
||||
}
|
||||
}
|
||||
setTreeData(data);
|
||||
submitDrop(isTop, data, dragKey);
|
||||
};
|
||||
|
||||
const submitDrop = (isTop: boolean, data: any, key: any) => {
|
||||
let result = checkDropArr(data, key);
|
||||
if (result) {
|
||||
if (isTop) {
|
||||
resourceCategory.dropSameClass(result.ids).then((res: any) => {
|
||||
console.log("ok");
|
||||
});
|
||||
} else {
|
||||
submitChildDrop(key, 0, result);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const submitChildDrop = (key: any, pid: any, ids: any) => {
|
||||
resourceCategory.dropDiffClass(key, pid, ids.ids).then((res: any) => {
|
||||
console.log("ok");
|
||||
});
|
||||
};
|
||||
|
||||
const checkDropArr = (data: any, key: any) => {
|
||||
let ids = [];
|
||||
let isSame = false;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
ids.push(data[i].key);
|
||||
if (data[i].key === key) {
|
||||
isSame = true;
|
||||
}
|
||||
if (data[i].children) {
|
||||
let res: any = checkDropArr(data[i].children, key);
|
||||
if (res) {
|
||||
submitChildDrop(key, data[i].key, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isSame) {
|
||||
return { key, ids };
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
Loading…
x
Reference in New Issue
Block a user