index.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import PermissionButton from '@/components/PermissionButton';
  2. import usePermissions from '@/hooks/permission';
  3. import { PageContainer } from '@ant-design/pro-layout';
  4. import { Form, FormItem } from '@formily/antd';
  5. import type { ISchema } from '@formily/json-schema';
  6. import { Card, Col, Input, Row } from 'antd';
  7. import { createSchemaField, observer } from '@formily/react';
  8. import { useEffect, useMemo, useState } from 'react';
  9. import { createForm } from '@formily/core';
  10. import CertificateFile from './components/CertificateFile';
  11. import Standard from './components/Standard';
  12. import { service } from '@/pages/link/Certificate';
  13. import { useParams } from 'umi';
  14. import './index.less';
  15. import { onlyMessage } from '@/utils/util';
  16. import { useLocation } from '@/hooks';
  17. const Detail = observer(() => {
  18. const params = useParams<{ id: string }>();
  19. const location = useLocation();
  20. const [view, setView] = useState<boolean>(false);
  21. const form = useMemo(
  22. () =>
  23. createForm({
  24. validateFirst: true,
  25. }),
  26. [],
  27. );
  28. useEffect(() => {
  29. if (params.id && params.id !== ':id') {
  30. service.detail(params.id).then((resp) => {
  31. if (resp.status === 200) {
  32. form.setValues(resp.result);
  33. }
  34. });
  35. }
  36. }, [params.id]);
  37. useEffect(() => {
  38. if (location && location.state) {
  39. setView(location.state.view);
  40. }
  41. }, [location]);
  42. const SchemaField = createSchemaField({
  43. components: {
  44. FormItem,
  45. Input,
  46. CertificateFile,
  47. Standard,
  48. },
  49. });
  50. const schema: ISchema = {
  51. type: 'object',
  52. properties: {
  53. type: {
  54. type: 'string',
  55. title: '证书标准',
  56. required: true,
  57. default: 'common',
  58. 'x-decorator': 'FormItem',
  59. 'x-component': 'Standard',
  60. 'x-validator': [
  61. {
  62. required: true,
  63. message: '请选择证书标准',
  64. },
  65. ],
  66. },
  67. name: {
  68. type: 'string',
  69. title: '证书名称',
  70. required: true,
  71. 'x-decorator': 'FormItem',
  72. 'x-component': 'Input',
  73. 'x-component-props': {
  74. placeholder: '请输入证书名称',
  75. },
  76. 'x-validator': [
  77. {
  78. required: true,
  79. message: '请输入证书名称',
  80. },
  81. {
  82. max: 64,
  83. message: '最多可输入64个字符',
  84. },
  85. ],
  86. },
  87. 'configs.cert': {
  88. title: '证书文件',
  89. 'x-component': 'CertificateFile',
  90. 'x-decorator': 'FormItem',
  91. required: true,
  92. 'x-component-props': {
  93. rows: 3,
  94. placeholder:
  95. '证书私钥格式以"-----BEGIN (RSA|EC) PRIVATE KEY-----"开头,以"-----END(RSA|EC) PRIVATE KEY-----"结尾。',
  96. },
  97. 'x-validator': [
  98. {
  99. required: true,
  100. message: '请上传证书文件',
  101. },
  102. ],
  103. },
  104. 'configs.key': {
  105. title: '证书私钥',
  106. 'x-component': 'Input.TextArea',
  107. 'x-decorator': 'FormItem',
  108. required: true,
  109. 'x-component-props': {
  110. rows: 3,
  111. placeholder:
  112. '证书私钥格式以"-----BEGIN (RSA|EC) PRIVATE KEY-----"开头,以"-----END(RSA|EC) PRIVATE KEY-----"结尾。',
  113. },
  114. 'x-validator': [
  115. {
  116. required: true,
  117. message: '请输入证书私钥',
  118. },
  119. ],
  120. },
  121. description: {
  122. title: '说明',
  123. 'x-component': 'Input.TextArea',
  124. 'x-decorator': 'FormItem',
  125. 'x-component-props': {
  126. rows: 3,
  127. showCount: true,
  128. maxLength: 200,
  129. placeholder: '请输入说明',
  130. },
  131. },
  132. },
  133. };
  134. const { getOtherPermission } = usePermissions('link/Certificate');
  135. return (
  136. <PageContainer>
  137. <Card>
  138. <Row gutter={24}>
  139. <Col span={12}>
  140. <Form form={form} layout="vertical">
  141. <SchemaField schema={schema} />
  142. {!view && (
  143. <PermissionButton
  144. type="primary"
  145. isPermission={getOtherPermission(['add', 'update'])}
  146. onClick={async () => {
  147. const data: any = await form.submit();
  148. const response: any = data.id
  149. ? await service.update(data)
  150. : await service.save(data);
  151. if (response.status === 200) {
  152. onlyMessage('操作成功');
  153. history.back();
  154. }
  155. }}
  156. >
  157. 保存
  158. </PermissionButton>
  159. )}
  160. </Form>
  161. </Col>
  162. <Col span={12}>
  163. <div className="doc">
  164. <h1>1. 概述</h1>
  165. <div>
  166. 证书由受信任的数字证书颁发机构CA,在验证服务器身份后颁发,具有服务器身份验证和数据传输加密功能,保障设备与平台间的数据传输安全。配置后可被网络组件引用。
  167. </div>
  168. <h1>2. 配置说明</h1>
  169. <h2>1、证书文件</h2>
  170. <div>
  171. 您可以使用文本编辑工具打开PEM或者CRT格式的证书文件,复制其中的内容并粘贴到该文本框,或者单击该文本框下的上传,并选择存储在本地计算机的证书文件,将文件内容上传到文本框。
  172. </div>
  173. <h2>2、证书私钥</h2>
  174. <div>
  175. 填写证书私钥内容的PEM编码。
  176. 您可以使用文本编辑工具打开KEY格式的证书私钥文件,复制其中的内容并粘贴到该文本框,或者单击该文本框下的上传并选择存储在本地计算机的证书私钥文件,将文件内容上传到文本框。
  177. </div>
  178. </div>
  179. </Col>
  180. </Row>
  181. </Card>
  182. </PageContainer>
  183. );
  184. });
  185. export default Detail;