Browse Source

(*)模型管理 名称判重改为api判重

master
peng.peng 2 years ago
parent
commit
4298416d64
  1. 17
      api/app/lib/controllers/modelManagement/index.js
  2. 27
      web/client/src/sections/metadataManagement/components/modelModal.js
  3. 9
      web/client/src/sections/metadataManagement/containers/metaModelManagement.js

17
api/app/lib/controllers/modelManagement/index.js

@ -46,10 +46,19 @@ function addModelManagement(opts) {
const models = ctx.fs.dc.models;
try {
let rslt = ctx.request.body;
await models.MetaModel.create(Object.assign({}, rslt))
ctx.status = 204;
ctx.body = { message: '新建模型成功' }
const { attributeName, attributeCode, modelType } = ctx.request.body
const checkName = await models.MetaModel.findOne({ where: { attributeName, modelType } });
const checkCode = await models.MetaModel.findOne({ where: { attributeCode, modelType } });
if (checkName || checkCode) {
ctx.status = 400;
ctx.body = { message: checkName ? '该属性名称已存在' : "该属性代码已存在" }
} else {
let rslt = ctx.request.body;
await models.MetaModel.create(Object.assign({}, rslt))
ctx.status = 204;
ctx.body = { message: '新建模型成功' }
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;

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

@ -1,5 +1,5 @@
import React from 'react';
import { Button } from 'antd';
import { Button, Form } from 'antd';
import {
ModalForm,
ProFormSelect,
@ -14,25 +14,10 @@ export default (props) => {
const initialValues = editData ? {
...editData,
} : {};
const checkName = async (rule, value) => {
let filter = models?.find(s => s?.attributeName == value && value !== editData?.attributeName)
if (filter) {
return Promise.reject(new Error('已存该属性名称!'));
}
return Promise.resolve();
}
const checkCode = async (rule, value) => {
let filter = models?.find(s => s?.attributeCode == value && value !== editData?.attributeCode)
if (filter) {
return Promise.reject(new Error('已存该属性代码!'));
}
return Promise.resolve();
}
const [form] = Form.useForm();
return (
<ModalForm
form={form}
title={title || ''}
initialValues={initialValues}
trigger={
@ -48,15 +33,14 @@ export default (props) => {
onCancel: () => { },
}}
onFinish={async (values) => {
onFinish && await onFinish(values, editData)
return true;
return onFinish && await onFinish(values, editData, form)
// return true;
}}
width={500}
>
<ProFormText
rules={[{ required: true, message: '请输入属性名称' },
{ max: 255, message: '属性名称长度不能大于255个字符' },
{ validator: checkName }
]}
name="attributeName"
label="属性名称"
@ -65,7 +49,6 @@ export default (props) => {
<ProFormText
rules={[{ required: true, message: '请输入属性代码' },
{ max: 255, message: '属性代码长度不能大于255个字符' },
{ validator: checkCode }
]}
name="attributeCode"
label="属性代码"

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

@ -44,8 +44,13 @@ function MetaModelManagement(props) {
return dispatch(actions.metadataManagement.addMetaModel({
modelType: selectedKeys[0],
...values,
})).then(() => {
queryData();
})).then(res => {
if (res.success) {
queryData();
return true;
} else {
return false;
}
});
};

Loading…
Cancel
Save