import { Badge, Button, Col, Input, message, Modal, Popconfirm, Row, Spin, Tooltip, Tree, } from 'antd'; import { observer } from '@formily/react'; import { service, state } from '..'; import type { ActionType, ProColumns } from '@jetlinks/pro-table'; import ProTable from '@jetlinks/pro-table'; import { useEffect, useRef, useState } from 'react'; import { history, useLocation } from 'umi'; import { DisconnectOutlined, EditOutlined } from '@ant-design/icons'; import BindUser from '../BindUser'; const SyncUser = observer(() => { const [dept, setDept] = useState(); const location = useLocation<{ id: string }>(); const id = (location as any).query?.id; const [visible, setVisible] = useState(false); const [current, setCurrent] = useState({}); const [list, setList] = useState([]); const idMap = { dingTalk: '钉钉', weixin: '微信', }; const actionRef = useRef(); const columns: ProColumns[] = [ { dataIndex: 'thirdPartyUserName', title: `${idMap[id]}用户名`, }, { dataIndex: 'userId', title: `用户`, render: (text: any, record: any) => ( {record?.userId ? `${record?.userName}(${record?.username})` : '--'} ), }, { dataIndex: 'status', title: '绑定状态', render: (text: any, record: any) => ( ), }, { dataIndex: 'action', title: '操作', render: (text: any, record: any) => [ , {record?.status === 1 && ( )} , ], }, ]; const [treeData, setTreeData] = useState([]); const [loading, setLoading] = useState(true); /** * 获取部门列表 */ const getDepartment = async () => { if (state.current?.id) { if (id === 'dingTalk') { service.syncUser .dingTalkDept(state.current?.id) .then((resp) => { if (resp.status === 200) { setTreeData(resp.result); setDept(resp.result[0].id); } }) .finally(() => setLoading(false)); } else if (id === 'weixin') { service.syncUser .wechatDept(state.current?.id) .then((resp) => { if (resp.status === 200) { setTreeData(resp.result); setDept(resp.result[0].id); } }) .finally(() => setLoading(false)); } } }; useEffect(() => { if (!state.current?.id) { history.goBack(); } getDepartment(); }, [id]); return ( (state.syncUser = false)} width="80vw" >
{ setDept(key[0] as string); }} treeData={treeData} />
{dept && ( service .queryZipSyncUser( { dingTalk: 'dingtalk', weixin: 'wechat', }[id], id, state.current?.provider || '', state.current?.id || '', params.dept || '', ) .then((resp: any) => { setList(resp); return { code: '', result: { data: resp || [], pageIndex: 0, pageSize: 0, total: 0, }, status: 200, }; }) } headerTitle={ { const arr = list .filter((item) => item.status === 0) .map((i) => { return { userId: i.userId, providerName: i.userName, thirdPartyUserId: i.thirdPartyUserId, }; }); const resp = await service.syncUser.bindUser( id, state.current?.provider || '', state.current?.id || '', [...arr], ); if (resp.status === 200) { message.success('操作成功!'); actionRef.current?.reload(); } }} > } /> )}
{visible && ( { setCurrent({}); setVisible(false); }} data={current} reload={() => { setCurrent({}); setVisible(false); actionRef.current?.reload(); }} /> )}
); }); export default SyncUser;