From e8f38bf4c80bd6b88b234c0aa3329c35d551e48b Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Tue, 21 Mar 2023 11:08:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E7=9B=AE=E5=BD=95=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 20 +-- .../metadataManagement/actions/index.js | 4 +- .../metadataManagement/actions/metadata.js | 53 ++++++ .../components/resourceCatalogModal.js | 86 ++++++++++ .../containers/latestMetadata.js | 152 +++++++++++++++++- .../metadataManagement/containers/style.css | 16 ++ .../containers/tagManagement.js | 14 +- .../src/sections/metadataManagement/routes.js | 2 +- web/client/src/utils/webapi.js | 5 + 9 files changed, 325 insertions(+), 27 deletions(-) create mode 100644 web/client/src/sections/metadataManagement/actions/metadata.js create mode 100644 web/client/src/sections/metadataManagement/components/resourceCatalogModal.js create mode 100644 web/client/src/sections/metadataManagement/containers/style.css diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index b45ba42..87a881a 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -77,6 +77,7 @@ async function delResourceCatalog(ctx) { const { id } = ctx.params; let resourceCatalogInfo = await models.ResourceCatalog.findOne({ where: { id } }); if (resourceCatalogInfo) { + let deletable = true; let childResourceCatalogInfo = await models.ResourceCatalog.findOne({ where: { parent: id } }); let databaseInfo = await models.MetadataDatabase.findOne({ where: { catalog: id } }); let fileInfo = await models.MetadataFile.findOne({ where: { catalog: id } }); @@ -86,16 +87,15 @@ async function delResourceCatalog(ctx) { ctx.body = { message: '存在关联子类目录或元数据,请删除相关数据,再删除该资源目录' } deletable = false; } - } - if (deletable) { - await models.ResourceCatalog.destroy({ - where: { id: id }, - transaction - }) - await transaction.commit(); - ctx.status = 200; - ctx.body = { message: '删除资源目录成功' } - + if (deletable) { + await models.ResourceCatalog.destroy({ + where: { id: id }, + transaction + }) + await transaction.commit(); + ctx.status = 200; + ctx.body = { message: '删除资源目录成功' } + } } else { ctx.status = 400; ctx.body = { message: '该资源目录不存在' } diff --git a/web/client/src/sections/metadataManagement/actions/index.js b/web/client/src/sections/metadataManagement/actions/index.js index 3517c90..9f06f2a 100644 --- a/web/client/src/sections/metadataManagement/actions/index.js +++ b/web/client/src/sections/metadataManagement/actions/index.js @@ -3,9 +3,11 @@ import * as example from './example' import * as tags from './tags' import * as models from './model' +import * as metadata from './metadata' export default { ...example, ...tags, - ...models + ...models, + ...metadata } \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/actions/metadata.js b/web/client/src/sections/metadataManagement/actions/metadata.js new file mode 100644 index 0000000..bafacd9 --- /dev/null +++ b/web/client/src/sections/metadataManagement/actions/metadata.js @@ -0,0 +1,53 @@ +'use strict'; + +import { basicAction } from '@peace/utils' +import { ApiTable } from '$utils' + +export function getResourceCatalog(params) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: params, + actionType: 'GET_RESOURCE_CATALOG', + url: ApiTable.getResourceCatalog, + msg: { error: '获取资源目录失败' }, + reducer: { name: 'resourceCatalog' } + }); +} + +export function postResourceCatalog(data) { + return dispatch => basicAction({ + type: 'post', + data: data, + dispatch: dispatch, + actionType: 'POST_RESOURCE_CATALOG', + url: ApiTable.postResourceCatalog, + msg: { option: '新增资源目录' }, + reducer: {} + }); +} + +export function putResourceCatalog(id, data) { + return dispatch => basicAction({ + type: 'put', + data: data, + dispatch, + actionType: 'PUT_RESOURCE_CATALOG', + url: ApiTable.putResourceCatalog.replace('{id}', id), + msg: { + option: '修改资源目录', + } + }); +} + +export function delResourceCatalog(id) { + return dispatch => basicAction({ + type: 'del', + dispatch, + actionType: 'DELETE_RESOURCE_CATALOG', + url: ApiTable.delResourceCatalog.replace('{id}', id), + msg: { + option: '删除资源目录', + } + }); +} \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/components/resourceCatalogModal.js b/web/client/src/sections/metadataManagement/components/resourceCatalogModal.js new file mode 100644 index 0000000..9431d6e --- /dev/null +++ b/web/client/src/sections/metadataManagement/components/resourceCatalogModal.js @@ -0,0 +1,86 @@ +import React, { useEffect, useState } from 'react'; +import { Modal, Input, Form, message } from 'antd'; +const { TextArea } = Input; +const ResourceCatalogModal = (props) => { + const { resourceCatalog, onConfirm, onCancel, editData } = props; + const [form] = Form.useForm(); + useEffect(() => { + }, []); + const handleOk = () => { + form.validateFields().then(values => { + if (onConfirm) { + if (editData.add) { + //新建 + let exist = resourceCatalog.find(rc => rc.name === values.name); + if (exist) { + message.error('该资源目录名称已存在'); + return false; + } + exist = resourceCatalog.find(rc => rc.code === values.code); + if (exist) { + message.error('该资源目录代码已存在'); + return false; + } + } else {//修改 + let exist = resourceCatalog.find(rc => rc.name === values.name && rc.id != editData.record.id); + if (exist) { + message.error('该资源目录名称已存在'); + return false; + } + exist = resourceCatalog.find(rc => rc.code === values.code && rc.id != editData.record.id); + if (exist) { + message.error('该资源目录代码已存在'); + return false; + } + } + onConfirm(values) + } + }) + } + const validatorNull = (rule, value, getFieldValue, validateFields) => { + if (!value || !value.trim().length) { + return Promise.reject(new Error(`${rule.field === 'name' ? '名称' : '代码'}不可空字符串`)); + } + return Promise.resolve(); + } + return ( + handleOk(null)} + onCancel={onCancel}> +
+ {editData.child ? + + : null} + ({ + validator(_, value) { return validatorNull(_, value, getFieldValue, validateFields) } + })]}> + + + ({ + validator(_, value) { return validatorNull(_, value, getFieldValue, validateFields) } + })]}> + + + +