import '@wangeditor/editor/dist/css/style.css'; import { Col, Radio, Row, Space, Spin, Typography } from 'antd'; import type { Key } from 'react'; import { forwardRef, useContext, useEffect, useImperativeHandle, useState } from 'react'; import { FormattedMessage, useIntl, useRequest } from 'umi'; import AppInfoDescriptions from '../AppInfoDescriptions'; import AgentPermission from '../AuditList/AgentPermission'; import SearchTree from '../SearchTree'; import UserSelectList from '../UserSelect/list'; import UserSuperiorName from '../UserSuperior/name'; import UserSuperiorTime from '../UserSuperior/time'; import { formatUserRender } from '../utils'; import { flatArray2Tree, tree2FlatArray } from '../utils/array'; import { AppDetailContext } from '../utils/hooks'; export interface NavProps { value: 1 | 2 | 3; setValue: (v: 1 | 2 | 3) => void; /** 多个申请、单个、运营端配置*/ type?: 'multiple' | 'single' | 'operation'; currentUser?: API.CurrentUser; appId?: number; selectAgent?: any; setSelectAgent?: (o: any) => void; checkedAgentKeys?: Key[]; setCheckedAgentKeys?: (keys: Key[]) => void; } export interface NavRef { reset: () => void; getType: () => number; getOtherUsers: () => any[]; } const Nav = forwardRef((props, ref) => { const { value, setValue, type = 'single', currentUser, appId, // selectAgent, setSelectAgent, checkedAgentKeys, setCheckedAgentKeys, } = props; const { applyInstructions, isAgent } = useContext(AppDetailContext); const { formatMessage } = useIntl(); const [list, setList] = useState([]); useImperativeHandle(ref, () => ({ reset: () => { setList([]); setValue(1); }, getType: () => value, getOtherUsers: () => list, })); const selfRender = () => (
{formatUserRender({ account: currentUser?.nameEn, state: currentUser?.state, name: currentUser?.nameZh, })}
); const otherRender = () => (
setList(val)} state={1} />
); const { data: treeData, run, loading, } = useRequest( () => ({ url: '/goapi/feature/user/selectable/list', method: 'POST', data: { appId }, }), { ready: !!appId, manual: true, formatResult: (res) => { const tree = res?.data?.data ?? []; const flat = tree2FlatArray(tree).map((o: any) => ({ ...o, name: `${o.name}(${o.uniqueKey})`, })); return flatArray2Tree(flat); }, onSuccess: (l) => { const [index] = l ?? []; setSelectAgent?.( index ? { ...index, name: index.name, id: index.id, } : undefined, ); setCheckedAgentKeys?.([]); }, }, ); useEffect(() => { if (value === 3 && appId) { run(); } }, [appId, run, value]); const agentRender = () => { return (
( {node.name} {!!appId && ( )} )} checkedKeys={checkedAgentKeys} onCheck={(keys) => setCheckedAgentKeys?.(Array.isArray(keys) ? keys : keys.checked)} // selectedKeys={selectAgent ? [selectAgent.id] : undefined} // onSelect={(__, info) => setSelectAgent?.(info.node)} />
); }; const valueRenderMap = { 1: selfRender, 2: otherRender, 3: agentRender, }; return ( {type === 'single' && (
{ setValue(e.target.value); setCheckedAgentKeys?.([]); }} value={value} > {isAgent && ( )}
)} {valueRenderMap[value]?.()} {type === 'single' && value !== 3 && appId && ( <> } />
)} ); }); export default Nav;