Browse Source

检查项分组删除功能

master
liujiangyong 2 years ago
parent
commit
d269fda871
  1. 17
      api/app/lib/controllers/patrolManage/checkItems.js
  2. 4
      api/app/lib/routes/patrolManage/checkItems.js
  3. 14
      web/client/src/sections/patrolManage/actions/checkItems.js
  4. 32
      web/client/src/sections/patrolManage/components/checkItemsModal.js
  5. 1
      web/client/src/utils/webapi.js

17
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,

4
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);

14
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',

32
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 (
<Modal
@ -71,7 +86,18 @@ const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => {
{
isNewGroup
? <Input />
: <Select options={group} loading={!group?.length} />
: <Select loading={!group?.length} optionLabelProp="label">
{
group?.map((g) => {
return <Option key={g.value} value={g.value} label={g.label}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
{g.label}
<DeleteOutlined onClick={() => { delGroup(g.value) }} />
</div>
</Option>
})
}
</Select>
}
</Form.Item>
</Form>

1
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',

Loading…
Cancel
Save