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) { function getDataSource(opts) {
return async function (ctx, next) { return async function (ctx, next) {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { page, limit, name } = ctx.query;
let errMsg = { message: '获取数据源失败' } let errMsg = { message: '获取数据源失败' }
const Op = ctx.fs.dc.ORM.Op;
try { try {
let searchWhere = {}
let option = { let option = {
where: {}, where: searchWhere,
order: [["id", "desc"]], 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.status = 200;
ctx.body = res; ctx.body = res;
} catch (error) { } catch (error) {

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

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const model = require('../../controllers/model-management/index'); const model = require('../../controllers/modelManagement/index');
module.exports = function (app, router, opts, AuthCode) { 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 = () => { 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('请填写完整的参数值!') message.warning('请填写完整的参数值!')
return false; return false;
} else { } 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; const TreeNode = Tree.TreeNode;
function DataSourceManagement(props) { function DataSourceManagement(props) {
const { loading, clientHeight, actions, dispatch, metaModel } = props; const { loading, clientHeight, actions, dispatch, dataSources, adapters } = props;
const [pageSize, setPageSize] = useState(10); const [pageSize, setPageSize] = useState(10);
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
const [searchValue, setSearchValue] = useState('')
const queryData = (search) => { const queryData = (search) => {
const query = { const query = {
limit: search ? 10 : pageSize || 10, limit: search ? 10 : pageSize || 10,
page: search ? 1 : currentPage || 1, page: search ? 1 : currentPage || 1,
name: searchValue
} }
dispatch(actions.metadataManagement.getMetaModelList(query)); dispatch(actions.metadataAcquisition.getDataSources(query));
} }
useEffect(() => { useEffect(() => {
dispatch(actions.metadataAcquisition.getAdapters())
queryData(); queryData();
}, [pageSize, currentPage]); }, [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 = [ const columns = [
{ {
title: '属性名称', title: '数据源名称',
dataIndex: 'attributeName', dataIndex: 'name',
ellipsis: true,
search: false,
}, },
{ {
title: '属性代码', title: '挂载点',
dataIndex: 'attributeCode', dataIndex: 'mountPath',
ellipsis: true,
search: false,
}, },
{ {
title: '数据类型', title: '适配器类型',
dataIndex: 'dataType', dataIndex: 'adapter',
ellipsis: true, render: (text, record) => {
search: false, const adapterInfo = adapters?.find(s => s.id == record?.adapter)
return adapterInfo?.adapterName
}
}, },
{ {
title: '输入控件', title: '采集方式',
dataIndex: 'control', dataIndex: 'control',
ellipsis: true, render: (text, record) => {
search: false, const adapterInfo = adapters?.find(s => s.id == record?.adapter)
return adapterInfo?.toolName
}
}, },
{ {
title: '长度', title: '工具版本',
dataIndex: 'length', dataIndex: 'length',
ellipsis: true, render: (text, record) => {
search: false, const adapterInfo = adapters?.find(s => s.id == record?.adapter)
return adapterInfo?.adapterVersion
}
}, },
{ {
title: '允许为空', title: '修改时间',
dataIndex: 'nullable', dataIndex: 'nullable',
ellipsis: true,
search: false,
render: (text, record) => record?.nullable ? '是' : '否'
},
{
title: '是否只读',
dataIndex: 'readOnly',
ellipsis: true,
search: false,
render: (text, record) => record?.readOnly ? '是' : '否'
}, },
{ {
title: '描述', title: '描述',
dataIndex: 'description', dataIndex: 'description',
ellipsis: true,
search: false,
}, },
{ {
title: '操作', title: '操作',
@ -103,7 +78,7 @@ function DataSourceManagement(props) {
valueType: 'option', valueType: 'option',
render: (text, record) => { render: (text, record) => {
const options = []; const options = [];
options.push(<a>编辑</a>) options.push(<a style={{ marginRight: 8 }}>编辑</a>)
options.push( options.push(
<Popconfirm <Popconfirm
key="del" key="del"
@ -124,7 +99,9 @@ function DataSourceManagement(props) {
return <Spin spinning={loading}> return <Spin spinning={loading}>
<Row style={{ marginBottom: 16 }}> <Row style={{ marginBottom: 16 }}>
<Col span={12}><Button type='primary'>新建</Button></Col> <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> </Row>
<Table <Table
columns={columns} columns={columns}
@ -138,7 +115,7 @@ function DataSourceManagement(props) {
} }
pagination={{ pagination={{
size: 'large', size: 'large',
total: metaModel?.count, total: dataSources?.count,
showSizeChanger: true, showSizeChanger: true,
// showQuickJumper: true, // showQuickJumper: true,
current: currentPage, current: currentPage,
@ -158,7 +135,7 @@ function DataSourceManagement(props) {
} }
}} }}
dataSource={metaModel?.rows || []} dataSource={dataSources?.rows || []}
options={false} options={false}
/> />
</Spin> </Spin>
@ -167,13 +144,14 @@ function DataSourceManagement(props) {
function mapStateToProps(state) { function mapStateToProps(state) {
const { const {
auth, global, metaModel auth, global, datasources, adapters
} = state; } = state;
return { return {
loading: metaModel.isRequesting, loading: datasources.isRequesting || adapters?.isRequesting,
clientHeight: global.clientHeight, clientHeight: global.clientHeight,
actions: global.actions, 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', pgCheckConnect: 'adapter/check/connect',
addDataSource: 'meta/acq/dataSource', addDataSource: 'meta/acq/dataSource',
getAdapters: 'meta/acq/adapters', getAdapters: 'meta/acq/adapters',
getDataSources: 'meta/acq/dataSources',
}; };
export const RouteTable = { export const RouteTable = {

Loading…
Cancel
Save