import {CloseOutlined} from '@ant-design/icons'; import type {ActionType} from '@jetlinks/pro-table'; import ProTable from '@jetlinks/pro-table'; import {Card, message, Space} from 'antd'; import {observer} from '@formily/react'; import {Store} from 'jetlinks-store'; import SystemConst from '@/utils/const'; import {useEffect, useRef} from 'react'; import {BindModel} from '@/components/BindUser/model'; import {columns, service} from '@/components/BindUser/index'; import {useIntl} from '@@/plugin-locale/localeExports'; const Unbound = observer(() => { const intl = useIntl(); const actionRef = useRef(); useEffect(() => { const listener = Store.subscribe(SystemConst.BIND_USER_STATE, () => actionRef.current?.reload(), ); return () => listener.unsubscribe(); }); const handleBindResult = { next: () => message.success( intl.formatMessage({ id: 'pages.bindUser.bindTheNewUser.success', defaultMessage: '绑定成功', }) ), error: async () => { message.success( intl.formatMessage({ id: 'pages.bindUser.bindTheNewUser.fail', defaultMessage: '绑定失败', })); }, complete: () => { // 通知左侧组件刷新 Store.set(SystemConst.BIND_USER_STATE, 'true'); actionRef.current?.reload(); BindModel.bindUsers = []; }, }; const handleOrgBind = () => { service .saveOrgBind( BindModel.bindUsers.map((item) => item.userId), BindModel.dimension.id!, ) .subscribe(handleBindResult); }; const handleRoleBind = () => { const data = BindModel.bindUsers.map( (item) => ({ ...item, dimensionId: BindModel.dimension.id, dimensionTypeId: BindModel.dimension.type, dimensionName: BindModel.dimension.name, } as BindDataItem), ); service.saveRoleBind(data).subscribe(handleBindResult); }; const handleBind = async () => { const bindType = BindModel.dimension.type; switch (bindType) { case 'role': handleRoleBind(); break; case 'org': handleOrgBind(); break; default: message.error( intl.formatMessage({ id: 'pages.bindUser.bindTheNewUser.typeError', defaultMessage: '绑定类型数据错误', })); } }; return ( { BindModel.bind = false; }} /> } > item.userId), onChange: (selectedRowKeys, selectedRows) => { BindModel.bindUsers = selectedRows.map((item) => ({ userId: item.id, userName: item.name, })); }, }} tableAlertRender={({selectedRowKeys, onCleanSelected}) => ( {intl.formatMessage({ id: 'pages.bindUser.bindTheNewUser.selected', defaultMessage: '已选', })} {selectedRowKeys.length} {intl.formatMessage({ id: 'pages.bindUser.bindTheNewUser.item', defaultMessage: '项', })} {intl.formatMessage({ id: 'pages.bindUser.bindTheNewUser.deselect', defaultMessage: '取消选择', })} )} tableAlertOptionRender={() => ( {intl.formatMessage({ id: 'pages.bindUser.bindTheNewUser.bulkBinds', defaultMessage: '批量绑定', })} )} size="small" columns={columns} pagination={{ pageSize: 7, }} request={async (params) => service.query(params)} defaultParams={{ [`id$in-dimension$${BindModel.dimension.type}$not`]: BindModel.dimension.id, }} /> ); }); export default Unbound;