Browse Source

增加 周/月日期切换

feat
chenJinxu 11 months ago
parent
commit
d4b60864a4
3 changed files with 136 additions and 44 deletions
  1. +77
    -0
      src/services/utils-service.js
  2. +4
    -3
      src/views/insight/index.vue
  3. +55
    -41
      src/views/insight/signsReport.vue

+ 77
- 0
src/services/utils-service.js View File

@@ -193,3 +193,80 @@ export function nameConvert(name) {
} }
return userName; return userName;
} }

// 获取最近两年的月份,返回每个月的开始时间和结束时间,当前年份和当前月份
/**
*
* @param {*} yearsBack 获取的最近多少年份
* @returns
*/
export function getMonthsByYear(yearsBack) {
const currentDate = new Date();
const startYear = currentDate.getFullYear() - yearsBack;
const endYear = currentDate.getFullYear();

const dates = [];

for (let year = startYear; year <= endYear; year++) {
for (let month = 0; month < 12; month++) {
const startOfMonth = new Date(year, month, 2);
startOfMonth.setHours(0, 0, 0, 0);

const endOfMonth = new Date(year, month + 1, 0);
endOfMonth.setHours(23, 59, 59, 999);

// 只保留当前年份之前的月份数据
if (year < currentDate.getFullYear() || (year === currentDate.getFullYear() && month <= currentDate.getMonth())) {
dates.push({
start: startOfMonth.toISOString().split('T')[0],
end: endOfMonth.toISOString().split('T')[0],
curYear: year,
curMonth: month + 1
});
}
}
}

return dates;
}

// 获取最近一年的周报,从上周五到上周六,返回周开始和结束时间的年月日
export function getWeeksByYear(yearsBack) {
const currentDate = new Date();
const startDate = new Date(currentDate.getFullYear() - yearsBack || 1, currentDate.getMonth(), currentDate.getDate());
const endDate = new Date(currentDate.getFullYear(), currentDate.getMonth());

const result = [];

while (startDate <= endDate) {
/* const monthStart = new Date(startDate.getFullYear(), startDate.getMonth(), 1) */ // 获取该月有多少天
const daysInMonth = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0).getDate();

for (let week = 0; week < 5; week++) {
// 假设每月至少有4周,最多包含5周
const weekStartDate = new Date(startDate);
weekStartDate.setDate(Math.max(1, weekStartDate.getDate() - (weekStartDate.getDay() || 7) + 7)); // 上周六
const weekEndDate = new Date(weekStartDate);
weekEndDate.setDate(weekEndDate.getDate() + 6); // 下周五

// 防止跨越到下个月
if (weekEndDate.getDate() > daysInMonth) {
break;
}

result.push({
curYear: startDate.getFullYear(),
curMonth: startDate.getMonth() + 1,
month: `${startDate.getFullYear()}-${startDate.getMonth() + 1}`,
start: weekStartDate.toISOString().split('T')[0],
end: weekEndDate.toISOString().split('T')[0]
});

startDate.setDate(startDate.getDate() + 7);
}

startDate.setMonth(startDate.getMonth() + 1);
}

return result;
}

+ 4
- 3
src/views/insight/index.vue View File

