bug:14076
parent
f459c9ef46
commit
b3189c154f
|
|
@ -18,6 +18,7 @@
|
|||
"lint": "eslint --ext .js,.jsx,.tsx --fix src"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ahooksjs/use-url-state": "^3.5.1",
|
||||
"@ant-design/icons": "^6.1.0",
|
||||
"@ant-design/pro-components": "^2.8.10",
|
||||
"@cqsjjb/jjb-common-decorator": "latest",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import useUrlState from "@ahooksjs/use-url-state";
|
||||
import { RightOutlined } from "@ant-design/icons";
|
||||
import { Permission } from "@cqsjjb/jjb-common-decorator/permission";
|
||||
import { Connect } from "@cqsjjb/jjb-dva-runtime";
|
||||
|
|
@ -12,17 +13,28 @@ import PersonnelSelect from "zy-react-library/components/Select/Personnel/Gwj";
|
|||
import DepartmentSelectTree from "zy-react-library/components/SelectTree/Department/Gwj";
|
||||
import Table from "zy-react-library/components/Table";
|
||||
import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
|
||||
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
|
||||
import useTable from "zy-react-library/hooks/useTable";
|
||||
import { NS_PART } from "~/enumerate/namespace";
|
||||
|
||||
function Part(props) {
|
||||
const urlQuery = useGetUrlQuery();
|
||||
const [treeData, setTreeData] = useState([]);
|
||||
const [parentId, setParentId] = useState(urlQuery.eqParentId || "");
|
||||
const [parentName, setParentName] = useState(urlQuery.eqParentName || "");
|
||||
const [addModalOpen, setAddModalOpen] = useState(false);
|
||||
const [currentId, setCurrentId] = useState("");
|
||||
const [urlState, setUrlState] = useUrlState({
|
||||
parentId: "0",
|
||||
parentName: "",
|
||||
backParentIds: [],
|
||||
backParentNames: [],
|
||||
}, {
|
||||
navigateMode: "replace",
|
||||
parseOptions: {
|
||||
arrayFormat: "index",
|
||||
},
|
||||
stringifyOptions: {
|
||||
arrayFormat: "index",
|
||||
},
|
||||
});
|
||||
|
||||
const getTreeData = async () => {
|
||||
const { data } = await props["partTreeList"]();
|
||||
setTreeData(data);
|
||||
|
|
@ -31,7 +43,8 @@ function Part(props) {
|
|||
getTreeData();
|
||||
}, []);
|
||||
const { tableProps, getData } = useTable(props["partList"], {
|
||||
params: () => ({ eqParentId: parentId }),
|
||||
params: () => ({ eqParentId: urlState.parentId }),
|
||||
manual: true,
|
||||
});
|
||||
|
||||
const onDelete = (id) => {
|
||||
|
|
@ -50,31 +63,8 @@ function Part(props) {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = props.history.listen((location) => {
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
const newParentId = searchParams.get("eqParentId");
|
||||
const newParentName = searchParams.get("eqParentName");
|
||||
|
||||
if (newParentId !== parentId || newParentName !== parentName) {
|
||||
setParentId(newParentId);
|
||||
setParentName(newParentName);
|
||||
getData();
|
||||
}
|
||||
});
|
||||
|
||||
return unlisten;
|
||||
}, [parentId, parentName]);
|
||||
|
||||
const getNextLevel = (hiddenregion, hiddenregionId) => {
|
||||
setParentName(hiddenregion);
|
||||
setParentId(hiddenregionId);
|
||||
const currentSearchParams = new URLSearchParams(props.history.location.search);
|
||||
currentSearchParams.set("eqParentId", hiddenregionId);
|
||||
currentSearchParams.set("eqParentName", hiddenregion);
|
||||
const queryString = currentSearchParams.toString();
|
||||
const newPath = `./part${queryString ? `?${queryString}` : ""}`;
|
||||
props.history.push(newPath);
|
||||
};
|
||||
getData();
|
||||
}, [urlState.parentId]);
|
||||
|
||||
return (
|
||||
<Page isShowAllAction={false}>
|
||||
|
|
@ -88,7 +78,12 @@ function Part(props) {
|
|||
onGetNodePaths={(event) => {
|
||||
const hiddenregion = event.at(-1).hiddenregion;
|
||||
const hiddenregionId = event.at(-1).hiddenregionId;
|
||||
getNextLevel(hiddenregion, hiddenregionId);
|
||||
setUrlState({
|
||||
parentId: hiddenregionId,
|
||||
parentName: hiddenregion,
|
||||
backParentIds: [...urlState.backParentIds, urlState.parentId],
|
||||
backParentNames: [...urlState.backParentNames, urlState.parentName],
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Spin>
|
||||
|
|
@ -110,11 +105,16 @@ function Part(props) {
|
|||
</Button>
|
||||
)}
|
||||
{
|
||||
parentId && (
|
||||
urlState.parentId !== "0" && (
|
||||
<Button
|
||||
icon={<BackIcon />}
|
||||
onClick={() => {
|
||||
props.history.goBack();
|
||||
setUrlState({
|
||||
parentId: urlState.backParentIds.at(-1),
|
||||
parentName: urlState.backParentNames.at(-1),
|
||||
backParentIds: urlState.backParentIds.slice(0, -1),
|
||||
backParentNames: urlState.backParentNames.slice(0, -1),
|
||||
});
|
||||
}}
|
||||
>
|
||||
返回
|
||||
|
|
@ -135,7 +135,12 @@ function Part(props) {
|
|||
onClick={() => {
|
||||
const hiddenregion = record.hiddenregion;
|
||||
const hiddenregionId = record.hiddenregionId;
|
||||
getNextLevel(hiddenregion, hiddenregionId);
|
||||
setUrlState({
|
||||
parentId: hiddenregionId,
|
||||
parentName: hiddenregion,
|
||||
backParentIds: [...urlState.backParentIds, urlState.parentId],
|
||||
backParentNames: [...urlState.backParentNames, urlState.parentName],
|
||||
});
|
||||
}}
|
||||
>
|
||||
{record.hiddenregion}
|
||||
|
|
@ -174,8 +179,8 @@ function Part(props) {
|
|||
{addModalOpen && (
|
||||
<AddModal
|
||||
id={currentId}
|
||||
parentName={parentName}
|
||||
parentId={parentId}
|
||||
parentName={urlState.parentName}
|
||||
parentId={urlState.parentId}
|
||||
getData={getData}
|
||||
getTreeData={getTreeData}
|
||||
onCancel={() => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue