diff --git a/api/app/lib/controllers/patrolManage/patrolRecord.js b/api/app/lib/controllers/patrolManage/patrolRecord.js index 482cef0..f790006 100644 --- a/api/app/lib/controllers/patrolManage/patrolRecord.js +++ b/api/app/lib/controllers/patrolManage/patrolRecord.js @@ -166,6 +166,29 @@ async function findPatrolRecordUnlicensed (ctx, next) { } } +async function findPointCurPatrolRecord (ctx, next) { + let rslt = []; + let error = { name: 'FindError', message: '获取巡检记录失败' }; + try { + const models = ctx.fs.dc.models; + const { pointId } = ctx.params; + const options = { + where: { pointId }, + order: [['inspectionTime', 'desc']], + limit: 1, + } + rslt = await models.PatrolRecord.findAll(options); + ctx.status = 200; + ctx.body = rslt; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "获取巡检记录失败" + } + } +} + async function addPatrolRecord (ctx, next) { let error = { name: 'addError', message: '新增巡检记录失败' }; const transaction = await ctx.fs.dc.orm.transaction(); @@ -368,6 +391,7 @@ function editPatrolRecordIssueHandle (opts) { module.exports = { findPatrolRecord, findPatrolRecordUnlicensed, + findPointCurPatrolRecord, addPatrolRecord, getPatrolRecordIssueHandle, getPatrolRecordIssueHandleById, diff --git a/api/app/lib/routes/patrolManage/patrolRecord.js b/api/app/lib/routes/patrolManage/patrolRecord.js index 1535b07..4bf2272 100644 --- a/api/app/lib/routes/patrolManage/patrolRecord.js +++ b/api/app/lib/routes/patrolManage/patrolRecord.js @@ -11,6 +11,9 @@ module.exports = function (app, router, opts) { // 获取巡检记录,免token,用与生成巡检报告 router.get('/patrolRecord/unlicensed', patrolRecord.findPatrolRecordUnlicensed); + app.fs.api.logAttr['GET/patrolRecord/:pointId/cur'] = { content: '获取点位最近巡检记录', visible: true }; + router.get('/patrolRecord/:pointId/cur', patrolRecord.findPointCurPatrolRecord); + app.fs.api.logAttr['POST/patrolRecord/add'] = { content: '新增巡检记录', visible: true } router.post('/patrolRecord/add', patrolRecord.addPatrolRecord); diff --git a/weapp/package/pointsStatus/pointsStatus.js b/weapp/package/pointsStatus/pointsStatus.js index ab85df9..71b05ca 100644 --- a/weapp/package/pointsStatus/pointsStatus.js +++ b/weapp/package/pointsStatus/pointsStatus.js @@ -1,5 +1,5 @@ // package/pointsStatus/pointsStatus.js -import { getProjectGraph, getDeployPoints, getProjectPoints } from "../../utils/getApiUrl"; +import { getProjectGraph, getDeployPoints, getProjectPoints, getdPointCurPatrolRecord } from "../../utils/getApiUrl"; import { Request } from "../../common"; Page({ @@ -9,6 +9,7 @@ Page({ */ data: { imgUrl: getApp().globalData.imgUrl, + describe: '', image: '', allPoints: [], setedPoints: [], @@ -41,28 +42,44 @@ Page({ }, calcTooltip(e) { + const that = this; const pointNodeId = e.currentTarget.id; - const pointId = e.currentTarget.dataset.id; + const { id: pointId, show } = e.currentTarget.dataset; const windowWidth = wx.getSystemInfoSync().windowWidth; - const query = this.createSelectorQuery().in(this); - query.select('#' + pointNodeId).boundingClientRect(data => { - const sub = windowWidth - data.left < 100 ? 100 - (windowWidth - data.left) : 0; - const nextSetedPoints = this.data.setedPoints.map(p => { - if (p.id == pointId) { - p.sub = sub; - p.show = !p.show; - } - return p; + const setTooltip = (status) => { + const query = that.createSelectorQuery().in(that); + query.select('#' + pointNodeId).boundingClientRect(data => { + const sub = windowWidth - data.left < 100 ? 100 - (windowWidth - data.left) : 0; + const nextSetedPoints = that.data.setedPoints.map(p => { + if (p.pointId == pointId) { + p.sub = sub; + p.show = !p.show; + if (status) { + p.status = status; + } + } + return p; + }) + that.setData({ setedPoints: nextSetedPoints }) + }).exec() + } + if (!show) { + wx.showLoading({ title: '加载中...' }); + Request.get(getdPointCurPatrolRecord(pointId)).then(res => { + wx.hideLoading(); + setTooltip(res.length ? res[0].alarm ? '异常' : '正常' : '--'); }) - this.setData({ setedPoints: nextSetedPoints }) - }).exec() + } else { + setTooltip(); + } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { - const { projectId } = options; + const { projectId, describe } = options; + this.setData({ describe }); this.getData(projectId); }, diff --git a/weapp/package/pointsStatus/pointsStatus.wxml b/weapp/package/pointsStatus/pointsStatus.wxml index f1e2a9b..639c321 100644 --- a/weapp/package/pointsStatus/pointsStatus.wxml +++ b/weapp/package/pointsStatus/pointsStatus.wxml @@ -4,8 +4,9 @@ 设备编号:{{item.pointInfo.equipmentNo || '--'}} 设备型号:{{item.pointInfo.equipmentModel || '--'}} - 设备状态:正常 + 设备状态:{{item.status}} -结构物介绍 \ No newline at end of file +简介:{{describe || '--'}} \ No newline at end of file diff --git a/weapp/package/pointsStatus/pointsStatus.wxss b/weapp/package/pointsStatus/pointsStatus.wxss index 39206f0..30fb0e0 100644 --- a/weapp/package/pointsStatus/pointsStatus.wxss +++ b/weapp/package/pointsStatus/pointsStatus.wxss @@ -20,4 +20,10 @@ background-color: white; border: 1px solid gainsboro; width: 98px; + word-wrap: break-word; + word-break: normal; +} + +.describe { + margin: 10px; } \ No newline at end of file diff --git a/weapp/pages/index/index.js b/weapp/pages/index/index.js index afe59d6..1b91edd 100644 --- a/weapp/pages/index/index.js +++ b/weapp/pages/index/index.js @@ -74,7 +74,8 @@ Page({ }, onMarkerTap(e) { - wx.navigateTo({url: `/package/pointsStatus/pointsStatus?projectId=${e.detail.markerId}`}) + const describe = this.data.project.find(p => p.id === e.detail.markerId).describe || ''; + wx.navigateTo({url: `/package/pointsStatus/pointsStatus?projectId=${e.detail.markerId}&describe=${describe}`}) }, /** diff --git a/weapp/utils/getApiUrl.js b/weapp/utils/getApiUrl.js index 1e61553..38fa000 100644 --- a/weapp/utils/getApiUrl.js +++ b/weapp/utils/getApiUrl.js @@ -38,6 +38,10 @@ exports.addPatrolRecord = () => { exports.getPatrolRecord = (patrolPlanId, startTime, endTime, alarm, pointId) => { return `/patrolRecord/${patrolPlanId}/${startTime}/${endTime}/${alarm}/${pointId}` } +// 获取点位最新一条巡检记录 +exports.getdPointCurPatrolRecord = (pointId) => { + return `/patrolRecord/${pointId}/cur` +} // 获取巡检模板 exports.getPatrolTemplate = (id) => {