| | |
| | | onClick={() => column.id === 'name' && toggleNode(row.id)} |
| | | sx={{ |
| | | opacity: column.id === 'icon' ? 0.6 : (depth > 0 ? opacity : 1), |
| | | color: depth > 0 ? `rgba(0, 0, 0, ${opacity})` : 'inherit', |
| | | fontWeight: 400, |
| | | // 使用字体大小或颜色来区分层级 |
| | | fontSize: depth === 0 ? '0.95rem' : '0.9rem', |
| | |
| | | const [editRecord, setEditRecord] = React.useState(null); |
| | | const [openNodes, setOpenNodes] = React.useState({}); |
| | | const [expandAll, setExpandAll] = React.useState(false); |
| | | const notifyState = React.useRef({ last: '', at: 0 }); |
| | | const pushNotify = React.useCallback((type, msg) => { |
| | | const text = typeof msg === 'string' ? msg : (msg || ''); |
| | | const now = Date.now(); |
| | | if (notifyState.current.last === text && now - notifyState.current.at < 1500) return; |
| | | notifyState.current = { last: text, at: now }; |
| | | notify(text, { type, messageArgs: { _: text } }); |
| | | }, [notify]); |
| | | |
| | | const http = async () => { |
| | | const res = await request.post(RESOURCE + '/tree', { |
| | |
| | | if (res?.data?.code === 200) { |
| | | setTreeData(res.data.data); |
| | | } else { |
| | | notify(res.data.msg); |
| | | const msg = translate('ra.notification.http_error', { _: res?.data?.msg || 'Request failed' }); |
| | | pushNotify('warning', msg); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | onSuccess: () => { |
| | | handleRefresh(); |
| | | notify('Department deleted successfully', { type: 'info', messageArgs: { _: 'Department deleted successfully' } }); |
| | | const msg = translate('ra.message.delete_success', { _: 'Deleted successfully' }); |
| | | pushNotify('success', msg); |
| | | }, |
| | | onError: (error) => { |
| | | notify(`Error: ${error.message}`, { type: 'warning', messageArgs: { _: `Error: ${error.message}` } }); |
| | | const msg = translate('ra.notification.http_error', { _: error?.message || 'Network error' }); |
| | | pushNotify('error', msg); |
| | | }, |
| | | } |
| | | ); |
| | |
| | | const newExpandAll = !prevExpandAll; |
| | | const newOpenNodes = {}; |
| | | const updateOpenNodes = (nodes) => { |
| | | if (!nodes) return; |
| | | nodes.forEach(node => { |
| | | newOpenNodes[node.id] = newExpandAll; |
| | | if (node.children) { |
| | |
| | | ); |
| | | }; |
| | | |
| | | export default MenuList; |
| | | export default MenuList; |