|
@@ -12,11 +12,12 @@ const { DirectoryTree } = Tree
|
|
|
|
|
|
type LeftMenuProps = {
|
|
type LeftMenuProps = {
|
|
onSelect: (key: string) => void
|
|
onSelect: (key: string) => void
|
|
|
|
+ defaultActiveID: string
|
|
options: API.DataSourceMenuItem[]
|
|
options: API.DataSourceMenuItem[]
|
|
initFn: () => Promise<void>
|
|
initFn: () => Promise<void>
|
|
}
|
|
}
|
|
|
|
|
|
-const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options, showDelIcon, initFn }) => {
|
|
|
|
|
|
+const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, defaultActiveID, options, showDelIcon, initFn }) => {
|
|
const [activeID, setActiveID] = useState<Nullable<string>>(null)
|
|
const [activeID, setActiveID] = useState<Nullable<string>>(null)
|
|
const formRef = useRef<ProFormInstance>(null)
|
|
const formRef = useRef<ProFormInstance>(null)
|
|
const handleOnSelect: DirectoryTreeProps['onSelect'] = (keys, node) => {
|
|
const handleOnSelect: DirectoryTreeProps['onSelect'] = (keys, node) => {
|
|
@@ -80,19 +81,21 @@ const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options, showDelIcon, ini
|
|
)}
|
|
)}
|
|
<div className="extra">
|
|
<div className="extra">
|
|
<FormOutlined className="pr-2" onClick={() => setActiveID(item.ID)} />
|
|
<FormOutlined className="pr-2" onClick={() => setActiveID(item.ID)} />
|
|
- <Popconfirm
|
|
|
|
- disabled={!showDelIcon}
|
|
|
|
- title="确认删除吗?"
|
|
|
|
- onText="确认"
|
|
|
|
- cancelText="取消"
|
|
|
|
- onConfirm={() => tryDelRole(item.ID)}
|
|
|
|
- icon={<QuestionCircleOutlined style={{ color: 'red' }} />}>
|
|
|
|
- <DeleteOutlined
|
|
|
|
- onClick={() => {
|
|
|
|
- !showDelIcon && message.warning('该数据源已绑定子项,不允许删除')
|
|
|
|
- }}
|
|
|
|
- />
|
|
|
|
- </Popconfirm>
|
|
|
|
|
|
+ {item.ID === defaultActiveID ? (
|
|
|
|
+ <Popconfirm
|
|
|
|
+ disabled={!showDelIcon}
|
|
|
|
+ title="确认删除吗?"
|
|
|
|
+ onText="确认"
|
|
|
|
+ cancelText="取消"
|
|
|
|
+ onConfirm={() => tryDelRole(item.ID)}
|
|
|
|
+ icon={<QuestionCircleOutlined style={{ color: 'red' }} />}>
|
|
|
|
+ <DeleteOutlined
|
|
|
|
+ onClick={() => {
|
|
|
|
+ !showDelIcon && message.warning('该数据源已绑定子项,不允许删除')
|
|
|
|
+ }}
|
|
|
|
+ />
|
|
|
|
+ </Popconfirm>
|
|
|
|
+ ) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
)
|
|
@@ -141,13 +144,16 @@ const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options, showDelIcon, ini
|
|
id="role-list"
|
|
id="role-list"
|
|
className="p-4 bg-white rounded-b-20px"
|
|
className="p-4 bg-white rounded-b-20px"
|
|
style={{ height: 'calc(100% - 1rem*2 - 20px)' }}>
|
|
style={{ height: 'calc(100% - 1rem*2 - 20px)' }}>
|
|
- <DirectoryTree
|
|
|
|
- treeData={renderTreeNode(options.map(item => ({ title: item.name, key: item.ID, ...item })))}
|
|
|
|
- height={virtualHeigh - 32}
|
|
|
|
- onSelect={handleOnSelect}
|
|
|
|
- showIcon={false}
|
|
|
|
- defaultExpandAll
|
|
|
|
- />
|
|
|
|
|
|
+ {options.length ? (
|
|
|
|
+ <DirectoryTree
|
|
|
|
+ treeData={renderTreeNode(options.map(item => ({ title: item.name, key: item.ID, ...item })))}
|
|
|
|
+ height={virtualHeigh - 32}
|
|
|
|
+ defaultSelectedKeys={[options[0]?.ID]}
|
|
|
|
+ onSelect={handleOnSelect}
|
|
|
|
+ showIcon={false}
|
|
|
|
+ defaultExpandAll
|
|
|
|
+ />
|
|
|
|
+ ) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
)
|