|
@@ -1,192 +1,149 @@
|
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
import { PageContainer } from '@ant-design/pro-layout';
|
|
|
-import { Card, Col, Input, message, Popconfirm, Row, Space, Tree } from 'antd';
|
|
|
|
|
-import { useEffect, useRef, useState } from 'react';
|
|
|
|
|
|
|
+import { Card, Input, message, Popconfirm, Space, Tooltip, Tree } from 'antd';
|
|
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
import { service } from '@/pages/system/DataSource';
|
|
import { service } from '@/pages/system/DataSource';
|
|
|
-import { useIntl, useLocation } from 'umi';
|
|
|
|
|
-import type { ActionType, ProColumns } from '@jetlinks/pro-table';
|
|
|
|
|
-import PermissionButton from '@/components/PermissionButton';
|
|
|
|
|
|
|
+import { useLocation } from 'umi';
|
|
|
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
|
|
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
-import usePermissions from '@/hooks/permission';
|
|
|
|
|
-import SearchComponent from '@/components/SearchComponent';
|
|
|
|
|
-import ProTable from '@jetlinks/pro-table';
|
|
|
|
|
|
|
+// import usePermissions from '@/hooks/permission';
|
|
|
import DataTable from './DataTable';
|
|
import DataTable from './DataTable';
|
|
|
import styles from './index.less';
|
|
import styles from './index.less';
|
|
|
|
|
+import EditTable from './EditTable';
|
|
|
|
|
+import _ from 'lodash';
|
|
|
|
|
|
|
|
const Management = () => {
|
|
const Management = () => {
|
|
|
const location = useLocation<{ id: string }>();
|
|
const location = useLocation<{ id: string }>();
|
|
|
const id = (location as any).query?.id;
|
|
const id = (location as any).query?.id;
|
|
|
- const intl = useIntl();
|
|
|
|
|
- const actionRef = useRef<ActionType>();
|
|
|
|
|
- const [param, setParam] = useState({});
|
|
|
|
|
- const { permission: userPermission } = usePermissions('system/User');
|
|
|
|
|
|
|
|
|
|
const [rdbList, setRdbList] = useState<any[]>([]);
|
|
const [rdbList, setRdbList] = useState<any[]>([]);
|
|
|
|
|
+ const [allList, setAllList] = useState<any[]>([]);
|
|
|
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState<any[]>([]);
|
|
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState<any[]>([]);
|
|
|
const [visible, setVisible] = useState<boolean>(false);
|
|
const [visible, setVisible] = useState<boolean>(false);
|
|
|
const [current, setCurrent] = useState<any>({});
|
|
const [current, setCurrent] = useState<any>({});
|
|
|
|
|
+ const [model, setModel] = useState<'edit' | 'add' | 'list'>('list');
|
|
|
|
|
+ const [tableList, setTableList] = useState<any[]>([]);
|
|
|
|
|
+ const [param, setParam] = useState<string | undefined>(undefined);
|
|
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
|
|
+ const handleSearch = () => {
|
|
|
service.rdbTree(id).then((resp) => {
|
|
service.rdbTree(id).then((resp) => {
|
|
|
if (resp.status === 200) {
|
|
if (resp.status === 200) {
|
|
|
- setRdbList(resp.result);
|
|
|
|
|
|
|
+ setAllList(resp.result);
|
|
|
setDefaultSelectedKeys([resp.result[0]?.name]);
|
|
setDefaultSelectedKeys([resp.result[0]?.name]);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ handleSearch();
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- actionRef.current?.reload();
|
|
|
|
|
|
|
+ if (defaultSelectedKeys.length > 0) {
|
|
|
|
|
+ service.rdbTables(id, defaultSelectedKeys[0]).then((resp) => {
|
|
|
|
|
+ if (resp.status === 200) {
|
|
|
|
|
+ setTableList(resp.result?.columns || []);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setTableList([]);
|
|
|
|
|
+ }
|
|
|
}, [defaultSelectedKeys]);
|
|
}, [defaultSelectedKeys]);
|
|
|
|
|
|
|
|
- const columns: ProColumns<DataSourceType>[] = [
|
|
|
|
|
- {
|
|
|
|
|
- title: '列名',
|
|
|
|
|
- dataIndex: 'name',
|
|
|
|
|
- ellipsis: true,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title: '类型',
|
|
|
|
|
- dataIndex: 'type',
|
|
|
|
|
- ellipsis: true,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title: '长度',
|
|
|
|
|
- dataIndex: 'length',
|
|
|
|
|
- ellipsis: true,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title: '精度',
|
|
|
|
|
- dataIndex: 'scale',
|
|
|
|
|
- ellipsis: true,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title: '不能为空',
|
|
|
|
|
- dataIndex: 'notnull',
|
|
|
|
|
- ellipsis: true,
|
|
|
|
|
- render: (text, record) => {
|
|
|
|
|
- console.log(record.notnull);
|
|
|
|
|
- return <span>{text ? '是' : '否'}</span>;
|
|
|
|
|
- },
|
|
|
|
|
- valueType: 'select',
|
|
|
|
|
- valueEnum: {
|
|
|
|
|
- true: {
|
|
|
|
|
- text: '是',
|
|
|
|
|
- status: true,
|
|
|
|
|
- },
|
|
|
|
|
- false: {
|
|
|
|
|
- text: '否',
|
|
|
|
|
- status: false,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- dataIndex: 'description',
|
|
|
|
|
- title: '说明',
|
|
|
|
|
- ellipsis: true,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title: intl.formatMessage({
|
|
|
|
|
- id: 'pages.data.option',
|
|
|
|
|
- defaultMessage: '操作',
|
|
|
|
|
- }),
|
|
|
|
|
- valueType: 'option',
|
|
|
|
|
- render: (_, record) => [
|
|
|
|
|
- <PermissionButton
|
|
|
|
|
- style={{ padding: 0 }}
|
|
|
|
|
- type="link"
|
|
|
|
|
- isPermission={userPermission.update}
|
|
|
|
|
- key="editable"
|
|
|
|
|
- onClick={() => {
|
|
|
|
|
- setCurrent(record);
|
|
|
|
|
- setVisible(true);
|
|
|
|
|
- }}
|
|
|
|
|
- tooltip={{
|
|
|
|
|
- title: intl.formatMessage({
|
|
|
|
|
- id: 'pages.data.option.edit',
|
|
|
|
|
- defaultMessage: '编辑',
|
|
|
|
|
- }),
|
|
|
|
|
- }}
|
|
|
|
|
- >
|
|
|
|
|
- <EditOutlined />
|
|
|
|
|
- </PermissionButton>,
|
|
|
|
|
- <PermissionButton
|
|
|
|
|
- type="link"
|
|
|
|
|
- key="delete"
|
|
|
|
|
- style={{ padding: 0 }}
|
|
|
|
|
- isPermission={userPermission.delete}
|
|
|
|
|
- tooltip={{ title: '删除' }}
|
|
|
|
|
- >
|
|
|
|
|
- <Popconfirm
|
|
|
|
|
- onConfirm={async () => {
|
|
|
|
|
- // await service.remove(record.id);
|
|
|
|
|
- // actionRef.current?.reload();
|
|
|
|
|
- }}
|
|
|
|
|
- title="确认删除?"
|
|
|
|
|
- >
|
|
|
|
|
- <DeleteOutlined />
|
|
|
|
|
- </Popconfirm>
|
|
|
|
|
- </PermissionButton>,
|
|
|
|
|
- ],
|
|
|
|
|
- },
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (!!param) {
|
|
|
|
|
+ const list = allList.filter((item) => {
|
|
|
|
|
+ return item.name.includes(param);
|
|
|
|
|
+ });
|
|
|
|
|
+ setRdbList([...list]);
|
|
|
|
|
+ if (!_.map(list, 'name').includes(defaultSelectedKeys[0])) {
|
|
|
|
|
+ setDefaultSelectedKeys([list[0]?.name]);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setRdbList([...allList]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [allList, param]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<PageContainer>
|
|
<PageContainer>
|
|
|
<Card>
|
|
<Card>
|
|
|
- <Row gutter={24}>
|
|
|
|
|
- <Col span={6}>
|
|
|
|
|
|
|
+ <div className={styles.datasourceBox}>
|
|
|
|
|
+ <div className={styles.left}>
|
|
|
<Input.Search
|
|
<Input.Search
|
|
|
placeholder="请输入"
|
|
placeholder="请输入"
|
|
|
- onSearch={() => {}}
|
|
|
|
|
- style={{ width: '100%', marginBottom: 10 }}
|
|
|
|
|
|
|
+ onSearch={(val: string) => {
|
|
|
|
|
+ setParam(val);
|
|
|
|
|
+ }}
|
|
|
|
|
+ allowClear
|
|
|
|
|
+ style={{ width: '100%', marginBottom: 20 }}
|
|
|
/>
|
|
/>
|
|
|
<div className={styles.tables}>
|
|
<div className={styles.tables}>
|
|
|
- <Tree
|
|
|
|
|
- showLine
|
|
|
|
|
- showIcon
|
|
|
|
|
- defaultExpandAll
|
|
|
|
|
- height={500}
|
|
|
|
|
- selectedKeys={[...defaultSelectedKeys]}
|
|
|
|
|
- onSelect={(selectedKeys) => {
|
|
|
|
|
- if (!selectedKeys.includes('tables')) {
|
|
|
|
|
- setDefaultSelectedKeys([...selectedKeys]);
|
|
|
|
|
- }
|
|
|
|
|
- }}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <Tree showLine showIcon defaultExpandAll height={500}>
|
|
|
<Tree.TreeNode
|
|
<Tree.TreeNode
|
|
|
title={() => {
|
|
title={() => {
|
|
|
return (
|
|
return (
|
|
|
<div style={{ display: 'flex', justifyContent: 'space-between', width: 230 }}>
|
|
<div style={{ display: 'flex', justifyContent: 'space-between', width: 230 }}>
|
|
|
<div>数据源名称</div>
|
|
<div>数据源名称</div>
|
|
|
<div>
|
|
<div>
|
|
|
- <PlusOutlined
|
|
|
|
|
- onClick={() => {
|
|
|
|
|
- setCurrent({});
|
|
|
|
|
- setVisible(true);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <a>
|
|
|
|
|
+ <PlusOutlined
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ setCurrent({});
|
|
|
|
|
+ setModel('add');
|
|
|
|
|
+ setVisible(true);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </a>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}}
|
|
}}
|
|
|
key={'tables'}
|
|
key={'tables'}
|
|
|
>
|
|
>
|
|
|
- {rdbList.map((item) => (
|
|
|
|
|
|
|
+ {rdbList.map((item, index) => (
|
|
|
<Tree.TreeNode
|
|
<Tree.TreeNode
|
|
|
key={item.name}
|
|
key={item.name}
|
|
|
title={() => {
|
|
title={() => {
|
|
|
return (
|
|
return (
|
|
|
<div className={styles.treeTitle}>
|
|
<div className={styles.treeTitle}>
|
|
|
- <div className={styles.title}>{item.name}</div>
|
|
|
|
|
|
|
+ <div
|
|
|
|
|
+ className={styles.title}
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ setDefaultSelectedKeys([item.name]);
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <span
|
|
|
|
|
+ className={
|
|
|
|
|
+ defaultSelectedKeys[0] === item?.name ? styles.active : ''
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
|
|
+ <Tooltip title={item.name}>{item.name}</Tooltip>
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
<div className={styles.options}>
|
|
<div className={styles.options}>
|
|
|
<Space>
|
|
<Space>
|
|
|
- <EditOutlined
|
|
|
|
|
- onClick={() => {
|
|
|
|
|
- setCurrent(item);
|
|
|
|
|
- setVisible(true);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- <DeleteOutlined />
|
|
|
|
|
|
|
+ <a>
|
|
|
|
|
+ <EditOutlined
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ setCurrent(item);
|
|
|
|
|
+ setVisible(true);
|
|
|
|
|
+ setModel('edit');
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </a>
|
|
|
|
|
+ <a>
|
|
|
|
|
+ <Popconfirm
|
|
|
|
|
+ title="确认删除!"
|
|
|
|
|
+ onConfirm={() => {
|
|
|
|
|
+ const list = [...rdbList];
|
|
|
|
|
+ list.splice(index, 1);
|
|
|
|
|
+ setAllList([...list]);
|
|
|
|
|
+ if (item.name === defaultSelectedKeys[0]) {
|
|
|
|
|
+ setDefaultSelectedKeys([list[0]?.name]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <DeleteOutlined />
|
|
|
|
|
+ </Popconfirm>
|
|
|
|
|
+ </a>
|
|
|
</Space>
|
|
</Space>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -197,65 +154,42 @@ const Management = () => {
|
|
|
</Tree.TreeNode>
|
|
</Tree.TreeNode>
|
|
|
</Tree>
|
|
</Tree>
|
|
|
</div>
|
|
</div>
|
|
|
- </Col>
|
|
|
|
|
- <Col span={18}>
|
|
|
|
|
- <div>
|
|
|
|
|
- <SearchComponent<DataSourceType>
|
|
|
|
|
- field={columns}
|
|
|
|
|
- target="datasource-manage"
|
|
|
|
|
- onSearch={(data) => {
|
|
|
|
|
- // 重置分页数据
|
|
|
|
|
- actionRef.current?.reset?.();
|
|
|
|
|
- setParam(data);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- <ProTable<DataSourceType>
|
|
|
|
|
- actionRef={actionRef}
|
|
|
|
|
- params={param}
|
|
|
|
|
- columns={columns}
|
|
|
|
|
- search={false}
|
|
|
|
|
- rowKey="name"
|
|
|
|
|
- headerTitle={
|
|
|
|
|
- <PermissionButton
|
|
|
|
|
- onClick={() => {}}
|
|
|
|
|
- isPermission={userPermission.add}
|
|
|
|
|
- key="add"
|
|
|
|
|
- icon={<PlusOutlined />}
|
|
|
|
|
- type="primary"
|
|
|
|
|
- >
|
|
|
|
|
- 新增列
|
|
|
|
|
- </PermissionButton>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className={styles.right}>
|
|
|
|
|
+ <EditTable
|
|
|
|
|
+ table={{ id, table: defaultSelectedKeys[0] }}
|
|
|
|
|
+ data={tableList}
|
|
|
|
|
+ onChange={async (data: any) => {
|
|
|
|
|
+ const resp = await service.saveRdbTables(id, {
|
|
|
|
|
+ name: defaultSelectedKeys[0],
|
|
|
|
|
+ columns: [...data.array],
|
|
|
|
|
+ });
|
|
|
|
|
+ if (resp.status === 200) {
|
|
|
|
|
+ message.success('保存成功');
|
|
|
|
|
+ handleSearch();
|
|
|
}
|
|
}
|
|
|
- request={async (params) => {
|
|
|
|
|
- if (defaultSelectedKeys.length > 0) {
|
|
|
|
|
- const response = await service.rdbTables(id, defaultSelectedKeys[0], {
|
|
|
|
|
- ...params,
|
|
|
|
|
- sorts: [{ name: 'createTime', order: 'desc' }],
|
|
|
|
|
- });
|
|
|
|
|
- return {
|
|
|
|
|
- result: { data: response.result?.columns || [] },
|
|
|
|
|
- success: true,
|
|
|
|
|
- status: 200,
|
|
|
|
|
- } as any;
|
|
|
|
|
- } else {
|
|
|
|
|
- return {
|
|
|
|
|
- result: { data: [] },
|
|
|
|
|
- success: true,
|
|
|
|
|
- status: 200,
|
|
|
|
|
- } as any;
|
|
|
|
|
- }
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
- </Col>
|
|
|
|
|
- </Row>
|
|
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
</Card>
|
|
</Card>
|
|
|
{visible && (
|
|
{visible && (
|
|
|
<DataTable
|
|
<DataTable
|
|
|
data={current}
|
|
data={current}
|
|
|
save={(data) => {
|
|
save={(data) => {
|
|
|
- rdbList.push(data);
|
|
|
|
|
- setRdbList([...rdbList]);
|
|
|
|
|
|
|
+ if (model === 'edit') {
|
|
|
|
|
+ const list = [...rdbList].map((item) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ name: item?.name === current?.name ? data.name : item.name,
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+ setAllList(list);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const list = [...rdbList];
|
|
|
|
|
+ list.unshift(data);
|
|
|
|
|
+ setAllList([...list]);
|
|
|
|
|
+ }
|
|
|
|
|
+ setModel('list');
|
|
|
message.success('操作成功!');
|
|
message.success('操作成功!');
|
|
|
setVisible(false);
|
|
setVisible(false);
|
|
|
}}
|
|
}}
|