Browse Source

(*) 检查项web完善

master
liujiangyong 2 years ago
parent
commit
c4e2067d1a
  1. 10
      api/app/lib/controllers/patrolManage/checkItems.js
  2. 54
      web/client/src/sections/patrolManage/components/checkItemsModal.js
  3. 270
      web/client/src/sections/patrolManage/containers/checkItems.js
  4. 8
      web/client/src/utils/webapi.js

10
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
}

54
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 (
<Modal
visible={visible}
title="新增巡检计划"
title={curRecord ? "检查项修改" : "检查项添加"}
okText="确定"
cancelText="取消"
onCancel={() => {
@ -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'}
>
<Form.Item
name="name"
@ -79,34 +63,30 @@ const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecor
<Input />
</Form.Item>
<Form.Item
name="groupName"
name="group"
label="分组名称"
rules={[
{ required: true, message: '请选择分组' },
]}
>
{
isNewGroup ?
<Select options={pointOpt} disabled={!pointOpt || type === 'view'} /> :
<Input />
isNewGroup
? <Input />
: <Select options={group} loading={!group?.length} />
}
</Form.Item>
</Form>
<Button type='link' onClick={() => {
setIsNewGroup(!isNewGroup);
}}>创建分组</Button>
}}>{isNewGroup ? '选择已有' : '创建分组'}</Button>
</Modal >
);
};
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);

270
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 <div>{record?.check_items_group?.name}</div>
}
}, {
title: '操作',
dataIndex: 'action',
key: 'action',
search: false,
width: 200,
render: (_, record) => {
return <>
<Button type="link" onClick={() => {
setType('edit')
setCurRecord(record)
setVisible(true)
}}>修改</Button>
<Popconfirm
title="确认删除?"
onConfirm={() => {
dispatch(delPatrolPlan(record.id)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}}>
<Button type="link" danger>删除</Button>
</Popconfirm>
</>
},
}];
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 <div>{record?.check_items_group?.name}</div>
}
}, {
title: '操作',
dataIndex: 'action',
key: 'action',
search: false,
width: 200,
render: (_, record) => {
return <>
<Button type="link" onClick={() => {
setCurRecord(record)
setVisible(true)
}}>修改</Button>
<Popconfirm
title="确认删除?"
onConfirm={() => {
dispatch(delPatrolPlan(record.id)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}}>
<Button type="link" danger>删除</Button>
</Popconfirm>
</>
},
}];
return (
<>
<ProTable
columns={columns}
actionRef={tableRef}
options={false}
dataSource={dataSource || []}
rowKey='id'
pagination={{ pageSize: 10 }}
request={async (params = {}) => {
const res = await dispatch(getCheckItems(params));
setDataSource(res?.payload.data?.rows);
return { ...res };
}}
onReset={() => { }}
search={{
defaultCollapsed: false,
optionRender: (searchConfig, formProps, dom) => [
...dom.reverse(),
<Button
key="add"
type='primary'
onClick={() => {
setType('create')
setVisible(true)
}}
>新增</Button>,
<Button
key="del"
type='primary'
onClick={() => {
const values = searchConfig?.form?.getFieldsValue();
console.log(values);
}}
>批量删除</Button>,
],
}}
rowSelection={{
selectedRowKeys: select?.map(v => v.id) || [],
onChange: (selectedRowKeys, selectedRows) => {
setSelect(selectedRows)
}
}}
/>
{
visible ?
<CheckItemsModal
visible={visible}
onCreate={onCreate}
type={type}
curRecord={curRecord}
onCancel={() => {
setVisible(false);
}}
/> : null
}
</>
)
return (
<>
<ProTable
columns={columns}
actionRef={tableRef}
options={false}
dataSource={dataSource || []}
rowKey='id'
pagination={{ pageSize: 10 }}
request={async (params = {}) => {
const res = await dispatch(getCheckItems(params));
setDataSource(res?.payload.data?.rows);
return { ...res };
}}
onReset={() => { }}
search={{
defaultCollapsed: false,
optionRender: (searchConfig, formProps, dom) => [
...dom.reverse(),
<Button
key="add"
type='primary'
onClick={() => {
setCurRecord(null)
setVisible(true)
}}
>新增</Button>,
<Button
key="del"
type='primary'
onClick={() => {
// const values = searchConfig?.form?.getFieldsValue();
// console.log(values);
}}
>批量删除</Button>,
],
}}
rowSelection={{
selectedRowKeys: select?.map(v => v.id) || [],
onChange: (_, selectedRows) => {
setSelect(selectedRows)
}
}}
/>
{
visible ?
<CheckItemsModal
visible={visible}
onOk={onOk}
curRecord={curRecord}
onCancel={() => {
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);

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

Loading…
Cancel
Save