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 = { const whereopt = {
isdanger: query.isdanger isdanger: query.isdanger
} }
console.log('whereopt', whereopt)
const whereRoadOpt = { const whereRoadOpt = {
id: query.id id: query.id
} }
console.log('wherwhereRoadOpteopt', whereRoadOpt)
const taskRes = await models.TaskManage.findAndCountAll({ const taskRes = await models.TaskManage.findAndCountAll({
order: [['id', 'DESC']], order: [['id', 'DESC']],
attributes: ['id', 'dangerDescription', 'isdanger', 'issuanceTime', 'reportTime'], attributes: ['id', 'dangerDescription', 'isdanger', 'issuanceTime', 'reportTime'],
include: [ include: [
{ {
attributes: ['routeName', 'routeCode'], attributes: ['id', 'routeName', 'routeCode'],
model: models.Road, model: models.Road,
where: query.id == undefined ? {} : whereRoadOpt where: query.id == undefined ? {} : whereRoadOpt
}, },
{ {
attributes: ['name'], attributes: ['id', 'name'],
model: models.User model: models.User
} }
], ],
where: query.isdanger == undefined ? {} : whereopt where: query.isdanger == undefined ? {} : whereopt
}) })
ctx.body = taskRes ctx.body = taskRes
console.log('tas', taskRes)
ctx.status = 200 ctx.status = 200
} }
catch (error) { catch (error) {
@ -48,7 +44,6 @@ async function delTask(ctx) {
try { try {
const models = ctx.fs.dc.models const models = ctx.fs.dc.models
const { id } = ctx.params const { id } = ctx.params
console.log('params', id)
await models.TaskManage.destroy({ where: { id: id } }) await models.TaskManage.destroy({ where: { id: id } })
ctx.status = 204 ctx.status = 204
} catch (error) { } catch (error) {
@ -66,23 +61,18 @@ async function editTask(ctx) {
try { try {
const models = ctx.fs.dc.models const models = ctx.fs.dc.models
const params = ctx.request.body 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) { 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({ await models.TaskManage.create({
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim() roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim()
}) })
} else { } 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({ await models.TaskManage.update({
roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim() roadid: road.id, userid: user.id, dangerDescription: params.dangerDescription.trim()
}, { where: { id: params.id } }) }, { where: { id: params.id } })
} }
ctx.status = 204 ctx.status = 204
//await transaction.commit();
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; 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); router.get('/task', task.getTask);
app.fs.api.logAttr['DEL/task/:id'] = { content: '删除任务', visible: false }; app.fs.api.logAttr['DEL/task/:id'] = { content: '删除任务', visible: false };
router.del('/task/:id', task.delTask); router.del('/task/:id', task.delTask);
app.fs.api.logAttr['PUT/editTask'] = { content: '编辑任务', visible: false }; app.fs.api.logAttr['PUT/task'] = { content: '编辑任务', visible: false };
router.put('/editTask', task.editTask); router.put('/task', task.editTask);
//task END //task END
}; };

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

@ -28,8 +28,8 @@ export function editTask(query) {
type: 'put', type: 'put',
dispatch: dispatch, dispatch: dispatch,
data: query, data: query,
actionType: 'GET_TASK', actionType: 'PUT_TASK',
url: ApiTable.editTask, 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'])//清空具体某个表单的值 form.resetFields(['code'])//清空具体某个表单的值
} }
useEffect(() => { 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]) }, [recordRow])
useEffect(async () => { useEffect(async () => {
const res = await dispatch(getRoadway({})) const res = await dispatch(getRoadway({}))
@ -31,11 +31,12 @@ const AddModal = (props) => {
//新增和修改 //新增和修改
const handleSaveUpdate = () => { const handleSaveUpdate = () => {
form.validateFields().then((values) => { form.validateFields().then((values) => {
console.log('VALUES', values) //console.log('values', recordRow)
//console.log('values', values)
const val = { const val = {
routeCode: values.code,
dangerDescription: values.danger, dangerDescription: values.danger,
name: values.user, userId: values.user,
routeId: values.name,
id: recordRow?.id id: recordRow?.id
} }
dispatch(editTask(val)).then(res => { dispatch(editTask(val)).then(res => {
@ -77,7 +78,6 @@ const AddModal = (props) => {
showSearch showSearch
placeholder="请输入关键词" placeholder="请输入关键词"
onChange={(value) => { onChange={(value) => {
console.log('value', value)
onChange() onChange()
setSelectVal(value) setSelectVal(value)
}} }}
@ -86,7 +86,7 @@ const AddModal = (props) => {
} }
options={roadRes?.map((item) => ({ options={roadRes?.map((item) => ({
label: item.routeName, label: item.routeName,
value: item.routeCode value: item.id
}) })
)} )}
/> />
@ -120,7 +120,7 @@ const AddModal = (props) => {
placeholder="请输入负责人" placeholder="请输入负责人"
options={userList?.map((item) => ({ options={userList?.map((item) => ({
label: item.name, 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' import { delTask } from '../actions/task'
const Task = (props) => { const Task = (props) => {
const { dispatch, isRequesting } = props const { dispatch } = props
const [addModalVis, setAddModalVis] = useState(false) const [addModalVis, setAddModalVis] = useState(false)
const [roadRes, setRoadRes] = useState([])//路线列表 const [roadRes, setRoadRes] = useState([])//路线列表
const [selectVal, setSelectVal] = useState('all')//选择框得值 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 }) => { 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)) const task = await dispatch(getTask(querySelect))
setTaskRes(task.payload?.data) setTaskRes(task.payload?.data)
} }
@ -48,8 +47,7 @@ const Task = (props) => {
const delTaskHandler = async (record) => { const delTaskHandler = async (record) => {
const res = await dispatch(delTask({ id: record.id })) const res = await dispatch(delTask({ id: record.id }))
if (res.success) { if (res.success) {
const task = await getData() getData()
setTaskRes(task.payload?.data)
} }
} }
//查看 //查看
@ -75,6 +73,9 @@ const Task = (props) => {
{ {
title: '隐患说明', title: '隐患说明',
dataIndex: 'dangerDescription', dataIndex: 'dangerDescription',
//with: 20,
// textWrap: 'word-break',
// ellipsis: true
}, },
{ {
title: '下发时间', title: '下发时间',
@ -84,6 +85,7 @@ const Task = (props) => {
}, },
{ {
title: '责任人', title: '责任人',
//with: 20,
render: (_, record) => { render: (_, record) => {
return <div>{record.user.name}</div> return <div>{record.user.name}</div>
} }
@ -135,7 +137,6 @@ const Task = (props) => {
<div style={{ marginLeft: 20 }}> <div style={{ marginLeft: 20 }}>
路线名称: <Select 路线名称: <Select
allowClear='true' allowClear='true'
loading={isRequesting}
showSearch showSearch
placeholder="请输入关键词" placeholder="请输入关键词"
//optionFilterProp="children" //optionFilterProp="children"
@ -175,11 +176,10 @@ const Task = (props) => {
} }
function mapStateToProps(state) { function mapStateToProps(state) {
const { auth } = state; //const { task } = state;
return { return {
user: auth.user,
error: auth.error, //isRequesting: task.isRequesting,
isRequesting: auth.isRequesting,
} }
} }

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

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

Loading…
Cancel
Save