index.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // 部门-用户管理
  2. import type { ActionType, ProColumns } from '@jetlinks/pro-table';
  3. import ProTable from '@jetlinks/pro-table';
  4. import { useIntl } from '@@/plugin-locale/localeExports';
  5. import { Badge, Button, Popconfirm, Tooltip } from 'antd';
  6. import { useEffect, useRef, useState } from 'react';
  7. import { observer } from '@formily/react';
  8. import MemberModel from '@/pages/system/Department/Member/model';
  9. import type { MemberItem } from '@/pages/system/Department/typings';
  10. import Service from '@/pages/system/Department/Member/service';
  11. import { DisconnectOutlined, PlusOutlined } from '@ant-design/icons';
  12. import Bind from './bind';
  13. import SearchComponent from '@/components/SearchComponent';
  14. import Models from '@/pages/system/Department/Assets/productCategory/model';
  15. import { onlyMessage } from '@/utils/util';
  16. export const service = new Service('tenant');
  17. const Member = observer((props: { parentId: string }) => {
  18. const intl = useIntl();
  19. const actionRef = useRef<ActionType>();
  20. const [searchParam, setSearchParam] = useState({});
  21. const handleUnBind = () => {
  22. if (MemberModel.unBindUsers.length) {
  23. service.handleUser(props.parentId, MemberModel.unBindUsers, 'unbind').subscribe({
  24. next: () => onlyMessage('操作成功'),
  25. error: () => onlyMessage('操作失败', 'error'),
  26. complete: () => {
  27. MemberModel.unBindUsers = [];
  28. actionRef.current?.reload();
  29. },
  30. });
  31. } else {
  32. onlyMessage('请勾选需要解绑的数据', 'warning');
  33. }
  34. };
  35. const singleUnBind = (key: string) => {
  36. MemberModel.unBindUsers = [key];
  37. handleUnBind();
  38. };
  39. const columns: ProColumns<MemberItem>[] = [
  40. {
  41. dataIndex: 'name',
  42. title: intl.formatMessage({
  43. id: 'pages.system.name',
  44. defaultMessage: '姓名',
  45. }),
  46. search: {
  47. transform: (value) => ({ name$LIKE: value }),
  48. },
  49. width: 120,
  50. fixed: 'left',
  51. },
  52. {
  53. dataIndex: 'username',
  54. title: intl.formatMessage({
  55. id: 'pages.system.username',
  56. defaultMessage: '用户名',
  57. }),
  58. // search: {
  59. // transform: (value) => ({ username$LIKE: value }),
  60. // },
  61. width: 120,
  62. },
  63. {
  64. title: intl.formatMessage({
  65. id: 'pages.searchTable.titleStatus',
  66. defaultMessage: '状态',
  67. }),
  68. dataIndex: 'status',
  69. filters: true,
  70. onFilter: true,
  71. valueType: 'select',
  72. valueEnum: {
  73. all: {
  74. text: intl.formatMessage({
  75. id: 'pages.searchTable.titleStatus.all',
  76. defaultMessage: '全部',
  77. }),
  78. status: 'Default',
  79. },
  80. 1: {
  81. text: intl.formatMessage({
  82. id: 'pages.searchTable.titleStatus.normal',
  83. defaultMessage: '正常',
  84. }),
  85. status: 1,
  86. },
  87. 0: {
  88. text: intl.formatMessage({
  89. id: 'pages.searchTable.titleStatus.disable',
  90. defaultMessage: '禁用',
  91. }),
  92. status: 0,
  93. },
  94. },
  95. render: (_, data) => (
  96. <Badge
  97. status={data.status === 1 ? 'success' : 'error'}
  98. text={
  99. data.status === 1
  100. ? intl.formatMessage({
  101. id: 'pages.searchTable.titleStatus.normal',
  102. defaultMessage: '正常',
  103. })
  104. : intl.formatMessage({
  105. id: 'pages.searchTable.titleStatus.disable',
  106. defaultMessage: '禁用',
  107. })
  108. }
  109. />
  110. ),
  111. width: 80,
  112. },
  113. {
  114. title: intl.formatMessage({
  115. id: 'pages.data.option',
  116. defaultMessage: '操作',
  117. }),
  118. valueType: 'option',
  119. width: 60,
  120. ellipsis: true,
  121. fixed: 'right',
  122. render: (text, record) => [
  123. <Popconfirm
  124. title={intl.formatMessage({
  125. id: 'pages.system.role.option.unBindUser',
  126. defaultMessage: '是否解除绑定',
  127. })}
  128. key="unBindUser"
  129. onConfirm={() => {
  130. singleUnBind(record.id);
  131. }}
  132. >
  133. <Button type={'link'} style={{ padding: 0 }}>
  134. <Tooltip
  135. title={intl.formatMessage({
  136. id: 'pages.system.role.option.unBindUser',
  137. defaultMessage: '解绑',
  138. })}
  139. >
  140. <DisconnectOutlined />
  141. </Tooltip>
  142. </Button>
  143. </Popconfirm>,
  144. ],
  145. },
  146. ];
  147. const closeModal = () => {
  148. MemberModel.bind = false;
  149. };
  150. useEffect(() => {
  151. setSearchParam({
  152. terms: [{ column: 'id$in-dimension$org', value: props.parentId }],
  153. });
  154. actionRef.current?.reset?.();
  155. // 初始化所有状态
  156. Models.bindKeys = [];
  157. Models.unBindKeys = [];
  158. }, [props.parentId]);
  159. return (
  160. <>
  161. {MemberModel.bind && (
  162. <Bind
  163. visible={MemberModel.bind}
  164. onCancel={closeModal}
  165. reload={() => actionRef.current?.reload()}
  166. parentId={props.parentId}
  167. />
  168. )}
  169. <SearchComponent<MemberItem>
  170. // pattern={'simple'}
  171. field={columns}
  172. defaultParam={[{ column: 'id$in-dimension$org', value: props.parentId }]}
  173. onSearch={async (data) => {
  174. actionRef.current?.reset?.();
  175. setSearchParam(data);
  176. }}
  177. // onReset={() => {
  178. // // 重置分页及搜索参数
  179. // actionRef.current?.reset?.();
  180. // setSearchParam({});
  181. // }}
  182. target="department-user"
  183. />
  184. <ProTable<MemberItem>
  185. actionRef={actionRef}
  186. columns={columns}
  187. search={false}
  188. rowKey="id"
  189. columnEmptyText={''}
  190. request={(params) => {
  191. params.sorts = [{ name: 'createTime', order: 'desc' }];
  192. if (!props.parentId) {
  193. return {
  194. code: 200,
  195. result: {
  196. data: [],
  197. pageIndex: 0,
  198. pageSize: 0,
  199. total: 0,
  200. },
  201. status: 200,
  202. };
  203. }
  204. return service.queryUser(params);
  205. }}
  206. rowSelection={{
  207. selectedRowKeys: MemberModel.unBindUsers,
  208. onChange: (selectedRowKeys, selectedRows) => {
  209. MemberModel.unBindUsers = selectedRows.map((item) => item.id);
  210. },
  211. }}
  212. params={searchParam}
  213. toolBarRender={() => [
  214. <Button
  215. onClick={() => {
  216. MemberModel.bind = true;
  217. }}
  218. icon={<PlusOutlined />}
  219. type="primary"
  220. key="bind"
  221. disabled={!props.parentId}
  222. >
  223. {intl.formatMessage({
  224. id: 'pages.system.role.option.bindUser',
  225. defaultMessage: '绑定用户',
  226. })}
  227. </Button>,
  228. <Popconfirm
  229. title={intl.formatMessage({
  230. id: 'pages.system.role.option.unBinds',
  231. defaultMessage: '是否批量解除绑定',
  232. })}
  233. key="unBind"
  234. onConfirm={handleUnBind}
  235. >
  236. <Button icon={<DisconnectOutlined />}>
  237. {intl.formatMessage({
  238. id: 'pages.system.role.option.unBindUser',
  239. defaultMessage: '批量解绑',
  240. })}
  241. </Button>
  242. </Popconfirm>,
  243. ]}
  244. />
  245. </>
  246. );
  247. });
  248. export default Member;