index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 } from 'antd';
  5. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  6. import BaseCrud from '@/components/BaseCrud';
  7. import Service from './service';
  8. import { useIntl } from '@@/plugin-locale/localeExports';
  9. import { observer } from '@formily/react';
  10. import { history, useLocation } from 'umi';
  11. import { Store } from 'jetlinks-store';
  12. import SystemConst from '@/utils/const';
  13. import { CurdModel } from '@/components/BaseCrud/model';
  14. import { getButtonPermission, getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
  15. import { PermissionButton } from '@/components';
  16. export const service = new Service('role');
  17. const Role: React.FC = observer(() => {
  18. const intl = useIntl();
  19. const actionRef = useRef<ActionType>();
  20. const permissionCode = 'system/Role';
  21. const { permission } = PermissionButton.usePermission(permissionCode);
  22. const columns: ProColumns<RoleItem>[] = [
  23. // {
  24. // dataIndex: 'index',
  25. // valueType: 'indexBorder',
  26. // width: 48,
  27. // },
  28. {
  29. title: intl.formatMessage({
  30. id: 'pages.system.role.id',
  31. defaultMessage: '标识',
  32. }),
  33. dataIndex: 'id',
  34. // copyable: true,
  35. ellipsis: true,
  36. // sorter: true,
  37. // defaultSortOrder: 'ascend',
  38. formItemProps: {
  39. rules: [
  40. {
  41. required: true,
  42. message: '此项为必填项',
  43. },
  44. ],
  45. },
  46. },
  47. {
  48. title: intl.formatMessage({
  49. id: 'pages.table.name',
  50. defaultMessage: '名称',
  51. }),
  52. dataIndex: 'name',
  53. // copyable: true,
  54. ellipsis: true,
  55. // tip: intl.formatMessage({
  56. // id: 'pages.system.userName.tips',
  57. // defaultMessage: '用户名过长会自动收缩',
  58. // }),
  59. formItemProps: {
  60. rules: [
  61. {
  62. required: true,
  63. message: '此项为必填项',
  64. },
  65. ],
  66. },
  67. },
  68. {
  69. title: intl.formatMessage({
  70. id: 'pages.table.describe',
  71. defaultMessage: '描述',
  72. }),
  73. ellipsis: true,
  74. dataIndex: 'description',
  75. filters: true,
  76. onFilter: true,
  77. },
  78. {
  79. title: intl.formatMessage({
  80. id: 'pages.data.option',
  81. defaultMessage: '操作',
  82. }),
  83. valueType: 'option',
  84. width: 200,
  85. render: (text, record) => [
  86. <PermissionButton
  87. key="editable"
  88. tooltip={{
  89. title: intl.formatMessage({
  90. id: 'pages.data.option.edit',
  91. defaultMessage: '编辑',
  92. }),
  93. }}
  94. isPermission={permission.update}
  95. style={{ padding: 0 }}
  96. type="link"
  97. onClick={() => {
  98. history.push(`${getMenuPathByParams(MENUS_CODE['system/Role/Detail'], record.id)}`);
  99. }}
  100. >
  101. <EditOutlined />
  102. </PermissionButton>,
  103. <PermissionButton
  104. type="link"
  105. key="delete"
  106. style={{ padding: 0 }}
  107. popConfirm={{
  108. title: intl.formatMessage({
  109. id: 'pages.system.role.option.delete',
  110. defaultMessage: '确定要删除吗',
  111. }),
  112. onConfirm: async () => {
  113. await service.remove(record.id);
  114. message.success(
  115. intl.formatMessage({
  116. id: 'pages.data.option.success',
  117. defaultMessage: '操作成功!',
  118. }),
  119. );
  120. actionRef.current?.reload();
  121. },
  122. }}
  123. tooltip={{
  124. title: intl.formatMessage({
  125. id: 'pages.data.option.delete',
  126. defaultMessage: '删除',
  127. }),
  128. }}
  129. isPermission={permission.delete}
  130. >
  131. <DeleteOutlined />
  132. </PermissionButton>,
  133. ],
  134. },
  135. ];
  136. const schema = {
  137. type: 'object',
  138. properties: {
  139. name: {
  140. title: intl.formatMessage({
  141. id: 'pages.table.name',
  142. defaultMessage: '角色名称',
  143. }),
  144. type: 'string',
  145. 'x-decorator': 'FormItem',
  146. 'x-component': 'Input',
  147. 'x-decorator-props': {},
  148. name: 'name',
  149. required: true,
  150. 'x-component-props': {
  151. placeholder: '请输入角色名称',
  152. },
  153. 'x-validator': [
  154. {
  155. max: 64,
  156. message: '最多可输入64个字符',
  157. },
  158. {
  159. required: true,
  160. message: '请输入名称',
  161. },
  162. ],
  163. },
  164. description: {
  165. type: 'string',
  166. title: intl.formatMessage({
  167. id: 'pages.table.describe',
  168. defaultMessage: '描述',
  169. }),
  170. 'x-decorator': 'FormItem',
  171. 'x-component': 'Input.TextArea',
  172. 'x-component-props': {
  173. checkStrength: true,
  174. placeholder: '请输入说明',
  175. },
  176. 'x-decorator-props': {},
  177. name: 'password',
  178. required: false,
  179. 'x-validator': [
  180. {
  181. max: 200,
  182. message: '最多可输入200个字符',
  183. },
  184. ],
  185. },
  186. },
  187. };
  188. const location = useLocation();
  189. useEffect(() => {
  190. if ((location as any).query?.save === 'true') {
  191. CurdModel.add();
  192. }
  193. const subscription = Store.subscribe(SystemConst.BASE_UPDATE_DATA, (data) => {
  194. console.log('订阅数据');
  195. if ((window as any).onTabSaveSuccess) {
  196. (window as any).onTabSaveSuccess(data);
  197. setTimeout(() => window.close(), 300);
  198. }
  199. });
  200. return () => subscription.unsubscribe();
  201. }, []);
  202. return (
  203. <PageContainer>
  204. <BaseCrud<RoleItem>
  205. disableAdd={getButtonPermission('system/Role', ['add'])}
  206. actionRef={actionRef}
  207. moduleName="role"
  208. columns={columns}
  209. service={service}
  210. search={false}
  211. title={intl.formatMessage({
  212. id: 'pages.system.role',
  213. defaultMessage: '角色列表',
  214. })}
  215. schema={schema}
  216. />
  217. </PageContainer>
  218. );
  219. });
  220. export default Role;