index.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // 部门-资产分配
  2. import { Tabs } from 'antd';
  3. import { useIntl } from '@@/plugin-locale/localeExports';
  4. import Product from './product';
  5. import Device from '@/pages/system/Department/Assets/deivce';
  6. import Member from '@/pages/system/Department/Member';
  7. import { model } from '@formily/reactive';
  8. import { observer } from '@formily/react';
  9. // import { ExclamationCircleOutlined } from '@ant-design/icons';
  10. import { useEffect } from 'react';
  11. import { isNoCommunity } from '@/utils/util';
  12. interface AssetsProps {
  13. parentId: string;
  14. }
  15. export enum ASSETS_TABS_ENUM {
  16. 'ProductCategory' = 'ProductCategory',
  17. 'Product' = 'Product',
  18. 'Device' = 'Device',
  19. 'User' = 'User',
  20. }
  21. export const AssetsModel = model<{
  22. tabsIndex: string;
  23. bindModal: boolean;
  24. parentId: string;
  25. params: any;
  26. tabsArray: any[];
  27. }>({
  28. tabsIndex: ASSETS_TABS_ENUM.Product,
  29. bindModal: false,
  30. parentId: '',
  31. params: {},
  32. tabsArray: [],
  33. });
  34. const Assets = observer((props: AssetsProps) => {
  35. const intl = useIntl();
  36. // 资产类型
  37. const TabsArray = [
  38. // {
  39. // intlTitle: '1',
  40. // defaultMessage: '产品分类',
  41. // key: ASSETS_TABS_ENUM.ProductCategory,
  42. // components: ProductCategory,
  43. // },
  44. {
  45. intlTitle: '2',
  46. defaultMessage: '产品',
  47. key: ASSETS_TABS_ENUM.Product,
  48. components: Product,
  49. },
  50. {
  51. intlTitle: '3',
  52. defaultMessage: '设备',
  53. key: ASSETS_TABS_ENUM.Device,
  54. components: Device,
  55. },
  56. {
  57. intlTitle: '4',
  58. defaultMessage: '用户',
  59. key: ASSETS_TABS_ENUM.User,
  60. components: Member,
  61. },
  62. ];
  63. useEffect(() => {
  64. AssetsModel.tabsIndex = ASSETS_TABS_ENUM.Product;
  65. AssetsModel.tabsArray = [...TabsArray];
  66. }, []);
  67. useEffect(() => {
  68. AssetsModel.parentId = props.parentId;
  69. }, [props.parentId]);
  70. return (
  71. <div style={{ position: 'relative', width: '100%' }}>
  72. {/* <div style={{ position: 'absolute', top: 12, left: 180 }}>
  73. <ExclamationCircleOutlined style={{ marginRight: 12 }} />
  74. 部门拥有的资产为所有类型资产的并集
  75. </div> */}
  76. {isNoCommunity ? (
  77. <Tabs
  78. activeKey={AssetsModel.tabsIndex}
  79. onChange={(key) => {
  80. AssetsModel.tabsIndex = key;
  81. }}
  82. >
  83. {(AssetsModel?.tabsArray || []).map((item) => (
  84. <Tabs.TabPane
  85. tab={intl.formatMessage({
  86. id: item.intlTitle,
  87. defaultMessage: item.defaultMessage,
  88. })}
  89. key={item.key}
  90. >
  91. <item.components parentId={props.parentId} />
  92. </Tabs.TabPane>
  93. ))}
  94. </Tabs>
  95. ) : (
  96. <Member parentId={props.parentId} />
  97. )}
  98. </div>
  99. );
  100. });
  101. export default Assets;