index.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { fetchRoleBgStaffListByRoleId, linkRoleBgAccount } from '@/services/api/permission'
  2. import { PlusOutlined } from '@ant-design/icons'
  3. import { ModalForm, ProFormSelect } from '@ant-design/pro-form'
  4. import { Button, message } from 'antd'
  5. import { useEffect, useRef, useState } from 'react'
  6. import type { ProFormInstance } from '@ant-design/pro-form'
  7. import { useRequest } from '@umijs/max'
  8. const ConnectModal = ({ dataId, onReload }) => {
  9. const formRef = useRef<ProFormInstance>(null)
  10. const [menuRoles, setMenuRoles] = useState([])
  11. const { run: tryGetRoleBgStaffList } = useRequest(
  12. (params: { roleID: string; search?: string }) =>
  13. fetchRoleBgStaffListByRoleId({ current: 1, pageSize: 214000, ...params }),
  14. {
  15. manual: true,
  16. onSuccess: result => {
  17. setMenuRoles(result.items)
  18. }
  19. }
  20. )
  21. const { run: tryConnectRoleBgAccount } = useRequest(
  22. (params: API.LinkAccountParams) => linkRoleBgAccount(params),
  23. {
  24. manual: true,
  25. onSuccess: async () => {
  26. await onReload()
  27. }
  28. }
  29. )
  30. useEffect(() => {
  31. tryGetRoleBgStaffList()
  32. }, [])
  33. return (
  34. <ModalForm
  35. formRef={formRef}
  36. title="添加用户"
  37. width="30%"
  38. onVisibleChange={visible => !visible && formRef.current?.resetFields()}
  39. layout="horizontal"
  40. trigger={
  41. <Button size="small" type="primary" ghost>
  42. <PlusOutlined />
  43. 添加用户
  44. </Button>
  45. }
  46. onFinish={async values => {
  47. await tryConnectRoleBgAccount({ ...values, ID: dataId })
  48. message.success('添加成功')
  49. return true
  50. }}>
  51. <ProFormSelect
  52. label="角色名称"
  53. name="accountIDs"
  54. className="w-full"
  55. options={menuRoles?.map(item => ({ value: item.ID, label: item.name }))}
  56. />
  57. </ModalForm>
  58. )
  59. }
  60. export default ConnectModal