Browse Source

feat:小程序首页+子系统的接口实现,接入真实数据

master
zhaobing’ 1 year ago
parent
commit
17843ef310
  1. 34
      api/app/lib/controllers/patrolManage/patrolRecord.js
  2. 3
      api/app/lib/index.js
  3. 4
      api/app/lib/routes/patrolManage/patrolRecord.js
  4. 403
      weapp/package/subSystem/subSystem.js
  5. 9
      weapp/package/subSystem/subSystem.wxml
  6. 18
      weapp/package/subSystem/subSystem.wxss
  7. 41
      weapp/pages/home/home.js
  8. 22
      weapp/pages/home/home.wxml
  9. 11
      weapp/pages/home/home.wxss
  10. 6
      weapp/utils/getApiUrl.js

34
api/app/lib/controllers/patrolManage/patrolRecord.js

@ -412,6 +412,37 @@ function editPatrolRecordIssueHandle(opts) {
}
}
}
//查询子系统的当月的巡检和维修
function getSubSystemPatrolAbout(opts) {
return async function (ctx, next){
try{
let rslt=[]
const models = ctx.fs.dc.models;
const {STime,ETime,keywords}=ctx.query
let generalInclude = [{model: models.PatrolRecordIssueHandle},{model:models.Project,where:{subType :{$like: `%${keywords}%`}}}]
rslt=await models.PatrolRecord.findAll({
where:{inspectionTime: { $between: [STime, ETime] }},
include:generalInclude
})
let userInfo = ctx.fs.api.userInfo;
rslt = rslt.filter(f => f)
if (userInfo.username != 'SuperAdmin') {
if (userInfo.structure) {
rslt = rslt.filter(s => userInfo.structure.find(x => x == s.points.project.id))
} else {
rslt = []
}
}
ctx.status = 200;
ctx.body = rslt
}catch(error){
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '子系统查询巡检记录失败' }
}
}
}
//
Array.prototype.group = function (callback, thisArg = null) {
// 参数合法性判断
@ -441,5 +472,6 @@ module.exports = {
getPatrolRecordIssueHandle,
getPatrolRecordIssueHandleById,
addPatrolRecordIssueHandle,
editPatrolRecordIssueHandle
editPatrolRecordIssueHandle,
getSubSystemPatrolAbout
}

3
api/app/lib/index.js

@ -62,6 +62,9 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
PatrolRecord.belongsTo(PatrolPlan, { foreignKey: 'patrolPlanId', targetKey: 'id' });
PatrolPlan.hasMany(PatrolRecord, { foreignKey: 'patrolPlanId', sourceKey: 'id' });
PatrolRecord.belongsTo(Project, { foreignKey: 'projectId', targetKey: 'id' });
Project.hasMany(PatrolRecord, { foreignKey: 'projectId', sourceKey: 'id' });
PatrolRecordIssueHandle.belongsTo(PatrolRecord, { foreignKey: 'patrolRecordId', targetKey: 'id' });
PatrolRecord.hasMany(PatrolRecordIssueHandle, { foreignKey: 'patrolRecordId', sourceKey: 'id' });

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

@ -30,4 +30,8 @@ module.exports = function (app, router, opts) {
// 修改维修处理计划
app.fs.api.logAttr['PUT/patrolRecord/issue/handle/:id'] = { content: '修改维修处理计划', visible: true };
router.put('/patrolRecord/issue/handle/:id', patrolRecord.editPatrolRecordIssueHandle(opts))
//子系统巡检记录
app.fs.api.logAttr['GET/patrolRecord/subSystemPatrolAbout'] = { content: '子系统查询巡检记录', visible: true };
router.get('/patrolRecord/subSystemPatrolAbout', patrolRecord.getSubSystemPatrolAbout(opts))
};

403
weapp/package/subSystem/subSystem.js

@ -1,173 +1,242 @@
// package/subSystem/subSystem.js
import * as echarts from '../components/ec-canvas/echarts';
let chart = null;
function initChart(canvas, width, height, dpr) {
const chart = echarts.init(canvas, null, {
width: 300,
height: 300,
devicePixelRatio: dpr // new
});
canvas.setChart(chart);
var option = {
backgroundColor: "#ffffff",
series: [{
label: {
normal: {
fontSize: 14
}
},
type: 'pie',
center: ['50%', '50%'],
radius: ['20%', '40%'],
data: [{
value: 55,
name: '北京'
}, {
value: 20,
name: '武汉'
}, {
value: 10,
name: '杭州'
}, {
value: 20,
name: '广州'
}, {
value: 38,
name: '上海'
}]
}]
};
chart.setOption(option);
return chart;
}
Page({
import {
getSubSystemPatrolAbout
} from "../../utils/getApiUrl";
import {
Request
} from "../../common";
const moment = require("../../utils/moment");
/**
* 页面的初始数据
*/
data: {
ec: {
onInit: initChart
},
date: '',
show: true,
selectedDate: new Date(),// 设置默认选中的日期为当前日期
formatter(day) {
console.log('xxasaasas',day)
const month = day.date.getMonth() + 1;
const date = day.date.getDate();
const style = {};
if (month === 10) {
if (date === 1) {
day.bottomInfo = '.';
day.className='dayClass'
style.backgroundColor = 'red';
// document.getElementsByClassName('van-calendar__bottom-info')
}
}
if (day.type === 'start') {
day.bottomInfo = '入住';
} else if (day.type === 'end') {
day.bottomInfo = '离店';
}
day.style = style;
console.log('day111',day)
return day;
Page({
initECharts(option) {
this.ecComponent.init((canvas, width, height, dpr) => {
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr,
});
// 设置图表的配置
chart.setOption(option);
// 将 ECharts 实例保存在数据中
this.chart = chart;
// 返回 ECharts 实例
return chart;
});
},
/**
* 页面的初始数据
*/
data: {
ec: {
// lazyLoad: true, // 延迟加载 ECharts
},
date: '',
show: true,
currentPatrolCount: 0, //当月巡检次数
currentRepairCount: 0, //当月维修次数
level1Count: 0, //轻微
level2Count: 0, //中度
level3Count: 0, //严重
selectedDate: new Date(), // 设置默认选中的日期为当前日期
formatter(day) {
return day;
},
},
onDisplay() {
this.setData({ show: true });
},
onClose() {
this.setData({ show: false });
},
onConfirm(event) {
this.setData({
show: false,
date: this.formatDate(event.detail),
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.setNavigationBarTitle({
title: options.key,
});
// 其他渲染逻辑
// 创建一个 Date 对象来获取当前日期
const currentDate = new Date();
// 获取当前年份
const currentYear = currentDate.getFullYear();
// 获取当前月份(注意,月份是从 0 到 11 表示,所以需要加 1)
const currentMonth = currentDate.getMonth() + 1;
// 获取当前月份的第一天和最后一天
const nextMonth = new Date().getMonth() + 1;
const firstDay = new Date().setDate(1);
const lastDay = new Date().setMonth(nextMonth,1) - 86400000;
// 更新数据,将年份和月份传递给 WXML 页面
this.setData({
currentYear: currentYear,
currentMonth: currentMonth,
lastDay:lastDay,
firstDay:firstDay
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
},
onDisplay() {
this.setData({
show: true
});
},
onClose() {
this.setData({
show: false
});
},
onConfirm(event) {
this.setData({
show: false,
date: this.formatDate(event.detail),
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
const {windowHeight}=wx.getSystemInfoSync()
const pageHeight=windowHeight - 48
const that=this
wx.showLoading({
title: '加载中'
})
// const that = this;
wx.setNavigationBarTitle({
title: options.key,
});
//加载初始化数据
that.getSubSystemPatrolAbout(options)
//初始化图表的配置项
// 其他渲染逻辑
// 创建一个 Date 对象来获取当前日期
const currentDate = new Date();
// 获取当前年份
const currentYear = currentDate.getFullYear();
// 获取当前月份(注意,月份是从 0 到 11 表示,所以需要加 1)
const currentMonth = currentDate.getMonth() + 1;
// 获取当前月份的第一天和最后一天
const nextMonth = new Date().getMonth() + 1;
const firstDay = new Date().setDate(1);
const lastDay = new Date().setMonth(nextMonth, 1) - 86400000;
// 更新数据,将年份和月份传递给 WXML 页面
that.setData({
currentYear: currentYear,
currentMonth: currentMonth,
lastDay: lastDay,
firstDay: firstDay,
pageHeight:pageHeight+'px'
});
wx.hideLoading()
},
//过滤轻微,中度,重度的巡检个数
filterLevelCount:function(list,level){
return list?.filter(i => {
const content = i?.points?.inspectContent
if (content) {
for (let key in content) {
if (content.hasOwnProperty(key)) {
const subObject = content[key];
return subObject.level===level
}
}
}
})?.length
},
getSubSystemPatrolAbout: function (options) {
let that = this;
//当月开始时间
const STime = moment().startOf('month').format('YYYY-MM-DD')
//当月结束时间
const ETime = moment().endOf('month').format('YYYY-MM-DD')
//子系统关键字
let keywords = options.key
// keywords = '管廊'
const query = {
STime,
ETime,
keywords
}
Request.get(getSubSystemPatrolAbout(query)).then(res => {
if (res) {
//巡查内容
that.setData({
currentRepairCount: res?.filter(i => i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))).length || 0,
currentPatrolCount: res.length,
level1Count: that.filterLevelCount(res,'轻微')||0,
level2Count: that.filterLevelCount(res,'中度')||0,
level3Count: that.filterLevelCount(res,'严重')||0,
formatter:function(e){
res?.map(i=>{
if(moment(i.inspectionTime).format('YYYY-MM-DD')==moment(e.date).format('YYYY-MM-DD')){
if( i.patrolRecordIssueHandles.length==0){
e.bottomInfo = '.';e.className = 'greenClass'
}else if( i.patrolRecordIssueHandles.length&& i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))){
e.bottomInfo = '.';e.className = 'yellowClass'
}
}
})
return e
}
})
that.ecComponent = that.selectComponent('#mychart-dom-pie');
console.log('that.level1Count',this.data.level2Count)
var option = {
backgroundColor: "#ffffff",
legend: {
bottom: 10,
left: 'center',
},
series: [{
label: {
normal: {
fontSize: 14
}
},
type: 'pie',
center: ['50%', '50%'],
radius: ['20%', '40%'],
data:[ {name:'轻微',value:that.data.level1Count},
{name:'中度',value:that.data.level2Count},
{name:'重度',value:that.data.level3Count}]
}]
};
that.initECharts(option);
wx.hideLoading()
} else {
wx.hideLoading();
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
getSubSystemPatrolAbout()
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

9
weapp/package/subSystem/subSystem.wxml

@ -3,11 +3,11 @@
<view style="display: flex;justify-content: space-around;margin-bottom: 10px; padding-top: 10px; background-image: linear-gradient(179deg, #006BE3 0%, #4E87FF 16%, #4e87ff00 93%);">
<view>
<view>本月巡检次数</view>
<view class="number">0</view>
<view class="number">{{currentPatrolCount}}</view>
</view>
<view>
<view>本月维修次数</view>
<view class="number">0</view>
<view class="number">{{currentRepairCount}}</view>
</view>
</view>
<!--饼图-->
@ -15,7 +15,7 @@
<ec-canvas id="mychart-dom-pie" canvas-id="mychart-pie" ec="{{ ec }}"></ec-canvas>
</view>
<!--巡检日历-->
<view class="card">
<view class="card heightStyle">
<view class="header">
<view class="xunjian">巡检日历</view>
<view class="yearMonth">{{currentYear+'年'+currentMonth+'月'}}</view>
@ -28,7 +28,8 @@
show-subtitle="{{false}}"
poppable="{{ false }}"
show-confirm="{{ false }}"
:default-date="defaultDate"
default-date="{{selectedDate}}"
formatter="{{formatter}}"
color="#0000FF"
class="calendar" />
</view>

18
weapp/package/subSystem/subSystem.wxss

@ -20,9 +20,13 @@
/* padding: 10px 10px; */
margin: 5px 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
width: 300px;
/* width: 300px; */
height: 300px;
}
.heightStyle{
height: auto;
}
.xunjian{
width: 64px;
height: 22px;
@ -48,9 +52,15 @@
margin-bottom: 10px;
margin-top:10px;
}
.dayClass .van-calendar__bottom-info{
font-size: large;
color:blue;
.yellowClass .van-calendar__bottom-info{
font-size: 50px;
color:yellow;
}
.greenClass .van-calendar__bottom-info{
font-size: 50px;
color:green;
}

41
weapp/pages/home/home.js

@ -22,6 +22,7 @@ Page({
allHandleCount:0,//总的问题解决个数
todayRecord: [], // 今日巡检记录
markers: [],
pageHeight:0,//屏幕高度
isShowCallout: false,
itemList:[{
picPath:'/images/conduct.png',
@ -65,7 +66,6 @@ Page({
}
],
},
/**
@ -75,24 +75,47 @@ Page({
const userInfo=wx.getStorageSync('userInfo');
const {windowHeight}=wx.getSystemInfoSync()
const pageHeight=windowHeight - 48
console.log('todayRecord1',this.todayRecord)
const promiseArr = [];
const that = this;
var data = {
"datas": [
{
"id": 1,
"imgurl": "/images/avatar.png"
},
{
"id": 2,
"imgurl": "/images/card_bg.png"
}
]
};
wx.showLoading({ title: '加载中' })
promiseArr.push(Request.get(getPatrolRecord('all', moment('1970-1-1').format('YYYY-MM-DD') + ' 00:00:00', moment('2099-12-31').format('YYYY-MM-DD') + ' 23:59:59', 'null', 'null')));
Promise.all(promiseArr).then(res => {
console.log('xxxaxax',userInfo)
console.log('xxxaxax',res[0]?.filter(item=>item?.points?.user.id===userInfo.id))
wx.hideLoading()
//与自己相关的所有巡检记录
const list=res[0]?.filter(item=>item?.points?.user.id===userInfo.id)||[]
//过去七天的所有巡检记录
const sevenDaysList=list?.filter(item=>
{
const recordDate = moment(date, 'YYYY-MM-DD'); // 解析日期
const daysDifference = moment().diff(recordDate, 'days'); // 计算日期差
// 返回近七天内的记录
return daysDifference >= 0 && daysDifference < 7;
}
)||[]
that.setData({
allCount:res[0]?.filter(item=>item?.points?.user.id===userInfo.id)?.length || 0,
todayRecord: res[0],
pageHeight:pageHeight+'px'
allCount:list.length || 0,
allQuestionCount:list?.filter(i=>i.patrolRecordIssueHandles>0)?.length || 0,
allHandleCount:list?.filter(i => i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))).length || 0,
sevenDaysCount:sevenDaysList.length||0,
sevenDaysQuestionCount:sevenDaysList?.filter(i=>i.patrolRecordIssueHandles>0)?.length || 0,
sevenDaysHandleCount:sevenDaysList?.filter(i => i?.patrolRecordIssueHandles[0]?.yanshoushijian && parseInt(moment(i?.patrolRecordIssueHandles[0]?.yanshoushijian).format('YYYYMMDD')) === parseInt(moment().format('YYYYMMDD'))).length || 0,
pageHeight:pageHeight+'px',
swiperData:data.datas
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成

22
weapp/pages/home/home.wxml

@ -1,8 +1,14 @@
<!--pages/home/home.wxml-->
<view style="height:{{pageHeight}} ; overflow: auto;">
<!--顶部图片-->
<view class="top">
<image src="/images/email.svg" style="width: 100px;height: 100px;" />
<!--轮播图-->
<view class="card">
<swiper class="home-swiper" indicator-dots="true" autoplay="{{true}}" interval="{{2000}}" duration="{{500}}">
<block wx:for-items="{{swiperData}}">
<swiper-item>
<image src="{{item.imgurl}}" class="slide-image" />
</swiper-item>
</block>
</swiper>
</view>
<!--子系统列表-->
<view class="list card" style="display: flex; flex-wrap: wrap;">
@ -20,14 +26,14 @@
</view>
<view style="margin:40px 10px 20px 10px">
<view>巡检次数</view>
<view>次</view>
<view>{{sevenDaysCount}}次</view>
</view>
</view>
<view style="display: flex; justify-content: space-around;">
<view style="margin:10px 0px;">发现问题个数</view>
<view style="margin:10px 0px;">个</view>
<view style="margin:10px 0px;">{{sevenDaysQuestionCount}}个</view>
<view style="margin:10px 0px;">问题处理个数</view>
<view style="margin:10px 0px;">个</view>
<view style="margin:10px 0px;">{{sevenDaysHandleCount}}个</view>
</view>
</view>
<!--总巡巡检统计-->
@ -44,9 +50,9 @@
</view>
<view style="display: flex; justify-content: space-around;">
<view style="margin:10px 0px;">发现问题个数</view>
<view style="margin:10px 0px;">个</view>
<view style="margin:10px 0px;">{{allQuestionCount}}个</view>
<view style="margin:10px 0px;">问题处理个数</view>
<view style="margin:10px 0px;">{{todayRecord.length}}个</view>
<view style="margin:10px 0px;">{{allHandleCount}}个</view>
</view>
</view>
</view>

11
weapp/pages/home/home.wxss

@ -13,4 +13,13 @@
/* padding: 10px; */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
margin: 10px;
}
}
.home-swiper {
width: 95%;
/* height: 360rpx; */
}
/* .slide-image {
width: 100%;
height: 100%;
} */

6
weapp/utils/getApiUrl.js

@ -38,6 +38,12 @@ exports.addPatrolRecord = () => {
exports.getPatrolRecord = (patrolPlanId, startTime, endTime, alarm, pointId) => {
return `/patrolRecord/${patrolPlanId}/${startTime}/${endTime}/${alarm}/${pointId}`
}
//获取子系统的巡检记录
exports.getSubSystemPatrolAbout = (query) => {
const { STime, ETime,keywords } = query;
return `/patrolRecord/subSystemPatrolAbout?STime=${STime}&ETime=${ETime}&keywords=${keywords}`
}
// 获取点位最新一条巡检记录
exports.getdPointCurPatrolRecord = (pointId) => {
return `/patrolRecord/${pointId}/cur`

Loading…
Cancel
Save