Browse Source

(*)数据源管理 表格展示提交

master
peng.peng 2 years ago
parent
commit
9c1dc13adb
  1. 25
      api/app/lib/controllers/metadataAcquisition/dataSource.js
  2. 2
      api/app/lib/routes/modelManagement/index.js
  3. 13
      web/client/src/sections/metadataAcquisition/actions/dataSource.js
  4. 2
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepTwo.js
  5. 94
      web/client/src/sections/metadataAcquisition/containers/dataSourceManagement.js
  6. 1
      web/client/src/utils/webapi.js

25
api/app/lib/controllers/metadataAcquisition/dataSource.js

@ -20,15 +20,36 @@ function addDataSource(opts) {
function getDataSource(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
const { page, limit, name } = ctx.query;
let errMsg = { message: '获取数据源失败' }
const Op = ctx.fs.dc.ORM.Op;
try {
let searchWhere = {}
let option = {
where: {},
where: searchWhere,
order: [["id", "desc"]],
}
const res = await models.DataSource.findAll(option);
if (name) {
searchWhere.name = {
// 模糊查询
[Op.like]: '%' + name + '%',
};
}
option.where = searchWhere
let limit_ = limit || 10;
let page_ = page || 1;
let offset = (page_ - 1) * limit_;
if (limit && page) {
option.limit = limit_
option.offset = offset
}
const res = await models.DataSource.findAndCount(option);
ctx.status = 200;
ctx.body = res;
} catch (error) {

2
api/app/lib/routes/modelManagement/index.js

@ -1,6 +1,6 @@
'use strict';
const model = require('../../controllers/model-management/index');
const model = require('../../controllers/modelManagement/index');
module.exports = function (app, router, opts, AuthCode) {

13
web/client/src/sections/metadataAcquisition/actions/dataSource.js

@ -16,3 +16,16 @@ export function addDataSource(params, msg) {
});
}
export function getDataSources(query) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
query: query || {},
actionType: 'GET_ACQ_DATASOURCES',
url: `${ApiTable.getDataSources}`,
msg: { error: '获取适配器列表失败' },
reducer: { name: 'datasources' }
});
}

2
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepTwo.js

