index.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import React, { useEffect, useRef } from 'react';
  3. import { DeleteOutlined, EditOutlined } from '@ant-design/icons';
  4. import { message, Popconfirm, Tooltip } from 'antd';
  5. import type { ProColumns, ActionType } from '@jetlinks/pro-table';
  6. import BaseCrud from '@/components/BaseCrud';
  7. import BaseService from '@/utils/BaseService';
  8. import { useIntl } from '@@/plugin-locale/localeExports';
  9. import { observer } from '@formily/react';
  10. import { Link, useLocation } from 'umi';
  11. import { Store } from 'jetlinks-store';
  12. import SystemConst from '@/utils/const';
  13. import { CurdModel } from '@/components/BaseCrud/model';
  14. export const service = new BaseService<RoleItem>('role');
  15. const Role: React.FC = observer(() => {
  16. const intl = useIntl();
  17. const actionRef = useRef<ActionType>();
  18. const columns: ProColumns<RoleItem>[] = [
  19. // {
  20. // dataIndex: 'index',
  21. // valueType: 'indexBorder',
  22. // width: 48,
  23. // },
  24. {
  25. title: intl.formatMessage({
  26. id: 'pages.system.role.id',
  27. defaultMessage: '标识',
  28. }),
  29. dataIndex: 'id',
  30. // copyable: true,
  31. ellipsis: true,
  32. // sorter: true,
  33. // defaultSortOrder: 'ascend',
  34. formItemProps: {
  35. rules: [
  36. {
  37. required: true,
  38. message: '此项为必填项',
  39. },
  40. ],
  41. },
  42. },
  43. {
  44. title: intl.formatMessage({
  45. id: 'pages.table.name',
  46. defaultMessage: '名称',
  47. }),
  48. dataIndex: 'name',
  49. // copyable: true,
  50. ellipsis: true,
  51. // tip: intl.formatMessage({
  52. // id: 'pages.system.userName.tips',
  53. // defaultMessage: '用户名过长会自动收缩',
  54. // }),
  55. formItemProps: {
  56. rules: [
  57. {
  58. required: true,
  59. message: '此项为必填项',
  60. },
  61. ],
  62. },
  63. },
  64. {
  65. title: intl.formatMessage({
  66. id: 'pages.table.describe',
  67. defaultMessage: '描述',
  68. }),
  69. dataIndex: 'description',
  70. filters: true,
  71. onFilter: true,
  72. },
  73. {
  74. title: intl.formatMessage({
  75. id: 'pages.data.option',
  76. defaultMessage: '操作',
  77. }),
  78. valueType: 'option',
  79. align: 'center',
  80. width: 200,
  81. render: (text, record) => [
  82. <Link to={`/system/role/edit/${record.id}`} key="link">
  83. <Tooltip
  84. title={intl.formatMessage({
  85. id: 'pages.data.option.edit',
  86. defaultMessage: '编辑',
  87. })}
  88. key={'edit'}
  89. >
  90. <EditOutlined />
  91. </Tooltip>
  92. </Link>,
  93. <a key="delete">
  94. <Popconfirm
  95. title={intl.formatMessage({
  96. id: 'pages.data.option.remove.tips',
  97. defaultMessage: '确认删除?',
  98. })}
  99. onConfirm={async () => {
  100. await service.remove(record.id);
  101. message.success(
  102. intl.formatMessage({
  103. id: 'pages.data.option.success',
  104. defaultMessage: '操作成功!',
  105. }),
  106. );
  107. actionRef.current?.reload();
  108. }}
  109. >
  110. <Tooltip
  111. title={intl.formatMessage({
  112. id: 'pages.data.option.remove',
  113. defaultMessage: '删除',
  114. })}
  115. >
  116. <DeleteOutlined />
  117. </Tooltip>
  118. </Popconfirm>
  119. </a>,
  120. ],
  121. },
  122. ];
  123. const schema = {
  124. type: 'object',
  125. properties: {
  126. name: {
  127. title: intl.formatMessage({
  128. id: 'pages.table.name',
  129. defaultMessage: '角色名称',
  130. }),
  131. type: 'string',
  132. 'x-decorator': 'FormItem',
  133. 'x-component': 'Input',
  134. 'x-component-props': {},
  135. 'x-decorator-props': {},
  136. name: 'name',
  137. required: true,
  138. },
  139. description: {
  140. type: 'string',
  141. title: intl.formatMessage({
  142. id: 'pages.table.describe',
  143. defaultMessage: '描述',
  144. }),
  145. 'x-decorator': 'FormItem',
  146. 'x-component': 'Input.TextArea',
  147. 'x-component-props': {
  148. checkStrength: true,
  149. },
  150. 'x-decorator-props': {},
  151. name: 'password',
  152. required: false,
  153. },
  154. },
  155. };
  156. const location = useLocation();
  157. useEffect(() => {
  158. if ((location as any).query?.save === 'true') {
  159. CurdModel.add();
  160. }
  161. const subscription = Store.subscribe(SystemConst.BASE_UPDATE_DATA, (data) => {
  162. if ((window as any).onTabSaveSuccess) {
  163. (window as any).onTabSaveSuccess(data);
  164. setTimeout(() => window.close(), 300);
  165. }
  166. });
  167. return () => subscription.unsubscribe();
  168. }, []);
  169. return (
  170. <PageContainer>
  171. <BaseCrud<RoleItem>
  172. actionRef={actionRef}
  173. moduleName="role"
  174. columns={columns}
  175. service={service}
  176. search={false}
  177. title={intl.formatMessage({
  178. id: 'pages.system.role',
  179. defaultMessage: '角色列表',
  180. })}
  181. schema={schema}
  182. />
  183. </PageContainer>
  184. );
  185. });
  186. export default Role;