index.tsx 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import PermissionButton from "@/components/PermissionButton";
  2. import TitleComponent from "@/components/TitleComponent";
  3. import { useDomFullHeight } from "@/hooks";
  4. import usePermissions from "@/hooks/permission";
  5. import { onlyMessage } from "@/utils/util";
  6. import { PageContainer } from "@ant-design/pro-layout";
  7. import { Card, Descriptions, Input } from "antd";
  8. import { useEffect, useState } from "react";
  9. import Service from './service';
  10. const License = () => {
  11. const { minHeight } = useDomFullHeight(`.license`);
  12. const service = new Service('license');
  13. const [info, setInfo] = useState<any>()
  14. const [license, setLicens] = useState<any>()
  15. const [value, setValue] = useState<any>()
  16. const { permission: userPermission } = usePermissions('system/License');
  17. const getInfo = async () => {
  18. const res = await service.getModule()
  19. if (res.status === 200) {
  20. setInfo(res.result)
  21. }
  22. }
  23. const getLicense = async () => {
  24. const res = await service.getLicense()
  25. if (res.status === 200) {
  26. setLicens(res.result)
  27. setValue(res.result?.license)
  28. }
  29. }
  30. const save = async (data: any) => {
  31. const res: any = await service.save(data)
  32. if (res.status === 200) {
  33. onlyMessage('配置成功')
  34. getLicense()
  35. }
  36. }
  37. useEffect(() => {
  38. getInfo()
  39. getLicense()
  40. }, [])
  41. return (
  42. <PageContainer>
  43. <Card className="license" style={{ minHeight }}>
  44. <TitleComponent data={'基础信息'} />
  45. <div >
  46. <Descriptions bordered column={4}>
  47. <Descriptions.Item label="Host" span={4}>{info?.host}</Descriptions.Item>
  48. {info?.modules.map((item: any) => (
  49. <>
  50. <Descriptions.Item label="IP" span={2}>{item.ip}</Descriptions.Item>
  51. <Descriptions.Item label="Mac" span={2}>{item.mac}</Descriptions.Item>
  52. </>)
  53. )}
  54. </Descriptions>
  55. </div>
  56. <div style={{ display: 'flex', marginTop: 10, alignItems: 'center' }}>
  57. <TitleComponent data={'License'} style={{ marginTop: 10 }} />
  58. <div style={{ width: 200 }}>到期时间:{license?.expire}</div>
  59. </div>
  60. <Input.TextArea
  61. placeholder="请输入License"
  62. rows={10}
  63. // style={{ width: 900 }}
  64. value={value}
  65. onChange={(e) => {
  66. setValue(e.target.value)
  67. }}
  68. />
  69. <PermissionButton
  70. type="primary"
  71. key="save"
  72. style={{ marginTop: 20 }}
  73. onClick={() => {
  74. // save();
  75. if (value) {
  76. save(value)
  77. } else {
  78. onlyMessage('请配置License', 'warning')
  79. }
  80. }}
  81. isPermission={userPermission.update}
  82. >
  83. 保存
  84. </PermissionButton>
  85. </Card>
  86. </PageContainer>
  87. )
  88. }
  89. export default License;