@ -79,7 +79,7 @@ function StepTwo(props) {
];
const checkNext = () => {
if (!(params?.user || params?.host || params?.database || params?.password || params?.port)) {
if (!(params?.user && params?.host && params?.database && params?.password && params?.port)) {
message.warning('请填写完整的参数值!')
return false;
} else {

94
web/client/src/sections/metadataAcquisition/containers/dataSourceManagement.js

@ -5,20 +5,22 @@ import ProTable from '@ant-design/pro-table';
const TreeNode = Tree.TreeNode;
function DataSourceManagement(props) {
const { loading, clientHeight, actions, dispatch, metaModel } = props;
const { loading, clientHeight, actions, dispatch, dataSources, adapters } = props;
const [pageSize, setPageSize] = useState(10);
const [currentPage, setCurrentPage] = useState(1);
const [searchValue, setSearchValue] = useState('')
const queryData = (search) => {
const query = {
limit: search ? 10 : pageSize || 10,
page: search ? 1 : currentPage || 1,
name: searchValue
}
dispatch(actions.metadataManagement.getMetaModelList(query));
dispatch(actions.metadataAcquisition.getDataSources(query));
}
useEffect(() => {
dispatch(actions.metadataAcquisition.getAdapters())
queryData();
}, [pageSize, currentPage]);
@ -28,73 +30,46 @@ function DataSourceManagement(props) {
});
};
const onFinish = async (values, editData) => {
if (editData) {
const dataToSave = { ...values }
return dispatch(
actions.metadataManagement.modifyMetaModel(editData.id, dataToSave, values?.msg || ''),
).then(() => {
queryData();
});
}
return dispatch(actions.metadataManagement.addMetaModel({
...values,
})).then(() => {
queryData();
});
};
const columns = [
{
title: '属性名称',
dataIndex: 'attributeName',
ellipsis: true,
search: false,
title: '数据源名称',
dataIndex: 'name',
},
{
title: '属性代码',
dataIndex: 'attributeCode',
ellipsis: true,
search: false,
title: '挂载点',
dataIndex: 'mountPath',
},
{
title: '数据类型',
dataIndex: 'dataType',
ellipsis: true,
search: false,
title: '适配器类型',
dataIndex: 'adapter',
render: (text, record) => {
const adapterInfo = adapters?.find(s => s.id == record?.adapter)
return adapterInfo?.adapterName
}
},
{
title: '输入控件',
title: '采集方式',
dataIndex: 'control',
ellipsis: true,
search: false,
render: (text, record) => {
const adapterInfo = adapters?.find(s => s.id == record?.adapter)
return adapterInfo?.toolName
}
},
{
title: '长度',
title: '工具版本',
dataIndex: 'length',
ellipsis: true,
search: false,
render: (text, record) => {
const adapterInfo = adapters?.find(s => s.id == record?.adapter)
return adapterInfo?.adapterVersion
}
},
{
title: '允许为空',
title: '修改时间',
dataIndex: 'nullable',
ellipsis: true,
search: false,
render: (text, record) => record?.nullable ? '是' : '否'
},
{
title: '是否只读',
dataIndex: 'readOnly',
ellipsis: true,
search: false,
render: (text, record) => record?.readOnly ? '是' : '否'
},
{
title: '描述',
dataIndex: 'description',
ellipsis: true,
search: false,
},
{
title: '操作',
@ -103,7 +78,7 @@ function DataSourceManagement(props) {
valueType: 'option',
render: (text, record) => {
const options = [];
options.push(<a>编辑</a>)
options.push(<a style={{ marginRight: 8 }}>编辑</a>)
options.push(
<Popconfirm
key="del"
@ -124,7 +99,9 @@ function DataSourceManagement(props) {
return <Spin spinning={loading}>
<Row style={{ marginBottom: 16 }}>
<Col span={12}><Button type='primary'>新建</Button></Col>
<Col span={12} style={{ textAlign: 'right' }}><Input style={{ width: 220, marginRight: 15 }} placeholder="数据源名称" /><Button type='primary'>查询</Button></Col>
<Col span={12} style={{ textAlign: 'right' }}><Input
value={searchValue} onChange={e => { setSearchValue(e.target.value) }}
style={{ width: 220, marginRight: 15 }} placeholder="数据源名称" /><Button onClick={() => { queryData() }} type='primary'>查询</Button></Col>
</Row>
<Table
columns={columns}
@ -138,7 +115,7 @@ function DataSourceManagement(props) {
}
pagination={{
size: 'large',
total: metaModel?.count,
total: dataSources?.count,
showSizeChanger: true,
// showQuickJumper: true,
current: currentPage,
@ -158,7 +135,7 @@ function DataSourceManagement(props) {
}
}}
dataSource={metaModel?.rows || []}
dataSource={dataSources?.rows || []}
options={false}
/>
</Spin>
@ -167,13 +144,14 @@ function DataSourceManagement(props) {
function mapStateToProps(state) {
const {
auth, global, metaModel
auth, global, datasources, adapters
} = state;
return {
loading: metaModel.isRequesting,
loading: datasources.isRequesting || adapters?.isRequesting,
clientHeight: global.clientHeight,
actions: global.actions,
metaModel: metaModel?.data || {}
dataSources: datasources?.data || {},
adapters: adapters?.data || []
};
}

1
web/client/src/utils/webapi.js

@ -22,6 +22,7 @@ export const ApiTable = {
pgCheckConnect: 'adapter/check/connect',
addDataSource: 'meta/acq/dataSource',
getAdapters: 'meta/acq/adapters',
getDataSources: 'meta/acq/dataSources',
};
export const RouteTable = {

Loading…
Cancel
Save