import {CurdColumn, CurdPage} from "../../../components/curd"; import {useCallback, useMemo, useState} from "react"; import {LDAP, LDAPApis} from "../../../api/ldap.ts"; import {ICurdConfig} from "../../../components/curd/types.ts"; import {Button, Form, Input, Modal, Switch, Table} from "antd"; import './index.less' import {Message} from "auto-antd"; import {Link} from "react-router-dom"; const columns: CurdColumn[] = [ { key: 'id', title: 'ID', type: 'string', disabled: true, required: false, width: 50 }, { key: 'key', title: '服务编码', type: 'string', disabled: true, placeholder: '服务唯一编码,自动生成', required: false, width: 120 }, { key: 'url', title: '服务Url', type: 'string', placeholder: 'eg. ldap://192.168.1.1:389', width: 150 }, { key: 'userName', title: '管理员账号', type: 'string', width: 150 }, { key: 'password', title: '管理员密码', type: 'password', hidden: true, }, { key: 'baseDN', type: 'string', title: 'baseDN', placeholder: 'eg. ou=users,dc=xxxx,dc=cn' }, { key: 'filter', title: '过滤配置', type: 'string', placeholder: '默认:(objectClass=*)', required: false, width: 180 }, { title: '组织ObjectClass', key: 'organizeClass', type: 'string', }, { key: 'remark', title: '备注', type: 'textarea', required: false, } ] const serverConfig: ICurdConfig = { editDialogWidth: 500, labelSpan: 6, } type VerifyData = Partial & { search?: string } export const Server = () => { const [verifyData, setVerifyData] = useState() const [loading, setLoading] = useState(false) const [searchUsers, setSearchUsers] = useState([]) const getList = useCallback((query: any) => { return LDAPApis.getServerList(query).then(res => { console.log('server', res) return res.data.data }) }, []) const getDetail = (data: Partial) => { if (!data.id) { return Promise.resolve({} as LDAP.Server) } return LDAPApis.getServer(data.id).then(res => { if (res) { return res; } throw new Error('该服务不存在!') }) } const onSaveServer = (data: Partial) => { return LDAPApis.saveServer(data) .then(res => { return res.data.data as LDAP.Server; }) } const operationRender = (record: LDAP.Server, _: number) => { return (<> ) } const config = useMemo(() => { return { ...serverConfig, operationRender } as ICurdConfig }, []) const onChange = (data: Partial) => { setVerifyData(verify => ({...verify, ...data})) } const onVerify = () => { if (!verifyData?.id) { return } setLoading(true) LDAPApis.verifyServer({id: verifyData.id, active: verifyData.active, username: verifyData.search}) .then(res => { setLoading(false) setSearchUsers(res.data || []) Message.success('操作成功!') }) .finally(() => { setLoading(false) }) } return (<> setVerifyData(data)} config={config}/> setVerifyData(undefined)} confirmLoading={loading} width={600} onOk={onVerify}>
{verifyData?.url} {verifyData?.userName} {verifyData?.baseDN} onChange({active: ev})}> onChange({search: ev.target.value})}/>
) }