Browse Source

修改根据id查找用户和路线信息,以及前端的一些代码规范修改

dev
zhaobing 2 years ago
parent
commit
19b4055f19
  1. 18
      api/app/lib/controllers/data/task.js
  2. 4
      api/app/lib/routes/data/index.js
  3. 4
      web/client/src/sections/fillion/actions/task.js
  4. 14
      web/client/src/sections/fillion/components/task/addTaskModal.js
  5. 18
      web/client/src/sections/fillion/containers/task.js
  6. 2
      web/client/src/utils/webapi.js

18
api/app/lib/controllers/data/task.js

@ -7,31 +7,27 @@ async function getTask(ctx) {
const whereopt = {
isdanger: query.isdanger
}
console.log('whereopt', whereopt)
const whereRoadOpt = {
id: query.id
}
console.log('wherwhereRoadOpteopt', whereRoadOpt)
const taskRes = await models.TaskManage.findAndCountAll({
order: [['id', 'DESC']],
attributes: ['id', 'dangerDescription', 'isdanger', 'issuanceTime', 'reportTime'],
include: [
{
attributes: ['routeName', 'routeCode'],
attributes: ['id', 'routeName', 'routeCode'],
model: models.Road,
where: query.id == undefined ? {} : whereRoadOpt
},
{
attributes: ['name'],
attributes: ['id', 'name'],
model: models.User
}
],
where: query.isdanger == undefined ? {} : whereopt
})
ctx.body = taskRes
console.log('tas', taskRes)
ctx.status = 200
}
catch (error) {
@ -48,7 +44,6 @@ async function delTask(ctx) {
try {
const models = ctx.fs.dc.models
const { id } = ctx.params
console.log('params', id)
await models.TaskManage.destroy({ where: { id: id } })
ctx.status = 204
} catch (error) {
@ -66,23 +61,18 @@ async function editTask(ctx) {
try {
const models = ctx.fs.dc.models
const params = ctx.request.body
const road = await models.Road.findOne({ where: { id: params.routeId } })
const user = await models.User.findOne({ where: { id: params.userId } })
if (!params.id) {
const road = await models.Road.findOne({ where: { routeCode: params.routeCode } })
const user = await models.User.findOne({ where: { name: params.name } })
console.log('params', road.id, user.id)
await models.TaskManage.create({
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim()
})
} else {
const road = await models.Road.findOne({ where: { routeCode: params.routeCode } })
const user = await models.User.findOne({ where: { name: params.name } })
await models.TaskManage.update({
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim()
}, { where: { id: params.id } })
}
ctx.status = 204
//await transaction.commit();
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;

4
api/app/lib/routes/data/index.js

@ -177,7 +177,7 @@ module.exports = function (app, router, opts) {
router.get('/task', task.getTask);
app.fs.api.logAttr['DEL/task/:id'] = { content: '删除任务', visible: false };
router.del('/task/:id', task.delTask);
app.fs.api.logAttr['PUT/editTask'] = { content: '编辑任务', visible: false };
router.put('/editTask', task.editTask);
app.fs.api.logAttr['PUT/task'] = { content: '编辑任务', visible: false };
router.put('/task', task.editTask);
//task END
};

4
web/client/src/sections/fillion/actions/task.js

@ -28,8 +28,8 @@ export function editTask(query) {
type: 'put',
dispatch: dispatch,
data: query,
actionType: 'GET_TASK',
actionType: 'PUT_TASK',
url: ApiTable.editTask,
msg: { error: '编辑或新增任务信息' },
msg: { option: '编辑或新增任务信息' },
});
}

14
web/client/src/sections/fillion/components/task/addTaskModal.js

@ -22,7 +22,7 @@ const AddModal = (props) => {
form.resetFields(['code'])//清空具体某个表单的值
}
useEffect(() => {
form.setFieldsValue(recordRow ? { 'name': recordRow?.road.routeName, 'code': recordRow?.road.routeCode, 'danger': recordRow?.dangerDescription, 'user': recordRow?.user.name } : {})
form.setFieldsValue(recordRow ? { 'name': recordRow?.road.id, 'code': recordRow?.road.id, 'danger': recordRow?.dangerDescription, 'user': recordRow?.user.id } : {})
}, [recordRow])
useEffect(async () => {
const res = await dispatch(getRoadway({}))
@ -31,11 +31,12 @@ const AddModal = (props) => {
//新增和修改
const handleSaveUpdate = () => {
form.validateFields().then((values) => {
console.log('VALUES', values)
//console.log('values', recordRow)
//console.log('values', values)
const val = {
routeCode: values.code,
dangerDescription: values.danger,
name: values.user,
userId: values.user,
routeId: values.name,
id: recordRow?.id
}
dispatch(editTask(val)).then(res => {
@ -77,7 +78,6 @@ const AddModal = (props) => {
showSearch
placeholder="请输入关键词"
onChange={(value) => {
console.log('value', value)
onChange()
setSelectVal(value)
}}
@ -86,7 +86,7 @@ const AddModal = (props) => {
}
options={roadRes?.map((item) => ({
label: item.routeName,
value: item.routeCode
value: item.id
})
)}
/>
@ -120,7 +120,7 @@ const AddModal = (props) => {
placeholder="请输入负责人"
options={userList?.map((item) => ({
label: item.name,
value: item.name
value: item.id
})
)}
/>

18
web/client/src/sections/fillion/containers/task.js

@ -10,7 +10,7 @@ import { getTask } from '../actions/task'
import { delTask } from '../actions/task'
const Task = (props) => {
const { dispatch, isRequesting } = props
const { dispatch } = props
const [addModalVis, setAddModalVis] = useState(false)
const [roadRes, setRoadRes] = useState([])//路线列表
const [selectVal, setSelectVal] = useState('all')//选择框得值
@ -24,7 +24,6 @@ const Task = (props) => {
}, [])
const getData = async (querySelect = { id: inputVal, isdanger: selectVal === 'all' ? undefined : selectVal === 'y' ? true : false }) => {
console.log('getData', inputVal, selectVal)
const task = await dispatch(getTask(querySelect))
setTaskRes(task.payload?.data)
}
@ -48,8 +47,7 @@ const Task = (props) => {
const delTaskHandler = async (record) => {
const res = await dispatch(delTask({ id: record.id }))
if (res.success) {
const task = await getData()
setTaskRes(task.payload?.data)
getData()
}
}
//查看
@ -75,6 +73,9 @@ const Task = (props) => {
{
title: '隐患说明',
dataIndex: 'dangerDescription',
//with: 20,
// textWrap: 'word-break',
// ellipsis: true
},
{
title: '下发时间',
@ -84,6 +85,7 @@ const Task = (props) => {
},
{
title: '责任人',
//with: 20,
render: (_, record) => {
return <div>{record.user.name}</div>
}
@ -135,7 +137,6 @@ const Task = (props) => {
<div style={{ marginLeft: 20 }}>
路线名称: <Select
allowClear='true'
loading={isRequesting}
showSearch
placeholder="请输入关键词"
//optionFilterProp="children"
@ -175,11 +176,10 @@ const Task = (props) => {
}
function mapStateToProps(state) {
const { auth } = state;
//const { task } = state;
return {
user: auth.user,
error: auth.error,
isRequesting: auth.isRequesting,
//isRequesting: task.isRequesting,
}
}

2
web/client/src/utils/webapi.js

@ -280,7 +280,7 @@ export const ApiTable = {
//养护费用
getMaintenance: '/road/maintenance/cost/nanchang/query',
//任务信息
getTask: 'task', delTask: 'task/{taskId}', editTask: 'editTask'
getTask: 'task', delTask: 'task/{taskId}', editTask: 'task'
};

Loading…
Cancel
Save