Browse Source

结构物与点位删除调整

master
wenlele 2 years ago
parent
commit
d641d6283e
  1. 77
      api/app/lib/controllers/projectRegime/projectSituation.js
  2. 2
      web/client/src/layout/containers/layout/index.js
  3. 2
      web/client/src/sections/projectRegime/containers/information.js
  4. 309
      web/client/src/sections/projectRegime/containers/point.js

77
api/app/lib/controllers/projectRegime/projectSituation.js

@ -95,18 +95,53 @@ async function delProject (ctx, next) {
let userInfo = ctx.fs.api.userInfo;
const { id } = ctx.params
//删除结构物
await models.Project.destroy({
where: {
id,
}
})
const pointId = []
const pointLIst = await models.Point.findAll({
where: {
projectId: id,
},
attributes: ['id'],
})
pointLIst.map(v => pointId.push(v.id))
//点位
await models.Point.destroy({
where: {
projectId: id
}
})
//巡检计划
const planId = []
const planLIst = await models.PatrolPlan.findAll({
where: {
structureId: id,
},
attributes: ['id'],
})
planLIst.map(v => planId.push(v.id))
await models.PatrolPlan.destroy({
where: {
structureId: id
}
})
//巡检记录
await models.PatrolRecord.destroy({
where: {
pointId: { $in: pointId },
patrolPlanId: { $in: planId }
}
})
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
@ -202,6 +237,47 @@ async function delPosition (ctx, next) {
let userInfo = ctx.fs.api.userInfo;
const { id } = ctx.params
const pointOne = await models.Point.findOne({
where: {
id
},
attributes: ['projectId'],
})
if (pointOne) {
const patrolPlanLIst = await models.PatrolPlan.findAll({
where: {
structureId: pointOne.id,
},
attributes: ['id', 'structureId', 'points'],
})
patrolPlanLIst.map(async v => {
const points = []
v.points.map(r => {
if (r.id !== id) {
points.push(r)
}
})
v.points = points
await models.PatrolRecord.destroy({
where: {
pointId: id,
patrolPlanId: v.id
}
})
if (points.length > 0) {
await models.PatrolPlan.create(v)
} else {
await models.PatrolPlan.destroy({
where: {
id: v.id
}
})
}
})
}
await models.Point.destroy({
where: {
@ -209,6 +285,7 @@ async function delPosition (ctx, next) {
}
})
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)

2
web/client/src/layout/containers/layout/index.js

@ -67,7 +67,7 @@ const LayoutContainer = props => {
dom.scrollTop = 0;
}
})
console.log(clientHeight);
return (
<Layout id="layout">
<Layout.Header style={{ padding: 0 }}>

2
web/client/src/sections/projectRegime/containers/information.js

@ -103,7 +103,7 @@ const Information = (props) => {
>编辑</Button>
<Popconfirm
title='确认删除工程信息?'
title={<div style={{ width: 180 }}>删除此结构物后与结构物对应的点位巡检计划巡检记录也会删除是否确认删除</div>}
position='topLeft'
onConfirm={() => {
dispatch(projectRegime.delProject(record.id)).then(res => {

309
web/client/src/sections/projectRegime/containers/point.js

@ -6,7 +6,7 @@ import moment from "moment";
import '../style.less';
import { push } from 'react-router-redux';
import PointModel from '../components/pointModel'
import { Model } from 'echarts';
import { Model } from 'qrcode';
const Information = (props) => {
@ -27,11 +27,12 @@ const Information = (props) => {
const [form] = Form.useForm();
var QRCode = require('qrcode')
const { createCanvas, loadImage, registerFont } = require('canvas')
const qrCodeId = props?.match?.params?.id
useEffect(() => {
console.log(props?.match?.params?.id);
projectList(query)
}, [])
@ -71,141 +72,191 @@ const Information = (props) => {
return url
}
// const createQrCode = (name) => {
// const CW = 400, FONTSIZE = 30, FR = 2, CH = CW + FONTSIZE * FR;
// let url = ''
// // QRCode.toFile('F',name,
// // {
// // margin: 1,//二维码内边距,默认为4。单位px
// // height: CW,//二维码高度
// // width: CW,//二维码宽度
// // color: {
// // dark: '#000', //
// // light: '#fff' //
// // }
// // });
const columns = [
{
title: '序号',
dataIndex: 'index',
key: 'index',
render: (text, record, index) => index + 1
}, {
title: '点位名称',
dataIndex: 'name',
key: 'name',
}, {
title: '所在地区',
dataIndex: 'position',
key: 'position',
render: (text, record, index) => {
return record.longitude && record.latitude ? <div style={{ width: 100 }}>{record.longitude},{record.latitude}</div> : "--"
}
}, {
title: '描述',
dataIndex: 'describe',
key: 'describe',
render: (text, record, index) => record.describe || '--'
}, {
title: '操作',
dataIndex: 'operation',
key: 'operation',
render: (text, record, index) => {
return (
<div style={{ width: 224 }}>
<Button type="link" onClick={() => {
setAddModel(true)
setModelData(record)
console.log(record);
}}
// QRCode.toDataURL(name, {
// errorCorrectionLevel: 'low',
// type: 'image/png',
// quality: 0.3,
// margin: 2,
// maskPattern: 9,
// width: 400,
// color: {
// dark: "#000000ff",
// light: "#ffffffff"
// }
// }, function (err, v) {
// url = v
// })
// // return url
>编辑</Button>
<Popconfirm
title='确认删除工程信息?'
position='topLeft'
onConfirm={() => {
dispatch(projectRegime.delPosition(record.id)).then(res => {
if (res.success) {
if ((limits > 11 && tableList.length > 1) || limits < 11) {
projectList({ ...query, ...search })
} else {
projectList({ limit: query?.limit, page: query?.page - 1, ...search })
setQuery({ limit: query?.limit, page: query?.page - 1 });
}
// const canvas = createCanvas(CW, CH)
// const ctx = canvas.getContext('2d')
// ctx.clearRect(0, 0, CW, CH)
// ctx.fillStyle = 'rgba(255,255,255,1)'
// ctx.fillRect(0, 0, CW, CH)
// ctx.fillStyle = 'rgba(0,0,0,1)'
// ctx.font = `${FONTSIZE}px ZiTiQuanWeiJunHei`
// // ctx.font = `700 ${FONTSIZE}px `
// let image = loadImage(url)
// ctx.drawImage(image, 0, 0, CW, CW)
// const text = ctx.measureText(name)
// ctx.fillText(name, (CW - text.width) * 0.5, CH - FONTSIZE)
// canvas.toDataURL('image/png', (err, png) => {
// if (!err) {
// console.log(png);
// }
// })
// return url
// }
}
})
}}
>
<Button type="link" danger >删除</Button>
</Popconfirm>
{/* <Button type="link" danger >二维码生成</Button> */}
<Button type="link" onClick={() => {
let url = createQrCode('FS' + Date.now() + record.id)
console.log(url);
dispatch(projectRegime.addPosition({
qrCode: url,
id: record.id,
}, true))
}} >二维码生成</Button>
</div>
)
}
const columns = [
{
title: '序号',
dataIndex: 'index',
key: 'index',
render: (text, record, index) => index + 1
}, {
title: '点位名称',
dataIndex: 'name',
key: 'name',
}, {
title: '所在地区',
dataIndex: 'position',
key: 'position',
render: (text, record, index) => {
return record.longitude && record.latitude ? <div style={{ width: 100 }}>{record.longitude},{record.latitude}</div> : "--"
}
]
return (
<>
<img src={selec} />
<div style={{ display: 'flex', marginBottom: 10 }}>
<Button type="primary" onClick={() => {
setAddModel(true)
}}>新建点位</Button>
<Button type="primary" style={{ marginLeft: 20 }} onClick={() => {
select?.map(v => {
let url = createQrCode('FS' + Date.now() + v.id)
}, {
title: '描述',
dataIndex: 'describe',
key: 'describe',
render: (text, record, index) => record.describe || '--'
}, {
title: '操作',
dataIndex: 'operation',
key: 'operation',
render: (text, record, index) => {
return (
<div style={{ width: 224 }}>
<Button type="link" onClick={() => {
setAddModel(true)
setModelData(record)
console.log(record);
}}
>编辑</Button>
<Popconfirm
title={<div style={{ width: 184 }}>删除该点位后与巡检计划关联的点位删除对应的巡检记录删除是否确认删除</div>}
position='topLeft'
onConfirm={() => {
dispatch(projectRegime.delPosition(record.id)).then(res => {
if (res.success) {
if ((limits > 11 && tableList.length > 1) || limits < 11) {
projectList({ ...query, ...search })
} else {
projectList({ limit: query?.limit, page: query?.page - 1, ...search })
setQuery({ limit: query?.limit, page: query?.page - 1 });
}
}
})
}}
>
<Button type="link" danger >删除</Button>
</Popconfirm>
{/* <Button type="link" danger >二维码生成</Button> */}
<Button type="link" onClick={() => {
let url = createQrCode('FS' + Date.now() + record.id)
console.log(url);
dispatch(projectRegime.addPosition({
qrCode: url,
id: v.id,
id: record.id,
}, true))
})
}}>一键生成二维码</Button>
</div>
<Table
columns={columns}
dataSource={tableList}
pagination={{
current: query.page + 1,
total: limits,
showSizeChanger: true,
showQuickJumper: true,
pageSizeOptions: [10, 20, 50],
showTotal: (total) => {
return <span style={{ fontSize: 15 }}>{`${Math.ceil(total / query?.limit)}页,${total}`}</span>
},
onChange: (page, pageSize) => {
setQuery({ limit: pageSize, page: page - 1 });
projectList({ limit: pageSize, page: page - 1, ...search, companyId: companyID || search?.companyId })
}
}}
rowSelection={{
selectedRowKeys: select?.map(v => v.id) || [],
onChange: (selectedRowKeys, selectedRows) => {
setSelect(selectedRows)
console.log(selectedRows);
}
}}
/>
{
addModel ?
<PointModel
modelData={modelData}
qrCodeId={qrCodeId}
close={() => {
setAddModel(false)
setModelData({})
}}
success={() => {
setAddModel(false)
setModelData({})
setQuery({ limit: 10, page: 0 });
projectList({ limit: 10, page: 0 })
}}
/> : ""
}
</>
)
}} >二维码生成</Button>
</div>
)
}
}
]
return (
<>
<img src={selec} />
<div style={{ display: 'flex', marginBottom: 10 }}>
<Button type="primary" onClick={() => {
setAddModel(true)
}}>新建点位</Button>
<Button type="primary" style={{ marginLeft: 20 }} onClick={() => {
select?.map(v => {
let url = createQrCode('FS' + Date.now() + v.id)
console.log(url);
dispatch(projectRegime.addPosition({
qrCode: url,
id: v.id,
}, true))
})
}}>一键生成二维码</Button>
</div>
<Table
columns={columns}
dataSource={tableList}
pagination={{
current: query.page + 1,
total: limits,
showSizeChanger: true,
showQuickJumper: true,
pageSizeOptions: [10, 20, 50],
showTotal: (total) => {
return <span style={{ fontSize: 15 }}>{`${Math.ceil(total / query?.limit)}页,${total}`}</span>
},
onChange: (page, pageSize) => {
setQuery({ limit: pageSize, page: page - 1 });
projectList({ limit: pageSize, page: page - 1, ...search, companyId: companyID || search?.companyId })
}
}}
rowSelection={{
selectedRowKeys: select?.map(v => v.id) || [],
onChange: (selectedRowKeys, selectedRows) => {
setSelect(selectedRows)
console.log(selectedRows);
}
}}
/>
{
addModel ?
<PointModel
modelData={modelData}
qrCodeId={qrCodeId}
close={() => {
setAddModel(false)
setModelData({})
}}
success={() => {
setAddModel(false)
setModelData({})
setQuery({ limit: 10, page: 0 });
projectList({ limit: 10, page: 0 })
}}
/> : ""
}
</>
)
}
function mapStateToProps (state) {

Loading…
Cancel
Save