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; const models = ctx.fs.dc.models;
try { try {
let rslt = ctx.request.body; const { attributeName, attributeCode, modelType } = ctx.request.body
await models.MetaModel.create(Object.assign({}, rslt)) const checkName = await models.MetaModel.findOne({ where: { attributeName, modelType } });
ctx.status = 204; const checkCode = await models.MetaModel.findOne({ where: { attributeCode, modelType } });
ctx.body = { message: '新建模型成功' } 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) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;

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

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

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

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

Loading…
Cancel
Save