Browse Source

(*)模型管理功能提交

master
peng.peng 2 years ago
parent
commit
0722dd970a
  1. 20
      api/app/lib/controllers/model-management/index.js
  2. 2
      web/client/src/sections/metadataManagement/actions/model.js
  3. 121
      web/client/src/sections/metadataManagement/components/modelModal.js
  4. 64
      web/client/src/sections/metadataManagement/containers/metaModelManagement.js

20
api/app/lib/controllers/model-management/index.js

@ -7,7 +7,7 @@ function getModelManagementList(opts) {
const models = ctx.fs.dc.models;
const { page, limit, modelType } = ctx.query;
const Op = ctx.fs.dc.ORM.Op;
let errMsg = { message: '获取监察任务失败' }
let errMsg = { message: '获取模型失败' }
try {
let searchWhere = {}
let option = {
@ -40,7 +40,7 @@ function getModelManagementList(opts) {
}
}
// 新增监察任务
// 新增模型
function addModelManagement(opts) {
return async function (ctx, next) {
@ -49,16 +49,16 @@ function addModelManagement(opts) {
let rslt = ctx.request.body;
await models.MetaModel.create(Object.assign({}, rslt))
ctx.status = 204;
ctx.body = { message: '新建监察任务成功' }
ctx.body = { message: '新建模型成功' }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '新建监察任务失败' }
ctx.body = { message: '新建模型失败' }
}
}
}
// 修改监察任务
// 修改模型
function editModelManagement(opts) {
return async function (ctx, next) {
@ -71,16 +71,16 @@ function editModelManagement(opts) {
{ where: { id: id, } }
)
ctx.status = 204;
ctx.body = { message: '修改监察任务成功' }
ctx.body = { message: '修改模型成功' }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '修改监察任务失败' }
ctx.body = { message: '修改模型失败' }
}
}
}
// 删除监察任务
// 删除模型
function deleteModelManagement(opts) {
return async function (ctx, next) {
@ -93,11 +93,11 @@ function deleteModelManagement(opts) {
}
})
ctx.status = 204;
ctx.body = { message: '删除监察任务成功' }
ctx.body = { message: '删除模型成功' }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '删除监察任务失败' }
ctx.body = { message: '删除模型失败' }
}
}
}

2
web/client/src/sections/metadataManagement/actions/model.js

@ -11,7 +11,7 @@ export function getMetaModelList(query) {
actionType: 'GET_METAMODEL_REPORT',
url: `${ApiTable.getMetaModelList}`,
msg: { error: '获取模型列表失败' },
reducer: { name: 'rectification' }
reducer: { name: 'metaModel' }
});
}

121
web/client/src/sections/metadataManagement/components/modelModal.js

@ -0,0 +1,121 @@
import React, { useState, useRef } from 'react';
import { Button, Form, Row, Col, Table, Popconfirm, Input, message } from 'antd';
import {
ModalForm,
ProFormRadio,
ProFormSelect,
ProFormTextArea,
ProFormDigit,
ProFormDependency,
ProFormText
} from '@ant-design/pro-form';
import moment from 'moment';
export default (props) => {
const { title, triggerRender, editData = null, onFinish, readOnly, } = props;
const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 16 } };
const initialValues = editData ? {
...editData,
} : {};
return (
<ModalForm
title={title || ''}
initialValues={initialValues}
trigger={
triggerRender ? triggerRender : <Button type="primary" >
{title || ''}
</Button>
}
layout="horizontal"
grid={true}
{...formItemLayout}
modalProps={{
destroyOnClose: true,
onCancel: () => { },
// bodyStyle: { height: 800, overflowY: 'auto' }
}}
onFinish={async (values) => {
onFinish && await onFinish(values, editData)
return true;
}}
submitter={!readOnly}
width={500}
>
<ProFormText
rules={[{ required: true, message: '请输入属性名称' }]}
disabled={readOnly || editData}
name="attributeName"
label="属性名称"
/>
<ProFormText
rules={[{ required: true, message: '请输入属性代码' }]}
disabled={readOnly || editData}
name="attributeCode"
label="属性代码"
/>
<ProFormSelect
rules={[{ required: true, message: '请选择检查类型' }]}
options={[
{ label: '整型', value: '整型' },
{ label: '字符型', value: '字符型' },
{ label: '布尔型', value: '布尔型' },]}
disabled={readOnly || editData}
name="dataType"
label="数据类型"
fieldProps={{
showSearch: true
}}
/>
<ProFormDigit
disabled={readOnly || editData}
name="length"
label="长度"
fieldProps={{ precision: 0 }}
/>
<ProFormSelect
rules={[{ required: true, message: '请选择输入控件' }]}
options={[
{ label: '数字输入框', value: '数字输入框' },
{ label: '文本框', value: '文本框' },
{ label: '下拉框', value: '下拉框' },
]}
disabled={readOnly || editData}
name="control"
label="输入控件"
/>
<ProFormSelect
rules={[{ required: true, message: '请选择是否允许为空' }]}
options={[
{ label: '是', value: true },
{ label: '否', value: false }]}
disabled={readOnly || editData}
name="nullable"
label="是否允许为空"
/>
<ProFormSelect
rules={[{ required: true, message: '请选是否只读' }]}
options={[
{ label: '是', value: true },
{ label: '否', value: false }]}
disabled={readOnly || editData}
name="readOnly"
label="是否只读"
/>
<ProFormTextArea
disabled={readOnly || editData}
name="description"
label="描述"
/>
</ModalForm>
);
};

