bug:14076
parent
f459c9ef46
commit
b3189c154f
|
|
@ -18,6 +18,7 @@
|
||||||
"lint": "eslint --ext .js,.jsx,.tsx --fix src"
|
"lint": "eslint --ext .js,.jsx,.tsx --fix src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@ahooksjs/use-url-state": "^3.5.1",
|
||||||
"@ant-design/icons": "^6.1.0",
|
"@ant-design/icons": "^6.1.0",
|
||||||
"@ant-design/pro-components": "^2.8.10",
|
"@ant-design/pro-components": "^2.8.10",
|
||||||
"@cqsjjb/jjb-common-decorator": "latest",
|
"@cqsjjb/jjb-common-decorator": "latest",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import useUrlState from "@ahooksjs/use-url-state";
|
||||||
import { RightOutlined } from "@ant-design/icons";
|
import { RightOutlined } from "@ant-design/icons";
|
||||||
import { Permission } from "@cqsjjb/jjb-common-decorator/permission";
|
import { Permission } from "@cqsjjb/jjb-common-decorator/permission";
|
||||||
import { Connect } from "@cqsjjb/jjb-dva-runtime";
|
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 DepartmentSelectTree from "zy-react-library/components/SelectTree/Department/Gwj";
|
||||||
import Table from "zy-react-library/components/Table";
|
import Table from "zy-react-library/components/Table";
|
||||||
import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
|
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 useTable from "zy-react-library/hooks/useTable";
|
||||||
import { NS_PART } from "~/enumerate/namespace";
|
import { NS_PART } from "~/enumerate/namespace";
|
||||||
|
|
||||||
function Part(props) {
|
function Part(props) {
|
||||||
const urlQuery = useGetUrlQuery();
|
|
||||||
const [treeData, setTreeData] = useState([]);
|
const [treeData, setTreeData] = useState([]);
|
||||||
const [parentId, setParentId] = useState(urlQuery.eqParentId || "");
|
|
||||||
const [parentName, setParentName] = useState(urlQuery.eqParentName || "");
|
|
||||||
const [addModalOpen, setAddModalOpen] = useState(false);
|
const [addModalOpen, setAddModalOpen] = useState(false);
|
||||||
const [currentId, setCurrentId] = useState("");
|
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 getTreeData = async () => {
|
||||||
const { data } = await props["partTreeList"]();
|
const { data } = await props["partTreeList"]();
|
||||||
setTreeData(data);
|
setTreeData(data);
|
||||||
|
|
@ -31,7 +43,8 @@ function Part(props) {
|
||||||
getTreeData();
|
getTreeData();
|
||||||
}, []);
|
}, []);
|
||||||
const { tableProps, getData } = useTable(props["partList"], {
|
const { tableProps, getData } = useTable(props["partList"], {
|
||||||
params: () => ({ eqParentId: parentId }),
|
params: () => ({ eqParentId: urlState.parentId }),
|
||||||
|
manual: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const onDelete = (id) => {
|
const onDelete = (id) => {
|
||||||
|
|
@ -50,31 +63,8 @@ function Part(props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
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();
|
getData();
|
||||||
}
|
}, [urlState.parentId]);
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page isShowAllAction={false}>
|
<Page isShowAllAction={false}>
|
||||||
|
|
@ -88,7 +78,12 @@ function Part(props) {
|
||||||
onGetNodePaths={(event) => {
|
onGetNodePaths={(event) => {
|
||||||
const hiddenregion = event.at(-1).hiddenregion;
|
const hiddenregion = event.at(-1).hiddenregion;
|
||||||
const hiddenregionId = event.at(-1).hiddenregionId;
|
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>
|
</Spin>
|
||||||
|
|
@ -110,11 +105,16 @@ function Part(props) {
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{
|
{
|
||||||
parentId && (
|
urlState.parentId !== "0" && (
|
||||||
<Button
|
<Button
|
||||||
icon={<BackIcon />}
|
icon={<BackIcon />}
|
||||||
onClick={() => {
|
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={() => {
|
onClick={() => {
|
||||||
const hiddenregion = record.hiddenregion;
|
const hiddenregion = record.hiddenregion;
|
||||||
const hiddenregionId = record.hiddenregionId;
|
const hiddenregionId = record.hiddenregionId;
|
||||||
getNextLevel(hiddenregion, hiddenregionId);
|
setUrlState({
|
||||||
|
parentId: hiddenregionId,
|
||||||
|
parentName: hiddenregion,
|
||||||
|
backParentIds: [...urlState.backParentIds, urlState.parentId],
|
||||||
|
backParentNames: [...urlState.backParentNames, urlState.parentName],
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{record.hiddenregion}
|
{record.hiddenregion}
|
||||||
|
|
@ -174,8 +179,8 @@ function Part(props) {
|
||||||
{addModalOpen && (
|
{addModalOpen && (
|
||||||
<AddModal
|
<AddModal
|
||||||
id={currentId}
|
id={currentId}
|
||||||
parentName={parentName}
|
parentName={urlState.parentName}
|
||||||
parentId={parentId}
|
parentId={urlState.parentId}
|
||||||
getData={getData}
|
getData={getData}
|
||||||
getTreeData={getTreeData}
|
getTreeData={getTreeData}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue