diff --git a/api/app/lib/controllers/patrolManage/checkItems.js b/api/app/lib/controllers/patrolManage/checkItems.js
index a6dca43..d9e6e7b 100644
--- a/api/app/lib/controllers/patrolManage/checkItems.js
+++ b/api/app/lib/controllers/patrolManage/checkItems.js
@@ -25,9 +25,9 @@ async function createGroup(ctx, next) {
const models = ctx.fs.dc.models;
try {
const data = ctx.request.body;
- await models.CheckItemsGroup.create(data)
- ctx.status = 204;
- ctx.body = { message: '新建分组成功' }
+ const rslt = await models.CheckItemsGroup.create(data);
+ ctx.status = 200;
+ ctx.body = { message: '新建分组成功', groupId: rslt.dataValues.id }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
@@ -92,9 +92,7 @@ async function updateCheckItems(ctx, next) {
const data = ctx.request.body;
const { id } = ctx.params;
- await models.CheckItems.update({
- name: data.name,
- }, {
+ await models.CheckItems.update(data, {
where: {
id: id
}
diff --git a/web/client/src/sections/patrolManage/components/checkItemsModal.js b/web/client/src/sections/patrolManage/components/checkItemsModal.js
index aaeb857..ebe6fab 100644
--- a/web/client/src/sections/patrolManage/components/checkItemsModal.js
+++ b/web/client/src/sections/patrolManage/components/checkItemsModal.js
@@ -1,34 +1,27 @@
import { Button, Form, Input, Modal, Select } from 'antd';
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
-import { getUserList, getProjectList, positionList } from '../actions/plan';
import { getCheckItemsGroup } from '../actions/checkItems';
import moment from 'moment';
-const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecord }) => {
- const [pointOpt, setPointOpt] = useState();
- const [points, setPoints] = useState();
+const CheckItemsModal = ({ visible, onOk, onCancel, curRecord, dispatch }) => {
+ const [group, setGroup] = useState([]);
const [isNewGroup, setIsNewGroup] = useState(false);
const [form] = Form.useForm();
useEffect(() => {
- dispatch(getCheckItemsGroup());
- if (type === 'create') {
- dispatch(getUserList())
- } else {
- dispatch(positionList({ projectId: curRecord?.project?.id })).then(res => {
- if (res.success) {
- setPoints(res.payload.data?.rows)
- setPointOpt(res.payload.data?.rows[0]?.points?.map(p => ({ label: p.name, value: p.id })))
- }
- })
- }
+ dispatch(getCheckItemsGroup()).then(res => {
+ if (res.success) {
+ const opt = res.payload.data?.map(g => ({ value: g.id, label: g.name }));
+ setGroup(opt);
+ }
+ });
}, [])
-
+
return (
{
@@ -36,22 +29,15 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor
onCancel();
}}
onOk={() => {
- if (type === 'view') {
- form.resetFields();
- onCancel();
- return;
- }
form
.validateFields()
.then((values) => {
form.resetFields();
const params = {
...values,
- startTime: values.time[0],
- endTime: values.time[1],
- points: points[0]?.points?.filter(p => values?.points?.includes(p.id))
+ isNewGroup
}
- onCreate(params);
+ onOk(params);
})
.catch((info) => {
console.log('Validate Failed:', info);
@@ -64,10 +50,8 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor
name="form_in_modal"
initialValues={{
...curRecord,
- points: curRecord?.points?.map(p => p.id),
userDept: curRecord?.user?.department?.name,
}}
- disabled={type === 'view'}
>
{
- isNewGroup ?
- :
-
+ isNewGroup
+ ?
+ :
}
+ }}>{isNewGroup ? '选择已有' : '创建分组'}
);
};
function mapStateToProps(state) {
- const { auth, userList, structureList } = state
+ const { auth } = state
return {
user: auth.user,
- userList: userList.data || [],
- structureList: structureList.data || [],
- userLoading: userList.isRequesting,
- struLoading: structureList.isRequesting
}
}
export default connect(mapStateToProps)(CheckItemsModal);
\ No newline at end of file
diff --git a/web/client/src/sections/patrolManage/containers/checkItems.js b/web/client/src/sections/patrolManage/containers/checkItems.js
index 63858ad..690c9c5 100644
--- a/web/client/src/sections/patrolManage/containers/checkItems.js
+++ b/web/client/src/sections/patrolManage/containers/checkItems.js
@@ -4,143 +4,153 @@ import { Button, Popconfirm } from 'antd';
import ProTable from '@ant-design/pro-table';
import CheckItemsModal from '../components/checkItemsModal';
import { createPatrolPlan, delPatrolPlan, updatePatrolPlan } from '../actions/plan';
-import { getCheckItems } from '../actions/checkItems';
-import moment from 'moment';
+import { getCheckItems, createCheckItems, updateCheckItems, createCheckItemsGroup } from '../actions/checkItems';
function CheckItems(props) {
- const { dispatch, user } = props;
- const tableRef = useRef();
- const [dataSource, setDataSource] = useState([{}]);
- const [visible, setVisible] = useState(false);
- const [type, setType] = useState();
- const [curRecord, setCurRecord] = useState();
- const [select, setSelect] = useState([]);
+ const { dispatch, user } = props;
+ const tableRef = useRef();
+ const [dataSource, setDataSource] = useState([{}]);
+ const [visible, setVisible] = useState(false);
+ const [curRecord, setCurRecord] = useState(null); // 新增 or 修改
+ const [select, setSelect] = useState([]);
- const onCreate = (values) => {
- if (type === 'create') {
- dispatch(createPatrolPlan(values)).then(res => {
- if (res.success) {
- tableRef.current.reload();
- }
- })
- } else {
- dispatch(updatePatrolPlan({ ...values, id: curRecord.id })).then(res => {
- if (res.success) {
- tableRef.current.reload();
- }
- })
- }
- setVisible(false);
- };
+ const onOk = async (values) => {
+ let groupId = null;
+ if (values.isNewGroup) {
+ await dispatch(createCheckItemsGroup({ name: values.group })).then(res => {
+ if (res.success) {
+ groupId = res.payload.data?.groupId
+ }
+ })
+ }
+ if (!curRecord) {
+ dispatch(createCheckItems({
+ name: values.name,
+ groupId: groupId ? groupId : values.group
+ })).then(res => {
+ if (res.success) {
+ tableRef.current.reload();
+ }
+ })
+ } else {
+ dispatch(updateCheckItems(curRecord.id, {
+ name: values.name,
+ groupId: groupId ? groupId : values.group
+ })).then(res => {
+ if (res.success) {
+ tableRef.current.reload();
+ }
+ })
+ }
+ setVisible(false);
+ };
- const columns = [{
- title: '检查项',
- dataIndex: 'name',
- key: 'name',
- ellipsis: true,
- width: 150,
- }, {
- title: '分组名称',
- dataIndex: 'groupName',
- key: 'groupName',
- ellipsis: true,
- search: false,
- width: 150,
- render: (_, record) => {
- return
{record?.check_items_group?.name}
- }
- }, {
- title: '操作',
- dataIndex: 'action',
- key: 'action',
- search: false,
- width: 200,
- render: (_, record) => {
- return <>
-
- {
- dispatch(delPatrolPlan(record.id)).then(res => {
- if (res.success) {
- tableRef.current.reload();
- }
- })
- }}>
-
-
- >
- },
- }];
+ const columns = [{
+ title: '检查项',
+ dataIndex: 'name',
+ key: 'name',
+ ellipsis: true,
+ width: 150,
+ }, {
+ title: '分组名称',
+ dataIndex: 'groupName',
+ key: 'groupName',
+ ellipsis: true,
+ search: false,
+ width: 150,
+ render: (_, record) => {
+ return {record?.check_items_group?.name}
+ }
+ }, {
+ title: '操作',
+ dataIndex: 'action',
+ key: 'action',
+ search: false,
+ width: 200,
+ render: (_, record) => {
+ return <>
+
+ {
+ dispatch(delPatrolPlan(record.id)).then(res => {
+ if (res.success) {
+ tableRef.current.reload();
+ }
+ })
+ }}>
+
+
+ >
+ },
+ }];
- return (
- <>
- {
- const res = await dispatch(getCheckItems(params));
- setDataSource(res?.payload.data?.rows);
- return { ...res };
- }}
- onReset={() => { }}
- search={{
- defaultCollapsed: false,
- optionRender: (searchConfig, formProps, dom) => [
- ...dom.reverse(),
- ,
- ,
- ],
- }}
- rowSelection={{
- selectedRowKeys: select?.map(v => v.id) || [],
- onChange: (selectedRowKeys, selectedRows) => {
- setSelect(selectedRows)
- }
- }}
- />
- {
- visible ?
- {
- setVisible(false);
- }}
- /> : null
- }
- >
- )
+ return (
+ <>
+ {
+ const res = await dispatch(getCheckItems(params));
+ setDataSource(res?.payload.data?.rows);
+ return { ...res };
+ }}
+ onReset={() => { }}
+ search={{
+ defaultCollapsed: false,
+ optionRender: (searchConfig, formProps, dom) => [
+ ...dom.reverse(),
+ ,
+ ,
+ ],
+ }}
+ rowSelection={{
+ selectedRowKeys: select?.map(v => v.id) || [],
+ onChange: (_, selectedRows) => {
+ setSelect(selectedRows)
+ }
+ }}
+ />
+ {
+ visible ?
+ {
+ setVisible(false);
+ }}
+ /> : null
+ }
+ >
+ )
}
function mapStateToProps(state) {
- const { auth } = state
- return {
- user: auth.user
- }
+ const { auth } = state
+ return {
+ user: auth.user
+ }
}
export default connect(mapStateToProps)(CheckItems);
diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js
index 63855e1..b2005f4 100644
--- a/web/client/src/utils/webapi.js
+++ b/web/client/src/utils/webapi.js
@@ -31,10 +31,10 @@ export const ApiTable = {
patrolRecord: 'patrolRecord/:patrolPlanId/:startTime/:endTime/:alarm/:pointId',
// 检查项设定
- checkItems: '/checkItems', // 获取/新增
- updateCheckItems: '/checkItems/{id}',
- delCheckItems: '/checkItems/{ids}',
- checkItemsGroup: '/checkItems/group', // 获取/新增
+ checkItems: 'checkItems', // 获取/新增
+ updateCheckItems: 'checkItems/{id}',
+ delCheckItems: 'checkItems/{ids}',
+ checkItemsGroup: 'checkItems/group', // 获取/新增
// 用户权限
getResource: 'resource',