index.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // 菜单管理-详情
  2. import { PageContainer } from '@ant-design/pro-layout';
  3. import { useIntl } from '@@/plugin-locale/localeExports';
  4. import { useEffect, useState } from 'react';
  5. import BaseDetail from './edit';
  6. import Buttons from './buttons';
  7. import { useLocation, useParams, useRequest } from 'umi';
  8. import { service } from '@/pages/system/Menu';
  9. type LocationType = {
  10. id?: string;
  11. };
  12. export default () => {
  13. const intl = useIntl();
  14. const [tabKey, setTabKey] = useState('detail');
  15. const [pId, setPid] = useState<string | null>(null);
  16. const location = useLocation<LocationType>();
  17. const params: any = new URLSearchParams(location.search);
  18. const param = useParams<{ id?: string }>();
  19. const { data, run: queryData } = useRequest(service.queryDetail, {
  20. manual: true,
  21. formatResult: (response) => {
  22. return response.result;
  23. },
  24. });
  25. /**
  26. * 获取当前菜单详情
  27. */
  28. const queryDetail = (editId?: string) => {
  29. const id = editId || param.id;
  30. const _pId = params.get('pId');
  31. if (id && id !== ':id') {
  32. queryData(id);
  33. }
  34. if (_pId) {
  35. setPid(_pId);
  36. }
  37. };
  38. useEffect(() => {
  39. queryDetail();
  40. /* eslint-disable */
  41. }, [location]);
  42. return (
  43. <PageContainer
  44. tabList={[
  45. {
  46. tab: intl.formatMessage({
  47. id: 'pages.system.menu.detail',
  48. defaultMessage: '基本详情',
  49. }),
  50. key: 'detail',
  51. },
  52. data?.appId
  53. ? {}
  54. : {
  55. tab: intl.formatMessage({
  56. id: 'pages.system.menu.buttons',
  57. defaultMessage: '按钮管理',
  58. }),
  59. key: 'buttons',
  60. },
  61. ]}
  62. onTabChange={(key) => {
  63. setTabKey(key);
  64. }}
  65. >
  66. {tabKey === 'detail' && data ? (
  67. <BaseDetail
  68. data={{
  69. ...data,
  70. parentId: pId,
  71. }}
  72. basePath={params.get('basePath')}
  73. onLoad={queryDetail}
  74. />
  75. ) : (
  76. <Buttons data={data} onLoad={queryDetail} />
  77. )}
  78. </PageContainer>
  79. );
  80. };