@@ -1017,7 +1017,7 @@ export default {
let max = 0; let max = 0;
data.forEach(item => { data.forEach(item => {
if (item.value > max) { if (item.value > max) {
max = item.value;
max = item.value || '--';
} }
}); });
data.forEach(item => { data.forEach(item => {
@@ -1063,7 +1063,7 @@ export default {
let max = 0; let max = 0;
data.forEach(item => { data.forEach(item => {
if (item.value > max) { if (item.value > max) {
max = item.value;
max = item.value || '--';
} }
}); });
data.forEach(item => { data.forEach(item => {
@@ -1145,7 +1145,7 @@ export default {
} }
}); });
ydata.push({ ydata.push({
value: item.value,
value: item.value || '--',
label: { label: {
show: false show: false
}, },
@@ -1309,6 +1309,7 @@ export default {
align: 'center' align: 'center'
}, },
formatter: function (params) { formatter: function (params) {
console.log("params", params);
return params[0].marker + params[0].name + '</br>' + params[0].value; return params[0].marker + params[0].name + '</br>' + params[0].value;
} }
}, },


+ 55
- 41
src/views/insight/signsReport.vue View File

@@ -2,7 +2,7 @@


<template> <template>
<div class="report "> <div class="report ">
<NavBar title="周报" @on-click-left="onNavBack" right-text=""> </NavBar>
<NavBar :title="navTitle" @on-click-left="onNavBack" right-text=""> </NavBar>
<!-- 日期切换 --> <!-- 日期切换 -->
<div class="periodSwitch"> <div class="periodSwitch">
<div class="arrow arrowLeft"> <div class="arrow arrowLeft">
@@ -107,10 +107,10 @@
</template> </template>


<script> <script>
import axios from 'axios';
import NavBar from '@/components/NavBar'; import NavBar from '@/components/NavBar';
import { Signsmodel } from '@/config/models'; import { Signsmodel } from '@/config/models';
import EchartBox from '@/components/EchartBox'; import EchartBox from '@/components/EchartBox';
import { getMonthsByYear, getWeeksByYear } from '@/services/utils-service';
export default { export default {
components: { components: {
NavBar, EchartBox NavBar, EchartBox
@@ -126,8 +126,8 @@ export default {
currentRecord: {}, currentRecord: {},
psyCurrent: 0, psyCurrent: 0,
psyList: [ psyList: [
{ name: 'temperature', text: '体温', value: 1 },
{ name: 'heartrate', text: '心率', value: 0 }, { name: 'heartrate', text: '心率', value: 0 },
{ name: 'temperature', text: '体温', value: 1 },
{ name: 'step', text: '步数', value: 2 } { name: 'step', text: '步数', value: 2 }
], ],
healthyType: '', healthyType: '',
@@ -389,6 +389,9 @@ export default {
}, },
surveyTitle() { surveyTitle() {
return this.params.dateType == 0 ? '本周概览' : '本月概览' return this.params.dateType == 0 ? '本周概览' : '本月概览'
},
navTitle() {
return this.params.dateType == 0 ? '周报详情' : '月报详情'
} }


}, },
@@ -398,7 +401,12 @@ export default {
}, },
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
this.getWeekResult()
if (this.params.dateType == 1) {
this.getMonths();
} else {
this.getWeeks()
}

}) })
}, },
methods: { methods: {
@@ -407,6 +415,7 @@ export default {
if (params) { if (params) {
this.params = params; this.params = params;
this.emoName = Signsmodel[params.name].name; this.emoName = Signsmodel[params.name].name;
this.psyCurrent = this.calcPsyTabindex(Signsmodel[params.name].type);
this.currentEmoName = params.name; this.currentEmoName = params.name;
} }
}, },
@@ -456,9 +465,11 @@ export default {
} }
this.count--; this.count--;
this.isPreClick = true; this.isPreClick = true;

this.currentRecord = this.weekList.filter(item => { this.currentRecord = this.weekList.filter(item => {
return item.count === this.count; return item.count === this.count;
})[0]; })[0];
// 注意,周/月切换,日期不同
let date = this.weekList.filter(item => { let date = this.weekList.filter(item => {
return item.count === this.count; return item.count === this.count;
})[0].name; })[0].name;
@@ -474,6 +485,7 @@ export default {
this.count++; this.count++;
this.isAddClick = true; this.isAddClick = true;
// 当前切换的日期 // 当前切换的日期
// 注意,周/月切换,日期不同
let date = this.weekList.filter(item => { let date = this.weekList.filter(item => {
return item.count === this.count; return item.count === this.count;
})[0].name; })[0].name;
@@ -486,41 +498,6 @@ export default {
} }
} }
}, },
getWeekResult() {
let baseUrl =
process.env.NODE_ENV === 'production' ? 'https://dbmq.rzliot.com/auth_heart' : 'https://dbmq.rzliot.com/heart';
let reqUrl = `${baseUrl}/api/Data/GetWeekResult`;
let reqParams = {
uid: this.$store.getters.uid,
type: 1
};
axios
.get(reqUrl, {
params: { ...reqParams }
/* headers: { 'AccessToken': this.$store.getters.ssjlToken } */
})
.then(res => {
console.log('res', res);
const data = res.data.response;
this.weekList = data.reverse()
.map((item, index) => {
return {
name: item.Name.replace('周报', '').replace(/-/g, '.').replace(/~/g, '-'),
recordId: item.RecordId,
summary: item.Summary,
summaryLevel: item.SummaryLevel,
count: index
};
})

this.currentRecord = this.weekList[0];
this.count = 0;
this.maxCount = data.length - 1;
this.isAddClick = this.maxCount - this.count < this.maxCount;
this.isPreClick = this.maxCount - this.count > 0;
console.log("weekList", this.weekList, this.count);
});
},
onPsyTabClick(item) { onPsyTabClick(item) {
this.healthyType = item.value; this.healthyType = item.value;
this.psyCurrent = this.calcPsyTabindex(Signsmodel[item.name].type); this.psyCurrent = this.calcPsyTabindex(Signsmodel[item.name].type);
@@ -531,10 +508,10 @@ export default {
let psyIndex = ''; let psyIndex = '';
switch (type) { switch (type) {
case 0: case 0:
psyIndex = 1;
psyIndex = 0;
break; break;
case 1: case 1:
psyIndex = 0;
psyIndex = 1;
break; break;
case 2: case 2:
psyIndex = 2; psyIndex = 2;
@@ -551,6 +528,43 @@ export default {
this.pieEcharts = this.$echarts.init(this.$refs.pieChart); this.pieEcharts = this.$echarts.init(this.$refs.pieChart);
this.pieEcharts.setOption(this.pieOption); this.pieEcharts.setOption(this.pieOption);
}, },
getMonths() {
const months = getMonthsByYear(2);
console.log("months", months);
this.weekList = months.reverse()
.map((item, index) => {
return {
name: item.curYear + '-' + item.curMonth,
count: index
};
})
this.currentRecord = this.weekList.filter(item => {
return item.count === this.count;
})[0];
this.count = 0;
this.maxCount = months.length - 1;
this.isAddClick = this.maxCount - this.count < this.maxCount;
this.isPreClick = this.maxCount - this.count > 0;
},
getWeeks() {
const weeks = getWeeksByYear(1);
console.log("week", weeks);
this.weekList = weeks.reverse()
.map((item, index) => {
return {

name: item.start + '-' + item.end,
count: index
};
})
this.currentRecord = this.weekList.filter(item => {
return item.count === this.count;
})[0];
this.count = 0;
this.maxCount = weeks.length - 1;
this.isAddClick = this.maxCount - this.count < this.maxCount;
this.isPreClick = this.maxCount - this.count > 0;
}
}, },
} }
</script> </script>


Loading…
Cancel
Save