64
web/client/src/sections/metadataManagement/containers/metaModelManagement.js

@ -2,11 +2,11 @@ import React, { useEffect, useState } from 'react'
import { Spin, Select, Tree, Row, Col, Button } from 'antd';
import { connect } from 'react-redux';
import ProTable from '@ant-design/pro-table';
import MetaModelModal from '../components/modelModal'
const TreeNode = Tree.TreeNode;
const DATABASE_TYPE = ['目录', '库', '表', '字段', '主键', '外键', '索引'];
function MetaModelManagement(props) {
const { loading, clientHeight } = props;
const { loading, clientHeight, actions, dispatch, metaModel } = props;
const [selectedKeys, setSelectKeys] = useState([DATABASE_TYPE[0]])
const [pageSize, setPageSize] = useState(10);
const [currentPage, setCurrentPage] = useState(1);
@ -42,23 +42,19 @@ function MetaModelManagement(props) {
ellipsis: true,
search: false,
},
{
title: '小数位数',
dataIndex: 'company',
ellipsis: true,
search: false,
},
{
title: '允许为空',
dataIndex: 'readOnly',
dataIndex: 'nullable',
ellipsis: true,
search: false,
render: (text, record) => record?.nullable ? '是' : '否'
},
{
title: '是否只读',
dataIndex: 'readOnly',
ellipsis: true,
search: false,
render: (text, record) => record?.readOnly ? '是' : '否'
},
{
title: '描述',
@ -66,8 +62,6 @@ function MetaModelManagement(props) {
ellipsis: true,
search: false,
},
{
title: '操作',
width: 160,
@ -83,6 +77,36 @@ function MetaModelManagement(props) {
},
];
const queryData = (search) => {
const query = {
limit: search ? 10 : pageSize || 10,
page: search ? 1 : currentPage || 1,
modelType: selectedKeys[0]
}
dispatch(actions.metadataManagement.getMetaModelList(query));
}
useEffect(() => {
queryData();
}, [pageSize, currentPage, selectedKeys]);
const onFinish = async (values, editData) => {
if (editData) {
return dispatch(
actions.metadataManagement.modifyMetaModel(editData.id, dataToSave, values?.msg || ''),
).then(() => {
queryData();
});
}
return dispatch(actions.metadataManagement.addMetaModel({
modelType: selectedKeys[0],
...values,
})).then(() => {
queryData();
});
};
return <Spin spinning={loading}>
<Row>
@ -123,7 +147,7 @@ function MetaModelManagement(props) {
}
}
pagination={{
total: 0,
total: metaModel?.count,
showSizeChanger: true,
showQuickJumper: true,
current: currentPage,
@ -143,8 +167,15 @@ function MetaModelManagement(props) {
}
}}
dataSource={[]}
headerTitle={<Button type='primary'>新建</Button>}
dataSource={metaModel?.rows || []}
headerTitle={[
<MetaModelModal
triggerRender={<Button type='primary'>新建</Button>}
title="新建模型"
onFinish={onFinish}
key="addModel"
/>
]}
options={false}
/>
</Col>
@ -155,12 +186,13 @@ function MetaModelManagement(props) {
function mapStateToProps(state) {
const {
auth, global,
auth, global, metaModel
} = state;
return {
loading: auth.isRequesting,
clientHeight: global.clientHeight,
actions: global.actions,
metaModel: metaModel?.data || {}
};
}

Loading…
Cancel
Save