index.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import type { ProtocolItem } from '@/pages/link/Protocol/typings';
  3. import { useRef } from 'react';
  4. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  5. import { message, Popconfirm, Tag, Tooltip } from 'antd';
  6. import {
  7. CloudSyncOutlined,
  8. DeleteOutlined,
  9. EditOutlined,
  10. PlayCircleOutlined,
  11. } from '@ant-design/icons';
  12. import BaseCrud from '@/components/BaseCrud';
  13. import { useIntl } from '@@/plugin-locale/localeExports';
  14. import type { ISchema } from '@formily/json-schema';
  15. import { CurdModel } from '@/components/BaseCrud/model';
  16. import Service from '@/pages/link/Protocol/service';
  17. export const service = new Service('protocol');
  18. const Protocol = () => {
  19. const intl = useIntl();
  20. const actionRef = useRef<ActionType>();
  21. const modifyState = async (id: string, type: 'deploy' | 'un-deploy') => {
  22. const resp = await service.modifyState(id, type);
  23. if (resp.status === 200) {
  24. message.success('操作成功!');
  25. } else {
  26. message.error('操作失败!');
  27. }
  28. actionRef.current?.reload();
  29. };
  30. const columns: ProColumns<ProtocolItem>[] = [
  31. {
  32. dataIndex: 'index',
  33. valueType: 'indexBorder',
  34. width: 48,
  35. },
  36. {
  37. dataIndex: 'id',
  38. title: 'ID',
  39. sorter: true,
  40. defaultSortOrder: 'ascend',
  41. },
  42. {
  43. dataIndex: 'name',
  44. title: intl.formatMessage({
  45. id: 'pages.table.name',
  46. defaultMessage: '名称',
  47. }),
  48. },
  49. {
  50. dataIndex: 'type',
  51. title: '类型',
  52. },
  53. {
  54. dataIndex: 'state',
  55. title: '状态',
  56. renderText: (text) =>
  57. text === 1 ? <Tag color="#108ee9">正常</Tag> : <Tag color="#F50">禁用</Tag>,
  58. },
  59. {
  60. dataIndex: 'description',
  61. title: '说明',
  62. },
  63. {
  64. title: intl.formatMessage({
  65. id: 'pages.data.option',
  66. defaultMessage: '操作',
  67. }),
  68. valueType: 'option',
  69. align: 'center',
  70. width: 200,
  71. render: (text, record) => [
  72. <a
  73. key="edit"
  74. onClick={() => {
  75. CurdModel.update(record);
  76. CurdModel.model = 'edit';
  77. }}
  78. >
  79. <Tooltip
  80. title={intl.formatMessage({
  81. id: 'pages.data.option.edit',
  82. defaultMessage: '编辑',
  83. })}
  84. >
  85. <EditOutlined />
  86. </Tooltip>
  87. </a>,
  88. record.state !== 1 && (
  89. <a key="publish">
  90. <Popconfirm title="发布?" onConfirm={() => modifyState(record.id, 'deploy')}>
  91. <Tooltip title="发布">
  92. <PlayCircleOutlined />
  93. </Tooltip>
  94. </Popconfirm>
  95. </a>
  96. ),
  97. record.state === 1 && (
  98. <a key="reload">
  99. <Popconfirm title="重新发布?" onConfirm={() => modifyState(record.id, 'deploy')}>
  100. <Tooltip title="重新发布">
  101. <CloudSyncOutlined />
  102. </Tooltip>
  103. </Popconfirm>
  104. </a>
  105. ),
  106. record.state !== 1 && (
  107. <a key="delete">
  108. <Popconfirm
  109. title={intl.formatMessage({
  110. id: 'pages.data.option.remove.tips',
  111. defaultMessage: '确认删除?',
  112. })}
  113. onConfirm={async () => {
  114. await service.remove(record.id);
  115. message.success(
  116. intl.formatMessage({
  117. id: 'pages.data.option.success',
  118. defaultMessage: '操作成功!',
  119. }),
  120. );
  121. actionRef.current?.reload();
  122. }}
  123. >
  124. <Tooltip
  125. title={intl.formatMessage({
  126. id: 'pages.data.option.remove',
  127. defaultMessage: '删除',
  128. })}
  129. >
  130. <DeleteOutlined />
  131. </Tooltip>
  132. </Popconfirm>
  133. </a>
  134. ),
  135. ],
  136. },
  137. ];
  138. const schema: ISchema = {
  139. type: 'object',
  140. properties: {
  141. layout: {
  142. type: 'void',
  143. 'x-component': 'FormGrid',
  144. 'x-component-props': {
  145. maxColumns: 1,
  146. minColumns: 1,
  147. },
  148. properties: {
  149. id: {
  150. title: 'ID',
  151. 'x-component': 'Input',
  152. 'x-decorator': 'FormItem',
  153. 'x-decorator-props': {
  154. gridSpan: 1,
  155. },
  156. 'x-validator': [
  157. {
  158. required: true,
  159. message: '请输入ID',
  160. },
  161. {
  162. max: 64,
  163. message: '最多可输入64个字符',
  164. },
  165. ],
  166. },
  167. name: {
  168. title: '名称',
  169. 'x-component': 'Input',
  170. 'x-decorator': 'FormItem',
  171. 'x-decorator-props': {
  172. gridSpan: 1,
  173. },
  174. 'x-validator': [
  175. {
  176. required: true,
  177. message: '请输入名称',
  178. },
  179. {
  180. max: 64,
  181. message: '最多可输入64个字符',
  182. },
  183. ],
  184. },
  185. type: {
  186. title: '类型',
  187. 'x-component': 'Select',
  188. 'x-decorator': 'FormItem',
  189. 'x-decorator-props': {
  190. tooltip: <div>jar:上传协议jar包,文件格式支持.jar或.zip</div>,
  191. },
  192. 'x-validator': [
  193. {
  194. required: true,
  195. message: '请选择类型',
  196. },
  197. ],
  198. enum: [
  199. { label: 'jar', value: 'jar' },
  200. { label: 'local', value: 'local' },
  201. // { label: 'script', value: 'script' },
  202. ],
  203. },
  204. configuration: {
  205. type: 'object',
  206. properties: {
  207. location: {
  208. title: '文件地址',
  209. 'x-decorator': 'FormItem',
  210. 'x-visible': false,
  211. 'x-decorator-props': {
  212. tooltip: (
  213. <div>
  214. local:填写本地协议编译目录绝对地址,如:d:/workspace/protocol/target/classes
  215. </div>
  216. ),
  217. },
  218. 'x-validator': [
  219. {
  220. required: true,
  221. message: '请输入文件地址',
  222. },
  223. ],
  224. 'x-reactions': {
  225. dependencies: ['..type'],
  226. fulfill: {
  227. state: {
  228. visible: '{{["jar","local"].includes($deps[0])}}',
  229. componentType: '{{$deps[0]==="jar"?"FileUpload":"Input"}}',
  230. componentProps: '{{$deps[0]==="jar"?{type:"file", accept: ".jar, .zip"}:{}}}',
  231. },
  232. },
  233. },
  234. },
  235. // provider: {
  236. // title: '类名',
  237. // 'x-component': 'Input',
  238. // 'x-decorator': 'FormItem',
  239. // 'x-visible': false,
  240. // 'x-validator': [
  241. // {
  242. // required: true,
  243. // message: '请选择类名',
  244. // },
  245. // ],
  246. // 'x-reactions': {
  247. // dependencies: ['..type'],
  248. // fulfill: {
  249. // state: {
  250. // visible: '{{["jar","local"].includes($deps[0])}}',
  251. // },
  252. // },
  253. // },
  254. // },
  255. },
  256. },
  257. description: {
  258. title: '说明',
  259. 'x-component': 'Input.TextArea',
  260. 'x-decorator': 'FormItem',
  261. 'x-component-props': {
  262. rows: 3,
  263. showCount: true,
  264. maxLength: 200,
  265. },
  266. },
  267. },
  268. },
  269. },
  270. };
  271. return (
  272. <PageContainer>
  273. <BaseCrud
  274. columns={columns}
  275. service={service}
  276. title={'插件管理'}
  277. search={false}
  278. modelConfig={{ width: '550px' }}
  279. schema={schema}
  280. actionRef={actionRef}
  281. />
  282. {/* {visible && <Debug data={current} close={() => setVisible(!visible)} />} */}
  283. </PageContainer>
  284. );
  285. };
  286. export default Protocol;