diff --git a/api/app/lib/controllers/patrolManage/checkItems.js b/api/app/lib/controllers/patrolManage/checkItems.js index a61aa33..a4f9a89 100644 --- a/api/app/lib/controllers/patrolManage/checkItems.js +++ b/api/app/lib/controllers/patrolManage/checkItems.js @@ -39,6 +39,22 @@ async function createGroup(ctx, next) { } } +async function delGroup(ctx, next) { + const models = ctx.fs.dc.models; + try { + const { id } = ctx.params; + await models.CheckItemsGroup.destroy({ + where: { id } + }); + ctx.status = 200; + ctx.body = { message: '删除分组成功' } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { message: error.name === 'SequelizeForeignKeyConstraintError' ? '不能删除有检查项的分组' : '删除分组失败' } + } +} + async function getCheckItems(ctx, next) { try { const models = ctx.fs.dc.models; @@ -142,6 +158,7 @@ async function deleteCheckItems(ctx, next) { module.exports = { getGroup, createGroup, + delGroup, getCheckItems, createCheckItems, updateCheckItems, diff --git a/api/app/lib/routes/patrolManage/checkItems.js b/api/app/lib/routes/patrolManage/checkItems.js index f6874ae..d86ade4 100644 --- a/api/app/lib/routes/patrolManage/checkItems.js +++ b/api/app/lib/routes/patrolManage/checkItems.js @@ -13,8 +13,8 @@ module.exports = function (app, router, opts) { // app.fs.api.logAttr['PUT/organization/dept/:id/modify'] = { content: '修改部门', visible: true }; // router.put('/organization/dept/:id/modify', checkItems.updateDept); - // app.fs.api.logAttr['DELETE/organization/dept/:id'] = { content: '删除部门', visible: true }; - // router.del('/organization/dept/:id', checkItems.delDept); + app.fs.api.logAttr['DELETE/checkItems/group/:id'] = { content: '删除分组', visible: true }; + router.del('/checkItems/group/:id', checkItems.delGroup); app.fs.api.logAttr['GET/checkItems'] = { content: '获取检查项', visible: false }; router.get('/checkItems', checkItems.getCheckItems); diff --git a/web/client/src/sections/patrolManage/actions/checkItems.js b/web/client/src/sections/patrolManage/actions/checkItems.js index f7a2666..5ba4edc 100644 --- a/web/client/src/sections/patrolManage/actions/checkItems.js +++ b/web/client/src/sections/patrolManage/actions/checkItems.js @@ -7,7 +7,7 @@ export function getCheckItemsGroup() { return dispatch => basicAction({ type: 'get', dispatch: dispatch, - actionType: 'GET_CHECK_ITEMS_GRROUP', + actionType: 'GET_CHECK_ITEMS_GROUP', url: ApiTable.checkItemsGroup, msg: { error: '获取检查项分组失败' }, reducer:{name:'checkItemsGroup'} @@ -19,12 +19,22 @@ export function createCheckItemsGroup(data) { type: 'post', data, dispatch: dispatch, - actionType: 'CREATE_CHECK_ITEMS_GRROUP', + actionType: 'CREATE_CHECK_ITEMS_GROUP', url: ApiTable.checkItemsGroup, msg: { option: '创建检查项分组' }, }); } +export function delCheckItemsGroup(id) { + return dispatch => basicAction({ + type: 'del', + dispatch: dispatch, + actionType: 'DEL_CHECK_ITEMS_GROUP', + url: ApiTable.delCheckItemsGroup.replace('{id}', id), + msg: { option: '删除检查项分组' }, + }); +} + export function getCheckItems(query) { return dispatch => basicAction({ type: 'get', diff --git a/web/client/src/sections/patrolManage/components/checkItemsModal.js b/web/client/src/sections/patrolManage/components/checkItemsModal.js index 5f085e4..4eefa88 100644 --- a/web/client/src/sections/patrolManage/components/checkItemsModal.js +++ b/web/client/src/sections/patrolManage/components/checkItemsModal.js @@ -1,7 +1,9 @@ import { Button, Form, Input, Modal, Select } from 'antd'; +import { DeleteOutlined } from '@ant-design/icons'; import React, { useState, useEffect } from 'react'; import { connect } from 'react-redux'; -import { getCheckItemsGroup } from '../actions/checkItems'; +import { getCheckItemsGroup, delCheckItemsGroup } from '../actions/checkItems'; +const { Option } = Select; const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => { const [group, setGroup] = useState([]); @@ -9,13 +11,26 @@ const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => { const [form] = Form.useForm(); useEffect(() => { + getGroup(); + }, []) + + function getGroup() { dispatch(getCheckItemsGroup()).then(res => { if (res.success) { const opt = res.payload.data?.map(g => ({ value: g.id, label: g.name })); setGroup(opt); } }); - }, []) + } + + function delGroup(id) { + dispatch(delCheckItemsGroup(id)).then(res => { + if (res.success) { + form.setFieldValue('group', null) + getGroup(); + } + }); + } return ( { { isNewGroup ? - : + { + group?.map((g) => { + return + }) + } + } diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index b33e6ab..07f09da 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -38,6 +38,7 @@ export const ApiTable = { updateCheckItems: 'checkItems/{id}', delCheckItems: 'checkItems/{ids}', checkItemsGroup: 'checkItems/group', // 获取/新增 + delCheckItemsGroup: 'checkItems/group/{id}', // 用户权限 getResource: 'resource',