index.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import BaseService from '@/utils/BaseService';
  3. import type { CertificateItem } from '@/pages/link/Certificate/typings';
  4. import { useRef } from 'react';
  5. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  6. import { message, Popconfirm, Tooltip } from 'antd';
  7. import { EditOutlined, MinusOutlined } from '@ant-design/icons';
  8. import BaseCrud from '@/components/BaseCrud';
  9. import { useIntl } from '@@/plugin-locale/localeExports';
  10. import type { ISchema } from '@formily/json-schema';
  11. import { CurdModel } from '@/components/BaseCrud/model';
  12. export const service = new BaseService<CertificateItem>('network/certificate');
  13. const Certificate = () => {
  14. const intl = useIntl();
  15. const actionRef = useRef<ActionType>();
  16. const columns: ProColumns<CertificateItem>[] = [
  17. {
  18. dataIndex: 'index',
  19. valueType: 'indexBorder',
  20. width: 48,
  21. },
  22. {
  23. dataIndex: 'name',
  24. title: intl.formatMessage({
  25. id: 'pages.table.name',
  26. defaultMessage: '名称',
  27. }),
  28. },
  29. {
  30. dataIndex: 'instance',
  31. title: intl.formatMessage({
  32. id: 'pages.link.type',
  33. defaultMessage: '类型',
  34. }),
  35. },
  36. {
  37. dataIndex: 'description',
  38. title: intl.formatMessage({
  39. id: 'pages.table.describe',
  40. defaultMessage: '描述',
  41. }),
  42. },
  43. {
  44. title: intl.formatMessage({
  45. id: 'pages.data.option',
  46. defaultMessage: '操作',
  47. }),
  48. valueType: 'option',
  49. align: 'center',
  50. width: 200,
  51. render: (text, record) => [
  52. <a
  53. key="edit"
  54. onClick={() => {
  55. CurdModel.update(record);
  56. CurdModel.model = 'edit';
  57. }}
  58. >
  59. <Tooltip
  60. title={intl.formatMessage({
  61. id: 'pages.data.option.edit',
  62. defaultMessage: '编辑',
  63. })}
  64. >
  65. <EditOutlined />
  66. </Tooltip>
  67. </a>,
  68. <a key="delete">
  69. <Popconfirm
  70. title={intl.formatMessage({
  71. id: 'pages.data.option.remove.tips',
  72. defaultMessage: '确认删除?',
  73. })}
  74. onConfirm={async () => {
  75. await service.remove(record.id);
  76. message.success(
  77. intl.formatMessage({
  78. id: 'pages.data.option.success',
  79. defaultMessage: '操作成功!',
  80. }),
  81. );
  82. actionRef.current?.reload();
  83. }}
  84. >
  85. <Tooltip
  86. title={intl.formatMessage({
  87. id: 'pages.data.option.remove',
  88. defaultMessage: '删除',
  89. })}
  90. >
  91. <MinusOutlined />
  92. </Tooltip>
  93. </Popconfirm>
  94. </a>,
  95. ],
  96. },
  97. ];
  98. const schema: ISchema = {
  99. type: 'object',
  100. properties: {
  101. name: {
  102. title: '名称',
  103. 'x-component': 'Input',
  104. 'x-decorator': 'FormItem',
  105. },
  106. instance: {
  107. title: '类型',
  108. 'x-component': 'Select',
  109. 'x-decorator': 'FormItem',
  110. default: 'PEM',
  111. enum: [
  112. { label: 'PFX', value: 'PFX' },
  113. { label: 'JKS', value: 'JKS' },
  114. { label: 'PEM', value: 'PEM' },
  115. ],
  116. },
  117. configs: {
  118. type: 'object',
  119. properties: {
  120. '{url:keystoreBase64}': {
  121. title: '密钥库',
  122. 'x-component': 'FUpload',
  123. 'x-decorator': 'FormItem',
  124. 'x-component-props': {
  125. type: 'file',
  126. },
  127. },
  128. keystorePwd: {
  129. title: '密钥库密码',
  130. 'x-component': 'Password',
  131. 'x-decorator': 'FormItem',
  132. 'x-visible': false,
  133. 'x-component-props': {
  134. style: {
  135. width: '100%',
  136. },
  137. },
  138. 'x-reactions': {
  139. dependencies: ['..instance'],
  140. fulfill: {
  141. state: {
  142. visible: '{{["JKS","PFX"].includes($deps[0])}}',
  143. },
  144. },
  145. },
  146. },
  147. '{url:trustKeyStoreBase64}': {
  148. title: '信任库',
  149. 'x-component': 'FUpload',
  150. 'x-decorator': 'FormItem',
  151. 'x-component-props': {
  152. style: {
  153. width: '100px',
  154. },
  155. type: 'file',
  156. },
  157. },
  158. trustKeyStorePwd: {
  159. title: '信任库密码',
  160. 'x-visible': false,
  161. 'x-decorator': 'FormItem',
  162. 'x-component': 'Password',
  163. 'x-reactions': {
  164. dependencies: ['..instance'],
  165. fulfill: {
  166. state: {
  167. visible: '{{["JKS","PFX"].includes($deps[0])}}',
  168. },
  169. },
  170. },
  171. },
  172. },
  173. },
  174. description: {
  175. title: '说明',
  176. 'x-component': 'Input.TextArea',
  177. 'x-decorator': 'FormItem',
  178. },
  179. },
  180. };
  181. return (
  182. <PageContainer>
  183. <BaseCrud
  184. columns={columns}
  185. service={service}
  186. title={intl.formatMessage({
  187. id: 'pages.link.certificate',
  188. defaultMessage: '证书管理',
  189. })}
  190. schema={schema}
  191. actionRef={actionRef}
  192. />
  193. </PageContainer>
  194. );
  195. };
  196. export default Certificate;