Browse Source

设备状态接入

master
liujiangyong 2 years ago
parent
commit
45ebd1cea4
  1. 24
      api/app/lib/controllers/patrolManage/patrolRecord.js
  2. 3
      api/app/lib/routes/patrolManage/patrolRecord.js
  3. 31
      weapp/package/pointsStatus/pointsStatus.js
  4. 9
      weapp/package/pointsStatus/pointsStatus.wxml
  5. 6
      weapp/package/pointsStatus/pointsStatus.wxss
  6. 3
      weapp/pages/index/index.js
  7. 4
      weapp/utils/getApiUrl.js

24
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) { async function addPatrolRecord (ctx, next) {
let error = { name: 'addError', message: '新增巡检记录失败' }; let error = { name: 'addError', message: '新增巡检记录失败' };
const transaction = await ctx.fs.dc.orm.transaction(); const transaction = await ctx.fs.dc.orm.transaction();
@ -368,6 +391,7 @@ function editPatrolRecordIssueHandle (opts) {
module.exports = { module.exports = {
findPatrolRecord, findPatrolRecord,
findPatrolRecordUnlicensed, findPatrolRecordUnlicensed,
findPointCurPatrolRecord,
addPatrolRecord, addPatrolRecord,
getPatrolRecordIssueHandle, getPatrolRecordIssueHandle,
getPatrolRecordIssueHandleById, getPatrolRecordIssueHandleById,

3
api/app/lib/routes/patrolManage/patrolRecord.js

@ -11,6 +11,9 @@ module.exports = function (app, router, opts) {
// 获取巡检记录,免token,用与生成巡检报告 // 获取巡检记录,免token,用与生成巡检报告
router.get('/patrolRecord/unlicensed', patrolRecord.findPatrolRecordUnlicensed); 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 } app.fs.api.logAttr['POST/patrolRecord/add'] = { content: '新增巡检记录', visible: true }
router.post('/patrolRecord/add', patrolRecord.addPatrolRecord); router.post('/patrolRecord/add', patrolRecord.addPatrolRecord);

31
weapp/package/pointsStatus/pointsStatus.js

@ -1,5 +1,5 @@
// package/pointsStatus/pointsStatus.js // package/pointsStatus/pointsStatus.js
import { getProjectGraph, getDeployPoints, getProjectPoints } from "../../utils/getApiUrl"; import { getProjectGraph, getDeployPoints, getProjectPoints, getdPointCurPatrolRecord } from "../../utils/getApiUrl";
import { Request } from "../../common"; import { Request } from "../../common";
Page({ Page({
@ -9,6 +9,7 @@ Page({
*/ */
data: { data: {
imgUrl: getApp().globalData.imgUrl, imgUrl: getApp().globalData.imgUrl,
describe: '',
image: '', image: '',
allPoints: [], allPoints: [],
setedPoints: [], setedPoints: [],
@ -41,28 +42,44 @@ Page({
}, },
calcTooltip(e) { calcTooltip(e) {
const that = this;
const pointNodeId = e.currentTarget.id; const pointNodeId = e.currentTarget.id;
const pointId = e.currentTarget.dataset.id; const { id: pointId, show } = e.currentTarget.dataset;
const windowWidth = wx.getSystemInfoSync().windowWidth; const windowWidth = wx.getSystemInfoSync().windowWidth;
const query = this.createSelectorQuery().in(this); const setTooltip = (status) => {
const query = that.createSelectorQuery().in(that);
query.select('#' + pointNodeId).boundingClientRect(data => { query.select('#' + pointNodeId).boundingClientRect(data => {
const sub = windowWidth - data.left < 100 ? 100 - (windowWidth - data.left) : 0; const sub = windowWidth - data.left < 100 ? 100 - (windowWidth - data.left) : 0;
const nextSetedPoints = this.data.setedPoints.map(p => { const nextSetedPoints = that.data.setedPoints.map(p => {
if (p.id == pointId) { if (p.pointId == pointId) {
p.sub = sub; p.sub = sub;
p.show = !p.show; p.show = !p.show;
if (status) {
p.status = status;
}
} }
return p; return p;
}) })
this.setData({ setedPoints: nextSetedPoints }) that.setData({ setedPoints: nextSetedPoints })
}).exec() }).exec()
}
if (!show) {
wx.showLoading({ title: '加载中...' });
Request.get(getdPointCurPatrolRecord(pointId)).then(res => {
wx.hideLoading();
setTooltip(res.length ? res[0].alarm ? '异常' : '正常' : '--');
})
} else {
setTooltip();
}
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
const { projectId } = options; const { projectId, describe } = options;
this.setData({ describe });
this.getData(projectId); this.getData(projectId);
}, },

9
weapp/package/pointsStatus/pointsStatus.wxml

@ -4,8 +4,9 @@
<view wx:for="{{setedPoints}}"> <view wx:for="{{setedPoints}}">
<image <image
src="/images/circle.png" src="/images/circle.png"
id="{{'point' + item.id}}" id="{{'point' + item.pointId}}"
data-id="{{item.id}}" data-id="{{item.pointId}}"
data-show="{{item.show}}"
class="point" class="point"
style="left:{{(item.position.relativeX * 100) + '%'}}; top:{{(item.position.relativeY * 100) + '%'}}" style="left:{{(item.position.relativeX * 100) + '%'}}; top:{{(item.position.relativeY * 100) + '%'}}"
bind:tap="calcTooltip" bind:tap="calcTooltip"
@ -17,9 +18,9 @@
> >
<view>设备编号:{{item.pointInfo.equipmentNo || '--'}}</view> <view>设备编号:{{item.pointInfo.equipmentNo || '--'}}</view>
<view>设备型号:{{item.pointInfo.equipmentModel || '--'}}</view> <view>设备型号:{{item.pointInfo.equipmentModel || '--'}}</view>
<view>设备状态:正常</view> <view>设备状态:{{item.status}}</view>
</view> </view>
</view> </view>
</view> </view>
<van-empty wx:else description="暂无布设图" /> <van-empty wx:else description="暂无布设图" />
<view id="dddd" class="fixed-selector">结构物介绍</view> <view class="describe">简介:{{describe || '--'}}</view>

6
weapp/package/pointsStatus/pointsStatus.wxss

@ -20,4 +20,10 @@
background-color: white; background-color: white;
border: 1px solid gainsboro; border: 1px solid gainsboro;
width: 98px; width: 98px;
word-wrap: break-word;
word-break: normal;
}
.describe {
margin: 10px;
} }

3
weapp/pages/index/index.js

@ -74,7 +74,8 @@ Page({
}, },
onMarkerTap(e) { 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}`})
}, },
/** /**

4
weapp/utils/getApiUrl.js

@ -38,6 +38,10 @@ exports.addPatrolRecord = () => {
exports.getPatrolRecord = (patrolPlanId, startTime, endTime, alarm, pointId) => { exports.getPatrolRecord = (patrolPlanId, startTime, endTime, alarm, pointId) => {
return `/patrolRecord/${patrolPlanId}/${startTime}/${endTime}/${alarm}/${pointId}` return `/patrolRecord/${patrolPlanId}/${startTime}/${endTime}/${alarm}/${pointId}`
} }
// 获取点位最新一条巡检记录
exports.getdPointCurPatrolRecord = (pointId) => {
return `/patrolRecord/${pointId}/cur`
}
// 获取巡检模板 // 获取巡检模板
exports.getPatrolTemplate = (id) => { exports.getPatrolTemplate = (id) => {

Loading…
Cancel
Save