|
@@ -0,0 +1,113 @@
|
|
|
+import {
|
|
|
+ DeleteOutlined,
|
|
|
+ FormOutlined,
|
|
|
+ PlusOutlined,
|
|
|
+ QuestionCircleOutlined
|
|
|
+} from '@ant-design/icons'
|
|
|
+import { ModalForm, ProFormText } from '@ant-design/pro-form'
|
|
|
+
|
|
|
+import { Button, Input, Popconfirm, Tree } from 'antd'
|
|
|
+import type { DirectoryTreeProps } from 'antd/lib/tree'
|
|
|
+import '@/pages/Permission/Role/components/RoleLeftMenu/index.less'
|
|
|
+import { addDataSource } from '@/services/api/schema'
|
|
|
+
|
|
|
+const { DirectoryTree } = Tree
|
|
|
+
|
|
|
+type LeftMenuProps = {
|
|
|
+ onSelect: (key: string) => void
|
|
|
+ options: API.DataSourceMenuItem[]
|
|
|
+ initFn: () => Promise<void>
|
|
|
+}
|
|
|
+
|
|
|
+const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options }) => {
|
|
|
+ const handleOnSelect: DirectoryTreeProps['onSelect'] = keys => {
|
|
|
+ console.log('Trigger Select', keys, info)
|
|
|
+ onSelect?.(keys[0])
|
|
|
+ }
|
|
|
+
|
|
|
+ const renderTreeNode = tree => {
|
|
|
+ return tree.map((item: API.DataSourceMenuItem & { title: string; key: string }) => {
|
|
|
+ const newItem = {
|
|
|
+ ...item,
|
|
|
+ title: (
|
|
|
+ <div className="department-node py-1">
|
|
|
+ {item.ID === activeID ? (
|
|
|
+ <Input
|
|
|
+ autoFocus
|
|
|
+ defaultValue={item.name}
|
|
|
+ bordered={false}
|
|
|
+ size="small"
|
|
|
+ style={{ width: '70%', backgroundColor: 'white' }}
|
|
|
+ onBlur={e => handleOnFocus(e, item.name, item.ID)}
|
|
|
+ onPressEnter={e => handleOnFocus(e, item.name, item.ID)}
|
|
|
+ />
|
|
|
+ ) : (
|
|
|
+ <div className="title">{item.name}</div>
|
|
|
+ )}
|
|
|
+ <div className="extra">
|
|
|
+ <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>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (newItem.children?.length) {
|
|
|
+ newItem.children = renderTreeNode(newItem.items)
|
|
|
+ }
|
|
|
+ return newItem
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <div className="w-54 rounded-20px flex flex-col bg-white ">
|
|
|
+ <div className="p-4 border-b-1 rounded-tl-20px rounded-tr-20px border-solid border-black border-opacity-10 bg-hex-f7f9fa flex justify-around items-center flex-row">
|
|
|
+ <div className="text-base">数据源列表</div>
|
|
|
+ <ModalForm
|
|
|
+ layout="horizontal"
|
|
|
+ title="新增数据源"
|
|
|
+ width="30%"
|
|
|
+ isKeyPressSubmit
|
|
|
+ labelCol={{ span: 5 }}
|
|
|
+ trigger={
|
|
|
+ <Button size="small" type="primary" ghost>
|
|
|
+ <PlusOutlined />
|
|
|
+ 添加
|
|
|
+ </Button>
|
|
|
+ }
|
|
|
+ onFinish={async values => {
|
|
|
+ const { code = -1 } = await addDataSource(values)
|
|
|
+ return code === consts.RET_CODE.SUCCESS
|
|
|
+ }}>
|
|
|
+ <ProFormText
|
|
|
+ label="数据源名称"
|
|
|
+ name="name"
|
|
|
+ rules={[{ required: true, message: '请输入数据源名称' }]}
|
|
|
+ />
|
|
|
+ <ProFormText label="URL" name="url" required disabled placeholder="自动生成" />
|
|
|
+ </ModalForm>
|
|
|
+ </div>
|
|
|
+ <div className="flex-1">
|
|
|
+ <DirectoryTree
|
|
|
+ treeData={renderTreeNode(
|
|
|
+ options.map(item => ({ title: item.name, key: item.ID, ...item }))
|
|
|
+ )}
|
|
|
+ onSelect={handleOnSelect}
|
|
|
+ defaultExpandAll
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default LeftMenu
|